63template <
class T,
unsigned DIM>
66 inline constexpr void checkDataType();
69 static constexpr unsigned dim = DIM;
77 inline constexpr ADf();
79 inline constexpr ADf(
const ADf& a);
80 inline constexpr ADf(
const T&
v);
85 inline constexpr T&
v();
86 inline constexpr T&
d(
unsigned i);
87 inline constexpr const T&
d(
unsigned i)
const;
109 inline constexpr operator base_t()
const;
115 static constexpr bool value =
false;
118template<
class S,
unsigned DIM >
127template <
class T,
unsigned DIM>
131template <
class T,
unsigned DIM>
135template <
class T,
unsigned DIM>
139template <
class T,
unsigned DIM>
145template <
class T,
unsigned DIM>
150template <
class T,
unsigned DIM>
153 static_assert(std::is_floating_point<BaseType<T>>::value,
154 "Use floating point types (float, double or long double). Do not use integer types.");
157template <
class T,
unsigned DIM>
165template <
class T,
unsigned DIM>
173template <
class T,
unsigned DIM>
181template <
class T,
unsigned DIM>
189template <
class T,
unsigned DIM>
196template <
class T,
unsigned DIM>
204template <
class T,
unsigned DIM>
211template <
class T,
unsigned DIM>
219template <
class T,
unsigned DIM>
227template <
class T,
unsigned DIM>
236template <
class T,
unsigned DIM>
245template <
class T,
unsigned DIM>
251template <
class T,
unsigned DIM>
257template <
class T,
unsigned DIM>
263template <
class T,
unsigned DIM>
269template <
class T,
unsigned DIM>
276template <
class T,
unsigned DIM>
280 if constexpr (DIM>0) {
287template <
class T,
unsigned DIM>
300template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
306template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
312template <
class T,
unsigned DIM>
318template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
324template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
330template <
class T,
unsigned DIM>
336template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
342template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
348template <
class T,
unsigned DIM>
354template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
360template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
367template <
class T,
unsigned DIM>
374template <
class T,
unsigned DIM>
380template <
class T,
unsigned DIM>
395template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
399 T tmp(c._v*std::log(T(a)));
404template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
408 T tmp(T(b)*std::pow(a.
_v,b-T(1)));
414template <
class T,
unsigned DIM>
423 std::cout <<
"ADf WARNING: pow(Adf) - pow evaluated at non-differentiable point" << std::endl;
425 if (std::isfinite(c._v)) {
426 for (
unsigned i = 0; i < DIM; ++i) {
436template <
class T,
unsigned DIM>
440 T tmp(b*std::pow(a.
_v, b-1));
445template <
class T,
unsigned DIM>
454template <
class T,
unsigned DIM>
462template <
unsigned DIM>
468template <
unsigned DIM>
474template <
class T,
unsigned DIM>
483template <
unsigned DIM>
489template <
unsigned DIM>
495template <
class T,
unsigned DIM>
499 T tmp (T(1)/(a.
_v*std::log(T(10))));
504template <
unsigned DIM>
510template <
unsigned DIM>
516template <
class T,
unsigned DIM>
520 T tmp (T(1)/(a.
_v*std::log(T(2))));
525template <
unsigned DIM>
531template <
unsigned DIM>
537template <
class T,
unsigned DIM>
543template <
unsigned DIM>
549template <
unsigned DIM>
555template <
class T,
unsigned DIM>
559 T tmp(T(1.)/(c._v*T(2)));
560 for (
unsigned i = 0; i < DIM; ++i) {
568template <
class T,
unsigned DIM>
572 T tmp(std::cos(a.
_v));
577template <
class T,
unsigned DIM>
581 T tmp(-std::sin(a.
_v));
586template <
class T,
unsigned DIM>
590 T tmp(T(1)+c._v*c._v);
595template <
class T,
unsigned DIM>
599 T tmp(T(1)/std::sqrt(T(1)-(a.
_v)*(a.
_v)));
604template <
class T,
unsigned DIM>
608 T tmp(-T(1)/std::sqrt(T(1)-(a.
_v)*(a.
_v)));
613template <
class T,
unsigned DIM>
617 T tmp(T(1)/(T(1)+(a.
_v)*(a.
_v)));
622template <
class T,
unsigned DIM>
626 T tmpB(-y / (x.
_v*x.
_v + y*y));
631template <
class T,
unsigned DIM>
635 T tmpA(x / (x*x + y.
_v*y.
_v));
640template <
class T,
unsigned DIM>
646 c._d = tmpA*y.
_d + tmpB*x.
_d;
650template <
class T,
unsigned DIM>
653 return 0.5*(
exp(a)-
exp(-a));
656template <
class T,
unsigned DIM>
659 return 0.5*(
exp(a)+
exp(-a));
662template <
class T,
unsigned DIM>
665 return 1 - 2.0 / (
exp(2*a) + 1);
668template <
class T,
unsigned DIM>
674template <
class T,
unsigned DIM>
682 c._v = std::acosh(a.
_v);
683 c._d = ( std::numeric_limits<T>::quiet_NaN() );
688template <
class T,
unsigned DIM>
691 if (std::abs(a.
_v) < 1) {
692 return 0.5 *
log( (1+a) / (1-a) );
696 c._v = std::atanh(a.
_v);
697 c._d = ( std::numeric_limits<T>::quiet_NaN() );
702template <
class T,
unsigned DIM>
705 const T k = std::floor(T(a) / T(b));
709template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
715template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
730template <
class T,
unsigned DIM>
734 for (
unsigned i=0; i<DIM; i++) {
735 sum += std::fabs(_d[i]);
743template <
class T,
unsigned DIM>
749template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
755template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
761template <
class T,
unsigned DIM>
767template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
773template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
780template <
class T,
unsigned DIM>
786template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
792template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
798template <
class T,
unsigned DIM>
804template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
810template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
817template <
class T,
unsigned DIM>
823template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
829template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
835template <
class T,
unsigned DIM>
841template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
847template <class T, unsigned DIM, typename U, typename std::enable_if<std::is_integral<U>::value | std::is_floating_point<U>::value,
int>::type = 0>
855template <
class T,
unsigned DIM>
859 if (this->hasZeroDerivative() !=
true) {
860 std::cout <<
"ADf WARNING: non-zero derivative in typecast ADf -> Basetype" << std::endl;
861 std::cout << *
this << std::endl;
868template <
class T,
unsigned DIM>
872 if (a.
_v == std::floor(a.
_v)) {
875 std::cout <<
"ADf WARNING: floor(Adf) - floor evaluated at non-differentiable point" << std::endl;
877 for (
unsigned i = 0; i < DIM; ++i) {
878 c._d[i] = (a.
d(i) == 0) ? T(0) : std::numeric_limits<T>::quiet_NaN();
882 c._v = std::floor(a.
_v);
887template <
unsigned DIM>
893template <
unsigned DIM>
899template <
class T,
unsigned DIM>
906 std::cout <<
"ADf WARNING: ceil(Adf) - ceil evaluated at non-differentiable point" << std::endl;
908 for (
unsigned i = 0; i < DIM; ++i) {
909 c._d[i] = (a.
d(i) == 0) ? T(0) : std::numeric_limits<T>::quiet_NaN();
915template <
unsigned DIM>
921template <
unsigned DIM>
927template <
class T,
unsigned DIM>
931 constexpr T EPSILON (std::numeric_limits<T>::epsilon());
932 if (std::round(a.
_v - EPSILON) != std::round(a.
_v + EPSILON)) {
934 std::cout <<
"ADf WARNING: round(Adf) - round evaluated at non-differentiable point" << std::endl;
936 for (
unsigned i = 0; i < DIM; ++i) {
937 c._d[i] = (a.
d(i) == 0) ? T(0) : std::numeric_limits<T>::quiet_NaN();
943template <
unsigned DIM>
949template <
unsigned DIM>
956template <
class T,
unsigned DIM>
960 std::cout <<
"ADf WARNING: ADf does not support integer types. Using round() instead." << std::endl;
965template <
unsigned DIM>
971template <
unsigned DIM>
977template <
class T,
unsigned DIM>
983template <
unsigned DIM>
989template <
unsigned DIM>
995template <
class T,
unsigned DIM>
1000 std::cout <<
"ADf WARNING: fabs(Adf) - fabs evaluated at non-differentiable point" << std::endl;
1006template <
unsigned DIM>
1012template <
unsigned DIM>
1018template <
class T,
unsigned DIM>
1024template <
class T,
unsigned DIM>
1028 std::cout <<
"ADf WARNING: ADf is not supporting integer types. Using abs() instead." << std::endl;
1033template <
class T,
unsigned DIM>
1039template <
class T,
unsigned DIM>
1047template <
class T,
unsigned DIM>
1055template <
class T,
unsigned DIM>
1062template <
class T,
unsigned DIM>
1070template <
class T,
unsigned DIM>
1078template <
class T,
unsigned DIM>
1086template <
class T,
unsigned DIM>
1089 const T EPSILON = std::numeric_limits<T>::epsilon();
1090 if (a.
_v > -EPSILON && a.
_v < EPSILON) {
1098template <
typename T>
1101 static_assert(std::is_floating_point<T>::value,
1102 "The data type ADf has slipped in here. If you really want to use it here and lose all derivation information, then perform an explicit typecast.");
Definition of a description of a algoritmic differentiation data type using the forward method.
static constexpr unsigned dim
constexpr ADf & operator/=(const ADf &a)
constexpr void setDiffVariable(unsigned iD)
constexpr T & d(unsigned i)
Vector< T, DIM > _d
derivatives
constexpr bool hasZeroDerivative() const
tests if ADf has only zero derivatives
constexpr Vector< T, DIM > & d()
constexpr ADf & operator=(const ADf &a)
constexpr ADf & operator-=(const ADf &a)
constexpr ADf & operator*=(const ADf &a)
constexpr ADf & operator+=(const ADf &a)
ADf< T, DIM > labs(const ADf< T, DIM > &a)
cpu::simd::Pack< T > sqrt(cpu::simd::Pack< T > value)
ADf< long double, DIM > fabsl(const ADf< long double, DIM > &a)
ADf< T, DIM > abs(const ADf< T, DIM > &a)
ADf< T, DIM > ceil(const ADf< T, DIM > &a)
ADf< T, DIM > floor(const ADf< T, DIM > &a)
ADf< T, DIM > tan(const ADf< T, DIM > &a)
ADf< T, DIM > fmod(const ADf< T, DIM > &a, const ADf< T, DIM > &b)
cpu::simd::Pack< T > min(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
ADf< T, DIM > atan2(const T &y, const ADf< T, DIM > &x)
ADf< float, DIM > llroundf(const ADf< float, DIM > &a)
ADf< T, DIM > asinh(const ADf< T, DIM > &a)
ADf< long double, DIM > log1pl(const ADf< long double, DIM > &a)
ADf< T, DIM > lround(const ADf< T, DIM > &a)
ADf< float, DIM > log10f(const ADf< float, DIM > &a)
ADf< T, DIM > log(const ADf< T, DIM > &a)
ADf< long double, DIM > expl(const ADf< long double, DIM > &a)
ADf< float, DIM > logf(const ADf< float, DIM > &a)
ADf< long double, DIM > log2l(const ADf< long double, DIM > &a)
std::ostream & operator<<(std::ostream &os, const ADf< T, DIM > &o)
constexpr ADf< T, DIM > operator*(const U &a, const ADf< T, DIM > &b)
ADf< float, DIM > roundf(const ADf< float, DIM > &a)
constexpr bool operator<=(const ADf< T, DIM > &a, const ADf< T, DIM > &b)
constexpr ADf< T, DIM > operator+(const U &a, const ADf< T, DIM > &b)
ADf< T, DIM > round(const ADf< T, DIM > &a)
ADf< float, DIM > log2f(const ADf< float, DIM > &a)
ADf< long double, DIM > log10l(const ADf< long double, DIM > &a)
cpu::simd::Pack< T > max(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
ADf< T, DIM > llround(const ADf< T, DIM > &a)
ADf< float, DIM > floorf(const ADf< float, DIM > &a)
ADf< T, DIM > sin(const ADf< T, DIM > &a)
ADf< float, DIM > expf(const ADf< float, DIM > &a)
ADf< T, DIM > acosh(const ADf< T, DIM > &a)
ADf< long double, DIM > floorl(const ADf< long double, DIM > &a)
constexpr bool operator<(const ADf< T, DIM > &a, const ADf< T, DIM > &b)
ADf< float, DIM > fabsf(const ADf< float, DIM > &a)
constexpr void throwADfException(T arg)
ADf< T, DIM > asin(const ADf< T, DIM > &a)
ADf< T, DIM > log1p(const ADf< T, DIM > &a)
cpu::simd::Pack< T > pow(cpu::simd::Pack< T > base, cpu::simd::Pack< T > exp)
ADf< float, DIM > lroundf(const ADf< float, DIM > &a)
ADf< T, DIM > cosh(const ADf< T, DIM > &a)
ADf< T, DIM > llabs(const ADf< T, DIM > &a)
constexpr bool operator!=(const ADf< T, DIM > &a, const ADf< T, DIM > &b)
ADf< T, DIM > sinh(const ADf< T, DIM > &a)
cpu::simd::Pack< T > fabs(cpu::simd::Pack< T > value)
constexpr ADf< T, DIM > operator/(const U &a, const ADf< T, DIM > &b)
ADf< long double, DIM > lroundl(const ADf< long double, DIM > &a)
ADf< long double, DIM > roundl(const ADf< long double, DIM > &a)
ADf< T, DIM > acos(const ADf< T, DIM > &a)
ADf< long double, DIM > llroundl(const ADf< long double, DIM > &a)
bool nearZero(const ADf< T, DIM > &a)
ADf< long double, DIM > ceill(const ADf< long double, DIM > &a)
ADf< T, DIM > tanh(const ADf< T, DIM > &a)
ADf< float, DIM > log1pf(const ADf< float, DIM > &a)
ADf< T, DIM > log10(const ADf< T, DIM > &a)
constexpr bool operator>(const ADf< T, DIM > &a, const ADf< T, DIM > &b)
std::istream & operator>>(std::istream &is, ADf< T, DIM > &in)
ADf< T, DIM > atan(const ADf< T, DIM > &a)
constexpr bool operator==(const ADf< T, DIM > &a, const ADf< T, DIM > &b)
constexpr bool operator>=(const ADf< T, DIM > &a, const ADf< T, DIM > &b)
ADf< long double, DIM > logl(const ADf< long double, DIM > &a)
ADf< T, DIM > exp(const ADf< T, DIM > &a)
ADf< float, DIM > ceilf(const ADf< float, DIM > &a)
ADf< T, DIM > atanh(const ADf< T, DIM > &a)
constexpr ADf< T, DIM > operator-(const U &a, const ADf< T, DIM > &b)
ADf< T, DIM > log2(const ADf< T, DIM > &a)
ADf< T, DIM > cos(const ADf< T, DIM > &a)
Top level namespace for all of OpenLB.
typename util::BaseTypeHelper< T >::type BaseType
static constexpr bool value
Set of functions commonly used in LB computations – header file.
efficient implementation of a vector class