ImpactX
Loading...
Searching...
No Matches
Programmable.H
Go to the documentation of this file.
1/* Copyright 2022-2023 The Regents of the University of California, through Lawrence
2 * Berkeley National Laboratory (subject to receipt of any required
3 * approvals from the U.S. Dept. of Energy). All rights reserved.
4 *
5 * This file is part of ImpactX.
6 *
7 * Authors: Axel Huebl
8 * License: BSD-3-Clause-LBNL
9 */
10#ifndef IMPACTX_ELEMENTS_PROGRAMMABLE_H
11#define IMPACTX_ELEMENTS_PROGRAMMABLE_H
12
16#include "mixin/named.H"
17#include "mixin/thick.H"
18
19#include <AMReX_Extension.H>
20#include <AMReX_REAL.H>
21// TODO: #include <AMReX_SIMD.H>
22// SIMD will require better complex math support in vir-simd / C++26
23// https://github.com/mattkretz/vir-simd/issues/42
24
25#include <functional>
26#include <stdexcept>
27
28
29namespace impactx::elements
30{
32 : public mixin::Named,
33 public mixin::LinearTransport<Programmable, false>
34 // TODO: public amrex::simd::Vectorized<amrex::simd::native_simd_size_particlereal>
35 {
36 static constexpr auto type = "Programmable";
38
47 int nslice=1,
48 std::optional<std::string> name = std::nullopt
49 )
50 : Named(std::move(name)), m_ds(ds), m_nslice(nslice)
51 {}
52
54 void reverse ()
55 {
56 throw std::runtime_error("Programmable: reverse() is not supported.");
57 }
58
65 void operator() (
67 int step,
68 int period
69 ) const;
70
72 void operator() (
74 RefPart & ref_part,
75 [[maybe_unused]] bool spin
76 ) const;
77
82 void operator() (
83 RefPart & refpart
84 ) const;
85
87 using LinearTransport::operator();
88
95 Map6x6
96 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
97 {
98 // TODO: can/should we fuse the two elements?
99 throw std::runtime_error("The Programmable element cannot be used for linear transport maps. Use the LinearMap element instead.");
100
101 return Map6x6::Identity();
102 }
103
109 int nslice () const
110 {
111 return m_nslice;
112 }
113
120 {
121 return m_ds;
122 }
123
126 void
127 finalize ();
128
130 int m_nslice = 1;
131
139 bool m_threadsafe = false;
140
141 std::function<void(ImpactXParticleContainer *, int, int)> m_push;
143 std::function<void(RefPart &)> m_ref_particle;
144 std::function<void()> m_finalize;
145 };
146
147} // namespace impactx
148
149#endif // IMPACTX_ELEMENTS_PROGRAMMABLE_H
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST_DEVICE
#define AMREX_GPU_HOST
Definition ImpactXParticleContainer.H:136
impactx::ParIterSoA iterator
amrex iterator for particle boxes
Definition ImpactXParticleContainer.H:139
amrex_particle_real ParticleReal
Definition All.H:56
amrex::SmallMatrix< amrex::ParticleReal, 6, 6, amrex::Order::F, 1 > Map6x6
Definition CovarianceMatrix.H:20
static constexpr __host__ __device__ SmallMatrix< T, NRows, NCols, ORDER, StartIndex > Identity() noexcept
Definition ReferenceParticle.H:33
std::function< void(RefPart &)> m_ref_particle
hook for beam particles (pti, ref)
Definition Programmable.H:143
std::function< void(ImpactXParticleContainer::iterator *, RefPart &)> m_beam_particles
hook for push of whole container (pc, step, period)
Definition Programmable.H:142
ImpactXParticleContainer::ParticleType PType
Definition Programmable.H:37
void reverse()
Definition Programmable.H:54
std::function< void(ImpactXParticleContainer *, int, int)> m_push
Definition Programmable.H:141
bool m_threadsafe
number of slices used for the application of space charge
Definition Programmable.H:139
amrex::ParticleReal m_ds
Definition Programmable.H:129
void operator()(ImpactXParticleContainer &pc, int step, int period) const
Definition Programmable.cpp:20
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int nslice() const
Definition Programmable.H:109
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition Programmable.H:96
std::function< void()> m_finalize
hook for reference particle
Definition Programmable.H:144
int m_nslice
segment length in m
Definition Programmable.H:130
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal ds() const
Definition Programmable.H:119
static constexpr auto type
Definition Programmable.H:36
void finalize()
Definition Programmable.cpp:61
Programmable(amrex::ParticleReal ds=0.0, int nslice=1, std::optional< std::string > name=std::nullopt)
Definition Programmable.H:45
Definition lineartransport.H:50
Definition named.H:29
AMREX_GPU_HOST Named(std::optional< std::string > name)
Definition named.H:57
AMREX_FORCE_INLINE std::string name() const
Definition named.H:122