OpenLB 1.8.1
Loading...
Searching...
No Matches
olb::Hyperplane3D< T > Struct Template Reference

Definition of a analytical 2D plane embedded in 3D space. More...

#include <hyperplane3D.h>

+ Collaboration diagram for olb::Hyperplane3D< T >:

Public Member Functions

 Hyperplane3D ()=default
 
Hyperplane3DoriginAt (const Vector< T, 3 > &origin)
 Center the hyperplane at the given origin vector.
 
Hyperplane3DcenteredIn (const Cuboid3D< T > &cuboid)
 Center the hyperplane relative to the given cuboid.
 
Hyperplane3DspannedBy (const Vector< T, 3 > &u, const Vector< T, 3 > &v)
 Span the hyperplane using two span vectors.
 
Hyperplane3DnormalTo (const Vector< T, 3 > &normal)
 Calculate the spanning vectors of the hyperplane to be orthogonal to the given normal.
 
Hyperplane3DapplyMatrixToSpan (const Vector< T, 3 > &row0, const Vector< T, 3 > &row1, const Vector< T, 3 > &row2)
 Apply a matrix given by its row vectors to both span vectors.
 
Hyperplane3DrotateSpanAroundX (T r)
 Rotate the spanning vectors around the X axis.
 
Hyperplane3DrotateSpanAroundY (T r)
 Rotate the spanning vectors around the Y axis.
 
Hyperplane3DrotateSpanAroundZ (T r)
 Rotate the spanning vectors around the Z axis.
 
Hyperplane3DparseFromXML (const std::string &xml)
 Read origin and normal from XML.
 
bool isXYPlane () const
 
bool isXZPlane () const
 
bool isYZPlane () const
 
Vector< T, 3 > project (const Vector< T, 2 > &x) const
 

Public Attributes

Vector< T, 3 > origin
 
Vector< T, 3 > u
 
Vector< T, 3 > v
 
Vector< T, 3 > normal
 

Detailed Description

template<typename T>
struct olb::Hyperplane3D< T >

Definition of a analytical 2D plane embedded in 3D space.

Hyperplane3D defines a hyperplane using its origin and two span vectors.

In practice it might be preferable to define a hyperplane using a normal vector or to automatically center the origin in a given cuboid. For this purpose a fluent construction interface is offered:

// construct a hyperplane positioned at (1,1,1) and normal to (1,0,0)
auto plane = Hyperplane3D<T>().originAt({1,1,1})
.normalTo({1,0,0});
Hyperplane3D()=default
Hyperplane3D & normalTo(const Vector< T, 3 > &normal)
Calculate the spanning vectors of the hyperplane to be orthogonal to the given normal.

The primary reason for this development was the increasing constructor clutter in BlockReduction3D2D: Instead of using the correct Vector<T,3> types for passing span and origin vectors they were passed as a mix between raw values and array types to prevent the constructor from becoming ambiguous. e.g. on the type level passing two span vectors is indistinguishable from passing normal and origin vectors.

Definition at line 53 of file hyperplane3D.h.

Constructor & Destructor Documentation

◆ Hyperplane3D()

template<typename T >
olb::Hyperplane3D< T >::Hyperplane3D ( )
explicitdefault

Member Function Documentation

◆ applyMatrixToSpan()

template<typename T >
Hyperplane3D< T > & olb::Hyperplane3D< T >::applyMatrixToSpan ( const Vector< T, 3 > & row0,
const Vector< T, 3 > & row1,
const Vector< T, 3 > & row2 )

Apply a matrix given by its row vectors to both span vectors.

Returns
Hyperplane3D reference for further construction

Definition at line 107 of file hyperplane3D.hh.

111{
112 const auto u_prime = u;
113 const auto v_prime = v;
114
115 u[0] = row0 * u_prime;
116 u[1] = row1 * u_prime;
117 u[2] = row2 * u_prime;
118
119 v[0] = row0 * v_prime;
120 v[1] = row1 * v_prime;
121 v[2] = row2 * v_prime;
122
123 return *this;
124}
Vector< T, 3 > u
Vector< T, 3 > v

◆ centeredIn()

template<typename T >
Hyperplane3D< T > & olb::Hyperplane3D< T >::centeredIn ( const Cuboid3D< T > & cuboid)

Center the hyperplane relative to the given cuboid.

Returns
Hyperplane3D reference for further construction

Definition at line 90 of file hyperplane3D.hh.

91{
92 const Vector<T,3>& cuboidOrigin = cuboid.getOrigin();
93 const Vector<int,3>& extend = cuboid.getExtent();
94 const T deltaR = cuboid.getDeltaR();
95
96 origin[0] = (cuboidOrigin[0] + 0.5 * deltaR * extend[0]);
97 origin[1] = (cuboidOrigin[1] + 0.5 * deltaR * extend[1]);
98 origin[2] = (cuboidOrigin[2] + 0.5 * deltaR * extend[2]);
99 origin[0] -= 2*std::numeric_limits<T>::epsilon()*util::fabs(origin[0]);
100 origin[1] -= 2*std::numeric_limits<T>::epsilon()*util::fabs(origin[1]);
101 origin[2] -= 2*std::numeric_limits<T>::epsilon()*util::fabs(origin[2]);
102
103 return *this;
104}
Expr fabs(Expr x)
Definition expr.cpp:230
Vector< T, 3 > origin

