VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
GridReader.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 "GridReader.h"
34
35#include <iostream>
36
38#include "Parameter/Parameter.h"
39
40#include "CoordNeighborGeoV.h"
41#include "BoundaryQs.h"
42#include "BoundaryValues.h"
43
45#include "OffsetScale.h"
46
47using namespace vf::lbm::dir;
48
49namespace vf::gpu {
50
51GridReader::GridReader(FILEFORMAT format, std::shared_ptr<Parameter> para, std::shared_ptr<CudaMemoryManager> cudaMemoryManager)
52{
53 this->para = para;
54 this->cudaMemoryManager = cudaMemoryManager;
55
56 if (format == FILEFORMAT::ASCII)
57 this->binaer = false;
58 else
59 this->binaer = true;
60
61 channelDirections.resize(6);
62 channelBoundaryConditions.resize(6);
63 BC_Values.resize(6);
64
65 channelDirections[0] = "inlet";
66 channelDirections[1] = "outlet";
67 channelDirections[2] = "front";
68 channelDirections[3] = "back";
69 channelDirections[4] = "top";
70 channelDirections[5] = "bottom";
71}
72
74{
75 return binaer;
76}
77
79{
80 VF_LOG_TRACE("-----Config Arrays Coord, Neighbor, Geo------");
81
82 CoordNeighborGeoV coordX(para->getcoordX(), binaer, true);
83 CoordNeighborGeoV coordY(para->getcoordY(), binaer, true);
84 CoordNeighborGeoV coordZ(para->getcoordZ(), binaer, true);
85 neighX = std::shared_ptr<CoordNeighborGeoV>(new CoordNeighborGeoV(para->getneighborX(), binaer, false));
86 neighY = std::shared_ptr<CoordNeighborGeoV>(new CoordNeighborGeoV(para->getneighborY(), binaer, false));
87 neighZ = std::shared_ptr<CoordNeighborGeoV>(new CoordNeighborGeoV(para->getneighborZ(), binaer, false));
88 neighWSB = std::shared_ptr<CoordNeighborGeoV>(new CoordNeighborGeoV(para->getneighborWSB(), binaer, false));
89 CoordNeighborGeoV geoV(para->getgeoVec(), binaer, false);
90
91 uint maxLevel = coordX.getLevel();
92 VF_LOG_INFO("Number of Level: {}", maxLevel + 1);
94 VF_LOG_INFO("Number of Nodes: ");
95
96 for (uint level = 0; level <= maxLevel; level++)
97 {
98 const uint numberOfNodesPerLevel = coordX.getSize(level) + 1;
99 numberOfNodesGlobal += numberOfNodesPerLevel;
100 VF_LOG_INFO("Level {} = {} Nodes", level, numberOfNodesPerLevel);
101
102 setNumberOfNodes(numberOfNodesPerLevel, level);
103
104 cudaMemoryManager->cudaAllocCoord(level);
105 cudaMemoryManager->cudaAllocSP(level);
106 //cudaMemoryManager->cudaAllocF3SP(level);
107 cudaMemoryManager->cudaAllocNeighborWSB(level);
108
109 coordX.initalCoords( para->getParH(level)->coordinateX, level);
110 coordY.initalCoords( para->getParH(level)->coordinateY, level);
111 coordZ.initalCoords( para->getParH(level)->coordinateZ, level);
112 neighX->initalNeighbors( para->getParH(level)->neighborX, level);
113 neighY->initalNeighbors( para->getParH(level)->neighborY, level);
114 neighZ->initalNeighbors( para->getParH(level)->neighborZ, level);
115 neighWSB->initalNeighbors(para->getParH(level)->neighborInverse, level);
116 geoV.initalNeighbors( para->getParH(level)->typeOfGridNode, level);
117 setInitialNodeValues(numberOfNodesPerLevel, level);
118
119 cudaMemoryManager->cudaCopyNeighborWSB(level);
120 cudaMemoryManager->cudaCopySP(level);
121 cudaMemoryManager->cudaCopyCoord(level);
122 }
123 VF_LOG_INFO("Number of Nodes: {}", numberOfNodesGlobal);
124 VF_LOG_TRACE("-----finish Config Arrays Coord, Neighbor, Geo------");
125}
126
128{
129 VF_LOG_TRACE("------read BoundaryValues-------");
130
131
132 this->makeReader(para);
134 int level = BC_Values[0]->getLevel();
135
136 for (int i = 0; i <= level; i++) {
137 velocityX_BCvalues.push_back(std::vector<real>());
138 velocityY_BCvalues.push_back(std::vector<real>());
139 velocityZ_BCvalues.push_back(std::vector<real>());
140 velocityQs.push_back(std::vector<std::vector<real>>());
141 velocityIndex.push_back(std::vector<int>());
142 for (int j = 0; j < para->getD3Qxx(); j++) {
143 velocityQs[i].push_back(std::vector<real>());
144 }
145 }
146
147 for (uint i = 0; i < channelBoundaryConditions.size(); i++)
148 {
149 if ( this->channelBoundaryConditions[i] == "velocity") { fillVelocityVectors(i); }
150 else if (this->channelBoundaryConditions[i] == "pressure") { setPressureValues(i); }
151 else if (this->channelBoundaryConditions[i] == "outflow") { setOutflowValues(i); }
152 }
153
154 setVelocityValues();
155
157}
158
160{
161 VF_LOG_TRACE("------Config Arrays OffsetScale-------");
162 OffsetScale *obj_offCF = new OffsetScale(para->getscaleOffsetCF(), true);
163 OffsetScale *obj_offFC = new OffsetScale(para->getscaleOffsetFC(), true);
164 OffsetScale *obj_scaleCFC = new OffsetScale(para->getscaleCFC(), false);
165 OffsetScale *obj_scaleCFF = new OffsetScale(para->getscaleCFF(), false);
166 OffsetScale *obj_scaleFCC = new OffsetScale(para->getscaleFCC(), false);
167 OffsetScale *obj_scaleFCF = new OffsetScale(para->getscaleFCF(), false);
168
169 int level = obj_offCF->getLevel();
170
171 int AnzahlKnotenGesCF = 0;
172 int AnzahlKnotenGesFC = 0;
173
174 for (int i = 0; i<level; i++) {
175 unsigned int tempCF = obj_offCF->getSize(i);
176 VF_LOG_INFO("Size Data CF from Level {}: {}", i, tempCF);
177 unsigned int tempFC = obj_offFC->getSize(i);
178 VF_LOG_INFO("Size Data CF from Level {}: {}", i, tempFC);
179
182
184 //size CF
185 para->getParH(i)->coarseToFine.numberOfCells = tempCF;
186 para->getParD(i)->coarseToFine.numberOfCells = para->getParH(i)->coarseToFine.numberOfCells;
188 //size FC
189 para->getParH(i)->fineToCoarse.numberOfCells = tempFC;
190 para->getParD(i)->fineToCoarse.numberOfCells = para->getParH(i)->fineToCoarse.numberOfCells;
192 //alloc
193 cudaMemoryManager->cudaAllocInterfaceCF(i);
194 cudaMemoryManager->cudaAllocInterfaceFC(i);
195 cudaMemoryManager->cudaAllocInterfaceOffCF(i);
196 cudaMemoryManager->cudaAllocInterfaceOffFC(i);
198 //init
199 obj_offCF->initArrayOffset(para->getParH(i)->neighborCoarseToFine.x, para->getParH(i)->neighborCoarseToFine.y, para->getParH(i)->neighborCoarseToFine.z, i);
200 obj_offFC->initArrayOffset(para->getParH(i)->neighborFineToCoarse.x, para->getParH(i)->neighborFineToCoarse.y, para->getParH(i)->neighborFineToCoarse.z, i);
201 obj_scaleCFC->initScale(para->getParH(i)->coarseToFine.coarseCellIndices, i);
202 obj_scaleCFF->initScale(para->getParH(i)->coarseToFine.fineCellIndices, i);
203 obj_scaleFCC->initScale(para->getParH(i)->fineToCoarse.coarseCellIndices, i);
204 obj_scaleFCF->initScale(para->getParH(i)->fineToCoarse.fineCellIndices, i);
206 //copy
207 cudaMemoryManager->cudaCopyInterfaceCF(i);
208 cudaMemoryManager->cudaCopyInterfaceFC(i);
209 cudaMemoryManager->cudaCopyInterfaceOffCF(i);
210 cudaMemoryManager->cudaCopyInterfaceOffFC(i);
212 }
213 VF_LOG_INFO("Total number of Nodes CF = {}", AnzahlKnotenGesCF);
214 VF_LOG_INFO("Total number of Nodes FC = {}", AnzahlKnotenGesFC);
215
216 delete obj_offCF;
217 delete obj_offFC;
218 delete obj_scaleCFC;
219 delete obj_scaleCFF;
220 delete obj_scaleFCC;
221 delete obj_scaleFCF;
222 VF_LOG_TRACE("Finish OffsetScale");
223}
224
226 VF_LOG_WARNING("GridReader::allocArrays_fluidNodeIndices not implemented");
227 // TODO
228}
229
230void GridReader::tagFluidNodeIndices(const std::vector<uint>& taggedFluidNodeIndices, CollisionTemplate tag, uint level){
231 VF_LOG_WARNING("GridReader::tagFluidNodeIndices not implemented");
232 // TODO
233}
234
236 VF_LOG_WARNING("GridReader::sortFluidNodeTags not implemented");
237 // TODO
238}
239
240void GridReader::setPressureValues(int channelSide) const
241{
242 for (unsigned int level = 0; level <= BC_Values[channelSide]->getLevel(); level++)
243 {
244 int sizePerLevel = BC_Values[channelSide]->getSize(level);
246
247 if (sizePerLevel > 0)
248 {
249 VF_LOG_INFO("size pressure level {}: {}", level, sizePerLevel);
250
251 cudaMemoryManager->cudaAllocPress(level);
252
253 setPressRhoBC(sizePerLevel, level, channelSide);
254 cudaMemoryManager->cudaCopyPress(level);
255 }
256 }
257}
258
259void GridReader::setPressRhoBC(int sizePerLevel, int level, int channelSide) const
260{
261 BC_Values[channelSide]->setPressValues(para->getParH(level)->pressureBC.RhoBC, para->getParH(level)->pressureBC.kN, level);
262 for (int m = 0; m < sizePerLevel; m++)
263 para->getParH(level)->pressureBC.RhoBC[m] = (para->getParH(level)->pressureBC.RhoBC[m] / para->getFactorPressBC());
264}
265
266
267void GridReader::fillVelocityVectors(int channelSide)
268{
269 for (unsigned int level = 0; level <= BC_Values[channelSide]->getLevel(); level++)
270 {
271 const int sizePerLevel = BC_Values[channelSide]->getSize(level);
272
273 if (sizePerLevel > 1)
274 {
275 // set local vectors per side and level
279
280 VF_LOG_INFO("size velocity level {}: {}", level, sizePerLevel);
281 BC_Values[channelSide]->setVelocityValues(veloX_ValuesPerSide, veloY_ValuesPerSide, veloZ_ValuesPerSide, level);
282
283 for (int i = 0; i < sizePerLevel; i++) {
284 this->velocityX_BCvalues[level].push_back(veloX_ValuesPerSide[i]);
285 this->velocityY_BCvalues[level].push_back(veloY_ValuesPerSide[i]);
286 this->velocityZ_BCvalues[level].push_back(veloZ_ValuesPerSide[i]);
287 }
288
289 delete[] veloX_ValuesPerSide;
290 delete[] veloY_ValuesPerSide;
291 delete[] veloZ_ValuesPerSide;
292 }
293 }
294
295
296}
297
298void GridReader::setVelocityValues() {
299 for (int level = 0; level < (int)(velocityX_BCvalues.size()); level++) {
300
301 int sizePerLevel = (int) velocityX_BCvalues[level].size();
302 VF_LOG_INFO("Complete size velocity level {}: {}", level, sizePerLevel);
304
305 if (sizePerLevel > 1) {
306 cudaMemoryManager->cudaAllocVeloBC(level);
307 setVelocity(level, sizePerLevel);
308 cudaMemoryManager->cudaCopyVeloBC(level);
309 }
310 }
311}
312
313void GridReader::setVelocity(int level, int sizePerLevel) const
314{
315 for (int index = 0; index < sizePerLevel; index++)
316 {
317 para->getParH(level)->velocityBC.Vx[index] = this->velocityX_BCvalues[level][index] / para->getVelocityRatio();
318 para->getParH(level)->velocityBC.Vy[index] = this->velocityY_BCvalues[level][index] / para->getVelocityRatio();
319 para->getParH(level)->velocityBC.Vz[index] = this->velocityZ_BCvalues[level][index] / para->getVelocityRatio();
320 }
321}
322
323
324void GridReader::setOutflowValues(int channelSide) const
325{
326 for (unsigned int level = 0; level <= BC_Values[channelSide]->getLevel(); level++)
327 {
328 int sizePerLevel = BC_Values[channelSide]->getSize(level);
330
331 if (sizePerLevel > 1)
332 {
333 VF_LOG_INFO("size outflow level {}: {}", level, sizePerLevel);
334
335 cudaMemoryManager->cudaAllocOutflowBC(level);
336
337 setOutflow(level, sizePerLevel, channelSide);
338 cudaMemoryManager->cudaCopyOutflowBC(level);
339
340 }
341 }
342}
343
344void GridReader::setOutflow(int level, int sizePerLevel, int channelSide) const
345{
346 BC_Values[channelSide]->setOutflowValues(para->getParH(level)->outflowBC.RhoBC, para->getParH(level)->outflowBC.kN, level);
347 for (int index = 0; index < sizePerLevel; index++)
348 para->getParH(level)->outflowBC.RhoBC[index] = (para->getParH(level)->outflowBC.RhoBC[index] / para->getFactorPressBC()) * (real)0.0;
349}
350
351
353{
355 //3D domain decomposition
356 std::vector< std::shared_ptr<BoundaryValues> > procNeighborsSendX, procNeighborsSendY, procNeighborsSendZ;
357 std::vector< std::shared_ptr<BoundaryValues> > procNeighborsRecvX, procNeighborsRecvY, procNeighborsRecvZ;
358 std::vector< int > neighborRankX, neighborRankY, neighborRankZ;
359
360 if (para->getNumprocs() > 1)
361 {
362 for (int process = 0; process < para->getNumprocs(); process++)
363 {
364 std::shared_ptr<BoundaryValues> pnXsend = std::shared_ptr<BoundaryValues> (new BoundaryValues(process, para, "send", "X"));
365 std::shared_ptr<BoundaryValues> pnYsend = std::shared_ptr<BoundaryValues> (new BoundaryValues(process, para, "send", "Y"));
366 std::shared_ptr<BoundaryValues> pnZsend = std::shared_ptr<BoundaryValues> (new BoundaryValues(process, para, "send", "Z"));
367 std::shared_ptr<BoundaryValues> pnXrecv = std::shared_ptr<BoundaryValues> (new BoundaryValues(process, para, "recv", "X"));
368 std::shared_ptr<BoundaryValues> pnYrecv = std::shared_ptr<BoundaryValues> (new BoundaryValues(process, para, "recv", "Y"));
369 std::shared_ptr<BoundaryValues> pnZrecv = std::shared_ptr<BoundaryValues> (new BoundaryValues(process, para, "recv", "Z"));
370 if (para->getIsNeighborX())
371 {
372 procNeighborsSendX.push_back(pnXsend);
373 procNeighborsRecvX.push_back(pnXrecv);
374 neighborRankX.push_back(process);
375 std::cout << "MyID: " << para->getMyProcessID() << ", neighborRankX: " << process << std::endl;
376 }
377 if (para->getIsNeighborY())
378 {
379 procNeighborsSendY.push_back(pnYsend);
380 procNeighborsRecvY.push_back(pnYrecv);
381 neighborRankY.push_back(process);
382 std::cout << "MyID: " << para->getMyProcessID() << ", neighborRankY: " << process << std::endl;
383 }
384 if (para->getIsNeighborZ())
385 {
386 procNeighborsSendZ.push_back(pnZsend);
387 procNeighborsRecvZ.push_back(pnZrecv);
388 neighborRankZ.push_back(process);
389 std::cout << "MyID: " << para->getMyProcessID() << ", neighborRankZ: " << process << std::endl;
390 }
391 }
392 std::cout << "MyID: " << para->getMyProcessID() << ", size of neighborRankX: " << neighborRankX.size() << ", size of neighborRankY: " << neighborRankY.size() << ", size of neighborRankZ: " << neighborRankZ.size() << std::endl;
393 }
394
396 // 3D domain decomposition
397 // X
398 if ((para->getNumprocs() > 1) && (procNeighborsSendX.size() == procNeighborsRecvX.size())) {
399 for (std::size_t j = 0; j < procNeighborsSendX.size(); j++) {
400 for (int i = 0; i <= level; i++) {
401 const uint tempSend = procNeighborsSendX[j]->getSize(i);
402 const uint tempRecv = procNeighborsRecvX[j]->getSize(i);
403 if (tempSend == 0)
404 continue;
405
406 VF_LOG_INFO("size of Data for X send buffer, Level {} : {}", i, tempSend);
407 VF_LOG_INFO("size of Data for X receive buffer, Level {}: {}", i, tempRecv);
408 auto& parH = para->getParHostAsReference(i);
409 auto& parD = para->getParDeviceAsReference(i);
410 ProcessNeighbor27& sendNeighborHost = parH.sendProcessNeighborsX.emplace_back(tempSend, neighborRankX[j]);
411 ProcessNeighbor27& sendNeighborDevice = parD.sendProcessNeighborsX.emplace_back(tempSend, neighborRankX[j]);
412 ProcessNeighbor27& recvNeighborHost = parH.recvProcessNeighborsX.emplace_back(tempRecv, neighborRankX[j]);
413 ProcessNeighbor27& recvNeighborDevice = parD.recvProcessNeighborsX.emplace_back(tempRecv, neighborRankX[j]);
414
415 cudaMemoryManager->cudaAllocProcessNeighbor(sendNeighborHost, sendNeighborDevice);
416 cudaMemoryManager->cudaAllocProcessNeighbor( recvNeighborHost, recvNeighborDevice);
417
418 procNeighborsSendX[j]->initIndex(sendNeighborHost.index, i);
419 procNeighborsRecvX[j]->initIndex(recvNeighborHost.index, i);
420
421 cudaMemoryManager->cudaCopyProcessNeighborIndex(sendNeighborHost, sendNeighborDevice);
422 cudaMemoryManager->cudaCopyProcessNeighborIndex(recvNeighborHost, recvNeighborDevice);
423 }
424 }
425 }
426
428 // Y
429 if ((para->getNumprocs() > 1) && (procNeighborsSendY.size() == procNeighborsRecvY.size())) {
430 for (std::size_t j = 0; j < procNeighborsSendY.size(); j++) {
431 for (int i = 0; i <= level; i++) {
432 const uint tempSend = procNeighborsSendY[j]->getSize(i);
433 const uint tempRecv = procNeighborsRecvY[j]->getSize(i);
434 if (tempSend == 0)
435 continue;
436
437 VF_LOG_INFO("size of Data for Y send buffer, Level {} : {}", i, tempSend);
438 VF_LOG_INFO("size of Data for Y receive buffer, Level {}: {}", i, tempRecv);
439
440 auto& parH = para->getParHostAsReference(i);
441 auto& parD = para->getParDeviceAsReference(i);
442 ProcessNeighbor27& sendNeighborHost = parH.sendProcessNeighborsY.emplace_back(tempSend, neighborRankY[j]);
443 ProcessNeighbor27& sendNeighborDevice = parD.sendProcessNeighborsY.emplace_back(tempSend, neighborRankY[j]);
444 ProcessNeighbor27& recvNeighborHost = parH.recvProcessNeighborsY.emplace_back(tempRecv, neighborRankY[j]);
445 ProcessNeighbor27& recvNeighborDevice = parD.recvProcessNeighborsY.emplace_back(tempRecv, neighborRankY[j]);
446
447 cudaMemoryManager->cudaAllocProcessNeighbor(sendNeighborHost, sendNeighborDevice);
448 cudaMemoryManager->cudaAllocProcessNeighbor( recvNeighborHost, recvNeighborDevice);
449
450 procNeighborsSendY[j]->initIndex(sendNeighborHost.index, i);
451 procNeighborsRecvY[j]->initIndex(recvNeighborHost.index, i);
452
453 cudaMemoryManager->cudaCopyProcessNeighborIndex(sendNeighborHost, sendNeighborDevice);
454 cudaMemoryManager->cudaCopyProcessNeighborIndex(recvNeighborHost, recvNeighborDevice);
455
456 }
457 }
458 }
459
461 // Z
462 if ((para->getNumprocs() > 1) && (procNeighborsSendZ.size() == procNeighborsRecvZ.size())) {
463 for (std::size_t j = 0; j < procNeighborsSendZ.size(); j++) {
464 for (int i = 0; i <= level; i++) {
465 const uint tempSend = procNeighborsSendZ[j]->getSize(i);
466 const uint tempRecv = procNeighborsRecvZ[j]->getSize(i);
467 const int neighborRank = neighborRankZ[j];
468 if (tempSend == 0)
469 continue;
470
471 VF_LOG_INFO("size of Data for Z send buffer, Level {} : {}", i, tempSend);
472 VF_LOG_INFO("size of Data for Z receive buffer, Level {}: {}", i, tempRecv);
473 auto& parH = para->getParHostAsReference(i);
474 auto& parD = para->getParDeviceAsReference(i);
475 ProcessNeighbor27& sendNeighborHost = parH.sendProcessNeighborsZ.emplace_back(tempSend, neighborRank);
476 ProcessNeighbor27& sendNeighborDevice = parD.sendProcessNeighborsZ.emplace_back(tempSend, neighborRankZ[j]);
477 ProcessNeighbor27& recvNeighborHost = parH.recvProcessNeighborsZ.emplace_back(tempRecv, neighborRankZ[j]);
478 ProcessNeighbor27& recvNeighborDevice = parD.recvProcessNeighborsZ.emplace_back(tempRecv, neighborRankZ[j]);
479
480 cudaMemoryManager->cudaAllocProcessNeighbor(sendNeighborHost, sendNeighborDevice);
481 cudaMemoryManager->cudaAllocProcessNeighbor(recvNeighborHost, recvNeighborDevice);
482
483 procNeighborsSendZ[j]->initIndex(sendNeighborHost.index, i);
484 procNeighborsRecvZ[j]->initIndex(recvNeighborHost.index, i);
485
486 cudaMemoryManager->cudaCopyProcessNeighborIndex(sendNeighborHost, sendNeighborDevice);
487 cudaMemoryManager->cudaCopyProcessNeighborIndex( recvNeighborHost, recvNeighborDevice);
488 }
489 }
490 }
491}
492
494{
495 VF_LOG_TRACE("------read BoundaryQs-------");
496
497 std::vector<std::shared_ptr<BoundaryQs> > BC_Qs(channelDirections.size());
498 this->makeReader(BC_Qs, para);
499
500 for (std::size_t i = 0; i < channelBoundaryConditions.size(); i++)
501 {
502 if ( this->channelBoundaryConditions[i] == "noSlip" ) { setNoSlipQs(BC_Qs[i]); }
503 else if (this->channelBoundaryConditions[i] == "velocity") { setVelocityQs(BC_Qs[i]); }
504 else if (this->channelBoundaryConditions[i] == "pressure") { setPressQs(BC_Qs[i]); }
505 else if (this->channelBoundaryConditions[i] == "outflow" ) { setOutflowQs(BC_Qs[i]); }
506 }
507
508 for (int lev = 0; lev < (int)(velocityIndex.size()); lev++) {
509 if (velocityIndex[lev].size() > 1) {
510 copyVectorsToQStruct(velocityQs[lev], velocityIndex[lev], para->getParH(lev)->velocityBC);
511 cudaMemoryManager->cudaCopyVeloBC(lev);
512 }
513 }
514
515 std::shared_ptr<BoundaryQs> obj_geomQ = std::shared_ptr<BoundaryQs>(new BoundaryQs(para->getgeomBoundaryBcQs(), para, "geo", false));
516 if (para->getIsGeo())
517 setGeoQs(obj_geomQ);
518
519 VF_LOG_TRACE("------finish BoundaryQs-------");
520}
521
522
523/*------------------------------------------------------------------------------------------------*/
524/*----------------------------------------q setter methods----------------------------------------*/
525/*------------------------------------------------------------------------------------------------*/
526void GridReader::setPressQs(std::shared_ptr<BoundaryQs> boundaryQ) const
527{
528 for (unsigned int level = 0; level <= boundaryQ->getLevel(); level++)
529 {
530 if (hasQs(boundaryQ, level))
531 {
532 this->printQSize("pressure", boundaryQ, level);
533 this->initalQStruct(para->getParH(level)->pressureBC, boundaryQ, level);
534 cudaMemoryManager->cudaCopyPress(level);
535 }
536 }
537}
538
539void GridReader::setVelocityQs(std::shared_ptr<BoundaryQs> boundaryQ)
540{
541 for (unsigned int level = 0; level <= boundaryQ->getLevel(); level++)
542 {
543 if (hasQs(boundaryQ, level))
544 {
545 this->printQSize("velocity", boundaryQ, level);
546 this->initalVectorForQStruct(velocityQs, velocityIndex, boundaryQ, level);
547 }
548 }
549}
550
551void GridReader::setOutflowQs(std::shared_ptr<BoundaryQs> boundaryQ) const
552{
553 for (unsigned int level = 0; level <= boundaryQ->getLevel(); level++)
554 {
555 if (hasQs(boundaryQ, level))
556 {
557 this->printQSize("outflow", boundaryQ, level);
558 this->initalQStruct(para->getParH(level)->outflowBC, boundaryQ, level);
559 cudaMemoryManager->cudaCopyOutflowBC(level);
560 }
561 }
562}
563
564void GridReader::setNoSlipQs(std::shared_ptr<BoundaryQs> boundaryQ) const
565{
566 for (unsigned int level = 0; level <= boundaryQ->getLevel(); level++)
567 {
568 if (hasQs(boundaryQ, level))
569 {
570 this->printQSize("no slip", boundaryQ, level);
571 this->setSizeNoSlip(boundaryQ, level);
572 this->initalQStruct(para->getParH(level)->noSlipBC, boundaryQ, level);
573 cudaMemoryManager->cudaCopyNoSlipBC(level);
574 }
575 }
576}
577
578void GridReader::setGeoQs(std::shared_ptr<BoundaryQs> boundaryQ) const
579{
580 for (unsigned int level = 0; level <= boundaryQ->getLevel(); level++)
581 {
582 if (hasQs(boundaryQ, level))
583 {
584 this->printQSize("geo Qs", boundaryQ, level);
585 this->setSizeGeoQs(boundaryQ, level);
586 this->initalQStruct(para->getParH(level)->geometryBC, boundaryQ, level);
587
588 modifyQElement(boundaryQ, level);
589
590 cudaMemoryManager->cudaCopyGeomBC(level);
591 }
592 }
593}
594
595void GridReader::modifyQElement(std::shared_ptr<BoundaryQs> boundaryQ, unsigned int level) const
596{
597 QforBoundaryConditions Q;
598 real* QQ = para->getParH(level)->geometryBC.q27[0];
599 Q.q27[vf::lbm::dir::d000] = &QQ[vf::lbm::dir::d000 * para->getParH(level)->geometryBC.numberOfBCnodes];
600 for (unsigned int i = 0; i < boundaryQ->getSize(level); i++)
601 Q.q27[vf::lbm::dir::d000][i] = 0.0f;
602}
603
604/*------------------------------------------------------------------------------------------------*/
605/*---------------------------------------private q methods----------------------------------------*/
606/*------------------------------------------------------------------------------------------------*/
607void GridReader::initalVectorForQStruct(std::vector<std::vector<std::vector<real>>> &Qs, std::vector<std::vector<int>> &index,
608 std::shared_ptr<BoundaryQs> boundaryQ, unsigned int level) const
609{
610 boundaryQ->setValuesInVector(Qs, level);
611 boundaryQ->setIndexInVector(index, level);
612}
613
614void GridReader::copyVectorsToQStruct(std::vector<std::vector<real>> &Qs,
615 std::vector<int> &index, QforBoundaryConditions &Q) const
616{
617 QforBoundaryConditions qTemp;
618 this->setQ27Size(qTemp, Q.q27[0], Q.numberOfBCnodes);
619
620 uint sizeOfValues = (uint)index.size();
621
622 for (int direction = 0; direction < para->getD3Qxx(); direction++) {
623 for (size_t indexQ = 0; indexQ < sizeOfValues; indexQ++) {
624 qTemp.q27[direction][indexQ] = Qs[direction][indexQ];
625 }
626 }
627
628 for (size_t indexQ = 0; indexQ < sizeOfValues; indexQ++) {
629 Q.k[indexQ] = index[indexQ];
630 }
631}
632
633void GridReader::initalQStruct(QforBoundaryConditions &Q, std::shared_ptr<BoundaryQs> boundaryQ,
634 unsigned int level) const
635{
636 QforBoundaryConditions qTemp;
637 this->setQ27Size(qTemp, Q.q27[0], Q.numberOfBCnodes);
638 boundaryQ->setValues(qTemp.q27, level);
639 boundaryQ->setIndex(Q.k, level);
640}
641
642bool GridReader::hasQs(std::shared_ptr<BoundaryQs> boundaryQ, unsigned int level) const
643{
644 return boundaryQ->getSize(level) > 0;
645}
646
648{
649 int maxLevel = para->getMaxLevel();
650 std::vector<int> gridX, gridY, gridZ;
651 std::vector<int> distX, distY, distZ;
652
653 for (int i = 0; i <= maxLevel; i++) {
654 gridX.push_back(0);
655 gridY.push_back(0);
656 gridZ.push_back(0);
657 distX.push_back(0);
658 distY.push_back(0);
659 distZ.push_back(0);
660 }
661
662 para->setGridX(gridX);
663 para->setGridY(gridY);
664 para->setGridZ(gridZ);
665}
666
667void GridReader::setQ27Size(QforBoundaryConditions &Q, real* QQ, unsigned int sizeQ) const
668{
669 Q.q27[dP00] = &QQ[dP00 *sizeQ];
670 Q.q27[dM00] = &QQ[dM00 *sizeQ];
671 Q.q27[d0P0] = &QQ[d0P0 *sizeQ];
672 Q.q27[d0M0] = &QQ[d0M0 *sizeQ];
673 Q.q27[d00P] = &QQ[d00P *sizeQ];
674 Q.q27[d00M] = &QQ[d00M *sizeQ];
675 Q.q27[dPP0] = &QQ[dPP0 *sizeQ];
676 Q.q27[dMM0] = &QQ[dMM0 *sizeQ];
677 Q.q27[dPM0] = &QQ[dPM0 *sizeQ];
678 Q.q27[dMP0] = &QQ[dMP0 *sizeQ];
679 Q.q27[dP0P] = &QQ[dP0P *sizeQ];
680 Q.q27[dM0M] = &QQ[dM0M *sizeQ];
681 Q.q27[dP0M] = &QQ[dP0M *sizeQ];
682 Q.q27[dM0P] = &QQ[dM0P *sizeQ];
683 Q.q27[d0PP] = &QQ[d0PP *sizeQ];
684 Q.q27[d0MM] = &QQ[d0MM *sizeQ];
685 Q.q27[d0PM] = &QQ[d0PM *sizeQ];
686 Q.q27[d0MP] = &QQ[d0MP *sizeQ];
687 Q.q27[d000] = &QQ[d000*sizeQ];
688 Q.q27[dPPP] = &QQ[dPPP *sizeQ];
689 Q.q27[dMMP] = &QQ[dMMP *sizeQ];
690 Q.q27[dPMP] = &QQ[dPMP *sizeQ];
691 Q.q27[dMPP] = &QQ[dMPP *sizeQ];
692 Q.q27[dPPM] = &QQ[dPPM *sizeQ];
693 Q.q27[dMMM] = &QQ[dMMM *sizeQ];
694 Q.q27[dPMM] = &QQ[dPMM *sizeQ];
695 Q.q27[dMPM] = &QQ[dMPM *sizeQ];
696}
697
698void GridReader::setSizeNoSlip(std::shared_ptr<BoundaryQs> boundaryQ, unsigned int level) const
699{
700 para->getParH(level)->noSlipBC.numberOfBCnodes = boundaryQ->getSize(level);
701 para->getParD(level)->noSlipBC.numberOfBCnodes = para->getParH(level)->noSlipBC.numberOfBCnodes;
702 cudaMemoryManager->cudaAllocNoSlipBC(level);
703}
704
705void GridReader::setSizeGeoQs(std::shared_ptr<BoundaryQs> boundaryQ, unsigned int level) const
706{
707 para->getParH(level)->geometryBC.numberOfBCnodes = boundaryQ->getSize(level);
708 para->getParD(level)->geometryBC.numberOfBCnodes = para->getParH(level)->geometryBC.numberOfBCnodes;
709
710 cudaMemoryManager->cudaAllocGeomBC(level);
711}
712
713void GridReader::printQSize(std::string bc, std::shared_ptr<BoundaryQs> boundaryQ, unsigned int level) const
714{
715 std::cout << "level " << level << ", " << bc << "-size: " << boundaryQ->getSize(level) << std::endl;
716}
717
718
720{
721 std::ifstream numberNodes;
722 numberNodes.open(para->getnumberNodes().c_str(), std::ios::in);
723 if (!numberNodes) {
724 std::cerr << "can't open file NumberNodes: " << para->getnumberNodes() << std::endl;
725 exit(1);
726 }
727
728 std::string buffer;
729 int bufferInt;
730 std::vector<int> localGridNX;
731 std::vector<int> localGridNY;
732 std::vector<int> localGridNZ;
733
734 for (/*unsigned*/ int i = 0; i <= para->getMaxLevel(); i++) {
735 numberNodes >> buffer;
736 numberNodes >> bufferInt;
737 localGridNX.push_back(bufferInt);
738 numberNodes >> bufferInt;
739 localGridNY.push_back(bufferInt);
740 numberNodes >> bufferInt;
741 localGridNZ.push_back(bufferInt);
742 }
743 para->setGridX(localGridNX);
744 para->setGridY(localGridNY);
745 para->setGridZ(localGridNZ);
746}
747
749{
750 std::ifstream numberNodes;
751 numberNodes.open(para->getLBMvsSI().c_str(), std::ios::in);
752 if (!numberNodes) {
753 std::cerr << "can't open file LBMvsSI" << std::endl;
754 exit(1);
755 }
757 std::vector<real> minX, maxX, minY, maxY, minZ, maxZ;
758
759 for (int i = 0; i <= para->getMaxLevel(); i++) {
760 numberNodes >> bufferreal;
761 minX.push_back(bufferreal);
762 numberNodes >> bufferreal;
763 minY.push_back(bufferreal);
764 numberNodes >> bufferreal;
765 minZ.push_back(bufferreal);
766 numberNodes >> bufferreal;
767 maxX.push_back(bufferreal);
768 numberNodes >> bufferreal;
769 maxY.push_back(bufferreal);
770 numberNodes >> bufferreal;
771 maxZ.push_back(bufferreal);
772 }
773 para->setMinCoordX(minX);
774 para->setMinCoordY(minY);
775 para->setMinCoordZ(minZ);
776 para->setMaxCoordX(maxX);
777 para->setMaxCoordY(maxY);
778 para->setMaxCoordZ(maxZ);
779}
780
781void GridReader::initPeriodicNeigh(std::vector<std::vector<std::vector<unsigned int> > > periodV, std::vector<std::vector<unsigned int> > periodIndex, std::string boundaryCondition)
782{
783 std::vector<unsigned int>neighVec;
784 std::vector<unsigned int>indexVec;
785
786 int counter = 0;
787
788 for(unsigned int i=0; i<neighX->getLevel();i++) {
789 if(boundaryCondition =="periodic_y"){
790 neighVec = neighY->getVec(i);
791 }
792 else if(boundaryCondition =="periodic_x"){
793 neighVec = neighX->getVec(i);
794 }
795 else if(boundaryCondition =="periodic_z"){
796 neighVec = neighZ->getVec(i);
797 }
798 else {
799 std::cout << "wrong String in periodicValue" << std::endl;
800 exit(1);
801 }
802
803 for (std::vector<unsigned int>::iterator it = periodIndex[i].begin(); it != periodIndex[i].end(); it++) {
804 if(periodV[i][0][counter] != 0) {
805 neighVec[*it]=periodV[i][0][counter];
806 }
807
808 counter++;
809 }
810
811
812 if(boundaryCondition =="periodic_y"){
813 neighY->setVec(i, neighVec);
814 }
815 else if(boundaryCondition =="periodic_x"){
816 neighX->setVec(i, neighVec);
817 }
818 else if(boundaryCondition =="periodic_z"){
819 neighZ->setVec(i, neighVec);
820 }
821
822 }
823}
824
825void GridReader::makeReader(std::shared_ptr<Parameter> para)
826{
827 for (std::size_t i = 0; i < BC_Values.size(); i++)
828 {
829 if (channelDirections[i].compare("inlet") == 0){ BC_Values[i] = std::shared_ptr<BoundaryValues>(new BoundaryValues(para->getinletBcValues())); }
830 if (channelDirections[i].compare("outlet") == 0){ BC_Values[i] = std::shared_ptr<BoundaryValues>(new BoundaryValues(para->getoutletBcValues())); }
831 if (channelDirections[i].compare("back") == 0){ BC_Values[i] = std::shared_ptr<BoundaryValues>(new BoundaryValues(para->getbackBcValues())); }
832 if (channelDirections[i].compare("front") == 0){ BC_Values[i] = std::shared_ptr<BoundaryValues>(new BoundaryValues(para->getfrontBcValues())); }
833 if (channelDirections[i].compare("top") == 0){ BC_Values[i] = std::shared_ptr<BoundaryValues>(new BoundaryValues(para->gettopBcValues())); }
834 if (channelDirections[i].compare("bottom") == 0){ BC_Values[i] = std::shared_ptr<BoundaryValues>(new BoundaryValues(para->getbottomBcValues()));}
835 }
836}
837
838void GridReader::makeReader(std::vector<std::shared_ptr<BoundaryQs> > &BC_Qs, std::shared_ptr<Parameter> para)
839{
840 for (std::size_t i = 0; i < BC_Qs.size(); i++)
841 {
842 if (channelDirections[i].compare("inlet") == 0){ BC_Qs[i] = std::shared_ptr<BoundaryQs>(new BoundaryQs(para->getinletBcQs(), false)); }
843 if (channelDirections[i].compare("outlet") == 0){ BC_Qs[i] = std::shared_ptr<BoundaryQs>(new BoundaryQs(para->getoutletBcQs(), false)); }
844 if (channelDirections[i].compare("back") == 0){ BC_Qs[i] = std::shared_ptr<BoundaryQs>(new BoundaryQs(para->getbackBcQs(), false)); }
845 if (channelDirections[i].compare("front") == 0){ BC_Qs[i] = std::shared_ptr<BoundaryQs>(new BoundaryQs(para->getfrontBcQs(), false)); }
846 if (channelDirections[i].compare("top") == 0){ BC_Qs[i] = std::shared_ptr<BoundaryQs>(new BoundaryQs(para->gettopBcQs(), false)); }
847 if (channelDirections[i].compare("bottom") == 0){ BC_Qs[i] = std::shared_ptr<BoundaryQs>(new BoundaryQs(para->getbottomBcQs(), false)); }
848 }
849}
850
852{
853 for (std::size_t i = 0; i < channelDirections.size(); i++)
854 {
855 this->channelBoundaryConditions[i] = BC_Values[i]->getBoundaryCondition();
856 VF_LOG_INFO("{} Boundary: {}", this->channelDirections[i], channelBoundaryConditions[i]);
857 }
858}
859
860}
861
#define VF_LOG_TRACE(...)
Definition Logger.h:48
#define VF_LOG_INFO(...)
Definition Logger.h:50
#define VF_LOG_WARNING(...)
Definition Logger.h:51
void initalCoords(real *int_ptr, unsigned int level) const
unsigned int getSize(unsigned int level)
std::shared_ptr< Parameter > para
void setOutflowSizePerLevel(int level, int sizePerLevel) const
void setVelocitySizePerLevel(int level, int sizePerLevel) const
void setPressSizePerLevel(int level, int sizePerLevel) const
virtual void setInitialNodeValues(uint numberOfNodes, int level) const
std::shared_ptr< CudaMemoryManager > cudaMemoryManager
void setNumberOfNodes(uint numberOfNodes, int level) const
void allocArrays_BoundaryQs() override
void setDimensions() override
void allocArrays_taggedFluidNodes() override
void setBoundingBox() override
GridReader(FILEFORMAT format, std::shared_ptr< Parameter > para, std::shared_ptr< CudaMemoryManager > cudaMemoryManager)
void setChannelBoundaryCondition()
void allocArrays_BoundaryValues(const BoundaryConditionFactory *bcFactory) override
void tagFluidNodeIndices(const std::vector< uint > &taggedFluidNodeIndices, CollisionTemplate tag, uint level) override
void allocArrays_CoordNeighborGeo() override
void sortFluidNodeTags() override
void initPeriodicNeigh(std::vector< std::vector< std::vector< unsigned int > > > periodV, std::vector< std::vector< unsigned int > > periodIndex, std::string way) override
void initalValuesDomainDecompostion(int level)
void allocArrays_OffsetScale() override
void initalGridInformations() override
std::shared_ptr< T > SPtr
float real
Definition DataTypes.h:42
unsigned int uint
Definition DataTypes.h:47
CollisionTemplate
An enumeration for selecting a template of the collision kernel (CumulantK17)
Definition Calculation.h:57