OpenLB 1.8.1
Loading...
Searching...
No Matches
bouzidiSlipVelocityPostProcessor3D.h
Go to the documentation of this file.
1
2/* Lattice Boltzmann sample, written in C++, using the OpenLB
3 * library
4 *
5 * Copyright (C) 2023, Fedor Bukrev, Anas Selmi, Adrian Kummerländer, Mathias J. Krause
6 * E-mail contact: info@openlb.net
7 * The most recent release of OpenLB can be downloaded at
8 * <http://www.openlb.net/>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public
21 * License along with this program; if not, write to the Free
22 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
24 */
25
26// This file contains the implementation for General slip boundary condition
27// used in slip and moderate transition flow regimes (high Kn number)
28// See example microPoiseuille flow for use
29// It follows the equation below to compute the relative velocity on the wall:
30// U_slip = lambda dU/dn
31// To use it, first use setBouzidiBoundary<T,DESCRIPTOR,BouzidiSlipVelocityPostProcessor>();
32// Then setBouzidiGeneralSlipVelocity() with desired parameters
33// The parameters need to be set by sLattice.setParameter as in example
34
35#ifndef SET_GENERAL_SLIP_VELOCITY_POST_PROCESSOR_3D_H
36#define SET_GENERAL_SLIP_VELOCITY_POST_PROCESSOR_3D_H
37
38namespace olb {
39
40namespace descriptors {
41struct FD_DEG : public TYPED_FIELD_BASE<int, 1,0,0> {
42 template <typename T, typename DESCRIPTOR>
43 static constexpr auto getInitialValue() {
44 return Vector<value_type<T>,DESCRIPTOR::template size<FD_DEG>()>(1);
45 }
46};
47struct BOUZIDI_TUNER : public descriptors::FIELD_BASE<1,0,0> {
48 template <typename T, typename DESCRIPTOR>
49 static constexpr auto getInitialValue() {
50 return Vector<value_type<T>,DESCRIPTOR::template size<BOUZIDI_TUNER>()>(0.);
51 }
52};
53struct LAMBDA : public FIELD_BASE<1, 0, 0> { };
54struct CHAR_LENGTH : public FIELD_BASE<1, 0, 0> { };
55struct CONVERSION_FACTOR_VELOCITY: public FIELD_BASE<1, 0, 0> { };
56struct CONVERSION_FACTOR_LENGTH : public FIELD_BASE<1, 0, 0> { };
57
58}
59
60template <typename CELL, typename V = typename CELL::value_t,
61 typename DESCRIPTOR = typename CELL::descriptor_t>
63{
64 const auto q = x_b.template getFieldPointer<descriptors::BOUZIDI_DISTANCE>();
65 const auto veloCoeff =
66 x_b.template getFieldPointer<descriptors::BOUZIDI_VELOCITY>();
67 //const auto material = x_b.template getField<descriptors::MATERIAL>();
68 for (int iPop = 1; iPop < descriptors::q<DESCRIPTOR>(); ++iPop) {
69 // update missing population if valid bouzidi distance
70 if (q[iPop] > 0) {
71 const auto c = descriptors::c<DESCRIPTOR>(iPop);
72 const int iPop_opposite = descriptors::opposite<DESCRIPTOR>(iPop);
73 auto x_s = x_b.neighbor(c); // solid side neighbor
74 auto x_f = x_b.neighbor(descriptors::c<DESCRIPTOR>(
75 iPop_opposite)); // fluid side neighbor opposite to the missing population
76 auto veloTerm = veloCoeff[iPop] * (descriptors::t<V, DESCRIPTOR>(iPop)) *
78
79 x_b[iPop_opposite] =
80 (q[iPop] <= V {0.5}) // cut is closer to the fluid cell
81 * (V {2} * q[iPop] * x_s[iPop] +
82 (V {1} - V {2} * q[iPop]) * x_b[iPop] - V {2} * veloTerm) +
83 (q[iPop] > V {0.5}) // cut is closer to the solid cell
84 * (V {0.5} / q[iPop] * x_s[iPop] +
85 V {0.5} * (V {2} * q[iPop] - V {1}) / q[iPop] *
86 x_f[iPop_opposite] -
87 V {1} / q[iPop] * veloTerm);
88 }
89 // if intersection point is on the cell then fall back to full-way bounce back
90 else if (q[iPop] == V {0}) {
91 const int iPop_opposite = descriptors::opposite<DESCRIPTOR>(iPop);
92 auto veloTerm = veloCoeff[iPop] * (descriptors::t<V, DESCRIPTOR>(iPop)) *
94 x_b[iPop_opposite] = x_b[iPop] - V {2} * veloTerm;
95 }
96 }
97};
98
99//======================================================================
100// ======== Bouzidi General Slip Velocity 3D Post Processor ======//
101//======================================================================
102
103/* Post processor: BouzidiSlipVelocityPostProcessor
104 * This class calculate the slip velocity on a cell from
105 * neighbor velocities in normal direction.
106 */
108public:
110 struct TANGENT : public descriptors::FIELD_BASE<0, 1, 0> {};
111 struct BOUZIDI_SLIP : public descriptors::FIELD_BASE<0, 0, 1> {};
112
113 int getPriority() const { return -1; }
114
119
120 template <typename CELL, typename PARAMETERS,
121 typename V = typename CELL::value_t>
122 void apply(CELL& cell, PARAMETERS& parameters) any_platform
123 {
124
125 // get parameters
126 using DESCRIPTOR = typename CELL::descriptor_t;
127 auto bouzidiVel =
128 cell.template getFieldPointer<descriptors::BOUZIDI_VELOCITY>();
129 const V tuner = parameters.template get<descriptors::BOUZIDI_TUNER>();
130 const V lambda = parameters.template get<descriptors::LAMBDA>();
131 const V conversionFactorVelocity =
132 parameters.template get<descriptors::CONVERSION_FACTOR_VELOCITY>();
133 const V conversionFactorLength =
134 parameters.template get<descriptors::CONVERSION_FACTOR_LENGTH>();
135 const V charLength = parameters.template get<descriptors::CHAR_LENGTH>();
136 const int fd_degree = parameters.template get<
137 descriptors::
138 FD_DEG>(); // degree of the finite difference gradient calculation
139
140 //lbm::computeEquilibriumSecondOrder() must be done for every population direction
143
144 Vector<V, DESCRIPTOR::d> u0_latt {};
145 Vector<V, DESCRIPTOR::d> u0_phys {};
146 cell.computeU(u0_latt.data());
147 u0_phys = u0_latt * conversionFactorVelocity;
148
149 // do nothing if the norm of the normal vector is 0
150
151 for (int iPop = 1; iPop < DESCRIPTOR::q; ++iPop) {
152
153 const int iPop_opposite = descriptors::opposite<DESCRIPTOR>(iPop);
154 const auto opp_bouzidi_dist =
155 cell.template getFieldComponent<descriptors::BOUZIDI_DISTANCE>(
156 iPop_opposite);
157 normal = cell.template getField<
158 descriptors::NORMAL>(); // normal vector with length dx
159 V normal_norm = util::norm<DESCRIPTOR::d>(normal);
160
161 if (normal_norm != V {0.}) {
162 normal = normal / normal_norm;
163 }
164
165 Vector<V, DESCRIPTOR::d> u1_latt {};
166 Vector<V, DESCRIPTOR::d> u2_latt {};
167 Vector<V, DESCRIPTOR::d> u3_latt {};
168 Vector<V, DESCRIPTOR::d> u1_phys {};
169 Vector<V, DESCRIPTOR::d> u2_phys {};
170 Vector<V, DESCRIPTOR::d> u3_phys {};
171
172 Vector<V, DESCRIPTOR::d> us_phys(V(0.));
173 Vector<V, DESCRIPTOR::d> us_t_phys(V(0.));
174 // delta is distance to go along the normal where to take value for gradient computation
175 V delta = 2;
176
177 if ((opp_bouzidi_dist >= 0) && (normal_norm != 0)) {
178
179 // interpolate velocity at points delta, 2*delta and 3*delta along normal vector
180 //Vector<V,3> coeff {-2.5, 4, -1.5}; // coefficients for 3 point gradient computation
181 Vector<V, DESCRIPTOR::d> distance_bc(
182 opp_bouzidi_dist * descriptors::c<DESCRIPTOR>(iPop_opposite));
183 Vector<V, DESCRIPTOR::d> distance = delta * normal + distance_bc;
184 if (norm(distance) != V {0.}) {
185 interpolate3d<3>(cell, u1_latt, distance, [](auto cell, V res[3]){
186 cell.computeU(res);
187 });
188 u1_phys = u1_latt * conversionFactorVelocity;
189 distance = V(2) * delta * normal + distance_bc;
190 //distance = distance_bc + normal * charLength/(4*conversionFactorLength);
191 interpolate3d<3>(cell, u2_latt, distance, [](auto cell, V res[3]){
192 cell.computeU(res);
193 });
194 u2_phys = u2_latt * conversionFactorVelocity;
195 V sign = 1;
196 if (u1_phys > u2_phys) {
197 sign = -1;
198 }
199
200 //distance = 3*delta * normal + distance_bc;
201 //interpolateVelocityOnPoint(cell, distance, u3_latt);
202 //u3_phys = u3_latt * conversionFactorVelocity;
203 // Only compute slip if neighbor velocity is non zero
204 if (norm(u1_phys) > 0) {
205 // compute tangent velocity to boundary from neighbor velocity
206 tangent = u1_phys - normal * (u1_phys[0] * normal[0] +
207 u1_phys[1] * normal[1] +
208 u1_phys[2] * normal[2]);
209 tangent /= norm(tangent);
210 if (tangent[1] < 1e-3) {
211 tangent[1] = 0;
212 }
213 if (tangent[2] < 1e-3) {
214 tangent[2] = 0;
215 }
216 tangent /= norm(tangent);
217
218 // compute slip velocity using gradient along normal direction
219 auto kn = lambda / charLength;
220 V lambda_eff = lambda;
221 if (kn > 0) {
222 lambda_eff = 1 / (1 / lambda + tuner / charLength);
223 // tuner = 0 -> usual mean free path, tuner = 1 -> effective mean free path
224 }
225
226 if (fd_degree == 0) {
227 us_phys = tuner * u1_phys;
228 }
229 else if (fd_degree == 1) {
230 us_phys =
231 sign * lambda_eff /
232 (lambda_eff + delta * conversionFactorLength * norm(normal)) *
233 u1_phys;
234 }
235 else if (fd_degree == 2) {
236 us_phys = sign * lambda_eff /
237 (1.5 * lambda_eff +
238 delta * conversionFactorLength * norm(normal)) *
239 (2 * u1_phys - 0.5 * u2_phys);
240 //us_phys = sign * lambda_eff / (1.75*lambda_eff + delta*conversionFactorLength*norm(normal)) * (2.*u1_phys - 0.25*u2_phys);
241 }
242 //us_phys = lambda_eff * (2.*u1_phys - (7./4.)*u0_phys - 0.25*u2_phys) / (delta*conversionFactorLength); // u slip physical units
243 //us_phys = -(1.)*lambda_eff / (1.75*lambda_eff + delta*conversionFactorLength*norm(normal)) * (2.*u1_phys - 0.25*u2_phys);
244 //us_phys = (-1.)*lambda_eff / (lambda_eff + delta*conversionFactorLength*norm(normal)) * u1_phys;
245 //us_phys = lambda_eff * (u2_phys - u1_phys)/(delta*conversionFactorLength*norm(normal));
246 //us_phys = lambda_eff * (-2.5*u1_phys + 4*u2_phys - 1.5*u3_phys) / (delta*conversionFactorLength*norm(normal));
247
248 if (kn >= 10) {
249 us_phys = u1_phys;
250 }
251 // project u_s on the boundary-tangential vector
252 us_t_phys = us_phys - (us_phys * normal) * normal;
253 //us_t_phys = (us_phys*tangent)*tangent;
254 }
255
256 // Conversion from physical units to lattice units
257 Vector<V, DESCRIPTOR::d> us_t_lattice =
258 us_t_phys / conversionFactorVelocity;
259 cell.template setField<descriptors::VELOCITY2>(us_t_phys);
260 const auto c = descriptors::c<DESCRIPTOR>(iPop_opposite);
261 //V rho = interpolateDensityOnPoint(cell, 2 * normal);
262 V vel_slip_coeff = c * us_t_lattice;
263 bouzidiVel[iPop_opposite] = vel_slip_coeff;
264 }
265 }
266 } // for iPop
267
269 //BouzidiVelocityPostProcessor::apply(cell)
270 // write Fields for output
271 cell.template setField<descriptors::NORMAL>(normal);
272 cell.template setField<TANGENT>(tangent);
273 }
274};
275
276} // namespace olb
277#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
T norm(const std::vector< T > &a)
l2 norm of a vector of arbitrary length
Top level namespace for all of OpenLB.
void interpolate3d(CELL &cell, RESULT &result, const Vector< V, 3 > distance, F f) any_platform
trilinear interpolation of function f
void applyBouzidiVelocity(CELL &x_b) 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...
constexpr T norm(const ScalarVector< T, D, IMPL > &a) any_platform
Euclidean vector norm.
#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
static constexpr std::size_t size()
Definition fields.h:70
Base of a descriptor field of scalar TYPE.
Definition fields.h:132
Plain wrapper for list of types.
Definition meta.h:276