OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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 "Utilities/Random.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 { return Attributes::getString(itsAttr[FGEOM]); }
85
86 inline Topology getTopology() const {
87 static const std::unordered_map<std::string, Topology> stringTopology_s = {
88 {"RECTANGULAR", Topology::RECTANGULAR},
89 {"BOXCORNER", Topology::BOXCORNER},
90 {"ELLIPTIC", Topology::ELLIPTIC}};
91 Topology topo = stringTopology_s.at(Attributes::getString(itsAttr[TOPO]));
92 return topo;
93 }
94
95 inline double getA() { return (double)Attributes::getReal(itsAttr[A]); }
96
97 inline double getB() { return (double)Attributes::getReal(itsAttr[B]); }
98
99 inline double getC() { return (double)Attributes::getReal(itsAttr[C]); }
100
101 inline double getS() { return (double)Attributes::getReal(itsAttr[S]); }
102
103 inline double getLength() { return (double)Attributes::getReal(itsAttr[LENGTH]); }
104
105 inline double getL1() { return (double)Attributes::getReal(itsAttr[L1]); }
106
107 inline double getL2() { return (double)Attributes::getReal(itsAttr[L2]); }
108
112 inline size_t getNumBFaces() { return Triangles_m.size(); }
113
117 inline Vector_t<double, 3> gethr() { return voxelMesh_m.sizeOfVoxel; }
121 inline Vector_t<int, 3> getnr() { return voxelMesh_m.nr_m; }
122
131
133 if (haveInsidePoint_m == false) {
134 return false;
135 }
136 pt = insidePoint_m;
137 return true;
138 }
139
140 bool findInsidePoint(void);
141
144
145 int fastIsInside(
146 const Vector_t<double, 3>& reference_pt, // [in] a reference point
147 const Vector_t<double, 3>& P // [in] point to test
148 );
149
158
159 inline void enableDebug(enum DebugFlags flags) { debugFlags_m |= flags; }
160
161 inline void disableDebug(enum DebugFlags flags) { debugFlags_m &= ~flags; }
162
163private:
164 bool isInside(
165 const Vector_t<double, 3>& P // [in] point to test
166 );
167
168 int intersectTriangleVoxel(const int triangle_id, const int i, const int j, const int k);
169
172
174 const Vector_t<double, 3>& P0, const Vector_t<double, 3>& P1,
175 Vector_t<double, 3>& intersection_pt, int& triangle_id);
176
177 std::string h5FileName_m; // H5hut filename
178
179 std::vector<Vector_t<double, 3>> Points_m; // geometry point coordinates
180 std::vector<std::array<unsigned int, 4>>
181 Triangles_m; // boundary faces defined via point IDs
182 // please note: 4 is correct, historical reasons!
183
184 std::vector<Vector_t<double, 3>> TriNormals_m; // oriented normal vector of triangles
185 std::vector<double> TriAreas_m; // area of triangles
186
187 Vector_t<double, 3> minExtent_m; // minimum of geometry coordinate.
188 Vector_t<double, 3> maxExtent_m; // maximum of geometry coordinate.
189
190 struct {
191 Vector_t<double, 3> minExtent;
192 Vector_t<double, 3> maxExtent;
193 Vector_t<double, 3> sizeOfVoxel;
194 Vector_t<int, 3> nr_m; // number of intervals of geometry in X,Y,Z direction
195 std::unordered_map<
196 int, // map voxel IDs ->
197 std::unordered_set<int>>
198 ids; // intersecting triangles
199
201
203
205 Vector_t<double, 3> insidePoint_m; // attribute INSIDEPOINT
206
208
209 IpplTimings::TimerRef Tinitialize_m; // initialize geometry
210 IpplTimings::TimerRef TisInside_m;
211 IpplTimings::TimerRef TfastIsInside_m;
212 IpplTimings::TimerRef TRayTrace_m; // ray tracing
213 IpplTimings::TimerRef TPartInside_m; // particle inside
214
217
218 // Clone constructor.
219 BoundaryGeometry(const std::string& name, BoundaryGeometry* parent);
220
221 inline const Vector_t<double, 3>& getPoint(const int triangle_id, const int vertex_id) {
222 PAssert(1 <= vertex_id && vertex_id <= 3);
223 return Points_m[Triangles_m[triangle_id][vertex_id]];
224 }
225
227
229 const enum INTERSECTION_TESTS kind, const Vector_t<double, 3>& P0,
230 const Vector_t<double, 3>& P1, const int triangle_id, Vector_t<double, 3>& I);
231
232 inline int mapVoxelIndices2ID(const int i, const int j, const int k);
233 inline Vector_t<double, 3> mapIndices2Voxel(const int, const int, const int);
235 inline void computeMeshVoxelization(void);
236
237 enum {
238 FGEOM, // file holding the geometry
239 LENGTH, // length of elliptic tube or boxcorner
240 S, // start of the geometry
241 L1, // in case of BOXCORNER first part of geometry with height B
242 L2, // in case of BOXCORNER second part of geometry with height B-C
243 A, // major semi-axis of elliptic tube
244 B, // minor semi-axis of ellitpic tube
245 C, // in case of BOXCORNER height of corner
246 TOPO, // RECTANGULAR, BOXCORNER, ELLIPTIC if FGEOM is selected TOPO is over-written
247 ZSHIFT, // Shift in z direction
248 XYZSCALE, // Multiplicative scaling factor for coordinates
249 XSCALE, // Multiplicative scaling factor for x-coordinates
250 YSCALE, // Multiplicative scaling factor for y-coordinates
251 ZSCALE, // Multiplicative scaling factor for z-coordinates
253 SIZE
254 };
255};
256
257inline Inform& operator<<(Inform& os, const BoundaryGeometry& b) { return b.printInfo(os); }
258#endif
Inform & operator<<(Inform &os, const BoundaryGeometry &b)
ippl::Vector< T, Dim > Vector_t
struct BoundaryGeometry::@33 voxelMesh_m
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
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
The base class for all OPAL definitions.
Definition Definition.h:29
The base class for all OPAL objects.
Definition Object.h:45
std::vector< Attribute > itsAttr
The object attributes.
Definition Object.h:210
double getReal(const Attribute &attr)
Return real value.
std::string getString(const Attribute &attr)
Get string value.