Skip to content

Commit

Permalink
[restructure/plasma] Cleanup plasma assembly (#2748)
Browse files Browse the repository at this point in the history
* change numberdensity to input

* fixed number density

* some fixes

* removing density

* remove atomic and isotope mass

* add isotopic_number_density

* add opacities package

* Update imports in property_collections.py, base.py, test_numba_interface.py, transport_montecarlo_numba_interface.py, conftest.py, formal_integral.py, base.py, and macro_atom.py

* Add calculate_transition_probabilities function to util.py in macro_atom package

* Add calculate_transition_probabilities function to util.py in macro_atom package

* Remove unused imports and update plasma properties

* add __init__ to macroatom

* blackify tardis

* blackified

* chore: Update imports and remove unused code

* chore: Add PlanckRadiationField and DilutePlanckRadiationField classes

* chore: Update imports and remove unused code

* removed density

* ruff output

* cleanup and adding object mode

* starting to make radiation_field a thing

* switched over to old tau_sobolev calculation

* renamed function to indicate numba use

* address comments

* added dilute planckian radiation field

* refactor: Convert species lists to proper format in assemble_plasma function

* moved radiation field into plasma. Resulting in some renames

* some fixes

* black montecarlo

* chore: Initialize atom data and simulation state in `initialization.py`

* updating the documentation

* feat: Add EstimatedRadiationFieldProperties class for Monte Carlo estimators

* trying to get rid of j_blues in plasma with MC restructure

* completely restructure j_blues. Estimators and all.

* cleanup for the restructure

* remove parse_input.py

* chore: Refactor radiation field configuration parsing and state creation

Refactor the `parse_radiation_field_configuration.py` module to improve code organization and readability. Update the import statements to reflect the changes in the module structure. Replace the deprecated `DiluteBlackBodyRadiationFieldState` class with the new `DilutePlanckianRadiationField` class from the `tardis.plasma.radiation_field` module. This change ensures consistency and compatibility with the latest codebase.

Also, update the `tardis/simulation/base.py` module to import the `DilutePlanckianRadiationField` class from the `tardis.plasma.radiation_field` module. This change ensures that the correct class is used for creating the radiation field in the simulation.

* revert astropy_helpers

* remove astropy_helpers

* removed test.txt

* blackified code

* cleanup simulation from merges

* fix

* remove unused Input

* added description

* blackiefied codebase

* cleanup of branch

* blackify code

* chore: Refactor atom data parsing and simulation state initialization

* restructure logger

* working on continuum radfield properties

* Refactor continuum processes module structure

* Refactor opacities module structure

* cleanup from restructure

* cleanup

* clean up

* more cleanup

* cleanup standard_plasmas.py

* working nlte ionizations

* start of assemble plasma cleanup

* cleanup standard_plasmas.py

* updated tests

* some more cleanup

* fix benchmarks

* cleanup assembly

* cleanup assembly

* working on the restructure

* slowly fixing the assembly module

* blackify

* reverse the import pygraphviz

* fix docstrings

* fixed all plasma

* slow fixes

* Refactor recomb_rate_coeff.py and test_continuum_property_solver.py

* fixing assembly

* restructure the read in

* fixup plasma assemble to be clean

* fix shell info widget

* fix the widgets

* fixing hopefully last bugs

* slowly fix up assembly

* working on getting the notebook running

* Refactor code to address comments

* remove abundance

* added pydantic

* possible fix for test problem

Co-authored-by: Atharva Arya <[email protected]>

* fix problem with opacity solver

* chore: Refactor plasma assembly base and notebook

Refactor the `PlasmaSolverFactory` class in `tardis/plasma/assembly/base.py` to improve code organization and readability. Remove unused imports and reformat the code using the black linter. Also, remove the unnecessary code block in the Jupyter notebook `docs/physics/plasma/construction_simple_plasma.ipynb`. These changes aim to enhance the maintainability and clarity of the codebase.

* added docstrings

---------

Co-authored-by: Atharva Arya <[email protected]>
  • Loading branch information
wkerzendorf and atharva-2001 committed Aug 12, 2024
1 parent 63eb762 commit 2df54e5
Show file tree
Hide file tree
Showing 19 changed files with 838 additions and 31 deletions.
127 changes: 116 additions & 11 deletions docs/physics/plasma/construction_simple_plasma.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Constructing a simple plasma"
"# Constructing a simple thermal plasma"
]
},
{
Expand All @@ -23,7 +23,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bbbd27367e48465696aa4e40f25b8496",
"model_id": "adc8142e04de4ac4ad9fb6d9eba83286",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -37,7 +37,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6830a2c86f754397999e6801ccca1001",
"model_id": "36b88ed7168e46c8864e17b0107f8f71",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -51,9 +51,20 @@
],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"from astropy import units as u\n",
"from tardis.radiation_field.planck_rad_field import DilutePlanckianRadiationField\n",
"#from tardis.plasma.properties.plasma_input import T"
"\n",
"from tardis.io.atom_data import AtomData\n",
"from tardis.plasma.assembly.base import PlasmaSolverFactory\n",
"from tardis.plasma.radiation_field import DilutePlanckianRadiationField\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the default configuration the plasma solver assumes the conditions for a Local Thermodynamic Equilibrium meaning a planckian radiation field and a maxwellian electron velocity distribution at the same templerature"
]
},
{
Expand All @@ -62,8 +73,9 @@
"metadata": {},
"outputs": [],
"source": [
"temperatures_rad = np.ones(10) * 10000 * u.K\n",
"dilution_factor = np.ones(10) * 0.1"
"NO_OF_CELLS = 1000\n",
"temperatures_rad = np.ones(NO_OF_CELLS) * 10000 * u.K\n",
"dilution_factor = np.ones(NO_OF_CELLS) * 0.1"
]
},
{
Expand All @@ -77,12 +89,105 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"base_density = 1e-15 * u.Unit('g/cm^3')\n",
"number_densities = pd.DataFrame(columns=range(NO_OF_CELLS), index=[1,26,28])\n",
"number_densities.values[:] = 0.5 * (base_density / u.u).to(1/u.cm**3).value\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"test = DilutePlanckianRadFieldInput()\n",
"test.set_value(d_radfield)"
"atom_data = AtomData.from_hdf('kurucz_cd23_chianti_H_He.h5')\n",
"plasma_solver_factory = PlasmaSolverFactory(atom_data, selected_atomic_numbers=[1,26,28])\n",
"plasma_solver_factory.setup_factory()\n"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th></th>\n",
" <th>0</th>\n",
" </tr>\n",
" <tr>\n",
" <th>atomic_number</th>\n",
" <th>ion_number</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">1</th>\n",
" <th>0</th>\n",
" <td>2.245918e-04</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>3.011070e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"3\" valign=\"top\">2</th>\n",
" <th>0</th>\n",
" <td>1.405189e-15</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2.206015e-03</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3.011070e+08</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0\n",
"atomic_number ion_number \n",
"1 0 2.245918e-04\n",
" 1 3.011070e+08\n",
"2 0 1.405189e-15\n",
" 1 2.206015e-03\n",
" 2 3.011070e+08"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plasma_solver.ion_number_density"
]
},
{
Expand All @@ -107,7 +212,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion tardis/io/configuration/tests/test_config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from astropy.units import Quantity
from tardis.io.configuration.config_reader import Configuration
from tardis.plasma.exceptions import PlasmaConfigError
from tardis.plasma.standard_plasmas import assemble_plasma
from tardis.plasma.assembly.legacy_assembly import assemble_plasma


def test_convergence_section_parser():
Expand Down
1 change: 1 addition & 0 deletions tardis/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class SimulationState(HDFWriterMixin):
"density",
"r_inner",
"time_explosion",
"abundance",
]
hdf_name = "simulation_state"

Expand Down
4 changes: 3 additions & 1 deletion tardis/opacities/opacity_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def solve(self, legacy_plasma) -> OpacityState:
legacy_plasma.atomic_data.lines.shape[
0
], # number of lines
legacy_plasma.abundance.shape[1], # number of shells
legacy_plasma.number_density.shape[
1
], # number of shells
),
dtype=np.float64,
),
Expand Down
Empty file.
Loading

0 comments on commit 2df54e5

Please sign in to comment.