Skip to content

Commit

Permalink
Validating based on different sections
Browse files Browse the repository at this point in the history
  • Loading branch information
DhruvSondhi committed Apr 28, 2021
1 parent 905d26b commit a46c2cd
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 2 deletions.
94 changes: 92 additions & 2 deletions tardis/io/config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ def from_config_dict(cls, config_dict, validate=True, config_dirname=""):

validated_config_dict["config_dirname"] = config_dirname

# Montecarlo Section Implementation
montecarlo_section = validated_config_dict["montecarlo"]
if montecarlo_section["convergence_strategy"]["type"] == "damped":
montecarlo_section[
Expand Down Expand Up @@ -313,12 +314,101 @@ def from_config_dict(cls, config_dict, validate=True, config_dirname=""):
"relativity mode. "
)

# SuperNova Section Implementation
# Model Section Validation
model_section = validated_config_dict["model"]

if model_section["structure"]["type"] == "specific":
start_velocity = model_section["structure"]["velocity"]["start"]
stop_velocity = model_section["structure"]["velocity"]["stop"]
if stop_velocity.value < start_velocity.value:
raise ValueError(
"Stop Velocity Cannot Be Less than Start Velocity. \n"
f"Start Velocity = {start_velocity} \n"
f"Stop Velocity = {stop_velocity}"
)
elif model_section["structure"]["type"] == "file":
v_inner_boundary = model_section["structure"]["v_inner_boundary"]
v_outer_boundary = model_section["structure"]["v_outer_boundary"]
if v_outer_boundary.value < v_inner_boundary.value:
raise ValueError(
"Outer Boundary Velocity Cannot Be Less than Inner Boundary Velocity. \n"
f"Inner Boundary Velocity = {v_inner_boundary} \n"
f"Outer Boundary Velocity = {v_outer_boundary}"
)

if model_section["structure"]["density"]["type"] == "exponential":
time_0 = model_section["structure"]["density"]["time_0"]
rho_0 = model_section["structure"]["density"]["rho_0"]
v_0 = model_section["structure"]["density"]["v_0"]
if not time_0.value > 0:
raise ValueError(f"Time Specified is Invalid, {time_0}")
if not rho_0.value > 0:
raise ValueError(f"Density Specified is Invalid, {rho_0}")
if not v_0.value > 0:
raise ValueError(f"Velocity Specified is Invalid, {v_0}")

if model_section["structure"]["density"]["type"] == "power_law":
time_0 = model_section["structure"]["density"]["time_0"]
rho_0 = model_section["structure"]["density"]["rho_0"]
v_0 = model_section["structure"]["density"]["v_0"]
if not time_0.value > 0:
raise ValueError(f"Time Specified is Invalid, {time_0}")
if not rho_0.value > 0:
raise ValueError(f"Density Specified is Invalid, {rho_0}")
if not v_0.value > 0:
raise ValueError(f"Velocity Specified is Invalid, {v_0}")

if model_section["structure"]["density"]["type"] == "uniform":
time_0 = model_section["structure"]["density"]["time_0"]
value = model_section["structure"]["density"]["value"]
if not time_0.value > 0:
raise ValueError(f"Time Specified is Invalid, {time_0}")
if not value.value > 0:
raise ValueError(f"Density Value Specified is Invalid, {value}")

# SuperNova Section Validation
supernova_section = validated_config_dict["supernova"]

time_explosion = supernova_section["time_explosion"]
luminosity_wavelength_start = supernova_section[
"luminosity_wavelength_start"
]
luminosity_wavelength_end = supernova_section[
"luminosity_wavelength_end"
]
if not time_explosion.value > 0:
raise ValueError(f"Time Of Explosion is Invalid, {time_explosion}")
if luminosity_wavelength_start.value > luminosity_wavelength_end.value:
raise ValueError(
"Integral Values for Luminosity Wavelength are Invalid, Start Limit > End Limit \n"
f"Luminosity Wavelength Start : {luminosity_wavelength_start} \n"
f"Luminosity Wavelength End : {luminosity_wavelength_end}"
)

# Plasma Section Validation
plasma_section = validated_config_dict["plasma"]

initial_t_inner = plasma_section["initial_t_inner"]
initial_t_rad = plasma_section["initial_t_rad"]
if not initial_t_inner.value >= -1:
raise ValueError(
f"Initial Temperature of Inner Boundary Black Body is Invalid, {initial_t_inner}"
)
if not initial_t_rad.value >= -1:
raise ValueError(
f"Initial Radiative Temperature is Invalid, {initial_t_inner}"
)

# Spectrum Section Validation
spectrum_section = validated_config_dict["spectrum"]

start = spectrum_section["start"]
stop = spectrum_section["stop"]
if start.value > stop.value:
raise ValueError(
f"Time Of Explosion is an Invalid Time, {time_explosion}"
"Start Value of Spectrum Cannot be Greater than Stop Value. \n"
f"Start : {start} \n"
f"Stop : {stop}"
)

return cls(validated_config_dict)
Expand Down
1 change: 1 addition & 0 deletions tardis/io/schemas/model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ definitions:
exponent:
type: number
description: exponent for exponential density profile
minimum: 0
required:
- rho_0
- v_0
Expand Down
9 changes: 9 additions & 0 deletions tardis/io/schemas/montecarlo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ definitions:
description: the fraction of shells that have to converge to the given convergence
threshold. For example, 0.8 means that 80% of shells have to converge
to the threshold that convergence is established
minimum: 0
hold_iterations:
type: number
multipleOf: 1.0
Expand All @@ -115,11 +116,13 @@ definitions:
type: number
default: 1.0
description: damping constant
minimum: 0
threshold:
type: number
default: 0.05
description: specifies the threshold that is taken as convergence (i.e.
0.05 means that the value does not change more than 5%)
minimum: 0
t_inner:
type: object
additionalProperties: false
Expand All @@ -128,10 +131,12 @@ definitions:
type: number
default: 0.5
description: damping constant
minimum: 0
threshold:
type: number
description: specifies the threshold that is taken as convergence (i.e.
0.05 means that the value does not change more than 5%)
minimum: 0
t_rad:
type: object
additionalProperties: false
Expand All @@ -140,10 +145,12 @@ definitions:
type: number
default: 0.5
description: damping constant
minimum: 0
threshold:
type: number
description: specifies the threshold that is taken as convergence (i.e.
0.05 means that the value does not change more than 5%)
minimum: 0
required:
- threshold
w:
Expand All @@ -154,10 +161,12 @@ definitions:
type: number
default: 0.5
description: damping constant
minimum: 0
threshold:
type: number
description: specifies the threshold that is taken as convergence (i.e.
0.05 means that the value does not change more than 5%)
minimum: 0
required:
- threshold
lock_t_inner_cycles:
Expand Down

0 comments on commit a46c2cd

Please sign in to comment.