OpenLB 1.7
Loading...
Searching...
No Matches
hyperplaneLattice3D.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_LATTICE_3D_HH
25#define HYPERPLANE_LATTICE_3D_HH
26
27#include "hyperplaneLattice3D.h"
29
30namespace olb {
31
32template <typename T>
33int HyperplaneLattice3D<T>::computeMaxLatticeDistance(Cuboid3D<T>&& cuboid) const
34{
35 const Vector<T,3> origin = cuboid.getOrigin();
36 const Vector<int,3> extend = cuboid.getExtent();
37 const T deltaR = cuboid.getDeltaR();
38
39 T maxPhysDistance = T();
40 T tmp;
41 Vector<T,3> tmpO;
42 Vector<T,3> tmpE;
43
44 for (int iDim=0; iDim<3; ++iDim) {
45 tmpO[iDim] = origin[iDim] - _origin[iDim];
46 tmpE[iDim] = origin[iDim] + extend[iDim]*deltaR - _origin[iDim];
47 }
48 tmp = util::sqrt(tmpO[0]*tmpO[0] + tmpO[1]*tmpO[1] + tmpO[2]*tmpO[2]);
49 if (maxPhysDistance < tmp) {
50 maxPhysDistance = tmp;
51 }
52 tmp = util::sqrt((tmpE[0]*tmpE[0] + tmpO[1]*tmpO[1] + tmpO[2]*tmpO[2]));
53 if (maxPhysDistance < tmp) {
54 maxPhysDistance = tmp;
55 }
56 tmp = util::sqrt(tmpO[0]*tmpO[0] + tmpE[1]*tmpE[1] + tmpO[2]*tmpO[2]);
57 if (maxPhysDistance < tmp) {
58 maxPhysDistance = tmp;
59 }
60 tmp = util::sqrt(tmpO[0]*tmpO[0] + tmpO[1]*tmpO[1] + tmpE[2]*tmpE[2]);
61 if (maxPhysDistance < tmp) {
62 maxPhysDistance = tmp;
63 }
64 tmp = util::sqrt(tmpO[0]*tmpO[0] + tmpE[1]*tmpE[1] + tmpE[2]*tmpE[2]);
65 if (maxPhysDistance < tmp) {
66 maxPhysDistance = tmp;
67 }
68 tmp = util::sqrt(tmpE[0]*tmpE[0] + tmpO[1]*tmpO[1] + tmpE[2]*tmpE[2]);
69 if (maxPhysDistance < tmp) {
70 maxPhysDistance = tmp;
71 }
72 tmp = util::sqrt(tmpE[0]*tmpE[0] + tmpE[1]*tmpE[1] + tmpO[2]*tmpO[2]);
73 if (maxPhysDistance < tmp) {
74 maxPhysDistance = tmp;
75 }
76 tmp = util::sqrt(tmpE[0]*tmpE[0] + tmpE[1]*tmpE[1] + tmpE[2]*tmpE[2]);
77 if (maxPhysDistance < tmp) {
78 maxPhysDistance = tmp;
79 }
80
81 return int(maxPhysDistance/_h) + 1;
82}
83
84template <typename T>
85void HyperplaneLattice3D<T>::constructCuboid(
86 CuboidGeometry3D<T>& geometry, int maxLatticeDistance)
87{
88 int iC;
89 int minX = -maxLatticeDistance;
90 int maxX = maxLatticeDistance;
91 int minY = -maxLatticeDistance;
92 int maxY = maxLatticeDistance;
93 bool found = false;
94
95 for ( int iX = -maxLatticeDistance; iX < maxLatticeDistance; ++iX ) {
96 for ( int iY = -maxLatticeDistance; iY < maxLatticeDistance; ++iY ) {
97 if ( geometry.getC(getPhysR(iX, iY), iC) ) {
98 minX = iX;
99 found = true;
100 break;
101 }
102 }
103 if (found) {
104 break;
105 }
106 }
107 found = false;
108 for ( int iX = maxLatticeDistance; iX > -maxLatticeDistance; --iX ) {
109 for ( int iY = -maxLatticeDistance; iY < maxLatticeDistance; ++iY ) {
110 if ( geometry.getC(getPhysR(iX, iY), iC) ) {
111 maxX = iX;
112 found = true;
113 break;
114 }
115 }
116 if (found) {
117 break;
118 }
119 }
120 found = false;
121 for ( int iY = -maxLatticeDistance; iY < maxLatticeDistance; ++iY ) {
122 for ( int iX = -maxLatticeDistance; iX < maxLatticeDistance; ++iX ) {
123 if ( geometry.getC(getPhysR(iX, iY), iC) ) {
124 minY = iY;
125 found = true;
126 break;
127 }
128 }
129 if (found) {
130 break;
131 }
132 }
133 found = false;
134 for ( int iY = maxLatticeDistance; iY > -maxLatticeDistance; --iY ) {
135 for ( int iX = -maxLatticeDistance; iX < maxLatticeDistance; ++iX ) {
136 if ( geometry.getC(getPhysR(iX, iY), iC) ) {
137 maxY = iY;
138 found = true;
139 break;
140 }
141 }
142 if (found) {
143 break;
144 }
145 }
146
147 _nx = maxX - minX + 1;
148 _ny = maxY - minY + 1;
149
150 _origin = _origin + T(minX)*_u + T(minY)*_v;
151}
152
153template <typename T>
154void HyperplaneLattice3D<T>::setToResolution(int resolution)
155{
156 if (_nx > _ny) {
157 T newH = _nx*_h/(T) resolution;
158 _nx = resolution;
159 _ny = (int) (_ny*_h/newH) + 1;
160 _h = newH;
161 }
162 else {
163 T newH = _ny*_h/(T) resolution;
164 _ny = resolution;
165 _nx = (int) (_nx*_h/newH) + 1;
166 _h = newH;
167 }
168 _u = normalize(_u, _h);
169 _v = normalize(_v, _h);
170}
171
172template<typename T>
174 CuboidGeometry3D<T>& geometry, Hyperplane3D<T> hyperplane)
175 : _hyperplane(hyperplane),
176 _origin(hyperplane.origin),
177 _u(hyperplane.u),
178 _v(hyperplane.v),
179 _h(geometry.getMinDeltaR())
180{
181 _u = normalize(_u, _h);
182 _v = normalize(_v, _h);
183
184 const int maxLatticeDistance = computeMaxLatticeDistance(geometry.getMotherCuboid());
185 // compute _hyperplane.origin, _nx, _ny so that the cuboid is right inside the geometry
186 constructCuboid(geometry, maxLatticeDistance);
187}
188
189template<typename T>
191 CuboidGeometry3D<T>& geometry, Hyperplane3D<T> hyperplane, int resolution)
192 : _hyperplane(hyperplane),
193 _origin(hyperplane.origin),
194 _u(hyperplane.u),
195 _v(hyperplane.v),
196 _h(geometry.getMinDeltaR())
197{
198 _u = normalize(_u, _h);
199 _v = normalize(_v, _h);
200
201 const int maxLatticeDistance = computeMaxLatticeDistance(geometry.getMotherCuboid());
202 // compute _hyperplane.origin, _nx, _ny so that the cuboid is right inside the geometry
203 constructCuboid(geometry, maxLatticeDistance);
204
205 if ( resolution > 0 ) {
206 setToResolution(resolution);
207 }
208}
209
210template<typename T>
212 CuboidGeometry3D<T>& geometry, Hyperplane3D<T> hyperplane, T h)
213 : _hyperplane(hyperplane),
214 _origin(hyperplane.origin),
215 _u(hyperplane.u),
216 _v(hyperplane.v),
217 _h(h)
218{
219 if ( util::nearZero(_h) ) {
220 _h = geometry.getMinDeltaR();
221 }
222
223 _u = normalize(_u, _h);
224 _v = normalize(_v, _h);
225
226 const int maxLatticeDistance = computeMaxLatticeDistance(geometry.getMotherCuboid());
227 // compute _hyperplane.origin, _nx, _ny so that the cuboid is right inside the geometry
228 constructCuboid(geometry, maxLatticeDistance);
229}
230
231template<typename T>
233 Hyperplane3D<T> hyperplane,
234 T h, int nx, int ny)
235 : _hyperplane(hyperplane),
236 _origin(hyperplane.origin),
237 _u(hyperplane.u),
238 _v(hyperplane.v),
239 _h(h),
240 _nx(nx),
241 _ny(ny)
242{
243 _u = normalize(_u, _h);
244 _v = normalize(_v, _h);
245}
246
247template <typename T>
249{
250 return _hyperplane;
251}
252
253template <typename T>
254Vector<T,3> HyperplaneLattice3D<T>::getPhysR(const int& planeX, const int& planeY) const
255{
256 return Vector<T,3> {
257 _origin[0] + T(planeX)*_u[0] + T(planeY)*_v[0],
258 _origin[1] + T(planeX)*_u[1] + T(planeY)*_v[1],
259 _origin[2] + T(planeX)*_u[2] + T(planeY)*_v[2]
260 };
261}
262
263template <typename T>
265{
266 return _nx;
267}
268
269template <typename T>
271{
272 return _ny;
273}
274
275template <typename T>
277{
278 return _h;
279}
280
281template <typename T>
283{
284 return _origin;
285}
286
287template <typename T>
289{
290 return _u;
291}
292
293template <typename T>
295{
296 return _v;
297}
298
299}
300
301#endif
A cuboid geometry represents a voxel mesh.
Cuboid3D< T > getMotherCuboid()
Returns the smallest cuboid that includes all cuboids of the structure.
T getMinDeltaR() const
Returns the minimum delta in the structure.
Vector< T, 3 > getVectorV() const
Vector< T, 3 > getPhysR(const int &planeX, const int &planeY) const
Transform 2d lattice coordinates to their physical 3d location.
Vector< T, 3 > _v
Span vector of the lattice, normalized to grid width _h.
Vector< T, 3 > getPhysOrigin() const
Vector< T, 3 > getVectorU() const
Vector< T, 3 > _u
Span vector of the lattice, normalized to grid width _h.
const Hyperplane3D< T > & getHyperplane() const
HyperplaneLattice3D(CuboidGeometry3D< T > &geometry, Hyperplane3D< T > hyperplane)
Constructor for automatic discretization.
T _h
Distance between discrete lattice points.
Plain old scalar vector.
Definition vector.h:47
cpu::simd::Pack< T > sqrt(cpu::simd::Pack< T > value)
Definition pack.h:100
bool nearZero(const ADf< T, DIM > &a)
Definition aDiff.h:1087
Top level namespace for all of OpenLB.
constexpr Vector< T, D > normalize(const ScalarVector< T, D, IMPL > &a, T scale=T{1})
Definition vector.h:245
Definition of a analytical 2D plane embedded in 3D space.