Skip to content

Commit

Permalink
New geometry class (#2103)
Browse files Browse the repository at this point in the history
* Added 1D geometry class

* added r_inner, r_outer, v_inner, v_outer, volume

* Converting radius and velocity to cgs numpy arrays

* Made docstring more specific

* Removed dataframe and restructure properties

* Removed radius and velocity

* Added test for volume

* Updated docstring

* Fixed formatting
  • Loading branch information
satwik-kambham authored Aug 10, 2022
1 parent d1632db commit 79f2fc3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
23 changes: 23 additions & 0 deletions tardis/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion tardis/model/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"),
[
Expand Down

0 comments on commit 79f2fc3

Please sign in to comment.