OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
.PartBunchBase.h
Go to the documentation of this file.
1//
2// Class PartBunch
3// Base class for representing particle bunches.
4//
5// Copyright (c) 2008 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
6// All rights reserved
7//
8// This file is part of OPAL.
9//
10// OPAL is free software: you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// You should have received a copy of the GNU General Public License
16// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17//
18#ifndef PART_BUNCH_BASE_H
19#define PART_BUNCH_BASE_H
20
21#include "Ippl.h"
22
23#include <Kokkos_MathematicalConstants.hpp>
24#include <Kokkos_MathematicalFunctions.hpp>
25
26// /#include "Particle/AbstractParticle.h"
27#include "Particle/ParticleAttrib.h"
28#include "Particle/ParticleLayout.h"
29
33#include "Algorithms/Quaternion.h"
34
36
37#include "Algorithms/Matrix.h"
39#include "Physics/Units.h"
40#include "Structure/FieldSolver.h"
42#include "Utility/IpplTimings.h"
43
44#include <memory>
45#include <utility>
46#include <vector>
47
48class Distribution;
49class FieldSolver;
50class PartBins;
51class PartBinsCyc;
52class PartData;
53
54template <class T, unsigned Dim>
55class PartBunch : std::enable_shared_from_this<PartBunch<T, Dim>> {
56public:
57 // typedef typename AbstractParticle<T, Dim>::ParticlePos_t ParticlePos_t;
58 // typedef typename AbstractParticle<T, Dim>::ParticleIndex_t ParticleIndex_t;
59 // typedef typename AbstractParticle<T, Dim>::UpdateFlags UpdateFlags_t;
60 // typedef typename AbstractParticle<T, Dim>::Position_t Position_t;
61
62 typedef std::pair<Vector_t<double, 3>, Vector_t<double, 3>> VectorPair_t;
63
64 static const unsigned Dimension = Dim;
65
66 enum UnitState_t { units = 0, unitless = 1 };
67
68public:
69 virtual ~PartBunch() {
70 }
71
72 PartBunch(AbstractParticle<T, Dim>* pb, const PartData* ref);
73
74 PartBunch(const PartBunch& rhs) = delete; // implement if needed
75
77 friend class PartBunch<T, Dim>;
78
79 public:
80 ConstIterator() : bunch_m(nullptr), index_m(0) {
81 }
82 ConstIterator(PartBunch const* bunch, unsigned int i) : bunch_m(bunch), index_m(i) {
83 }
84
87
88 bool operator==(ConstIterator const& rhs) const {
89 return bunch_m == rhs.bunch_m && index_m == rhs.index_m;
90 }
91
92 bool operator!=(ConstIterator const& rhs) const {
93 return bunch_m != rhs.bunch_m || index_m != rhs.index_m;
94 }
95
97 if (index_m >= bunch_m->getLocalNum()) {
99 "PartBunch::ConstIterator::operator*", "out of bounds");
100 }
101 return OpalParticle(
102 bunch_m->ID[index_m], bunch_m->R[index_m], bunch_m->P[index_m], bunch_m->getT(),
103 bunch_m->Q[index_m], bunch_m->getM() * Units::eV2MeV);
104 }
105
107 ++index_m;
108 return *this;
109 }
110
112 ConstIterator it = *this;
113 ++index_m;
114
115 return it;
116 }
117
118 int operator-(const ConstIterator& other) const {
119 return index_m - other.index_m;
120 }
121
122 private:
124 unsigned int index_m;
125 };
126
127 ConstIterator begin() const {
128 return ConstIterator(this, 0);
129 }
130
131 ConstIterator end() const {
132 return ConstIterator(this, getLocalNum());
133 }
134
136 // The matrix [b]D[/b] is used to normalise the first two modes.
137 // The maximum normalised amplitudes for these modes are stored
138 // in [b]axmax[/b] and [b]aymax[/b].
139
141
148
149 void iterateEmittedBin(int binNumber);
150
151 void calcEMean();
152
153 size_t getTotalNum() const;
154 void setTotalNum(size_t n);
155 void setLocalNum(size_t n);
156 size_t getLocalNum() const;
157
158 size_t getDestroyNum() const;
159 size_t getGhostNum() const;
160
161 bool getUpdateFlag(UpdateFlags_t f) const;
162 void setUpdateFlag(UpdateFlags_t f, bool val);
163
164 ParticleBConds<Position_t, Dimension>& getBConds() {
165 return pbase_m->getBConds();
166 }
167
168 void setBConds(const ParticleBConds<Position_t, Dimension>& bc) {
169 pbase_m->setBConds(bc);
170 }
171
172 void resetID();
173
174 void update();
175 void update(const ParticleAttrib<char>& canSwap);
176
177 void createWithID(unsigned id);
178 void create(size_t M);
179 void globalCreate(size_t np);
180
181 void destroy(size_t M, size_t I, bool doNow = false);
182 void performDestroy(bool updateLocalNum = false);
183 void ghostDestroy(size_t M, size_t I);
184
185protected:
186 size_t calcMoments(); // Calculates bunch moments using only emitted particles.
187
188 /* Calculates bunch moments by summing over bins
189 * (not accurate when any particles have been emitted).
190 */
193 double calculateAngle(double x, double y);
194
195private:
196 virtual void updateDomainLength(Vektor<int, 3>& grid) = 0;
197
198 virtual void updateFields(const Vector_t<double, 3>& hr, const Vector_t<double, 3>& origin);
199
200 void setup(AbstractParticle<T, Dim>* pb);
201};
202
203template <class T, unsigned Dim>
205 return bunch.begin();
206}
207
208template <class T, unsigned Dim>
210 return bunch.end();
211}
212
213#include "PartBunch.hpp"
214
215#endif
Quaternion Quaternion_t
ippl::Vector< T, Dim > Vector_t
PartBunch< T, Dim >::ConstIterator end(PartBunch< T, Dim > const &bunch)
PartBunch< T, Dim >::ConstIterator begin(PartBunch< T, Dim > const &bunch)
ippl::ParticleAttrib< T > ParticleAttrib
double T
Definition datatypes.h:7
constexpr double eV2MeV
Definition Units.h:77
Vector_t< double, 3 > getKs3DRefr()
void create(size_t M)
ConstIterator begin() const
virtual ~PartBunch()
void setKs3DRefp(Vector_t< double, 3 > p)
virtual void updateDomainLength(Vektor< int, 3 > &grid)=0
void performDestroy(bool updateLocalNum=false)
void destroy(size_t M, size_t I, bool doNow=false)
void setKs3DRefr(Vector_t< double, 3 > r)
std::pair< Vector_t< double, 3 >, Vector_t< double, 3 > > VectorPair_t
double calculateAngle(double x, double y)
angle range [0~2PI) degree
ConstIterator end() const
virtual void updateFields(const Vector_t< double, 3 > &hr, const Vector_t< double, 3 > &origin)
size_t getDestroyNum() const
void update(const ParticleAttrib< char > &canSwap)
Vector_t< double, 3 > getKs3DRefp()
void setQKs3D(Quaternion_t q)
void calcMomentsInitial()
void ghostDestroy(size_t M, size_t I)
size_t getLocalNum() const
Quaternion_t getQKs3D()
void setLocalNum(size_t n)
PartBunch(const PartBunch &rhs)=delete
void setup(AbstractParticle< T, Dim > *pb)
void setBConds(const ParticleBConds< Position_t, Dimension > &bc)
void get_PBounds(Vector_t< double, 3 > &min, Vector_t< double, 3 > &max) const
Return maximum amplitudes.
ParticleBConds< Position_t, Dimension > & getBConds()
void setUpdateFlag(UpdateFlags_t f, bool val)
PartBunch(AbstractParticle< T, Dim > *pb, const PartData *ref)
PartBunch(PLayout_t< double, 3 > &pl, Vector_t< double, Dim > hr, Vector_t< double, Dim > rmin, Vector_t< double, Dim > rmax, std::array< bool, Dim > decomp, double Qtot)
void globalCreate(size_t np)
bool getUpdateFlag(UpdateFlags_t f) const
void createWithID(unsigned id)
size_t getTotalNum() const
void iterateEmittedBin(int binNumber)
void setTotalNum(size_t n)
size_t getGhostNum() const
size_t calcMoments()
PartBunch const * bunch_m
bool operator!=(ConstIterator const &rhs) const
ConstIterator(PartBunch const *bunch, unsigned int i)
bool operator==(ConstIterator const &rhs) const
ConstIterator operator++(int)
int operator-(const ConstIterator &other) const
OpalParticle operator*() const
Particle reference data.
Definition PartData.h:37