Skip to content

Commit

Permalink
Merge pull request #4828 from yut23/castro-parameters-cleanup
Browse files Browse the repository at this point in the history
BUG: fix parameter parsing for Castro and MAESTRO
  • Loading branch information
neutrinoceros authored Feb 29, 2024
2 parents ec27766 + b65b3fb commit 94547d9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
30 changes: 5 additions & 25 deletions yt/frontends/boxlib/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,9 @@ def _parse_cparams(self):
param, vals = (s.strip() for s in line.split("="))
except ValueError:
continue
# Castro and Maestro mark overridden defaults with a "[*]" before
# the parameter name
param = param.removeprefix("[*]").strip()
if param == "amr.ref_ratio":
vals = self.refine_by = int(vals[0])
elif param == "Prob.lo_bc":
Expand Down Expand Up @@ -1128,16 +1131,6 @@ def _parse_parameter_file(self):
self.parameters[fields[0]] = fields[1].strip()
line = next(f)

# runtime parameters that we overrode follow "Inputs File
# Parameters"
# skip the "====..." line
line = next(f)
for line in f:
if line.strip() == "" or "fortin parameters" in line:
continue
p, v = line.strip().split("=")
self.parameters[p] = v.strip()

# hydro method is set by the base class -- override it here
self.parameters["HydroMethod"] = "Castro"

Expand Down Expand Up @@ -1199,21 +1192,8 @@ def _parse_parameter_file(self):
fields = line.split(":")
self.parameters[fields[0]] = fields[1].strip()

with open(jobinfo_filename) as f:
# get the runtime parameters
for line in f:
try:
p, v = (_.strip() for _ in line[4:].split("=", 1))
if len(v) == 0:
self.parameters[p] = ""
else:
self.parameters[p] = _guess_pcast(v)
except ValueError:
# not a parameter line
pass

# hydro method is set by the base class -- override it here
self.parameters["HydroMethod"] = "Maestro"
# hydro method is set by the base class -- override it here
self.parameters["HydroMethod"] = "Maestro"

# set the periodicity based on the integer BC runtime parameters
periodicity = [False, False, False]
Expand Down
25 changes: 25 additions & 0 deletions yt/frontends/boxlib/tests/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,28 @@ def test_maestro_parameters():
# Check an int parameter
assert ds.parameters["s0_interp_type"] == 3
assert type(ds.parameters["s0_interp_type"]) is int # noqa: E721


castro_1d_cyl = "castro_sedov_1d_cyl_plt00150"


@requires_file(castro_1d_cyl)
def test_castro_parameters():
ds = data_dir_load(castro_1d_cyl)
assert isinstance(ds, CastroDataset)

# Modified from default (leading [*])
assert ds.parameters["castro.do_hydro"] == 1
assert ds.parameters["castro.cfl"] == 0.5
assert ds.parameters["problem.p_ambient"] == float("1e-06")
# Leading [*] should be removed from the parameter name
assert "[*] castro.do_hydro" not in ds.parameters

# Not modified from default
assert ds.parameters["castro.pslope_cutoff_density"] == float("-1e+20")
assert ds.parameters["castro.do_sponge"] == 0
assert ds.parameters["problem.dens_ambient"] == 1
assert ds.parameters["eos.eos_assume_neutral"] == 1

# Empty string value
assert ds.parameters["castro.stopping_criterion_field"] is None

0 comments on commit 94547d9

Please sign in to comment.