VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
MultipleGridBuilderFacade.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//=======================================================================================
35
36#ifndef MULTIGPUGRIDHELPER_H
37#define MULTIGPUGRIDHELPER_H
38
39#include <array>
40#include <optional>
41#include <stdexcept>
42#include <vector>
43
44#include <basics/DataTypes.h>
47
48#include "GbSpatialData3D.h"
52
53namespace vf::gpu {
54
55struct GridDimensions;
56class MultipleGridBuilder;
57class Object;
58class FileCollection;
59
87{
88public:
90 std::optional<real> overlapOfSubdomains = std::nullopt);
91
92 MultipleGridBuilderFacade(SPtr<GridDimensions> gridDimensions, std::optional<real> overlapOfSubdomains = std::nullopt);
93
96 void addDomainSplit(real coordinate, Axis direction);
97
100
103 void addFineGrid(std::shared_ptr<Object> gridShape, uint levelFine);
104
108
111 void setNumberOfLayersForRefinement(uint numberOfLayersFine, uint numberOfLayersBetweenLevels) const;
112
116
117 // Boundary conditions, call after createGrids()
118 void setSlipBoundaryCondition(SideType sideType, real normalX, real normalY, real normalZ) const;
119 void setStressBoundaryCondition(SideType sideType, real normalX, real normalY, real normalZ, uint samplingOffset, real vonKarmanConstant,
120 real roughnessLength, real deltaX, std::shared_ptr<GbSpatialData3D<real>> roughnessMap=nullptr) const;
121 void setSurfaceLayerBoundaryCondition(SideType sideType, real normalX, real normalY, real normalZ, uint samplingOffset, real vonKarmanConstant,
122 real roughnessLength, real roughnessLengthTemperature, real surfaceHeatFlux, real surfaceTemperature, real heatingRate,
123 real deltaX, real deltaT, std::shared_ptr<GbSpatialData3D<real>> roughnessMap=nullptr) const;
124 void setVelocityBoundaryCondition(SideType sideType, real vx, real vy, real vz, std::optional<std::function<void(real x, real y, real z, real& vx, real& vy, real& vz)>> velocityProfile = std::nullopt) const;
128 void setPeriodicBoundaryCondition(const std::array<bool, 3>& periodicity);
130 real velocityX = vf::basics::constant::c0o1,
131 real velocityY = vf::basics::constant::c0o1,
132 real velocityZ = vf::basics::constant::c0o1,
133 real shiftY = vf::basics::constant::c0o1,
134 real shiftZ = vf::basics::constant::c0o1,
135 std::vector<uint> fileLevelToGridLevelMap = {}) const;
137 void setADFluxBoundaryCondition(SideType sideType, real normalX, real normalY, real normalZ, real gradient, real deltaX);
148
150
151protected:
152 // index calculations
153 std::array<uint, 3> convertToIndices3D(uint index1D) const;
154 uint getX3D(uint index1D) const;
155 uint getY3D(uint index1D) const;
156 uint getZ3D(uint index1D) const;
158 uint getIndex1D(const std::array<uint, 3>& index3D) const;
159
160private:
161 void setGlobalPeriodicity();
162 void setLocalPeriodicity(bool periodicX, bool periodicY, bool periodicZ);
164 void calculateNumberOfSubdomains();
165
167 void sortSplitLocations();
168
170 void calculatedIndexOfPart(uint generatePart);
171
173 void checkForNeighbors();
174
176 void configureSubDomainGrids();
177
179 void setUpCommunicationNeighbors();
180
182 void checkSplitLocations(const std::vector<real>& splits, real lowerBound, real upperBound) const;
183
185 void addFineGridsToGridBuilder();
186
188 void addGeometriesToGridBuilder();
189
191 bool isFinalSubdomainInDirection(communication_directions::CommunicationDirection direction) const;
192
194 uint getIndexOfFinalSubdomainInDirection(communication_directions::CommunicationDirection direction) const;
195
197 template <typename function>
198 void setBoundaryCondition(SideType sideType, function boundaryConditionFunction) const
199 {
200 if (!createGridsHasBeenCalled) {
201 throw std::runtime_error(
202 "MultipleGridBuilderFacade::createGrids() has to be called before setting boundary conditions");
203 }
204
206 !hasNeighbors.at(static_cast<communication_directions::CommunicationDirection>(static_cast<int>(sideType)))) {
208 }
209 }
210
211protected:
213 std::array<uint, 3> numberOfSubdomains;
214
215private:
216 const SPtr<MultipleGridBuilder> gridBuilder;
217
218 // basic grid dimension (set in constructor)
219 const SPtr<GridDimensions> gridDimensionsDomain;
220
221 uint numberOfSubdomainsTotal;
222
224 std::vector<real> xSplits;
225 std::vector<real> ySplits;
226 std::vector<real> zSplits;
227
229 std::optional<real> overlapOfSubdomains = std::nullopt;
230
232 std::array<uint, 3> index;
233 std::array<bool, 3> periodicity {false, false, false};
234
237 std::map<communication_directions::CommunicationDirection, bool> hasNeighbors = {
241 };
242
244 std::vector<std::pair<std::shared_ptr<Object>, uint>> fineGrids;
245
247 std::vector<std::shared_ptr<Object>> geometries;
248
249 bool createGridsHasBeenCalled = false;
250 real shiftOnXInY{}, shiftOnXInZ{}, shiftOnYInX{}, shiftOnYInZ{}, shiftOnZInX{}, shiftOnZInY{};
251};
252
253}
254
255#endif
Simplifies the creation of the grids for a multi-gpu simulation.
uint getIndex1D(uint xIndex, uint yIndex, uint zIndex) const
void setNumberOfLayersForRefinement(uint numberOfLayersFine, uint numberOfLayersBetweenLevels) const
add number of layers for refinements
void addDomainSplit(real coordinate, Axis direction)
split the domain in the passed direction at the passed coordinate
void setADFluxBoundaryCondition(SideType sideType, real normalX, real normalY, real normalZ, real gradient, real deltaX)
void addFineGrid(std::shared_ptr< Object > gridShape, uint levelFine)
adds a fine grid
void setOverlapOfSubdomains(real overlap)
set the overlap of the subdomains
void setPressureBoundaryCondition(SideType sideType, real rho) const
void setADDirichletBoundaryCondition(SideType sideType, real value, real vx, real vy, real vz)
std::array< uint, 3 > convertToIndices3D(uint index1D) const
void setSlipBoundaryCondition(SideType sideType, real normalX, real normalY, real normalZ) const
void setSurfaceLayerBoundaryCondition(SideType sideType, real normalX, real normalY, real normalZ, uint samplingOffset, real vonKarmanConstant, real roughnessLength, real roughnessLengthTemperature, real surfaceHeatFlux, real surfaceTemperature, real heatingRate, real deltaX, real deltaT, std::shared_ptr< GbSpatialData3D< real > > roughnessMap=nullptr) const
void setStressBoundaryCondition(SideType sideType, real normalX, real normalY, real normalZ, uint samplingOffset, real vonKarmanConstant, real roughnessLength, real deltaX, std::shared_ptr< GbSpatialData3D< real > > roughnessMap=nullptr) const
SPtr< MultipleGridBuilder > getGridBuilder() const
void setPeriodicBoundaryCondition(bool periodic_X, bool periodic_Y, bool periodic_Z)
void setVelocityBoundaryCondition(SideType sideType, real vx, real vy, real vz, std::optional< std::function< void(real x, real y, real z, real &vx, real &vy, real &vz)> > velocityProfile=std::nullopt) const
void createGrids(uint generatePart)
generate the subdomain which is specified by generatePart
std::array< uint, 3 > numberOfSubdomains
total number of subdomains in each coordinate direction (computed)
void setPrecursorBoundaryCondition(SideType sideType, SPtr< FileCollection > fileCollection, bool cycleFiles=false, real velocityX=vf::basics::constant::c0o1, real velocityY=vf::basics::constant::c0o1, real velocityZ=vf::basics::constant::c0o1, real shiftY=vf::basics::constant::c0o1, real shiftZ=vf::basics::constant::c0o1, std::vector< uint > fileLevelToGridLevelMap={}) const
void setADNeumannBoundaryCondition(SideType sideType, real gradient, real vx, real vy, real vz, real dx)
void setNoSlipBoundaryCondition(SideType sideType) const
void addGeometry(SPtr< Object > gridShape)
adds a geometry to the fluid domain
std::shared_ptr< T > SPtr
float real
Definition DataTypes.h:42
unsigned int uint
Definition DataTypes.h:47
Axis
Definition Axis.h:41
@ z
Definition Axis.h:44
@ x
Definition Axis.h:42
@ y
Definition Axis.h:43
const real dx
SideType
Definition Side.h:63