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>
34 // TODO: public amrex::simd::Vectorized<amrex::simd::native_simd_size_particlereal>
35 {
36 static constexpr auto type = "Programmable";
38
46 amrex::ParticleReal ds=0.0,
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
59 void operator() (
61 int step,
62 int period
63 ) const;
64
66 void operator() (
68 RefPart & ref_part
69 ) const;
70
75 void operator() (
76 RefPart & refpart
77 ) const;
78
80 using LinearTransport::operator();
81
88 Map6x6
89 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
90 {
91 // TODO: can/should we fuse the two elements?
92 throw std::runtime_error("The Programmable element cannot be used for linear transport maps. Use the LinearMap element instead.");
93
94 return Map6x6::Identity();
95 }
96
102 int nslice () const
103 {
104 return m_nslice;
105 }
106
112 amrex::ParticleReal ds () const
113 {
114 return m_ds;
115 }
116
119 void
120 finalize ();
121
122 amrex::ParticleReal m_ds = 0.0;
123 int m_nslice = 1;
124
132 bool m_threadsafe = false;
133
134 std::function<void(ImpactXParticleContainer *, int, int)> m_push;
136 std::function<void(RefPart &)> m_ref_particle;
137 std::function<void()> m_finalize;
138 };
139
140} // namespace impactx
141
142#endif // IMPACTX_ELEMENTS_PROGRAMMABLE_H
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST_DEVICE
#define AMREX_GPU_HOST
Definition ImpactXParticleContainer.H:133
impactx::ParIterSoA iterator
amrex iterator for particle boxes
Definition ImpactXParticleContainer.H:136
Definition All.H:54
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:31
std::function< void(RefPart &)> m_ref_particle
hook for beam particles
Definition Programmable.H:136
std::function< void(ImpactXParticleContainer::iterator *, RefPart &)> m_beam_particles
hook for push of whole container (pc, step, period)
Definition Programmable.H:135
ImpactXParticleContainer::ParticleType PType
Definition Programmable.H:37
std::function< void(ImpactXParticleContainer *, int, int)> m_push
Definition Programmable.H:134
bool m_threadsafe
number of slices used for the application of space charge
Definition Programmable.H:132
amrex::ParticleReal m_ds
Definition Programmable.H:122
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:102
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition Programmable.H:89
std::function< void()> m_finalize
hook for reference particle
Definition Programmable.H:137
int m_nslice
segment length in m
Definition Programmable.H:123
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal ds() const
Definition Programmable.H:112
static constexpr auto type
Definition Programmable.H:36
void finalize()
Definition Programmable.cpp:60
Programmable(amrex::ParticleReal ds=0.0, int nslice=1, std::optional< std::string > name=std::nullopt)
Definition Programmable.H:45
Definition lineartransport.H:29
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