ImpactX
Loading...
Searching...
No Matches
Programmable.H
Go to the documentation of this file.
1/* Copyright 2022-2026 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
28namespace impactx::elements
29{
31 : public mixin::Named,
32 public mixin::LinearTransport<Programmable, false>
33 // TODO: public amrex::simd::Vectorized<amrex::simd::native_simd_size_particlereal>
34 {
35 static constexpr auto type = "Programmable";
37
38 static constexpr amrex::ParticleReal DEFAULT_ds = 0;
40
50 std::optional<std::string> name = DEFAULT_name
51 )
52 : Named(std::move(name)), m_ds(ds), m_nslice(nslice)
53 {}
54
56 void reverse ()
57 {
58 throw std::runtime_error("Programmable: reverse() is not supported.");
59 }
60
67 void operator() (
69 int step,
70 int period
71 ) const;
72
74 void operator() (
76 RefPart & ref_part,
77 [[maybe_unused]] bool spin
78 ) const;
79
84 void operator() (
85 RefPart & refpart
86 ) const;
87
89 using LinearTransport::operator();
90
97 Map6x6
98 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
99 {
100 // TODO: can/should we fuse the two elements?
101 throw std::runtime_error("The Programmable element cannot be used for linear transport maps. Use the LinearMap element instead.");
102
103 return Map6x6::Identity();
104 }
105
111 int nslice () const
112 {
113 return m_nslice;
114 }
115
122 {
123 return m_ds;
124 }
125
128 void
129 finalize ();
130
133
141 bool m_threadsafe = false;
142
143 std::function<void(ImpactXParticleContainer *, int, int)> m_push;
145 std::function<void(RefPart &)> m_ref_particle;
146 std::function<void()> m_finalize;
147 };
148
149} // namespace impactx
150
151#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:55
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:145
std::function< void(ImpactXParticleContainer::iterator *, RefPart &)> m_beam_particles
hook for push of whole container (pc, step, period)
Definition Programmable.H:144
static constexpr amrex::ParticleReal DEFAULT_ds
Definition Programmable.H:38
ImpactXParticleContainer::ParticleType PType
Definition Programmable.H:36
void reverse()
Definition Programmable.H:56
std::function< void(ImpactXParticleContainer *, int, int)> m_push
Definition Programmable.H:143
bool m_threadsafe
number of slices used for the application of space charge
Definition Programmable.H:141
amrex::ParticleReal m_ds
Definition Programmable.H:131
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:111
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition Programmable.H:98
std::function< void()> m_finalize
hook for reference particle
Definition Programmable.H:146
static constexpr int DEFAULT_nslice
Definition Programmable.H:39
int m_nslice
segment length in m
Definition Programmable.H:132
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal ds() const
Definition Programmable.H:121
Programmable(amrex::ParticleReal ds=DEFAULT_ds, int nslice=DEFAULT_nslice, std::optional< std::string > name=DEFAULT_name)
Definition Programmable.H:47
static constexpr auto type
Definition Programmable.H:35
void finalize()
Definition Programmable.cpp:61
Definition lineartransport.H:50
Definition named.H:29
static constexpr std::nullopt_t DEFAULT_name
Definition named.H:30
AMREX_GPU_HOST Named(std::optional< std::string > name)
Definition named.H:59
AMREX_FORCE_INLINE std::string name() const
Definition named.H:124
static constexpr int DEFAULT_nslice
Definition thick.H:25