criptic v1
Cosmic Ray Interstellar Propagation Tool using Itô Calculus
Loading...
Searching...
No Matches
Geometry.H
Go to the documentation of this file.
1
11#ifndef _GEOMETRY_H_
12#define _GEOMETRY_H_
13
14#include <algorithm>
15#include <cmath>
16#include <vector>
17#include "CRPacket.H"
18#include "../IO/ParmParser.H"
19#include "../Utils/RealBox.H"
20#include "../Utils/Types.H"
21#include "../Utils/Vec3.H"
22
23namespace criptic {
24
32 class Geometry {
33
34 public:
35
39 typedef enum {
40 openBC = 0,
44#ifdef TRACK_PITCH_ANGLE
45 , reflectingPitchAngleBC
46#endif
48
53 Geometry(const ParmParser &pp);
54
59 const RealBox& xBox() const { return box; }
60
65 const RealVec& xLo() const { return box.lo; }
66
71 const RealVec& xHi() const { return box.hi; }
72
77 const RealVec& xSize() const { return probSize; }
78
83 const Vec3<bcType>& bLo() const { return bcLo; }
84
89 const Vec3<bcType>& bHi() const { return bcHi; }
90
95 const BoolVec& isPeriodic() const { return periodicity; }
96
101 bool isAnyPeriodic() const { return hasPeriodicDim; }
102
107 bool isAnyOpen() const {
108 BoolVec lo = bcLo == openBC;
109 BoolVec hi = bcHi == openBC;
110 return max(lo, hi).max();
111 }
112
125#ifdef TRACK_PITCH_ANGLE
126 , CRPacket& pkt
127#endif
128 ) const {
129 for (int i = 0; i < 3; i++) {
130 if (periodicity[i]) {
131 while (x[i] < box.lo[i]) x[i] += probSize[i];
132 while (x[i] > box.hi[i]) x[i] += probSize[i];
133 } else if (bcLo[i] == reflectingBC && x[i] < box.lo[i]) {
134 x[i] += 2 * (box.lo[i] - x[i]);
135 } else if (bcHi[i] == reflectingBC && x[i] > box.hi[i]) {
136 x[i] -= 2 * (x[i] - box.hi[i]);
137 }
138#ifdef TRACK_PITCH_ANGLE
139 else if (bcLo[i] == reflectingPitchAngleBC && x[i] < box.lo[i]) {
140 x[i] += 2 * (box.lo[i] - x[i]);
141 pkt.mu = -pkt.mu;
142 } else if (bcHi[i] == reflectingPitchAngleBC && x[i] > box.hi[i]) {
143 x[i] -= 2 * (x[i] - box.hi[i]);
144 pkt.mu = -pkt.mu;
145 }
146#endif
147 }
148 }
149
166 const int i,
167 const bool recenter = false) const {
168 Real x_ = x;
169 if (periodicity[i]) {
170 while (x_ < box.lo[i]) x_ += probSize[i];
171 while (x_ > box.hi[i]) x_ -= probSize[i];
172 if (recenter) x_ -= (box.lo[i] + box.hi[i]) / 2.0;
173 }
174 return x_;
175 }
176
192 const bool recenter = false) const {
193 if (!hasPeriodicDim) return x;
194 RealVec x_ = x;
195 for (int i=0; i<3; i++) x_[i] = periodicLoop(x_[i], i, recenter);
196 return x_;
197 }
198
213 std::vector<RealBox> periodicLoopBox(const RealBox& b,
214 const bool recenter = false) const {
215 std::vector<RealBox> vrb;
216 RealBox rb;
217 rb.lo = periodicLoop(b.lo, recenter);
218 rb.hi = periodicLoop(b.hi, recenter);
219 for (int i=0; i<3; i++) {
220 if (rb.lo[i] > rb.hi[i]) {
221 RealBox rb1 = rb;
222 RealBox rb2 = rb;
223 if (recenter) {
224 rb1.hi[i] = probSize[i]/2;
225 rb2.lo[i] = -probSize[i]/2;
226 } else {
227 rb1.hi[i] = box.hi[i];
228 rb2.lo[i] = box.lo[i];
229 }
230 std::vector<RealBox> vrb1 = periodicLoopBox(rb1, recenter);
231 std::vector<RealBox> vrb2 = periodicLoopBox(rb2, recenter);
232 for (auto r : vrb1) vrb.push_back(r);
233 for (auto r : vrb2) vrb.push_back(r);
234 }
235 }
236 if (vrb.size() == 0) vrb.push_back(rb);
237 return vrb;
238 }
239
245 bool contains(const RealVec& x) const {
246 for (int i=0; i<3; i++) {
247 if (!periodicity[i] && (x[i] < box.lo[i] || x[i] > box.hi[i]))
248 return false;
249 }
250 return true;
251 }
252
264 RealVec disp(const RealVec& x1, const RealVec& x2) const {
265 return periodicLoop(x1 - x2, true);
266 }
267
279 Real dist(const RealVec& x1, const RealVec& x2) const {
280 return disp(x1, x2).mag();
281 }
282
297 const RealVec& boxLo,
298 const RealVec& boxHi) const {
299 Real d2 = 0.0;
300 for (int i=0; i<3; i++) {
301 if (boxLo[i] <= x[i] && x[i] <= boxHi[i]) continue;
302 Real dxLo = x[i] - boxLo[i];
303 if (periodicity[i]) {
304 while (dxLo < 0) dxLo += probSize[i];
305 while (dxLo > probSize[i]) dxLo -= probSize[i];
306 }
307 Real dxHi = x[i] - boxHi[i];
308 if (periodicity[i]) {
309 while (dxHi < 0) dxHi += probSize[i];
310 while (dxHi > probSize[i]) dxHi -= probSize[i];
311 }
312 Real dx2Lo = dxLo * dxLo;
313 Real dx2Hi = dxHi * dxHi;
314 d2 += std::max(dx2Lo, dx2Hi);
315 }
316 return std::sqrt(d2);
317 }
318
333 const RealVec& boxLo,
334 const RealVec& boxHi) const {
335 Real d2 = 0.0;
336 for (int i=0; i<3; i++) {
337 Real dxLo = x[i] - boxLo[i];
338 if (periodicity[i]) {
339 while (dxLo < 0) dxLo += probSize[i];
340 while (dxLo > probSize[i]) dxLo -= probSize[i];
341 }
342 Real dxHi = x[i] - boxHi[i];
343 if (periodicity[i]) {
344 while (dxHi < 0) dxHi += probSize[i];
345 while (dxHi > probSize[i]) dxHi -= probSize[i];
346 }
347 Real dx2Lo = dxLo * dxLo;
348 Real dx2Hi = dxHi * dxHi;
349 d2 += std::max(dx2Lo, dx2Hi);
350 }
351 return std::sqrt(d2);
352 }
353
372 void minMaxBoxDist2(const RealVec& x,
373 const RealVec& boxLo,
374 const RealVec& boxHi,
375 RealVec& d2Min,
376 RealVec& d2Max) const {
377 d2Min = 0.0;
378 d2Max = 0.0;
379 for (int i=0; i<3; i++) {
380 Real dxLo = x[i] - boxLo[i];
381 if (periodicity[i]) {
382 while (dxLo < 0) dxLo += probSize[i];
383 while (dxLo > probSize[i]) dxLo -= probSize[i];
384 }
385 Real dxHi = x[i] - boxHi[i];
386 if (periodicity[i]) {
387 while (dxHi < 0) dxHi += probSize[i];
388 while (dxHi > probSize[i]) dxHi -= probSize[i];
389 }
390 Real dx2Lo = dxLo * dxLo;
391 Real dx2Hi = dxHi * dxHi;
392 d2Max[i] = std::max(dx2Lo, dx2Hi);
393 if (x[i] < boxLo[i] || x[i] > boxHi[i])
394 d2Min[i] = std::min(dx2Lo, dx2Hi);
395 else
396 d2Min[i] = 0.0;
397 }
398 }
399
414 void minMaxBoxDist2(const RealVec& x,
415 const RealVec& boxLo,
416 const RealVec& boxHi,
417 Real& d2Min,
418 Real& d2Max) const {
419 RealVec d2MinVec, d2MaxVec;
420 minMaxBoxDist2(x, boxLo, boxHi, d2MinVec, d2MaxVec);
421 d2Min = d2MinVec.sum();
422 d2Max = d2MaxVec.sum();
423 }
424
439 void minMaxBoxDist(const RealVec& x,
440 const RealVec& boxLo,
441 const RealVec& boxHi,
442 Real& dMin,
443 Real& dMax) const {
444 Real d2Min, d2Max;
445 minMaxBoxDist2(x, boxLo, boxHi, d2Min, d2Max);
446 dMin = std::sqrt(d2Min);
447 dMax = std::sqrt(d2Max);
448 }
449
450 private:
451
459 };
460
461}
462
463#endif
464// _GEOMETRY_H_
Class to hold data on a CR packet.
A class that holds data to describe a CR packet.
Definition CRPacket.H:28
A class that describes the geometry of a calculation.
Definition Geometry.H:32
bool contains(const RealVec &x) const
Report if a specified point is in the problem domain.
Definition Geometry.H:245
const BoolVec & isPeriodic() const
Return periodicity of problem domain.
Definition Geometry.H:95
bool isAnyOpen() const
Return whether the domain is open in any direction.
Definition Geometry.H:107
const RealBox & xBox() const
Return the domain bounding box.
Definition Geometry.H:59
BoolVec periodicity
Definition Geometry.H:456
void minMaxBoxDist2(const RealVec &x, const RealVec &boxLo, const RealVec &boxHi, RealVec &d2Min, RealVec &d2Max) const
Compute min and max squared distances between a point and a box.
Definition Geometry.H:372
bcType
An enum describing boundary condition types.
Definition Geometry.H:39
@ openBC
Definition Geometry.H:40
@ periodicBC
Definition Geometry.H:43
@ reflectingBC
Definition Geometry.H:42
@ absorbingBC
Definition Geometry.H:41
void applyBC(RealVec &x) const
Apply boundary conditions to a packet.
Definition Geometry.H:124
const Vec3< bcType > & bHi() const
Return high boundary conditions of computational domain.
Definition Geometry.H:89
const Vec3< bcType > & bLo() const
Return low boundary conditions of computational domain.
Definition Geometry.H:83
const RealVec & xSize() const
Return size of computational domain.
Definition Geometry.H:77
bool isAnyPeriodic() const
Return whether the domain is periodic in any dimension.
Definition Geometry.H:101
Real maxBoxDist(const RealVec &x, const RealVec &boxLo, const RealVec &boxHi) const
Return maximum distance between a point and a box.
Definition Geometry.H:332
RealVec periodicLoop(const RealVec &x, const bool recenter=false) const
Loop the input position over periodic boundaries.
Definition Geometry.H:191
bool hasPeriodicDim
Definition Geometry.H:458
void minMaxBoxDist2(const RealVec &x, const RealVec &boxLo, const RealVec &boxHi, Real &d2Min, Real &d2Max) const
Compute min and max squared distances between a point and a box.
Definition Geometry.H:414
void minMaxBoxDist(const RealVec &x, const RealVec &boxLo, const RealVec &boxHi, Real &dMin, Real &dMax) const
Compute min and max squared distances between a point and a box.
Definition Geometry.H:439
Real dist(const RealVec &x1, const RealVec &x2) const
Compute distance between two points.
Definition Geometry.H:279
Vec3< bcType > bcHi
Definition Geometry.H:453
RealVec disp(const RealVec &x1, const RealVec &x2) const
Get displacement vector between two points.
Definition Geometry.H:264
RealVec probSize
Definition Geometry.H:455
std::vector< RealBox > periodicLoopBox(const RealBox &b, const bool recenter=false) const
Loop the input box over periodic boundaries.
Definition Geometry.H:213
Vec3< bcType > bcLo
Definition Geometry.H:452
const RealVec & xHi() const
Return high boundary of computational domain.
Definition Geometry.H:71
Real minBoxDist(const RealVec &x, const RealVec &boxLo, const RealVec &boxHi) const
Return minimum distance between a point and a box.
Definition Geometry.H:296
const RealVec & xLo() const
Return low boundary of computational domain.
Definition Geometry.H:65
Real periodicLoop(const Real x, const int i, const bool recenter=false) const
Loop the input coordinate over periodic boundaries.
Definition Geometry.H:165
RealBox box
Definition Geometry.H:454
Class to parse the criptic input deck.
Definition ParmParser.H:37
Class that represents a 3D rectangular prism.
Definition RealBox.H:30
RealVec hi
Definition RealBox.H:166
RealVec lo
Definition RealBox.H:165
Real mag() const
Computes the magnitude of the vector.
Definition Vec3.H:470
T sum() const
Return the sum of the elements.
Definition Vec3.H:561
The primary namespace for criptic objects.
Definition AdvancePacket.H:25
criptic::FieldQty max(const criptic::FieldQty &q1, const criptic::FieldQty &q2)
Take elementwise maximum of two FieldQty objects.
Definition FieldQty.H:277
double Real
Definition Types.H:38