OpenLB 1.8.1
Loading...
Searching...
No Matches
knudsenVelocityPostProcessor.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 KNUDSEN_VELOCITY_POST_PROCESSOR_H
25#define KNUDSEN_VELOCITY_POST_PROCESSOR_H
26
27namespace olb {
28//======================================================================
29// ======== Knudsen General Slip PostProcessor ======//
30//======================================================================
31// interpolation of the momentum along the surface normal on the chosen distance from the boundary cell
32 template <typename CELL, typename V = typename CELL::value_t, typename DESCRIPTOR = typename CELL::descriptor_t>
36 for( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
37 floorV[iD] = util::floor(distance[iD]);
38 }
39 Vector<Vector<V,DESCRIPTOR::d>,(DESCRIPTOR::d==2)*4+(DESCRIPTOR::d==3)*8> surroundingPoints(floorV);
40 surroundingPoints[1][0] += 1.;
41 surroundingPoints[2][1] += 1.;
42 surroundingPoints[3][0] += 1.; surroundingPoints[3][1] += 1.;
43 if( DESCRIPTOR::d == 3) {
44 surroundingPoints[4][2] += 1.;
45 surroundingPoints[5][0] += 1.; surroundingPoints[5][2] += 1.;
46 surroundingPoints[6][1] += 1.; surroundingPoints[6][2] += 1.;
47 surroundingPoints[7][0] += 1.; surroundingPoints[7][1] += 1.; surroundingPoints[7][2] += 1.;
48 }
49
50 V sumWeight = V(0);
51 for (auto point : surroundingPoints) {
52 const Vector<V,DESCRIPTOR::d> dist = distance - point;
53 V weight = V(1);
54 for( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
55 weight *=(V(1.) - util::abs(dist[iD]));
56 }
57 auto jNP = cell.neighbor(point).template getField<descriptors::VELOCITY>();
58 for( int iD = 0; iD < DESCRIPTOR::d; iD++ ) {
59 if(!std::isnan(jNP[iD])) {
60 momentum[iD] += jNP[iD]*weight;
61 sumWeight += (iD==0)*weight;
62 }
63 }
64 }
65 momentum *= V(1)/sumWeight;
66 return momentum;
67 };
68
69 template<bool thermalCreep = false>
71 public:
73 struct SLIPCOEFF : public descriptors::FIELD_BASE<1> { };
74 struct CREEPCOEFF : public descriptors::FIELD_BASE<1> { };
76
77 int getPriority() const {
78 return -10;
79 }
80
81 template <typename CELL, typename PARAMETERS, typename V = typename CELL::value_t>
82 void apply(CELL& cell, PARAMETERS& parameters) any_platform{
83
84 using DESCRIPTOR = typename CELL::descriptor_t;
85 auto normal = cell.template getField<descriptors::NORMAL>();
86 if(util::norm<DESCRIPTOR::d>(normal) != V(0)) {
87 const V slipCoeff = parameters.template get<SLIPCOEFF>();
88 const V creepCoeff = parameters.template get<CREEPCOEFF>();
89 const V dX = V(2);
90 V veloCoeff[DESCRIPTOR::q] {V(0)};
92 if(thermalCreep) {
93 V rho = cell.computeRho();
94 uC = cell.template getField<descriptors::TEMPGRADIENT>();
95 uC *= rho*creepCoeff;
96 }
97 for (int iPop=1; iPop < descriptors::q<DESCRIPTOR>(); ++iPop) {
98 const int iPop_opposite = descriptors::opposite<DESCRIPTOR>(iPop);
99 const auto opp_bouzidi_dist = cell.template getFieldComponent<descriptors::BOUZIDI_DISTANCE>(iPop_opposite);
100 if (opp_bouzidi_dist >= 0) {
101 const auto c = descriptors::c<DESCRIPTOR>(iPop_opposite);
102 auto dist0 = opp_bouzidi_dist * c + normal*dX;
103 auto dist1 = opp_bouzidi_dist * c + normal*V(2)*dX;
104 auto jSample0 = interpolateMomentum(cell, dist0);
105 auto jSample1 = interpolateMomentum(cell, dist1);
106 V jSampleNormal0 = jSample0*normal;
107 V jSampleNormal1 = jSample1*normal;
108 auto jSampleTang0 = jSample0 - jSampleNormal0*normal;
109 auto jSampleTang1 = jSample1 - jSampleNormal1*normal;
110 auto jSlip = V(1)/(1. + (1./dX)*3./2.*slipCoeff)*(slipCoeff/dX*0.5*(4.*jSampleTang0 - jSampleTang1) + uC);
111 veloCoeff[iPop_opposite] = c*jSlip;
112 }
113 }
114
115 // Bouzidi step
116 const auto q = cell.template getFieldPointer<descriptors::BOUZIDI_DISTANCE>();
117 for (int iPop=1; iPop < descriptors::q<DESCRIPTOR>(); ++iPop) {
118 // update missing population if valid bouzidi distance
119 if (q[iPop] > 0) {
120 const auto c = descriptors::c<DESCRIPTOR>(iPop);
121 const int iPop_opposite = descriptors::opposite<DESCRIPTOR>(iPop);
122 auto x_s = cell.neighbor(c); // solid side neighbor
123 auto x_f = cell.neighbor(descriptors::c<DESCRIPTOR>(iPop_opposite)); // fluid side neighbor opposite to the missing population
124 auto veloTerm = veloCoeff[iPop] * (descriptors::t<V,DESCRIPTOR>(iPop)) * (descriptors::invCs2<V,DESCRIPTOR>());
125
126 cell[iPop_opposite] = (q[iPop] <= V{0.5}) // cut is closer to the fluid cell
127 * (V{2} * q[iPop] * x_s[iPop] + (V{1} - V{2} * q[iPop]) * cell[iPop] - V{2} * veloTerm)
128 + (q[iPop] > V{0.5}) // cut is closer to the solid cell
129 * (V{0.5} / q[iPop] * x_s[iPop] + V{0.5} * (V{2} * q[iPop] - V{1}) / q[iPop] * x_f[iPop_opposite] - V{1}/q[iPop] * veloTerm);
130 }
131 // if intersection point is on the cell then fall back to full-way bounce back
132 else if (q[iPop] == V{0}) {
133 const int iPop_opposite = descriptors::opposite<DESCRIPTOR>(iPop);
134 auto veloTerm = veloCoeff[iPop] * (descriptors::t<V,DESCRIPTOR>(iPop)) * (descriptors::invCs2<V,DESCRIPTOR>());
135 cell[iPop_opposite] = cell[iPop] - V{2} * veloTerm;
136 }
137 }
138 }
139 }
140 };
141}
142#endif
void apply(CELL &cell, PARAMETERS &parameters) any_platform
Plain old scalar vector.
constexpr T invCs2() any_platform
Definition functions.h:107
constexpr T t(unsigned iPop, tag::CUM) any_platform
Definition cum.h:108
constexpr int c(unsigned iPop, unsigned iDim) any_platform
Definition functions.h:83
constexpr int opposite(unsigned iPop) any_platform
Definition functions.h:95
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
T norm(const std::vector< T > &a)
l2 norm of a vector of arbitrary length
Top level namespace for all of OpenLB.
Vector< V, DESCRIPTOR::d > interpolateMomentum(CELL &cell, Vector< V, DESCRIPTOR::d > distance) any_platform
OperatorScope
Block-wide operator application scopes.
@ PerCellWithParameters
Per-cell application with parameters, i.e. OPERATOR::apply is passed a CELL concept implementation an...
#define any_platform
Define preprocessor macros for device-side functions, constant storage.
Definition platform.h:77
Base of a field whose size is defined by [C_0,C_1,C_2]^T * [1,D,Q].
Definition fields.h:52
Plain wrapper for list of types.
Definition meta.h:276