OpenLB 1.7
Loading...
Searching...
No Matches
interface.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2006 Jonas Latt, 2021 Julius Jessberger, Adrian Kummerlaender
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
35#ifndef DYNAMICS_MOMENTA_INTERFACE_H
36#define DYNAMICS_MOMENTA_INTERFACE_H
37
38#include <type_traits>
39#include <functional>
40
41#include "elements.h"
42
43namespace olb {
44
45namespace momenta {
46
48
51template <typename BASE, typename DENSITY, typename MOMENTUM>
53 template <typename CELL, typename RHO, typename U>
54 void operator()(CELL& cell, RHO& rho, U& u) const any_platform
55 {
56 DENSITY().template compute<BASE>(cell, rho);
57 MOMENTUM().template computeU<BASE>(cell, u);
58 };
59};
60
61template <typename BASE>
63 template <typename CELL, typename RHO, typename U, typename DESCRIPTOR=typename CELL::descriptor_t>
64 void operator()(CELL& cell, RHO& rho, U& u) const any_platform
65 {
66 lbm<DESCRIPTOR>::computeRhoU(cell, rho, u);
67 };
68};
69
70template <
71 typename DENSITY,
72 typename MOMENTUM,
73 typename STRESS,
74 typename DefinitionRule
75>
76struct Tuple;
77
79
88template <
89 typename DESCRIPTOR,
90 typename DENSITY,
91 typename MOMENTUM,
92 typename STRESS,
93 typename DefinitionRule
94>
96 using descriptor = DESCRIPTOR;
98 using density = DENSITY;
99 using momentum = MOMENTUM;
100 using stress = STRESS;
101 using definition = DefinitionRule;
102
104
105 template <typename CELL, typename V=typename CELL::value_t>
106 V computeRho(CELL& cell) const any_platform
107 {
108 V rho{};
109 DENSITY().template compute<type>(cell, rho);
110 return rho;
111 }
112
113 template <typename CELL, typename U>
114 void computeU(CELL& cell, U& u) const any_platform
115 {
116 MOMENTUM().template computeU<type>(cell, u);
117 }
118
119 template <typename CELL, typename J>
120 void computeJ(CELL& cell, J& j) const any_platform
121 {
122 MOMENTUM().template compute<type>(cell, j);
123 }
124
125 // TODO: Drop the rho and u args here, this is just another opportunity for
126 // injecting false values. Replaces calls with computeAllMomenta
127 template <typename CELL, typename RHO, typename U, typename PI>
128 void computeStress(CELL& cell,
129 const RHO& rho, const U& u, PI& pi) const any_platform
130 {
131 STRESS().template compute<type>(cell, rho, u, pi);
132 }
133
134 //computeStress without rho and u args
135 template <typename CELL, typename PI, typename V=typename CELL::value_t>
136 void computeStress(CELL& cell, PI& pi) const any_platform
137 {
138 V rho, u[DESCRIPTOR::d];
139 computeRhoU(cell, rho, u);
140 STRESS().template compute<type>(cell, rho, u, pi);
141 }
142
143 template <typename CELL, typename RHO, typename J>
144 void computeRhoJ(CELL& cell, RHO& rho, J& j) const any_platform
145 {
146 DENSITY().template compute<type>(cell, rho);
147 MOMENTUM().template compute<type>(cell, j);
148 }
149
150 template <typename CELL, typename RHO, typename U>
151 void computeRhoU(CELL& cell, RHO& rho, U& u) const any_platform
152 {
154 }
155
156 template <typename CELL, typename RHO, typename U, typename PI>
157 void computeAllMomenta(CELL& cell, RHO& rho, U& u, PI& pi) const any_platform
158 {
159 computeRhoU(cell, rho, u);
160 STRESS().template compute<type>(cell, rho, u, pi);
161 }
162
163 template <typename CELL, typename PINEQNORMSQR, typename V=typename CELL::value_t>
164 void computePiNeqNormSqr(CELL& cell, PINEQNORMSQR& piNeqNormSqr) const any_platform
165 {
166 V rho, u[DESCRIPTOR::d], pi[util::TensorVal<DESCRIPTOR>::n] { };
167 computeRhoU(cell, rho, u);
168 STRESS().template compute<type>(cell, rho, u, pi);
169 piNeqNormSqr = pi[0]*pi[0] + 2.*pi[1]*pi[1] + pi[2]*pi[2];
170 if constexpr (util::TensorVal<DESCRIPTOR>::n == 6) {
171 piNeqNormSqr += pi[2]*pi[2] + pi[3]*pi[3] + 2.*pi[4]*pi[4] +pi[5]*pi[5];
172 }
173 }
174
175 template <typename CELL, typename RHO>
176 void defineRho(CELL& cell, const RHO& rho) any_platform
177 {
178 DENSITY().template define<type>(cell, rho);
179
180 RHO rhoShift = rho;
181 inverseShiftRho(cell, rhoShift);
182 DefinitionRule().template defineRho<type>(cell, rho);
183 }
184
185 template <typename CELL, typename U>
186 void defineU(CELL& cell, const U& u) any_platform
187 {
188 MOMENTUM().template define<type>(cell, u);
189
190 using U_ARITH = std::remove_const_t<std::remove_pointer_t<std::remove_extent_t<U>>>;
191 U_ARITH uShift[DESCRIPTOR::d];
192 util::copyN(uShift, u, DESCRIPTOR::d);
193 inverseShiftU(cell, uShift);
194 DefinitionRule().template defineU<type>(cell, u);
195 }
196
197 template <typename CELL, typename RHO, typename U>
198 void defineRhoU(CELL& cell, const RHO& rho, const U& u) any_platform
199 {
200 DENSITY().template define<type>(cell, rho);
201 MOMENTUM().template define<type>(cell, u);
202
203 RHO rhoShift = rho;
204 using U_ARITH = std::remove_const_t<std::remove_pointer_t<std::remove_extent_t<U>>>;
205 U_ARITH uShift[DESCRIPTOR::d];
206 util::copyN(uShift, u, DESCRIPTOR::d);
207 inverseShiftRhoU(cell, rhoShift, uShift);
208 DefinitionRule().template defineRhoU<type>(cell, rhoShift, uShift);
209 }
210
211 template <typename CELL, typename RHO, typename U, typename PI>
212 void defineAllMomenta(CELL& cell, const RHO& rho, const U& u, const PI& pi) any_platform
213 {
214 DENSITY().template define<type>(cell, rho);
215 MOMENTUM().template define<type>(cell, u);
216
217 RHO rhoShift = rho;
218 using U_ARITH = std::remove_const_t<std::remove_pointer_t<std::remove_extent_t<U>>>;
219 U_ARITH uShift[DESCRIPTOR::d];
220 util::copyN(uShift, u, DESCRIPTOR::d);
221 inverseShiftRhoU(cell, rhoShift, uShift);
222 DefinitionRule().template defineAllMomenta<type>(cell, rhoShift, uShift, pi);
223 }
224
225 template <typename CELL>
226 void initialize(CELL& cell)
227 {
228 DENSITY().template initialize<type>(cell);
229 MOMENTUM().template initialize<type>(cell);
230 }
231
232 template <typename CELL, typename RHO>
233 void inverseShiftRho(CELL& cell, RHO& rho) any_platform
234 {
235 DENSITY().template inverseShift<type>(cell, rho);
236 }
237
238 template <typename CELL, typename U>
239 void inverseShiftU(CELL& cell, U& u) any_platform
240 {
241 MOMENTUM().template inverseShift<type>(cell, u);
242 }
243
244 template <typename CELL, typename RHO, typename U>
245 void inverseShiftRhoU(CELL& cell, RHO& rho, U& u) any_platform
246 {
247 inverseShiftRho(cell, rho);
248 inverseShiftU(cell, u);
249 }
250
251 std::string getName() const
252 {
253 return "Momenta<"
254 + density().getName() + ","
255 + momentum().getName() + ","
256 + stress().getName() + ","
257 + definition().getName() +
258 ">";
259 }
260};
261
262template <
263 typename DENSITY,
264 typename MOMENTUM,
265 typename STRESS,
266 typename DefinitionRule
267>
268struct Tuple {
269 using density = DENSITY;
270 using momentum = MOMENTUM;
271 using stress = STRESS;
272 using definition = DefinitionRule;
273
274 template <typename DESCRIPTOR>
276};
277
278template <typename MOMENTA>
279struct Forced {
280 template <typename DESCRIPTOR>
282 DESCRIPTOR,
283 typename MOMENTA::template type<DESCRIPTOR>::density,
285 typename MOMENTA::template type<DESCRIPTOR>::stress,
286 typename MOMENTA::template type<DESCRIPTOR>::definition
287 >;
288};
289
290template <typename MOMENTA>
292 template <typename DESCRIPTOR>
294 DESCRIPTOR,
295 typename MOMENTA::template type<DESCRIPTOR>::density,
297 typename MOMENTA::template type<DESCRIPTOR>::stress,
298 typename MOMENTA::template type<DESCRIPTOR>::definition
299 >;
300};
301
302template <typename MOMENTA>
313
314template <typename MOMENTA>
315using Identity = MOMENTA;
316
317template <typename MOMENTA>
319 template <typename DESCRIPTOR>
321 DESCRIPTOR,
322 typename MOMENTA::template type<DESCRIPTOR>::density,
325 typename MOMENTA::template type<DESCRIPTOR>::definition
326 >;
327};
328
329template <typename MOMENTA>
330struct Porous {
331 template <typename DESCRIPTOR>
333 DESCRIPTOR,
334 typename MOMENTA::template type<DESCRIPTOR>::density,
336 typename MOMENTA::template type<DESCRIPTOR>::stress,
337 typename MOMENTA::template type<DESCRIPTOR>::definition
338 >;
339};
340
341template <typename MOMENTA>
343 template <typename DESCRIPTOR>
345 DESCRIPTOR,
346 typename MOMENTA::template type<DESCRIPTOR>::density,
348 typename MOMENTA::template type<DESCRIPTOR>::stress,
349 typename MOMENTA::template type<DESCRIPTOR>::definition
350 >;
351};
352
353} // namespace momenta
354
355} // namespace olb
356
357#endif
Implementation of computation and definition of the moments density, velocity, stress.
MOMENTA Identity
Definition interface.h:315
void copyN(T c[], const T a[], const unsigned dim) any_platform
Top level namespace for all of OpenLB.
#define any_platform
Define preprocessor macros for device-side functions, constant storage.
Definition platform.h:78
static void computeRhoU(CELL &cell, RHO &rho, U &u) any_platform
Computation of hydrodynamic variables.
Definition lbm.h:219
Standard computation for density in the bulk as zeroth moment of the population.
Definition elements.h:132
Standard computation for momentum in the bulk as first moment of the population.
Definition elements.h:378
void operator()(CELL &cell, RHO &rho, U &u) const any_platform
Definition interface.h:64
Partially-specializable rho and u computation.
Definition interface.h:52
void operator()(CELL &cell, RHO &rho, U &u) const any_platform
Definition interface.h:54
Tuple of momenta components forming a moment system.
Definition interface.h:95
void defineAllMomenta(CELL &cell, const RHO &rho, const U &u, const PI &pi) any_platform
Definition interface.h:212
void defineRhoU(CELL &cell, const RHO &rho, const U &u) any_platform
Definition interface.h:198
void initialize(CELL &cell)
Definition interface.h:226
std::string getName() const
Definition interface.h:251
void computeRhoU(CELL &cell, RHO &rho, U &u) const any_platform
Definition interface.h:151
void computeRhoJ(CELL &cell, RHO &rho, J &j) const any_platform
Definition interface.h:144
void inverseShiftU(CELL &cell, U &u) any_platform
Definition interface.h:239
void computeStress(CELL &cell, PI &pi) const any_platform
Definition interface.h:136
void computeJ(CELL &cell, J &j) const any_platform
Definition interface.h:120
void defineU(CELL &cell, const U &u) any_platform
Definition interface.h:186
void computeU(CELL &cell, U &u) const any_platform
Definition interface.h:114
V computeRho(CELL &cell) const any_platform
Definition interface.h:106
void computeStress(CELL &cell, const RHO &rho, const U &u, PI &pi) const any_platform
Definition interface.h:128
void inverseShiftRhoU(CELL &cell, RHO &rho, U &u) any_platform
Definition interface.h:245
void computePiNeqNormSqr(CELL &cell, PINEQNORMSQR &piNeqNormSqr) const any_platform
Definition interface.h:164
void computeAllMomenta(CELL &cell, RHO &rho, U &u, PI &pi) const any_platform
Definition interface.h:157
void inverseShiftRho(CELL &cell, RHO &rho) any_platform
Definition interface.h:233
DefinitionRule definition
Definition interface.h:101
void defineRho(CELL &cell, const RHO &rho) any_platform
Definition interface.h:176
DefinitionRule definition
Definition interface.h:272
Compute number of elements of a symmetric d-dimensional tensor.
Definition util.h:210