OpenLB 1.7
Loading...
Searching...
No Matches
subgridUtilities.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2023 Nicolas Hafen, Mathias J. Krause
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
25
26#ifndef SUBGRID_UTILITIES_H
27#define SUBGRID_UTILITIES_H
28
30
31namespace olb {
32
33namespace particles {
34
35namespace subgrid {
36
37
38// Initialize particle velocities
39template<typename T, typename PARTICLETYPE, typename DESCRIPTOR>
42 SuperGeometry<T,DESCRIPTOR::d>& superGeometry,
43 UnitConverter<T,DESCRIPTOR> const& converter,
44 SuperParticleSystem<T,PARTICLETYPE>& supParticleSystem )
45{
46 using namespace descriptors;
47 constexpr unsigned D = DESCRIPTOR::d;
48 // Iterate over individual particle systems
50 [&](ParticleSystem<T,PARTICLETYPE>& particleSystem, int iC, int globiC){
51 // Retrieve block quantities
52 auto& blockLattice = sLattice.getBlock(iC);
53 auto& blockGeometry = superGeometry.getBlockGeometry(iC);
54 const auto& cuboid = blockGeometry.getCuboid();
55 // Create block velocity interpolation functor
57 blockLattice, converter, cuboid);
58 // Loop over all particles in particle system
59 forParticlesInParticleSystem<T,PARTICLETYPE>( particleSystem,
60 [&](Particle<T,PARTICLETYPE>& particle){
61 // Retrieve particle position
62 Vector<T,D> position = particle.template getField<GENERAL,POSITION>();
63 // Calculate interpolated velocity
64 Vector<T,D> fluidVel(0.);
65 blockInterpPhysVelF(fluidVel.data(), position.data());
66 //Apply velocity to particle
67 particle.template setField<MOBILITY,VELOCITY>( fluidVel );
68 });
69 });
70}
71
72
73// Add particles in indicator domain
74template<typename T, typename PARTICLETYPE>
76 IndicatorF3D<T>& ind, T partRho, T radius,
77 const std::size_t noOfParticles, util::Randomizer<T>& randomizer )
78{
79 Vector<T,3> pos(0.);
80 std::size_t noP = 0;
81 while (noP<noOfParticles){
82 //Generate randomized position
83 pos[0] = ind.getMin()[0]
84 + randomizer.generate() * (ind.getMax()[0] - ind.getMin()[0]);
85 pos[1] = ind.getMin()[1]
86 + randomizer.generate() * (ind.getMax()[1] - ind.getMin()[1]);
87 pos[2] = ind.getMin()[2]
88 + randomizer.generate() * (ind.getMax()[2] - ind.getMin()[2]);
89 //Call sub-grid creator if in indicator domain
90 bool inside[1] = { false };
91 ind(inside, pos.data());
92 if (inside[0]){
93 creators::addSubgridSphere3D( supParticleSystem, pos, radius, partRho );
94 noP++;
95 }
96 }
97}
98
99
100#ifdef PARALLEL_MODE_MPI
101
102// Calculate capture and escape rate
103template<typename T, typename PARTICLETYPE, bool verbose=true>
105 SuperIndicatorMaterial<T,PARTICLETYPE::d>& materialIndicatorOutput,
106 std::size_t& noActive, std::size_t reprParticleID=0 )
107{
108 noActive = 0;
109 std::size_t noFound = 0;
110 std::size_t noExcaped = 0;
112 [&](Particle<T,PARTICLETYPE>& particle,
113 ParticleSystem<T,PARTICLETYPE>& particleSystem, int globiC){
114 //Check activity
115 bool active = access::isActive(particle);
116 if (active){
117 noActive++;
118 //Check whether representative particle and potentially print
119 std::size_t globalId = access::getGlobalID(particle);
120 if constexpr (verbose){
121 if (globalId==reprParticleID){
123 }
124 }
125 }
126 //Check individual material vicinities
127 bool outputVicinity = boundaries::checkMaterialVicinity(
128 materialIndicatorOutput, particle );
129 if (outputVicinity){ noExcaped++; }
130 //Increase particle counter
131 noFound++;
132 });
133 singleton::mpi().reduceAndBcast(noActive, MPI_SUM);
134 singleton::mpi().reduceAndBcast(noFound, MPI_SUM);
135 singleton::mpi().reduceAndBcast(noExcaped, MPI_SUM);
136
137 //Calculate escape and capture rate
138 T escapeRate = T(noExcaped)/T(noFound);
139 T captureRate = 1.-escapeRate;
140
141 //Output
142 if constexpr (verbose){
143 OstreamManager clout( std::cout, "captureStatistics" );
144 clout << "globalNumOfParticles=" << noFound;
145 clout << "; activeParticles=" << noActive;
146 clout << "; escapedParticles=" << noExcaped << std::endl;
147 clout << "captureRate=" << captureRate << "; escapeRate=" << escapeRate;
148 clout << std::endl;
149 }
150}
151
152#endif
153
154
155} //namespace subgrid
156
157} //namespace particles
158
159} //namespace olb
160
161
162#endif
IndicatorF3D is an application from .
virtual Vector< S, 3 > & getMax()
virtual Vector< S, 3 > & getMin()
class for marking output with some text
Representation of a statistic for a parallel 2D geometry.
BlockGeometry< T, D > & getBlockGeometry(int locIC)
Read and write access to a single block geometry.
Super class maintaining block lattices for a cuboid decomposition.
BlockLattice< T, DESCRIPTOR > & getBlock(int locC)
Return BlockLattice with local index locC.
Conversion between physical and lattice units, as well as discretization.
Plain old scalar vector.
Definition vector.h:47
constexpr const T * data() const any_platform
Definition vector.h:161
void reduceAndBcast(T &reductVal, MPI_Op op, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Reduction operation, followed by a broadcast.
O generate()
Generate scalar or vector filled with scalars.
Definition random.hh:90
bool isActive(Particle< T, PARTICLETYPE > particle)
auto getGlobalID(Particle< T, PARTICLETYPE > particle)
bool checkMaterialVicinity(SuperIndicatorMaterial< T, PARTICLETYPE::d > &materialIndicator, Particle< T, PARTICLETYPE > &particle)
void forSystemsInSuperParticleSystem(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem, F f)
void forParticlesInSuperParticleSystem(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem, F f)
ParallelParticleLocator addSubgridSphere3D(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem, const Vector< T, 3 > &position, T radius, T density=0., const Vector< T, 3 > &velocity=Vector< T, 3 >(0.))
void printSubgridParticleInfo(Particle< T, PARTICLETYPE > &particle, const std::string &streamName="ParticleInfo")
void captureStatistics(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem, SuperIndicatorMaterial< T, PARTICLETYPE::d > &materialIndicatorOutput, std::size_t &noActive, std::size_t reprParticleID=0)
void addParticles(SuperParticleSystem< T, PARTICLETYPE > &supParticleSystem, IndicatorF3D< T > &ind, T partRho, T radius, const std::size_t noOfParticles, util::Randomizer< T > &randomizer)
void initializeParticleVelocity(SuperLattice< T, DESCRIPTOR > &sLattice, SuperGeometry< T, DESCRIPTOR::d > &superGeometry, UnitConverter< T, DESCRIPTOR > const &converter, SuperParticleSystem< T, PARTICLETYPE > &supParticleSystem)
MpiManager & mpi()
Top level namespace for all of OpenLB.
std::conditional_t< DESCRIPTOR::d==2, BlockLatticeInterpPhysVelocity2D< T, DESCRIPTOR >, BlockLatticeInterpPhysVelocity3D< T, DESCRIPTOR > > BlockLatticeInterpPhysVelocity
Definition aliases.h:360
std::conditional_t< D==2, SuperIndicatorMaterial2D< T >, SuperIndicatorMaterial3D< T > > SuperIndicatorMaterial
Definition aliases.h:298