OpenLB 1.8.1
Loading...
Searching...
No Matches
wrapper.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2024 Adrian Kummerlaender, Shota Ito
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 CSE_WRAPPER_H
25#define CSE_WRAPPER_H
26
27#include "dynamics/interface.h"
28
29namespace olb {
30
31namespace dynamics {
32
35
37
40template <typename DYNAMICS>
41struct CSE : public not_cse_optimized_tag {
42 template <concepts::Cell CELL, concepts::Parameters PARAMETERS, concepts::BaseType V=typename CELL::value_t>
43 CellStatistic<V> collide(CELL& cell, PARAMETERS& parameters) any_platform {
44 return DYNAMICS().collide(cell, parameters);
45 };
46};
47
49template <typename DYNAMICS>
50using is_cse_optimized = std::integral_constant<
51 bool,
52 !std::is_base_of_v<not_cse_optimized_tag, CSE<DYNAMICS>>
53>;
54
56template <typename DYNAMICS>
57constexpr static bool is_cse_optimized_v = is_cse_optimized<DYNAMICS>::value;
58
59}
60
62template <concepts::IntrospectableDynamics DYNAMICS>
63class CSE : public Dynamics<typename DYNAMICS::value_t,
64 typename DYNAMICS::descriptor_t> {
65private:
66 using T = typename DYNAMICS::value_t;
67 using DESCRIPTOR = typename DYNAMICS::descriptor_t;
68
69public:
70 using value_t = typename DYNAMICS::value_t;
71 using descriptor_t = typename DYNAMICS::descriptor_t;
72
73 using MomentaF = typename DYNAMICS::MomentaF;
74 using EquilibriumF = typename DYNAMICS::EquilibriumF;
75
76 using parameters = typename DYNAMICS::parameters;
77
78 template <typename NEW_T>
80
81 template <typename NEW_MOMENTA>
83
84 constexpr static bool is_vectorizable = dynamics::is_vectorizable_v<DYNAMICS>;
85 constexpr static bool is_optimized = dynamics::is_cse_optimized_v<DYNAMICS>;
86
87 std::type_index id() override {
88 return typeid(CSE);
89 }
90
91 std::string getName() const override {
92 return "dynamics::cse<" + DYNAMICS().getName() + ">";
93 };
94
95 template <concepts::Cell CELL, concepts::Parameters PARAMETERS, concepts::BaseType V=typename CELL::value_t>
98 };
99
101 template <typename FIELD>
102 constexpr bool hasParameter() const {
103 return DYNAMICS().template hasParameter<FIELD>();
104 };
105
108 return DYNAMICS().getParameters(block);
109 }
110
111 void initialize(Cell<T,DESCRIPTOR>& cell) override {
112 DYNAMICS().initialize(cell);
113 };
114 void computeEquilibrium(ConstCell<T,DESCRIPTOR>& cell, T rho, const T u[DESCRIPTOR::d], T fEq[DESCRIPTOR::q]) const override {
115 DYNAMICS().computeEquilibrium(cell, rho, u, fEq);
116 };
117 T computeRho(ConstCell<T,DESCRIPTOR>& cell) const override {
118 return DYNAMICS().computeRho(cell);
119 };
120 void computeU(ConstCell<T,DESCRIPTOR>& cell, T u[DESCRIPTOR::d]) const override {
121 DYNAMICS().computeU(cell, u);
122 };
123 void computeJ(ConstCell<T,DESCRIPTOR>& cell, T j[DESCRIPTOR::d]) const override {
124 DYNAMICS().computeJ(cell, j);
125 };
127 T rho, const T u[DESCRIPTOR::d], T pi[util::TensorVal<DESCRIPTOR >::n]) const override {
128 DYNAMICS().computeStress(cell, rho, u, pi);
129 };
130 void computeRhoU(ConstCell<T,DESCRIPTOR>& cell, T& rho, T u[DESCRIPTOR::d]) const override {
131 DYNAMICS().computeRhoU(cell, rho, u);
132 };
134 T& rho, T u[DESCRIPTOR::d], T pi[util::TensorVal<DESCRIPTOR >::n]) const override {
135 DYNAMICS().computeAllMomenta(cell, rho, u, pi);
136 };
137 void defineRho(Cell<T,DESCRIPTOR>& cell, T rho) override {
138 DYNAMICS().defineRho(cell, rho);
139 };
140 void defineU(Cell<T,DESCRIPTOR>& cell, const T u[DESCRIPTOR::d]) override {
141 DYNAMICS().defineU(cell, u);
142 };
143 void defineRhoU(Cell<T,DESCRIPTOR>& cell, T rho, const T u[DESCRIPTOR::d]) override {
144 DYNAMICS().defineRhoU(cell, rho, u);
145 };
147 T rho, const T u[DESCRIPTOR::d], const T pi[util::TensorVal<DESCRIPTOR >::n]) override {
148 DYNAMICS().defineAllMomenta(cell, rho, u, pi);
149 };
150 void inverseShiftRhoU(ConstCell<T,DESCRIPTOR>& cell, T& rho, T u[DESCRIPTOR::d]) const override {
151 DYNAMICS().inverseShiftRhoU(cell, rho, u);
152 }
153};
154
155
156namespace operators {
157
160
162
165template <typename OPERATOR, typename DESCRIPTOR>
166struct CSE_O : public not_cse_optimized_tag { };
167
168template <typename OPERATOR, typename DESCRIPTOR>
169requires (OPERATOR::scope == OperatorScope::PerCell)
171 template <concepts::Cell CELL>
172 void apply(CELL& cell) any_platform {
173 OPERATOR().apply(cell);
174 };
175};
176
177template <typename OPERATOR, typename DESCRIPTOR>
178requires (OPERATOR::scope == OperatorScope::PerCellWithParameters)
179struct CSE_O<OPERATOR,DESCRIPTOR> : public not_cse_optimized_tag {
180 template <concepts::Cell CELL, concepts::Parameters PARAMETERS>
181 void apply(CELL& cell, PARAMETERS& parameters) any_platform {
182 OPERATOR().apply(cell, parameters);
183 };
184};
185
187template <typename OPERATOR, typename DESCRIPTOR>
188using is_cse_optimized = std::integral_constant<
189 bool,
190 (!std::is_base_of_v<not_cse_optimized_tag, CSE_O<OPERATOR,DESCRIPTOR>> &&
192>;
193
195template <typename OPERATOR, typename DESCRIPTOR>
196constexpr static bool is_cse_optimized_v = is_cse_optimized<OPERATOR,DESCRIPTOR>::value;
197
198}
199
201template <typename OPERATOR, typename DESCRIPTOR>
202struct CSE_O { };
203
204template <typename OPERATOR, typename DESCRIPTOR>
205requires (OPERATOR::scope == OperatorScope::PerCell)
207 static constexpr OperatorScope scope = OperatorScope::PerCell;
208
209 int getPriority() const {
210 return OPERATOR().getPriority();
211 }
212
213 template <concepts::Cell CELL>
214 void apply(CELL& cell) any_platform {
216 };
217};
218
219template <typename OPERATOR, typename DESCRIPTOR>
220requires (OPERATOR::scope == OperatorScope::PerCellWithParameters)
222 static constexpr OperatorScope scope = OperatorScope::PerCellWithParameters;
223
224 int getPriority() const {
225 return OPERATOR().getPriority();
226 }
227
228 template <concepts::Cell CELL, concepts::Parameters PARAMETERS>
229 void apply(CELL& cell, PARAMETERS& parameters) any_platform {
230 operators::CSE_O<OPERATOR,DESCRIPTOR>().apply(cell, parameters);
231 };
232};
233
234}
235
236#endif
#define OPERATOR(OP, rhs)
Definition aDiffTape.h:64
Wrapper for auto-generated CSE-optimized DYNAMICS.
Definition wrapper.h:64
typename DYNAMICS::EquilibriumF EquilibriumF
Definition wrapper.h:74
CellStatistic< V > collide(CELL &cell, PARAMETERS &parameters) any_platform
Definition wrapper.h:96
std::type_index id() override
Expose unique type-identifier for RTTI.
Definition wrapper.h:87
typename DYNAMICS::parameters parameters
Definition wrapper.h:76
typename DYNAMICS::value_t value_t
Definition wrapper.h:70
void defineRho(Cell< T, DESCRIPTOR > &cell, T rho) override
Set particle density.
Definition wrapper.h:137
T computeRho(ConstCell< T, DESCRIPTOR > &cell) const override
Compute particle density.
Definition wrapper.h:117
void inverseShiftRhoU(ConstCell< T, DESCRIPTOR > &cell, T &rho, T u[DESCRIPTOR::d]) const override
Calculate population momenta s.t. the physical momenta are reproduced by the computeRhoU.
Definition wrapper.h:150
static constexpr bool is_vectorizable
Definition wrapper.h:84
constexpr bool hasParameter() const
Return true iff FIELD is a parameter.
Definition wrapper.h:102
void computeU(ConstCell< T, DESCRIPTOR > &cell, T u[DESCRIPTOR::d]) const override
Compute fluid velocity.
Definition wrapper.h:120
AbstractParameters< T, DESCRIPTOR > & getParameters(BlockLattice< T, DESCRIPTOR > &block) override
Interim workaround for accessing dynamics parameters in legacy post processors.
Definition wrapper.h:107
void defineU(Cell< T, DESCRIPTOR > &cell, const T u[DESCRIPTOR::d]) override
Set fluid velocity.
Definition wrapper.h:140
typename DYNAMICS::MomentaF MomentaF
Definition wrapper.h:73
void computeJ(ConstCell< T, DESCRIPTOR > &cell, T j[DESCRIPTOR::d]) const override
Compute fluid momentum.
Definition wrapper.h:123
void computeStress(ConstCell< T, DESCRIPTOR > &cell, T rho, const T u[DESCRIPTOR::d], T pi[util::TensorVal< DESCRIPTOR >::n]) const override
Definition wrapper.h:126
typename DYNAMICS::descriptor_t descriptor_t
Definition wrapper.h:71
void computeAllMomenta(ConstCell< T, DESCRIPTOR > &cell, T &rho, T u[DESCRIPTOR::d], T pi[util::TensorVal< DESCRIPTOR >::n]) const override
Definition wrapper.h:133
void initialize(Cell< T, DESCRIPTOR > &cell) override
Initialize dynamics-specific data for cell.
Definition wrapper.h:111
void computeRhoU(ConstCell< T, DESCRIPTOR > &cell, T &rho, T u[DESCRIPTOR::d]) const override
Compute fluid velocity and particle density.
Definition wrapper.h:130
void defineRhoU(Cell< T, DESCRIPTOR > &cell, T rho, const T u[DESCRIPTOR::d]) override
Define fluid velocity and particle density.
Definition wrapper.h:143
static constexpr bool is_optimized
Definition wrapper.h:85
void computeEquilibrium(ConstCell< T, DESCRIPTOR > &cell, T rho, const T u[DESCRIPTOR::d], T fEq[DESCRIPTOR::q]) const override
Return iPop equilibrium for given first and second momenta.
Definition wrapper.h:114
std::string getName() const override
Return human-readable name.
Definition wrapper.h:91
void defineAllMomenta(Cell< T, DESCRIPTOR > &cell, T rho, const T u[DESCRIPTOR::d], const T pi[util::TensorVal< DESCRIPTOR >::n]) override
Definition wrapper.h:146
Highest-level interface to read-only Cell data.
Definition interface.h:36
Cell-wise operator with scope, priority and apply template.
Definition concepts.h:275
std::integral_constant< bool, !std::is_base_of_v< not_cse_optimized_tag, CSE< DYNAMICS > > > is_cse_optimized
Exposes whether a auto-generated CSE specialization is available.
Definition wrapper.h:50
std::integral_constant< bool,(!std::is_base_of_v< not_cse_optimized_tag, CSE_O< OPERATOR, DESCRIPTOR > > && concepts::CellOperator< OPERATOR >) > is_cse_optimized
Exposes whether a auto-generated CSE specialization is available.
Definition wrapper.h:188
Top level namespace for all of OpenLB.
OperatorScope
Block-wide operator application scopes.
@ PerCell
Per-cell application, i.e. OPERATOR::apply is passed a CELL concept implementation.
#define any_platform
Define preprocessor macros for device-side functions, constant storage.
Definition platform.h:77
Dynamic access interface for FIELD-valued parameters.
void apply(CELL &cell, PARAMETERS &parameters) any_platform
Definition wrapper.h:229
void apply(CELL &cell) any_platform
Definition wrapper.h:214
Wrapper for auto-generated CSE-optimized OPERATOR.
Definition wrapper.h:202
Return value of any collision.
Definition interface.h:45
Interface for per-cell dynamics.
Definition interface.h:56
To be specialized for automatically generated CSE-optimized DYNAMICS::collide.
Definition wrapper.h:41
CellStatistic< V > collide(CELL &cell, PARAMETERS &parameters) any_platform
Definition wrapper.h:43
Marker for the default non-optimized specialization of olb::CSE<>
Definition wrapper.h:34
void apply(CELL &cell, PARAMETERS &parameters) any_platform
Definition wrapper.h:181
To be specialized for automatically generated CSE-optimized OPERATOR::apply.
Definition wrapper.h:166
Marker for the default non-optimized specialization of olb::CSE<>
Definition wrapper.h:159
Compute number of elements of a symmetric d-dimensional tensor.
Definition util.h:216