OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
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
32
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 { RECTANGULAR, BOXCORNER, ELLIPTIC };
53
55public:
57 virtual ~BoundaryGeometry();
58
59 virtual bool canReplaceBy(Object* object);
60
61 virtual BoundaryGeometry* clone(const std::string& name);
62
63 // Check the GEOMETRY data.
64 virtual void execute();
65
66 // Find named GEOMETRY.
67 static BoundaryGeometry* find(const std::string& name);
68
69 // Update the GEOMETRY data.
70 virtual void update();
71
72 void updateElement(ElementBase* element);
73
74 void initialize();
75
76 int partInside(
77 const Vector_t<double, 3>& r, const Vector_t<double, 3>& v, const double dt,
78 Vector_t<double, 3>& intecoords, int& triId);
79
80 Inform& printInfo(Inform& os) const;
81
82 void writeGeomToVtk(std::string fn);
83
84 inline std::string getFilename() const {
86 }
87
88 inline Topology getTopology() const {
89 static const std::unordered_map<std::string, Topology> stringTopology_s = {
90 {"RECTANGULAR", Topology::RECTANGULAR},
91 {"BOXCORNER", Topology::BOXCORNER},
92 {"ELLIPTIC", Topology::ELLIPTIC}};
93 Topology topo = stringTopology_s.at(Attributes::getString(itsAttr[TOPO]));
94 return topo;
95 }
96
97 inline double getA() {
98 return (double)Attributes::getReal(itsAttr[A]);
99 }
100
101 inline double getB() {
102 return (double)Attributes::getReal(itsAttr[B]);
103 }
104
105 inline double getC() {
106 return (double)Attributes::getReal(itsAttr[C]);
107 }
108
109 inline double getS() {
110 return (double)Attributes::getReal(itsAttr[S]);
111 }
112
113 inline double getLength() {
114 return (double)Attributes::getReal(itsAttr[LENGTH]);
115 }
116
117 inline double getL1() {
118 return (double)Attributes::getReal(itsAttr[L1]);
119 }
120
121 inline double getL2() {
122 return (double)Attributes::getReal(itsAttr[L2]);
123 }
124
128 inline size_t getNumBFaces() {
129 return Triangles_m.size();
130 }
131
136 return voxelMesh_m.sizeOfVoxel;
137 }
138
142 return voxelMesh_m.nr_m;
143 }
144
149 return minExtent_m;
150 }
151
155 return maxExtent_m;
156 }
157
159 if (haveInsidePoint_m == false) {
160 return false;
161 }
162 pt = insidePoint_m;
163 return true;
164 }
165
166 bool findInsidePoint(void);
167
170
171 int fastIsInside(
172 const Vector_t<double, 3>& reference_pt, // [in] a reference point
173 const Vector_t<double, 3>& P // [in] point to test
174 );
175
184
185 inline void enableDebug(enum DebugFlags flags) {
186 debugFlags_m |= flags;
187 }
188
189 inline void disableDebug(enum DebugFlags flags) {
190 debugFlags_m &= ~flags;
191 }
192
193private:
194 bool isInside(const Vector_t<double, 3>& P // [in] point to test
195 );
196
197 int intersectTriangleVoxel(const int triangle_id, const int i, const int j, const int k);
198
201
203 const Vector_t<double, 3>& P0, const Vector_t<double, 3>& P1,
204 Vector_t<double, 3>& intersection_pt, int& triangle_id);
205
206 std::string h5FileName_m; // H5hut filename
207
208 std::vector<Vector_t<double, 3>> Points_m; // geometry point coordinates
209 std::vector<std::array<unsigned int, 4>>
210 Triangles_m; // boundary faces defined via point IDs
211 // please note: 4 is correct, historical reasons!
212
213 std::vector<Vector_t<double, 3>> TriNormals_m; // oriented normal vector of triangles
214 std::vector<double> TriAreas_m; // area of triangles
215
216 Vector_t<double, 3> minExtent_m; // minimum of geometry coordinate.
217 Vector_t<double, 3> maxExtent_m; // maximum of geometry coordinate.
218
219 struct {
220 Vector_t<double, 3> minExtent;
221 Vector_t<double, 3> maxExtent;
222 Vector_t<double, 3> sizeOfVoxel;
223 Vector_t<int, 3> nr_m; // number of intervals of geometry in X,Y,Z direction
224 std::unordered_map<
225 int, // map voxel IDs ->
226 std::unordered_set<int>>
227 ids; // intersecting triangles
228
230
232
234 Vector_t<double, 3> insidePoint_m; // attribute INSIDEPOINT
235
236 gsl_rng* randGen_m; //
237
238 IpplTimings::TimerRef Tinitialize_m; // initialize geometry
239 IpplTimings::TimerRef TisInside_m;
240 IpplTimings::TimerRef TfastIsInside_m;
241 IpplTimings::TimerRef TRayTrace_m; // ray tracing
242 IpplTimings::TimerRef TPartInside_m; // particle inside
243
246
247 // Clone constructor.
248 BoundaryGeometry(const std::string& name, BoundaryGeometry* parent);
249
250 inline const Vector_t<double, 3>& getPoint(const int triangle_id, const int vertex_id) {
251 PAssert(1 <= vertex_id && vertex_id <= 3);
252 return Points_m[Triangles_m[triangle_id][vertex_id]];
253 }
254
256
258 const enum INTERSECTION_TESTS kind, const Vector_t<double, 3>& P0,
259 const Vector_t<double, 3>& P1, const int triangle_id, Vector_t<double, 3>& I);
260
261 inline int mapVoxelIndices2ID(const int i, const int j, const int k);
262 inline Vector_t<double, 3> mapIndices2Voxel(const int, const int, const int);
264 inline void computeMeshVoxelization(void);
265
266 enum {
267 FGEOM, // file holding the geometry
268 LENGTH, // length of elliptic tube or boxcorner
269 S, // start of the geometry
270 L1, // in case of BOXCORNER first part of geometry with height B
271 L2, // in case of BOXCORNER second part of geometry with height B-C
272 A, // major semi-axis of elliptic tube
273 B, // minor semi-axis of ellitpic tube
274 C, // in case of BOXCORNER height of corner
275 TOPO, // RECTANGULAR, BOXCORNER, ELLIPTIC if FGEOM is selected TOPO is over-written
276 ZSHIFT, // Shift in z direction
277 XYZSCALE, // Multiplicative scaling factor for coordinates
278 XSCALE, // Multiplicative scaling factor for x-coordinates
279 YSCALE, // Multiplicative scaling factor for y-coordinates
280 ZSCALE, // Multiplicative scaling factor for z-coordinates
283 };
284};
285
286inline Inform& operator<<(Inform& os, const BoundaryGeometry& b) {
287 return b.printInfo(os);
288}
289#endif
ippl::Vector< T, Dim > Vector_t
Inform & operator<<(Inform &os, const BoundaryGeometry &b)
double getReal(const Attribute &attr)
Return real value.
std::string getString(const Attribute &attr)
Get string value.
Definition(int size, const char *name, const char *help)
Constructor for exemplars.
Object(int size, const char *name, const char *help)
Constructor for exemplars.
Definition Object.cpp:354
std::vector< Attribute > itsAttr
The object attributes.
Definition Object.h:216
IpplTimings::TimerRef TisInside_m
int fastIsInside(const Vector_t< double, 3 > &reference_pt, const Vector_t< double, 3 > &P)
Vector_t< double, 3 > mapIndices2Voxel(const int, const int, const int)
BoundaryGeometry(const BoundaryGeometry &)
std::vector< double > TriAreas_m
virtual void execute()
Execute the command.
virtual void update()
Update this object.
IpplTimings::TimerRef TRayTrace_m
struct BoundaryGeometry::@117056140100230112133004050263065356254101277345 voxelMesh_m
virtual bool canReplaceBy(Object *object)
Test if replacement is allowed.
Vector_t< double, 3 > maxExtent_m
Vector_t< double, 3 > gethr()
const Vector_t< double, 3 > & getPoint(const int triangle_id, const int vertex_id)
std::vector< std::array< unsigned int, 4 > > Triangles_m
std::string h5FileName_m
bool getInsidePoint(Vector_t< double, 3 > &pt)
void operator=(const BoundaryGeometry &)
Vector_t< double, 3 > getmaxcoords()
int intersectLineTriangle(const enum INTERSECTION_TESTS kind, const Vector_t< double, 3 > &P0, const Vector_t< double, 3 > &P1, const int triangle_id, Vector_t< double, 3 > &I)
static BoundaryGeometry * find(const std::string &name)
IpplTimings::TimerRef Tinitialize_m
int mapVoxelIndices2ID(const int i, const int j, const int k)
void disableDebug(enum DebugFlags flags)
int intersectRayBoundary(const Vector_t< double, 3 > &P, const Vector_t< double, 3 > &v, Vector_t< double, 3 > &I)
IpplTimings::TimerRef TPartInside_m
IpplTimings::TimerRef TfastIsInside_m
int intersectTriangleVoxel(const int triangle_id, const int i, const int j, const int k)
void enableDebug(enum DebugFlags flags)
int intersectLineSegmentBoundary(const Vector_t< double, 3 > &P0, const Vector_t< double, 3 > &P1, Vector_t< double, 3 > &intersection_pt, int &triangle_id)
Vector_t< double, 3 > insidePoint_m
int partInside(const Vector_t< double, 3 > &r, const Vector_t< double, 3 > &v, const double dt, Vector_t< double, 3 > &intecoords, int &triId)
int intersectTinyLineSegmentBoundary(const Vector_t< double, 3 > &, const Vector_t< double, 3 > &, Vector_t< double, 3 > &, int &)
void writeGeomToVtk(std::string fn)
Vector_t< int, 3 > getnr()
Vector_t< double, 3 > getmincoords()
virtual BoundaryGeometry * clone(const std::string &name)
Return a clone.
bool isInside(const Vector_t< double, 3 > &P)
Topology getTopology() const
Inform & printInfo(Inform &os) const
Vector_t< double, 3 > mapPoint2Voxel(const Vector_t< double, 3 > &)
void computeMeshVoxelization(void)
std::vector< Vector_t< double, 3 > > TriNormals_m
std::vector< Vector_t< double, 3 > > Points_m
Vector_t< double, 3 > minExtent_m
void updateElement(ElementBase *element)
std::string getFilename() const