Loading...
Searching...
No Matches
exprTraits.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2021-2023 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::exprTypeTraits
28
29Description
30 Simple type identifiers for polymorphic expression values.
31 The definitions are similar to std::integral_constant in that they
32 provide value, value_type (and name).
33
34SourceFiles
35 exprTraits.C
36
37Namespace
38 Foam::expressions
39
40Description
41 A namespace for expression-related classes/traits etc.
42
43Namespace
44 Foam::expressions::Detail
45
46Description
47 A namespace for implementation details related to expressions.
48
49\*---------------------------------------------------------------------------*/
50
51#ifndef Foam_expressions_exprTraits_H
52#define Foam_expressions_exprTraits_H
53
54// Regular field types
55#include "label.H"
56#include "scalar.H"
57//TBD: #include "complex.H"
58#include "vector.H"
59#include "sphericalTensor.H"
60#include "symmTensor.H"
61#include "tensor.H"
62#include "word.H"
63
64// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
65
66namespace Foam
67{
68namespace expressions
69{
70
71//- An enumeration of known and expected expression value types.
72// Do not rely on the enumeration values for any direct coding.
73//
74// \note NONE used when initializing types, whereas INVALID is used
75// for unsupported types (never as a stored type).
76// This avoids false positives when testing.
77//
78// Except NONE and INVALID, the enumerations will mostly not be used
79// directly, but through exprTypeTraits :: value
80
81enum class valueTypeCode : unsigned char
82{
83 NONE = 0,
85
86 // Rank 0 types
90//TBD: type_complex, //!< Type is 'complex'
91
92 // Rank 1 types
94
95 // Rank 2 types
99};
100
101
102// Global Functions
103
104//- From string to valueTypeCode (if any)
106(
107 const word& dataTypeName,
108 // Fallback for unknown
110);
111
112
113// Some implementation detail
114namespace Detail
115{
116
117//- The number of components associated with given valueTypeCode
119
120//- The vector-space rank associated with given valueTypeCode
122
123} // End namespace Detail
124
125
126// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
127
128} // End namespace expressions
129
130
131/*---------------------------------------------------------------------------*\
132 Class exprTypeTraits Declaration
133\*---------------------------------------------------------------------------*/
134
135// Generic enumerated traits is INVALID (unknown)
136template<class Type>
137struct exprTypeTraits
138{
139 // The value type
140 typedef Type value_type;
141 // The type name (similar to pTraits typeName)
142 static constexpr const char* const name = "";
143 // The enumeration number associated with the type
144 static constexpr
145 ::Foam::expressions::valueTypeCode value =
147 // The rank of the type
148 static constexpr ::Foam::direction rank = 0;
149 // The number of components
150 static constexpr ::Foam::direction nComponents = 0;
152
153
154#undef defineExprTypeTraits
155#define defineExprTypeTraits(Type, Name, Rank, NumCmpts) \
157 template<> \
158 struct exprTypeTraits<Type> \
159 { \
160 typedef Type value_type; \
161 static constexpr const char* const name = #Name ; \
162 static constexpr \
163 ::Foam::expressions::valueTypeCode value = \
164 ::Foam::expressions::valueTypeCode::type_##Name ; \
165 static constexpr ::Foam::direction rank = Rank ; \
166 static constexpr ::Foam::direction nComponents = NumCmpts ; \
167 };
168
169
170// Define with name to match pTraits::typeName, with rank/nComponents
171defineExprTypeTraits(bool, bool, 0, 1);
172defineExprTypeTraits(::Foam::label, label, 0, 1);
173defineExprTypeTraits(::Foam::scalar, scalar, 0, 1);
174//TBD: defineExprTypeTraits(::Foam::complex, complex, 0, 2);
180#undef defineExprTypeTraits
182// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184//- A word representation of a valueTypeCode.
185//- Empty for expressions::valueTypeCode::INVALID
186word name(const expressions::valueTypeCode typeCode);
187
188
189//- A word representation of a valueTypeCode.
190//- Empty for expressions::valueTypeCode::INVALID
191template<>
192struct nameOp<expressions::valueTypeCode>
193{
194 word operator()(const expressions::valueTypeCode typeCode) const
195 {
196 return Foam::name(typeCode);
197 }
198};
199
200// No IOstream Operators for valueTypeCode at the moment (Nov 2021)
201
202} // End namespace Foam
203
204// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205
206#endif
207
208// ************************************************************************* //
Tensor of scalars, i.e. Tensor<scalar>.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineExprTypeTraits(Type, Name, Rank, NumCmpts)
Definition exprTraits.H:161
auto & name
Implementation details for various OpenFOAM classes.
Definition zoneSubSet.C:30
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
Definition exprTraits.C:40
::Foam::direction rank(const expressions::valueTypeCode) noexcept
The vector-space rank associated with given valueTypeCode.
Definition exprTraits.C:70
A namespace for expression-related classes/traits etc.
valueTypeCode valueTypeCodeOf(const word &dataTypeName, const expressions::valueTypeCode deflt=expressions::valueTypeCode::INVALID)
From string to valueTypeCode (if any).
Definition exprTraits.C:100
valueTypeCode
An enumeration of known and expected expression value types.
Definition exprTraits.H:82
@ type_sphericalTensor
Type is 'sphericalTensor'.
Definition exprTraits.H:96
@ type_symmTensor
Type is 'symmTensor'.
Definition exprTraits.H:97
@ type_scalar
Type is 'scalar'.
Definition exprTraits.H:89
@ type_vector
Type is 'vector'.
Definition exprTraits.H:93
@ NONE
No type, or default initialized type.
Definition exprTraits.H:83
@ INVALID
Invalid/unknown/error type.
Definition exprTraits.H:84
@ type_tensor
Type is 'tensor'.
Definition exprTraits.H:98
Namespace for OpenFOAM.
Tensor< scalar > tensor
Definition symmTensor.H:57
uint8_t direction
Definition direction.H:49
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
Vector< scalar > vector
Definition vector.H:57
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
Definition symmTensor.H:55
Simple type identifiers for polymorphic expression values. The definitions are similar to std::integr...
Definition exprTraits.H:144
static constexpr const char *const name
Definition exprTraits.H:148
static constexpr ::Foam::direction rank
Definition exprTraits.H:154
static constexpr ::Foam::direction nComponents
Definition exprTraits.H:156
static constexpr::Foam::expressions::valueTypeCode value
Definition exprTraits.H:151
word operator()(const expressions::valueTypeCode typeCode) const
Definition exprTraits.H:204
Extract name (as a word) from an object, typically using its name() method.
Definition word.H:341
word operator()(const T &obj) const
Definition word.H:342