SPH
Generic.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include "math/MathUtils.h"
10 
12 
14 template <typename T>
15 INLINE Float norm(const T& value) {
16  return Sph::abs(value);
17 }
18 
20 template <typename T>
21 INLINE Float normSqr(const T& value) {
22  return sqr(value);
23 }
24 
28 template <typename T>
29 INLINE Float maxElement(const T& value) {
30  return value;
31 }
32 
36 template <typename T>
37 INLINE Float minElement(const T& value) {
38  return value;
39 }
40 
42 template <typename T>
43 INLINE bool isReal(const T& value) {
44  return !std::isnan(value) && !std::isinf(value);
45 }
46 
52 template <typename T>
53 INLINE constexpr auto less(const T& v1, const T& v2) {
54  return v1 < v2 ? T(1) : T(0);
55 }
56 
58 template <typename T>
60  // for floats and indices, return the value itself.
61  return { (Float)value };
62 }
63 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
constexpr INLINE auto less(const T &v1, const T &v2)
Compares two objects of the same time component-wise.
Definition: Generic.h:53
INLINE Float minElement(const T &value)
Returns minimum element, simply the value iself by default.
Definition: Generic.h:37
INLINE Float normSqr(const T &value)
Squared value of the norm.
Definition: Generic.h:21
NAMESPACE_SPH_BEGIN INLINE Float norm(const T &value)
Returns a norm, absolute value by default.
Definition: Generic.h:15
INLINE StaticArray< Float, 6 > getComponents(const T &value)
Returns the components of the object in array.
Definition: Generic.h:59
INLINE bool isReal(const T &value)
Checks for nans and infs.
Definition: Generic.h:43
INLINE Float maxElement(const T &value)
Returns maximum element, simply the value iself by default.
Definition: Generic.h:29
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Definition: Globals.h:13
Additional math routines (with more includes).
constexpr INLINE T sqr(const T &f) noexcept
Return a squared value.
Definition: MathUtils.h:67
INLINE auto abs(const T &f)
Definition: MathUtils.h:276
#define INLINE
Macros for conditional compilation based on selected compiler.
Definition: Object.h:31
#define NAMESPACE_SPH_END
Definition: Object.h:12
Array with fixed number of allocated elements.
Definition: StaticArray.h:19