OpenLB 1.7
Loading...
Searching...
No Matches
frameChangeF2D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2014-2015 Mathias J. Krause, Marie-Luise Maier
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 ANALYTICAL_FRAME_CHANGE_F_2D_HH
25#define ANALYTICAL_FRAME_CHANGE_F_2D_HH
26
27#include<vector>
28#include<cmath>
29#include<string>
30
31#include "frameChangeF2D.h"
32#include "frameChangeF3D.h"
33#include "functors/genericF.h"
34#include "analyticalF.h"
37
38#include "core/superLattice2D.h"
39#include "dynamics/lbm.h" // for computation of lattice rho and velocity
40#include "utilities/vectorHelpers.h" // for normalize
41
42
43namespace olb {
44
45template <typename T>
46PowerLaw2D<T>::PowerLaw2D(std::vector<T> axisPoint, std::vector<T> axisDirection, T maxVelocity, T radius, T exponent) : AnalyticalF2D<T,T>(2)
47{
48 this->getName() = "PowerLaw2D";
49 _axisPoint.resize(2);
50 _axisDirection.resize(2);
51 for (int i = 0; i < 2; ++i) {
52 _axisDirection[i] = axisDirection[i];
53 _axisPoint[i] = axisPoint[i];
54 }
55 _maxVelocity = maxVelocity;
56 _radius = radius;
57 _exponent = exponent;
58}
59
60template <typename T>
61PowerLaw2D<T>::PowerLaw2D(SuperGeometry<T,2>& superGeometry, int material, T maxVelocity, T distance2Wall, T exponent) : AnalyticalF2D<T,T>(2)
62{
63 this->getName() = "PowerLaw2D";
64 _axisPoint.resize(2);
65 _axisDirection.resize(2);
66 _axisPoint = superGeometry.getStatistics().getCenterPhysR(material);
67 std::vector<int> discreteNormal = superGeometry.getStatistics().computeDiscreteNormal(material);
68 for (int i = 0; i < 2; ++i) {
69 _axisDirection[i] = discreteNormal[i];
70 }
71
72 _radius = T(distance2Wall);
73 for (int iD = 0; iD < 2; iD++) {
74 _radius += (superGeometry.getStatistics().getPhysRadius(material)[iD]);
75 }
76 _maxVelocity = maxVelocity;
77 _exponent = exponent;
78}
79
80
81template <typename T>
82bool PowerLaw2D<T>::operator()(T output[], const T x[])
83{
84 T d = util::fabs(_axisDirection[1]*(x[0] - _axisPoint[0]) - _axisDirection[0]*(x[1] - _axisPoint[1]));
85 output[0] = _maxVelocity*_axisDirection[0]*(1. - util::pow(d/_radius,_exponent));
86 output[1] = _maxVelocity*_axisDirection[1]*(1. - util::pow(d/_radius,_exponent));
87 if ( 1. - util::pow(d/_radius,_exponent) < 0.) {
88 output[0] = T();
89 output[1] = T();
90 }
91 return true;
92}
93
94
95template <typename T>
96Poiseuille2D<T>::Poiseuille2D(std::vector<T> axisPoint, std::vector<T> axisDirection, T maxVelocity, T radius) : PowerLaw2D<T>(axisPoint, axisDirection, maxVelocity, radius, 2)
97{
98 this->getName() = "Poiseuille2D";
99}
100
101
102template <typename T>
103Poiseuille2D<T>::Poiseuille2D(SuperGeometry<T,2>& superGeometry, int material, T maxVelocity, T distance2Wall) : PowerLaw2D<T>(superGeometry, material, maxVelocity, distance2Wall, 2)
104{
105 this->getName() = "Poiseuille2D";
106}
107
108
109template <typename T, typename S, typename DESCRIPTOR>
111 : AnalyticalF2D<T,S>(4), _lengthY(ly), _maxVelocity(converter.getCharPhysVelocity())
112{
113 this->getName() = "PoiseuilleStrainRate2D";
114}
115
116
117template <typename T, typename S, typename DESCRIPTOR>
119{
120 T y = input[1];
121
122 T DuDx = T();
123 T DuDy = (T) _maxVelocity*(-2.*(y-(_lengthY/2.))/((_lengthY/2.)*(_lengthY/2.)));
124 T DvDx = T();
125 T DvDy = T();
126
127 output[0] = (DuDx + DuDx)/2.;
128 output[1] = (DuDy + DvDx)/2.;
129 output[2] = (DvDx + DuDy)/2.;
130 output[3] = (DvDy + DvDy)/2.;
131
132 return true;
133};
134
135template <typename T>
136AnalyticalPorousVelocity2D<T>::AnalyticalPorousVelocity2D(std::vector<T> axisDirection_, T K_, T mu_, T gradP_, T radius_, T eps_)
137 : AnalyticalF2D<T,T>(2), axisDirection(axisDirection_), K(K_), mu(mu_), gradP(gradP_),radius(radius_), eps(eps_)
138{
139 this->getName() = "AnalyticalPorousVelocity2D";
140};
141
142
143template <typename T>
145{
146 T uMax = K / mu*gradP*(1. - 1./(util::cosh((util::sqrt(1./K))*radius)));
147
148 return uMax/eps;
149};
150
151
152template <typename T>
153bool AnalyticalPorousVelocity2D<T>::operator()(T output[], const T input[])
154{
155 output[0] = K / mu*gradP*(1. - (util::cosh((util::sqrt(1./K))*(input[1] - radius)))/(util::cosh((util::sqrt(1./K))*radius)));
156 output[1] = K / mu*gradP*(1. - (util::cosh((util::sqrt(1./K))*(input[0] - radius)))/(util::cosh((util::sqrt(1./K))*radius)));
157
158 output[0] *= axisDirection[0]/eps;
159 output[1] *= axisDirection[1]/eps;
160
161 return true;
162};
163
164
166
167
168// constructor to obtain Cartesian coordinates of polar coordinates,
169// with _polarOrigin, in x-y-plane
170template<typename T, typename S>
172 : AnalyticalF2D<T, S>(2),
173 _polarOrigin(polarOrigin)
174{
175 this->getName() = "const";
176}
177
178// operator returns Cartesian coordinates of polar coordinates,
179// input is x[0] = radius , x[1] = phi
180template<typename T, typename S>
181bool PolarToCartesian2D<T, S>::operator()(T output[], const S x[])
182{
183 output[0] = x[0]*util::cos(x[1]) + _polarOrigin[0];
184 output[1] = x[0]*util::sin(x[1]) + _polarOrigin[1];
185 return true;
186}
187
188
189// constructor to obtain polar coordinates of Cartesian coordinates
190template<typename T, typename S>
192 T cartesianOriginY, T cartesianOriginZ,
193 T axisDirectionX, T axisDirectionY, T axisDirectionZ,
194 T orientationX, T orientationY, T orientationZ)
195 : AnalyticalF2D<T, S>(2)
196{
197 _cartesianOrigin[0] = cartesianOriginX;
198 _cartesianOrigin[1] = cartesianOriginY;
199 _cartesianOrigin[2] = cartesianOriginZ;
200
201 _axisDirection[0] = axisDirectionX;
202 _axisDirection[1] = axisDirectionY;
203 _axisDirection[2] = axisDirectionZ;
204
205 _orientation[0] = orientationX;
206 _orientation[1] = orientationY;
207 _orientation[2] = orientationZ;
208}
209
210template<typename T, typename S>
212 olb::Vector<T, 3> axisDirection,
213 olb::Vector<T, 3> orientation)
214 : AnalyticalF2D<T, S>(2),
215 _cartesianOrigin(cartesianOrigin),
216 _axisDirection(axisDirection),
217 _orientation(orientation)
218{
219 this->getName() = "const";
220}
221
222// operator returns polar coordinates, output[0] = radius(>= 0),
223// output[1] = phi in [0, 2Pi)
224template<typename T, typename S>
225bool CartesianToPolar2D<T, S>::operator()(T output[], const S x[])
226{
227 //Vector<T, 3> x_rot(x[this->getSourceDim()]); //// CAUSES ERROR
228 int dim = this->getSourceDim();
229 //std::cout<<"Source dim return: "<<dim<<std::endl; //sourceDim = 2
230 Vector<T, 3> x_rot;
231 for (int i = 0; i < dim; ++i) {
232 x_rot[i] = x[i];
233 }
234 Vector<T, 3> e3(T(), T(), 1);
235 Vector<T, 3> axisDirection(_axisDirection);
236
237 Vector<T, 3> normal = crossProduct3D(axisDirection, e3);
238 Vector<T, 3> normalAxisDir(axisDirection);
239 normalAxisDir = normalize(normalAxisDir);
240
241 // if axis has to be rotated
242 if (!( util::nearZero(normalAxisDir[0]) && util::nearZero(normalAxisDir[1]) && util::nearZero(normalAxisDir[2]-1) ) ) {
243
244 if ( !util::nearZero(olb::norm(_orientation)) ) {
245 normal = _orientation;
246 }
247
248 // normal is orientation direction
250 T tmp[3] = {_axisDirection[0],_axisDirection[1],_axisDirection[2]};
251 T alpha[1] = {};
252 angle(alpha, tmp);
253
254 // cross is rotation axis
255 //Vector<T, 3> cross = crossProduct3D(e3, axisDirection);
256 // rotation with angle alpha to rotAxisDir
257 RotationRoundAxis3D<T, S> rotRAxis(_cartesianOrigin, util::fromVector3(normal), -alpha[0]);
258 T x_tmp[3] = {};
259 x_tmp[0] = x[0];
260 x_tmp[1] = x[1];
261 x_tmp[2] = x[2];
262 T tmp2[3] = {};
263 rotRAxis(tmp2,x_tmp);
264 x_rot[0] = tmp2[0];
265 x_rot[1] = tmp2[1];
266 x_rot[2] = tmp2[2];
267 }
268
269 // calculates r, phi related to cartesianAxisDirection and their origin
270 Vector<T, 2> difference;
271 difference[0] = x_rot[0] - _cartesianOrigin[0];
272 difference[1] = x_rot[1] - _cartesianOrigin[1];
273 T distance = T();
274
275 for (int i = 0; i < 2; ++i) {
276 distance += difference[i]*difference[i];
277 }
278
279 distance = util::sqrt(distance);
280 T phi[1] = {};
281
282 if (distance > T()) {
283 Vector<T, 3> e1(T(1), T(), T());
285
286 T x_help[3] = {difference[0],difference[1],0.};
287 angle(phi, x_help);
288 }
289
290 output[0] = distance;
291 output[1] = phi[0];
292 return true;
293}
294
295} // end namespace olb
296#endif
AnalyticalF are applications from DD to XD, where X is set by the constructor.
bool operator()(T output[], const T input[]) override
AnalyticalPorousVelocity2D(std::vector< T > axisDirection_, T K_, T mu_, T gradP_, T radius_, T eps_=T(1))
This class calculates the angle alpha between vector _referenceVector and any other vector x.
CartesianToPolar2D(olb::Vector< T, 3 > cartesianOrigin, olb::Vector< T, 3 > axisDirection, olb::Vector< T, 3 > orientation={T(1), T(), T()})
olb::Vector< T, 3 > _cartesianOrigin
origin of the Cartesian coordinate system
bool operator()(T output[], const S x[]) override
operator writes polar coordinates of Cartesian point x into output field, returns output[0] = radius ...
olb::Vector< T, 3 > _orientation
direction to know orientation for math positive to obtain angle phi of Cartesian point x
olb::Vector< T, 3 > _axisDirection
direction of the axis along which the polar coordinates are calculated
std::string & getName()
read and write access to name
Definition genericF.hh:51
Poiseuille2D(std::vector< T > axisPoint, std::vector< T > axisDirection, T maxVelocity, T radius)
bool operator()(T output[], const S input[]) override
has to be implemented for 'every' derived class
PoiseuilleStrainRate2D(UnitConverter< T, DESCRIPTOR > const &converter, T ly)
bool operator()(T output[], const S x[]) override
operator writes Cartesian coordinates of polar coordinates x[0] = radius >= 0, x[1] = phi in [0,...
PolarToCartesian2D(olb::Vector< T, 3 > polarOrigin)
constructor to obtain Cartesian coordinates of polar coordinates
PowerLaw2D(std::vector< T > axisPoint, std::vector< T > axisDirection, T maxVelocity, T radius, T exponent)
std::vector< T > _axisDirection
std::vector< T > _axisPoint
bool operator()(T output[], const T input[]) override
This class saves coordinates of the resulting point after rotation in the output field.
Representation of a statistic for a parallel 2D geometry.
SuperGeometryStatistics< T, D > & getStatistics()
Returns the statistics object.
Conversion between physical and lattice units, as well as discretization.
Plain old scalar vector.
Definition vector.h:47
This file contains two different classes of functors, in the FIRST part.
This file contains two different classes of functors, in the FIRST part.
The description of a generic interface for all functor classes – header file.
cpu::simd::Pack< T > sqrt(cpu::simd::Pack< T > value)
Definition pack.h:100
std::vector< T > fromVector3(const Vector< T, 3 > &vec)
ADf< T, DIM > sin(const ADf< T, DIM > &a)
Definition aDiff.h:569
cpu::simd::Pack< T > pow(cpu::simd::Pack< T > base, cpu::simd::Pack< T > exp)
Definition pack.h:112
ADf< T, DIM > cosh(const ADf< T, DIM > &a)
Definition aDiff.h:657
cpu::simd::Pack< T > fabs(cpu::simd::Pack< T > value)
Definition pack.h:106
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 T norm(const ScalarVector< T, D, IMPL > &a)
Euclidean vector norm.
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
Representation of a parallel 2D geometry – header file.
The description of a 2D super lattice – header file.