From b65b3fb6887ed30d2fb3d8f27fb6901ea7e99297 Mon Sep 17 00:00:00 2001 From: "Eric T. Johnson" Date: Fri, 23 Feb 2024 15:28:15 -0500 Subject: [PATCH] BUG: fix parameter parsing for Castro and MAESTRO Castro (since 18.04), MAESTROeX (since 20.09), and MAESTRO (since 2013) add a prefix `[*]` before runtime parameters that are changed from their defaults. This was being handled by the Dataset subclasses individually, leading to duplicated and inconsistent logic (CastroDataset wasn't stripping the parameter names, leading to duplicates with trailing spaces). This change moves the prefix handling into BoxlibDataset, and removes the prefix so analysis scripts don't need to check for both versions in `ds.parameters`. --- yt/frontends/boxlib/data_structures.py | 30 ++++------------------- yt/frontends/boxlib/tests/test_outputs.py | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/yt/frontends/boxlib/data_structures.py b/yt/frontends/boxlib/data_structures.py index d7c8e087a71..2725275896f 100644 --- a/yt/frontends/boxlib/data_structures.py +++ b/yt/frontends/boxlib/data_structures.py @@ -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": @@ -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" @@ -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] diff --git a/yt/frontends/boxlib/tests/test_outputs.py b/yt/frontends/boxlib/tests/test_outputs.py index d3e9e5d91e5..f0d3bb2647d 100644 --- a/yt/frontends/boxlib/tests/test_outputs.py +++ b/yt/frontends/boxlib/tests/test_outputs.py @@ -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