OpenLB 1.7
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
33
34namespace olb {
35
36namespace concepts {
37
38// DESCRIPTOR describes DdQq lattice with associated fields
39template <typename DESCRIPTOR>
40concept LatticeDescriptor = std::derived_from<DESCRIPTOR, descriptors::LATTICE_DESCRIPTOR_BASE>;
41
43template <typename CELL>
44concept MinimalCell = requires(CELL cell) {
45 // CELL::value_t exists
46 typename CELL::value_t;
47 // CELL::descriptor_t is a lattice descriptor
49 // Population references are exposed via operator[]
50 { cell[unsigned{0}] } -> std::convertible_to<const typename CELL::value_t&>;
51};
52
54template <typename CELL>
55concept Cell = requires(CELL cell, typename CELL::value_t value) {
56 // Population access
57 requires MinimalCell<CELL>;
58
59 // Computation of moments
60 { cell.computeRho() } -> std::convertible_to<typename CELL::value_t>;
61 cell.computeU(&value);
62 cell.computeJ(&value);
63 cell.computeRhoU(value, &value);
64 cell.computeStress(&value);
65 cell.computeAllMomenta(value,&value,&value);
66
67 // Definition of moments
68 cell.defineRho(value);
69 cell.defineU(&value);
70 cell.defineRhoU(value,&value);
71 cell.defineAllMomenta(value,&value,&value);
72 cell.inverseShiftRhoU(value,&value);
73
74 // Definition of populations
75 cell.definePopulations(&value);
76
77 // Initialize to equilibrium
78 cell.iniEquilibrium(value,&value);
79 cell.iniRegularized(value,&value,&value);
80
81 // Access to dynamics
82 cell.getDynamics();
83
84 // Access to associated fields by-value
85 // (using guaranteed POPULATION field as placeholder)
86 { cell.template getField<descriptors::POPULATION>() } -> std::same_as<
87 FieldD<typename CELL::value_t,typename CELL::descriptor_t,descriptors::POPULATION>
88 >;
89 cell.template setField<descriptors::POPULATION>(&value);
90
91 // Access to associated field components by-reference
92 // (using guaranteed POPULATION field as placeholder)
93 { cell.template getFieldComponent<descriptors::POPULATION>(0) } -> std::convertible_to<const typename CELL::value_t&>;
94
95 // Access to associated fields by-pointer
96 // (using guaranteed POPULATION field as placeholder, return type operator[] accessible)
97 { cell.template getFieldPointer<descriptors::POPULATION>()[0] } -> std::convertible_to<typename CELL::value_t>;
98};
99
101template <typename OPERATOR>
102concept CellOperator = requires(OPERATOR op) {
103 // Operator scope is defined
104 { OPERATOR::scope } -> std::convertible_to<OperatorScope>;
105 // Operator scope is cell-wise
106 requires OPERATOR::scope == OperatorScope::PerCell
107 || OPERATOR::scope == OperatorScope::PerCellWithParameters;
108 // Operator priority is defined
109 { op.getPriority() } -> std::same_as<int>;
110 // Todo: Operator provides apply method template
111};
112
114template <typename OPERATOR>
115concept BlockOperator = requires(OPERATOR op) {
116 // Operator scope is defined
117 { OPERATOR::scope } -> std::convertible_to<OperatorScope>;
118 // Operator scope is block-wise
119 requires OPERATOR::scope == OperatorScope::PerBlock;
120 // Operator priority is defined
121 { op.getPriority() } -> std::same_as<int>;
122 // Todo: Operator provides apply method template
123};
124
125}
126
127}
128
129#define CONCEPT(C) olb::concepts::C
130
131#else // Fallback if concepts are not available (standard < C++20)
132
133#define CONCEPT(C) typename
134
135#endif
136
137#endif
Block-wise operator with scope, priority and apply template.
Definition concepts.h:115
Cell-wise operator with scope, priority and apply template.
Definition concepts.h:102
Full cell exposing populations, moments, dynamics and associated fields.
Definition concepts.h:55
Basic cell exposing value-typed population references.
Definition concepts.h:44
Top level namespace for all of OpenLB.
@ 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...