OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
BoundaryGeometry.h
Go to the documentation of this file.
1 //
2 // Implementation of the BoundaryGeometry class
3 //
4 // Copyright (c) 200x - 2020, Achim Gsell,
5 // 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 
33 #ifndef _OPAL_BOUNDARY_GEOMETRY_H
34 #define _OPAL_BOUNDARY_GEOMETRY_H
35 
36 class OpalBeamline;
37 class ElementBase;
38 
39 #include <unordered_map>
40 #include <unordered_set>
41 #include <array>
42 #include <vector>
43 
45 #include "Attributes/Attributes.h"
46 #include "Utilities/Util.h"
47 #include "Utility/IpplTimings.h"
48 #include "Utility/PAssert.h"
49 
50 #include <gsl/gsl_rng.h>
51 
52 class BoundaryGeometry : public Definition {
53 
54 public:
56  virtual ~BoundaryGeometry();
57 
58  virtual bool canReplaceBy (
59  Object* object);
60 
61  virtual BoundaryGeometry* clone (
62  const std::string& name);
63 
64  // Check the GEOMETRY data.
65  virtual void execute ();
66 
67  // Find named GEOMETRY.
68  static BoundaryGeometry* find (
69  const std::string& name);
70 
71  // Update the GEOMETRY data.
72  virtual void update ();
73 
74  void updateElement (
75  ElementBase* element);
76 
77  void initialize ();
78 
79  int partInside (
80  const Vector_t& r,
81  const Vector_t& v,
82  const double dt,
83  Vector_t& intecoords,
84  int& triId);
85 
86  Inform& printInfo (
87  Inform& os) const;
88 
89  void writeGeomToVtk (std::string fn);
90 
91  inline std::string getFilename() const {
93  }
94 
95  inline std::string getTopology() const {
97  }
98 
99  inline double getA() {
100  return (double)Attributes::getReal(itsAttr[A]);
101  }
102 
103  inline double getB() {
104  return (double)Attributes::getReal(itsAttr[B]);
105  }
106 
107  inline double getC() {
108  return (double)Attributes::getReal(itsAttr[C]);
109  }
110 
111  inline double getS() {
112  return (double)Attributes::getReal(itsAttr[S]);
113  }
114 
115  inline double getLength() {
116  return (double)Attributes::getReal(itsAttr[LENGTH]);
117  }
118 
119  inline double getL1() {
120  return (double)Attributes::getReal(itsAttr[L1]);
121  }
122 
123  inline double getL2() {
124  return (double)Attributes::getReal(itsAttr[L2]);
125  }
126 
130  inline size_t getNumBFaces () {
131  return Triangles_m.size();
132  }
133 
137  inline Vector_t gethr () {
138  return voxelMesh_m.sizeOfVoxel;
139  }
143  inline Vektor<int, 3> getnr () {
144  return voxelMesh_m.nr_m;
145  }
146 
150  inline Vector_t getmincoords () {
151  return minExtent_m;
152  }
156  inline Vector_t getmaxcoords () {
157  return maxExtent_m;
158  }
159 
160  inline bool getInsidePoint (Vector_t& pt) {
161  if (haveInsidePoint_m == false) {
162  return false;
163  }
164  pt = insidePoint_m;
165  return true;
166  }
167 
168  bool findInsidePoint (void);
169 
171  const Vector_t& P,
172  const Vector_t& v,
173  Vector_t& I);
174 
175  int fastIsInside (
176  const Vector_t& reference_pt, // [in] a reference point
177  const Vector_t& P // [in] point to test
178  );
179 
180  enum DebugFlags {
181  debug_isInside = 0x0001,
187  };
188 
189  inline void enableDebug(enum DebugFlags flags) {
190  debugFlags_m |= flags;
191  }
192 
193  inline void disableDebug(enum DebugFlags flags) {
194  debugFlags_m &= ~flags;
195  }
196 
197 private:
198  bool isInside (
199  const Vector_t& P // [in] point to test
200  );
201 
203  const int triangle_id,
204  const int i,
205  const int j,
206  const int k);
207 
209  const Vector_t&,
210  const Vector_t&,
211  Vector_t&,
212  int&
213  );
214 
216  const Vector_t& P0,
217  const Vector_t& P1,
218  Vector_t& intersection_pt,
219  int& triangle_id
220  );
221 
222  std::string h5FileName_m; // H5hut filename
223 
224  std::vector<Vector_t> Points_m; // geometry point coordinates
225  std::vector<std::array<unsigned int,4>> Triangles_m; // boundary faces defined via point IDs
226  // please note: 4 is correct, historical reasons!
227 
228  std::vector<Vector_t> TriNormals_m; // oriented normal vector of triangles
229  std::vector<double> TriAreas_m; // area of triangles
230 
231  Vector_t minExtent_m; // minimum of geometry coordinate.
232  Vector_t maxExtent_m; // maximum of geometry coordinate.
233 
234  struct {
238  Vektor<int, 3> nr_m; // number of intervals of geometry in X,Y,Z direction
239  std::unordered_map<int, // map voxel IDs ->
240  std::unordered_set<int>> ids; // intersecting triangles
241 
243 
245 
247  Vector_t insidePoint_m; // attribute INSIDEPOINT
248 
249  gsl_rng *randGen_m; //
250 
251  IpplTimings::TimerRef Tinitialize_m; // initialize geometry
256 
259 
260  // Clone constructor.
261  BoundaryGeometry(const std::string& name, BoundaryGeometry* parent);
262 
263  inline const Vector_t& getPoint (const int triangle_id, const int vertex_id) {
264  PAssert (1 <= vertex_id && vertex_id <=3);
265  return Points_m[Triangles_m[triangle_id][vertex_id]];
266  }
267 
271  LINE
272  };
273 
275  const enum INTERSECTION_TESTS kind,
276  const Vector_t& P0,
277  const Vector_t& P1,
278  const int triangle_id,
279  Vector_t& I);
280 
281  inline int mapVoxelIndices2ID (const int i, const int j, const int k);
282  inline Vector_t mapIndices2Voxel (const int, const int, const int);
283  inline Vector_t mapPoint2Voxel (const Vector_t&);
284  inline void computeMeshVoxelization (void);
285 
286  enum {
287  FGEOM, // file holding the geometry
288  LENGTH, // length of elliptic tube or boxcorner
289  S, // start of the geometry
290  L1, // in case of BOXCORNER first part of geometry with height B
291  L2, // in case of BOXCORNER second part of geometry with height B-C
292  A, // major semi-axis of elliptic tube
293  B, // minor semi-axis of ellitpic tube
294  C, // in case of BOXCORNER height of corner
295  TOPO, // RECTANGULAR, BOXCORNER, ELLIPTIC if FGEOM is selected TOPO is over-written
296  ZSHIFT, // Shift in z direction
297  XYZSCALE, // Multiplicative scaling factor for coordinates
298  XSCALE, // Multiplicative scaling factor for x-coordinates
299  YSCALE, // Multiplicative scaling factor for y-coordinates
300  ZSCALE, // Multiplicative scaling factor for z-coordinates
302  SIZE
303  };
304 };
305 
306 inline Inform &operator<< (Inform& os, const BoundaryGeometry& b) {
307  return b.printInfo (os);
308 }
309 #endif
Inform & operator<<(Inform &os, const BoundaryGeometry &b)
#define PAssert(c)
Definition: PAssert.h:102
const std::string name
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:252
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
std::string toUpper(const std::string &str)
Definition: Util.cpp:132
The base class for all OPAL definitions.
Definition: Definition.h:30
The base class for all OPAL objects.
Definition: Object.h:48
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
std::vector< std::array< unsigned int, 4 > > Triangles_m
IpplTimings::TimerRef TisInside_m
std::unordered_map< int, std::unordered_set< int > > ids
std::vector< Vector_t > TriNormals_m
int fastIsInside(const Vector_t &reference_pt, const Vector_t &P)
Vektor< int, 3 > nr_m
int intersectRayBoundary(const Vector_t &P, const Vector_t &v, Vector_t &I)
Vector_t getmincoords()
BoundaryGeometry(const BoundaryGeometry &)
std::vector< double > TriAreas_m
virtual void execute()
Execute the command.
virtual void update()
Update this object.
struct BoundaryGeometry::@69 voxelMesh_m
IpplTimings::TimerRef TRayTrace_m
virtual bool canReplaceBy(Object *object)
Test if replacement is allowed.
bool isInside(const Vector_t &P)
std::string h5FileName_m
std::vector< Vector_t > Points_m
void operator=(const BoundaryGeometry &)
Vector_t getmaxcoords()
static BoundaryGeometry * find(const std::string &name)
int intersectLineSegmentBoundary(const Vector_t &P0, const Vector_t &P1, Vector_t &intersection_pt, int &triangle_id)
IpplTimings::TimerRef Tinitialize_m
int mapVoxelIndices2ID(const int i, const int j, const int k)
void disableDebug(enum DebugFlags flags)
IpplTimings::TimerRef TPartInside_m
Vector_t mapPoint2Voxel(const Vector_t &)
std::string getTopology() const
IpplTimings::TimerRef TfastIsInside_m
bool getInsidePoint(Vector_t &pt)
int intersectTriangleVoxel(const int triangle_id, const int i, const int j, const int k)
void enableDebug(enum DebugFlags flags)
void writeGeomToVtk(std::string fn)
@ debug_intersectTinyLineSegmentBoundary
int partInside(const Vector_t &r, const Vector_t &v, const double dt, Vector_t &intecoords, int &triId)
int intersectTinyLineSegmentBoundary(const Vector_t &, const Vector_t &, Vector_t &, int &)
const Vector_t & getPoint(const int triangle_id, const int vertex_id)
Vektor< int, 3 > getnr()
virtual BoundaryGeometry * clone(const std::string &name)
Return a clone.
Inform & printInfo(Inform &os) const
Vector_t mapIndices2Voxel(const int, const int, const int)
int intersectLineTriangle(const enum INTERSECTION_TESTS kind, const Vector_t &P0, const Vector_t &P1, const int triangle_id, Vector_t &I)
void computeMeshVoxelization(void)
void updateElement(ElementBase *element)
std::string getFilename() const
Definition: Inform.h:42
Timing::TimerRef TimerRef
Definition: IpplTimings.h:176