DUNE-ACFEM (unstable)

namedconstant.hh
1#ifndef __DUNE_ACFEM_COMMON_NAMED_CONSTANT_HH__
2#define __DUNE_ACFEM_COMMON_NAMED_CONSTANT_HH__
3
4#include "types.hh"
5#include "tostring.hh"
6
7namespace Dune
8{
9
10 namespace ACFem
11 {
12
13 namespace TypedValue
14 {
15
20 template<class T, char... Name>
22
23 template<class T>
24 struct IsNamedConstant
25 : FalseType
26 {};
27
28 template<class T>
29 struct IsNamedConstant<T&>
30 : IsNamedConstant<std::decay_t<T> >
31 {};
32
33 template<class T>
34 struct IsNamedConstant<T&&>
35 : IsNamedConstant<std::decay_t<T> >
36 {};
37
38 template<class T, char... Name>
39 struct IsNamedConstant<NamedConstant<T, Name...> >
40 : TrueType
41 {};
42
43 template<class T, char... Name>
44 std::string toString(NamedConstant<T, Name...>)
45 {
46 using Type = NamedConstant<T, Name...>;
47 const std::string name({ Name... });
48 return name+":"+ACFem::toString(Type::value);
49 }
50
52 template<class T>
53 struct NamedConstant<T, 'E'>
54 {
55 static_assert(sizeof(T) < sizeof(0.0L), "Unsupported floating point precision.");
56 static constexpr T value = (T)2.718281828459045235360287471352662498L;
57 constexpr T operator()() const
58 {
59 return value;
60 }
61 constexpr operator T() const
62 {
63 return value;
64 }
65 };
66
68 template<class T>
69 struct NamedConstant<T, 'L', 'O', 'G', '2', 'E'>
70 {
71 static_assert(sizeof(T) < sizeof(0.0L), "Unsupported floating point precision.");
72 static constexpr T value = (T)1.442695040888963407359924681001892137L;
73 constexpr T operator()() const
74 {
75 return value;
76 }
77 constexpr operator T() const
78 {
79 return value;
80 }
81 };
82
84 template<class T>
85 struct NamedConstant<T, 'L', 'O', 'G', '1', '0', 'E'>
86 {
87 static_assert(sizeof(T) < sizeof(0.0L), "Unsupported floating point precision.");
88 static constexpr T value = (T)0.434294481903251827651128918916605082L;
89 constexpr T operator()() const
90 {
91 return value;
92 }
93 constexpr operator T() const
94 {
95 return value;
96 }
97 };
98
100 template<class T>
101 struct NamedConstant<T, 'L', 'N', '2'>
102 {
103 static_assert(sizeof(T) < sizeof(0.0L), "Unsupported floating point precision.");
104 static constexpr T value = (T)0.693147180559945309417232121458176568L;
105 constexpr T operator()() const
106 {
107 return value;
108 }
109 constexpr operator T() const
110 {
111 return value;
112 }
113 };
114
116 template<class T>
117 struct NamedConstant<T, 'L', 'N', '1', '0'>
118 {
119 static_assert(sizeof(T) < sizeof(0.0L), "Unsupported floating point precision.");
120 static constexpr T value = (T)2.302585092994045684017991454684364208L;
121 constexpr T operator()() const
122 {
123 return value;
124 }
125 constexpr operator T() const
126 {
127 return value;
128 }
129 };
130
132 template<class T>
133 struct NamedConstant<T, 'P', 'I'>
134 {
135 static_assert(sizeof(T) < sizeof(0.0L), "Unsupported floating point precision.");
136 static constexpr T value = (T)3.141592653589793238462643383279502884L;
137 constexpr T operator()() const
138 {
139 return value;
140 }
141 constexpr operator T() const
142 {
143 return value;
144 }
145 };
146
148 template<class T>
149 struct NamedConstant<T, 'P', 'I', '_', '2'>
150 {
151 static_assert(sizeof(T) < sizeof(0.0L), "Unsupported floating point precision.");
152 static constexpr T value = (T)1.570796326794896619231321691639751442L;
153 constexpr T operator()() const
154 {
155 return value;
156 }
157 constexpr operator T() const
158 {
159 return value;
160 }
161 };
162
164 template<class T>
165 struct NamedConstant<T, 'P', 'I', '_', '4'>
166 {
167 static_assert(sizeof(T) < sizeof(0.0L), "Unsupported floating point precision.");
168 static constexpr T value = (T)0.785398163397448309615660845819875721L;
169 constexpr T operator()() const
170 {
171 return value;
172 }
173 constexpr operator T() const
174 {
175 return value;
176 }
177 };
178
180 template<class T>
181 struct NamedConstant<T, '1', '_', 'P', 'I'>
182 {
183 static_assert(sizeof(T) < sizeof(0.0L), "Unsupported floating point precision.");
184 static constexpr T value = (T)0.318309886183790671537767526745028724L;
185 constexpr T operator()() const
186 {
187 return value;
188 }
189 constexpr operator T() const
190 {
191 return value;
192 }
193 };
194
196 template<class T>
197 struct NamedConstant<T, '2', '_', 'P', 'I'>
198 {
199 static_assert(sizeof(T) < sizeof(0.0L), "Unsupported floating point precision.");
200 static constexpr T value = (T)0.636619772367581343075535053490057448L;
201 constexpr T operator()() const
202 {
203 return value;
204 }
205 constexpr operator T() const
206 {
207 return value;
208 }
209 };
210
212 template<class T>
213 struct NamedConstant<T, '2', '_', 'S', 'Q', 'R', 'T', 'P', 'I'>
214 {
215 static_assert(sizeof(T) < sizeof(0.0L), "Unsupported floating point precision.");
216 static constexpr T value = (T)1.128379167095512573896158903121545172L;
217 constexpr T operator()() const
218 {
219 return value;
220 }
221 constexpr operator T() const
222 {
223 return value;
224 }
225 };
226
228 template<class T>
229 struct NamedConstant<T, 'S', 'Q', 'R', 'T', '2'>
230 {
231 static_assert(sizeof(T) < sizeof(0.0L), "Unsupported floating point precision.");
232 static constexpr T value = (T)1.414213562373095048801688724209698079L;
233 constexpr T operator()() const
234 {
235 return value;
236 }
237 constexpr operator T() const
238 {
239 return value;
240 }
241 };
242
244 template<class T>
245 struct NamedConstant<T, 'S', 'Q', 'R', 'T', '1', '_', '2'>
246 {
247 static_assert(sizeof(T) < sizeof(0.0L), "Unsupported floating point precision.");
248 static constexpr T value = (T)0.707106781186547524400844362104849039L;
249 constexpr T operator()() const
250 {
251 return value;
252 }
253 constexpr operator T() const
254 {
255 return value;
256 }
257 };
258
259 } // NS TypedValue
260
261 using TypedValue::IsNamedConstant;
262
263 } // NS ACFem
264
265} // NS Dune
266
267#endif // __DUNE_ACFEM_COMMON_NAMED_CONSTANT_HH__
BoolConstant< false > FalseType
Alias for std::false_type.
Definition: types.hh:110
BoolConstant< true > TrueType
Alias for std::true_type.
Definition: types.hh:107
A named constant wraps a constant of the given type T tagging it with the given character sequence.
Definition: namedconstant.hh:21
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Jun 23, 22:32, 2025)