OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
CollimatorPhysics.hh
Go to the documentation of this file.
1 #ifndef COLLIMATORPHYSICS_HH
2 #define COLLIMATORPHYSICS_HH
3 //Class:CollimatorPhysics
4 // Defines the collimator physics models
5 // ------------------------------------------------------------------------
6 // Class category:
7 // ------------------------------------------------------------------------
8 // $Date: 2009/07/20 09:32:31 $
9 // $Author: Bi, Yang, Stachel, Adelmann$
10 //-------------------------------------------------------------------------
11 #include <vector>
13 #include "Algorithms/Vektor.h"
14 #include "AbsBeamline/Component.h"
17 #include "AbsBeamline/Degrader.h"
18 #include <gsl/gsl_rng.h>
19 
20 #include "Utility/IpplTimings.h"
21 
22 #ifdef OPAL_DKS
23 #include "DKSOPAL.h"
24 #endif
25 
26 class ElementBase;
27 
28 template <class T, unsigned Dim>
29 class PartBunchBase;
30 
31 class LossDataSink;
32 class Inform;
33 
34 #ifdef OPAL_DKS
35 typedef struct __align__(16) {
36  int label;
37  unsigned localID;
38  Vector_t Rincol;
39  Vector_t Pincol;
40  long IDincol;
41  int Binincol;
42  double DTincol;
43  double Qincol;
44  Vector_t Bfincol;
45  Vector_t Efincol;
46 } PART;
47 
48 typedef struct {
49  int label;
50  unsigned localID;
51  Vector_t Rincol;
52  Vector_t Pincol;
53 } PART_DKS;
54 
55 #else
56 typedef struct { // struct for description of particle in material
57  int label; // the status of the particle (0 = in material / -1 = move back to bunch
58  unsigned localID; // not so unique identifier of the particle
59  Vector_t Rincol; // position
60  Vector_t Pincol; // momentum
61  long IDincol; // unique identifier of the particle inherited from the bunch
62  int Binincol; // bin number
63  double DTincol; // time step size
64  double Qincol; // charge
65  Vector_t Bfincol; // magnetic field
66  Vector_t Efincol; // electric field
67 } PART;
68 #endif
69 
70 struct InsideTester {
71  virtual ~InsideTester()
72  { }
73 
74  virtual
75  bool checkHit(const Vector_t &R, const Vector_t &P, double dt) = 0;
76 };
77 
78 
80 public:
81  CollimatorPhysics(const std::string &name,
82  ElementBase *element,
83  std::string &mat,
84  bool enableRutherford);
86 
87  void apply(PartBunchBase<double, 3> *bunch,
88  const std::pair<Vector_t, double> &boundingSphere,
89  size_t numParticlesInSimulation = 0);
90 
91  virtual const std::string getType() const;
92 
93  void print(Inform& os);
94  bool stillActive();
96 
97  double getTime();
98  std::string getName();
99  size_t getParticlesInMat();
100  unsigned getRediffused();
101  unsigned int getNumEntered();
102  void computeInteraction();
103 
104  virtual bool computeEnergyLoss(Vector_t &P,
105  const double deltat,
106  bool includeFluctuations = true) const;
107 
108 private:
109 
112  Vector_t &P,
113  double dt);
114 
115  void applyRotation(Vector_t &P,
116  Vector_t &R,
117  double xplane,
118  double thetacou);
119  void applyRandomRotation(Vector_t &P, double theta0);
120 
122  const std::pair<Vector_t, double> &boundingSphere);
124 
126  const std::pair<Vector_t, double> &boundingSphere,
127  size_t numParticlesInSimulation);
128 #ifdef OPAL_DKS
129  void applyDKS(PartBunchBase<double, 3> *bunch,
130  const std::pair<Vector_t, double> &boundingSphere,
131  size_t numParticlesInSimulation);
132  void copyFromBunchDKS(PartBunchBase<double, 3> *bunch,
133  const std::pair<Vector_t, double> &boundingSphere);
134  void addBackToBunchDKS(PartBunchBase<double, 3> *bunch, unsigned int i);
135 
136  void setupCollimatorDKS(PartBunchBase<double, 3> *bunch, size_t numParticlesInSimulation);
137  void clearCollimatorDKS();
138 
139  void applyDKS();
140  void deleteParticleFromLocalVectorDKS();
141 
142 #endif
144 
145  void calcStat(double Eng);
146  void gatherStatistics();
147 
148  void push();
149  void resetTimeStep();
151 
152  double T_m; // own time, maybe larger than in the bunch object
153  double dT_m; // dt from bunch
154 
155  gsl_rng *rGen_m; // random number generator
156 
157  std::string material_m; // type of material e.g. aluminum
158  std::unique_ptr<InsideTester> hitTester_m; // tests whether particles are inside material
159  ElementBase::ElementType collshape_m; // the type of element (DEGRADER, CCOLLIMATOR or FLEXIBLECOLLIMATOR)
160  std::string collshapeStr_m; // the type of element as string
161 
162  // material parameters
163  double Z_m; // the atomic number [1]
164  double A_m; // the atomic mass [u]
165  double rho_m; // the volumetric mass density in [g cm^-3]
166  double X0_m; // the radiation length in [m]
167  double I_m; // the mean excitation energy [eV]
168 
169  double A2_c; // coefficients to fit model to measurement data
170  double A3_c; // see e.g. page 16-20 in H. H. Andersen, J. F. Ziegler,
171  double A4_c; // "Hydrogen Stopping Powers and Ranges in All Elements",
172  double A5_c; // Pergamon Press, 1977
173 
174  // number of particles that enter the material in current step (count for single step)
175  unsigned int bunchToMatStat_m;
176  // number of particles that are stopped by the material in current step
177  unsigned int stoppedPartStat_m;
178  // number of particles that leave the material in current step
179  unsigned int rediffusedStat_m;
180  // total number of particles that are in the material
181  unsigned int totalPartsInMat_m;
182 
183  // some statistics
184  double Eavg_m; // average kinetic energy
185  double Emax_m; // maximum kinetic energy
186  double Emin_m; // minimum kinetic energy
187 
188  std::vector<PART> locParts_m; // local particles that are in material
189 
190  std::unique_ptr<LossDataSink> lossDs_m;
191 
193 #ifdef OPAL_DKS
194  DKSOPAL dksbase_m;
195  int curandInitSet_m;
196 
197  int ierr_m;
198  int maxparticles_m;
199  int numparticles_m;
200  int numlocalparts_m;
201  void *par_ptr;
202  void *mem_ptr;
203 
204  std::vector<PART_DKS> dksParts_m;
205 
206  static const int numpar_m;
207 #endif
208 
212 };
213 
214 inline
215 void CollimatorPhysics::calcStat(double Eng) {
216  Eavg_m += Eng;
217  if (Emin_m > Eng)
218  Emin_m = Eng;
219  if (Emax_m < Eng)
220  Emax_m = Eng;
221 }
222 
223 inline
225  return T_m;
226 }
227 
228 inline
230  return totalPartsInMat_m;
231 }
232 
233 inline
235  return rediffusedStat_m;
236 }
237 
238 inline
240  return bunchToMatStat_m;
241 }
242 
243 inline
244 const std::string CollimatorPhysics::getType() const {
245  return "CollimatorPhysics";
246 }
247 
248 #endif //COLLIMATORPHYSICS_HH
249 
250 // vi: set et ts=4 sw=4 sts=4:
251 // Local Variables:
252 // mode:c++
253 // c-basic-offset: 4
254 // indent-tabs-mode:nil
255 // End:
std::unique_ptr< InsideTester > hitTester_m
CollimatorPhysics(const std::string &name, ElementBase *element, std::string &mat, bool enableRutherford)
IpplTimings::TimerRef DegraderDestroyTimer_m
Interface for basic beam line object.
Definition: ElementBase.h:128
void applyRotation(Vector_t &P, Vector_t &R, double xplane, double thetacou)
Definition: TSVMeta.h:24
void computeCoulombScattering(Vector_t &R, Vector_t &P, double dt)
std::vector< PART > locParts_m
IpplTimings::TimerRef DegraderApplyTimer_m
void apply(PartBunchBase< double, 3 > *bunch, const std::pair< Vector_t, double > &boundingSphere, size_t numParticlesInSimulation=0)
virtual const std::string getType() const
Vector_t Bfincol
std::unique_ptr< LossDataSink > lossDs_m
unsigned localID
bool stillAlive(PartBunchBase< double, 3 > *bunch)
double Qincol
Vector_t Pincol
unsigned int stoppedPartStat_m
Class: DataSink.
Definition: OpalData.h:29
IpplTimings::TimerRef DegraderLoopTimer_m
unsigned int rediffusedStat_m
virtual ~InsideTester()
std::string collshapeStr_m
void print(Inform &os)
unsigned int bunchToMatStat_m
Vector_t Rincol
long IDincol
void applyRandomRotation(Vector_t &P, double theta0)
void configureMaterialParameters()
The material of the collimator.
double DTincol
unsigned int totalPartsInMat_m
ElementBase::ElementType collshape_m
const std::string name
void calcStat(double Eng)
Timing::TimerRef TimerRef
Definition: IpplTimings.h:176
unsigned int getNumEntered()
void applyNonDKS(PartBunchBase< double, 3 > *bunch, const std::pair< Vector_t, double > &boundingSphere, size_t numParticlesInSimulation)
Vector_t Efincol
Definition: Inform.h:41
void addBackToBunch(PartBunchBase< double, 3 > *bunch)
void copyFromBunch(PartBunchBase< double, 3 > *bunch, const std::pair< Vector_t, double > &boundingSphere)
virtual bool computeEnergyLoss(Vector_t &P, const double deltat, bool includeFluctuations=true) const