OpenLB 1.7
Loading...
Searching...
No Matches
descriptorField.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2019 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
24#ifndef DESCRIPTOR_FIELD_H
25#define DESCRIPTOR_FIELD_H
26
27#include <type_traits>
28#include <stdexcept>
29
30#include "core/meta.h"
31#include "core/vector.h"
32
34
35namespace olb {
36
38struct Expr;
39
40namespace descriptors {
41
42// *INDENT-OFF*
43
45
46
48template <unsigned C, unsigned... U>
49struct FIELD_BASE {
50 FIELD_BASE() = default;
51
53
59 template <typename T>
60 using value_type = T;
61
62 template <typename T>
64
66 template <std::size_t... V>
67 static constexpr std::size_t size(std::index_sequence<V...>)
68 {
69 static_assert(sizeof...(U) == sizeof...(V), "V size fits U params");
70 return ((U*V) + ... + C);
71 }
72
74 template <std::size_t... V>
75 static constexpr std::size_t size()
76 {
77 if constexpr (sizeof...(U) < sizeof...(V)) {
78 return size(meta::take_n_sequence<sizeof...(U)>(std::index_sequence<V...>()));
79 } else if constexpr (sizeof...(U) > sizeof...(V)) {
80 using namespace meta;
81 static_assert(is_zero_sequence(drop_n_sequence<sizeof...(V)>(std::index_sequence<U...>())),
82 "Dropped U entries are zero");
83 return size(std::index_sequence<V...>() + zero_sequence<sizeof...(U) - sizeof...(V)>());
84 } else {
85 return size(std::index_sequence<V...>());
86 }
87 __builtin_unreachable();
88 }
89
90 // Initial value used for allocation of field data in FieldArrayD (optional)
94 template <typename T, typename DESCRIPTOR>
95 static constexpr auto getInitialValue() {
96 return Vector<value_type<T>, DESCRIPTOR::template size<FIELD_BASE<C,U...>>()>{};
97 }
98
99 static constexpr bool isSerializable() {
100 return true;
101 }
102};
103
105template <typename TYPE, unsigned C, unsigned... U>
106struct TYPED_FIELD_BASE : public FIELD_BASE<C,U...> {
107 template <typename T>
108 using value_type = std::conditional_t<std::is_same_v<T,Expr>,Expr,TYPE>;
109
110 template <typename T>
112
113 template <typename T, typename DESCRIPTOR>
114 static constexpr auto getInitialValue() {
115 return Vector<value_type<T>, DESCRIPTOR::template size<FIELD_BASE<C,U...>>()>{};
116 }
117
118 static constexpr bool isSerializable() {
119 return !std::is_pointer_v<TYPE>;
120 }
121};
122
123template <template<typename> typename TYPE, unsigned C, unsigned... U>
124struct TEMPLATE_FIELD_BASE : public FIELD_BASE<C,U...> {
125 template <typename T>
126 using value_type = TYPE<T>;
127
128 template <typename T>
130
131 template <typename T, typename DESCRIPTOR>
132 static constexpr auto getInitialValue() {
133 return Vector<value_type<T>, DESCRIPTOR::template size<FIELD_BASE<C,U...>>()>{};
134 }
135
136 static constexpr bool isSerializable() {
137 return false;
138 }
139};
140
142struct PROPAGATABLE_FIELD_BASE : public FIELD_BASE<0,0,1> {
143 template <typename T>
144 using value_type = T;
145
146 template <typename T>
148};
149
151template <typename FIELD>
152using is_propagatable_field = typename std::is_base_of<PROPAGATABLE_FIELD_BASE, FIELD>::type;
153
155struct TENSOR {
156 TENSOR() = delete;
157
158 template <unsigned D, unsigned Q>
159 static constexpr unsigned size()
160 {
161 return (D * (D+1)) / 2; // see `TensorVal` in `core/util.h`
162 }
163};
164
166template <typename TYPE>
167struct OBJECT_POINTER_FIELD_BASE : public TYPED_FIELD_BASE<std::add_pointer_t<TYPE>,1> {
168 static_assert(std::is_object_v<TYPE>, "TYPE must be object");
169};
170
173
174
175struct CELL_ID : public TYPED_FIELD_BASE<std::size_t,1> { };
176struct MATERIAL : public TYPED_FIELD_BASE<int, 1> { };
177struct LATTICE_TIME : public TYPED_FIELD_BASE<std::size_t,1> { };
178
180
181struct STATISTIC_GENERATED : public TYPED_FIELD_BASE<int,1> { };
182struct STATISTIC : public FIELD_BASE<2> { };
183
184// Field types need to be distinct (i.e. not aliases)
185// (Field size parametrized: Cs + Ds*D + Qs*Q) Cs Ds Qs
186struct VELOCITY : public FIELD_BASE<0, 1, 0> { };
187struct VELOCITY2 : public FIELD_BASE<0, 1, 0> { };
188struct AVERAGE_VELOCITY : public FIELD_BASE<0, 1, 0> { };
189struct SOURCE : public FIELD_BASE<1, 0, 0> { };
190struct PRESSCORR : public FIELD_BASE<1, 0, 0> { };
191struct FORCE : public FIELD_BASE<0, 1, 0> { };
192struct EXTERNAL_FORCE : public FIELD_BASE<0, 1, 0> { };
193struct TAU_EFF : public FIELD_BASE<1, 0, 0> { };
194struct GAMMA : public FIELD_BASE<1, 0, 0> { };
195struct CUTOFF_KIN_ENERGY : public FIELD_BASE<1, 0, 0> { };
196struct CUTOFF_HEAT_FLUX : public FIELD_BASE<1, 0, 0> { };
197struct CHEM_POTENTIAL : public FIELD_BASE<1, 0, 0> { };
198struct ADDEND : public FIELD_BASE<1, 0, 0> { };
199struct V6 : public FIELD_BASE<6, 0, 0> { };
200struct V12 : public FIELD_BASE<12, 0, 0> { };
201struct OMEGA : public FIELD_BASE<1, 0, 0> { };
202struct MAGIC : public FIELD_BASE<1, 0, 0> { };
203struct G : public FIELD_BASE<0, 1, 0> { };
204struct EPSILON : public FIELD_BASE<1, 0, 0> { };
205struct BODY_FORCE : public FIELD_BASE<0, 1, 0> { };
206struct K : public FIELD_BASE<1, 0, 0> { };
207struct NU : public FIELD_BASE<1, 0, 0> { };
208struct VELOCITY_NUMERATOR : public FIELD_BASE<0, 1, 0> { };
209struct VELOCITY_DENOMINATOR : public FIELD_BASE<1, 0, 0> { };
210struct ZETA : public FIELD_BASE<0, 0, 1> { };
211struct LOCAL_DRAG : public FIELD_BASE<0, 1, 0> { };
212struct VELOCITY_SOLID : public FIELD_BASE<0, 1, 0> { };
213struct COORDINATE : public FIELD_BASE<0, 1, 0> { };
214struct F : public FIELD_BASE<0, 0, 1> { };
215struct NEIGHBOR : public FIELD_BASE<1, 0, 0>{
216 template <typename T, typename DESCRIPTOR>
217 static constexpr auto getInitialValue() {
218 return Vector<value_type<T>,1>(0.);
219 }
220};
221struct DJDF : public FIELD_BASE<0, 0, 1> { };
222struct DJDALPHA : public FIELD_BASE<0, 1, 0> { };
223struct AV_SHEAR : public FIELD_BASE<1, 0, 0> { };
224struct SHEAR_RATE_MAGNITUDE : public FIELD_BASE<1, 0, 0> { };
225struct TAU_W : public FIELD_BASE<1, 0, 0> { };
226struct SCALAR : public FIELD_BASE<1, 0, 0> { };
227struct SMAGO_CONST : public FIELD_BASE<1, 0, 0> { };
228struct EFFECTIVE_OMEGA : public FIELD_BASE<1, 0, 0> { };
229struct VELO_GRAD : public FIELD_BASE<0, 3, 0> { };
230struct FIL_RHO : public FIELD_BASE<1, 0, 0> { };
231struct LOCAL_FIL_VEL_X : public FIELD_BASE<1, 0, 0> { };
232struct LOCAL_FIL_VEL_Y : public FIELD_BASE<1, 0, 0> { };
233struct LOCAL_FIL_VEL_Z : public FIELD_BASE<1, 0, 0> { };
234struct LOCAL_AV_DISS : public FIELD_BASE<1, 0, 0> { };
235struct LOCAL_AV_TKE : public FIELD_BASE<1, 0, 0> { };
236struct LOCAL_SIGMA_ADM : public FIELD_BASE<1, 0, 0> { };
237struct LOCAL_NU_EDDY : public FIELD_BASE<1, 0, 0> { };
238struct FILTERED_VEL_GRAD : public FIELD_BASE<0, 3, 0> { };
239struct ERROR_COVARIANCE : public FIELD_BASE<1, 0, 0> { };
240struct VARIANCE : public FIELD_BASE<1, 0, 0> { };
241struct TAU_SGS : public FIELD_BASE<1, 0, 0> { };
242struct FILTERED_POPULATION : public FIELD_BASE<0, 0, 1> { };
243struct INDICATE : public FIELD_BASE<1, 0, 0> { };
244struct BIOGAS_INSTANT : public FIELD_BASE<1, 0, 0> { };
245struct BIOGAS_CUMULATIVE : public FIELD_BASE<1, 0, 0> { };
246struct METHANE_INSTANT : public FIELD_BASE<1, 0, 0> { };
247struct METHANE_CUMULATIVE : public FIELD_BASE<1, 0, 0> { };
248struct CO2_INSTANT : public FIELD_BASE<1, 0, 0> { };
249struct CO2_CUMULATIVE : public FIELD_BASE<1, 0, 0> { };
250struct TEMPERATURE : public FIELD_BASE<1, 0, 0> { };
251struct INTERPHASE_NORMAL : public FIELD_BASE<0, 1, 0> { };
252struct MASS : public FIELD_BASE<1, 0, 0> { };
253struct CELL_TYPE : public FIELD_BASE<1, 0, 0> { };
254struct BOUNDARY : public FIELD_BASE<1, 0, 0> { };
255struct CONTACT_DETECTION : public TYPED_FIELD_BASE<size_t, 1, 0, 0> { };
256struct POROSITY : public FIELD_BASE<1, 0, 0> {
257 template <typename T, typename DESCRIPTOR>
258 static constexpr auto getInitialValue() {
259 return Vector<value_type<T>,DESCRIPTOR::template size<POROSITY>()>{1};
260 }
261};
262struct POROSITY2 : public FIELD_BASE<1, 0, 0> { };
263struct EUL2LAGR : public FIELD_BASE<1, 0, 0> { };
264struct LOCATION : public FIELD_BASE<0, 1, 0> { };
265struct VORTICITY : public FIELD_BASE<1, 0, 0> { };
266
267//TODO: This expression has been removed on master lately. As no obvious equivalent could be found immediately,
268// it is added back in to enable some functionality on feature/unifiedParticleFramework.
269// In case a proper equivalent exists, this expression can be removed for good!
270template <
271 typename WANTED_FIELD,
272 typename CURRENT_FIELD,
273 typename... FIELDS,
274 // WANTED_FIELD equals the head of our field list, terminate recursion
275 std::enable_if_t<std::is_same<WANTED_FIELD,CURRENT_FIELD>::value, int> = 0
276 >
277constexpr unsigned getIndexInFieldList()
278{
279 return 0;
280}
281
282template <
283 typename WANTED_FIELD,
284 typename CURRENT_FIELD,
285 typename... FIELDS,
286 // WANTED_FIELD doesn't equal the head of our field list
287 std::enable_if_t<!std::is_same<WANTED_FIELD,CURRENT_FIELD>::value, int> = 0
288 >
289constexpr unsigned getIndexInFieldList()
290{
291 // Break compilation when WANTED_FIELD is not provided by list of fields
292 static_assert(sizeof...(FIELDS) > 0, "Field not found.");
293
294 return 1 + getIndexInFieldList<WANTED_FIELD,FIELDS...>();
295}
296
298
300
301// *INDENT-ON*
302
303}
304
305}
306
307#endif
Basic value-substitute enabling extraction of expression trees for code generation.
Definition expr.h:38
Plain old scalar vector.
Definition vector.h:47
constexpr unsigned getIndexInFieldList()
typename std::is_base_of< PROPAGATABLE_FIELD_BASE, FIELD >::type is_propagatable_field
Evaluates to true iff FIELD is propagatable (e.g. POPULATION)
constexpr auto take_n_sequence(std::index_sequence< I, Is... >)
Definition meta.h:475
Top level namespace for all of OpenLB.
Abstract declarator of Column-like storage.
Definition column.h:34
Abstract declarator of cyclic Column-like storage.
Definition column.h:43
Base of a field whose size is defined by [C,U_1,...,U_N]^T * [1,V_1,...V_N].
static constexpr bool isSerializable()
static constexpr std::size_t size()
Get size of field for parameter vector V (zero-padds or shortens V as required)
static constexpr std::size_t size(std::index_sequence< V... >)
Get size of field for parameter vector V (strict)
static constexpr auto getInitialValue()
Return value must be a correctly sized and typed olb::Vector.
T value_type
Return value type of field.
static constexpr auto getInitialValue()
Base of a descriptor field of pointer type.
static constexpr auto getInitialValue()
Base of a implicitly propagatable descriptor field.
static constexpr auto getInitialValue()
Base of a tensor-valued descriptor field.
static constexpr unsigned size()
Base of a descriptor field of scalar TYPE with dimensions A*B + B*Q + C.
static constexpr auto getInitialValue()
std::conditional_t< std::is_same_v< T, Expr >, Expr, TYPE > value_type
static constexpr bool isSerializable()
efficient implementation of a vector class