OpenLB 1.8.1
Loading...
Searching...
No Matches
turbulentWallModelPostProcessor.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2024 Fedor Bukreev, Adrian Kummerländer
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#ifndef TURBULENT_WALL_MODEL_POST_PROCESSOR_H
25#define TURBULENT_WALL_MODEL_POST_PROCESSOR_H
26
27namespace olb {
28
29 // interpolation of the velocity along the surface normal on the chosen distance from the boundary cell
30 template <typename CELL, typename V = typename CELL::value_t, typename DESCRIPTOR = typename CELL::descriptor_t>
31 void interpolateVelocity(CELL& cell, Vector<V,DESCRIPTOR::d> distance, V u_y2[DESCRIPTOR::d]) any_platform{
33 for( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
34 floorV[iD] = util::floor(distance[iD]);
35 }
36 Vector<Vector<V,DESCRIPTOR::d>,(DESCRIPTOR::d==2)*4+(DESCRIPTOR::d==3)*8> surroundingPoints(floorV);
37 surroundingPoints[1][0] += 1.;
38 surroundingPoints[2][1] += 1.;
39 surroundingPoints[3][0] += 1.; surroundingPoints[3][1] += 1.;
40 if( DESCRIPTOR::d == 3) {
41 surroundingPoints[4][2] += 1.;
42 surroundingPoints[5][0] += 1.; surroundingPoints[5][2] += 1.;
43 surroundingPoints[6][1] += 1.; surroundingPoints[6][2] += 1.;
44 surroundingPoints[7][0] += 1.; surroundingPoints[7][1] += 1.; surroundingPoints[7][2] += 1.;
45 }
46
47 for (auto point : surroundingPoints) {
48 const Vector<V,DESCRIPTOR::d> dist = distance - point;
49 V weight = V(1);
50 for( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
51 weight *=(V(1.) - util::abs(dist[iD]));
52 }
53 V uNP[DESCRIPTOR::d] = {0.};
54 cell.neighbor(point).computeU(uNP);
55 for( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
56 u_y2[iD] += uNP[iD]*weight;
57 }
58 }
59 };
60
61 template <typename CELL, typename V = typename CELL::value_t, typename DESCRIPTOR = typename CELL::descriptor_t>
64 for( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
65 floorV[iD] = util::floor(distance[iD]);
66 }
67 Vector<Vector<V,DESCRIPTOR::d>,(DESCRIPTOR::d==2)*4+(DESCRIPTOR::d==3)*8> surroundingPoints(floorV);
68 surroundingPoints[1][0] += 1.;
69 surroundingPoints[2][1] += 1.;
70 surroundingPoints[3][0] += 1.; surroundingPoints[3][1] += 1.;
71 if( DESCRIPTOR::d == 3) {
72 surroundingPoints[4][2] += 1.;
73 surroundingPoints[5][0] += 1.; surroundingPoints[5][2] += 1.;
74 surroundingPoints[6][1] += 1.; surroundingPoints[6][2] += 1.;
75 surroundingPoints[7][0] += 1.; surroundingPoints[7][1] += 1.; surroundingPoints[7][2] += 1.;
76 }
77
78 for (auto point : surroundingPoints) {
79 const Vector<V,DESCRIPTOR::d> dist = distance - point;
80 V weight = V(1);
81 for( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
82 weight *=(V(1.) - util::abs(dist[iD]));
83 }
84 V piNP[util::TensorVal<DESCRIPTOR>::n] {V(0)};
85 cell.neighbor(point).computeStress(piNP);
86 for ( int iN = 0; iN < util::TensorVal<DESCRIPTOR>::n; iN++ ) {
87 pi[iN] += piNP[iN] * weight;
88 }
89 }
90 };
91
92
93 // Spalding wall function written in form of [f = (u+) + ... - (y+)] for the ongoing Newton approximation process
94 // vector = {V u_tau, V u_2, V y_Norm, V nu, V u_plus, V y_plus, V spalding_u2}
95 template <typename V, typename Par_f>
97 if(int (params[6]) == 2){
98 params[4] = params[1]/params[0];
99 params[5] = params[2]/params[3]*params[0];
100 }
101 V k = 0.4;
102 V b = 5.5;
103 V function = params[4] + util::exp(-k*b)*(util::exp(k*params[4]) - 1. - k*params[4] - 0.5*util::pow(k*params[4],2.) - 1./6.*util::pow(k*params[4],3.)) - params[5];
104 return function;
105 };
106
107 // Spalding wall function derivatives [f'(u_2+),f'(u+)] for the ongoing Newton approximation process
108 // vector = {V x, V u2, V y2, V nu, V k}
109 template <typename V, typename Par_d>
111 V derivative = 0.;
112 V k = 0.4;
113 V b = 5.5;
114 if(int (param[4]) == 2){
115 derivative = (-param[1]*(util::pow(param[0],-2.))) + util::exp(-k*b)*( (util::exp(k*param[1]/param[0]))*(-k*param[1]*(util::pow(param[0],-2.))) + k*param[1]/(util::pow(param[0],2.)) + (util::pow(k*param[1]/param[0],2.))/param[0] + 0.5*(util::pow(k*param[1]/param[0],3.))/param[0] ) - (param[2]/param[3]);
116 }
117 if(int (param[4]) == 1){
118 derivative = 1. + util::exp(-k*b)*(util::exp(k*param[0])*k - k - k*k*param[0] - 0.5*k*util::pow(k*param[0],2));
119 }
120 return derivative;
121 };
122
123 // Newton approximation process
124
125 // Newton with derivatives, params=(f:function, d:derivative, args: params, optArg: variable, Crit: Convergence)
126 template <typename V, typename Funcf, typename Funcd, typename Par_f, typename Par_d>
127 V newtonSpalding(Funcf f, Funcd d, Par_f & argsf, Par_d & argsd, int optArg, V convergeCrit, int iter) any_platform{
128 V x = argsf[optArg];
129 V x_old = argsf[optArg];
130 for(int i = 0; i<iter; i++){
131 argsf[optArg] = x;
132 argsd[0] = x;
133 x -= f(argsf)/d(argsd);
134 argsf[optArg] = x;
135 argsd[0] = x;
136 if(util::abs(f(argsf)) < convergeCrit ){
137 break;
138 }
139 if(util::isnan(x)){
140 //printf("x is NAN!!,Applied x=x_old, iter i x_old=%d,%lf,%d\n",i,x_old,optArg);
141 x = x_old;
142 break;
143 }
144 x_old = x;
145 }
146 return x;
147 };
148
149 //Power Law profile
150 //output = {u_tau, u_plus(x1)}
151 template <typename V>
153 Vector<V,2> output(V(0), V(0));
154 V u_tau = util::sqrt(V(0.0246384) * util::pow(nu, V(0.25)) * util::pow(u2, V(1.75)) / util::pow(y2, V(0.25)));
155 V y_plus = y1 * u_tau / nu;
156
157 if (y_plus > V(28.178)) {
158 output[0] = u_tau;
159 output[1] = V(5.5) + V(1./0.399) * util::log(y_plus);
160 }
161 else if (y_plus < V(28.178) && y_plus > V(5.)) {
162 output[0] = u_tau;
163 output[1] = V(-3.05) + V(5.) * util::log(y_plus);
164 }
165 else {
166 output[0] = util::sqrt(V(2.) * u2 * nu / y2);
167 y_plus = y1 * output[0] / nu;
168 output[1] = y_plus;
169 }
170 return output;
171 };
172
173
174
175//======================================================================
176// ======== Wall function velocity and vsiscosity PostProcessor ======//
177//======================================================================
178
179template <bool bodyForce, bool interpolateSampleVelocity, bool useVanDriest, int wallFunctionProfile, bool movingWall>
181public:
184
185 int getPriority() const {
186 return 1;
187 }
188
189 template <typename CELL, typename PARAMETERS, typename V = typename CELL::value_t>
190 void apply(CELL& cell, PARAMETERS& parameters) any_platform {
191 // interpolate the velocity at the y2 point
192 using DESCRIPTOR = typename CELL::descriptor_t;
193 auto y1 = cell.template getField<descriptors::Y1>();
194 V y1Norm = util::norm<DESCRIPTOR::d>(y1);
195 if( y1Norm > V(1.e-3) ){
198 //Vector<V,DESCRIPTOR::d> uWallTang;
199 for ( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
200 normal[iD] = y1[iD] / y1Norm;
201 }
202 V samplingCellDistance = parameters.template get<descriptors::SAMPLING_DISTANCE>();
203 Vector<V,DESCRIPTOR::d> y2 = samplingCellDistance*normal;
204 V u_plusF {};
205 auto y1y2 = y2 - y1;
206 V u_y2[DESCRIPTOR::d] = {0.};
207 if ( interpolateSampleVelocity ) {
208 interpolateVelocity(cell, y1y2, u_y2);
209 } else {
210 Vector<V,DESCRIPTOR::d> roundedNormal;
211 for ( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
212 roundedNormal[iD] = int(util::round(y1y2[iD]));
213 }
214 cell.neighbor(roundedNormal).computeU(u_y2);
215 }
216 if (movingWall) {
217 // I need to go backwards along the normal and take the solid velocity there
218 uWall = cell.template getField<descriptors::VELOCITY>();
219 for ( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
220 u_y2[iD] -= uWall[iD];
221 }
222 }
223 V u_y2Norm = util::norm<DESCRIPTOR::d>(u_y2);
224 if( u_y2Norm >= V(1.e-7)) {
225 V u_1Actual[DESCRIPTOR::d] = {0.};
226 cell.computeU(u_1Actual);
227 if (movingWall) {
228 for ( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
229 u_1Actual[iD] -= uWall[iD];
230 }
231 }
232 V u_y2normal = V(0);
233 for ( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
234 u_y2normal += u_y2[iD]*normal[iD];
235 }
236 auto u_t = u_y2 - u_y2normal*normal;
237 auto tangent = u_t/util::norm<DESCRIPTOR::d>(u_t);
238
239 // computing friction velocity u_tau and tangent velocity at y1 with Spalding function and Newton iteration
240 const V omega = parameters.template get<descriptors::OMEGA>();
241 V nu = (V(1)/omega - 0.5)/descriptors::invCs2<V,DESCRIPTOR>();
242 V u_2 = V(0);
243 for ( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
244 u_2 += u_y2[iD]*tangent[iD];
245 }
246 V y2Norm = util::norm<DESCRIPTOR::d>(y2);
247 V u_tau = cell.template getField<descriptors::U_TAU>();
248 if(u_tau == V(0)){
249 u_tau = util::sqrt(nu*util::abs(u_2)/y2Norm);
250 }
251 V u_plus = util::abs(u_2)/u_tau;
252 V y_plus = y2Norm/nu*u_tau;
253 V u_1t = V(0);
254 for ( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
255 u_1t += u_1Actual[iD]*tangent[iD];
256 }
257 if ( u_2 != 0. ) {
258 if ( wallFunctionProfile == 0 ) {
259 Vector<V,2> wf = powerLawWallFunction(nu, util::abs(u_2), y2Norm, y1Norm);
260 u_tau = wf[0];
261 } else {
263 Vector<V,7> params_u2 = {u_tau, util::abs(u_2), y2Norm, nu, u_plus, y2Norm/nu*u_tau, 2.}; // Vector for spalding wall function
264 Vector<V,5> params_d2 = {u_tau, util::abs(u_2), y2Norm, nu, 2.}; // Vector for spalding derivative
265 u_tau = newtonSpalding( [](Vector<V,7> par1) { return spaldingWallFunction<V>(par1); }, [](Vector<V,5> par2) { return spaldingDerivative<V>(par2); }, params_u2, params_d2, 0, V{0.0001}, 10);
266 }
267 cell.template setField<descriptors::U_TAU>(u_tau);
268
269 if (y2Norm/nu*u_tau > V(2.5)) {
271 u_plus = util::abs(u_1t)/u_tau;
272 y_plus = y1Norm/nu*u_tau;
273 if ( wallFunctionProfile == 0 ) {
274 Vector<V,2> wf = powerLawWallFunction(nu, util::abs(u_2), y2Norm, y1Norm);
275 u_plus = wf[1];
276 } else {
277 Vector<V,7> params_u1 = {u_tau, util::abs(u_1t), y1Norm, nu, u_plus, y_plus, 1.}; //Vector for spalding wall function
278 Vector<V,5> params_d1 = {u_plus, 0., 0., 0., 1.}; // Vector for spalding derivative
279 u_plus = newtonSpalding( [](Vector<V,7> par1) { return spaldingWallFunction<V>(par1); }, [](Vector<V,5> par2) { return spaldingDerivative<V>(par2); }, params_u1, params_d1, 4, V{0.0001},10);
280 }
281 u_plusF = u_plus;
282
283 if(useVanDriest){
284 // Van Driest damping
285 V dUdY = (u_2 - u_plusF*u_tau)/util::norm<DESCRIPTOR::d>(y1y2);
286 V nuTurb = util::pow((V(0.4)*y1Norm*(V(1)-util::exp(-y_plus/V(26)))),2) * util::abs(dUdY);
287 cell.template setField<descriptors::VISCOSITY>(nu+nuTurb);
288 }
289 }
290 }
291 V u_1 = u_plusF*u_tau;
292 // Exchange the computed tangential boundary velocity through the modelled one
293 if(util::norm<DESCRIPTOR::d>(u_t) != 0. && u_1 > 0.){
294 auto ub = u_1*tangent;
295 if (movingWall) {
296 ub = ub + uWall;
297 auto ub_prev = cell.template getField<descriptors::WMVELOCITY>();
298 ub = V{0.9}*ub_prev + V{0.1}*ub;
299 }
300 if (bodyForce) {
301 auto force = cell.template getField<descriptors::FORCE>();
302 V u_b[DESCRIPTOR::d] { };
303 for ( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
304 u_b[iD] = ub[iD]-V(0.5)*force[iD]*tangent[iD];
305 }
306 cell.template setField<descriptors::WMVELOCITY>(u_b);
307 } else {
308 cell.template setField<descriptors::WMVELOCITY>(ub);
309 }
310 }
311 } else {
312 cell.template setField<descriptors::WMVELOCITY>(0);
313 }
314 } else {
315 cell.template setField<descriptors::WMVELOCITY>(0);
316 }
317 }
318};
319
320//======================================================================
321// PostProcessor for fNeq from neighbor cell along the normal for wall modelling
322//======================================================================
323
324 template<int rhoMethod>
326 public:
329
330 int getPriority() const {
331 return 2;
332 }
333
334 template <typename CELL, typename PARAMETERS, typename V = typename CELL::value_t>
335 void apply(CELL& cell, PARAMETERS& parameters) any_platform {
336 using DESCRIPTOR = typename CELL::descriptor_t;
337 auto y1 = cell.template getField<descriptors::Y1>();
338 V y1Norm = util::norm<DESCRIPTOR::d>(y1);
339 if( y1Norm > V(1.e-3)){
340 auto u = cell.template getField<descriptors::WMVELOCITY>();
341 V uNorm = util::norm<DESCRIPTOR::d>(u);
342 if ( uNorm < V(1.e-7) ) {
343 cell.template setField<descriptors::WMPOROSITY>(V(1));
344 cell.template setField<collision::HYBRID>(V(1));
345 if( rhoMethod == 1) {
346 cell.template setField<collision::HYBRID_RHO>(V(1));
347 }
348 else if( rhoMethod == 2) {
349 cell.template setField<collision::HYBRID_RHO>(V(1));
350 }
351 } else {
352 cell.template setField<descriptors::WMPOROSITY>(V(0));
353 cell.template setField<collision::HYBRID>(V(0));
355 for ( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
356 normal[iD] = y1[iD] / y1Norm;
357 }
358 Vector<V,DESCRIPTOR::d> yNext = V(1.5)*normal;
359 //Vector<V,DESCRIPTOR::d> yNextNext = V(3.)*normal;
360 Vector<V,DESCRIPTOR::d> roundedNormal;
361 for ( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
362 roundedNormal[iD] = int(util::round(normal[iD]));
363 }
364 const V omega = parameters.template get<descriptors::OMEGA>();
365 V kinVisc = (V(1)/omega - V(0.5))/descriptors::invCs2<V,DESCRIPTOR>();
366 V invPreFactor = -V(1)/(omega * kinVisc * descriptors::invCs2<V,DESCRIPTOR>());
367 V rho {};
368 if( rhoMethod == 0) {
369 rho = cell.computeRho();
370 }
371 else if( rhoMethod == 1) {
372 rho = cell.neighbor(roundedNormal).computeRho();
373 cell.template setField<descriptors::DENSITY>(rho);
374 cell.template setField<collision::HYBRID_RHO>(V(0));
375 }
376 else if( rhoMethod == 2) {
377 rho = V(1.);
378 cell.template setField<descriptors::DENSITY>(rho);
379 cell.template setField<collision::HYBRID_RHO>(V(0));
380 }
381 V factor = invPreFactor * V(2) * kinVisc * rho;
383 V piNext[util::TensorVal<DESCRIPTOR>::n] {V(0)};
384 //V piNextNext[util::TensorVal<DESCRIPTOR>::n] {V(0)};
385 //cell.neighbor(roundedNormal).computeStress(pi);
386 interpolateStrainRate(cell, yNext, piNext);
387 //interpolateStrainRate(cell, yNextNext, piNextNext);
388 for ( int i = 0; i < util::TensorVal<DESCRIPTOR>::n; i++ ) {
389 pi[i] = piNext[i];// + (piNext[i] - piNextNext[i]);
390 pi[i] /= factor;
391 }
392 cell.template setField<descriptors::TENSOR>(pi);
393 }
394 }
395 }
396 };
397
398//======================================================================
399// PostProcessor for fNeq from finite difference method (FDM) stress tensor for wall modelling
400//======================================================================
401
402 template<int rhoMethod>
404 public:
406
407 int getPriority() const {
408 return 2;
409 }
410
411 template <typename CELL, typename V = typename CELL::value_t>
412 void apply(CELL& cell) any_platform{
413 using DESCRIPTOR = typename CELL::descriptor_t;
414 auto y1 = cell.template getField<descriptors::Y1>();
415 V y1Norm = util::norm<DESCRIPTOR::d>(y1);
416 if( y1Norm > V(1.e-3)){
417 auto u = cell.template getField<descriptors::WMVELOCITY>();
418 V uNorm = util::norm<DESCRIPTOR::d>(u);
419 if ( uNorm < V(1.e-7) ) {
420 cell.template setField<descriptors::WMPOROSITY>(V(1));
421 cell.template setField<collision::HYBRID>(V(1));
422 if( rhoMethod == 1) {
423 cell.template setField<collision::HYBRID_RHO>(V(1));
424 }
425 else if( rhoMethod == 2) {
426 cell.template setField<collision::HYBRID_RHO>(V(1));
427 }
428 } else {
429 cell.template setField<descriptors::WMPOROSITY>(V(0));
430 cell.template setField<collision::HYBRID>(V(0));
431 if constexpr ( DESCRIPTOR::d == 2 ) {
432 using namespace olb::util::tensorIndices2D;
433 V uxDx = 0, uyDx = 0, uxDy = 0, uyDy = 0;
434 //----------- FDM in X-direction --------------------------------------------------//
435 if (y1[0] > V(0)) {
436 auto uXp = cell.neighbor({1,0}).template getField<descriptors::WMVELOCITY>();
437 uxDx = uXp[0] - u[0];
438 uyDx = uXp[1] - u[1];
439 }
440 else if (y1[0] < V(0)) {
441 auto uXm = cell.neighbor({-1,0}).template getField<descriptors::WMVELOCITY>();
442 uxDx = u[0] - uXm[0];
443 uyDx = u[1] - uXm[1];
444 }
445 if (util::abs(y1[0]) < V(1.e-8)) {
446 auto uXp = cell.neighbor({1,0}).template getField<descriptors::WMVELOCITY>();
447 auto uXm = cell.neighbor({-1,0}).template getField<descriptors::WMVELOCITY>();
448 uxDx = V(0.5)*(uXp[0] - uXm[0]);
449 uyDx = V(0.5)*(uXp[1] - uXm[1]);
450 }
451 //----------- FDM in Y-direction --------------------------------------------------//
452 if (y1[1] > V(0)) {
453 auto uYp = cell.neighbor({0,1}).template getField<descriptors::WMVELOCITY>();
454 uxDy = uYp[0] - u[0];
455 uyDy = uYp[1] - u[1];
456 }
457 else if (y1[1] < V(0)) {
458 auto uYm = cell.neighbor({0,-1}).template getField<descriptors::WMVELOCITY>();
459 uxDy = u[0] - uYm[0];
460 uyDy = u[1] - uYm[1];
461 }
462 if (util::abs(y1[1]) < V(1.e-8)) {
463 auto uYp = cell.neighbor({0,1}).template getField<descriptors::WMVELOCITY>();
464 auto uYm = cell.neighbor({0,-1}).template getField<descriptors::WMVELOCITY>();
465 uxDy = V(0.5)*(uYp[0] - uYm[0]);
466 uyDy = V(0.5)*(uYp[1] - uYm[1]);
467 }
468 //----------- TENSOR tensor with FDM --------------------------------------------------//
470 pi[xx] = V(0.5)*(V)2 * uxDx;
471 pi[yy] = V(0.5)*(V)2 * uyDy;
472 pi[xy] = V(0.5)*(uxDy + uyDx);
473 cell.template setField<descriptors::TENSOR>(pi);
474 }
475 else {
476 using namespace olb::util::tensorIndices3D;
477 V uxDx = 0, uyDx = 0, uzDx = 0, uxDy = 0, uyDy = 0, uzDy = 0, uxDz = 0, uyDz = 0, uzDz = 0;
478 //----------- FDM in X-direction --------------------------------------------------//
479 if (y1[0] > V(0)) {
480 auto uXp = cell.neighbor({1,0,0}).template getField<descriptors::WMVELOCITY>();
481 uxDx = uXp[0] - u[0];
482 uyDx = uXp[1] - u[1];
483 uzDx = uXp[2] - u[2];
484 }
485 else if (y1[0] < V(0)) {
486 auto uXm = cell.neighbor({-1,0,0}).template getField<descriptors::WMVELOCITY>();
487 uxDx = u[0] - uXm[0];
488 uyDx = u[1] - uXm[1];
489 uzDx = u[2] - uXm[2];
490 }
491 if (util::abs(y1[0]) < V(1.e-8)) {
492 auto uXp = cell.neighbor({1,0,0}).template getField<descriptors::WMVELOCITY>();
493 auto uXm = cell.neighbor({-1,0,0}).template getField<descriptors::WMVELOCITY>();
494 uxDx = V(0.5)*(uXp[0] - uXm[0]);
495 uyDx = V(0.5)*(uXp[1] - uXm[1]);
496 uzDx = V(0.5)*(uXp[2] - uXm[2]);
497 }
498 //----------- FDM in Y-direction --------------------------------------------------//
499 if (y1[1] > V(0)) {
500 auto uYp = cell.neighbor({0,1,0}).template getField<descriptors::WMVELOCITY>();
501 uxDy = uYp[0] - u[0];
502 uyDy = uYp[1] - u[1];
503 uzDy = uYp[2] - u[2];
504 }
505 else if (y1[1] < V(0)) {
506 auto uYm = cell.neighbor({0,-1,0}).template getField<descriptors::WMVELOCITY>();
507 uxDy = u[0] - uYm[0];
508 uyDy = u[1] - uYm[1];
509 uzDy = u[2] - uYm[2];
510 }
511 if (util::abs(y1[1]) < V(1.e-8)) {
512 auto uYp = cell.neighbor({0,1,0}).template getField<descriptors::WMVELOCITY>();
513 auto uYm = cell.neighbor({0,-1,0}).template getField<descriptors::WMVELOCITY>();
514 uxDy = V(0.5)*(uYp[0] - uYm[0]);
515 uyDy = V(0.5)*(uYp[1] - uYm[1]);
516 uzDy = V(0.5)*(uYp[2] - uYm[2]);
517 }
518 //----------- FDM in Z-direction --------------------------------------------------//
519 if (y1[2] > V(0)) {
520 auto uZp = cell.neighbor({0,0,1}).template getField<descriptors::WMVELOCITY>();
521 uxDz = uZp[0] - u[0];
522 uyDz = uZp[1] - u[1];
523 uzDz = uZp[2] - u[2];
524 }
525 else if (y1[2] < V(0)) {
526 auto uZm = cell.neighbor({0,0,-1}).template getField<descriptors::WMVELOCITY>();
527 uxDz = u[0] - uZm[0];
528 uyDz = u[1] - uZm[1];
529 uzDz = u[2] - uZm[2];
530 }
531 if (util::abs(y1[2]) < V(1.e-8)) {
532 auto uZp = cell.neighbor({0,0,1}).template getField<descriptors::WMVELOCITY>();
533 auto uZm = cell.neighbor({0,0,-1}).template getField<descriptors::WMVELOCITY>();
534 uxDz = V(0.5)*(uZp[0] - uZm[0]);
535 uyDz = V(0.5)*(uZp[1] - uZm[1]);
536 uzDz = V(0.5)*(uZp[2] - uZm[2]);
537 }
538 //----------- TENSOR tensor with FDM --------------------------------------------------//
540 pi[xx] = V(0.5)*(V)2 * uxDx;
541 pi[yy] = V(0.5)*(V)2 * uyDy;
542 pi[zz] = V(0.5)*(V)2 * uzDz;
543 pi[xy] = V(0.5)*(uxDy + uyDx);
544 pi[xz] = V(0.5)*(uxDz + uzDx);
545 pi[yz] = V(0.5)*(uyDz + uzDy);
546 cell.template setField<descriptors::TENSOR>(pi);
547 }
548
549 if( rhoMethod == 1) {
551 for ( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
552 normal[iD] = y1[iD] / y1Norm;
553 }
554 Vector<V,DESCRIPTOR::d> roundedNormal;
555 for ( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
556 roundedNormal[iD] = int(util::round(normal[iD]));
557 }
558 V extRho = cell.neighbor(roundedNormal).computeRho();
559 cell.template setField<descriptors::DENSITY>(extRho);
560 cell.template setField<collision::HYBRID_RHO>(V(0));
561 }
562 else if( rhoMethod == 2) {
563 cell.template setField<descriptors::DENSITY>(V(1.));
564 cell.template setField<collision::HYBRID_RHO>(V(0));
565 }
566 }
567 }
568 }
569 };
570
571
572
573//======================================================================
574// PostProcessor for fNeq from finite difference method (FDM) stress tensor for wall modelling at porous domains
575//======================================================================
576
577 template<int rhoMethod>
579 public:
581
582 int getPriority() const {
583 return 2;
584 }
585
586 template <typename CELL, typename V = typename CELL::value_t>
587 void apply(CELL& cell) any_platform{
588 using DESCRIPTOR = typename CELL::descriptor_t;
589 auto y1 = cell.template getField<descriptors::Y1>();
590 V y1Norm = util::norm<DESCRIPTOR::d>(y1);
591 if( y1Norm > V(1.e-3)){
592 auto u = cell.template getField<descriptors::WMVELOCITY>();
593 V uNorm = util::norm<DESCRIPTOR::d>(u);
594 if ( uNorm < V(1.e-7) ) {
595 cell.template setField<descriptors::WMPOROSITY>(V(1));
596 cell.template setField<collision::HYBRID>(V(1));
597 if( rhoMethod == 1) {
598 cell.template setField<collision::HYBRID_RHO>(V(1));
599 }
600 else if( rhoMethod == 2) {
601 cell.template setField<collision::HYBRID_RHO>(V(1));
602 }
603 } else {
604 cell.template setField<descriptors::WMPOROSITY>(V(0));
605 cell.template setField<collision::HYBRID>(V(0));
606 if constexpr ( DESCRIPTOR::d == 2 ) {
607 using namespace olb::util::tensorIndices2D;
608 V uxDx = 0, uyDx = 0, uxDy = 0, uyDy = 0;
609 //----------- FDM in X-direction --------------------------------------------------//
610 if (y1[0] > V(0) || cell.neighbor({-1,0}).template getField<descriptors::POROSITY>() == V(0)) {
611 V uXp[DESCRIPTOR::d] {};
612 cell.neighbor({1,0}).computeU(uXp);
613 uxDx = uXp[0] - u[0];
614 uyDx = uXp[1] - u[1];
615 }
616 else if (y1[0] < V(0) || cell.neighbor({1,0}).template getField<descriptors::POROSITY>() == V(0)) {
617 V uXm[DESCRIPTOR::d] {};
618 cell.neighbor({-1,0}).computeU(uXm);
619 uxDx = u[0] - uXm[0];
620 uyDx = u[1] - uXm[1];
621 }
622 if (util::abs(y1[0]) < V(1.e-8) &&
623 cell.neighbor({-1,0}).template getField<descriptors::POROSITY>() == V(0) &&
624 cell.neighbor({1,0}).template getField<descriptors::POROSITY>() == V(0)) {
625 V uXp[DESCRIPTOR::d], uXm[DESCRIPTOR::d] {};
626 cell.neighbor({1,0}).computeU(uXp);
627 cell.neighbor({-1,0}).computeU(uXm);
628 uxDx = V(0.5)*(uXp[0] - uXm[0]);
629 uyDx = V(0.5)*(uXp[1] - uXm[1]);
630 }
631 //----------- FDM in Y-direction --------------------------------------------------//
632 if (y1[1] > V(0) || cell.neighbor({0,-1}).template getField<descriptors::POROSITY>() == V(0)) {
633 V uYp[DESCRIPTOR::d] {};
634 cell.neighbor({0,1}).computeU(uYp);
635 uxDy = uYp[0] - u[0];
636 uyDy = uYp[1] - u[1];
637 }
638 else if (y1[1] < V(0) || cell.neighbor({0,1}).template getField<descriptors::POROSITY>() == V(0)) {
639 V uYm[DESCRIPTOR::d] {};
640 cell.neighbor({0,-1}).computeU(uYm);
641 uxDy = u[0] - uYm[0];
642 uyDy = u[1] - uYm[1];
643 }
644 if (util::abs(y1[1]) < V(1.e-8) &&
645 cell.neighbor({0,-1}).template getField<descriptors::POROSITY>() == V(0) &&
646 cell.neighbor({0,1}).template getField<descriptors::POROSITY>() == V(0)) {
647 V uYp[DESCRIPTOR::d], uYm[DESCRIPTOR::d] {};
648 cell.neighbor({0,1}).computeU(uYp);
649 cell.neighbor({0,-1}).computeU(uYm);
650 uxDy = V(0.5)*(uYp[0] - uYm[0]);
651 uyDy = V(0.5)*(uYp[1] - uYm[1]);
652 }
653 //----------- TENSOR tensor with FDM --------------------------------------------------//
655 pi[xx] = V(0.5)*(V)2 * uxDx;
656 pi[yy] = V(0.5)*(V)2 * uyDy;
657 pi[xy] = V(0.5)*(uxDy + uyDx);
658 cell.template setField<descriptors::TENSOR>(pi);
659 }
660 else {
661 using namespace olb::util::tensorIndices3D;
662 V uxDx = 0, uyDx = 0, uzDx = 0, uxDy = 0, uyDy = 0, uzDy = 0, uxDz = 0, uyDz = 0, uzDz = 0;
663 //----------- FDM in X-direction --------------------------------------------------//
664 if (y1[0] > V(0) || cell.neighbor({-1,0,0}).template getField<descriptors::POROSITY>() == V(0)) {
665 V uXp[DESCRIPTOR::d] {};
666 cell.neighbor({1,0,0}).computeU(uXp);
667 uxDx = uXp[0] - u[0];
668 uyDx = uXp[1] - u[1];
669 uzDx = uXp[2] - u[2];
670 }
671 else if (y1[0] < V(0) || cell.neighbor({1,0,0}).template getField<descriptors::POROSITY>() == V(0)) {
672 V uXm[DESCRIPTOR::d] {};
673 cell.neighbor({-1,0,0}).computeU(uXm);
674 uxDx = u[0] - uXm[0];
675 uyDx = u[1] - uXm[1];
676 uzDx = u[2] - uXm[2];
677 }
678 if (util::abs(y1[0]) < V(1.e-8) &&
679 cell.neighbor({-1,0,0}).template getField<descriptors::POROSITY>() == V(0) &&
680 cell.neighbor({1,0,0}).template getField<descriptors::POROSITY>() == V(0)) {
681 V uXp[DESCRIPTOR::d], uXm[DESCRIPTOR::d] {};
682 cell.neighbor({1,0,0}).computeU(uXp);
683 cell.neighbor({-1,0,0}).computeU(uXm);
684 uxDx = V(0.5)*(uXp[0] - uXm[0]);
685 uyDx = V(0.5)*(uXp[1] - uXm[1]);
686 uzDx = V(0.5)*(uXp[2] - uXm[2]);
687 }
688 //----------- FDM in Y-direction --------------------------------------------------//
689 if (y1[1] > V(0) || cell.neighbor({0,-1,0}).template getField<descriptors::POROSITY>() == V(0)) {
690 V uYp[DESCRIPTOR::d] {};
691 cell.neighbor({0,1,0}).computeU(uYp);
692 uxDy = uYp[0] - u[0];
693 uyDy = uYp[1] - u[1];
694 uzDy = uYp[2] - u[2];
695 }
696 else if (y1[1] < V(0) || cell.neighbor({0,1,0}).template getField<descriptors::POROSITY>() == V(0)) {
697 V uYm[DESCRIPTOR::d] {};
698 cell.neighbor({0,-1,0}).computeU(uYm);
699 uxDy = u[0] - uYm[0];
700 uyDy = u[1] - uYm[1];
701 uzDy = u[2] - uYm[2];
702 }
703 if (util::abs(y1[1]) < V(1.e-8) &&
704 cell.neighbor({0,-1,0}).template getField<descriptors::POROSITY>() == V(0) &&
705 cell.neighbor({0,1,0}).template getField<descriptors::POROSITY>() == V(0)) {
706 V uYp[DESCRIPTOR::d], uYm[DESCRIPTOR::d] {};
707 cell.neighbor({0,1,0}).computeU(uYp);
708 cell.neighbor({0,-1,0}).computeU(uYm);
709 uxDy = V(0.5)*(uYp[0] - uYm[0]);
710 uyDy = V(0.5)*(uYp[1] - uYm[1]);
711 uzDy = V(0.5)*(uYp[2] - uYm[2]);
712 }
713 //----------- FDM in Z-direction --------------------------------------------------//
714 if (y1[2] > V(0) || cell.neighbor({0,0,-1}).template getField<descriptors::POROSITY>() == V(0)) {
715 V uZp[DESCRIPTOR::d] {};
716 cell.neighbor({0,0,1}).computeU(uZp);
717 uxDz = uZp[0] - u[0];
718 uyDz = uZp[1] - u[1];
719 uzDz = uZp[2] - u[2];
720 }
721 else if (y1[2] < V(0) || cell.neighbor({0,0,1}).template getField<descriptors::POROSITY>() == V(0)) {
722 V uZm[DESCRIPTOR::d] {};
723 cell.neighbor({0,0,-1}).computeU(uZm);
724 uxDz = u[0] - uZm[0];
725 uyDz = u[1] - uZm[1];
726 uzDz = u[2] - uZm[2];
727 }
728 if (util::abs(y1[2]) < V(1.e-8) &&
729 cell.neighbor({0,0,-1}).template getField<descriptors::POROSITY>() == V(0) &&
730 cell.neighbor({0,0,1}).template getField<descriptors::POROSITY>() == V(0)) {
731 V uZp[DESCRIPTOR::d], uZm[DESCRIPTOR::d] {};
732 cell.neighbor({0,0,1}).computeU(uZp);
733 cell.neighbor({0,0,-1}).computeU(uZm);
734 uxDz = V(0.5)*(uZp[0] - uZm[0]);
735 uyDz = V(0.5)*(uZp[1] - uZm[1]);
736 uzDz = V(0.5)*(uZp[2] - uZm[2]);
737 }
738 //----------- TENSOR tensor with FDM --------------------------------------------------//
740 pi[xx] = V(0.5)*(V)2 * uxDx;
741 pi[yy] = V(0.5)*(V)2 * uyDy;
742 pi[zz] = V(0.5)*(V)2 * uzDz;
743 pi[xy] = V(0.5)*(uxDy + uyDx);
744 pi[xz] = V(0.5)*(uxDz + uzDx);
745 pi[yz] = V(0.5)*(uyDz + uzDy);
746 cell.template setField<descriptors::TENSOR>(pi);
747 }
748
749 if( rhoMethod == 1) {
751 for ( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
752 normal[iD] = y1[iD] / y1Norm;
753 }
754 Vector<V,DESCRIPTOR::d> roundedNormal;
755 for ( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
756 roundedNormal[iD] = int(util::round(normal[iD]));
757 }
758 V extRho = cell.neighbor(roundedNormal).computeRho();
759 cell.template setField<descriptors::DENSITY>(extRho);
760 cell.template setField<collision::HYBRID_RHO>(V(0));
761 }
762 else if( rhoMethod == 2) {
763 cell.template setField<descriptors::DENSITY>(V(1.));
764 cell.template setField<collision::HYBRID_RHO>(V(0));
765 }
766 }
767 } else {
768 cell.template setField<descriptors::WMPOROSITY>(V(1));
769 cell.template setField<collision::HYBRID>(V(1));
770 if( rhoMethod == 1) {
771 cell.template setField<collision::HYBRID_RHO>(V(1));
772 }
773 else if( rhoMethod == 2) {
774 cell.template setField<collision::HYBRID_RHO>(V(1));
775 }
776 }
777 }
778 };
779
780
781//======================================================================
782// PostProcessor for zero fNeq for wall modelling
783//======================================================================
784
785 template<int rhoMethod>
787 public:
789
790 int getPriority() const {
791 return 2;
792 }
793
794 template <typename CELL, typename V = typename CELL::value_t>
795 void apply(CELL& cell) any_platform{
796 using DESCRIPTOR = typename CELL::descriptor_t;
797 auto u = cell.template getField<descriptors::WMVELOCITY>();
798 V uNorm = util::norm<DESCRIPTOR::d>(u);
799 if ( uNorm < V(1.e-7) ) {
800 cell.template setField<descriptors::WMPOROSITY>(V(1));
801 cell.template setField<collision::HYBRID>(V(1));
802 if( rhoMethod == 1) {
803 cell.template setField<collision::HYBRID_RHO>(V(1));
804 }
805 else if( rhoMethod == 2) {
806 cell.template setField<collision::HYBRID_RHO>(V(1));
807 }
808 } else {
809 if( rhoMethod == 1) {
810 auto y1 = cell.template getField<descriptors::Y1>();
811 V y1Norm = util::norm<DESCRIPTOR::d>(y1);
813 for ( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
814 normal[iD] = y1[iD] / y1Norm;
815 }
816 Vector<V,DESCRIPTOR::d> roundedNormal;
817 for ( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
818 roundedNormal[iD] = int(util::round(normal[iD]));
819 }
820 V extRho = cell.neighbor(roundedNormal).computeRho();
821 cell.template setField<descriptors::DENSITY>(extRho);
822 cell.template setField<collision::HYBRID_RHO>(V(0));
823 }
824 else if( rhoMethod == 2) {
825 cell.template setField<descriptors::DENSITY>(V(1.));
826 cell.template setField<collision::HYBRID_RHO>(V(0));
827 }
828 cell.template setField<descriptors::WMPOROSITY>(V(0));
829 cell.template setField<collision::HYBRID>(V(0));
831
832 cell.template setField<descriptors::TENSOR>(pi);
833 }
834 }
835 };
836}
837#endif
void apply(CELL &cell, PARAMETERS &parameters) any_platform
void apply(CELL &cell, PARAMETERS &parameters) any_platform
Plain old scalar vector.
constexpr T invCs2() any_platform
Definition functions.h:107
ADf< T, DIM > abs(const ADf< T, DIM > &a)
Definition aDiff.h:1019
ADf< T, DIM > floor(const ADf< T, DIM > &a)
Definition aDiff.h:869
Expr sqrt(Expr x)
Definition expr.cpp:225
ADf< T, DIM > log(const ADf< T, DIM > &a)
Definition aDiff.h:475
any_platform bool isnan(T arg)
Definition omath.h:1621
ADf< T, DIM > round(const ADf< T, DIM > &a)
Definition aDiff.h:928
T norm(const std::vector< T > &a)
l2 norm of a vector of arbitrary length
Expr pow(Expr base, Expr exp)
Definition expr.cpp:235
Expr exp(Expr x)
Definition expr.cpp:240
Top level namespace for all of OpenLB.
Vector< V, 2 > powerLawWallFunction(V nu, V u2, V y2, V y1) any_platform
void interpolateStrainRate(CELL &cell, Vector< V, DESCRIPTOR::d > distance, V pi[util::TensorVal< DESCRIPTOR >::n]) any_platform
V newtonSpalding(Funcf f, Funcd d, Par_f &argsf, Par_d &argsd, int optArg, V convergeCrit, int iter) any_platform
V spaldingWallFunction(Par_f &params) any_platform
void interpolateVelocity(CELL &cell, Vector< V, DESCRIPTOR::d > distance, V u_y2[DESCRIPTOR::d]) any_platform
OperatorScope
Block-wide operator application scopes.
@ PerCell
Per-cell application, i.e. OPERATOR::apply is passed a CELL concept implementation.
@ PerCellWithParameters
Per-cell application with parameters, i.e. OPERATOR::apply is passed a CELL concept implementation an...
V spaldingDerivative(Par_d &param) any_platform
#define any_platform
Define preprocessor macros for device-side functions, constant storage.
Definition platform.h:77
Plain wrapper for list of types.
Definition meta.h:276
Compute number of elements of a symmetric d-dimensional tensor.
Definition util.h:216