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