Skip to content

Commit bef0ba0

Browse files
authored
Merge branch 'main' into features/clang-tidy-fix-3
2 parents 0033f6d + f9423cc commit bef0ba0

4 files changed

Lines changed: 122 additions & 0 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""
2+
Barotropic EOS functions
3+
=======================================
4+
5+
"""
6+
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
10+
import shamrock
11+
12+
cs = 190.0
13+
rho_c1 = 1.92e-13 * 1000 # g/cm^3 -> kg/m^3
14+
rho_c2 = 3.84e-8 * 1000 # g/cm^3 -> kg/m^3
15+
rho_c3 = 1.92e-3 * 1000 # g/cm^3 -> kg/m^3
16+
17+
18+
si = shamrock.UnitSystem()
19+
sicte = shamrock.Constants(si)
20+
kb = sicte.kb()
21+
print(kb)
22+
mu = 2.375
23+
mh = 1.00784 * sicte.dalton()
24+
print(mu * mh * kb)
25+
26+
rho_plot = np.logspace(-15, 5, 1000)
27+
P_plot = []
28+
cs_plot = []
29+
T_plot = []
30+
for rho in rho_plot:
31+
P, _cs, T = shamrock.phys.eos.eos_Machida06(
32+
cs=cs, rho=rho, rho_c1=rho_c1, rho_c2=rho_c2, rho_c3=rho_c3, mu=mu, mh=mh, kb=kb
33+
)
34+
P_plot.append(P)
35+
cs_plot.append(_cs)
36+
T_plot.append(T)
37+
38+
plt.figure()
39+
plt.plot(rho_plot, P_plot, label="P")
40+
plt.yscale("log")
41+
plt.xscale("log")
42+
plt.xlabel("$\\rho$ [kg.m^-3]")
43+
plt.ylabel("$P$ [Pa]")
44+
plt.axvspan(rho_c1, rho_c2, color="grey", alpha=0.5)
45+
plt.axvspan(rho_c3, rho_plot[-1], color="grey", alpha=0.5)
46+
47+
plt.figure()
48+
plt.plot(rho_plot, cs_plot, label="cs")
49+
plt.yscale("log")
50+
plt.xlabel("$\\rho$ [kg.m^-3]")
51+
plt.xscale("log")
52+
plt.ylabel("$c_s$ [m/s]")
53+
plt.axvspan(rho_c1, rho_c2, color="grey", alpha=0.5)
54+
plt.axvspan(rho_c3, rho_plot[-1], color="grey", alpha=0.5)
55+
56+
plt.figure()
57+
plt.plot(rho_plot, T_plot, label="T")
58+
plt.yscale("log")
59+
plt.xscale("log")
60+
plt.xlabel("$\\rho$ [kg.m^-3]")
61+
plt.ylabel("$T$ [K]")
62+
plt.axvspan(rho_c1, rho_c2, color="grey", alpha=0.5)
63+
plt.axvspan(rho_c3, rho_plot[-1], color="grey", alpha=0.5)
64+
65+
66+
plt.tight_layout()
67+
plt.show()

src/shamphys/include/shamphys/eos.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,34 @@ namespace shamphys {
6767
static constexpr T pressure_from_cs(T cs0sq, T rho) { return cs0sq * rho; }
6868
};
6969

70+
template<class T>
71+
struct EOS_Machida06 {
72+
73+
static constexpr T soundspeed(T P, T rho, T rho_c1, T rho_c2, T rho_c3) {
74+
const T gamma = (rho < rho_c1) ? T(1.0)
75+
: (rho < rho_c2) ? T(7.0 / 5.0)
76+
: (rho < rho_c3) ? T(1.1)
77+
: T(5.0 / 3.0);
78+
return sycl::sqrt(gamma * P / rho);
79+
}
80+
81+
static constexpr T temperature(T P, T rho, T mu, T mh, T kb) {
82+
return mu * mh * P / (rho * kb);
83+
}
84+
85+
static constexpr T pressure(T cs, T rho, T rho_c1, T rho_c2, T rho_c3) {
86+
if (rho < rho_c1) {
87+
return cs * cs * rho;
88+
} else if (rho < rho_c2) {
89+
return cs * cs * rho_c1 * sycl::pow(rho / rho_c1, 7. / 5.);
90+
} else if (rho < rho_c3) {
91+
return cs * cs * rho_c1 * sycl::pow(rho_c2 / rho_c1, 7. / 5.)
92+
* sycl::pow(rho / rho_c2, 1.1);
93+
} else {
94+
return cs * cs * rho_c1 * sycl::pow(rho_c2 / rho_c1, 7. / 5.)
95+
* sycl::pow(rho_c3 / rho_c2, 1.1) * sycl::pow(rho / rho_c3, 5. / 3.);
96+
}
97+
}
98+
};
99+
70100
} // namespace shamphys

src/shampylib/src/pyShamphys.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "shamphys/Planets.hpp"
2424
#include "shamphys/SedovTaylor.hpp"
2525
#include "shamphys/SodTube.hpp"
26+
#include "shamphys/eos.hpp"
2627
#include "shamphys/fmm/GreenFuncGravCartesian.hpp"
2728
#include "shamphys/fmm/contract_grav_moment.hpp"
2829
#include "shamphys/fmm/grav_moment_offset.hpp"
@@ -409,4 +410,26 @@ Register_pymod(shamphyslibinit) {
409410
py::arg("dM"),
410411
py::arg("from"),
411412
py::arg("to"));
413+
414+
// EOS
415+
416+
py::module eos_module = shamphys_module.def_submodule("eos");
417+
418+
eos_module.def(
419+
"eos_Machida06",
420+
[](f64 cs, f64 rho, f64 rho_c1, f64 rho_c2, f64 rho_c3, f64 mu, f64 mh, f64 kb) {
421+
auto P = shamphys::EOS_Machida06<f64>::pressure(cs, rho, rho_c1, rho_c2, rho_c3);
422+
auto _cs = shamphys::EOS_Machida06<f64>::soundspeed(P, rho, rho_c1, rho_c2, rho_c3);
423+
auto T = shamphys::EOS_Machida06<f64>::temperature(P, rho, mu, mh, kb);
424+
return std::tuple<f64, f64, f64>{P, _cs, T};
425+
},
426+
py::kw_only(),
427+
py::arg("cs"),
428+
py::arg("rho"),
429+
py::arg("rho_c1"),
430+
py::arg("rho_c2"),
431+
py::arg("rho_c3"),
432+
py::arg("mu"),
433+
py::arg("mh"),
434+
py::arg("kb"));
412435
}

src/shamunits/include/shamunits/Constants.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
X(jupiter_mass /***/, Uget(kg, 1)) \
7171
X(sol_mass /*******/, Uget(kg, 1)) \
7272
X(planck_mass /****/, Uget(kg, 1)) \
73+
X(dalton /*********/, Uget(kg, 1)) \
7374
/* densities */ \
7475
X(guiness_density, Uget(kg, 1) * Uget(m, -1)) \
7576
/* derived ctes */ \
@@ -155,6 +156,7 @@ namespace shamunits {
155156
static constexpr T jupiter_mass = 1.898e27; //(kg)
156157
static constexpr T sol_mass = 1.98847e30; //(kg)
157158
static constexpr T planck_mass = 2.17643424e-8; //(kg)
159+
static constexpr T dalton = 1.66053906892e-27; //(kg)
158160

159161
static constexpr T guiness_density = Conv::gcm3_to_guiness_density * 1000; //(kg.m-3)
160162
};

0 commit comments

Comments
 (0)