VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
BoundaryCondition.cpp
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//
32//=======================================================================================
33#include "BoundaryCondition.h"
34
35#include <cmath>
36#include <stdexcept>
37
38#include "DataTypes.h"
41#include "grid/Grid.h"
43
44namespace vf::gpu {
45
47{
48 return this->side->whoAmI() == side;
49}
51
53 SPtr<Grid> grid, std::function<void(real, real, real, real &, real &, real &)> velocityProfile)
54{
55 for (uint index = 0; index < this->indices.size(); index++) {
56
57 real x, y, z;
58
59 grid->transIndexToCoords(this->indices[index], x, y, z);
60
61 velocityProfile(x, y, z, this->vxList[index], this->vyList[index], this->vzList[index]);
62 }
63}
64
66
70 real v, real r)
71{
72 for( uint index = 0; index < this->indices.size(); index++ ){
73 if( this->patches[index] == patch ){
74
75 real x, y, z;
76
77 grid->transIndexToCoords( this->indices[index], x, y, z );
78
79 real pVecX = p2x - p1x;
80 real pVecY = p2y - p1y;
81 real pVecZ = p2z - p1z;
82
83 real xVecX = x - p1x;
84 real xVecY = y - p1y;
85 real xVecZ = z - p1z;
86
87 // compute and normalize tangent
88
92
94
98
99 // compute distance from rotation axis
100
102
103 real d = sqrt( ( xVecX - projection * pVecX ) * ( xVecX - projection * pVecX )
104 + ( xVecY - projection * pVecY ) * ( xVecY - projection * pVecY )
105 + ( xVecZ - projection * pVecZ ) * ( xVecZ - projection * pVecZ ) );
106
107 this->vxList[index] = tangentX * d / r * v;
108 this->vyList[index] = tangentY * d / r * v;
109 this->vzList[index] = tangentZ * d / r * v;
110
111 }
112 }
113}
114
116
118{
119 using namespace vf::lbm::dir;
121 grid->transIndexToCoords(index, nodeX, nodeY, nodeZ);
122 const auto normal = side->getNormal();
123 const real samplingOffsetFromNode = static_cast<real>(getSamplingOffset() - 1);
124 const real samplingX = nodeX - normal[0] * grid->getDelta() * samplingOffsetFromNode;
125 const real samplingY = nodeY - normal[1] * grid->getDelta() * samplingOffsetFromNode;
126 const real samplingZ = nodeZ - normal[2] * grid->getDelta() * samplingOffsetFromNode;
127 const uint samplingIndex = grid->transCoordToIndex(samplingX, samplingY, samplingZ);
129 throw std::runtime_error("StressBoundaryCondition::setAdditionalIndices could not find sampling index");
130 samplingIndices.push_back(samplingIndex);
131
132 const auto qNode = qs.back();
134 switch (side->whoAmI()) {
135 case SideType::PX:
137 break;
138 case SideType::MX:
140 break;
141 case SideType::PY:
143 break;
144 case SideType::MY:
146 break;
147 case SideType::PZ:
149 break;
150 case SideType::MZ:
152 break;
153 default:
154 throw std::runtime_error("Side type not implemented!");
155 }
156
157 const real samplingDistance =
158 std::hypot(samplingX - nodeX, samplingY - nodeY, samplingZ - nodeZ) / grid->getDelta() + distanceNodeToWall;
159 samplingDistanceList.push_back(samplingDistance);
160 if (roughnessMap) {
161 const real wallX = nodeX + normal[0] * vf::basics::constant::c1o2 * grid->getDelta();
162 const real wallY = nodeY + normal[1] * vf::basics::constant::c1o2 * grid->getDelta();
163 const real wallZ = nodeZ + normal[2] * vf::basics::constant::c1o2 * grid->getDelta();
164 const real roughnessLength = roughnessMap->interpolateToPoint({ wallX, wallY, wallZ });
165 roughnessLengthList.push_back(roughnessLength / grid->getDelta());
166 }
167}
168
170{
171
172 real x, y, z;
173 grid->transIndexToCoords(index, x, y, z);
174
175 real nx = x;
176 real ny = y;
177 real nz = z;
178
179 if (side->getCoordinate() == X_INDEX)
180 nx = -side->getDirection() * grid->getDelta() + x;
181 if (side->getCoordinate() == Y_INDEX)
182 ny = -side->getDirection() * grid->getDelta() + y;
183 if (side->getCoordinate() == Z_INDEX)
184 nz = -side->getDirection() * grid->getDelta() + z;
185
186 uint neighborIndex = grid->transCoordToIndex(nx, ny, nz);
187 neighborIndices.push_back(neighborIndex);
188}
189
191{
192 if (!reader)
193 throw std::runtime_error("PrecursorBoundaryCondition: reader has not been set");
194 return reader;
195}
196
198{
199 real x, y, z;
200 grid->transIndexToCoords(index, x, y, z);
201
202 real nx = x;
203 real ny = y;
204 real nz = z;
205
206 if (side->getCoordinate() == X_INDEX)
207 nx = -side->getDirection() * grid->getDelta() + x;
208 if (side->getCoordinate() == Y_INDEX)
209 ny = -side->getDirection() * grid->getDelta() + y;
210 if (side->getCoordinate() == Z_INDEX)
211 nz = -side->getDirection() * grid->getDelta() + z;
212
213 uint neighborIndex = grid->transCoordToIndex(nx, ny, nz);
214 neighborIndices.push_back(neighborIndex);
215}
216
218{
219 const real gradient = static_cast<real>(side->getDirection()) * this->gradient;
220 std::fill_n(std::back_inserter(this->vxList), this->indices.size(), vx);
221 std::fill_n(std::back_inserter(this->vyList), this->indices.size(), vy);
222 std::fill_n(std::back_inserter(this->vzList), this->indices.size(), vz);
223 std::fill_n(std::back_inserter(this->gradientList), this->indices.size(), gradient);
224}
225
227{
228 const real gradient = static_cast<real>(side->getDirection()) * this->gradient;
229 std::fill_n(std::back_inserter(this->normalXList), this->indices.size(), normalX);
230 std::fill_n(std::back_inserter(this->normalYList), this->indices.size(), normalY);
231 std::fill_n(std::back_inserter(this->normalZList), this->indices.size(), normalZ);
232 std::fill_n(std::back_inserter(this->gradientList), this->indices.size(), gradient);
233}
234
235}
236
void setAdditionalIndices(const SPtr< Grid > &grid, uint index) override
void setTangentialVelocityForPatch(SPtr< Grid > grid, uint patch, real p1x, real p1y, real p1z, real p2x, real p2y, real p2z, real v, real r)
SPtr< TransientBCInputFileReader > getReader()
void setAdditionalIndices(const SPtr< Grid > &grid, uint index) override
void setAdditionalIndices(const SPtr< Grid > &grid, uint index) override
void setVelocityProfile(SPtr< Grid > grid, std::function< void(real, real, real, real &, real &, real &)> velocityProfile)
std::shared_ptr< T > SPtr
float real
Definition DataTypes.h:42
unsigned int uint
Definition DataTypes.h:47
#define INVALID_INDEX
Definition DataTypes.h:48
@ z
Definition Axis.h:44
@ x
Definition Axis.h:42
@ y
Definition Axis.h:43
const uint ny
const uint nz
const uint nx
#define X_INDEX
Definition Side.h:46
#define Y_INDEX
Definition Side.h:47
#define Z_INDEX
Definition Side.h:48
SideType
Definition Side.h:63