OpenLB 1.8.1
Loading...
Searching...
No Matches
concepts.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2022 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 CORE_CONCEPTS_H
25#define CORE_CONCEPTS_H
26
27#if (defined __cpp_concepts && (__cplusplus >= __cpp_concepts))
28
29#include <concepts>
30#include <type_traits>
31
32#include "baseType.h"
33#include "vector.h"
34#include "fieldArrayD.h"
35#include "operatorScope.h"
36
38
39#include "utilities/aDiff.h"
40
41namespace olb {
42
43namespace concepts {
44
46template <typename T>
47concept BaseType = requires(T x, T y) {
48 // Basic arithmetic
49 x + y; x - y; x * y; x / y;
50 // in-place arithmetic
51 x += y; x -= y; x *= y; x /= y;
52 // Establish guaranteed core set of additional functions
53 util::sqrt(x);
54 //util::abs(x);
55 //util::sin(x);
56 //util::cos(x);
57 //util::pow(x,y);
58};
59
60template <typename DESCRIPTOR>
61concept Descriptor = requires () {
62 { DESCRIPTOR::d } -> std::convertible_to<std::size_t>;
63 requires std::is_base_of_v<meta::list_base, DESCRIPTOR>;
64};
65
66namespace placeholder {
67
68using ValueType = float;
70
73
74}
75
77template <typename DESCRIPTOR>
78concept LatticeDescriptor = requires () {
81 { DESCRIPTOR::q } -> std::convertible_to<std::size_t>;
83 requires (DESCRIPTOR::template provides<descriptors::POPULATION>());
85 { descriptors::c<DESCRIPTOR>(unsigned{}) } -> std::same_as<Vector<int,DESCRIPTOR::d>>;
87 { descriptors::t<placeholder::ValueType,DESCRIPTOR>(unsigned{}) } -> std::same_as<placeholder::ValueType>;
89 { descriptors::opposite<DESCRIPTOR>(unsigned{}) } -> std::same_as<int>;
91 { descriptors::invCs2<placeholder::ValueType,DESCRIPTOR>() } -> std::same_as<placeholder::ValueType>;
92};
93
94template <typename FIELD>
95concept Field = requires() {
96 // Column type is declared
97 //FIELD::template column_type<placeholder::ValueType>;
98 // Size is exposed
99 { FIELD::template size<placeholder::Descriptor>() } -> std::convertible_to<std::size_t>;
100 // Initial value is defined
101 { FIELD::template getInitialValue<placeholder::ValueType,placeholder::Descriptor>() } -> std::same_as<
103 placeholder::Descriptor::template size<FIELD>()>
104 >;
105 // (De)Serializability is defined
106 { FIELD::isSerializable() } -> std::same_as<bool>;
107};
108
109namespace placeholder {
110
111struct Field {
112 template <typename T>
113 using value_type = T;
114
115 template <typename T>
117
118 static constexpr bool isSerializable() {
119 return true;
120 }
121
122 template <typename DESCRIPTOR>
123 static constexpr std::size_t size() {
124 return 3;
125 }
126
127 template <typename T, typename DESCRIPTOR>
128 static constexpr auto getInitialValue() {
130 }
131};
132
133}
134
136template <typename CELL>
137concept MinimalCell = requires(CELL cell) {
138 // Population references are exposed via operator[]
139 { cell[unsigned{}] } -> std::convertible_to<const typename CELL::value_t&>;
140};
141
143template <typename CELL>
144concept Cell = requires(CELL cell) {
145 // Population access
146 requires MinimalCell<CELL>;
147 // CELL::value_t is valid BaseType
149 // CELL::descriptor_t is a DdQq lattice descriptor
151 // Access to associated fields (using guaranteed POPULATION field as placeholder)
152 // get by-value
153 { cell.template getField<descriptors::POPULATION>() } -> std::same_as<
155 >;
156 // set by-value
157 //cell.template setField<descriptors::POPULATION>(
158 // FieldD<typename CELL::value_t,typename CELL::descriptor_t,descriptors::POPULATION>{});
159 // get component by-value
160 { cell.template getFieldComponent<descriptors::POPULATION>(unsigned{}) } -> std::convertible_to<typename CELL::value_t>;
161 // get by-pointer
162 { cell.template getFieldPointer<descriptors::POPULATION>()[unsigned{}] } -> std::convertible_to<typename CELL::value_t>;
163};
164
166template <typename PARAMETERS>
167concept Parameters = requires (typename PARAMETERS::template include_fields<placeholder::Field> parameters) {
168 // PARAMETERS::value_t is valid BaseType
170 // PARAMETERS::descriptor_t is a descriptor
171 //requires LatticeDescriptor<typename PARAMETERS::descriptor_t>;
172
173 // Access to parameter fields
174 { parameters.template provides<placeholder::Field>() } -> std::same_as<bool>;
175 { parameters.template get<placeholder::Field>() } -> std::convertible_to<
177 >;
178 // set by-value
179 parameters.template set<placeholder::Field>(
181};
182
183namespace placeholder {
184
188
190 ValueType& operator[](unsigned iPop) { return f[iPop]; }
191};
192
193struct Cell : public MinimalCell {
194 template <typename FIELD>
196 template <typename FIELD>
197 auto getFieldComponent(unsigned iPop) { return this->f[iPop]; }
198 template <typename FIELD>
199 auto& getFieldPointer() { return this->f; }
200 template <typename FIELD>
202};
203
207
208 template <typename...>
210
211 template <typename FIELD>
212 bool provides() const { return false; }
213 template <typename FIELD>
214 auto get() {
215 if constexpr (descriptor_t::template size<FIELD>() == 1) {
217 } else {
219 }
220 }
221 template <typename FIELD>
223};
224
228
229 template <typename...>
231
232 template <typename FIELD>
233 bool provides() const { return false; }
234 template <typename FIELD>
235 auto get() {
236 if constexpr (descriptor_t::template size<FIELD>() == 1) {
238 } else {
240 }
241 }
242 template <typename FIELD>
244};
245
247
248}
249
251template <typename CELL>
252concept DynamicCell = requires(CELL cell, typename CELL::value_t value) {
253 // Field access
254 requires Cell<CELL>;
255
256 // Computation of moments
257 { cell.computeRho() } -> std::convertible_to<typename CELL::value_t>;
258 cell.computeU(&value);
259 cell.computeJ(&value);
260 cell.computeRhoU(value, &value);
261 cell.computeStress(&value);
262 cell.computeAllMomenta(value,&value,&value);
263
264 // Definition of moments
265 cell.defineRho(value);
266 cell.defineU(&value);
267 cell.defineRhoU(value,&value);
268 cell.defineAllMomenta(value,&value,&value);
269 cell.inverseShiftRhoU(value,&value);
270
271};
272
274template <typename OPERATOR>
275concept CellOperator = requires(OPERATOR op) {
276 // Operator scope is defined
277 { OPERATOR::scope } -> std::convertible_to<OperatorScope>;
278 // Operator scope is cell-wise
279 requires OPERATOR::scope == OperatorScope::PerCell
280 || OPERATOR::scope == OperatorScope::PerCellWithParameters;
281 // Operator priority is defined
282 { op.getPriority() } -> std::same_as<int>;
283 // Todo: Operator provides apply method template
284};
285
287template <typename OPERATOR>
288concept BlockOperator = requires(OPERATOR op) {
289 // Operator scope is defined
290 { OPERATOR::scope } -> std::convertible_to<OperatorScope>;
291 // Operator scope is block-wise
292 requires OPERATOR::scope == OperatorScope::PerBlock;
293 // Operator priority is defined
294 { op.getPriority() } -> std::same_as<int>;
295 // Todo: Operator provides apply method template
296};
297
298}
299
300}
301
302#else // Fallback if concepts are not available (standard < C++20)
303
304#error C++20 concept support is required
305
306#endif
307
308#endif
#define OPERATOR(OP, rhs)
Definition aDiffTape.h:64
The description of a algoritmic differentiation data type using the forward method – header file.
Plain old scalar vector.
Foundational arithmetic type for all computations.
Definition concepts.h:47
Block-wise operator with scope, priority and apply template.
Definition concepts.h:288
Cell-wise operator with scope, priority and apply template.
Definition concepts.h:275
Cell exposing populations and associated fields.
Definition concepts.h:144
Full cell exposing populations, moments, dynamics and associated fields.
Definition concepts.h:252
Descriptor of DdQq lattice and associated constants.
Definition concepts.h:78
Basic cell exposing value-typed population references.
Definition concepts.h:137
Parameters tuple for use in collision, non-local operators.
Definition concepts.h:167
descriptors::D3Q19<> Descriptor3D
Definition concepts.h:72
descriptors::D2Q9<> Descriptor2D
Definition concepts.h:71
descriptors::D2Q9<> Descriptor
Definition concepts.h:69
constexpr T invCs2() any_platform
Definition functions.h:107
constexpr T t(unsigned iPop, tag::CUM) any_platform
Definition cum.h:108
constexpr int c(unsigned iPop, unsigned iDim) any_platform
Definition functions.h:83
constexpr int opposite(unsigned iPop) any_platform
Definition functions.h:95
Expr sqrt(Expr x)
Definition expr.cpp:225
Top level namespace for all of OpenLB.
Vector(T &&t, Ts &&... ts) -> Vector< std::remove_cvref_t< T >, 1+sizeof...(Ts)>
Vector< typename FIELD::template value_type< T >, DESCRIPTOR::template size< FIELD >() > FieldD
Vector storing a single field instance.
Definition vector.h:480
@ PerBlock
Per-block application, i.e. OPERATOR::apply is passed a ConcreteBlockLattice.
@ PerCell
Per-cell application, i.e. OPERATOR::apply is passed a CELL concept implementation.
@ PerCellWithParameters
Per-cell application with parameters, i.e. OPERATOR::apply is passed a CELL concept implementation an...
Abstract declarator of Column-like storage.
Definition column.h:34
auto getFieldComponent(unsigned iPop)
Definition concepts.h:197
void setField(FieldD< ValueType, Descriptor, FIELD > &&)
Definition concepts.h:201
static constexpr bool isSerializable()
Definition concepts.h:118
static constexpr std::size_t size()
Definition concepts.h:123
static constexpr auto getInitialValue()
Definition concepts.h:128
ValueType & operator[](unsigned iPop)
Definition concepts.h:190
void set(FieldD< ValueType, Descriptor2D, FIELD > &&)
Definition concepts.h:222
void set(FieldD< ValueType, Descriptor3D, FIELD > &&)
Definition concepts.h:243
D2Q9 lattice.
Definition common.h:46
D3Q19 lattice.
Definition common.h:122
efficient implementation of a vector class