Skip to content

Commit bf6370f

Browse files
author
Wolfgang Kastaun
committed
Release version 1.5
-Various fixes of 1.5beta -Improved docstrings of Python interface -Improved HTML documentation -Spline EOS creation does not need pseudo-enthalpy anymore, can be computed via numerical integration. Similarly, specific energy is not required for creating isentropic spline EOS. -EOS interface offers description string for logging etc -Tabulated EOS (linear interpolation EOS) is now deprecated in favour of new spline EOS. Loading (and direct creation) still supported for reproducability, but there is no saving functionality. -Added some more example EOS files for testing
1 parent f1cf4d9 commit bf6370f

38 files changed

+1435
-188
lines changed
40 KB
Binary file not shown.

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ The full documentation can be found [here](https://wokast.github.io/RePrimAnd/in
1010

1111
The main target and devolpment platform is Linux, although the
1212
library code is not platform-specific and should also work on Macs.
13-
Windows and AIX are not supported. Binary packages are currently not available, but a conda
14-
package is planned.
13+
Windows and AIX are not supported. For use in HPC, users need to build
14+
the library from source. For use in postprocessing, the Python intferface
15+
can also be installed via pip (binary wheel of the library available for
16+
Linux). Conda packages for the C++ library and Python intface are planned
17+
but not available yet.
1518

1619
## Requirements
1720

@@ -192,7 +195,7 @@ This requires Python+matplotlib.
192195
### Visualizing Master Function
193196

194197
In addition, there is code to sample the primitive recovery master
195-
function (the central ingredient of the scheme) for various cases,
198+
function (the central ingredient of the con2prim scheme) for various cases,
196199
as shown in the paper.
197200

198201
```bash

bindings/python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
55

66
[project]
77
name = "RePrimAnd"
8-
version = "1.5beta"
8+
version = "1.5"
99
authors = [
1010
{ name = "Wolfgang Kastaun", email = "physik@fangwolg.de" }
1111
]

bindings/python/pyreprimand.cpp

Lines changed: 573 additions & 57 deletions
Large diffs are not rendered by default.

docker/cibw_prepare.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ INST_DIR=/usr
1212

1313
mkdir -p $BUILD_DIR
1414
cd /project
15-
meson setup --prefix=$INST_DIR -Dbuild_python_api=false -Dbuild_tests=false -Dbuild_benchmarks=false -Dbuild_documentation=false $BUILD_DIR
15+
meson setup --prefix=$INST_DIR -Dbuild_tests=false -Dbuild_benchmarks=false -Dbuild_documentation=false $BUILD_DIR
1616
cd $BUILD_DIR
1717
ninja
1818
ninja install

docsrc/sphinx/eos_barotr_available.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ In terms of the pseudo-enthalpy, the segments are given by
113113
.. warning::
114114
The intended use case for this EOS contains just few (<10) segments.
115115
It would be very inefficient to approximate arbitrary EOS using
116-
hundreds of segments. For this, use the tabulated EOS below.
116+
hundreds of segments. For this, use the spline EOS below.
117117

118118

119119

@@ -127,8 +127,9 @@ interpolation. The EOS is therefore differentiable in principle.
127127
Of course, there can still be steep gradients.
128128

129129
Internally, most properties are represented in terms of the
130-
pseudo enthalpy. This has the advantage of avoiding jumps at phase
131-
transitions. Only the density has a jump.
130+
pseudo enthalpy. This has some advantages for computing hydrostatic
131+
equilibrium models and also with regard to phase
132+
transitions (although the density has a jump at those).
132133
When calling the EOS using density as independent variable, another
133134
interpolation spline is used to first compute the pseudo enthalpy
134135
(in presence of phase transitions, it has a plateau as function of

docsrc/sphinx/eos_barotr_ref.rst

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,73 @@ Reference
22
---------
33

44

5-
Generic Interface
6-
^^^^^^^^^^^^^^^^^
7-
.. doxygenclass:: EOS_Toolkit::eos_barotr
8-
:project: RePrimAnd
9-
:members:
10-
115
Loading from File
126
^^^^^^^^^^^^^^^^^
137

148
.. doxygenfunction:: EOS_Toolkit::load_eos_barotr
159
:project: RePrimAnd
1610

1711

18-
Creating Specific EOS
19-
^^^^^^^^^^^^^^^^^^^^^
12+
Creating EOS from sampled data
13+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
To create a EOS based on spline interpolation from given sample points,
15+
there are three options.
16+
Depending on whether the pseudo-enthalpy and/or specific energy are
17+
known accurately, one should use one of the following.
18+
19+
.. doxygenfunction:: EOS_Toolkit::make_eos_barotr_spline(const std::vector<real_t>& gm1, const std::vector<real_t>& rho, const std::vector<real_t>& eps, const std::vector<real_t>& press, const std::vector<real_t>& csnd, const std::vector<real_t>& temp, const std::vector<real_t>& efrac, bool isentropic, interval<real_t> rg_rho, real_t n_poly, units u, std::size_t pts_per_mag)
20+
:project: RePrimAnd
21+
22+
|
23+
24+
.. doxygenfunction:: EOS_Toolkit::make_eos_barotr_spline(const std::vector<real_t>& rho, const std::vector<real_t>& eps, const std::vector<real_t>& press, const std::vector<real_t>& csnd, const std::vector<real_t>& temp, const std::vector<real_t>& efrac, bool isentropic, interval<real_t> rg_rho, real_t n_poly, units u, std::size_t pts_per_mag)
25+
:project: RePrimAnd
26+
27+
|
2028
21-
.. doxygenfunction:: EOS_Toolkit::make_eos_barotr_spline(const std::vector<real_t>& gm1, const std::vector<real_t>& rho, const std::vector<real_t>& eps, const std::vector<real_t>& press, const std::vector<real_t>& csnd, const std::vector<real_t>& temp, const std::vector<real_t>& efrac, bool isentropic_, interval<real_t> rg_rho, real_t n_poly_, units units_, std::size_t pts_per_mag)
29+
.. doxygenfunction:: EOS_Toolkit::make_eos_barotr_spline(const std::vector<real_t>& rho, const std::vector<real_t>& press, const std::vector<real_t>& csnd, const std::vector<real_t>& temp, const std::vector<real_t>& efrac, interval<real_t> rg_rho, real_t n_poly, real_t eps0, units u, std::size_t pts_per_mag)
2230
:project: RePrimAnd
2331

2432
|
2533
34+
It is also possible to sample an existing EOS:
35+
2636
.. doxygenfunction:: EOS_Toolkit::make_eos_barotr_spline(const eos_barotr& eos, interval<real_t> rg_rho, real_t n_poly, std::size_t pts_per_mag=200)
2737
:project: RePrimAnd
2838

2939
|
3040
41+
Creating Polytropic EOS
42+
^^^^^^^^^^^^^^^^^^^^^^^
43+
3144
.. doxygenfunction:: EOS_Toolkit::make_eos_barotr_poly
3245
:project: RePrimAnd
3346

3447
|
3548
49+
Creating Piecewise Polytropic EOS
50+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
51+
3652
.. doxygenfunction:: EOS_Toolkit::make_eos_barotr_pwpoly
3753
:project: RePrimAnd
3854

39-
|
4055

4156

57+
Generic Interface
58+
^^^^^^^^^^^^^^^^^
59+
.. doxygenclass:: EOS_Toolkit::eos_barotr
60+
:project: RePrimAnd
61+
:members:|
62+
63+
64+
Deprecated EOS
65+
^^^^^^^^^^^^^^
66+
67+
In older versions, there was no spline based EOS. Instead
68+
there was eos_barotr_table based on linear interpolation. This type
69+
can still be used for sake of reproducing old results, but for new
70+
EOS its use is discouraged.
71+
4272
.. deprecated:: 1.5
4373
Use make_eos_barotr_spline instead make_eos_barotr_table
4474

docsrc/sphinx/installing.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ Installation
33

44
The main target and devolpment platform is Linux, although the
55
library code is not platform-specific and should also work on Macs.
6-
Windows and AIX are not supported. Binary packages are currently not available, but a conda
7-
package is planned.
6+
Windows and AIX are not supported. For use in HPC, users need to build
7+
the library from source. For use in postprocessing, the Python intferface
8+
can also be installed via pip (binary wheel of the library available for
9+
Linux). Conda packages for the C++ library and Python intface are planned
10+
but not available yet.
811

912
Requirements
1013
------------
@@ -84,7 +87,7 @@ it is easiest to install from pypi
8487

8588
.. code::
8689
87-
pip install reprimand
90+
pip install pyreprimand
8891
8992
9093
Otherwise, one first has to buid and install the C++ library as shown above.

docsrc/sphinx/python_interf.rst

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ valid range.
4242
import pyreprimand as pyr
4343
import numpy as np
4444
45-
u = pyr.units.geom_solar
45+
u = pyr.units.geom_solar()
4646
eos = pyr.load_eos_barotr("EOS/MS1_PP.eos.h5", units=u)
4747
4848
rho = np.linspace(eos.range_rho.min, eos.range_rho.max, 1000)
@@ -52,15 +52,15 @@ Creating EOS Files
5252
^^^^^^^^^^^^^^^^^^
5353

5454
One prime use for the Python interface is the creation of EOS files based on
55-
data from other sources. Polytropic, piecewise polytropic, and tabulated EOS
56-
are supported directly. Other EOS types can be represented by first sampling
57-
them.
55+
data from other sources. Polytropic, piecewise polytropic, and spline-based
56+
EOS for tabulated data are supported directly. Other EOS types can be represented
57+
by first sampling them.
5858

5959
Creating a piecewise polytropic EOS file is as simple as
6060

6161
.. code-block:: python
6262
63-
u = pyr.units.geom_solar
63+
u = pyr.units.geom_solar()
6464
6565
eos = pyr.make_eos_barotr_pwpoly(rho_poly,
6666
rho_bounds, gammas, rho_max, uc)
@@ -78,15 +78,15 @@ EOS as follows
7878

7979
.. code-block:: python
8080
81-
u = pyr.units.geom_solar
81+
u = pyr.units.geom_solar()
8282
83-
eos = pyr.make_eos_barotr_spline(gm1, rho, eps, press, csnd,
83+
eos = pyr.make_eos_barotr_spline(rho, eps, press, csnd,
8484
temp, efrac, is_isentropic, range_rho, n_poly,
8585
eos_units, pts_per_mag)
8686
8787
pyr.save_eos_barotr("example_spline.eos.h5", eos)
8888
89-
where `gm1`, `rho`, `eps`, `press`, `csnd`, `temp`, and `efrac` are numpy
89+
where `rho`, `eps`, `press`, `csnd`, `temp`, and `efrac` are numpy
9090
arrays with the arbitrarily-spaced tabulated sample points. If temperature
9191
and/or electron fraction are not available, pass an empty list instead.
9292
Any dimensionful arguments have to be specified in the unit system desired
@@ -123,10 +123,8 @@ Methods related to stellar profiles, such as
123123
:cpp:func:`~EOS_Toolkit::spherical_star::press_from_rc`
124124
are vectorized and accept a numpy array as argument for the radius.
125125
Note that computing TOV solutions is not vectorized, so passing a numpy array as central density
126-
will not work. Future versions may contain dedicated functions for TOV sequences.
126+
will not work. See below for working with TOV sequences.
127127

128-
An example Python script plotting TOV sequences can be found under
129-
`examples/pwpoly_TOV.py`.
130128

131129
NS Sequences
132130
^^^^^^^^^^^^
@@ -143,6 +141,9 @@ branches) are vectorized, i.e., they accept `numpy` arrays. If the input is outs
143141
the valid range, the result is NAN. The same holds for :cpp:class:`~EOS_Toolkit::star_seq`
144142
objects representing a general NS sequence.
145143

144+
An example Python script plotting TOV sequences can be found under
145+
`examples/pwpoly_TOV.py`.
146+
146147
Units
147148
^^^^^
148149

@@ -151,7 +152,10 @@ objects, which are used throughout the interface to specify unit systems
151152
in a unified consistent way. The unit objects should also be very
152153
useful on their own, for example in quick interactive calculations.
153154
The very popular system defined by :math:`G=c=M_\odot=1` is predefined as
154-
`pyr.units.geom_solar` and provides units as data members such as
155+
`pyr.units.geom_solar()`. Note this is a function; when setting up
156+
geometric units, the default values for :math:`G` and/or :math:`M_\odot`
157+
can be overridden by parameters msun_si, g_si.
158+
Unit objects provide specific units via data members such as
155159
`u.density` (try Tab-completion for the complete list!).
156160
Note that temperatures in the EOS framework are always in `MeV` and the unit
157-
conversion objects do not define a temperature unit.
161+
conversion objects do not define a temperature unit.

example/pwpoly_TOV.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,38 @@
99
matplotlib.use("AGG")
1010
from matplotlib import pyplot as plt
1111

12-
def get_seq(eos, rho_min, rho_max,
13-
nsamp=400, acc_tov=1.e-6, acc_def=1.e-3, acc_mres=500):
12+
13+
14+
def get_seq(eos, mgmin=0.5, acc_tov=1.e-6, acc_def=1.e-3,
15+
acc_mres=500, seq_res=500):
16+
"""Compute stable TOV branch
1417
"""
15-
Compute mass, radius, and tidal deformability for a sequence
16-
of TOV solution with given EOS and within given range of central
17-
density.
18-
"""
19-
rho_max = min(rho_max, eos.range_rho.max*0.99999)
20-
21-
rhoc = np.exp(np.linspace(np.log(rho_min), np.log(rho_max), nsamp))
22-
23-
accs = pyr.tov_acc_simple(acc_tov, acc_def, acc_mres)
24-
25-
@np.vectorize
26-
def props(rho_cent):
27-
tov = pyr.get_tov_star_properties(eos, rho_cent, accs)
28-
return (tov.grav_mass, tov.circ_radius,
29-
tov.deformability.lambda_tidal)
30-
31-
return props(rhoc)
3218

19+
acc = pyr.tov_acc_simple(acc_tov, acc_def, acc_mres)
3320

21+
return pyr.make_tov_branch_stable(eos, acc, mgrav_min=mgmin,
22+
num_samp=seq_res)
23+
#
24+
3425
def plot_seqs(seqs):
3526
"""
3627
Plot mass-radius and compactness-deformability diagrams for
3728
a list of TOV sequences.
3829
"""
39-
u = pyr.units.geom_solar
4030

4131
fig,(ax1,ax2) = plt.subplots(2,1)
4232
cm = plt.get_cmap("viridis")
43-
for oga,mg,rc,lt in seqs:
33+
for oga,seq in seqs:
4434
clr = cm(oga)
35+
36+
u = seq.units_to_SI
37+
rggm1 = seq.range_center_gm1
38+
gm1 = np.linspace(rggm1.min, rggm1.max, 800)
39+
40+
mg = seq.grav_mass_from_center_gm1(gm1)
41+
rc = seq.circ_radius_from_center_gm1(gm1)
42+
lt = seq.lambda_tidal_from_center_gm1(gm1)
43+
4544
c = mg/rc
4645
ax2.semilogy(c, lt, ls='-', color=clr)
4746
ax2.set_xlabel(r"$M/R$")
@@ -60,7 +59,7 @@ def main():
6059
of the segment's adiabatic exponent. Compute TOV sequence
6160
for each EOS, plot them, save plot in current directory.
6261
"""
63-
u = pyr.units.geom_solar
62+
u = pyr.units.geom_solar()
6463

6564
seg_bounds_si = [0.0, 2.44034e+10, 3.78358e+14, 2.6278e+15,
6665
9.417030181375906e+16, 5.011872336272714e+17,
@@ -77,16 +76,16 @@ def main():
7776
rho_max = rho_max_si / u.density
7877
rho_min = rho_min_si / u.density
7978

80-
81-
seqs = []
82-
for oga in np.linspace(0, 1, 10):
79+
80+
def mkeos(oga):
8381
ga = 2.9 + (oga-0.5)*0.5
8482
gammas = seg_gammas[:4] + [ga] + seg_gammas[5:]
85-
eos = pyr.make_eos_barotr_pwpoly(rho_poly, seg_bounds, gammas,
86-
rho_max*2)
83+
return pyr.make_eos_barotr_pwpoly(rho_poly, seg_bounds, gammas,
84+
rho_max*2)
85+
#
8786

88-
seq = get_seq(eos, rho_min, rho_max)
89-
seqs.append([oga]+list(seq))
87+
seqs = [( oga, get_seq(mkeos(oga)) )
88+
for oga in np.linspace(0, 1, 10)]
9089

9190
plot_seqs(seqs)
9291

0 commit comments

Comments
 (0)