diff --git a/docs/physics/montecarlo/geometricgrids.ipynb b/docs/physics/montecarlo/geometricgrids.ipynb new file mode 100644 index 00000000000..b102b8aa01f --- /dev/null +++ b/docs/physics/montecarlo/geometricgrids.ipynb @@ -0,0 +1,80 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## grids" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To improve functionality of TARDIS, multiple geometric grid options have been implemented. In addition to the 1D radial shell model, TARDIS now has options for a 2D cartesian grid and 3D cartesian grid. The old radial 1D class, NumbaModel has been renamed GeometryGridSpherical1D." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A 2D cartesian grid has been added as GeometryGridCartesian2D, and a 3D cartesian grid has been added as GeometryGridCartesian3D." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The cartesian cells are of uniform size (squares or cubes depending on the dimensionality). " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "While the 1D radial shell model is suitable for spherically symmetry supernovae, it does not accurately model non-spherically symmetric supernovae. Notable, type Ic supernovae produce gamma ray jets, which are plainly non-spherically symmetric. Other supernovae also possess non spherical shapes.\n", + "\n", + "It will also be useful to see if different geometric models produce matching results for spherically symmetric supernovae." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Upon full implementation, the user will select which geometric grid they would like to use, and then the simulation will emply that grid." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3.8.13 ('tardis')", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.13" + }, + "orig_nbformat": 4, + "vscode": { + "interpreter": { + "hash": "dde2274465eb8939574804a93aa9b05c38ce95b3902c9801d5d6516b86c3fabe" + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/tardis/montecarlo/montecarlo_numba/numba_interface.py b/tardis/montecarlo/montecarlo_numba/numba_interface.py index 884991e45a1..66cb38d9ee7 100644 --- a/tardis/montecarlo/montecarlo_numba/numba_interface.py +++ b/tardis/montecarlo/montecarlo_numba/numba_interface.py @@ -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): @@ -43,6 +64,74 @@ 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 + inner radii of spherical shells + r_outer : numpy.ndarray + outer radii of spherical shells + """ + 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 + x coordinates of the left of the grid cells + y_coord : numpy.ndarray + y coordinates of the bottom of the grid cells + cell_width : float + side length of each square cell + + Notes + ----- + coords specify lower left coordinate of each cell, i.e. the least coordinate in each dimension + """ + 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 + x coordinates of the left of the grid cells + y_coord : numpy.ndarray + y coordinates of the lower of the grid cells + z_coord : numpy.ndarray + z coordinates of the back of the grid cells + cell_width : float + side length of each cubic cell + + Notes + ----- + coords specify lower left, into the page coordinate of each cell, i.e. the least coordinate in each dimension + """ + 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[:]), diff --git a/tardis/montecarlo/montecarlo_numba/tests/conftest.py b/tardis/montecarlo/montecarlo_numba/tests/conftest.py index 91d1ae63cfd..6847c6116a8 100644 --- a/tardis/montecarlo/montecarlo_numba/tests/conftest.py +++ b/tardis/montecarlo/montecarlo_numba/tests/conftest.py @@ -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 ( @@ -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