VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
UbEqual.h
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
33//=======================================================================================
34#ifndef UBEQUAL_H
35#define UBEQUAL_H
36
37#include <cmath>
38
40//
53//
55
56// std-trait, fuer alle nicht spezifischen typen:
57template <typename T1, typename T2>
59 using High = T1;
60 using Low = T1;
61};
62
63// std-trait, fuer gleiche T
64template <typename T>
65struct UbEqualTrait<T, T> {
66 using High = T;
67 using Low = T;
68};
69
70// spezialisierung fuer diverse Typen-Tuples
71template <>
73 using High = int;
74 using Low = short;
75};
76template <>
78 using High = long;
79 using Low = short;
80};
81template <>
83 using High = float;
84 using Low = short;
85};
86template <>
88 using High = double;
89 using Low = short;
90};
91template <>
93 using High = long double;
94 using Low = short;
95};
96
97template <>
99 using High = int;
100 using Low = short;
101};
102template <>
104 using High = long;
105 using Low = int;
106};
107template <>
109 using High = float;
110 using Low = int;
111};
112template <>
114 using High = double;
115 using Low = int;
116};
117template <>
119 using High = long double;
120 using Low = int;
121};
122
123template <>
125 using High = long;
126 using Low = short;
127};
128template <>
130 using High = long;
131 using Low = int;
132};
133template <>
135 using High = float;
136 using Low = long;
137};
138template <>
140 using High = double;
141 using Low = long;
142};
143template <>
145 using High = long double;
146 using Low = long;
147};
148
149template <>
151 using High = float;
152 using Low = short;
153};
154template <>
156 using High = float;
157 using Low = int;
158};
159template <>
161 using High = float;
162 using Low = long;
163};
164template <>
166 using High = double;
167 using Low = float;
168};
169template <>
171 using High = long double;
172 using Low = float;
173};
174
175template <>
177 using High = double;
178 using Low = short;
179};
180template <>
182 using High = double;
183 using Low = int;
184};
185template <>
187 using High = double;
188 using Low = long;
189};
190template <>
192 using High = double;
193 using Low = float;
194};
195template <>
197 using High = long double;
198 using Low = double;
199};
200
201template <>
203 using High = long double;
204 using Low = short;
205};
206template <>
208 using High = long double;
209 using Low = int;
210};
211template <>
213 using High = long double;
214 using Low = long;
215};
216template <>
218 using High = long double;
219 using Low = float;
220};
221template <>
223 using High = long double;
224 using Low = double;
225};
226
228// fuer Allgmeine-Typen ( operator== ):
229template <typename T1, typename T2>
230inline bool specific_equal(const T1 &a, const T2 &b)
231{
232 return a == b;
233}
234
236// fuer floating point build-in-type
237// float.float
238template </*float,float*/>
239inline bool specific_equal<float, float>(const float &a, const float &b)
240{
241 return std::fabs(a - b) < 1E-8;
242}
243
244template </*double,double*/>
245inline bool specific_equal<double, double>(const double &a, const double &b)
246{
247 return std::fabs(a - b) < 1E-13;
248}
249
250template </*long double,long double*/>
251inline bool specific_equal<long double, long double>(const long double &a, const long double &b)
252{
253 return std::fabs(a - b) < 1E-16;
254}
255
257// globale isUbEqual - Funktion
258template <typename T1, typename T2>
259inline bool isUbEqual(const T1 &a, const T2 &b)
260{
261 using Low = typename UbEqualTrait<T1, T2>::Low;
262 return specific_equal<Low, Low>(static_cast<Low>(a), static_cast<Low>(b));
263}
264
266// UbEqual-Functor
267template <typename T1, typename T2>
268struct UbEqual {
269 bool operator()(const T1 &a, const T2 &b) { return isUbEqual(a, b); }
270};
271
272#endif // UBEQUAL_H
273
std::shared_ptr< T > SPtr
bool specific_equal(const T1 &a, const T2 &b)
Definition UbEqual.h:230
bool specific_equal< long double, long double >(const long double &a, const long double &b)
Definition UbEqual.h:251
bool specific_equal< double, double >(const double &a, const double &b)
Definition UbEqual.h:245
bool specific_equal< float, float >(const float &a, const float &b)
Definition UbEqual.h:239
bool isUbEqual(const T1 &a, const T2 &b)
Definition UbEqual.h:259
bool operator()(const T1 &a, const T2 &b)
Definition UbEqual.h:269
isUbEqual<T1,T2>(a,b) Compares the equality of values a and b.
Definition UbEqual.h:58