OpenLB 1.7
Loading...
Searching...
No Matches
hyperplaneLattice2D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2018 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_2D_HH
25#define HYPERPLANE_LATTICE_2D_HH
26
27#include "hyperplaneLattice2D.h"
29
30namespace olb {
31
32template <typename T>
33int HyperplaneLattice2D<T>::computeMaxLatticeDistance() const
34{
35 const Cuboid2D<T>& cuboid = _geometry.getMotherCuboid();
36 const Vector<T,2> origin = cuboid.getOrigin();
37 const Vector<int,2> extend = cuboid.getExtent();
38 const T deltaR = cuboid.getDeltaR();
39
40 T maxPhysDistance = T();
41 T tmp;
42 Vector<T,2> tmpO;
43 Vector<T,2> tmpE;
44
45 for (int iDim=0; iDim<2; ++iDim) {
46 tmpO[iDim] = origin[iDim] - _origin[iDim];
47 tmpE[iDim] = origin[iDim] + extend[iDim]*deltaR - _origin[iDim];
48 }
49 tmp = util::sqrt(tmpO[0]*tmpO[0] + tmpO[1]*tmpO[1]);
50 if (maxPhysDistance < tmp) {
51 maxPhysDistance = tmp;
52 }
53 tmp = util::sqrt((tmpE[0]*tmpE[0] + tmpO[1]*tmpO[1]));
54 if (maxPhysDistance < tmp) {
55 maxPhysDistance = tmp;
56 }
57 tmp = util::sqrt(tmpO[0]*tmpO[0] + tmpE[1]*tmpE[1]);
58 if (maxPhysDistance < tmp) {
59 maxPhysDistance = tmp;
60 }
61 tmp = util::sqrt(tmpE[0]*tmpE[0] + tmpE[1]*tmpE[1]);
62 if (maxPhysDistance < tmp) {
63 maxPhysDistance = tmp;
64 }
65
66 return int(maxPhysDistance/_h) + 1;
67}
68
69template <typename T>
70void HyperplaneLattice2D<T>::constructCuboid(int maxLatticeDistance)
71{
72 int iC;
73 int min = -maxLatticeDistance;
74 int max = maxLatticeDistance;
75
76 for ( int i = -maxLatticeDistance; i < maxLatticeDistance; ++i ) {
77 if ( _geometry.getC(getPhysR(i), iC) ) {
78 min = i;
79 break;
80 }
81 }
82 for ( int i = maxLatticeDistance; i > -maxLatticeDistance; --i ) {
83 if ( _geometry.getC(getPhysR(i), iC) ) {
84 max = i;
85 break;
86 }
87 }
88
89 _n = max - min + 1;
90 _origin = _origin + T(min)*_u;
91}
92
93template <typename T>
94void HyperplaneLattice2D<T>::setToResolution(int resolution)
95{
96 T newH = _n*_h/(T) resolution;
97 _n = resolution;
98 _h = newH;
99 _u = normalize(_u, _h);
100}
101
102template<typename T>
104 CuboidGeometry2D<T>& geometry, Hyperplane2D<T> hyperplane)
105 : _geometry(geometry),
106 _hyperplane(hyperplane),
107 _origin(hyperplane.origin),
108 _u(hyperplane.u),
109 _h(geometry.getMinDeltaR())
110{
111 _u = normalize(_u, _h);
112
113 const int maxLatticeDistance = computeMaxLatticeDistance();
114 // compute _hyperplane.origin, _nx, _ny so that the cuboid is right inside the geometry
115 constructCuboid(maxLatticeDistance);
116}
117
118template<typename T>
120 CuboidGeometry2D<T>& geometry, Hyperplane2D<T> hyperplane, int resolution)
121 : _geometry(geometry),
122 _hyperplane(hyperplane),
123 _origin(hyperplane.origin),
124 _u(hyperplane.u),
125 _h(geometry.getMinDeltaR())
126{
127 _u = normalize(_u, _h);
128
129 const int maxLatticeDistance = computeMaxLatticeDistance();
130 // compute _hyperplane.origin, _nx, _ny so that the cuboid is right inside the geometry
131 constructCuboid(maxLatticeDistance);
132
133 if ( resolution > 0 ) {
134 setToResolution(resolution);
135 }
136}
137
138template<typename T>
140 CuboidGeometry2D<T>& geometry, Hyperplane2D<T> hyperplane, T h)
141 : _geometry(geometry),
142 _hyperplane(hyperplane),
143 _origin(hyperplane.origin),
144 _u(hyperplane.u),
145 _h(h)
146{
147 if ( util::nearZero(_h) ) {
148 _h = _geometry.getMinDeltaR();
149 }
150
151 _u = normalize(_u, _h);
152
153 const int maxLatticeDistance = computeMaxLatticeDistance();
154 // compute _hyperplane.origin, _nx, _ny so that the cuboid is right inside the geometry
155 constructCuboid(maxLatticeDistance);
156}
157
158template <typename T>
160{
161 return _hyperplane;
162}
163
164template <typename T>
166{
167 return Vector<T,2> {
168 _origin[0] + T(n)*_u[0],
169 _origin[1] + T(n)*_u[1]
170 };
171}
172
173template <typename T>
175{
176 return _n;
177}
178
179template <typename T>
181{
182 return _h;
183}
184
185template <typename T>
187{
188 return _origin;
189}
190
191template <typename T>
193{
194 return _u;
195}
196
197
198}
199
200#endif
A cuboid structure represents the grid of a considered domain.
HyperplaneLattice2D(CuboidGeometry2D< T > &geometry, Hyperplane2D< T > hyperplane)
Constructor for automatic discretization.
Vector< T, 2 > getPhysR(const int &n) const
Transform 1d lattice coordinates to their physical 2d location.
T _h
Distance between discrete lattice points.
const Hyperplane2D< T > & getHyperplane() const
Vector< T, 2 > getPhysOrigin() const
Vector< T, 2 > getVectorU() const
Vector< T, 2 > _u
Direction vector of the lattice, normalized to grid width _h.
Plain old scalar vector.
Definition vector.h:47
Pack< T > min(Pack< T > rhs, Pack< T > lhs)
Definition 256.h:406
Pack< T > max(Pack< T > rhs, Pack< T > lhs)
Definition 256.h:416
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 line embedded in 2D space.