chombo-discharge
CD_SignedDistanceBVHImplem.H
Go to the documentation of this file.
1 /* chombo-discharge
2  * Copyright © 2021 SINTEF Energy Research.
3  * Please refer to Copyright.txt and LICENSE in the chombo-discharge root directory.
4  */
5 
12 #ifndef CD_SignedDistanceBVHImplem_H
13 #define CD_SignedDistanceBVHImplem_H
14 
15 // Std includes
16 #include <chrono>
17 
18 // Our includes
19 #include <CD_SignedDistanceBVH.H>
20 #include <CD_NamespaceHeader.H>
21 
22 using namespace std::chrono;
23 
24 template <class T, class BV, int K>
25 SignedDistanceBVH<T, BV, K>::SignedDistanceBVH(const std::shared_ptr<Node>& a_root,
26  const bool a_flipInside,
27  const Real a_zCoord)
28 {
29  m_root = a_root;
30  m_zCoord = a_zCoord;
31  m_flipInside = a_flipInside;
32 
33  m_numCalled = 0L;
34  m_timespan = std::chrono::duration<double>(0.0);
35 }
36 
37 template <class T, class BV, int K>
39 {
40  m_root = a_primitive.m_root;
41  m_zCoord = a_primitive.m_zCoord;
42  m_flipInside = a_primitive.m_flipInside;
43 
44  m_numCalled = 0L;
45  m_timespan = std::chrono::duration<double>(0.0);
46 }
47 
48 template <class T, class BV, int K>
50 {
51  if (m_numCalled > 0L) {
52  pout() << "In file CD_SignedDistanceBVHImplem: SignedDistanceBVH::~SignedDistanceBVH() On destructor: Calls: "
53  << m_numCalled << "\t Tot: " << m_timespan.count()
54  << "\t Avg./Call = " << m_timespan.count() / (1.0 * m_numCalled) << endl;
55  }
56 }
57 
58 template <class T, class BV, int K>
59 Real
60 SignedDistanceBVH<T, BV, K>::value(const RealVect& a_point) const
61 {
62 
63  // TLDR: In 2D we ignore z-variations, freezing that coordinate to some value. We then use the bounding volume hierarchy methodology for computing the signed distance.
64 #if CH_SPACEDIM == 2
65  Vec3 p(a_point[0], a_point[1], m_zCoord);
66 #else
67  Vec3 p(a_point[0], a_point[1], a_point[2]);
68 #endif
69 
70  high_resolution_clock::time_point t1 = high_resolution_clock::now();
71  auto d = m_root->signedDistance(p);
72  high_resolution_clock::time_point t2 = high_resolution_clock::now();
73  duration<double> time_span = duration_cast<duration<double>>(t2 - t1);
74 
75  if (m_flipInside) {
76  d = -d;
77  }
78 
79  m_timespan += time_span;
80  m_numCalled++;
81 
82  return Real(d);
83 }
84 
85 template <class T, class BV, int K>
86 BaseIF*
88 {
89  return static_cast<BaseIF*>(new SignedDistanceBVH(*this));
90 }
91 
92 #include <CD_NamespaceFooter.H>
93 
94 #endif
Declaration of an signe distance function class that gets its value function from a DCEL surface Tess...
Signed distance function for a DCEL mesh.
Definition: CD_SignedDistanceBVH.H:35
bool m_flipInside
Hook for turning inside to outside.
Definition: CD_SignedDistanceBVH.H:102
Real m_zCoord
For 2D only. This is the z-coordinate through which we slice the object.
Definition: CD_SignedDistanceBVH.H:92
BaseIF * newImplicitFunction() const override
Factory method. Sends pointers around.
Definition: CD_SignedDistanceBVHImplem.H:87
SignedDistanceBVH()=delete
Disallowed weak construction.
std::shared_ptr< Node > m_root
Pointer to root node in bounding volume hierarchy.
Definition: CD_SignedDistanceBVH.H:97
EBGeometry::Vec3T< T > Vec3
Alias for always-3D vector with template.
Definition: CD_SignedDistanceBVH.H:40
virtual ~SignedDistanceBVH()
Destructor (does nothing)
Definition: CD_SignedDistanceBVHImplem.H:49
Real value(const RealVect &a_point) const override
Value function.
Definition: CD_SignedDistanceBVHImplem.H:60