OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
BoundaryGeometry.h
Go to the documentation of this file.
1 //
2 // Copyright & License: See Copyright.readme in src directory
3 //
4 
19 #ifndef _OPAL_BOUNDARY_GEOMETRY_H
20 #define _OPAL_BOUNDARY_GEOMETRY_H
21 
22 class OpalBeamline;
23 class ElementBase;
24 
25 #include <assert.h>
26 #include <unordered_map>
27 #include <unordered_set>
28 #include <array>
29 
31 #include "Attributes/Attributes.h"
33 
34 #include <gsl/gsl_rng.h>
35 
36 extern Inform* gmsg;
37 
38 namespace BGphysics {
39  enum TPHYACTION {
40  Nop = 0x01, // triangle is transparent to particle like beam window
41  Absorption = 0x02, // triangle has no field and secondary emission
42  FNEmission = 0x04, // triangle has field emission
43  SecondaryEmission = 0x08 // triangle has secondary emission
44  };
45 }
46 
47 class BoundaryGeometry : public Definition {
48 
49 public:
51  virtual ~BoundaryGeometry();
52 
53  virtual bool canReplaceBy (
54  Object* object);
55 
56  virtual BoundaryGeometry* clone (
57  const std::string& name);
58 
59  // Check the GEOMETRY data.
60  virtual void execute ();
61 
62  // Find named GEOMETRY.
63  static BoundaryGeometry* find (
64  const std::string& name);
65 
66  // Update the GEOMETRY data.
67  virtual void update ();
68 
69  void updateElement (
70  ElementBase* element);
71 
72  void initialize ();
73 
75  size_t n, double darkinward,
76  OpalBeamline& itsOpalBeamline,
77  PartBunchBase<double, 3>* itsBunch);
78 
79  void createPriPart (
80  size_t n, double darkinward,
81  OpalBeamline& itsOpalBeamline,
82  PartBunchBase<double, 3>* itsBunch);
83 
84  int partInside (
85  const Vector_t& r,
86  const Vector_t& v,
87  const double dt,
88  int Parttype,
89  const double Qloss,
90  Vector_t& intecoords,
91  int& triId);
92 
93  // non secondary emission version.
94  int emitSecondaryNone (
95  const Vector_t& intecoords,
96  const int& triId);
97 
98  // call Furman-Pivi's model
100  const Vector_t& intecoords,
101  const int i,
102  PartBunchBase<double, 3>* itsBunch,
103  double& seyNum);
104 
105  // call Vaughan's model
107  const Vector_t& intecoords,
108  const int i,
109  PartBunchBase<double, 3>* itsBunch,
110  double& seyNum);
111 
112  Inform& printInfo (
113  Inform& os) const;
114 
115  void writeGeomToVtk (std::string fn);
116 
117  inline std::string getFilename () const {
118  return (std::string) Attributes::getString (itsAttr[FGEOM]);
119  }
120 
121  inline std::string getTopology () const {
122  return (std::string) Attributes::getString (itsAttr[TOPO]);
123  }
124 
125  inline std::string getDistribution () {
126  return (std::string) Attributes::getString (itsAttr[DISTR]);
127  }
128 
129  inline std::vector<std::string> getDistributionArray () {
131  }
132 
133  inline size_t getN () {
134  return partsr_m.size ();
135  }
136 
137  inline Vector_t getCooridinate (size_t i) {
138  return partsr_m[i];
139  }
140  inline void clearCooridinateArray () {
141  return partsr_m.clear ();
142  }
143  inline Vector_t getMomenta (size_t i) {
144  return partsp_m[i];
145  }
146 
147  inline void clearMomentaArray () {
148  return partsp_m.clear ();
149  }
150 
151  inline double getA() {
152  return (double)Attributes::getReal(itsAttr[A]);
153  }
154 
155  inline double getB() {
156  return (double)Attributes::getReal(itsAttr[B]);
157  }
158 
159  inline double getC() {
160  return (double)Attributes::getReal(itsAttr[C]);
161  }
162 
163  inline double getS() {
164  return (double)Attributes::getReal(itsAttr[S]);
165  }
166 
167  inline double getLength() {
168  return (double)Attributes::getReal(itsAttr[LENGTH]);
169  }
170 
171  inline double getL1() {
172  return (double)Attributes::getReal(itsAttr[L1]);
173  }
174 
175  inline double getL2() {
176  return (double)Attributes::getReal(itsAttr[L2]);
177  }
178 
179  inline void setNEmissionMode (bool nEmissionMode) {
180  nEmissionMode_m = nEmissionMode;
181  }
182 
183  inline void setWorkFunction (double workFunction) {
184  workFunction_m = workFunction;
185  }
186 
187  inline void setFieldEnhancement (double fieldEnhancement) {
188  fieldEnhancement_m = fieldEnhancement;
189  }
190 
191  inline void setMaxFN (size_t maxFNemission) {
192  maxFNemission_m = maxFNemission;
193  }
194 
195  inline void setFNTreshold (double fieldFNthreshold) {
196  fieldFNthreshold_m = - 1.0e6 * fieldFNthreshold;
197  }
198 
199  inline void setFNParameterA (double parameterFNA) {
200  parameterFNA_m = parameterFNA;
201  }
202 
203  inline void setFNParameterB (double parameterFNB) {
204  parameterFNB_m = parameterFNB;
205  }
206 
207  inline void setFNParameterY (double parameterFNY) {
208  parameterFNY_m = parameterFNY;
209  }
210 
211  inline void setFNParameterVYZe (double parameterFNVYZe) {
212  parameterFNVYZe_m = parameterFNVYZe;
213  }
214 
215  inline void setFNParameterVYSe (double parameterFNVYSe) {
216  parameterFNVYSe_m = parameterFNVYSe;
217  }
218 
219  inline void setBoundaryMatType (int BoundaryMatType) {
220  seBoundaryMatType_m = BoundaryMatType;
221  }
222 
223  inline void setEInitThreshold (double einitthreshold) {
224  eInitThreshold_m = 1.0e6 * einitthreshold;
225  }
226 
227  // return sey_0 in Vaughan's model
228  inline void setvSeyZero (double vSeyZero) {
229  vSeyZero_m = vSeyZero;
230  }
231 
232  // set the energy related to sey_0 in Vaughan's model
233  inline void setvEZero (double vEZero) {
234  vEzero_m = vEZero;
235  }
236 
237  // set sey max in Vaughan's model
238  inline void setvSeyMax (double vSeyMax) {
239  vSeyMax_m = vSeyMax;
240  }
241 
242  // return Emax in Vaughan's model
243  inline void setvEmax (double vEmax) {
244  vEmax_m = vEmax;
245  }
246 
247  // return fitting parameter denotes the roughness of surface for
248  // impact energy in Vaughan's model
249  inline void setvKenergy (double vKenergy) {
250  vKenergy_m = vKenergy;
251  }
252 
253  // return fitting parameter denotes the roughness of surface for impact
254  // angle in Vaughan's model
255  inline void setvKtheta (double vKtheta) {
256  vKtheta_m = vKtheta;
257  }
258 
259  // return thermal velocity Maxwellian distribution of secondaries
260  // in Vaughan's model
261  inline void setvVThermal (double vVThermal) {
262  vVThermal_m = vVThermal;
263  }
264 
265  inline void setVw (double ppVw) {
266  ppVw_m = ppVw;
267  }
268 
272  inline size_t getNumBFaces () {
273  return Triangles_m.size();
274  }
275 
279  inline Vector_t gethr () {
280  return voxelMesh_m.sizeOfVoxel;
281  }
285  inline Vektor<int, 3> getnr () {
286  return voxelMesh_m.nr_m;
287  }
288 
292  inline Vector_t getmincoords () {
293  return minExtent_m;
294  }
298  inline Vector_t getmaxcoords () {
299  return maxExtent_m;
300  }
301 
306  std::vector<Vector_t> TriBarycenters_m;
307 
312  std::vector<double> TriPrPartloss_m;
313 
318  std::vector<double> TriSePartloss_m;
319 
325  std::vector<double> TriFEPartloss_m;
326 
331  std::vector<short> TriBGphysicstag_m;
332 
333  inline bool isOutsideApperture(Vector_t x) {
334  if (hasApperture()) {
335  for (size_t i = 0; i < apert_m.size(); i += 3) {
336  if ((apert_m[i] <= x(2)) && (x(2) < apert_m[i+1])) {
337  // yes we are inside the interval
338  const double r = apert_m[i+2] * apert_m[i+2];
339  return ((x(0)*x(0)) + (x(1)*x(1))) > r;
340  }
341  }
342  }
343  return false;
344  }
345 
347  const Vector_t& P,
348  const Vector_t& v,
349  Vector_t& I);
350 
351  int fastIsInside (
352  const Vector_t& reference_pt, // [in] a reference point
353  const Vector_t& P // [in] point to test
354  );
355 
356  enum DebugFlags {
357  debug_isInside = 0x0001,
363  };
364 
365  inline void enableDebug(enum DebugFlags flags) {
366  debugFlags_m |= flags;
367  }
368 
369  inline void disableDebug(enum DebugFlags flags) {
370  debugFlags_m &= ~flags;
371  }
372 
373 private:
375  const int triangle_id,
376  const int i,
377  const int j,
378  const int k);
379 
381  const Vector_t&,
382  const Vector_t&,
383  Vector_t&,
384  int&
385  );
386 
388  const Vector_t& P0,
389  const Vector_t& P1,
390  Vector_t& intersection_pt,
391  int& triangle_id
392  );
393 
394  std::string h5FileName_m; // H5hut filename
395 
396  std::vector<Vector_t> Points_m; // geometry point coordinates
397  std::vector<std::array<unsigned int,4>> Triangles_m; // boundary faces defined via point IDs
398  // please note: 4 is correct, historical reasons!
399 
400  std::vector<Vector_t> TriNormals_m; // oriented normal vector of triangles
401  std::vector<double> TriAreas_m; // area of triangles
402 
403  Vector_t minExtent_m; // minimum of geometry coordinate.
404  Vector_t maxExtent_m; // maximum of geometry coordinate.
405 
406  struct {
410  Vektor<int, 3> nr_m; // number of intervals of geometry in X,Y,Z direction
411  std::unordered_map<int, // map voxel IDs ->
412  std::unordered_set<int>> ids; // intersecting triangles
413 
414  } voxelMesh_m;
415 
417 
418  std::vector<Vector_t> partsp_m; // particle momenta
419  std::vector<Vector_t> partsr_m; // particle positions
420 
421  /*
422  An additional structure to hold apperture information
423  to prevent that particles go past the geometry. The user
424  can specify n trippel with the form: (zmin, zmax, r)
425  */
426  std::vector<double> apert_m;
427 
429 
432 
433  // Vaughan's model
434  double vSeyZero_m; // energy related to sey_
435  double vEzero_m; // sey_0
436  double vSeyMax_m; // sey max
437  double vEmax_m; // Emax
438  double vKenergy_m; // roughness of surface for impact energy
439  double vKtheta_m; // roughness of surface for impact angle
440  double vVThermal_m; // thermal velocity of Maxwellian distribution of secondaries
441 
442  double ppVw_m; // velocity scalar for Parallel plate benchmark.
443  int seBoundaryMatType_m; // user defined material type for secondary emission model.
444 
445  // Fowler-Nordheim model
446  double workFunction_m; // work function
447  double fieldEnhancement_m; // field factor
448  size_t maxFNemission_m; // maximum emitted number per triangle
449  double fieldFNthreshold_m; // lower threshold electric field
450  double parameterFNA_m; // parameter A. Default: \f$1.54\times 10^{-6}\f$.
451  double parameterFNB_m; // parameter B. Default: \f$6.83\times 10^9\f$.
452  double parameterFNY_m; // parameter Y. Default:\f$3.795\times 10^{-5}\f$.
453  double parameterFNVYZe_m; // zero order fit constant for v(y). Default:\f$0.9632\f$.
454  double parameterFNVYSe_m; // second order fit constant for v(y). Default:\f$1.065\f$.
455 
456  gsl_rng *randGen_m; //
457 
458  IpplTimings::TimerRef Tinitialize_m; // initialize geometry
463 
465  void operator= (const BoundaryGeometry&);
466 
467  // Clone constructor.
468  BoundaryGeometry(const std::string& name, BoundaryGeometry* parent);
469 
470  inline bool hasApperture() {
471  return (apert_m.size() != 0);
472  }
473 
474  inline const Vector_t& getPoint (const int triangle_id, const int vertex_id) {
475  assert (1 <= vertex_id && vertex_id <=3);
476  return Points_m[Triangles_m[triangle_id][vertex_id]];
477  }
478 
483  };
484 
486  const enum INTERSECTION_TESTS kind,
487  const Vector_t& P0,
488  const Vector_t& P1,
489  const int triangle_id,
490  Vector_t& I);
491 
492  inline int mapVoxelIndices2ID (const int i, const int j, const int k);
493  inline Vector_t mapIndices2Voxel (const int, const int, const int);
494  inline Vector_t mapPoint2Voxel (const Vector_t&);
495  inline void computeMeshVoxelization (void);
496 
497  enum {
498  FGEOM, // file holding the geometry
499  LENGTH, // length of elliptic tube or boxcorner
500  S, // start of the geometry
501  L1, // in case of BOXCORNER first part of geometry with hight B
502  L2, // in case of BOXCORNER second part of geometry with hight B-C
503  A, // major semi-axis of elliptic tube
504  B, // minor semi-axis of ellitpic tube
505  C, // in case of BOXCORNER hight of corner
506  TOPO, // BOX, BOXCORNER, ELLIPTIC if FGEOM is selected topo is over-written
507  DISTR, // Add distribution to generate physics model on the surface
508  DISTRS, // Add distribution array to generate physics model on the surface
509  ZSHIFT, // Shift in z direction
510  XYZSCALE, // Multiplicative scaling factor for coordinates
511  XSCALE, // Multiplicative scaling factor for x-coordinates
512  YSCALE, // Multiplicative scaling factor for y-coordinates
513  ZSCALE, // Multiplicative scaling factor for z-coordinates
514  APERTURE, // in addition to the geometry
516  };
517 };
518 
519 inline Inform &operator<< (Inform& os, const BoundaryGeometry& b) {
520  return b.printInfo (os);
521 }
522 #endif
523 // vi: set et ts=4 sw=4 sts=4:
524 // Local Variables:
525 // mode:c
526 // c-basic-offset: 4
527 // indent-tabs-mode:nil
528 // End:
Vektor< int, 3 > nr_m
void setFNParameterY(double parameterFNY)
std::vector< double > TriFEPartloss_m
std::ostream & operator<<(std::ostream &os, const Attribute &attr)
Definition: Attribute.cpp:167
void setVw(double ppVw)
Interface for basic beam line object.
Definition: ElementBase.h:128
The base class for all OPAL definitions.
Definition: Definition.h:30
std::vector< Vector_t > partsr_m
int intersectLineSegmentBoundary(const Vector_t &P0, const Vector_t &P1, Vector_t &intersection_pt, int &triangle_id)
std::unordered_map< int, std::unordered_set< int > > ids
IpplTimings::TimerRef TfastIsInside_m
void writeGeomToVtk(std::string fn)
Vector_t getCooridinate(size_t i)
int intersectLineTriangle(const enum INTERSECTION_TESTS kind, const Vector_t &P0, const Vector_t &P1, const int triangle_id, Vector_t &I)
IpplTimings::TimerRef TisInside_m
void setvVThermal(double vVThermal)
Inform * gmsg
Definition: Main.cpp:21
std::vector< double > apert_m
SecondaryEmissionPhysics sec_phys_m
void setMaxFN(size_t maxFNemission)
void createParticlesOnSurface(size_t n, double darkinward, OpalBeamline &itsOpalBeamline, PartBunchBase< double, 3 > *itsBunch)
void setEInitThreshold(double einitthreshold)
void setWorkFunction(double workFunction)
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
std::vector< Vector_t > Points_m
void setFNParameterB(double parameterFNB)
virtual void execute()
Execute the command.
std::vector< Vector_t > TriNormals_m
std::vector< double > TriAreas_m
void setFNParameterA(double parameterFNA)
std::vector< std::array< unsigned int, 4 > > Triangles_m
std::vector< short > TriBGphysicstag_m
std::string getDistribution()
int emitSecondaryFurmanPivi(const Vector_t &intecoords, const int i, PartBunchBase< double, 3 > *itsBunch, double &seyNum)
struct BoundaryGeometry::@91 voxelMesh_m
int intersectTinyLineSegmentBoundary(const Vector_t &, const Vector_t &, Vector_t &, int &)
void updateElement(ElementBase *element)
void createPriPart(size_t n, double darkinward, OpalBeamline &itsOpalBeamline, PartBunchBase< double, 3 > *itsBunch)
Vector_t getmaxcoords()
int emitSecondaryNone(const Vector_t &intecoords, const int &triId)
IpplTimings::TimerRef Tinitialize_m
int partInside(const Vector_t &r, const Vector_t &v, const double dt, int Parttype, const double Qloss, Vector_t &intecoords, int &triId)
std::vector< std::string > getStringArray(const Attribute &attr)
Get string array value.
Definition: Attributes.cpp:378
Vector_t mapIndices2Voxel(const int, const int, const int)
Vector_t getmincoords()
static BoundaryGeometry * find(const std::string &name)
std::vector< double > TriSePartloss_m
bool isOutsideApperture(Vector_t x)
Vector_t getMomenta(size_t i)
std::vector< std::string > getDistributionArray()
IpplTimings::TimerRef TRayTrace_m
std::vector< double > TriPrPartloss_m
void setvSeyMax(double vSeyMax)
IpplTimings::TimerRef TPartInside_m
std::string h5FileName_m
int fastIsInside(const Vector_t &reference_pt, const Vector_t &P)
void setvKtheta(double vKtheta)
std::vector< Vector_t > partsp_m
int emitSecondaryVaughan(const Vector_t &intecoords, const int i, PartBunchBase< double, 3 > *itsBunch, double &seyNum)
void setBoundaryMatType(int BoundaryMatType)
std::string getFilename() const
Vector_t mapPoint2Voxel(const Vector_t &)
The base class for all OPAL objects.
Definition: Object.h:48
void enableDebug(enum DebugFlags flags)
const std::string name
int intersectTriangleVoxel(const int triangle_id, const int i, const int j, const int k)
void setFNParameterVYSe(double parameterFNVYSe)
Inform & printInfo(Inform &os) const
void computeMeshVoxelization(void)
std::vector< Vector_t > TriBarycenters_m
void setvEZero(double vEZero)
void setNEmissionMode(bool nEmissionMode)
Timing::TimerRef TimerRef
Definition: IpplTimings.h:176
void setvSeyZero(double vSeyZero)
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
void setvKenergy(double vKenergy)
void setvEmax(double vEmax)
Definition: Inform.h:41
virtual void update()
Update this object.
void disableDebug(enum DebugFlags flags)
int mapVoxelIndices2ID(const int i, const int j, const int k)
void setFNParameterVYZe(double parameterFNVYZe)
virtual bool canReplaceBy(Object *object)
Test if replacement is allowed.
void operator=(const BoundaryGeometry &)
virtual BoundaryGeometry * clone(const std::string &name)
Return a clone.
const Vector_t & getPoint(const int triangle_id, const int vertex_id)
std::string getTopology() const
void setFNTreshold(double fieldFNthreshold)
int intersectRayBoundary(const Vector_t &P, const Vector_t &v, Vector_t &I)
Vektor< int, 3 > getnr()
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307
void setFieldEnhancement(double fieldEnhancement)