OpenLB 1.7
Loading...
Searching...
No Matches
hyperplane3D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2017 Adrian Kummerlaender
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef HYPERPLANE_3D_HH
25#define HYPERPLANE_3D_HH
26
27#include "hyperplane3D.h"
28#include "core/olbDebug.h"
30
31namespace olb {
32
33
34template <typename T>
47
48template <typename T>
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
68 v = normalize(crossProduct3D(normal,u));
69 u = normalize(u);
70 normal = normalize(normal);
71
75
76 return *this;
77}
78
79template <typename T>
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}
88
89template <typename T>
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}
105
106template <typename T>
108 const Vector<T,3>& row0,
109 const Vector<T,3>& row1,
110 const Vector<T,3>& row2)
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}
125
126template <typename T>
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}
136
137template <typename T>
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}
146
147template <typename T>
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}
156
157template <typename T>
159{
160 return util::nearZero(util::dotProduct3D(normal, {1,0,0})) &&
161 util::nearZero(util::dotProduct3D(normal, {0,1,0}));
162}
163
164template <typename T>
166{
167 return util::nearZero(util::dotProduct3D(normal, {1,0,0})) &&
168 util::nearZero(util::dotProduct3D(normal, {0,0,1}));
169}
170
171template <typename T>
173{
174 return util::nearZero(util::dotProduct3D(normal, {0,1,0})) &&
175 util::nearZero(util::dotProduct3D(normal, {0,0,1}));
176}
177
178template <typename T>
180{
181 return origin + x[0]*u + x[1]*v;
182}
183
184}
185
186#endif
A regular single 3D cuboid is the basic component of a 3D cuboid structure which defines the grid.
Definition cuboid3D.h:58
Vector< T, 3 > getOrigin() const
Read only access to left lower corner coordinates.
Definition cuboid3D.hh:135
Vector< int, 3 > const getExtent() const
Read only access to the number of voxels in every dimension.
Definition cuboid3D.hh:165
T getDeltaR() const
Read only access to the distance of cuboid nodes.
Definition cuboid3D.hh:141
Plain old scalar vector.
Definition vector.h:47
ADf< T, DIM > sin(const ADf< T, DIM > &a)
Definition aDiff.h:569
cpu::simd::Pack< T > fabs(cpu::simd::Pack< T > value)
Definition pack.h:106
T dotProduct3D(const Vector< T, 3 > &a, const Vector< T, 3 > &b)
dot product, only valid in 3d
bool nearZero(const ADf< T, DIM > &a)
Definition aDiff.h:1087
ADf< T, DIM > cos(const ADf< T, DIM > &a)
Definition aDiff.h:578
Top level namespace for all of OpenLB.
constexpr Vector< T, 3 > crossProduct3D(const ScalarVector< T, 3, IMPL > &a, const ScalarVector< T, 3, IMPL_ > &b) any_platform
Definition vector.h:224
constexpr Vector< T, D > normalize(const ScalarVector< T, D, IMPL > &a, T scale=T{1})
Definition vector.h:245
#define OLB_POSTCONDITION(COND)
Definition olbDebug.h:47
Definition of a analytical 2D plane embedded in 3D space.
Vector< T, 3 > project(const Vector< T, 2 > &x) const
Hyperplane3D & centeredIn(const Cuboid3D< T > &cuboid)
Center the hyperplane relative to the given cuboid.
Hyperplane3D & rotateSpanAroundZ(T r)
Rotate the spanning vectors around the Z axis.
bool isXZPlane() const
Hyperplane3D & spannedBy(const Vector< T, 3 > &u, const Vector< T, 3 > &v)
Span the hyperplane using two span vectors.
Hyperplane3D & rotateSpanAroundX(T r)
Rotate the spanning vectors around the X axis.
Hyperplane3D & rotateSpanAroundY(T r)
Rotate the spanning vectors around the Y axis.
Hyperplane3D & normalTo(const Vector< T, 3 > &normal)
Calculate the spanning vectors of the hyperplane to be orthogonal to the given normal.
bool isYZPlane() const
bool isXYPlane() const
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.
Hyperplane3D & originAt(const Vector< T, 3 > &origin)
Center the hyperplane at the given origin vector.