OpenLB 1.7
Loading...
Searching...
No Matches
descriptorBase.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2019 Adrian Kummerlaender, Mathias J. Krause
4 * 2021 Adrian Kummerlaender, Nicolas Hafen, Mathias J. Krause
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 DESCRIPTOR_BASE_H
26#define DESCRIPTOR_BASE_H
27
28#include "descriptorTag.h"
29#include "descriptorField.h"
30#include "core/meta.h"
31
32namespace olb {
33
34namespace descriptors {
35
36template <typename FIELD>
37using is_data_field = std::integral_constant<bool, !is_tag_field<FIELD>::value>;
38
40
41
43struct TYPE_LATTICE;
44struct TYPE_PARTICLE;
45
46
48template <typename... FIELDS>
49struct FIELD_TUPLE : public meta::list<FIELDS...> {
51 FIELD_TUPLE() = delete;
52
53 using fields_t = meta::list<FIELDS...>;
54
55 template <template<typename...> class COLLECTION>
56 using decompose_into = COLLECTION<FIELDS...>;
57
59 static constexpr std::size_t field_count = sizeof...(FIELDS);
60
62 template <template<typename> class COND>
63 using filter = typename meta::filter_t<COND, FIELDS...>
65
67 template <typename WANTED_FIELD>
68 static constexpr bool provides()
69 {
70 return meta::contains<WANTED_FIELD,FIELDS...>();
71 }
72
74 static bool provides(std::type_index field)
75 {
76 return meta::contains<FIELDS...>(field);
77 }
78
79};
80
82template <unsigned... PARAMS>
84 template <typename FIELD>
85 static constexpr std::size_t size() {
86 return FIELD::template size<PARAMS...>();
87 };
88};
89
91template <typename PARAMETERS, typename... FIELDS>
92struct CONCRETE_FIELD_TUPLE : public FIELD_TUPLE<FIELDS...> {
93 using parameter_tuple_t = PARAMETERS;
94
96
99 template<typename BASE>
100 using derivedField = std::conditional_t<
102 typename meta::list_item_with_base_default_base<BASE,FIELDS...>::type,
103 FIELDS...
104 >(),
106 void
107 >;
108
110
114 template <typename ...NESTED_FIELDS>
119
121
124 template <typename FIELD = void>
125 static constexpr std::size_t size()
126 {
127 if constexpr (std::is_void_v<FIELD>) {
128 return (parameter_tuple_t::template size<FIELDS>() + ... + 0);
129 } else {
130 return parameter_tuple_t::template size<FIELD>();
131 }
132 __builtin_unreachable();
133 }
134};
135
137template <unsigned D, typename... FIELDS>
138struct SPATIAL_DESCRIPTOR : public CONCRETE_FIELD_TUPLE<PARAMETER_TUPLE<D>, FIELDS...> {
140 static constexpr int d = D;
141};
142
144
146template <unsigned D, unsigned Q, typename... FIELDS>
148 , public CONCRETE_FIELD_TUPLE<PARAMETER_TUPLE<D,Q>, FIELDS...> {
150 using type = TYPE_LATTICE;
152 static constexpr int d = D;
154 static constexpr int q = Q;
155
156 using all_t = meta::list<FIELDS...>;
158 using tags_t = meta::filter_t<is_tag_field, FIELDS...>;
159
161
167
168};
169
171template <typename T, typename DESCRIPTOR>
173 using value_t = T;
174 using descriptor_t = DESCRIPTOR;
175};
176
178
181template <typename TYPE>
183 typename std::remove_reference_t<TYPE>::value_t,
184 typename std::remove_reference_t<TYPE>::descriptor_t
185>;
186
187
189template <unsigned D, typename... FIELDS>
190struct PARTICLE_DESCRIPTOR : public CONCRETE_FIELD_TUPLE<PARAMETER_TUPLE<D>, FIELDS...> {
192 using type = TYPE_PARTICLE;
194 static constexpr int d = D;
195
196};
197
199
200}
201
202}
203
204#endif
std::integral_constant< bool, !is_tag_field< FIELD >::value > is_data_field
std::is_base_of< DESCRIPTOR_TAG, FIELD > is_tag_field
typename filter< COND, TYPES... >::type filter_t
meta::list of TYPES meeting COND
Definition meta.h:245
constexpr bool contains()
Returns true iff a given type list contains WANTED.
Definition meta.h:125
Top level namespace for all of OpenLB.
Tuple of concretized field declarations.
std::conditional_t< meta::contains< typename meta::list_item_with_base_default_base< BASE, FIELDS... >::type, FIELDS... >(), typename meta::list_item_with_base_default_base< BASE, FIELDS... >::type, void > derivedField
Returns FIELD by provided BASE.
static constexpr std::size_t size()
Returns size of FIELD if given or of whole tuple if not.
static constexpr bool providesNested()
Returns whether WANTED_FIELD (last in NESTED_FIELDS) is provided by CONCRETE_FIELD_TUPLE.
Tuple of abstract field declarations.
static constexpr bool provides()
Returns whether WANTED_FIELD is contained in FIELDS.
FIELD_TUPLE()=delete
Deleted constructor to enforce pure usage as type and prevent implicit narrowing conversions.
static constexpr std::size_t field_count
Number of fields.
COLLECTION< FIELDS... > decompose_into
typename meta::filter_t< COND, FIELDS... > ::template decompose_into< FIELD_TUPLE > filter
Returns FIELD_TUPLE with subset of FIELDS meeting COND.
static bool provides(std::type_index field)
Returns whether field is contained in FIELDS.
Base descriptor of a D-dimensional lattice with Q directions and a list of additional fields.
TYPE_LATTICE type
Type identifier.
meta::filter_t< is_tag_field, FIELDS... > tags_t
typename tags_t::template first_with_base_or_fallback< tag::CATEGORY, tag::DEFAULT > category_tag
Tag that describes the category of the descriptor.
static constexpr int q
Number of velocities.
static constexpr int d
Number of dimensions.
meta::filter_t< is_data_field, FIELDS... > fields_t
Tuple of parameters to concretize field declarations.
static constexpr std::size_t size()
Base descriptor of a particle system.
static constexpr int d
Number of dimensions.
TYPE_PARTICLE type
Type identifier.
Base descriptor of a d-dimensional system.
static constexpr int d
Number of dimensions.
Pair of base value and descriptor type.
static constexpr bool contains()
Definition meta.h:598
Get first type based on BASE contained in a given type list.
Definition meta.h:145
std::conditional_t< std::is_base_of< BASE, HEAD >::value, HEAD, typename list_item_with_base_default_base< BASE, TAIL... >::type > type
Definition meta.h:146
Plain wrapper for list of types.
Definition meta.h:276
std::conditional_t< std::is_void_v< first_with_base< BASE > >, FALLBACK, first_with_base< BASE > > first_with_base_or_fallback
Returns first type of TYPES that is derived from BASE.
Definition meta.h:317