References olb::util::fabs(), olb::Cuboid< T, D >::getDeltaR(), olb::Cuboid< T, D >::getExtent(), and olb::Cuboid< T, D >::getOrigin().

+ Here is the call graph for this function:

◆ isXYPlane()

template<typename T >
bool olb::Hyperplane3D< T >::isXYPlane ( ) const
Returns
true iff normal is orthogonal to X, Y axis

Definition at line 189 of file hyperplane3D.hh.

190{
191 return util::nearZero(util::dotProduct3D(normal, {1,0,0})) &&
193}
T dotProduct3D(const Vector< T, 3 > &a, const Vector< T, 3 > &b)
dot product, only valid in 3d
bool nearZero(T a) any_platform
return true if a is close to zero
Definition util.h:402
Vector< T, 3 > normal

References olb::util::dotProduct3D(), and olb::util::nearZero().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isXZPlane()

template<typename T >
bool olb::Hyperplane3D< T >::isXZPlane ( ) const
Returns
true iff normal is orthogonal to X, Z axis

Definition at line 196 of file hyperplane3D.hh.

197{
198 return util::nearZero(util::dotProduct3D(normal, {1,0,0})) &&
200}

References olb::util::dotProduct3D(), and olb::util::nearZero().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isYZPlane()

template<typename T >
bool olb::Hyperplane3D< T >::isYZPlane ( ) const
Returns
true iff normal is orthogonal to Y, Z axis

Definition at line 203 of file hyperplane3D.hh.

204{
205 return util::nearZero(util::dotProduct3D(normal, {0,1,0})) &&
207}

References olb::util::dotProduct3D(), and olb::util::nearZero().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ normalTo()

template<typename T >
Hyperplane3D< T > & olb::Hyperplane3D< T >::normalTo ( const Vector< T, 3 > & normal)

Calculate the spanning vectors of the hyperplane to be orthogonal to the given normal.

Returns
Hyperplane3D reference for further construction

Definition at line 49 of file hyperplane3D.hh.

50{
51 normal = n;
52
53 if ( util::nearZero(normal[0]*normal[1]*normal[2]) ) {
54 if ( util::nearZero(normal[0]) ) {
55 u = {T(1), T(), T()};
56 }
57 else if ( util::nearZero(normal[1]) ) {
58 u = {T(), T(1), T()};
59 }
60 else if ( util::nearZero(normal[2]) ) {
61 u = {T(), T(), T(1)};
62 }
63 }
64 else {
65 u = {normal[2], T(), -normal[0]};
66 }
67
69 u = normalize(u);
71
75
76 return *this;
77}
constexpr Vector< T, 3 > crossProduct3D(const ScalarVector< T, 3, IMPL > &a, const ScalarVector< T, 3, IMPL_ > &b) any_platform
Definition vector.h:263
constexpr Vector< T, D > normalize(const ScalarVector< T, D, IMPL > &a, T scale=T{1})
Definition vector.h:284
#define OLB_POSTCONDITION(COND)
Definition olbDebug.h:47

References olb::crossProduct3D(), olb::util::dotProduct3D(), olb::util::nearZero(), olb::normalize(), and OLB_POSTCONDITION.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ originAt()

template<typename T >
Hyperplane3D< T > & olb::Hyperplane3D< T >::originAt ( const Vector< T, 3 > & origin)

Center the hyperplane at the given origin vector.

Returns
Hyperplane3D reference for further construction

Definition at line 80 of file hyperplane3D.hh.

81{
82 origin[0] = o[0] - 2*std::numeric_limits<T>::epsilon()*util::fabs(o[0]);
83 origin[1] = o[1] - 2*std::numeric_limits<T>::epsilon()*util::fabs(o[1]);
84 origin[2] = o[2] - 2*std::numeric_limits<T>::epsilon()*util::fabs(o[2]);
85
86 return *this;
87}

References olb::util::fabs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseFromXML()

template<typename T >
Hyperplane3D< T > & olb::Hyperplane3D< T >::parseFromXML ( const std::string & xml)

Read origin and normal from XML.

Returns
Hyperplane3D reference for further construction

Definition at line 158 of file hyperplane3D.hh.

