ViennaLS
Loading...
Searching...
No Matches
lsGeometricAdvectDistributions.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <hrleVectorType.hpp>
4
5#include <vcLogger.hpp>
6#include <vcVectorUtil.hpp>
7
8namespace viennals {
9
10using namespace viennacore;
11
15template <class T, int D> class GeometricAdvectDistribution {
16public:
18
23 virtual bool isInside(const Vec3D<hrleCoordType> &initial,
24 const Vec3D<hrleCoordType> &candidate,
25 double eps = 0.) const {
26 return true;
27 }
28
32 virtual T getSignedDistance(const Vec3D<hrleCoordType> &initial,
33 const Vec3D<hrleCoordType> &candidate,
34 unsigned long initialPointId) const = 0;
35
37 virtual std::array<hrleCoordType, 6> getBounds() const = 0;
38
40};
41
44template <class T, int D>
46public:
47 const T radius = 0.;
48 const T radius2;
49 const T gridDelta;
50
51 SphereDistribution(const T passedRadius, const T delta)
52 : radius(passedRadius), radius2(radius * radius), gridDelta(delta) {}
53
54 bool isInside(const Vec3D<hrleCoordType> &initial,
55 const Vec3D<hrleCoordType> &candidate,
56 double eps = 0.) const override {
57 hrleCoordType dot = 0.;
58 for (unsigned i = 0; i < D; ++i) {
59 double tmp = candidate[i] - initial[i];
60 dot += tmp * tmp;
61 }
62
63 if (std::sqrt(dot) <= std::abs(radius) + eps)
64 return true;
65 else
66 return false;
67 }
68
69 T getSignedDistance(const Vec3D<hrleCoordType> &initial,
70 const Vec3D<hrleCoordType> &candidate,
71 unsigned long /*initialPointId*/) const override {
72 T distance = std::numeric_limits<T>::max();
73 Vec3D<hrleCoordType> v{};
74 for (unsigned i = 0; i < D; ++i) {
75 v[i] = candidate[i] - initial[i];
76 }
77
78 if (std::abs(radius) <= gridDelta) {
79 distance =
80 std::max(std::max(std::abs(v[0]), std::abs(v[1])), std::abs(v[2])) -
81 std::abs(radius);
82 } else {
83 for (unsigned i = 0; i < D; ++i) {
84 T y = (v[(i + 1) % D]);
85 T z = 0;
86 if constexpr (D == 3)
87 z = (v[(i + 2) % D]);
88 T x = radius2 - y * y - z * z;
89 if (x < 0.)
90 continue;
91 T dirRadius = std::abs(v[i]) - std::sqrt(x);
92 if (std::abs(dirRadius) < std::abs(distance))
93 distance = dirRadius;
94 }
95 }
96 // return distance;
97 if (radius < 0) {
98 return -distance;
99 } else {
100 return distance;
101 }
102 }
103
104 std::array<hrleCoordType, 6> getBounds() const override {
105 std::array<hrleCoordType, 6> bounds = {};
106 for (unsigned i = 0; i < D; ++i) {
107 bounds[2 * i] = -radius;
108 bounds[2 * i + 1] = radius;
109 }
110 return bounds;
111 }
112};
113
116template <class T, int D>
118public:
119 const hrleVectorType<T, 3> posExtent;
121
122 BoxDistribution(const std::array<T, 3> &halfAxes, const T delta)
123 : posExtent(halfAxes), gridDelta(delta) {
124 for (unsigned i = 0; i < D; ++i) {
125 if (std::abs(posExtent[i]) < gridDelta) {
126 Logger::getInstance()
127 .addWarning("One half-axis of BoxDistribution is smaller than "
128 "the grid Delta! This can lead to numerical errors "
129 "breaking the distribution!")
130 .print();
131 }
132 }
133 }
134
135 bool isInside(const Vec3D<hrleCoordType> &initial,
136 const Vec3D<hrleCoordType> &candidate,
137 double eps = 0.) const override {
138 for (unsigned i = 0; i < D; ++i) {
139 if (std::abs(candidate[i] - initial[i]) >
140 (std::abs(posExtent[i]) + eps)) {
141 return false;
142 }
143 }
144 return true;
145 }
146
147 T getSignedDistance(const Vec3D<hrleCoordType> &initial,
148 const Vec3D<hrleCoordType> &candidate,
149 unsigned long /*initialPointId*/) const override {
150 T distance = std::numeric_limits<T>::lowest();
151 for (unsigned i = 0; i < D; ++i) {
152 T vector = std::abs(candidate[i] - initial[i]);
153 distance = std::max(vector - std::abs(posExtent[i]), distance);
154 }
155 return (posExtent[0] < 0) ? -distance : distance;
156 }
157
158 std::array<hrleCoordType, 6> getBounds() const override {
159 std::array<hrleCoordType, 6> bounds = {};
160 for (unsigned i = 0; i < D; ++i) {
161 bounds[2 * i] = -posExtent[i];
162 bounds[2 * i + 1] = posExtent[i];
163 }
164 return bounds;
165 }
166};
167
168} // namespace viennals
Concrete implementation of GeometricAdvectDistribution for a rectangular box distribution.
Definition lsGeometricAdvectDistributions.hpp:117
const T gridDelta
Definition lsGeometricAdvectDistributions.hpp:120
T getSignedDistance(const Vec3D< hrleCoordType > &initial, const Vec3D< hrleCoordType > &candidate, unsigned long) const override
Returns the signed distance of a point relative to the distributions center. This is the signed manha...
Definition lsGeometricAdvectDistributions.hpp:147
std::array< hrleCoordType, 6 > getBounds() const override
Sets bounds to the bounding box of the distribution.
Definition lsGeometricAdvectDistributions.hpp:158
bool isInside(const Vec3D< hrleCoordType > &initial, const Vec3D< hrleCoordType > &candidate, double eps=0.) const override
Quick check whether a point relative to the distributions center is inside the distribution....
Definition lsGeometricAdvectDistributions.hpp:135
const hrleVectorType< T, 3 > posExtent
Definition lsGeometricAdvectDistributions.hpp:119
BoxDistribution(const std::array< T, 3 > &halfAxes, const T delta)
Definition lsGeometricAdvectDistributions.hpp:122
Base class for distributions used by lsGeometricAdvect. All functions are pure virtual and must be im...
Definition lsGeometricAdvectDistributions.hpp:15
virtual T getSignedDistance(const Vec3D< hrleCoordType > &initial, const Vec3D< hrleCoordType > &candidate, unsigned long initialPointId) const =0
Returns the signed distance of a point relative to the distributions center. This is the signed manha...
GeometricAdvectDistribution()
Definition lsGeometricAdvectDistributions.hpp:17
virtual ~GeometricAdvectDistribution()
Definition lsGeometricAdvectDistributions.hpp:39
virtual bool isInside(const Vec3D< hrleCoordType > &initial, const Vec3D< hrleCoordType > &candidate, double eps=0.) const
Quick check whether a point relative to the distributions center is inside the distribution....
Definition lsGeometricAdvectDistributions.hpp:23
virtual std::array< hrleCoordType, 6 > getBounds() const =0
Sets bounds to the bounding box of the distribution.
Concrete implementation of GeometricAdvectDistribution for a spherical advection distribution.
Definition lsGeometricAdvectDistributions.hpp:45
const T gridDelta
Definition lsGeometricAdvectDistributions.hpp:49
bool isInside(const Vec3D< hrleCoordType > &initial, const Vec3D< hrleCoordType > &candidate, double eps=0.) const override
Quick check whether a point relative to the distributions center is inside the distribution....
Definition lsGeometricAdvectDistributions.hpp:54
T getSignedDistance(const Vec3D< hrleCoordType > &initial, const Vec3D< hrleCoordType > &candidate, unsigned long) const override
Returns the signed distance of a point relative to the distributions center. This is the signed manha...
Definition lsGeometricAdvectDistributions.hpp:69
std::array< hrleCoordType, 6 > getBounds() const override
Sets bounds to the bounding box of the distribution.
Definition lsGeometricAdvectDistributions.hpp:104
const T radius2
Definition lsGeometricAdvectDistributions.hpp:48
const T radius
Definition lsGeometricAdvectDistributions.hpp:47
SphereDistribution(const T passedRadius, const T delta)
Definition lsGeometricAdvectDistributions.hpp:51
Definition lsAdvect.hpp:46
constexpr int D
Definition pyWrap.cpp:65
double T
Definition pyWrap.cpp:63