OpenLB 1.7
Loading...
Searching...
No Matches
advectionDiffusionBoundaries.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2008 Orestis Malaspinas, Andrea Parmigiani
4 * 2022 Nando Suntoyo, Adrian Kummerlaender, Shota Ito
5 * E-mail contact: info@openlb.net
6 * The most recent release of OpenLB can be downloaded at
7 * <http://www.openlb.net/>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23*/
24
25#ifndef ADVECTION_DIFFUSION_BOUNDARIES_H
26#define ADVECTION_DIFFUSION_BOUNDARIES_H
27
30#include "dynamics/dynamics.h"
31
32namespace olb {
33
34//===================================================================================
35//================= AdvectionDiffusionDynamcis on Flat Boundaries =========
36//===================================================================================
37// D2Q5/D3Q7: moment-based BC (see ref. doi:10.1504/PCFD.2016.077296)
38// D2Q9/D3Q19: non-equilibrium bounce back method (see ref. doi:10.1007/978-3-319-44649-3)
39template<typename T, typename DESCRIPTOR, typename DYNAMICS, typename MOMENTA, int direction, int orientation>
40struct AdvectionDiffusionBoundariesDynamics final : public dynamics::CustomCollision<T,DESCRIPTOR,MOMENTA> {
41 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
42
43 using parameters = typename DYNAMICS::parameters;
44
45 template <typename M>
47
48 std::type_index id() override {
50 };
51
53 return block.template getData<OperatorParameters<AdvectionDiffusionBoundariesDynamics>>();
54 }
55
56 template <typename CELL, typename PARAMETERS, typename V=typename CELL::value_t>
57 CellStatistic<V> apply(CELL& cell, PARAMETERS& parameters) any_platform {
58 V dirichletTemperature = MomentaF().computeRho(cell);
59
60 // Placeholder - the index calculation of this section can and should be done at compile time
61 constexpr auto unknownIndices = util::subIndexOutgoing<DESCRIPTOR, direction, orientation>();
62 constexpr auto knownIndices = util::subIndexOutgoingRemaining<DESCRIPTOR, direction, orientation>();
63
64 if constexpr ((DESCRIPTOR::d == 3 && DESCRIPTOR::q == 7)||(DESCRIPTOR::d == 2 && DESCRIPTOR::q == 5)) {
65 static_assert(unknownIndices.size() == 1 && knownIndices.size() == DESCRIPTOR::q - 1,
66 "More than one population missing");
67 V sum = V{0};
68 for (unsigned iPop : knownIndices) {
69 sum += cell[iPop];
70 }
71
72 // on cell there are non-shifted values -> temperature has to be changed
73 V difference = dirichletTemperature - V{1} - sum;
74 cell[unknownIndices[0]] = difference;
75 return typename DYNAMICS::template exchange_momenta<MOMENTA>::CollisionO().apply(cell, parameters);
76 }
77 else {
78 auto u = cell.template getField<descriptors::VELOCITY>();
79 // part for q=19 copied from AdvectionDiffusionEdgesDynamics.collide()
80 // but here just all missing directions, even at border of inlet area
81 // has to be checked!
82 for (unsigned iPop : unknownIndices) {
83 cell[iPop] =
84 equilibrium<DESCRIPTOR>::template firstOrder(iPop, dirichletTemperature, u)
85 - (cell[descriptors::opposite<DESCRIPTOR>(iPop)]
87 descriptors::opposite<DESCRIPTOR>(iPop),
88 dirichletTemperature, u));
89 }
90 return {-1,-1};
91 }
92 };
93
94 T computeEquilibrium(int iPop, T rho, const T u[DESCRIPTOR::d]) const override any_platform {
95 return equilibrium<DESCRIPTOR>::template firstOrder(iPop, rho, u);
96 };
97
98 std::string getName() const override {
99 return "AdvectionDiffusionBoundariesDynamics";
100 };
101
102};
103
104template <typename T, typename DESCRIPTOR, typename DYNAMICS, typename MOMENTA, int...ARGS>
106AdvectionDiffusionBoundariesDynamics< T, DESCRIPTOR, DYNAMICS, MOMENTA, ARGS...>
107>;
108
109//===================================================================================
110//================= AdvectionDiffusionDynamcis On Edges =========
111//===================================================================================
112// non-equilibrium bounce back method (see ref. doi:10.1007/978-3-319-44649-3)
113template<typename T, typename DESCRIPTOR, typename DYNAMICS, typename MOMENTA, int plane, int normal1, int normal2>
114class AdvectionDiffusionEdgesDynamics final : public dynamics::CustomCollision<T,DESCRIPTOR,MOMENTA> {
115public:
116 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
117
118 using parameters = typename DYNAMICS::parameters;
119
120 template <typename M>
122
123 std::type_index id() override {
124 return typeid(AdvectionDiffusionEdgesDynamics);
125 };
126
128 return block.template getData<OperatorParameters<AdvectionDiffusionEdgesDynamics>>();
129 }
130
131 template <typename CELL, typename PARAMETERS, typename V=typename CELL::value_t>
133 V temperature = MomentaF().computeRho(cell);
134 auto u = cell.template getField<descriptors::VELOCITY>();
135 // I need to get Missing information on the corners !!!!
136 constexpr auto unknownIndexes = util::subIndexOutgoing3DonEdges<DESCRIPTOR,plane,normal1,normal2>();
137 // here I know all missing and non missing f_i
138
139 // The collision procedure for D2Q5 and D3Q7 lattice is the same ...
140 // Given the rule f_i_neq = -f_opposite(i)_neq
141 // I have the right number of equations for the number of unknowns using these lattices
142
143 for (unsigned iPop : unknownIndexes) {
144 cell[iPop] = equilibrium<DESCRIPTOR>::template firstOrder(iPop, temperature, u)
145 - ( cell[descriptors::opposite<DESCRIPTOR>(iPop)]
146 - equilibrium<DESCRIPTOR>::template firstOrder(descriptors::opposite<DESCRIPTOR>(iPop),
147 temperature,
148 u));
149 }
150
151 // Once all the f_i are known, I can call the collision for the Regularized Model.
152 return typename DYNAMICS::template exchange_momenta<MOMENTA>::CollisionO().apply(cell, parameters);
153 };
154
155 T computeEquilibrium(int iPop, T rho, const T u[DESCRIPTOR::d]) const override any_platform {
156 return equilibrium<DESCRIPTOR>::template firstOrder(iPop, rho, u);
157 };
158
159 std::string getName() const override {
160 return "AdvectionDiffusionEdgesDynamics";
161 };
162};
163
164template <typename T, typename DESCRIPTOR, typename DYNAMICS, typename MOMENTA, int...ARGS>
166AdvectionDiffusionEdgesDynamics< T, DESCRIPTOR, DYNAMICS, MOMENTA, ARGS...>
167>;
168
169//===================================================================================
170//================= AdvectionDiffusionDynamics on Corners for 2D Boundaries =========
171//===================================================================================
172// non-equilibrium bounce back method (see ref. doi:10.1007/978-3-319-44649-3)
173template<typename T, typename DESCRIPTOR, typename DYNAMICS, typename MOMENTA, int xNormal, int yNormal>
174struct AdvectionDiffusionCornerDynamics2D final : public dynamics::CustomCollision<T,DESCRIPTOR,MOMENTA> {
175 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
176
177 using parameters = typename DYNAMICS::parameters;
178
179 template <typename M>
181
182 std::type_index id() override {
184 };
185
187 return block.template getData<OperatorParameters<AdvectionDiffusionCornerDynamics2D>>();
188 }
189
190 template <typename CELL, typename PARAMETERS, typename V=typename CELL::value_t>
192 V temperature = MomentaF().computeRho(cell);
193 auto u = cell.template getField<descriptors::VELOCITY>();
194 // I need to get Missing information on the corners !!!!
195 constexpr auto unknownIndexes = util::subIndexOutgoing2DonCorners<DESCRIPTOR,xNormal,yNormal>();
196 // here I know all missing and non missing f_i
197
198 // The collision procedure for D2Q5 and D3Q7 lattice is the same ...
199 // Given the rule f_i_neq = -f_opposite(i)_neq
200 // I have the right number of equations for the number of unknowns using these lattices
201
202 for (unsigned iPop : unknownIndexes) {
203 cell[iPop] = equilibrium<DESCRIPTOR>::template firstOrder(iPop, temperature, u)
204 - ( cell[descriptors::opposite<DESCRIPTOR>(iPop)]
205 - equilibrium<DESCRIPTOR>::template firstOrder(descriptors::opposite<DESCRIPTOR>(iPop),
206 temperature,
207 u));
208 }
209
210 // Once all the f_i are known, I can call the collision for the Regularized Model.
211 return typename DYNAMICS::CollisionO().apply(cell, parameters);
212 };
213
214 T computeEquilibrium(int iPop, T rho, const T u[DESCRIPTOR::d]) const override any_platform {
215 return equilibrium<DESCRIPTOR>::template firstOrder(iPop, rho, u);
216 };
217
218 std::string getName() const override {
219 return "AdvectionDiffusionCornerDynamics2D";
220 };
221
222};
223
224template<typename T, typename DESCRIPTOR, typename DYNAMICS, typename MOMENTA, int... NORMAL>
226 AdvectionDiffusionCornerDynamics2D<T, DESCRIPTOR, DYNAMICS, MOMENTA, NORMAL... >
227>;
228
229//===================================================================================
230//================= AdvectionDiffusionDynamics on Corners for 3D Boundaries =========
231//===================================================================================
232// non-equilibrium bounce back method (see ref. doi:10.1007/978-3-319-44649-3)
233template<typename T, typename DESCRIPTOR, typename DYNAMICS, typename MOMENTA, int xNormal, int yNormal, int zNormal>
234struct AdvectionDiffusionCornerDynamics3D final : public dynamics::CustomCollision<T,DESCRIPTOR,MOMENTA> {
235 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
236
237 using parameters = typename DYNAMICS::parameters;
238
239 template <typename M>
241
242 std::type_index id() override {
244 };
245
247 return block.template getData<OperatorParameters<AdvectionDiffusionCornerDynamics3D>>();
248 }
249
250 template <typename CELL, typename PARAMETERS, typename V=typename CELL::value_t>
252 V temperature = MomentaF().computeRho(cell);
253 auto u = cell.template getField<descriptors::VELOCITY>();
254 // I need to get Missing information on the corners !!!!
255 constexpr auto unknownIndexes = util::subIndexOutgoing3DonCorners<DESCRIPTOR,xNormal,yNormal,zNormal>();
256 // here I know all missing and non missing f_i
257
258 // The collision procedure for D2Q5 and D3Q7 lattice is the same ...
259 // Given the rule f_i_neq = -f_opposite(i)_neq
260 // I have the right number of equations for the number of unknowns using these lattices
261
262 for (unsigned iPop : unknownIndexes) {
263 cell[iPop] = equilibrium<DESCRIPTOR>::template firstOrder(iPop, temperature, u)
264 - ( cell[descriptors::opposite<DESCRIPTOR>(iPop)]
265 - equilibrium<DESCRIPTOR>::template firstOrder(descriptors::opposite<DESCRIPTOR>(iPop),
266 temperature,
267 u));
268 }
269
270 // Once all the f_i are known, I can call the collision for the Regularized Model.
271 return typename DYNAMICS::template exchange_momenta<MOMENTA>::CollisionO().apply(cell, parameters);
272 };
273
274 T computeEquilibrium(int iPop, T rho, const T u[DESCRIPTOR::d]) const override any_platform {
275 return equilibrium<DESCRIPTOR>::template firstOrder(iPop, rho, u);
276 };
277
278 std::string getName() const override {
279 return "AdvectionDiffusionCornerDynamics3D";
280 };
281
282};
283
284template<typename T, typename DESCRIPTOR, typename DYNAMICS, typename MOMENTA, int... NORMAL>
286 AdvectionDiffusionCornerDynamics3D<T, DESCRIPTOR, DYNAMICS, MOMENTA, NORMAL... >
287>;
288
289
290} // namespace olb
291
292#endif
A collection of dynamics classes (e.g.
T computeEquilibrium(int iPop, T rho, const T u[DESCRIPTOR::d]) const override any_platform
Return iPop equilibrium for given first and second momenta.
std::string getName() const override
Return human-readable name.
typename MOMENTA::template type< DESCRIPTOR > MomentaF
AbstractParameters< T, DESCRIPTOR > & getParameters(BlockLattice< T, DESCRIPTOR > &block) override
Parameters access for legacy post processors.
std::type_index id() override
Expose unique type-identifier for RTTI.
CellStatistic< V > apply(CELL &cell, PARAMETERS &parameters) any_platform
Platform-abstracted block lattice for external access and inter-block interaction.
Descriptor for all types of 2D and 3D lattices.
Top level namespace for all of OpenLB.
#define any_platform
Define preprocessor macros for device-side functions, constant storage.
Definition platform.h:78
Dynamic access interface for FIELD-valued parameters.
std::string getName() const override
Return human-readable name.
CellStatistic< V > apply(CELL &cell, PARAMETERS &parameters) any_platform
std::type_index id() override
Expose unique type-identifier for RTTI.
AbstractParameters< T, DESCRIPTOR > & getParameters(BlockLattice< T, DESCRIPTOR > &block) override
Parameters access for legacy post processors.
typename MOMENTA::template type< DESCRIPTOR > MomentaF
T computeEquilibrium(int iPop, T rho, const T u[DESCRIPTOR::d]) const override any_platform
Return iPop equilibrium for given first and second momenta.
typename MOMENTA::template type< DESCRIPTOR > MomentaF
CellStatistic< V > apply(CELL &cell, PARAMETERS &parameters) any_platform
AbstractParameters< T, DESCRIPTOR > & getParameters(BlockLattice< T, DESCRIPTOR > &block) override
Parameters access for legacy post processors.
T computeEquilibrium(int iPop, T rho, const T u[DESCRIPTOR::d]) const override any_platform
Return iPop equilibrium for given first and second momenta.
std::type_index id() override
Expose unique type-identifier for RTTI.
std::string getName() const override
Return human-readable name.
std::string getName() const override
Return human-readable name.
CellStatistic< V > apply(CELL &cell, PARAMETERS &parameters) any_platform
AbstractParameters< T, DESCRIPTOR > & getParameters(BlockLattice< T, DESCRIPTOR > &block) override
Parameters access for legacy post processors.
typename MOMENTA::template type< DESCRIPTOR > MomentaF
std::type_index id() override
Expose unique type-identifier for RTTI.
T computeEquilibrium(int iPop, T rho, const T u[DESCRIPTOR::d]) const override any_platform
Return iPop equilibrium for given first and second momenta.
Return value of any collision.
Definition interface.h:43
Set PARAMETER of DYNAMICS from CELL (for CustomCollision-based DYNAMICS)
Definition interface.h:361