OpenLB 1.7
Loading...
Searching...
No Matches
setBouzidiZeroVelocityBoundary3D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2020 Alexander Schulz
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24//This file contains the BouzidiZeroVelocityBoundary
25//This is an offLattice Boundary
26//This is a new version of the Boundary, which only contains free floating functions
27#ifndef SET_BOUZIDI_ZERO_VELOCITY_BOUNDARY_HH
28#define SET_BOUZIDI_ZERO_VELOCITY_BOUNDARY_HH
29
31
32namespace olb {
33
34namespace legacy {
35
37
39template<typename T, typename DESCRIPTOR>
40void setBouzidiZeroVelocityBoundary(SuperLattice<T, DESCRIPTOR>& sLattice, SuperGeometry<T,3>& superGeometry, int material,IndicatorF3D<T>& geometryIndicator,
41 std::vector<int> bulkMaterials)
42{
43 setBouzidiZeroVelocityBoundary<T,DESCRIPTOR>(sLattice, superGeometry.getMaterialIndicator(material),
44 geometryIndicator,
45 bulkMaterials);
46}
47template<typename T, typename DESCRIPTOR>
49 std::vector<int> bulkMaterials)
50{
51 OstreamManager clout(std::cout, "setBouzidiZeroVelocityBoundary");
52 SuperGeometry<T,3>& superGeometry = boundaryIndicator->getSuperGeometry();
53 setBouzidiZeroVelocityBoundary<T,DESCRIPTOR>(sLattice, std::forward<decltype(boundaryIndicator)>(boundaryIndicator), superGeometry.getMaterialIndicator(std::move(bulkMaterials)),
54 geometryIndicator);
55}
56
57template<typename T, typename DESCRIPTOR>
59 FunctorPtr<SuperIndicatorF3D<T>>&& bulkIndicator,
60 IndicatorF3D<T>& geometryIndicator)
61{
62 OstreamManager clout(std::cout, "setBouzidiZeroVelocityBoundary");
63 T _epsFraction = 0.0001;
64 int overlap = 1;
65 bool _output = false;
66 if (_output) {
67 clout << "epsFraction=" << _epsFraction << std::endl;
68 clout.setMultiOutput(true);
69 }
70 for (int iCloc = 0; iCloc < sLattice.getLoadBalancer().size(); ++iCloc) {
71 if (_output) {
72 clout << "Cuboid globiC " << sLattice.getLoadBalancer().glob(iCloc)
73 << " starts to read distances for ZeroVelocity Boundary..." << std::endl;
74 }
75 setBouzidiZeroVelocityBoundary<T,DESCRIPTOR>(sLattice.getBlock(iCloc),
76 boundaryIndicator->getBlockIndicatorF(iCloc),
77 bulkIndicator->getBlockIndicatorF(iCloc),
78 geometryIndicator, _epsFraction);
79 if (_output) {
80 clout << "Cuboid globiC " << sLattice.getLoadBalancer().glob(iCloc)
81 << " finished reading distances for ZeroVelocity Boundary." << std::endl;
82 }
83 }
84 if (_output) {
85 clout.setMultiOutput(false);
86 }
88 addPoints2CommBC(sLattice,std::forward<decltype(boundaryIndicator)>(boundaryIndicator), overlap);
89}
90
91
92
93template<typename T, typename DESCRIPTOR>
94void setBouzidiZeroVelocityBoundary(BlockLattice<T, DESCRIPTOR>& block, BlockIndicatorF3D<T>& boundaryIndicator, BlockIndicatorF3D<T>& bulkIndicator, IndicatorF3D<T>& geometryIndicator, T _epsFraction)
95{
96 block.forSpatialLocations([&](auto iX, auto iY, auto iZ) {
97 if (boundaryIndicator(iX,iY,iZ)) {
98 setBouzidiZeroVelocityBoundary1<T,DESCRIPTOR>(block,
99 boundaryIndicator.getBlockGeometry(),
100 iX, iY, iZ,
101 geometryIndicator,
102 bulkIndicator,
103 _epsFraction);
104 }
105 });
106}
107
109
110
111template<typename T, typename DESCRIPTOR>
112void setBouzidiZeroVelocityBoundary1(BlockLattice<T, DESCRIPTOR>& block, BlockGeometry<T,3>& blockGeometryStructure, int iX, int iY, int iZ, IndicatorF3D<T>& geometryIndicator,
113 BlockIndicatorF3D<T>& bulkIndicator, T _epsFraction)
114{
115 OstreamManager clout(std::cout, "BouzidiBoundary");
116 T distances[DESCRIPTOR::q];
117 std::fill(std::begin(distances), std::end(distances), -1);
118
119 for (int iPop = 1; iPop < DESCRIPTOR::q ; ++iPop) {
120 const Vector<int,3> c = descriptors::c<DESCRIPTOR>(iPop);
121 const int iXn = iX + c[0];
122 const int iYn = iY + c[1];
123 const int iZn = iZ + c[2];
124 if (blockGeometryStructure.isInside(iXn,iYn,iZn)) {
125 if (bulkIndicator(iXn,iYn,iZn)) {
126 T dist = -1;
127 T physR[3];
128 blockGeometryStructure.getPhysR(physR,{iXn,iYn,iZn});
129 T voxelSize=blockGeometryStructure.getDeltaR();
130
131 Vector<T,3> physC(physR);
132
133 Vector<T,3> direction(-voxelSize*c[0],-voxelSize*c[1],-voxelSize*c[2]);
134 T cPhysNorm = voxelSize*util::sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]);
135
136 if (!geometryIndicator.distance(dist,physC,direction,blockGeometryStructure.getIcGlob() ) ) {
137 T epsX = voxelSize*c[0]*_epsFraction;
138 T epsY = voxelSize*c[1]*_epsFraction;
139 T epsZ = voxelSize*c[2]*_epsFraction;
140
141 Vector<T,3> physC2(physC);
142 physC2[0] += epsX;
143 physC2[1] += epsY;
144 physC2[2] += epsZ;
145 Vector<T,3> direction2(direction);
146 direction2[0] -= 2.*epsX;
147 direction2[1] -= 2.*epsY;
148 direction2[2] -= 2.*epsZ;
149
150 if ( !geometryIndicator.distance(dist,physC2,direction2,blockGeometryStructure.getIcGlob())) {
151 clout << "ERROR: no boundary found at (" << iXn << "," << iYn << "," << iZn <<") ~ ("
152 << physR[0] << "," << physR[1] << "," << physR[2] <<"), "
153 << "in direction " << descriptors::opposite<DESCRIPTOR >(iPop)
154 << std::endl;
155 break;
156 }
157 T distNew = (dist - util::sqrt(epsX*epsX+epsY*epsY+epsZ*epsZ))/cPhysNorm;
158 if (distNew < 0.5) {
159 dist = 0;
160 }
161 else {
162 dist = 0.5 * cPhysNorm;
163 clout << "WARNING: distance at (" << iXn << "," << iYn << "," << iZn <<") ~ ("
164 << physR[0] << "," << physR[1] << "," << physR[2] <<"), "
165 << "in direction " << descriptors::opposite<DESCRIPTOR >(iPop) << ": "
166 << distNew
167 << " rounded to "
168 << dist/cPhysNorm
169 << std::endl;
170 }
171 }
172 distances[descriptors::opposite<DESCRIPTOR>(iPop)] = dist/cPhysNorm;
173 }
174 else {
175 if (blockGeometryStructure.getMaterial(iXn,iYn,iZn) != 0) {
176 auto postProcessor = std::unique_ptr<PostProcessorGenerator3D<T, DESCRIPTOR>>{
177 new ZeroVelocityBounceBackPostProcessorGenerator3D<T,DESCRIPTOR>(iXn, iYn, iZn, descriptors::opposite<DESCRIPTOR>(iPop), 0) };
178 block.addPostProcessor(*postProcessor);
179 }
180 }
181 }
182 }
183 setBouzidiZeroVelocityBoundary<T,DESCRIPTOR>(block,blockGeometryStructure, iX, iY, iZ, distances);
184}
185
186template<typename T, typename DESCRIPTOR>
187void setBouzidiZeroVelocityBoundary(BlockLattice<T, DESCRIPTOR>& block, BlockGeometry<T,3>& blockGeometryStructure, int x, int y, int z, T distances[DESCRIPTOR::q])
188{
189 for (int iPop = 1; iPop < DESCRIPTOR::q; ++iPop) {
190 if ( !util::nearZero(distances[iPop]+1) ) {
191 const Vector<int,3> c = descriptors::c<DESCRIPTOR>(iPop);
192 setBouzidiZeroVelocityBoundary<T,DESCRIPTOR>(block, blockGeometryStructure, x-c[0], y-c[1], z-c[2], iPop, distances[iPop]);
193 }
194 }
195}
196
197template<typename T, typename DESCRIPTOR>
198void setBouzidiZeroVelocityBoundary(BlockLattice<T, DESCRIPTOR>& block, BlockGeometry<T,3>& blockGeometryStructure, int x, int y, int z, int iPop, T dist)
199{
200 auto postProcessor = std::unique_ptr<PostProcessorGenerator3D<T, DESCRIPTOR>>{ nullptr };
201 const Vector<int,3> c = descriptors::c<DESCRIPTOR>(iPop);
202
203 if (blockGeometryStructure.getMaterial(x-c[0], y-c[1], z-c[2]) != 1) {
204 postProcessor.reset(new ZeroVelocityBounceBackPostProcessorGenerator3D<T,DESCRIPTOR>(x, y, z, iPop, dist));
205 }
206 else {
207 postProcessor.reset(new ZeroVelocityBouzidiLinearPostProcessorGenerator3D<T,DESCRIPTOR>(x, y, z, iPop, dist));
208 }
209
210 if (postProcessor && !block.isPadding({x,y,z})) {
211 block.addPostProcessor(*postProcessor);
212 }
213}
214
215}
216
217}
218
219#endif
Representation of a block geometry.
Vector< T, D > getPhysR(LatticeR< D > latticeR)
int getMaterial(LatticeR< D > latticeR) const
returns the (iX,iY) entry in the 2D scalar field
int getIcGlob() const
Read only access to the global iC number which is given !=-1 if the block geometries are part of a su...
T getDeltaR() const
Read only access to the voxel size given in SI units (meter)
Base block indicator functor.
BlockGeometry< T, 3 > & getBlockGeometry()
Get underlying block geometry structure.
Platform-abstracted block lattice for external access and inter-block interaction.
virtual void addPostProcessor(std::type_index stage, LatticeR< DESCRIPTOR::d > latticeR, PostProcessorPromise< T, DESCRIPTOR > &&promise)=0
Schedule post processor for application to latticeR in stage.
void forSpatialLocations(F f) const
bool isPadding(LatticeR< D > latticeR) const
Return whether location is valid.
bool isInside(LatticeR< D > latticeR) const
Return whether location is valid.
Smart pointer for managing the various ways of passing functors around.
Definition functorPtr.h:60
IndicatorF3D is an application from .
virtual bool distance(S &distance, const Vector< S, 3 > &origin, S precision, const Vector< S, 3 > &direction)
class for marking output with some text
void setMultiOutput(bool b)
enable message output for all MPI processes, disabled by default
Representation of a statistic for a parallel 2D geometry.
std::unique_ptr< SuperIndicatorF< T, D > > getMaterialIndicator(std::vector< int > &&materials)
Returns a material indicator using the given vector of materials.
Base indicator functor (discrete)
Super class maintaining block lattices for a cuboid decomposition.
BlockLattice< T, DESCRIPTOR > & getBlock(int locC)
Return BlockLattice with local index locC.
LoadBalancer< T > & getLoadBalancer()
Read and write access to the load balancer.
Plain old scalar vector.
Definition vector.h:47
void setBouzidiZeroVelocityBoundary1(BlockLattice< T, DESCRIPTOR > &block, BlockGeometry< T, 3 > &blockGeometryStructure, int iX, int iY, int iZ, IndicatorF3D< T > &geometryIndicator, BlockIndicatorF3D< T > &bulkIndicator, T _epsFraction)
void setBouzidiZeroVelocityBoundary(SuperLattice< T, DESCRIPTOR > &sLattice, SuperGeometry< T, 2 > &superGeometry, int material, IndicatorF2D< T > &geometryIndicator, std::vector< int > bulkMaterials=std::vector< int >(1, 1))
Set offDynamics with boundary links and post processors using indicators.
cpu::simd::Pack< T > sqrt(cpu::simd::Pack< T > value)
Definition pack.h:100
bool nearZero(const ADf< T, DIM > &a)
Definition aDiff.h:1087
Top level namespace for all of OpenLB.
void addPoints2CommBC(SuperLattice< T, DESCRIPTOR > &sLattice, FunctorPtr< SuperIndicatorF2D< T > > &&indicator, int _overlap)
Adds needed Cells to the Communicator _commBC in SuperLattice.