Commit 30790af3 authored by Alain O' Miniussi's avatar Alain O' Miniussi
Browse files

move all fundamentals to constexpr

parent c6dba421
......@@ -27,40 +27,78 @@
#include "precision.hpp"
namespace fargOCA {
real constexpr PI = 3.14159265358979323844;
//real const PI4 = 4*PI;
real constexpr YEAR = 365.25*24*3600; ///< one year in s
real constexpr RSUN = 6.96e+10; ///< Sun radius in cm
real constexpr XMH = 1.67e-24; ///< Hydrogen mass
real constexpr BOLTZ = 1.38e-16; ///< Boltzmann Constant
real constexpr CLIGHT = 2.99792458e+10; ///< Light speed in cm/s
real constexpr GRAVC = 6.67e-08; ///< Gravitation Constant in cm^3 x g^-1 x s^-2
real constexpr RGAS = 8.314e+07; ///< Gas Constant
real constexpr AR = 7.56e-15; ///< Radiation Constant
real constexpr G = 1;
real constexpr MU = 2.3; ///< Mean molecular weight
real constexpr R = 1; ///< Universal Gas Constant in code units
real constexpr XMSTAR = 1; ///< Amount of solar masses
real constexpr XMSOL = 1.989e+33; ///< Solar mass in g
real constexpr AU = 1.496e+13; ///< Astronomical Unit in cm
real constexpr R0 = 5.2*AU; ///< Unit of distance in cm
real constexpr VOL0 = R0*R0*R0; ///< Unit ofe volume in cm^3
real constexpr XM0 = XMSOL*XMSTAR; ///< Initial solar mass in g
namespace details {
real constexpr
cstSqrtImpl(real x, real l, real r) {
real const epsilon = x/1e19;
while ( l <= r ) {
real const mid = (l + r) / 2;
if ( mid * mid > x ) {
r = mid;
} else {
if ( x - mid * mid < epsilon ) {
return mid;
}
l = mid;
}
}
return -1;
}
real constexpr
cstSqrt(real x) {
if ( x > 0 && x < 1 ) {
return 1/cstSqrt(1/x);
} else {
return cstSqrtImpl(x, 0, x);
}
}
real constexpr
cstPow(real r, int e) {
if (e == 1) {
return r;
} else {
real const s = cstPow(r, e/2);
return e%2 == 0 ? s*s : r*s*s;
}
}
}
using details::cstSqrt;
using details::cstPow;
real constexpr PI = 3.14159265358979323844;
real constexpr YEAR = 365.25*24*3600; ///< one year in s
real constexpr RSUN = 6.96e+10; ///< Sun radius in cm
real constexpr XMH = 1.67e-24; ///< Hydrogen mass
real constexpr BOLTZ = 1.38e-16; ///< Boltzmann Constant
real constexpr CLIGHT = 2.99792458e+10; ///< Light speed in cm/s
real constexpr GRAVC = 6.67e-08; ///< Gravitation Constant in cm^3 x g^-1 x s^-2
real constexpr RGAS = 8.314e+07; ///< Gas Constant
real constexpr AR = 7.56e-15; ///< Radiation Constant
real constexpr G = 1;
real constexpr MU = 2.3; ///< Mean molecular weight
real constexpr R = 1; ///< Universal Gas Constant in code units
real constexpr XMSTAR = 1; ///< Amount of solar masses
real constexpr XMSOL = 1.989e+33; ///< Solar mass in g
real constexpr AU = 1.496e+13; ///< Astronomical Unit in cm
real constexpr R0 = 5.2*AU; ///< Unit of distance in cm
real constexpr VOL0 = R0*R0*R0; ///< Unit ofe volume in cm^3
real constexpr XM0 = XMSOL*XMSTAR; ///< Initial solar mass in g
/// Shocks are spread over CVNR zones:
/// von Neumann-Richtmyer viscosity constant
/// Beware of misprint in Stone and Norman's
/// paper : use C2^2 instead of C2
real constexpr CVNR = 1.41;
real constexpr CVNR = 1.41;
real const TIME0 = std::sqrt(VOL0/GRAVC/XM0); // Unit of time in s
real const V0 = R0/TIME0;
real const XNU0 = R0*V0;
real const TEMP0 = V0*V0/RGAS;
real const RHO0 = XM0/VOL0;
real const C0 = CLIGHT/V0;
real const A0 = AR*std::pow(TEMP0,4)/(RHO0*V0*V0);
real const SIGMARAD = A0*C0/4; // Boltzmann constant
real const E0 = XM0*R0*R0/(TIME0*TIME0);
real constexpr TIME0 = cstSqrt(VOL0/GRAVC/XM0); // Unit of time in s
real constexpr V0 = R0/TIME0;
real constexpr XNU0 = R0*V0;
real constexpr TEMP0 = cstPow(V0,2)/RGAS;
real constexpr RHO0 = XM0/VOL0;
real constexpr C0 = CLIGHT/V0;
real constexpr A0 = AR*cstPow(TEMP0,4)/(RHO0*cstPow(V0,2));
real constexpr SIGMARAD = A0*C0/4; // Boltzmann constant
real constexpr E0 = XM0*cstPow(R0,2)/cstPow(TIME0,2);
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment