VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
BoundaryConditions.h
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
33//=======================================================================================
34#ifndef BoundaryConditions_H
35#define BoundaryConditions_H
36
37#include <string>
38#include <vector>
39
40#include "D3Q27System.h"
41
48
51{
52public:
54 {
55 UB_STATIC_ASSERT(sizeof(long long) >= 8);
56 UB_STATIC_ASSERT((sizeof(long long) * 8) >= (d3q27_system::FENDDIR + 1) * BoundaryConditions::optionDigits);
57
58 for (int fdir = d3q27_system::FSTARTDIR; fdir <= d3q27_system::FENDDIR; fdir++)
59 q[fdir] = -999.;
60 }
61 virtual ~BoundaryConditions() = default;
62
72
73 virtual bool hasBoundaryConditionFlag(const int &direction)
74 {
75 assert(direction >= d3q27_system::FSTARTDIR && direction <= d3q27_system::FENDDIR);
76
77 return (hasNoSlipBoundaryFlag(direction) || hasSlipBoundaryFlag(direction) ||
78 hasDensityBoundaryFlag(direction) || hasVelocityBoundaryFlag(direction) ||
79 hasWallModelBoundaryFlag(direction));
80 }
81
82protected:
83 void setFlagBits(long long &flag, const int &direction, const short &secOpt)
84 {
85 if ((secOpt + 1) > maxOptionVal)
86 throw UbException(UB_EXARGS, "error: option > " + ub_system::toString(maxOptionVal - 1));
87
88 // all digits at the respective positions to "0"
89 flag &= ~(maxOptionVal << (direction * optionDigits));
90 // set all digits according to the flag at the respective positions
91 flag |= ((long long)(secOpt + 1) << (direction * optionDigits));
92 }
93
94public:
95 /*===================== NoSlip Boundary ==================================================*/
96 void setNoSlipBoundaryFlag(const int &direction, const short &secOpt = 0)
97 {
98 this->setFlagBits(noslipBoundaryFlags, direction, secOpt);
99 }
100 void unsetNoSlipBoundaryFlag(const int &direction)
101 {
102 this->noslipBoundaryFlags &= ~(maxOptionVal << (direction * optionDigits));
103 }
105 long long getNoSlipBoundary() { return this->noslipBoundaryFlags; }
106 bool hasNoSlipBoundary() { return (noslipBoundaryFlags != 0); }
107 bool hasNoSlipBoundaryFlag(const int &direction)
108 {
109 return (((noslipBoundaryFlags >> (optionDigits * direction)) & maxOptionVal) != 0);
110 }
111 short getNoSlipSecondaryOption(const int &direction)
112 {
113 return (short)(((noslipBoundaryFlags >> (optionDigits * direction)) & maxOptionVal) - 1);
114 }
115 /*===================== WallModel Boundary ==================================================*/
116 void setWallModelBoundaryFlag(const int &direction, const short &secOpt = 0)
117 {
118 this->setFlagBits(wallModelBoundaryFlags, direction, secOpt);
119 }
120 void unsetWallModelBoundaryFlag(const int &direction)
121 {
122 this->wallModelBoundaryFlags &= ~(maxOptionVal << (direction * optionDigits));
123 }
125 long long getWallModelBoundary() { return this->wallModelBoundaryFlags; }
127 bool hasWallModelBoundaryFlag(const int &direction)
128 {
129 return (((wallModelBoundaryFlags >> (optionDigits * direction)) & maxOptionVal) != 0);
130 }
131 short getWallModelSecondaryOption(const int &direction)
132 {
133 return (short)(((wallModelBoundaryFlags >> (optionDigits * direction)) & maxOptionVal) - 1);
134 }
135 /*===================== Slip-Solid Boundary ==================================================*/
136 void setSlipBoundaryFlag(const int &direction, const short &secOpt = 0)
137 {
138 this->setFlagBits(slipBoundaryFlags, direction, secOpt);
139 }
140 void unsetSlipBoundaryFlag(const int &direction)
141 {
142 this->slipBoundaryFlags &= ~(maxOptionVal << (direction * optionDigits));
143 }
145 long long getSlipBoundary() { return this->slipBoundaryFlags; }
146 bool hasSlipBoundary() { return (slipBoundaryFlags != 0); }
147 bool hasSlipBoundaryFlag(const int &direction)
148 {
149 return (((slipBoundaryFlags >> (optionDigits * direction)) & maxOptionVal) != 0);
150 }
151 short getSlipSecondaryOption(const int &direction)
152 {
153 return (short)(((slipBoundaryFlags >> (optionDigits * direction)) & maxOptionVal) - 1);
154 }
155 void setNormalVector(const float &nx1, const float &nx2, const float &nx3)
156 {
157 this->nx1 = nx1;
158 this->nx2 = nx2;
159 this->nx3 = nx3;
160 }
162
163 /*============== Velocity Boundary ========================*/
164 void setVelocityBoundaryFlag(const int &direction, const short &secOpt = 0)
165 {
166 this->setFlagBits(velocityBoundaryFlags, direction, secOpt);
167 }
168 void unsetVelocityBoundaryFlag(const int &direction)
169 {
170 this->velocityBoundaryFlags &= ~(maxOptionVal << (direction * optionDigits));
171 }
173 long long getVelocityBoundary() { return this->velocityBoundaryFlags; }
174 bool hasVelocityBoundary() { return this->velocityBoundaryFlags != 0; }
175 bool hasVelocityBoundaryFlag(const int &direction)
176 {
177 return (((velocityBoundaryFlags >> (optionDigits * direction)) & maxOptionVal) != 0);
178 }
179 short getVelocitySecondaryOption(const int &direction)
180 {
181 return (short)(((velocityBoundaryFlags >> (optionDigits * direction)) & maxOptionVal) - 1);
182 }
183
185 {
186 setBoundaryVelocityX1((float)vx[0]);
187 setBoundaryVelocityX2((float)vx[1]);
188 setBoundaryVelocityX3((float)vx[2]);
189 }
190 void setBoundaryVelocityX1(const float &vx1) { this->bcVelocityX1 = vx1; }
191 void setBoundaryVelocityX2(const float &vx2) { this->bcVelocityX2 = vx2; }
192 void setBoundaryVelocityX3(const float &vx3) { this->bcVelocityX3 = vx3; }
193 float getBoundaryVelocityX1() { return this->bcVelocityX1; }
194 float getBoundaryVelocityX2() { return this->bcVelocityX2; }
195 float getBoundaryVelocityX3() { return this->bcVelocityX3; }
196 float getBoundaryVelocity(const int &direction)
197 {
198 using namespace vf::lbm::dir;
199
200 switch (direction) {
201 case dP00:
202 return (float)(vf::basics::constant::c4o9 *
203 (+bcVelocityX1)); //(2/cs^2)(=6)*rho_0(=1 bei inkompr)*wi*u*ei mit cs=1/sqrt(3)
204 case dM00:
205 return (float)(vf::basics::constant::c4o9 *
206 (-bcVelocityX1)); // z.B. aus paper manfred MRT LB models in three dimensions (2002)
207 case d0P0:
208 return (float)(vf::basics::constant::c4o9 * (+bcVelocityX2));
209 case d0M0:
210 return (float)(vf::basics::constant::c4o9 * (-bcVelocityX2));
211 case d00P:
212 return (float)(vf::basics::constant::c4o9 * (+bcVelocityX3));
213 case d00M:
214 return (float)(vf::basics::constant::c4o9 * (-bcVelocityX3));
215 case dPP0:
216 return (float)(vf::basics::constant::c1o9 * (+bcVelocityX1 + bcVelocityX2));
217 case dMM0:
218 return (float)(vf::basics::constant::c1o9 * (-bcVelocityX1 - bcVelocityX2));
219 case dPM0:
220 return (float)(vf::basics::constant::c1o9 * (+bcVelocityX1 - bcVelocityX2));
221 case dMP0:
222 return (float)(vf::basics::constant::c1o9 * (-bcVelocityX1 + bcVelocityX2));
223 case dP0P:
224 return (float)(vf::basics::constant::c1o9 * (+bcVelocityX1 + bcVelocityX3));
225 case dM0M:
226 return (float)(vf::basics::constant::c1o9 * (-bcVelocityX1 - bcVelocityX3));
227 case dP0M:
228 return (float)(vf::basics::constant::c1o9 * (+bcVelocityX1 - bcVelocityX3));
229 case dM0P:
230 return (float)(vf::basics::constant::c1o9 * (-bcVelocityX1 + bcVelocityX3));
231 case d0PP:
232 return (float)(vf::basics::constant::c1o9 * (+bcVelocityX2 + bcVelocityX3));
233 case d0MM:
234 return (float)(vf::basics::constant::c1o9 * (-bcVelocityX2 - bcVelocityX3));
235 case d0PM:
236 return (float)(vf::basics::constant::c1o9 * (+bcVelocityX2 - bcVelocityX3));
237 case d0MP:
238 return (float)(vf::basics::constant::c1o9 * (-bcVelocityX2 + bcVelocityX3));
239 case dPPP:
240 return (float)(vf::basics::constant::c1o36 * (+bcVelocityX1 + bcVelocityX2 + bcVelocityX3));
241 case dMMM:
242 return (float)(vf::basics::constant::c1o36 * (-bcVelocityX1 - bcVelocityX2 - bcVelocityX3));
243 case dPPM:
244 return (float)(vf::basics::constant::c1o36 * (+bcVelocityX1 + bcVelocityX2 - bcVelocityX3));
245 case dMMP:
246 return (float)(vf::basics::constant::c1o36 * (-bcVelocityX1 - bcVelocityX2 + bcVelocityX3));
247 case dPMP:
248 return (float)(vf::basics::constant::c1o36 * (+bcVelocityX1 - bcVelocityX2 + bcVelocityX3));
249 case dMPM:
250 return (float)(vf::basics::constant::c1o36 * (-bcVelocityX1 + bcVelocityX2 - bcVelocityX3));
251 case dPMM:
252 return (float)(vf::basics::constant::c1o36 * (+bcVelocityX1 - bcVelocityX2 - bcVelocityX3));
253 case dMPP:
254 return (float)(vf::basics::constant::c1o36 * (-bcVelocityX1 + bcVelocityX2 + bcVelocityX3));
255 default:
256 throw UbException(UB_EXARGS, "unknown error");
257 }
258 }
259
260 //Multiphase
261 void setBoundaryPhaseField(const float &phiBC) { this->bcPhaseField = phiBC; }
262 float getBoundaryPhaseField() { return this->bcPhaseField; }
263
264 /*============== Density Boundary ========================*/
265 void setDensityBoundaryFlag(const int &direction, const short &secOpt = 0)
266 {
267 this->setFlagBits(densityBoundaryFlags, direction, secOpt);
268 }
269 void unsetDensityBoundaryFlag(const int &direction)
270 {
271 this->densityBoundaryFlags &= ~(maxOptionVal << (direction * optionDigits));
272 }
274 long long getDensityBoundary() { return this->densityBoundaryFlags; }
275 bool hasDensityBoundary() { return (this->densityBoundaryFlags != 0); }
276 bool hasDensityBoundaryFlag(const int &direction)
277 {
278 return (((densityBoundaryFlags >> (optionDigits * direction)) & maxOptionVal) != 0);
279 }
280 short getDensitySecondaryOption(const int &direction)
281 {
282 return (short)(((densityBoundaryFlags >> (optionDigits * direction)) & maxOptionVal) - 1);
283 }
284
285 void setBoundaryDensity(float density) { this->bcDensity = density; }
286 float getBoundaryDensity() { return this->bcDensity; }
287
288 /*======================= Qs =============================*/
289 void setQ(const float &val, const int &direction) { q[direction] = val; }
290 float getQ(const int &direction) { return q[direction]; }
291
292 virtual std::vector<std::string> getBCNames()
293 {
294 std::vector<std::string> tmp;
295 tmp.push_back("NoSlipBC");
296 tmp.push_back("SlipBC");
297 tmp.push_back("VelocityBC");
298 tmp.push_back("DensityBC");
299 return tmp;
300 }
301 virtual std::vector<long long> getBCFlags()
302 {
303 std::vector<long long> tmp;
304 tmp.push_back(noslipBoundaryFlags);
305 tmp.push_back(slipBoundaryFlags);
306 tmp.push_back(velocityBoundaryFlags);
307 tmp.push_back(densityBoundaryFlags);
308 return tmp;
309 }
310
311 static bool hasFlagForDirection(const long long &flag, const int &direction)
312 {
313 return (((flag >> (optionDigits * direction)) & maxOptionVal) != 0);
314 }
315
316 void setBCStrategyKey(char key) { bcStrategyKey = key; }
318
319public:
320 static const int optionDigits = 2; //--> 2 bits for secondary Option --> maxOptionVal = 7
321 static const long long maxOptionVal; // = ( 1<<optionDigits ) - 1; //2^3-1 -> 7
322
323protected:
324 float q[d3q27_system::FENDDIR + 1];
325
326 long long noslipBoundaryFlags{ 0 };
327 long long slipBoundaryFlags{ 0 };
328 long long velocityBoundaryFlags{ 0 };
329 long long densityBoundaryFlags{ 0 };
331
332 float bcVelocityX1{ 0.0 };
333 float bcVelocityX2{ 0.0 };
334 float bcVelocityX3{ 0.0 };
335 float bcDensity{ 0.0 };
336 float bcPhaseField{ 0.0 };
337
338 float nx1{ vf::basics::constant::c0o1 }, nx2{ vf::basics::constant::c0o1 }, nx3{ vf::basics::constant::c0o1 };
339
340 char bcStrategyKey { 0 };
341
342private:
346};
347
348#endif
349
Definition of boundary conditions in grid generation.
void unsetSlipBoundaryFlag(const int &direction)
bool hasNoSlipBoundaryFlag(const int &direction)
void setBoundaryPhaseField(const float &phiBC)
void setBoundaryVelocity(const GbVector3D &vx)
void setBoundaryVelocityX3(const float &vx3)
void setNoSlipBoundaryFlag(const int &direction, const short &secOpt=0)
static bool hasFlagForDirection(const long long &flag, const int &direction)
void unsetWallModelBoundaryFlag(const int &direction)
short getVelocitySecondaryOption(const int &direction)
long long getWallModelBoundary()
void setSlipBoundaryFlag(const int &direction, const short &secOpt=0)
float getQ(const int &direction)
short getDensitySecondaryOption(const int &direction)
void setWallModelBoundaryFlag(const int &direction, const short &secOpt=0)
virtual bool hasBoundaryConditionFlag(const int &direction)
bool hasDensityBoundaryFlag(const int &direction)
void unsetVelocityBoundaryFlag(const int &direction)
UbTupleFloat3 getNormalVector()
bool hasSlipBoundaryFlag(const int &direction)
float getBoundaryVelocity(const int &direction)
virtual ~BoundaryConditions()=default
void unsetNoSlipBoundaryFlag(const int &direction)
void setBCStrategyKey(char key)
void setBoundaryDensity(float density)
long long getVelocityBoundary()
bool hasWallModelBoundaryFlag(const int &direction)
void unsetDensityBoundaryFlag(const int &direction)
void setQ(const float &val, const int &direction)
bool hasVelocityBoundaryFlag(const int &direction)
short getNoSlipSecondaryOption(const int &direction)
void setBoundaryVelocityX1(const float &vx1)
static const int optionDigits
float q[d3q27_system::FENDDIR+1]
virtual std::vector< long long > getBCFlags()
void setFlagBits(long long &flag, const int &direction, const short &secOpt)
void setVelocityBoundaryFlag(const int &direction, const short &secOpt=0)
void setDensityBoundaryFlag(const int &direction, const short &secOpt=0)
short getWallModelSecondaryOption(const int &direction)
short getSlipSecondaryOption(const int &direction)
void setNormalVector(const float &nx1, const float &nx2, const float &nx3)
void setBoundaryVelocityX2(const float &vx2)
virtual bool hasBoundaryCondition()
virtual std::vector< std::string > getBCNames()
This Class provides basic 3D vector objects.
Definition GbVector3D.h:47
Writes the grid each timestep into the files and reads the grip from the files before regenerating.
std::shared_ptr< T > SPtr
static const long long maxOptionVal
UbTypeOp< typenameUbDuoT< N, UbDuo< A, B > >::ResultT >::RefT val(UbDuo< A, B > &d)
Definition UbTuple.h:393
#define UB_STATIC_ASSERT(expr)
Definition UbSystem.h:527
#define UB_EXARGS
Definition UbException.h:73
UbTuple< T1 > makeUbTuple(T1 const &a1)
Definition UbTuple.h:554
std::string toString(const T &x, int precision=15)
Definition UbSystem.h:199