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

Restructure radiation field #2474

Merged
merged 108 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 100 commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
314cf30
restructure of geometry
wkerzendorf Sep 28, 2023
d353133
add radial1d boundary logic
wkerzendorf Oct 4, 2023
2475551
black format
wkerzendorf Oct 4, 2023
e6d1697
several fixes
wkerzendorf Oct 4, 2023
3c53cda
fix epsilon
wkerzendorf Oct 4, 2023
6dce2b4
add testing of boundaries
wkerzendorf Oct 4, 2023
1fdcea8
change the r_inner_active
wkerzendorf Oct 4, 2023
56e9da5
first integration with `from_config` working
wkerzendorf Oct 7, 2023
f6743d7
hunting down density indexing bug
wkerzendorf Oct 8, 2023
b55b21d
all model tests (without csvy) pass
wkerzendorf Oct 8, 2023
ed978d9
more fixes
wkerzendorf Oct 9, 2023
cae9c19
fix of model to simulation_state
wkerzendorf Oct 9, 2023
d829e73
fix inner boundary packet error
wkerzendorf Oct 9, 2023
9592a97
fix some leftovers
wkerzendorf Oct 10, 2023
4da6869
final fix for csvy
wkerzendorf Oct 10, 2023
f381d2e
blackify
wkerzendorf Oct 10, 2023
e59741d
restructure to readers and remove some leftover code
wkerzendorf Oct 11, 2023
a42dd55
further cleanup
wkerzendorf Oct 11, 2023
3288c6c
first start of the restructure
wkerzendorf Oct 11, 2023
518a8f9
add comment about removing quantitiness
wkerzendorf Oct 11, 2023
c78b6de
add velocity check
wkerzendorf Oct 11, 2023
006ca9d
add new abundance functions
wkerzendorf Oct 12, 2023
9c680a8
remove default units
wkerzendorf Oct 12, 2023
268bd23
add new matter module
wkerzendorf Oct 12, 2023
6b03e93
several restructures. move decay from io to tardis/model/matter
wkerzendorf Oct 12, 2023
3114413
mid restructure
wkerzendorf Oct 13, 2023
217dcf2
slow progress on abundance refactor
wkerzendorf Oct 16, 2023
78055b4
include effective_element_masses
wkerzendorf Oct 22, 2023
73f5175
Merge remote-tracking branch 'upstream/master' into restructure/abund…
wkerzendorf Oct 22, 2023
b96d717
further updates
wkerzendorf Nov 2, 2023
08ea21d
fix of csvy readers
wkerzendorf Nov 2, 2023
f0fc7c2
last fixes to custom abundance widget
wkerzendorf Nov 4, 2023
fe7c415
restructuring the radiation field
wkerzendorf Nov 5, 2023
226fb57
some cleanup
wkerzendorf Nov 5, 2023
cbd025e
Merge branch 'restructure/abundance' into restructure/radiation_field
wkerzendorf Nov 5, 2023
afb9613
cleanup
wkerzendorf Nov 5, 2023
daf12a5
further cleanup
wkerzendorf Nov 5, 2023
f2d26a8
Merge branch 'restructure/abundance' into restructure/radiation_field
wkerzendorf Nov 5, 2023
7575512
clearnup
wkerzendorf Nov 5, 2023
dc34343
changes
wkerzendorf Nov 6, 2023
37d36e1
remove matter base.py
wkerzendorf Nov 8, 2023
4a77a4a
removing matter
wkerzendorf Nov 8, 2023
dbd47cc
Merge remote-tracking branch 'upstream/master' into restructure/abund…
wkerzendorf Nov 8, 2023
d1792bf
fixed last tests
wkerzendorf Nov 20, 2023
c757848
Merge remote-tracking branch 'upstream/master' into restructure/abund…
wkerzendorf Nov 20, 2023
5b1c7b2
Merge branch 'restructure/abundance' into restructure/radiation_field
wkerzendorf Nov 20, 2023
398631a
add several parsers
wkerzendorf Nov 20, 2023
ed60c0f
add composition
wkerzendorf Nov 20, 2023
8723fdf
remove isotopemassfractions
wkerzendorf Nov 20, 2023
08874ca
some small fixes
wkerzendorf Nov 20, 2023
d89b957
Merge branch 'restructure/abundance' into restructure/radiation_field
wkerzendorf Nov 20, 2023
1da7ed0
fixed w, t_rad to dilution_factor, t_radiative
wkerzendorf Nov 20, 2023
9f28ecd
add setters for w, t_rad
wkerzendorf Nov 20, 2023
0d85540
several fixes for instantiating the right t_rads.
wkerzendorf Nov 21, 2023
7161791
add the from_config atom_data
wkerzendorf Nov 21, 2023
4f4aad6
Merge remote-tracking branch 'upstream/master' into restructure/abund…
wkerzendorf Nov 21, 2023
f65a2d7
fixing model.ipynb
wkerzendorf Nov 21, 2023
cbfe685
Merge branch 'restructure/abundance' into restructure/radiation_field
wkerzendorf Nov 21, 2023
b961734
fix some more tests
wkerzendorf Nov 21, 2023
1c38607
fix tests
wkerzendorf Nov 23, 2023
c99e9d4
fix some of the issues wdigets
wkerzendorf Nov 23, 2023
4c0b49a
assert mass fractions positive.
wkerzendorf Nov 23, 2023
8e0de5c
add radiation_field_state
wkerzendorf Nov 23, 2023
fcd34bb
Fix isotope mass fraction typo and t_radiatve duplicate definition
wkerzendorf Nov 27, 2023
1e3a035
Document remove functionality for effective element masses
wkerzendorf Nov 27, 2023
af1f114
Fix variable name in
wkerzendorf Nov 27, 2023
203bae0
Refactor test names and variable names in
wkerzendorf Nov 27, 2023
56aaa8c
Merge remote-tracking branch 'upstream/master' into restructure/abund…
wkerzendorf Nov 27, 2023
2a50667
Refactor gamma ray simulation setup and test
wkerzendorf Nov 29, 2023
b17b7c7
fix gamma ray tests
wkerzendorf Nov 29, 2023
a479cf6
Add model_isotope_time_0 property to abundances
wkerzendorf Nov 29, 2023
6d64b2d
Add test for montecarlo main loop with vpacket
wkerzendorf Nov 29, 2023
b92158d
Refactor config_reader and config_validator
wkerzendorf Nov 29, 2023
e56ddcc
Fix model_isotope_time_0 property in
wkerzendorf Nov 29, 2023
29fa091
Refactor simulation module to use pathlib
wkerzendorf Nov 29, 2023
8dff14e
remove bad comment and refactor with ruff
wkerzendorf Nov 29, 2023
fcb5dba
Fix variable name in test_simulation_state_mass()
wkerzendorf Nov 29, 2023
7da18f3
Fix unit conversion in calculate_cell_masses
wkerzendorf Nov 29, 2023
1bb7266
Fix logger debug message in CSV reader and update
wkerzendorf Nov 29, 2023
821f4ce
black formatting
wkerzendorf Nov 29, 2023
2257093
Refactor code to use composition variable in
wkerzendorf Nov 29, 2023
e105e71
Merge remote-tracking branch 'upstream/master' into restructure/abund…
wkerzendorf Nov 30, 2023
75840d3
Refactor imports in atom_web_download.py and
wkerzendorf Nov 30, 2023
59d5eff
fix for documentation not builiding
wkerzendorf Dec 4, 2023
1f65771
add fix for model_isotope_time_0
wkerzendorf Dec 4, 2023
dd6ba4f
fix grid test
wkerzendorf Dec 4, 2023
5391968
restructure the grid
wkerzendorf Dec 4, 2023
9706437
final change
wkerzendorf Dec 4, 2023
512d737
Merge branch 'restructure/abundance' into restructure/radiation_field
wkerzendorf Dec 4, 2023
c6d3a59
add stuff
wkerzendorf Dec 4, 2023
d9a191c
add vpacket_log
wkerzendorf Dec 4, 2023
b31561e
Refactor model_reader.py and shell_info.py
wkerzendorf Dec 4, 2023
f438ec3
Update damping constants and variable names
wkerzendorf Dec 4, 2023
ef8cf30
fix w in several places in tardis
wkerzendorf Dec 4, 2023
361e0b7
slowly fixing radiation_field changes
wkerzendorf Dec 4, 2023
d5cb35d
Merge remote-tracking branch 'origin/restructure/radiation_field' int…
wkerzendorf Dec 4, 2023
6244535
last fix
wkerzendorf Dec 4, 2023
3c8f3da
change hdf from model to simulation_state
wkerzendorf Dec 4, 2023
815b0d8
fixing model->simulation-state
wkerzendorf Dec 4, 2023
5925f6e
Merge remote-tracking branch 'upstream/master' into restructure/radia…
wkerzendorf Dec 4, 2023
81ebd21
Fix model_reader.py imports and formatting issues
wkerzendorf Dec 4, 2023
e24f1fa
Refactor variable names for clarity and
wkerzendorf Dec 4, 2023
50d3ec3
Update variable names in model.ipynb
wkerzendorf Dec 4, 2023
566d279
Update variable name for average temperature
wkerzendorf Dec 4, 2023
a949f49
Refactor variable names in model reader and
wkerzendorf Dec 10, 2023
56a948d
Refactor store_model_to_hdf to
wkerzendorf Dec 10, 2023
2e6caac
Refactor HDF file handling and model reader
wkerzendorf Dec 11, 2023
1cc8004
add docstr
wkerzendorf Dec 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions docs/physics/update_and_conv/update_and_conv.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@
"\n",
"# We manually put in the damping constants and t_inner_update_exponent for\n",
"# illustrative purposes:\n",
"d_t_rad = 0.5\n",
"d_w = 0.3\n",
"d_t_inner = 0.7\n",
"damping_t_radiative = 0.5\n",
"damping_dilution_factor = 0.3\n",
"damping_t_inner = 0.7\n",
"t_inner_update_exponent = -0.5\n",
"\n",
"# We set the above values into the configuration:\n",
"tardis_config.montecarlo.convergence_strategy.t_rad.damping_constant = d_t_rad\n",
"tardis_config.montecarlo.convergence_strategy.w.damping_constant = d_w\n",
"tardis_config.montecarlo.convergence_strategy.t_inner.damping_constant = d_t_inner\n",
"tardis_config.montecarlo.convergence_strategy.t_rad.damping_constant = damping_t_radiative\n",
"tardis_config.montecarlo.convergence_strategy.w.damping_constant = damping_dilution_factor\n",
"tardis_config.montecarlo.convergence_strategy.t_inner.damping_constant = damping_t_inner\n",
"tardis_config.montecarlo.convergence_strategy.t_inner_update_exponent = t_inner_update_exponent"
]
},
Expand All @@ -212,7 +212,7 @@
"source": [
"sim = Simulation.from_config(tardis_config)\n",
"\n",
"model = sim.simulation_state\n",
"simulation_state = sim.simulation_state\n",
"plasma = sim.plasma\n",
"transport = sim.transport"
]
Expand All @@ -233,7 +233,7 @@
"metadata": {},
"outputs": [],
"source": [
"model.t_rad"
"simulation_state.t_radiative"
]
},
{
Expand All @@ -243,7 +243,7 @@
"metadata": {},
"outputs": [],
"source": [
"model.w"
"simulation_state.dilution_factor"
]
},
{
Expand All @@ -253,7 +253,7 @@
"metadata": {},
"outputs": [],
"source": [
"model.t_inner"
"simulation_state.t_inner"
]
},
{
Expand Down Expand Up @@ -344,8 +344,8 @@
"metadata": {},
"outputs": [],
"source": [
"V = model.volume\n",
"Delta_t = transport.calculate_time_of_simulation(model)\n",
"V = simulation_state.volume\n",
"Delta_t = transport.calculate_time_of_simulation(simulation_state)\n",
"prefactor = 1 / (4 * np.pi * V * Delta_t)\n",
"J = prefactor * j_estimator\n",
"J"
Expand Down Expand Up @@ -410,7 +410,7 @@
"metadata": {},
"outputs": [],
"source": [
"t_rad_updated = model.t_rad + d_t_rad * (t_rad_estimated - model.t_rad)\n",
"t_rad_updated = simulation_state.t_radiative + damping_t_radiative * (t_rad_estimated - simulation_state.t_radiative)\n",
"t_rad_updated"
]
},
Expand All @@ -421,8 +421,8 @@
"metadata": {},
"outputs": [],
"source": [
"w_estimated = ( j_estimator / (4 * const.sigma_sb.cgs * t_rad_estimated**4 * V * Delta_t) ).decompose()\n",
"w_estimated"
"dilution_factor_estimated = ( j_estimator / (4 * const.sigma_sb.cgs * t_rad_estimated**4 * V * Delta_t) ).decompose()\n",
"dilution_factor_estimated"
]
},
{
Expand All @@ -432,8 +432,8 @@
"metadata": {},
"outputs": [],
"source": [
"w_updated = model.w + d_w * (w_estimated - model.w)\n",
"w_updated"
"dilution_factor_updated = simulation_state.dilution_factor + damping_dilution_factor * (dilution_factor_estimated - simulation_state.dilution_factor)\n",
"dilution_factor_updated"
]
},
{
Expand Down Expand Up @@ -484,7 +484,7 @@
"metadata": {},
"outputs": [],
"source": [
"t_inner_estimated = model.t_inner * (L_output / L_requested)**t_inner_update_exponent\n",
"t_inner_estimated = simulation_state.t_inner * (L_output / L_requested)**t_inner_update_exponent\n",
"t_inner_estimated"
]
},
Expand All @@ -495,7 +495,7 @@
"metadata": {},
"outputs": [],
"source": [
"t_inner_updated = model.t_inner + d_t_inner * (t_inner_estimated - model.t_inner)\n",
"t_inner_updated = simulation_state.t_inner + damping_t_inner * (t_inner_estimated - simulation_state.t_inner)\n",
"t_inner_updated"
]
},
Expand Down Expand Up @@ -536,7 +536,7 @@
"metadata": {},
"outputs": [],
"source": [
"model.t_rad"
"simulation_state.t_radiative"
]
},
{
Expand All @@ -548,7 +548,7 @@
},
"outputs": [],
"source": [
"model.w"
"simulation_state.dilution_factor"
]
},
{
Expand All @@ -558,7 +558,7 @@
"metadata": {},
"outputs": [],
"source": [
"model.t_inner"
"simulation_state.t_inner"
]
},
{
Expand Down
98 changes: 13 additions & 85 deletions tardis/io/model/model_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def transport_from_hdf(fname):
return new_transport


def simulation_state_to_dict(model):
def simulation_state_to_dict(simulation_state):
"""
Retrieves all the data from a SimulationState object and returns a dictionary.

Expand All @@ -296,20 +296,20 @@ def simulation_state_to_dict(model):
isotope_abundance : dict
"""
simulation_state_dict = {
"velocity_cgs": model.velocity.cgs,
"abundance": model.abundance,
"time_explosion_cgs": model.time_explosion.cgs,
"t_inner_cgs": model.t_inner.cgs,
"t_radiative_cgs": model.t_radiative.cgs,
"dilution_factor": model.dilution_factor,
"v_boundary_inner_cgs": model.v_boundary_inner.cgs,
"v_boundary_outer_cgs": model.v_boundary_outer.cgs,
"w": model.w,
"t_rad_cgs": model.t_rad.cgs,
"r_inner_cgs": model.r_inner.cgs,
"density_cgs": model.density.cgs,
"velocity_cgs": simulation_state.velocity.cgs,
"abundance": simulation_state.abundance,
"time_explosion_cgs": simulation_state.time_explosion.cgs,
"t_inner_cgs": simulation_state.t_inner.cgs,
"t_radiative_cgs": simulation_state.t_radiative.cgs,
"dilution_factor": simulation_state.dilution_factor,
"v_boundary_inner_cgs": simulation_state.v_boundary_inner.cgs,
"v_boundary_outer_cgs": simulation_state.v_boundary_outer.cgs,
"dilution_factor": simulation_state.dilution_factor,
"r_inner_cgs": simulation_state.r_inner.cgs,
"density_cgs": simulation_state.density.cgs,
}

for key, value in simulation_state_dict.items():
for key, value in simulation_state_dict.items():
if hasattr(value, "unit"):
simulation_state_dict[key] = [
Expand All @@ -318,75 +318,3 @@ def simulation_state_to_dict(model):
]

return simulation_state_dict


def model_from_hdf(fname):
"""
Creates a SimulationState object using data stored in a hdf file.

Parameters
----------
fname : str

Returns
-------
new_model : tardis.model.SimulationState
"""

from tardis.model import SimulationState

d = {}

# Loading data from hdf file
with h5py.File(fname, "r") as f:
model_group = f["model"]
for key, value in model_group.items():
if not key.endswith("_unit"):
if type(value) == h5py._hl.dataset.Dataset:
if isinstance(value[()], bytes):
d[key] = value[()].decode("utf-8")
else:
d[key] = value[()]
else:
data_inner = {}
for key_inner, value_inner in value.items():
if isinstance(value_inner[()], bytes):
data_inner[key] = value_inner[()].decode("utf-8")
else:
data_inner[key] = value_inner[()]
data_inner[key_inner] = value_inner[()]
d[key] = data_inner

for key, value in model_group.items():
if key.endswith("_unit"):
d[key[:-5]] = [d[key[:-5]], value[()]]

# Converting cgs data to astropy quantities
for key, value in d.items():
if key.endswith("_cgs"):
d[key] = u.Quantity(value[0], unit=u.Unit(value[1].decode("utf-8")))

homologous_density = calculate_density_after_time(
d["homologous_density"]["density_0"],
d["homologous_density"]["time_0"],
d["time_explosion_cgs"],
)

new_model = SimulationState(
velocity=d["velocity_cgs"],
density=homologous_density,
abundance=d["abundance"],
isotope_abundance=None,
time_explosion=d["time_explosion_cgs"],
elemental_mass=None,
t_inner=d["t_inner_cgs"],
t_radiative=d["t_radiative_cgs"],
dilution_factor=d["dilution_factor"],
v_boundary_inner=d["v_boundary_inner_cgs"],
v_boundary_outer=d["v_boundary_outer_cgs"],
)

new_model.t_rad = d["t_rad_cgs"]
new_model.w = d["w"]

return new_model
69 changes: 0 additions & 69 deletions tardis/io/model_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,72 +866,3 @@ def store_model_to_hdf(model, fname):
model_group.create_dataset(key + "_unit", data=value[1])
else:
model_group.create_dataset(key, data=value)


def model_from_hdf(fname):
"""
Creates a SimulationState object using data stored in a hdf file.

Parameters
----------
fname : str

Returns
-------
new_model : tardis.model.SimulationState
"""

from tardis.model import SimulationState

d = {}

# Loading data from hdf file
with h5py.File(fname, "r") as f:
model_group = f["model"]
for key, value in model_group.items():
if not key.endswith("_unit"):
if type(value) == h5py._hl.dataset.Dataset:
if isinstance(value[()], bytes):
d[key] = value[()].decode("utf-8")
else:
d[key] = value[()]
else:
data_inner = {}
for key_inner, value_inner in value.items():
if isinstance(value_inner[()], bytes):
data_inner[key] = value_inner[()].decode("utf-8")
else:
data_inner[key] = value_inner[()]
data_inner[key_inner] = value_inner[()]
d[key] = data_inner

for key, value in model_group.items():
if key.endswith("_unit"):
d[key[:-5]] = [d[key[:-5]], value[()]]

# Converting cgs data to astropy quantities
for key, value in d.items():
if key.endswith("_cgs"):
d[key] = u.Quantity(value[0], unit=u.Unit(value[1].decode("utf-8")))

homologous_density = HomologousDensity(
d["homologous_density"]["density_0"], d["homologous_density"]["time_0"]
)

new_model = SimulationState(
velocity=d["velocity_cgs"],
homologous_density=homologous_density,
abundance=d["abundance"],
isotope_abundance=None,
time_explosion=d["time_explosion_cgs"],
t_inner=d["t_inner_cgs"],
t_radiative=d["t_radiative_cgs"],
dilution_factor=d["dilution_factor"],
v_boundary_inner=d["v_boundary_inner_cgs"],
v_boundary_outer=d["v_boundary_outer_cgs"],
)

new_model.t_rad = d["t_rad_cgs"]
new_model.w = d["w"]

return new_model
Loading
Loading