OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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
36class OpalBeamline;
37class ElementBase;
38
41#include "Utilities/Util.h"
42#include "Utility/IpplTimings.h"
43#include "Utility/PAssert.h"
44
45#include <gsl/gsl_rng.h>
46
47#include <array>
48#include <unordered_map>
49#include <unordered_set>
50#include <vector>
51
52enum class Topology: unsigned short {
56};
57
59
60public:
62 virtual ~BoundaryGeometry();
63
64 virtual bool canReplaceBy (
65 Object* object);
66
67 virtual BoundaryGeometry* clone (
68 const std::string& name);
69
70 // Check the GEOMETRY data.
71 virtual void execute ();
72
73 // Find named GEOMETRY.
74 static BoundaryGeometry* find (
75 const std::string& name);
76
77 // Update the GEOMETRY data.
78 virtual void update ();
79
80 void updateElement (
81 ElementBase* element);
82
83 void initialize ();
84
85 int partInside (
86 const Vector_t& r,
87 const Vector_t& v,
88 const double dt,
89 Vector_t& intecoords,
90 int& triId);
91
93 Inform& os) const;
94
95 void writeGeomToVtk (std::string fn);
96
97 inline std::string getFilename() const {
99 }
100
101 inline Topology getTopology() const {
102 static const std::unordered_map<std::string, Topology> stringTopology_s = {
103 {"RECTANGULAR", Topology::RECTANGULAR},
104 {"BOXCORNER", Topology::BOXCORNER},
105 {"ELLIPTIC", Topology::ELLIPTIC}
106 };
107 Topology topo = stringTopology_s.at(Attributes::getString(itsAttr[TOPO]));
108 return topo;
109 }
110
111 inline double getA() {
112 return (double)Attributes::getReal(itsAttr[A]);
113 }
114
115 inline double getB() {
116 return (double)Attributes::getReal(itsAttr[B]);
117 }
118
119 inline double getC() {
120 return (double)Attributes::getReal(itsAttr[C]);
121 }
122
123 inline double getS() {
124 return (double)Attributes::getReal(itsAttr[S]);
125 }
126
127 inline double getLength() {
128 return (double)Attributes::getReal(itsAttr[LENGTH]);
129 }
130
131 inline double getL1() {
132 return (double)Attributes::getReal(itsAttr[L1]);
133 }
134
135 inline double getL2() {
136 return (double)Attributes::getReal(itsAttr[L2]);
137 }
138
142 inline size_t getNumBFaces () {
143 return Triangles_m.size();
144 }
145
149 inline Vector_t gethr () {
150 return voxelMesh_m.sizeOfVoxel;
151 }
156 return voxelMesh_m.nr_m;
157 }
158
163 return minExtent_m;
164 }
169 return maxExtent_m;
170 }
171
172 inline bool getInsidePoint (Vector_t& pt) {
173 if (haveInsidePoint_m == false) {
174 return false;
175 }
176 pt = insidePoint_m;
177 return true;
178 }
179
180 bool findInsidePoint (void);
181
183 const Vector_t& P,
184 const Vector_t& v,
185 Vector_t& I);
186
187 int fastIsInside (
188 const Vector_t& reference_pt, // [in] a reference point
189 const Vector_t& P // [in] point to test
190 );
191
199 };
200
201 inline void enableDebug(enum DebugFlags flags) {
202 debugFlags_m |= flags;
203 }
204
205 inline void disableDebug(enum DebugFlags flags) {
206 debugFlags_m &= ~flags;
207 }
208
209private:
210 bool isInside (
211 const Vector_t& P // [in] point to test
212 );
213
215 const int triangle_id,
216 const int i,
217 const int j,
218 const int k);
219
221 const Vector_t&,
222 const Vector_t&,
223 Vector_t&,
224 int&
225 );
226
228 const Vector_t& P0,
229 const Vector_t& P1,
230 Vector_t& intersection_pt,
231 int& triangle_id
232 );
233
234 std::string h5FileName_m; // H5hut filename
235
236 std::vector<Vector_t> Points_m; // geometry point coordinates
237 std::vector<std::array<unsigned int,4>> Triangles_m; // boundary faces defined via point IDs
238 // please note: 4 is correct, historical reasons!
239
240 std::vector<Vector_t> TriNormals_m; // oriented normal vector of triangles
241 std::vector<double> TriAreas_m; // area of triangles
242
243 Vector_t minExtent_m; // minimum of geometry coordinate.
244 Vector_t maxExtent_m; // maximum of geometry coordinate.
245
246 struct {
250 Vektor<int, 3> nr_m; // number of intervals of geometry in X,Y,Z direction
251 std::unordered_map<int, // map voxel IDs ->
252 std::unordered_set<int>> ids; // intersecting triangles
253
255
257
259 Vector_t insidePoint_m; // attribute INSIDEPOINT
260
261 gsl_rng *randGen_m; //
262
263 IpplTimings::TimerRef Tinitialize_m; // initialize geometry
268
271
272 // Clone constructor.
273 BoundaryGeometry(const std::string& name, BoundaryGeometry* parent);
274
275 inline const Vector_t& getPoint (const int triangle_id, const int vertex_id) {
276 PAssert (1 <= vertex_id && vertex_id <=3);
277 return Points_m[Triangles_m[triangle_id][vertex_id]];
278 }
279
283 LINE
284 };
285
287 const enum INTERSECTION_TESTS kind,
288 const Vector_t& P0,
289 const Vector_t& P1,
290 const int triangle_id,
291 Vector_t& I);
292
293 inline int mapVoxelIndices2ID (const int i, const int j, const int k);
294 inline Vector_t mapIndices2Voxel (const int, const int, const int);
295 inline Vector_t mapPoint2Voxel (const Vector_t&);
296 inline void computeMeshVoxelization (void);
297
298 enum {
299 FGEOM, // file holding the geometry
300 LENGTH, // length of elliptic tube or boxcorner
301 S, // start of the geometry
302 L1, // in case of BOXCORNER first part of geometry with height B
303 L2, // in case of BOXCORNER second part of geometry with height B-C
304 A, // major semi-axis of elliptic tube
305 B, // minor semi-axis of ellitpic tube
306 C, // in case of BOXCORNER height of corner
307 TOPO, // RECTANGULAR, BOXCORNER, ELLIPTIC if FGEOM is selected TOPO is over-written
308 ZSHIFT, // Shift in z direction
309 XYZSCALE, // Multiplicative scaling factor for coordinates
310 XSCALE, // Multiplicative scaling factor for x-coordinates
311 YSCALE, // Multiplicative scaling factor for y-coordinates
312 ZSCALE, // Multiplicative scaling factor for z-coordinates
314 SIZE
315 };
316};
317
319 return b.printInfo (os);
320}
321#endif
Topology
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
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
Vektor< int, 3 > getnr()
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
struct BoundaryGeometry::@70 voxelMesh_m
virtual void execute()
Execute the command.
const Vector_t & getPoint(const int triangle_id, const int vertex_id)
virtual void update()
Update this object.
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 &)
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 &)
virtual BoundaryGeometry * clone(const std::string &name)
Return a clone.
Topology getTopology() const
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