ImpactX
Loading...
Searching...
No Matches
ImpactXParticleContainer.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_PARTICLE_CONTAINER_H
11#define IMPACTX_PARTICLE_CONTAINER_H
12
13#include "ReferenceParticle.H"
15
16#include <AMReX_AmrCoreFwd.H>
17#include <AMReX_BaseFwd.H>
18#include <AMReX_MultiFab.H>
19#include <AMReX_ParIter.H>
20#include <AMReX_Particles.H>
21#include <AMReX_ParticleTile.H>
22#include <AMReX_REAL.H>
23
24#include <AMReX_IntVect.H>
25#include <AMReX_Vector.H>
26
27#include <list>
28#include <optional>
29#include <tuple>
30#include <unordered_map>
31
32
33namespace impactx
34{
35 enum class CoordSystem
36 {
37 s,
39 };
40
44 struct RealSoA
45 {
46 enum
47 {
48 x,
49 y,
50 t,
55 w,
57 };
58
59 // at fixed t, the third component represents the position z, the 6th component represents the momentum in z
60 enum {
61 z = t,
62 pz = pt
63 };
64
66 static constexpr auto names_s = { "position_x", "position_y", "position_t", "momentum_x", "momentum_y", "momentum_t", "qm", "weighting" };
68 static constexpr auto names_t = { "position_x", "position_y", "position_z", "momentum_x", "momentum_y", "momentum_z", "qm", "weighting" };
69 static_assert(names_s.size() == nattribs);
70 static_assert(names_t.size() == nattribs);
71 };
72
76 struct IntSoA
77 {
78 enum
79 {
81 };
82
84 static constexpr std::initializer_list<char const *> names_s = {};
86 static constexpr std::initializer_list<char const *> names_t = {};
87 static_assert(names_s.size() == nattribs);
88 static_assert(names_t.size() == nattribs);
89 };
90
97 : public amrex::ParIterSoA<RealSoA::nattribs, IntSoA::nattribs>
98 {
99 public:
101
102 ParIterSoA (ContainerType& pc, int level);
103
104 ParIterSoA (ContainerType& pc, int level, amrex::MFItInfo& info);
105
106 ContainerType * pc () { return m_pc; }
107 };
108
115 : public amrex::ParConstIterSoA<RealSoA::nattribs, IntSoA::nattribs>
116 {
117 public:
119
120 ParConstIterSoA (ContainerType& pc, int level);
121
122 ParConstIterSoA (ContainerType& pc, int level, amrex::MFItInfo& info);
123
124 ContainerType const * pc () const { return m_pc; }
125 };
126
132 : public amrex::ParticleContainerPureSoA<RealSoA::nattribs, IntSoA::nattribs>
133 {
134 public:
137
140
143
145 virtual ~ImpactXParticleContainer() = default;
146
152 void prepare ();
153
161 void clear (bool keep_mass=false, bool keep_charge=false);
162
183 void
191 amrex::ParticleReal qm,
192 std::optional<amrex::ParticleReal> bunch_charge = std::nullopt,
193 std::optional<amrex::Gpu::DeviceVector<amrex::ParticleReal>> w = std::nullopt
194 );
195
200 void
202
205
210 void
211 SetRefParticle (RefPart const & refpart);
212
217 RefPart &
219
224 RefPart const &
225 GetRefParticle () const;
226
230 void SetRefParticleEdge ();
231
234 int
235 GetParticleShape () const { return m_particle_shape.value(); }
236
243 void SetParticleShape ();
244
253 void SetParticleShape (int order);
254
259 std::tuple<
260 amrex::ParticleReal, amrex::ParticleReal,
261 amrex::ParticleReal, amrex::ParticleReal,
262 amrex::ParticleReal, amrex::ParticleReal>
264
269 std::tuple<
270 amrex::ParticleReal, amrex::ParticleReal,
271 amrex::ParticleReal, amrex::ParticleReal,
272 amrex::ParticleReal, amrex::ParticleReal>
274
284 void
285 DepositCharge (std::unordered_map<int, amrex::MultiFab> & rho,
286 amrex::Vector<amrex::IntVect> const & ref_ratio);
287
290 GetCoordSystem () const;
291
296 void
297 SetCoordSystem (CoordSystem coord_system);
298
300 bool store_beam_moments = false;
301
303 void
305
307 std::unordered_map<std::string, amrex::ParticleReal>
308 beam_moments ();
309
311 std::list<std::unordered_map<std::string, amrex::ParticleReal> >
313
315 void
317
318 private:
319
322
324 std::optional<int> m_particle_shape;
325
328
331
333 std::list<std::unordered_map<std::string, amrex::ParticleReal> > m_beam_moments;
334
335 }; // ImpactXParticleContainer
336
337} // namespace impactx
338
339#endif // IMPACTX_PARTICLE_CONTAINER_H
ParticleContainer_impl< ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor > ContainerType
ParticleContainer_impl< ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor > ContainerType
void AddNParticles(amrex::Gpu::DeviceVector< amrex::ParticleReal > const &x, amrex::Gpu::DeviceVector< amrex::ParticleReal > const &y, amrex::Gpu::DeviceVector< amrex::ParticleReal > const &t, amrex::Gpu::DeviceVector< amrex::ParticleReal > const &px, amrex::Gpu::DeviceVector< amrex::ParticleReal > const &py, amrex::Gpu::DeviceVector< amrex::ParticleReal > const &pt, amrex::ParticleReal qm, std::optional< amrex::ParticleReal > bunch_charge=std::nullopt, std::optional< amrex::Gpu::DeviceVector< amrex::ParticleReal > > w=std::nullopt)
Definition ImpactXParticleContainer.cpp:236
std::unordered_map< std::string, amrex::ParticleReal > beam_moments()
Definition ImpactXParticleContainer.cpp:442
virtual ~ImpactXParticleContainer()=default
Destruct a particle container.
void record_beam_moments()
Definition ImpactXParticleContainer.cpp:430
int GetParticleShape() const
Definition ImpactXParticleContainer.H:235
std::list< std::unordered_map< std::string, amrex::ParticleReal > > m_beam_moments
history of the beam moments over s
Definition ImpactXParticleContainer.H:333
void SetLostParticleContainer(ImpactXParticleContainer *lost_pc)
Definition ImpactXParticleContainer.cpp:74
void DepositCharge(std::unordered_map< int, amrex::MultiFab > &rho, amrex::Vector< amrex::IntVect > const &ref_ratio)
Definition ChargeDeposition.cpp:28
std::tuple< amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal > MinAndMaxPositions()
Definition ImpactXParticleContainer.cpp:399
void reset_beam_moments_history()
Definition ImpactXParticleContainer.H:316
void SetRefParticle(RefPart const &refpart)
Definition ImpactXParticleContainer.cpp:372
impactx::ParIterSoA iterator
amrex iterator for particle boxes
Definition ImpactXParticleContainer.H:136
bool store_beam_moments
Definition ImpactXParticleContainer.H:300
CoordSystem GetCoordSystem() const
Definition ImpactXParticleContainer.cpp:418
void SetRefParticleEdge()
Definition ImpactXParticleContainer.cpp:390
ImpactXParticleContainer * m_particles_lost
a non-owning reference to lost particles, i.e., due to apertures
Definition ImpactXParticleContainer.H:327
ImpactXParticleContainer(initialization::AmrCoreData *amr_core)
Construct a new particle container.
Definition ImpactXParticleContainer.cpp:63
void SetParticleShape()
Definition ImpactXParticleContainer.cpp:105
void SetCoordSystem(CoordSystem coord_system)
Definition ImpactXParticleContainer.cpp:424
ImpactXParticleContainer * GetLostParticleContainer()
Definition ImpactXParticleContainer.cpp:80
impactx::ParConstIterSoA const_iterator
amrex constant iterator for particle boxes (read-only)
Definition ImpactXParticleContainer.H:139
std::tuple< amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal > MeanAndStdPositions()
Definition ImpactXParticleContainer.cpp:409
RefPart m_refpart
the reference particle for the beam in the particle container
Definition ImpactXParticleContainer.H:321
std::optional< int > m_particle_shape
the particle shape
Definition ImpactXParticleContainer.H:324
CoordSystem m_coordsystem
the current coordinate system of particles in this container
Definition ImpactXParticleContainer.H:330
std::list< std::unordered_map< std::string, amrex::ParticleReal > > beam_moments_history()
Definition ImpactXParticleContainer.H:312
void prepare()
Definition ImpactXParticleContainer.cpp:126
void clear(bool keep_mass=false, bool keep_charge=false)
Definition ImpactXParticleContainer.cpp:228
RefPart & GetRefParticle()
Definition ImpactXParticleContainer.cpp:378
Definition ImpactXParticleContainer.H:116
ContainerType const * pc() const
Definition ImpactXParticleContainer.H:124
ParConstIterSoA(ContainerType &pc, int level)
Definition ImpactXParticleContainer.cpp:55
Definition ImpactXParticleContainer.H:98
ContainerType * pc()
Definition ImpactXParticleContainer.H:106
ParIterSoA(ContainerType &pc, int level)
Definition ImpactXParticleContainer.cpp:47
Definition AmrCoreData.H:44
PODVector< T, ArenaAllocator< T > > DeviceVector
ParIter_impl< SoAParticle< T_NArrayReal, T_NArrayInt >, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor > ParIterSoA
ParConstIter_impl< SoAParticle< T_NArrayReal, T_NArrayInt >, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor > ParConstIterSoA
ParticleContainer_impl< SoAParticle< T_NArrayReal, T_NArrayInt >, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor > ParticleContainerPureSoA
Definition CovarianceMatrixMath.H:25
CoordSystem
Definition ImpactXParticleContainer.H:36
@ s
fixed s as the independent variable
Definition ImpactXParticleContainer.H:37
@ t
fixed t as the independent variable
Definition ImpactXParticleContainer.H:38
Definition ImpactXParticleContainer.H:77
static constexpr std::initializer_list< char const * > names_s
named labels for fixed s
Definition ImpactXParticleContainer.H:84
@ nattribs
the number of attributes above (always last)
Definition ImpactXParticleContainer.H:80
static constexpr std::initializer_list< char const * > names_t
named labels for fixed t
Definition ImpactXParticleContainer.H:86
Definition ImpactXParticleContainer.H:45
static constexpr auto names_s
named labels for fixed s
Definition ImpactXParticleContainer.H:66
@ z
position in z [m] (at fixed t)
Definition ImpactXParticleContainer.H:61
@ pz
momentum in z, scaled by the magnitude of the reference momentum [unitless] (at fixed t)
Definition ImpactXParticleContainer.H:62
static constexpr auto names_t
named labels for fixed t
Definition ImpactXParticleContainer.H:68
@ pt
energy deviation, scaled by speed of light * the magnitude of the reference momentum [unitless] (at f...
Definition ImpactXParticleContainer.H:53
@ y
position in y [m] (at fixed s or t)
Definition ImpactXParticleContainer.H:49
@ t
time-of-flight ct [m] (at fixed s)
Definition ImpactXParticleContainer.H:50
@ w
particle weight, number of real particles represented by this macroparticle [unitless]
Definition ImpactXParticleContainer.H:55
@ px
momentum in x, scaled by the magnitude of the reference momentum [unitless] (at fixed s or t)
Definition ImpactXParticleContainer.H:51
@ nattribs
the number of attributes above (always last)
Definition ImpactXParticleContainer.H:56
@ py
momentum in y, scaled by the magnitude of the reference momentum [unitless] (at fixed s or t)
Definition ImpactXParticleContainer.H:52
@ x
position in x [m] (at fixed s or t)
Definition ImpactXParticleContainer.H:48
@ qm
charge to mass ratio, in q_e/m_e [q_e/eV]
Definition ImpactXParticleContainer.H:54
Definition ReferenceParticle.H:31