VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
BoundaryValues.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 "BoundaryValues.h"
34
35#include "Parameter/Parameter.h"
36
37#include <iostream>
38#include <stdio.h>
39#include <stdlib.h>
40
41namespace vf::gpu {
42
44{
45 file.open(path.c_str(), std::ios::in);
46
47 if (!file) {
48 std::cerr << "error can not open value file:" << path << std::endl;
49 exit(1);
50 }
51 init();
52}
53
54BoundaryValues::BoundaryValues(std::string path, std::shared_ptr<Parameter> para, std::string str)
55{
56 if (!file) {
57 std::cerr << "error can not open value file:" << path << std::endl;
58 exit(1);
59 }
60
61 file.open(path.c_str(), std::ios::in);
62 if (!file) {
63 para->setObj(str, false);
64 } else {
65 init();
66 para->setObj(str, true);
67 }
68}
69
70
71BoundaryValues::BoundaryValues(int neighbor, std::shared_ptr<Parameter> para, std::string sor, std::string direction)
72{
73 if (direction=="X")
74 {
75 std::string ad = para->getPossNeighborFilesX(sor)[neighbor];
76 file.open(ad.c_str(), std::ios::in);
77
78 if (file.fail()) {
79 para->setIsNeighborX(false);
80 } else {
81 para->setIsNeighborX(true);
82 init();
83 }
84 }
85 else if (direction=="Y")
86 {
87 std::string ad = para->getPossNeighborFilesY(sor)[neighbor];
88 file.open(ad.c_str(), std::ios::in);
89
90 if (file.fail()) {
91 para->setIsNeighborY(false);
92 } else {
93 para->setIsNeighborY(true);
94 init();
95 }
96 }
97 else
98 {
99 std::string ad = para->getPossNeighborFilesZ(sor)[neighbor];
100 file.open(ad.c_str(), std::ios::in);
101
102 if (file.fail()) {
103 para->setIsNeighborZ(false);
104 } else {
105 para->setIsNeighborZ(true);
106 init();
107 }
108 }
109}
110
111
113{
114 file.close();
115}
116
117
118int BoundaryValues::getNumberOfColumns()
119{
120 if (boundaryCondition == "velocity")
121 return 3;
122 if (boundaryCondition == "noSlip")
123 return 3;
124 if (boundaryCondition == "pressure")
125 return 2;
126 if (boundaryCondition == "processor")
127 return 0;
128 if (boundaryCondition == "concentration")
129 return 0;
130 else
131 return -1;
132}
133
134
135void BoundaryValues::init()
136{
137 readBC();
138 readNumberOfLevels();
139 resizeVectors();
140
141 int maxColumn = getNumberOfColumns();
142
143 if (maxColumn == -1)
144 initalVectorsWithSingleZero();
145 else
146 initalVectors(maxColumn);
147}
148
149void BoundaryValues::initalVectors(uint maxColumn)
150{
151 for (uint level = 0; level <= maxLevel; level++)
152 {
153 readLevelSize(level);
154
155 if (levelSizes[level] == 0)
156 {
157 skipLine();
158 continue;
159 }
160
161 resizeVectorsPerLevel(level, maxColumn);
162
163 for (uint index = 0; index < levelSizes[level]; index++)
164 readData(level, index, maxColumn);
165
166 }
167}
168
169void BoundaryValues::readData(uint level, int index, uint maxColumn)
170{
171 file >> indices[level][index];
172 for (uint column = 0; column < maxColumn; column++)
173 file >> values[level][column][index];
174}
175
176void BoundaryValues::resizeVectorsPerLevel(uint level, uint maxColumn)
177{
178 values[level].resize(maxColumn);
179 indices[level].resize(levelSizes[level]);
180 for (uint column = 0; column < maxColumn; column++)
181 values[level][column].resize(levelSizes[level]);
182}
183
184void BoundaryValues::skipLine()
185{
186 std::string bufferString;
187 getline(file, bufferString);
188}
189
190void BoundaryValues::readLevelSize(uint level)
191{
192 file >> levelSizes[level];
193}
194
195void BoundaryValues::initalVectorsWithSingleZero()
196{
197 indices = { {0} };
198 values = { { {0.0} } };
199}
200
201void BoundaryValues::readNumberOfLevels()
202{
203 file >> maxLevel;
204}
205
206void BoundaryValues::readBC()
207{
208 file >> boundaryCondition;
209}
210
211void BoundaryValues::resizeVectors()
212{
213 levelSizes.resize(maxLevel + 1);
214 values.resize(maxLevel + 1);
215 indices.resize(maxLevel + 1);
216}
217
218void BoundaryValues::setBoundarys(std::vector<std::vector<std::vector<real> > > &qs) const
219{
220 for (uint level = 0; level < values.size(); level++)
221 for (uint index = 0; index < values[level].size(); index++)
222 for (uint value = 0; value < values[level][index].size(); value++)
223 qs[level][index].push_back(values[level][index][value]);
224}
225
227{
228 for (std::size_t index = 0; index < values[level][column].size(); index++)
229 velo[index] = values[level][column][index];
230}
231
233{
234 for (std::size_t i = 0; i < indices[level].size(); i++)
235 ptr[i] = indices[level][i];
236}
237
239{
240 return maxLevel;
241}
242
244{
245 return this->levelSizes[level];
246}
247
249{
250 return this->boundaryCondition;
251}
252
253
255{
256 procNeighbor = pN;
257}
258
260{
261 return procNeighbor;
262}
263
264
265void BoundaryValues::setPressValues(real *RhoBC, int* kN, int level) const
266{
267 for (std::size_t column = 0; column < values[level].size(); column++) {
268 for (std::size_t index = 0; index < values[level][column].size(); index++) {
269 if (column == 0) RhoBC[index] = values[level][column][index];
270 if (column == 1) kN[index] = (int)values[level][column][index];
271 }
272 }
273}
274
275void BoundaryValues::setVelocityValues(real *vx, real *vy, real *vz, int level) const
276{
277 for (std::size_t column = 0; column < values[level].size(); column++) {
278 for (std::size_t index = 0; index < values[level][column].size(); index++) {
279 if (column == 0) vx[index] = values[level][column][index];
280 if (column == 1) vy[index] = values[level][column][index];
281 if (column == 2) vz[index] = values[level][column][index];
282 }
283 }
284}
285
286void BoundaryValues::setOutflowValues(real *RhoBC, int* kN, int level) const
287{
288 for (std::size_t column = 0; column < values[level].size(); column++) {
289 for (std::size_t index = 0; index < values[level][column].size(); index++) {
290 if (column == 0) RhoBC[index] = values[level][column][index];
291 if (column == 1) kN[index] = (int)values[level][column][index];
292 }
293 }
294}
295
296}
297
void setValues(real *velo, uint level, uint column) const
void setVelocityValues(real *vx, real *vy, real *vz, int level) const
void setOutflowValues(real *RhoBC, int *kN, int level) const
BoundaryValues(std::string path)
void initIndex(uint *ptr, uint level)
void setBoundarys(std::vector< std::vector< std::vector< real > > > &qs) const
std::string getBoundaryCondition()
void setPressValues(real *RhoBC, int *kN, int level) const
std::shared_ptr< T > SPtr
float real
Definition DataTypes.h:42
unsigned int uint
Definition DataTypes.h:47