OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
ScatteringPhysics.h
Go to the documentation of this file.
1 //
2 // Class ScatteringPhysics
3 // Defines the physical processes of beam scattering
4 // and energy loss by heavy charged particles
5 //
6 // Copyright (c) 2009 - 2021, Bi, Yang, Stachel, Adelmann
7 // Paul Scherrer Institut, Villigen PSI, Switzerland
8 // All rights reserved.
9 //
10 // This file is part of OPAL.
11 //
12 // OPAL is free software: you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation, either version 3 of the License, or
15 // (at your option) any later version.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
19 //
20 #ifndef SCATTERINGPHYSICS_HH
21 #define SCATTERINGPHYSICS_HH
22 
24 
26 #include "Algorithms/Vektor.h"
27 
28 #include <gsl/gsl_rng.h>
29 
30 #include "Utility/IpplTimings.h"
31 
32 #include <memory>
33 #include <string>
34 #include <utility>
35 #include <vector>
36 
37 template <class T, unsigned Dim>
38 class PartBunchBase;
39 
40 class LossDataSink;
41 class Inform;
42 
43 typedef struct { // struct for description of particle in material
44  int label; // the status of the particle (0 = in material / -1 = move back to bunch
45  unsigned localID; // not so unique identifier of the particle
46  Vector_t Rincol; // position
47  Vector_t Pincol; // momentum
48  long IDincol; // unique identifier of the particle inherited from the bunch
49  int Binincol; // bin number
50  double DTincol; // time step size
51  double Qincol; // charge
52  double Mincol; // mass
53  Vector_t Bfincol; // magnetic field
54  Vector_t Efincol; // electric field
55 } PART;
56 
57 struct InsideTester {
58  virtual ~InsideTester()
59  { }
60 
61  virtual
62  bool checkHit(const Vector_t &R) = 0;
63 };
64 
65 
67 public:
68  ScatteringPhysics(const std::string& name,
69  ElementBase* element,
70  std::string& mat,
71  bool enableRutherford,
72  double lowEnergyThr);
74 
75  virtual void apply(PartBunchBase<double, 3>* bunch,
76  const std::pair<Vector_t, double>& boundingSphere);
77 
78  virtual const std::string getType() const;
79  virtual void print(Inform& os);
80  virtual bool stillActive();
81 
82  virtual double getTime();
83  virtual std::string getName();
84  virtual size_t getParticlesInMat();
85  virtual unsigned getRediffused();
86  virtual unsigned int getNumEntered();
87 
89 
90  virtual bool computeEnergyLoss(PartBunchBase<double, 3>* bunch,
91  Vector_t& P,
92  const double deltat,
93  bool includeFluctuations = true) const;
94 
95 private:
96 
99  Vector_t& P,
100  double dt);
101 
102  void applyRotation(Vector_t& P,
103  Vector_t& R,
104  double xplane,
105  double thetacou);
106  void applyRandomRotation(Vector_t& P, double theta0);
107 
109  const std::pair<Vector_t, double>& boundingSphere);
111 
113 
114  void calcStat(double Eng);
115  void gatherStatistics();
116 
117  void push();
118  void resetTimeStep();
120 
121  double T_m; // own time, maybe larger than in the bunch object
122  double dT_m; // dt from bunch
123 
124  double mass_m; // mass from bunch (eV)
125  double charge_m; // charge from bunch (elementary charges)
126 
127  gsl_rng* rGen_m; // random number generator
128  std::string material_m; // type of material e.g. aluminum
129  std::unique_ptr<InsideTester> hitTester_m; // tests whether particles are inside material
130  ElementBase::ElementType collshape_m; // the type of element (DEGRADER, CCOLLIMATOR or FLEXIBLECOLLIMATOR)
131  std::string collshapeStr_m; // the type of element as string
132 
133  // material parameters
134  double Z_m; // the atomic number [1]
135  double A_m; // the atomic mass [u]
136  double rho_m; // the volumetric mass density in [g cm^-3]
137  double X0_m; // the radiation length in [m]
138  double I_m; // the mean excitation energy [eV]
139 
140  /*
141  coefficients to fit model to measurement data according to Andersen-Ziegler formulae.
142  see ICRU-49, "Stopping Powers and Ranges for Protons and Alpha Particles",
143  chapter 'Electronic (Collision) Stopping Powers in the Low-Energy Region'
144  */
145  double A1_c;
146  double A2_c;
147  double A3_c;
148  double A4_c;
149  double A5_c;
150  double B1_c;
151  double B2_c;
152  double B3_c;
153  double B4_c;
154  double B5_c;
155 
156  // number of particles that enter the material in current step (count for single step)
157  unsigned int bunchToMatStat_m;
158  // number of particles that are stopped by the material in current step
159  unsigned int stoppedPartStat_m;
160  // number of particles that leave the material in current step
161  unsigned int rediffusedStat_m;
162  // total number of particles that are in the material
163  unsigned int totalPartsInMat_m;
164 
165  // some statistics
166  double Eavg_m; // average kinetic energy
167  double Emax_m; // maximum kinetic energy
168  double Emin_m; // minimum kinetic energy
169 
170  std::vector<PART> locParts_m; // local particles that are in material
171 
172  std::unique_ptr<LossDataSink> lossDs_m;
173 
176 
180 };
181 
182 inline
183 void ScatteringPhysics::calcStat(double Eng) {
184  Eavg_m += Eng;
185  if (Emin_m > Eng)
186  Emin_m = Eng;
187  if (Emax_m < Eng)
188  Emax_m = Eng;
189 }
190 
191 inline
193  return T_m;
194 }
195 
196 inline
198  return (element_ref_m->getName() + "_" + name_m);
199 }
200 
201 inline
203  return totalPartsInMat_m;
204 }
205 
206 inline
208  return rediffusedStat_m;
209 }
210 
211 inline
213  return bunchToMatStat_m;
214 }
215 
216 inline
217 const std::string ScatteringPhysics::getType() const {
218  return "ScatteringPhysics";
219 }
220 
221 #endif //SCATTERINGPHYSICS_HH
const std::string name
virtual const std::string & getName() const
Get element name.
double Qincol
long IDincol
unsigned localID
double DTincol
double Mincol
int Binincol
Vector_t Rincol
Vector_t Pincol
Vector_t Bfincol
Vector_t Efincol
virtual ~InsideTester()
virtual bool checkHit(const Vector_t &R)=0
void addBackToBunch(PartBunchBase< double, 3 > *bunch)
virtual bool computeEnergyLoss(PartBunchBase< double, 3 > *bunch, Vector_t &P, const double deltat, bool includeFluctuations=true) const
void configureMaterialParameters()
The material of the collimator.
virtual double getTime()
virtual bool stillActive()
ElementBase::ElementType collshape_m
void copyFromBunch(PartBunchBase< double, 3 > *bunch, const std::pair< Vector_t, double > &boundingSphere)
void calcStat(double Eng)
std::string collshapeStr_m
virtual void apply(PartBunchBase< double, 3 > *bunch, const std::pair< Vector_t, double > &boundingSphere)
unsigned int bunchToMatStat_m
IpplTimings::TimerRef DegraderLoopTimer_m
virtual unsigned getRediffused()
void applyRotation(Vector_t &P, Vector_t &R, double xplane, double thetacou)
ScatteringPhysics(const std::string &name, ElementBase *element, std::string &mat, bool enableRutherford, double lowEnergyThr)
virtual size_t getParticlesInMat()
void computeInteraction(PartBunchBase< double, 3 > *bunch)
unsigned int totalPartsInMat_m
void applyRandomRotation(Vector_t &P, double theta0)
void computeCoulombScattering(Vector_t &R, Vector_t &P, double dt)
std::unique_ptr< InsideTester > hitTester_m
virtual const std::string getType() const
virtual std::string getName()
std::vector< PART > locParts_m
unsigned int rediffusedStat_m
IpplTimings::TimerRef DegraderApplyTimer_m
unsigned int stoppedPartStat_m
IpplTimings::TimerRef DegraderDestroyTimer_m
virtual unsigned int getNumEntered()
virtual void print(Inform &os)
std::unique_ptr< LossDataSink > lossDs_m
Definition: Inform.h:42
Timing::TimerRef TimerRef
Definition: IpplTimings.h:176