diff --git a/tardis/model/base.py b/tardis/model/base.py index f4fce247b0a..c5cb5ea3272 100644 --- a/tardis/model/base.py +++ b/tardis/model/base.py @@ -84,6 +84,29 @@ def r_outer(self): return self.geometry.r_outer.values * self.geometry_units["r_outer"] +class Radial1DGeometry: + """ + Holds information about model geometry for radial 1D models. + + Parameters + ---------- + r_inner : astropy.units.quantity.Quantity + r_outer : astropy.units.quantity.Quantity + v_inner : astropy.units.quantity.Quantity + v_outer : astropy.units.quantity.Quantity + """ + + def __init__(self, r_inner, r_outer, v_inner, v_outer): + self.r_inner = r_inner + self.r_outer = r_outer + self.v_inner = v_inner + self.v_outer = v_outer + + @property + def volume(self): + return (4.0 / 3) * np.pi * (self.r_outer**3 - self.r_inner**3) + + class Composition: """ Holds information about model composition diff --git a/tardis/model/tests/test_base.py b/tardis/model/tests/test_base.py index a3483afac3d..e5036de2335 100644 --- a/tardis/model/tests/test_base.py +++ b/tardis/model/tests/test_base.py @@ -5,7 +5,7 @@ from numpy.testing import assert_almost_equal, assert_array_almost_equal from tardis.io.config_reader import Configuration -from tardis.model import Radial1DModel +from tardis.model import Radial1DModel, Radial1DGeometry from tardis.io.decay import IsotopeAbundances from tardis.model.base import Composition from tardis.simulation.base import Simulation @@ -381,6 +381,26 @@ def test_density(self): ) +@pytest.mark.parametrize( + ("index", "expected"), + [ + (0, 1.00977478e45), + (10, 1.98154804e45), + (19, 3.13361319e45), + ], +) +def test_radial_1D_geometry_volume(simulation_verysimple, index, expected): + sim = simulation_verysimple + model = sim.model + geometry = Radial1DGeometry( + model.r_inner, model.r_outer, model.v_inner, model.v_outer + ) + volume = geometry.volume + + assert volume.unit == u.Unit("cm3") + assert_almost_equal(volume[index].value, expected, decimal=-40) + + @pytest.mark.parametrize( ("index", "expected"), [