/home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/physics/thermodynamics.hh Source File#

DiFfRG: /home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/physics/thermodynamics.hh Source File
DiFfRG
thermodynamics.hh
Go to the documentation of this file.
1#pragma once
2
3// DiFfRG
6
7// standard library
8#include <cmath>
9
10namespace DiFfRG
11{
12
13 // ----------------------------------------------------------------------------------------------------
14 // For convenience, all hyperbolic functions
15 // ----------------------------------------------------------------------------------------------------
16 namespace internal
17 {
18 using Kokkos::cosh, Kokkos::sinh, Kokkos::tanh, Kokkos::exp, Kokkos::expm1;
19 template <typename T> auto KOKKOS_FORCEINLINE_FUNCTION Cosh(const T x) { return cosh(x); }
20 template <typename T> auto KOKKOS_FORCEINLINE_FUNCTION Sinh(const T x) { return sinh(x); }
21 template <typename T> auto KOKKOS_FORCEINLINE_FUNCTION Tanh(const T x) { return tanh(x); }
22 template <typename T> auto KOKKOS_FORCEINLINE_FUNCTION Coth(const T x) { return 1. / tanh(x); }
23 template <typename T> auto KOKKOS_FORCEINLINE_FUNCTION Sech(const T x) { return 1. / cosh(x); }
24 template <typename T> auto KOKKOS_FORCEINLINE_FUNCTION Csch(const T x) { return 1. / sinh(x); }
25 } // namespace internal
26
28
29 // ----------------------------------------------------------------------------------------------------
30 // Finite temperature hyperbolic functions
31 // ----------------------------------------------------------------------------------------------------
32
33 template <typename T1, typename T2>
34 requires(std::is_arithmetic_v<T2>)
35 auto KOKKOS_FORCEINLINE_FUNCTION CothFiniteT(const T1 x, const T2 T)
36 {
37 using R = decltype(Coth(x / (2 * T)));
38 return is_close(T / x, T2(0)) ? (R)(real(x) < 0 ? -1 : 1) : Coth(x / (2 * T));
39 }
40 template <typename T1, typename T2>
41 requires(std::is_arithmetic_v<T2>)
42 auto KOKKOS_FORCEINLINE_FUNCTION TanhFiniteT(const T1 x, const T2 T)
43 {
44 using R = decltype(Tanh(x / (2 * T)));
45 return is_close(T / x, T2(0)) ? (R)(real(x) < 0 ? -1 : 1) : Tanh(x / (2 * T));
46 }
47 template <typename T1, typename T2>
48 requires(std::is_arithmetic_v<T2>)
49 auto KOKKOS_FORCEINLINE_FUNCTION SechFiniteT(const T1 x, const T2 T)
50 {
51 using R = decltype(Cosh(x / (2 * T)));
52 const auto res = Cosh(x / (2 * T));
53 return !isfinite(res) ? (R)0 : (R)(1) / res;
54 }
55 template <typename T1, typename T2>
56 requires(std::is_arithmetic_v<T2>)
57 auto KOKKOS_FORCEINLINE_FUNCTION CschFiniteT(const T1 x, const T2 T)
58 {
59 using R = decltype(Sinh(x / (2 * T)));
60 const auto res = Sinh(x / (2 * T));
61 return !isfinite(res) ? (R)0 : (R)(1) / res;
62 }
63
64 // ----------------------------------------------------------------------------------------------------
65 // Thermodynamic hyperbolic functions
66 // ----------------------------------------------------------------------------------------------------
67 // coth(e/2T)
68 template <typename T1, typename T2> auto KOKKOS_FORCEINLINE_FUNCTION cothS(const T1 e, const T2 T)
69 {
70 return Coth(e / (T * 2.));
71 }
72 // d/de cothS
73 template <typename T1, typename T2> auto KOKKOS_FORCEINLINE_FUNCTION dcothS(const T1 e, const T2 T)
74 {
75 return -1. / powr<2>(Sinh(e / (T * 2.))) / (2. * T);
76 }
77 // d^2/de^2 cothS
78 template <typename T1, typename T2> auto KOKKOS_FORCEINLINE_FUNCTION ddcothS(const T1 e, const T2 T)
79 {
80 return -dcothS(e, T) * cothS(e, T) / T;
81 }
82 // d^3/de^3 cothS
83 template <typename T1, typename T2> auto KOKKOS_FORCEINLINE_FUNCTION dddcothS(const T1 e, const T2 T)
84 {
85 return -(ddcothS(e, T) * cothS(e, T) + powr<2>(dcothS(e, T)));
86 }
87 // tanh(e/2T)
88 template <typename T1, typename T2> auto KOKKOS_FORCEINLINE_FUNCTION tanhS(const T1 e, const T2 T)
89 {
90 return Tanh(e / (T * 2.));
91 }
92 // d/de tanhS
93 template <typename T1, typename T2> auto KOKKOS_FORCEINLINE_FUNCTION dtanhS(const T1 e, const T2 T)
94 {
95 return 1. / powr<2>(Cosh(e / (T * 2.))) / (2. * T);
96 }
97 // d^2/de^2 tanhS
98 template <typename T1, typename T2> auto KOKKOS_FORCEINLINE_FUNCTION ddtanhS(const T1 e, const T2 T)
99 {
100 return -dtanhS(e, T) * tanhS(e, T) / T;
101 }
102 // sech(e/2T)
103 template <typename T1, typename T2> auto KOKKOS_FORCEINLINE_FUNCTION sechS(const T1 e, const T2 T)
104 {
105 return 1. / Cosh(e / (T * 2.));
106 }
107 // csch(e/2T)
108 template <typename T1, typename T2> auto KOKKOS_FORCEINLINE_FUNCTION cschS(const T1 e, const T2 T)
109 {
110 return 1. / Sinh(e / (T * 2.));
111 }
112
113 // ----------------------------------------------------------------------------------------------------
114 // Distribution Functions nB, nF and their Derivatives
115 // ----------------------------------------------------------------------------------------------------
116 // Bosonic distribution
117 template <typename T1, typename T2> auto KOKKOS_FORCEINLINE_FUNCTION nB(const T1 e, const T2 T)
118 {
119 using Kokkos::cosh, Kokkos::sinh, Kokkos::tanh, Kokkos::exp, Kokkos::expm1;
120 return 1. / expm1(e / T);
121 }
122 // Derivative d/de of the bosonic distribution
123 template <typename T1, typename T2> auto KOKKOS_FORCEINLINE_FUNCTION dnB(const T1 e, const T2 T)
124 {
125 using Kokkos::cosh, Kokkos::sinh, Kokkos::tanh, Kokkos::exp, Kokkos::expm1;
126 return -exp(e / T) / powr<2>(expm1(e / T)) / T;
127 }
128 // Derivative d²/de² of the bosonic distribution
129 template <typename T1, typename T2> auto KOKKOS_FORCEINLINE_FUNCTION ddnB(const T1 e, const T2 T)
130 {
131 using Kokkos::cosh, Kokkos::sinh, Kokkos::tanh, Kokkos::exp, Kokkos::expm1;
132 return exp(e / T) * (1. + exp(e / T)) / powr<3>(expm1(e / T)) / powr<2>(T);
133 }
134 // Fermionic distribution
135 template <typename T1, typename T2> auto KOKKOS_FORCEINLINE_FUNCTION nF(const T1 e, const T2 T)
136 {
137 using Kokkos::cosh, Kokkos::sinh, Kokkos::tanh, Kokkos::exp, Kokkos::expm1;
138 return 1. / (exp(e / T) + 1.);
139 }
140 // Derivative d/de of the fermionic distribution
141 template <typename T1, typename T2> auto KOKKOS_FORCEINLINE_FUNCTION dnF(const T1 e, const T2 T)
142 {
143 using Kokkos::cosh, Kokkos::sinh, Kokkos::tanh, Kokkos::exp, Kokkos::expm1;
144 return -exp(e / T) / powr<2>(exp(e / T) + 1.) / T;
145 }
146} // namespace DiFfRG
auto KOKKOS_FORCEINLINE_FUNCTION Sech(const T x)
Definition thermodynamics.hh:23
auto KOKKOS_FORCEINLINE_FUNCTION Coth(const T x)
Definition thermodynamics.hh:22
auto KOKKOS_FORCEINLINE_FUNCTION Cosh(const T x)
Definition thermodynamics.hh:19
auto KOKKOS_FORCEINLINE_FUNCTION Csch(const T x)
Definition thermodynamics.hh:24
auto KOKKOS_FORCEINLINE_FUNCTION Sinh(const T x)
Definition thermodynamics.hh:20
auto KOKKOS_FORCEINLINE_FUNCTION Tanh(const T x)
Definition thermodynamics.hh:21
Definition complex_math.hh:10
auto KOKKOS_FORCEINLINE_FUNCTION SechFiniteT(const T1 x, const T2 T)
Definition thermodynamics.hh:49
auto KOKKOS_FORCEINLINE_FUNCTION ddnB(const T1 e, const T2 T)
Definition thermodynamics.hh:129
auto KOKKOS_FORCEINLINE_FUNCTION CschFiniteT(const T1 x, const T2 T)
Definition thermodynamics.hh:57
auto KOKKOS_FORCEINLINE_FUNCTION CothFiniteT(const T1 x, const T2 T)
Definition thermodynamics.hh:35
auto KOKKOS_FORCEINLINE_FUNCTION sechS(const T1 e, const T2 T)
Definition thermodynamics.hh:103
auto KOKKOS_FORCEINLINE_FUNCTION dnF(const T1 e, const T2 T)
Definition thermodynamics.hh:141
auto KOKKOS_FORCEINLINE_FUNCTION cothS(const T1 e, const T2 T)
Definition thermodynamics.hh:68
bool KOKKOS_INLINE_FUNCTION is_close(T1 a, T2 b, T3 eps_)
Function to evaluate whether two floats are equal to numerical precision. Tests for both relative and...
Definition math.hh:168
auto KOKKOS_FORCEINLINE_FUNCTION nB(const T1 e, const T2 T)
Definition thermodynamics.hh:117
auto KOKKOS_FORCEINLINE_FUNCTION dtanhS(const T1 e, const T2 T)
Definition thermodynamics.hh:93
constexpr KOKKOS_INLINE_FUNCTION NumberType powr(const NumberType x)
A compile-time evaluatable power function for whole number exponents.
Definition math.hh:41
auto KOKKOS_FORCEINLINE_FUNCTION tanhS(const T1 e, const T2 T)
Definition thermodynamics.hh:88
auto KOKKOS_FORCEINLINE_FUNCTION nF(const T1 e, const T2 T)
Definition thermodynamics.hh:135
auto KOKKOS_FORCEINLINE_FUNCTION TanhFiniteT(const T1 x, const T2 T)
Definition thermodynamics.hh:42
auto KOKKOS_FORCEINLINE_FUNCTION ddcothS(const T1 e, const T2 T)
Definition thermodynamics.hh:78
auto KOKKOS_FORCEINLINE_FUNCTION dnB(const T1 e, const T2 T)
Definition thermodynamics.hh:123
auto KOKKOS_FORCEINLINE_FUNCTION cschS(const T1 e, const T2 T)
Definition thermodynamics.hh:108
KOKKOS_FORCEINLINE_FUNCTION auto real(const autodiff::Real< N, T > &a)
Definition complex_math.hh:96
auto KOKKOS_FORCEINLINE_FUNCTION ddtanhS(const T1 e, const T2 T)
Definition thermodynamics.hh:98
auto KOKKOS_FORCEINLINE_FUNCTION dddcothS(const T1 e, const T2 T)
Definition thermodynamics.hh:83
bool isfinite(const autodiff::Real< N, T > &x)
Finite-ness check for autodiff::real.
Definition math.hh:22
auto KOKKOS_FORCEINLINE_FUNCTION dcothS(const T1 e, const T2 T)
Definition thermodynamics.hh:73