OpenLB 1.8.1
Loading...
Searching...
No Matches
boundaryHandling.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2022 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 PARTICLE_BOUNDARY_HANDLING_H
27#define PARTICLE_BOUNDARY_HANDLING_H
28
30
31namespace olb {
32
33namespace particles {
34
35namespace boundaries {
36
37
38//Return normal on closest surface specified by solid boundary
39//-referenceLength: For particles, use circumRadius etc.
40
41template<typename T, unsigned D>
43 Vector<T,D>& position, T referenceLength )
44{
45 T delXofCentralDifference = 1.e-8*referenceLength;
46 return solidBoundary.getIndicator()->surfaceNormalExact(position, delXofCentralDifference);
47}
48
49template<typename T, typename PARTICLETYPE>
51 Particle<T,PARTICLETYPE>& particle )
52{
53 auto position = access::getPosition( particle );
54 auto radius = access::getRadius( particle );
55 return getNormalOnClosestSurface( solidBoundary, position, radius );
56}
57
66template<bool useCubicBounds=false, typename T, typename PARTICLETYPE, typename F>
70 F f )
71{
72 using namespace descriptors;
73 //Retrieve quantities
74 auto position = access::getPosition( particle );
75 T radius = access::getRadius( particle );
76 //VERSION A: Use signed distance functions of indicator
77 if constexpr (!useCubicBounds){
78 T distToWall = solidBoundary.getIndicator()->signedDistanceExact(position)-radius;
79 if (distToWall<=0){
80 //std::cout << "radius is " << radius <<'\n';
81 //std::cout << "signedDistance is " << solidBoundary.getIndicator()->signedDistance(position) << std::endl;
82 if constexpr (std::is_invocable_v<F,Particle<T,PARTICLETYPE>&,Vector<T,PARTICLETYPE::d>&,T>){
83 auto normal = getNormalOnClosestSurface( solidBoundary, position, radius );
84 T penetrationDepth = -distToWall;
85 f( particle, normal, penetrationDepth );
86 } else if constexpr (std::is_invocable_v<F,Particle<T,PARTICLETYPE>&,Vector<T,PARTICLETYPE::d>&>){
87 auto normal = getNormalOnClosestSurface( solidBoundary, position, radius );
88 f( particle, normal );
89 } else {
90 f( particle );
91 }
92
93 }
94 }
95 //VERSION B: Use origin and end of cubic indicator bounds (min, max)
96 else {
97 auto origin = solidBoundary.getIndicator()->getMin();
98 auto end = solidBoundary.getIndicator()->getMax();
99 for (int iDim=0; iDim<PARTICLETYPE::d; ++iDim){
100 T posParticleStart = position[iDim] - radius;
101 T posParticleEnd = position[iDim] + radius;
102 //Retrieve distance for lower and upper limit
103 T distToWallOrig = posParticleStart - origin[iDim];
104 T distToWallEnd = end[iDim] - posParticleEnd;
105 //Set up normal
106 Vector<T,PARTICLETYPE::d> normal(0.);
107 //Evaluate distances
108 if (distToWallOrig<=0){
109 normal[iDim] = 1;
110 if constexpr (std::is_invocable_v<F,Particle<T,PARTICLETYPE>&,Vector<T,PARTICLETYPE::d>&,T>){
111 T penetrationDepth = -distToWallOrig;
112 f( particle, normal, penetrationDepth );
113 } else if constexpr (std::is_invocable_v<F,Particle<T,PARTICLETYPE>&,Vector<T,PARTICLETYPE::d>&>){
114 f( particle, normal );
115 } else {
116 f( particle );
117 }
118 } else if (distToWallEnd<=0){
119 normal[iDim] = -1;
120 if constexpr (std::is_invocable_v<F,Particle<T,PARTICLETYPE>&,Vector<T,PARTICLETYPE::d>&,T>){
121 T penetrationDepth = -distToWallEnd;
122 f( particle, normal, penetrationDepth );
123 } else if constexpr (std::is_invocable_v<F,Particle<T,PARTICLETYPE>&,Vector<T,PARTICLETYPE::d>&>){
124 f( particle, normal );
125 } else {
126 f( particle );
127 }
128 }
129 }
130 } //constexpr if (!useCubicBounds)
131}
132
133
134//normal of each STLTriangle should point outside of the model according to STL conventions
135//https://www.loc.gov/preservation/digital/formats/fdd/fdd000504.shtml
136
137template<bool useCubicBounds=false, typename T, typename PARTICLETYPE, typename F>
139 Particle<T,PARTICLETYPE>& particle,
141 F f )
142{
143 using namespace descriptors;
144 //Retrieve quantities
145 auto position = particle.template getField<GENERAL,POSITION>();
146 T radius = particle.template getField<PHYSPROPERTIES,RADIUS>();
147 //VERSION A: Use signed distance functions of indicator
148 if constexpr (!useCubicBounds){
149 STLtriangle<T> tri;
150 //the minus sign is because the signedDistance is defined negative when inside the geometry!
151 T distCenterToWall = solidBoundary.getIndicator()->signedDistance(position);//is positive, if inside, due to negative IndicatorInverse
152
153
154
155 if(distCenterToWall < radius)//deposition for sure
156 {
157 std::cout << "Simple var: Dist to wall < radius and distance is " <<distCenterToWall << " from axis " << std::sqrt(std::pow(position[1],2) + std::pow(position[2],2 )) << " point " << position << " deposited!" << std::endl;
158 if constexpr (std::is_invocable_v<F,Particle<T,PARTICLETYPE>&,Vector<T,PARTICLETYPE::d>&,T>){
159 Vector<T,3> normal;//auto normal = getNormalOnClosestSurface( solidBoundary, position, radius );
160 T penetrationDepth = -distCenterToWall;
161 f( particle, normal, penetrationDepth );
162 } else if constexpr (std::is_invocable_v<F,Particle<T,PARTICLETYPE>&,Vector<T,PARTICLETYPE::d>&>){
163 auto normal = getNormalOnClosestSurface( solidBoundary, position, radius );
164 f( particle, normal );
165 } else {
166 f( particle );
167 }
168 }
169 else if (distCenterToWall > radius*particle.template getField<NUMERICPROPERTIES,BETA>())//no deposition possible
170 {
171
172 return;}
173 else
174 {
175
176 Vector<T,3> orientation = particle.template getField<NUMERICPROPERTIES,ORIENTATION>();
177 T beta = particle.template getField<NUMERICPROPERTIES,BETA> ();
178 auto normal = getNormalOnClosestSurface( solidBoundary, position, radius );
179 if (eler::elipsoidDeposition(radius, beta, distCenterToWall, orientation, normal))
180 {
181 if constexpr (std::is_invocable_v<F,Particle<T,PARTICLETYPE>&,Vector<T,PARTICLETYPE::d>&,T>){
182 auto normal = getNormalOnClosestSurface( solidBoundary, position, radius );
183 T penetrationDepth = -distCenterToWall;
184 f( particle, normal, penetrationDepth );
185 } else if constexpr (std::is_invocable_v<F,Particle<T,PARTICLETYPE>&,Vector<T,PARTICLETYPE::d>&>){
186 auto normal = getNormalOnClosestSurface( solidBoundary, position, radius );
187 f( particle, normal );
188 } else {
189 f( particle );
190 }
191
192 }
193
194 }
195 }
196 //VERSION B: Use origin and end of cubic indicator bounds (min, max)
197 else {
198 auto origin = solidBoundary.getIndicator()->getMin();
199 auto end = solidBoundary.getIndicator()->getMax();
200 for (int iDim=0; iDim<PARTICLETYPE::d; ++iDim){
201 T posParticleStart = position[iDim] - radius;
202 T posParticleEnd = position[iDim] + radius;
203 //Retrieve distance for lower and upper limit
204 T distToWallOrig = posParticleStart - origin[iDim];
205 T distToWallEnd = end[iDim] - posParticleEnd;
206 //Set up normal
207 Vector<T,PARTICLETYPE::d> normal(0.);
208 //Evaluate distances
209 if (distToWallOrig<=0){
210 normal[iDim] = 1;
211 if constexpr (std::is_invocable_v<F,Particle<T,PARTICLETYPE>&,Vector<T,PARTICLETYPE::d>&,T>){
212 T penetrationDepth = -distToWallOrig;
213 f( particle, normal, penetrationDepth );
214 } else if constexpr (std::is_invocable_v<F,Particle<T,PARTICLETYPE>&,Vector<T,PARTICLETYPE::d>&>){
215 f( particle, normal );
216 } else {
217 f( particle );
218 }
219 } else if (distToWallEnd<=0){
220 normal[iDim] = -1;
221 if constexpr (std::is_invocable_v<F,Particle<T,PARTICLETYPE>&,Vector<T,PARTICLETYPE::d>&,T>){
222 T penetrationDepth = -distToWallEnd;
223 f( particle, normal, penetrationDepth );
224 } else if constexpr (std::is_invocable_v<F,Particle<T,PARTICLETYPE>&,Vector<T,PARTICLETYPE::d>&>){
225 f( particle, normal );
226 } else {
227 f( particle );
228 }
229 }
230 }
231 } //constexpr if (!useCubicBounds)
232}
233
234
235//Orientation between given normal and closest surface of solid boundary
236// - usable for quantifying tilting of surface attached particles
237template<typename T, unsigned D>
239 SolidBoundary<T,D>& solidBoundary, Vector<T,D>& position,
240 Vector<T,D>& normalToBeComparedTo, T referenceLength )
241{
242 auto normalWall = getNormalOnClosestSurface( solidBoundary, position, referenceLength );
243 auto orientation = util::angleBetweenVectors( normalWall, normalToBeComparedTo );
244 return orientation;
245}
246
247} //namespace boundaries
248
249} //namespace particles
250
251} //namespace olb
252
253
254#endif
Plain old scalar vector.
$(Helper functions for subgrid scale spheroid rotation computation in moving reference frame) This fi...
T getRadius(Particle< T, PARTICLETYPE > &particle)
Vector< T, PARTICLETYPE::d > getPosition(Particle< T, PARTICLETYPE > particle)
void doAtParticleWallContactSpheroid(Particle< T, PARTICLETYPE > &particle, SolidBoundary< T, PARTICLETYPE::d > &solidBoundary, F f)
Vector< T, D > getNormalOnClosestSurface(SolidBoundary< T, D > &solidBoundary, Vector< T, D > &position, T referenceLength)
Vector< T, utilities::dimensions::convert< D >::rotation > getRelativeSurfaceOrientation(SolidBoundary< T, D > &solidBoundary, Vector< T, D > &position, Vector< T, D > &normalToBeComparedTo, T referenceLength)
void doAtParticleWallContact(Particle< T, PARTICLETYPE > &particle, SolidBoundary< T, PARTICLETYPE::d > &solidBoundary, F f)
Generic treatment of particle wall contact.
T angleBetweenVectors(const Vector< T, 2 > &a, const Vector< T, 2 > &b)
Calculates angles between two 2D vectors.
Top level namespace for all of OpenLB.
IndicatorF< T, D > * getIndicator()
Definition wall.hh:42