OpenLB 1.7
Loading...
Searching...
No Matches
setBouzidiVelocityBoundary3D.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 BouzidiVelocityBoundary
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_VELOCITY_BOUNDARY_HH
28#define SET_BOUZIDI_VELOCITY_BOUNDARY_HH
29
31
32namespace olb {
33
34namespace legacy {
35
37
39template<typename T, typename DESCRIPTOR>
41 IndicatorF3D<T>& geometryIndicator,
42 std::vector<int> bulkMaterials)
43{
44
45 setBouzidiVelocityBoundary<T,DESCRIPTOR>(sLattice, superGeometry.getMaterialIndicator(material),
46 superGeometry.getMaterialIndicator(std::move(bulkMaterials)),
47 geometryIndicator);
48}
49
51template<typename T, typename DESCRIPTOR>
53 FunctorPtr<SuperIndicatorF3D<T>>&& bulkIndicator,
54 IndicatorF3D<T>& geometryIndicator)
55{
56 OstreamManager clout(std::cout, "setBouzidiBoundary");
57 T _epsFraction = 0.0001;
58 int overlap = 1;
59 bool _output = false;
60 if (_output) {
61 clout << "epsFraction=" << _epsFraction << std::endl;
62 clout.setMultiOutput(true);
63 }
64 for (int iCloc = 0; iCloc < sLattice.getLoadBalancer().size(); ++iCloc) {
65 if (_output) {
66 clout << "Cuboid globiC " << sLattice.getLoadBalancer().glob(iCloc)
67 << " starts to read distances for Velocity Boundary..." << std::endl;
68 }
69 //this is a guess to solve the private member block issue
70 setBouzidiVelocityBoundary<T,DESCRIPTOR>(
71 sLattice.getBlock(iCloc), boundaryIndicator->getBlockIndicatorF(iCloc),
72 bulkIndicator->getBlockIndicatorF(iCloc),
73 geometryIndicator, _epsFraction);
74 if (_output) {
75 clout << "Cuboid globiC " << sLattice.getLoadBalancer().glob(iCloc)
76 << " finished reading distances for Velocity Boundary." << std::endl;
77 }
78 }
79 if (_output) {
80 clout.setMultiOutput(false);
81 }
83 addPoints2CommBC<T,DESCRIPTOR>(sLattice,std::forward<decltype(boundaryIndicator)>(boundaryIndicator), overlap);
84}
85
86
88
89
90template<typename T, typename DESCRIPTOR>
92 BlockIndicatorF3D<T>& bulkIndicator, IndicatorF3D<T>& geometryIndicator, T _epsFraction)
93{
94 block.forSpatialLocations([&](auto iX, auto iY, auto iZ) {
95 if (boundaryIndicator(iX,iY,iZ)) {
96 setBouzidiVelocityBoundary<T,DESCRIPTOR>(block,
97 bulkIndicator.getBlockGeometry(),
98 iX, iY, iZ,
99 geometryIndicator,
100 bulkIndicator,
101 _epsFraction);
102 }
103 });
104}
105
106
107template<typename T, typename DESCRIPTOR>
108void setBouzidiVelocityBoundary(BlockLattice<T, DESCRIPTOR>& block, BlockGeometry<T,3>& blockGeometryStructure, int iX, int iY, int iZ,
109 IndicatorF3D<T>& geometryIndicator, BlockIndicatorF3D<T>& bulkIndicator, T _epsFraction)
110{
111 OstreamManager clout(std::cout, "setBouzidiBoundary");
112 T distances[DESCRIPTOR::q];
113 for (int iPop = 1; iPop < DESCRIPTOR::q ; ++iPop) {
114 distances[iPop] = -1;
115 }
116
117 for (int iPop = 1; iPop < DESCRIPTOR::q ; ++iPop) {
118 const Vector<int,3> c = descriptors::c<DESCRIPTOR>(iPop);
119 const int iXn = iX + c[0];
120 const int iYn = iY + c[1];
121 const int iZn = iZ + c[2];
122 if (blockGeometryStructure.isInside(iXn,iYn,iZn) && bulkIndicator(iXn,iYn,iZn)) {
123 T dist = -1;
124 T physR[3];
125 blockGeometryStructure.getPhysR(physR,{iXn,iYn,iZn});
126 T voxelSize=blockGeometryStructure.getDeltaR();
127
128 Vector<T,3> physC(physR);
129 Vector<T,3> direction(-voxelSize*c[0],-voxelSize*c[1],-voxelSize*c[2]);
130 T cPhysNorm = voxelSize*util::sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]);
131
132 if (!geometryIndicator.distance(dist,physC,direction,blockGeometryStructure.getIcGlob() ) ) {
133 T epsX = voxelSize*c[0]*_epsFraction;
134 T epsY = voxelSize*c[1]*_epsFraction;
135 T epsZ = voxelSize*c[2]*_epsFraction;
136
137 Vector<T,3> physC2(physC);
138 physC2[0] += epsX;
139 physC2[1] += epsY;
140 physC2[2] += epsZ;
141 Vector<T,3> direction2(direction);
142 direction2[0] -= 2.*epsX;
143 direction2[1] -= 2.*epsY;
144 direction2[2] -= 2.*epsZ;
145
146 if ( !geometryIndicator.distance(dist,physC2,direction2,blockGeometryStructure.getIcGlob())) {
147 clout << "ERROR: no boundary found at (" << iXn << "," << iYn << "," << iZn <<") ~ ("
148 << physR[0] << "," << physR[1] << "," << physR[2] <<"), "
149 << "in direction " << descriptors::opposite<DESCRIPTOR >(iPop)
150 << std::endl;
151
152 }
153 T distNew = (dist - util::sqrt(epsX*epsX+epsY*epsY+epsZ*epsZ))/cPhysNorm;
154 if (distNew < 0.5) {
155 dist = 0;
156 }
157 else {
158 dist = 0.5 * cPhysNorm;
159 clout << "WARNING: distance at (" << iXn << "," << iYn << "," << iZn <<") ~ ("
160 << physR[0] << "," << physR[1] << "," << physR[2] <<"), "
161 << "in direction " << descriptors::opposite<DESCRIPTOR >(iPop) << ": "
162 << distNew
163 << " rounded to "
164 << dist/cPhysNorm
165 << std::endl;
166
167 }
168 }
169 distances[descriptors::opposite<DESCRIPTOR >(iPop)] = dist/cPhysNorm;
170 } // bulk indicator if
171 } // iPop loop
172 setBouzidiVelocityBoundary<T,DESCRIPTOR>(block, blockGeometryStructure, iX, iY, iZ, distances);
173}
174
175
176template<typename T, typename DESCRIPTOR>
177void setBouzidiVelocityBoundary(BlockLattice<T, DESCRIPTOR>& block, BlockGeometry<T,3>& blockGeometryStructure, int x, int y, int z, T distances[DESCRIPTOR::q])
178{
179 T location[DESCRIPTOR::d];
180 blockGeometryStructure.getPhysR(location, {x,y,z});
181 T distancesCopy[DESCRIPTOR::q];
182 T spacing = blockGeometryStructure.getDeltaR();
183 for (int iPop = 1; iPop < DESCRIPTOR::q ; ++iPop) {
184 distancesCopy[iPop] = spacing*(1.-distances[iPop]);
185 if ( util::nearZero(distances[iPop]+1) ) {
186 distancesCopy[iPop] = -1;
187 }
188 }
189 Dynamics<T,DESCRIPTOR>* dynamics = new legacy::OffDynamics<T, DESCRIPTOR>(location, distancesCopy);
190 block.defineDynamics({x,y,z}, dynamics);
191
192 for (int iPop = 1; iPop < DESCRIPTOR::q ; ++iPop) {
193 if (!util::nearZero(distances[iPop]+1)) {
194 const Vector<int,3> c = descriptors::c<DESCRIPTOR>(iPop);
195
196 setBouzidiVelocityBoundary<T,DESCRIPTOR>(block, blockGeometryStructure, x-c[0], y-c[1], z-c[2], iPop, distances[iPop]);
197 }
198 }
199}
200
201template<typename T, typename DESCRIPTOR>
202void setBouzidiVelocityBoundary(BlockLattice<T, DESCRIPTOR>& block, BlockGeometry<T,3>& blockGeometryStructure, int x, int y, int z, int iPop, T dist)
203{
204 const Vector<int,3> c = descriptors::c<DESCRIPTOR>(iPop);
205 //setOnePointVelocityBoundary. This corresponds to Bounce Back
206 auto postProcessor = std::unique_ptr<PostProcessorGenerator3D<T, DESCRIPTOR>> { nullptr };
207 if (blockGeometryStructure.getMaterial({x-c[0], y-c[1], z-c[2]}) != 1) {
208 postProcessor.reset(new VelocityBounceBackPostProcessorGenerator3D <T, DESCRIPTOR>(x, y, z, iPop, dist));
209 }
210 //setTwoPointVelocityBoundary.This corresponds to Linear Interpolation
211 else {
212 postProcessor.reset(new VelocityBouzidiLinearPostProcessorGenerator3D<T, DESCRIPTOR>(x, y, z, iPop, dist));
213 }
214 if (postProcessor && !block.isPadding({x,y,z})) {
215 block.addPostProcessor(*postProcessor);
216 }
217}
218
219}
220
221}
222
223#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 defineDynamics(LatticeR< DESCRIPTOR::d > latticeR, DynamicsPromise< T, DESCRIPTOR > &&promise)
Assign promised DYNAMICS to latticeR.
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
Dynamics for offLattice boundary conditions OffDynamics are basically NoLatticeDynamics with the addi...
Definition dynamics.h:145
void setBouzidiVelocityBoundary(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.
Interface for per-cell dynamics.
Definition interface.h:54