Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made new classes for updated geometry #2085

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
80 changes: 80 additions & 0 deletions tardis/montecarlo/montecarlo_numba/numba_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@
("v_outer", float64[:]),
]

geometry_grid_spherical_1d_spec = [
("r_inner", float64[:]),
("r_outer", float64[:]),
("time_explosion", float64),
]

geometry_grid_cartesian_2d_spec = [
("x_coord", float64[:]),
("y_coord", float64[:]),
("time_explosion", float64),
("cell_width", float64),
]

geometry_grid_cartesian_3d_spec = [
("x_coord", float64[:]),
("y_coord", float64[:]),
("z_coord", float64[:]),
("time_explosion", float64),
("cell_width", float64),
]


@jitclass(numba_model_spec)
class NumbaModel(object):
Expand All @@ -43,6 +64,65 @@ def __init__(self, r_inner, r_outer, v_inner, v_outer, time_explosion):
self.time_explosion = time_explosion


@jitclass(geometry_grid_spherical_1d_spec)
class GeometryGridSpherical1D(object):
def __init__(self, r_inner, r_outer):
"""
1D spherical shell model

Parameters
----------
r_inner : numpy.ndarray
andrewfullard marked this conversation as resolved.
Show resolved Hide resolved
r_outer : numpy.ndarray
"""
self.r_inner = r_inner
self.r_outer = r_outer


@jitclass(geometry_grid_cartesian_2d_spec)
class GeometryGridCartesian2D(object):
def __init__(self, x_coord, y_coord, cell_width):
"""
Model for the 2D Cartesian grid system

Parameters
----------
x_coord : numpy.ndarray
y_coord : numpy.ndarray
cell_width : float

Notes
-----
coords specify upper left coordinate of each cell
"""
self.x_coord = x_coord
self.y_coord = y_coord
self.cell_width = cell_width


@jitclass(geometry_grid_cartesian_3d_spec)
class GeometryGridCartesian3D(object):
def __init__(self, x_coord, y_coord, z_coord, cell_width):
"""
Model for the 3D Cartesian grid system

Parameters
----------
x_coord : numpy.ndarray
y_coord : numpy.ndarray
z_coord : numpy.ndarray
cell_width : float

Notes
-----
coords specify upper left, out of the page coordinate of each cell
"""
self.x_coord = x_coord
self.y_coord = y_coord
self.z_coord = z_coord
self.cell_width = cell_width


numba_plasma_spec = [
("electron_density", float64[:]),
("t_electrons", float64[:]),
Expand Down
38 changes: 37 additions & 1 deletion tardis/montecarlo/montecarlo_numba/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

from tardis.simulation import Simulation
from tardis.montecarlo.montecarlo_numba import RPacket, PacketCollection
from tardis.montecarlo.montecarlo_numba.numba_interface import Estimators
from tardis.montecarlo.montecarlo_numba.numba_interface import (
Estimators,
GeometryGridCartesian2D,
GeometryGridSpherical1D,
GeometryGridCartesian3D,
)


from tardis.montecarlo.montecarlo_numba.numba_interface import (
Expand Down Expand Up @@ -58,6 +63,37 @@ def verysimple_numba_model(nb_simulation_verysimple):
)


@pytest.fixture(scope="package")
def verysimple_geometry_grid_spherical_1d(nb_simulation_verysimple):
runner = nb_simulation_verysimple.runner
model = nb_simulation_verysimple.model
return GeometryGridSpherical1D(
runner.r_inner_cgs,
runner.r_outer_cgs,
)


@pytest.fixture(scope="package")
def verysimple_geometry_grid_cartesian_2d(two_d_grid_verysimple):

width = 1.0
x_list = np.arange(-10, 10, width, dtype=np.float64)
y_list = np.arange(-10, 10, width, dtype=np.float64)

return GeometryGridCartesian2D(x_list, y_list, width)


@pytest.fixture(scope="package")
def verysimple_geometry_grid_cartesian_3d(nb_simulation_verysimple):

width = 1.0
x_list = np.arange(-10, 10, width, dtype=np.float64)
y_list = np.arange(-10, 10, width, dtype=np.float64)
z_list = np.arange(-10, 10, width, dtype=np.float64)

return GeometryGridCartesian3D(x_list, y_list, z_list, width)


@pytest.fixture(scope="package")
def verysimple_estimators(nb_simulation_verysimple):
runner = nb_simulation_verysimple.runner
Expand Down