OpenLB 1.8.1
Loading...
Searching...
No Matches
bouzidiTemperatureJumpPostProcessor3D.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, Anas Selmi, Shota Ito, 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 temperature jump boundary condition
27// used in slip and moderate transition flow regimes (high Kn number)
28// See example tempJumpTest for use
29// It follows the equation below to compute the temperature of the fluid on the wall:
30// T_f = c dT/dn
31// To use it, first use setBouzidiBoundary<T,DESCRIPTOR,TemperatureJumpPostProcessor>();
32// Then setBouzidiTempJump() with desired parameters
33// The parameters need to be set by sLattice.setParameter as in example
34
35#ifndef SET_TEMPERATURE_JUMP_POST_PROCESSOR_3D_H
36#define SET_TEMPERATURE_JUMP_POST_PROCESSOR_3D_H
38namespace olb {
39
40namespace descriptors {
41
43 template <typename T, typename DESCRIPTOR>
44 static constexpr auto getInitialValue()
45 {
47 DESCRIPTOR::template size<BOUZIDI_WALL_TEMP>()>(0);
48 }
49};
50
52 template <typename T, typename DESCRIPTOR>
53 static constexpr auto getInitialValue()
54 {
56 DESCRIPTOR::template size<BOUZIDI_JUMP_TEMP>()>(0);
57 }
58};
59
60} // namespace descriptors
61
62template <typename CELL, typename V = typename CELL::value_t>
64{
65 using DESCRIPTOR = typename CELL::descriptor_t;
66 const auto q = x_b.template getFieldPointer<descriptors::BOUZIDI_DISTANCE>();
67 const auto phi_d =
68 x_b.template getFieldPointer<descriptors::BOUZIDI_JUMP_TEMP>();
69 V f = V {1 / 3}; // D2Q5
70 if (descriptors::q<DESCRIPTOR>() == 7) {
71 f = V {0.25}; // D3Q7
72 }
73 for (int iPop = 1; iPop < descriptors::q<DESCRIPTOR>(); ++iPop) {
74 // update missing population if valid bouzidi distance
75 if (q[iPop] > V {0}) {
76 const auto c = descriptors::c<DESCRIPTOR>(iPop);
77 const int iPop_opposite = descriptors::opposite<DESCRIPTOR>(iPop);
78 auto x_s = x_b.neighbor(c); // solid side neighbor
79 auto x_f = x_b.neighbor(descriptors::c<DESCRIPTOR>(
80 iPop_opposite)); // fluid side neighbor opposite to the missing population
81 auto source_d =
82 phi_d[iPop] * f; // source term set by the dirichlet condition
83 auto t_i = descriptors::t<V, DESCRIPTOR>(iPop);
84 auto t_iopp = descriptors::t<V, DESCRIPTOR>(iPop_opposite);
85
86 x_b[iPop_opposite] =
87 (q[iPop] <= V {0.5}) // cut is closer to the fluid cell
88 * (V {-2} * q[iPop] * (x_s[iPop] + t_i) +
89 (V {2} * q[iPop] - V {1}) * (x_b[iPop] + t_i) + source_d) +
90 (q[iPop] > V {0.5}) // cut is closer to the solid cell
91 * (V {-1} / (V {2} * q[iPop]) * (x_s[iPop] + t_i) +
92 (V {1} - V {1} / (V {2} * q[iPop])) *
93 (x_f[iPop_opposite] + t_iopp) +
94 (V {1} / (V {2} * q[iPop])) * source_d) -
95 t_iopp;
96 }
97 // if intersection point is on the cell then fall back to full-way bounce back
98 else if (q[iPop] == V {0}) {
99 const int iPop_opposite = descriptors::opposite<DESCRIPTOR>(iPop);
100 auto source_d = phi_d[iPop] * f;
101 auto t_i = descriptors::t<V, DESCRIPTOR>(iPop);
102 auto t_iopp = descriptors::t<V, DESCRIPTOR>(iPop_opposite);
103 x_b[iPop_opposite] = -(x_b[iPop] + t_i) + source_d - t_iopp;
104 }
105 }
106};
107
108//======================================================================
109// ======== Bouzidi Temperature Jump 3D Post Processor ======//
110//======================================================================
112public:
114
115 int getPriority() const {
116 return -1;
117 }
118
119 template <typename CELL, typename V = typename CELL::value_t>
121 {
122 static_assert(CELL::descriptor_t::d == 3);
123 Vector<int, 3> floorV(util::floor(distance[0]), util::floor(distance[1]),
124 util::floor(distance[2]));
125 Vector<Vector<int, 3>, 8> surroundingPoints(floorV);
126 // surroundingPoints[0] contains point at floor x, floor y, floor z
127 surroundingPoints[1][0] += 1; // x+1, y, z
128 surroundingPoints[2][1] += 1; // x, y+1, z
129 surroundingPoints[3][2] += 1; // x, y, z+1
130 surroundingPoints[4][0] += 1;
131 surroundingPoints[4][1] += 1; // x+1, y+1,z
132 surroundingPoints[5][0] += 1;
133 surroundingPoints[5][2] += 1; // x+1, y, z+1
134 surroundingPoints[6][1] += 1;
135 surroundingPoints[6][2] += 1; // x, y+1, z+1
136 surroundingPoints[7][0] += 1;
137 surroundingPoints[7][1] += 1;
138 surroundingPoints[7][2] += 1; // x+1, y+1, z+1
139 V rho = 0.;
140 for (int nP = 0; nP < 8; nP++) {
141 auto dist = distance - surroundingPoints[nP];
142 //V volume = util::abs(dist[0] * dist[1] * dist[2]);
143 V volume = (V(1) - util::abs(dist[0])) * (V(1) - util::abs(dist[1])) *
144 (V(1) - util::abs(dist[2]));
145 rho += volume * cell.neighbor(surroundingPoints[nP]).computeRho();
146 }
147 return rho;
148 }
149
153 descriptors::SCALAR // SCALAR is C = (2*gamma/(gamma+1))*1/Pr
154 >;
155
156 template <typename CELL, typename PARAMETERS,
157 typename V = typename CELL::value_t>
158 void apply(CELL& cell, PARAMETERS& parameters) any_platform
159 {
160
161 // get parameters
162 using DESCRIPTOR = typename CELL::descriptor_t;
163
164 const V lambda = parameters.template get<descriptors::LAMBDA>();
165 const V conversionFactorLength =
166 parameters.template get<descriptors::CONVERSION_FACTOR_LENGTH>();
167 const V charLength = parameters.template get<descriptors::CHAR_LENGTH>();
168 const V scalar = parameters.template get<descriptors::SCALAR>();
169 const auto phi_d =
170 cell.template getFieldPointer<descriptors::BOUZIDI_WALL_TEMP>();
171 auto bouzidiTemp =
172 cell.template getFieldPointer<descriptors::BOUZIDI_JUMP_TEMP>();
173
175 normal = cell.template getField<descriptors::NORMAL>();
176
177 // do nothing if the norm of the normal vector is 0
178 V normal_norm = util::norm<DESCRIPTOR::d>(normal);
179 if (normal_norm != V {0.}) {
180 normal = normal / normal_norm;
181 }
182 for (int iPop = 1; iPop < DESCRIPTOR::q; ++iPop) {
183
184 const int iPop_opposite = descriptors::opposite<DESCRIPTOR>(iPop);
185 const auto opp_bouzidi_dist =
186 cell.template getFieldComponent<descriptors::BOUZIDI_DISTANCE>(
187 iPop_opposite);
188
189 if ((opp_bouzidi_dist >= 0) && (normal_norm != 0)) {
190 V delta = 2;
191 Vector<V, DESCRIPTOR::d> distance_bc(
192 opp_bouzidi_dist * descriptors::c<DESCRIPTOR>(iPop_opposite));
193 Vector<V, DESCRIPTOR::d> distance = delta * normal + distance_bc;
194 if (norm(distance) != V {0.}) {
195 V T_1 = interpolateDensityOnPoint(cell, distance);
196 V T_2 = interpolateDensityOnPoint(cell, 2 * delta * normal + distance_bc);
197 // compute Jump temperature using gradient along normal direction
198 V lambda_eff = lambda;
199 // First degree gradient
200 V Dx = delta * conversionFactorLength;
201 //V T_f = (lambda_eff*scalar*T_1 + Dx*phi_d[iPop_opposite]) / (Dx + scalar*lambda_eff) ;
202 V T_f = (scalar * lambda * (4 * T_1 - T_2) +
203 2 * Dx * phi_d[iPop_opposite]) /
204 (2 * Dx + 3 * scalar * lambda);
205
206 bouzidiTemp[iPop_opposite] = T_f;
207 }
208 }
209 } // for iPop
210
211 applyBouzidiTemp(cell);
212 }
213};
214
215} // namespace olb
216#endif
static V interpolateDensityOnPoint(CELL &cell, Vector< V, 3 > distance) any_platform
void apply(CELL &cell, PARAMETERS &parameters) any_platform
Plain old scalar vector.
constexpr int q() any_platform
Definition functions.h:140
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.
void applyBouzidiTemp(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
Plain wrapper for list of types.
Definition meta.h:276