159{
160 using namespace tinyxml2;
161 XMLDocument doc;
162 if (doc.Parse(xmlData.c_str()) != XML_SUCCESS) {
163 throw std::runtime_error("Failed to parse XML: " + std::string(doc.ErrorStr()));
164 }
165 XMLElement* root = doc.FirstChildElement("UpdateSlice");
166 if (!root) {
167 throw std::runtime_error("Root element <UpdateSlice> not found.");
168 }
169 XMLElement* origin = root->FirstChildElement("origin");
170 if (!origin) {
171 throw std::runtime_error("Element <origin> not found.");
172 }
173 const T ox = origin->DoubleAttribute("x");
174 const T oy = origin->DoubleAttribute("y");
175 const T oz = origin->DoubleAttribute("z");
176 XMLElement* normal = root->FirstChildElement("normal");
177 if (!normal) {
178 throw std::runtime_error("Element <normal> not found.");
179 }
180 const T nx = normal->DoubleAttribute("x");
181 const T ny = normal->DoubleAttribute("y");
182 const T nz = normal->DoubleAttribute("z");
183 Vector n{nx, ny, nz};
184 return originAt({ox,oy,oz})
185 .normalTo(normalize(n));
186}
Vector(T &&t, Ts &&... ts) -> Vector< std::remove_cvref_t< T >, 1+sizeof...(Ts)>
Hyperplane3D & originAt(const Vector< T, 3 > &origin)
Center the hyperplane at the given origin vector.

References olb::normalize().

+ Here is the call graph for this function:

◆ project()

template<typename T >
Vector< T, 3 > olb::Hyperplane3D< T >::project ( const Vector< T, 2 > & x) const
Returns
2D vector relative to origin projected to 3D

Definition at line 210 of file hyperplane3D.hh.

211{
212 return origin + x[0]*u + x[1]*v;
213}
+ Here is the caller graph for this function:

◆ rotateSpanAroundX()

template<typename T >
Hyperplane3D< T > & olb::Hyperplane3D< T >::rotateSpanAroundX ( T r)

Rotate the spanning vectors around the X axis.

Returns
Hyperplane3D reference for further construction

Definition at line 127 of file hyperplane3D.hh.

128{
129 return applyMatrixToSpan(
130 {1, 0, 0 },
131 {0, util::cos(r), -util::sin(r)},
132 {0, util::sin(r), util::cos(r)}
133 );
134
135}
ADf< T, DIM > sin(const ADf< T, DIM > &a)
Definition aDiff.h:569
ADf< T, DIM > cos(const ADf< T, DIM > &a)
Definition aDiff.h:578
Hyperplane3D & applyMatrixToSpan(const Vector< T, 3 > &row0, const Vector< T, 3 > &row1, const Vector< T, 3 > &row2)
Apply a matrix given by its row vectors to both span vectors.

References olb::util::cos(), and olb::util::sin().

+ Here is the call graph for this function:

◆ rotateSpanAroundY()

template<typename T >
Hyperplane3D< T > & olb::Hyperplane3D< T >::rotateSpanAroundY ( T r)

Rotate the spanning vectors around the Y axis.

Returns
Hyperplane3D reference for further construction

Definition at line 138 of file hyperplane3D.hh.

139{
140 return applyMatrixToSpan(
141 { util::cos(r), 0, util::sin(r)},
142 { 0, 1, 0 },
143 {-util::sin(r), 0, util::cos(r)}
144 );
145}

References olb::util::cos(), and olb::util::sin().

+ Here is the call graph for this function:

◆ rotateSpanAroundZ()

template<typename T >
Hyperplane3D< T > & olb::Hyperplane3D< T >::rotateSpanAroundZ ( T r)

Rotate the spanning vectors around the Z axis.

Returns
Hyperplane3D reference for further construction

Definition at line 148 of file hyperplane3D.hh.

149{
150 return applyMatrixToSpan(
151 {util::cos(r), -util::sin(r), 0},
152 {util::sin(r), util::cos(r), 0},
153 {0, 0, 1}
154 );
155}

References olb::util::cos(), and olb::util::sin().

+ Here is the call graph for this function:

◆ spannedBy()

template<typename T >
Hyperplane3D< T > & olb::Hyperplane3D< T >::spannedBy ( const Vector< T, 3 > & u,
const Vector< T, 3 > & v )

Span the hyperplane using two span vectors.

Returns
Hyperplane3D reference for further construction

Definition at line 35 of file hyperplane3D.hh.

References olb::crossProduct3D(), olb::util::dotProduct3D(), olb::util::nearZero(), olb::normalize(), and OLB_POSTCONDITION.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ normal

template<typename T >
Vector<T,3> olb::Hyperplane3D< T >::normal

Definition at line 57 of file hyperplane3D.h.

◆ origin

template<typename T >
Vector<T,3> olb::Hyperplane3D< T >::origin

Definition at line 54 of file hyperplane3D.h.

◆ u

template<typename T >
Vector<T,3> olb::Hyperplane3D< T >::u

Definition at line 55 of file hyperplane3D.h.

◆ v

template<typename T >
Vector<T,3> olb::Hyperplane3D< T >::v

Definition at line 56 of file hyperplane3D.h.


The documentation for this struct was generated from the following files: