OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
PartBunch.h
Go to the documentation of this file.
1//
2// Class PartBunch
3// Particle Bunch.
4// A representation of a particle bunch as a vector of particles.
5//
6// Copyright (c) 2008 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
7// All rights reserved
8//
9// This file is part of OPAL.
10//
11// OPAL is free software: you can redistribute it and/or modify
12// it under the terms of the GNU General Public License as published by
13// the Free Software Foundation, either version 3 of the License, or
14// (at your option) any later version.
15//
16// You should have received a copy of the GNU General Public License
17// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
18//
19#ifndef OPAL_PartBunch_HH
20#define OPAL_PartBunch_HH
21
24
25#include <cstddef>
26#include <functional>
27#include <string>
28#include <vector>
29
30class PartBunch: public PartBunchBase<double, 3> {
31
32public:
34 enum { Dim = Dimension };
35
36public:
37
39 // Construct empty bunch.
40 explicit PartBunch(const PartData *ref);
41
42 PartBunch() = delete;
43 PartBunch(const PartBunch &) = delete;
44 PartBunch &operator=(const PartBunch &) = delete;
45
46 ~PartBunch();
47
48// pbase_t* clone();
49
50 void initialize(FieldLayout_t *fLayout);
51
52 void do_binaryRepart();
53
54 double getRho(int x, int y, int z);
55
56 /*
57
58 Mesh and Field Layout related functions
59
60 */
61
62 // MATTHIAS CHECK
63 const Mesh_t &getMesh() const;
64
65// void setMesh(Mesh_t* mesh);
66
67 // MATTHIAS CHECK
68 Mesh_t &getMesh();
69
70// void setFieldLayout(FieldLayout_t* fLayout);
71
72 // MATTHIAS CHECK
74
75 void setBCAllPeriodic();
76 void setBCAllOpen();
77
78 void setBCForDCBeam();
79
80 /*
81 Compatibility function push_back
82
83 */
84
86
87 void computeSelfFields();
88
90 void computeSelfFields(int b);
91
92 void computeSelfFields_cycl(double gamma);
93 void computeSelfFields_cycl(int b);
94
96 typedef std::function<bool(size_t)> ParticleMask_t;
97
105 void scatterMasked(const ParticleMask_t& accept);
106
113 void gatherMasked(const ParticleMask_t& accept);
114
115 void resetInterpolationCache(bool clearCache = false);
116
117 void swap(unsigned int i, unsigned int j);
118
121
124
125 Inform &print(Inform &os);
126
127private:
128
130
131 void updateFields(const Vector_t& hr, const Vector_t& origin);
132
134 void resizeMesh();
135
155 void computeFarField(double gamma, const std::vector<CoreFitSC::ParticleClass>& particleClass);
156
160 void checkUnmaskedInterpolation(const std::string& where) const;
161
165
166
168
170
174
175 //FIXME
177 return pbase_m->getLayout();
178 }
179
180 //FIXME
182 return pbase_m->getLayout();
183 }
184};
185
186
187
188inline
189double PartBunch::getRho(int x, int y, int z) {
190 return rho_m[x][y][z].get();
191}
192
193inline
195 const Layout_t* layout = static_cast<const Layout_t*>(&getLayout());
196 return layout->getLayout().getMesh();
197}
198
199inline
201 Layout_t* layout = static_cast<Layout_t*>(&getLayout());
202 return layout->getLayout().getMesh();
203}
204
205// inline
206
208 return p.print(os);
209}
210
211#endif // OPAL_PartBunch_HH
Inform & operator<<(Inform &os, PartBunch &p)
Definition PartBunch.h:207
PETE_TTTree< OpWhere, typename Cond_t::PETE_Expr_t, typename True_t::PETE_Expr_t, PETE_Scalar< Vektor< T, Dim > > > where(const PETE_Expr< Cond_t > &c, const PETE_Expr< True_t > &t, const Vektor< T, Dim > &f)
std::shared_ptr< AbstractParticle< double, Dim > > pbase_m
std::pair< Vector_t, Vector_t > VectorPair_t
static const unsigned Dimension
void resetInterpolationCache(bool clearCache=false)
ParticleAttrib< double > maskedQ_m
scatterMasked(): the charges and positions of the particles that a predicate accepts
Definition PartBunch.h:172
BConds< double, 3, Mesh_t, Center_t > bc_m
for defining the boundary conditions
Definition PartBunch.h:163
double getRho(int x, int y, int z)
Definition PartBunch.h:189
void computeSelfFields()
PartBunch & operator=(const PartBunch &)=delete
IpplParticleBase< Layout_t > pbase_t
Definition PartBunch.h:33
void scatterMasked(const ParticleMask_t &accept)
CIC scatter of Q onto rho_m, of the particles with Bin >= 0 and accept(i) true.
void do_binaryRepart()
Definition PartBunch.cpp:70
Field_t rho_m
scalar potential
Definition PartBunch.h:120
PartBunch()=delete
void swap(unsigned int i, unsigned int j)
const ParticleLayout< double, 3 > & getLayout() const
Definition PartBunch.h:181
void computeFarField(double gamma, const std::vector< CoreFitSC::ParticleClass > &particleClass)
MESHFIT=CORE: field of the particles outside the core bounds.
ParticleLayout< double, 3 > & getLayout()
Definition PartBunch.h:176
void initialize(FieldLayout_t *fLayout)
Definition PartBunch.cpp:64
void gatherMasked(const ParticleMask_t &accept)
CIC gather of eg_m into Ef, at the particles with accept(i) true.
void setBCAllOpen()
bool interpolationCacheSet_m
Definition PartBunch.h:167
Inform & print(Inform &os)
ParticleAttrib< Vector_t > maskedR_m
Definition PartBunch.h:173
void checkUnmaskedInterpolation(const std::string &where) const
void updateDomainLength(Vektor< int, 3 > &grid)
void setBCForDCBeam()
FieldLayout_t & getFieldLayout()
VField_t eg_m
vector field on the grid
Definition PartBunch.h:123
VectorPair_t getEExtrema()
void setBCAllPeriodic()
const Mesh_t & getMesh() const
Definition PartBunch.h:194
PartBunch(const PartBunch &)=delete
ParticleAttrib< CacheDataCIC< double, 3U > > interpolationCache_m
Definition PartBunch.h:169
void resizeMesh()
resize mesh to geometry specified
BConds< Vector_t, 3, Mesh_t, Center_t > vbc_m
Definition PartBunch.h:164
void computeSelfFields_cycl(double gamma)
Calculates the self electric field from the charge density distribution for use in cyclotrons.
void updateFields(const Vector_t &hr, const Vector_t &origin)
std::function< bool(size_t)> ParticleMask_t
Per-particle predicate on the local index, for scatterMasked() and gatherMasked().
Definition PartBunch.h:96
RegionLayout< T, Dim, Mesh > & getLayout()