From c39a817da5f2c641c48b865632ca3dbc6fd73dd6 Mon Sep 17 00:00:00 2001 From: Ethan Coon Date: Fri, 8 Mar 2024 13:32:29 -0700 Subject: [PATCH] standardizing names, removing WRM in favor of water retention model, removing via names in favor of comma, etc --- ...oil_resistance_sakagucki_zeng_evaluator.hh | 4 +- .../soil_resistance_sakagucki_zeng_model.hh | 2 +- .../wrm/rel_perm_evaluator.hh | 4 +- .../wrm/rel_perm_evaluator_reg.hh | 2 +- .../wrm/rel_perm_frzBC_evaluator.hh | 4 +- .../wrm/rel_perm_frzBC_evaluator_reg.hh | 2 +- .../wrm/wrm_brooks_corey.cc | 4 +- .../wrm/wrm_brooks_corey.hh | 10 +- .../wrm/wrm_evaluator.hh | 3 +- .../wrm/wrm_evaluator_reg.hh | 3 +- .../wrm/wrm_permafrost_evaluator_reg.hh | 2 +- .../land_cover/land_cover_evaluator_reg.hh | 6 +- testing/ats-regression-tests | 2 +- tools/input_converters/xml-1.4-master.py | 151 +++++++++--------- 14 files changed, 101 insertions(+), 98 deletions(-) diff --git a/src/pks/flow/constitutive_relations/sources/soil_resistance_sakagucki_zeng_evaluator.hh b/src/pks/flow/constitutive_relations/sources/soil_resistance_sakagucki_zeng_evaluator.hh index 82127bec4..5dce0356e 100644 --- a/src/pks/flow/constitutive_relations/sources/soil_resistance_sakagucki_zeng_evaluator.hh +++ b/src/pks/flow/constitutive_relations/sources/soil_resistance_sakagucki_zeng_evaluator.hh @@ -26,9 +26,9 @@ referred to Sakagucki and Zeng (2009). through method 2 in Ma et al. (1999). Originally this method is from Lenhard et al. (1989). - - If `"Brooks-Corey`" is used for WRM, `"Brooks Corey lambda [-]`" will + - If `"Brooks-Corey`" is used for WRM, `"Brooks-Corey lambda [-]`" will be used to determine Clapp-Hornberger-b, which is the reciprocal of - `"Brooks Corey lambda [-]`". + `"Brooks-Corey lambda [-]`". - `"residual saturation [-]`" ``[double]`` **0.0** diff --git a/src/pks/flow/constitutive_relations/sources/soil_resistance_sakagucki_zeng_model.hh b/src/pks/flow/constitutive_relations/sources/soil_resistance_sakagucki_zeng_model.hh index d5727cc0c..8a3475062 100644 --- a/src/pks/flow/constitutive_relations/sources/soil_resistance_sakagucki_zeng_model.hh +++ b/src/pks/flow/constitutive_relations/sources/soil_resistance_sakagucki_zeng_model.hh @@ -81,7 +81,7 @@ class SoilResistanceSakaguckiZengModel { b_ = 1. / lambda; } } else if (plist_.get("wrm type") == "Brooks-Corey") { - double lambda = plist_.get("Brooks Corey lambda [-]"); + double lambda = plist_.get("Brooks-Corey lambda [-]"); b_ = 1. / lambda; } else { b_ = plist_.get("Clapp-Hornberger b [-]"); diff --git a/src/pks/flow/constitutive_relations/wrm/rel_perm_evaluator.hh b/src/pks/flow/constitutive_relations/wrm/rel_perm_evaluator.hh index 8b165e47c..33b23dcdc 100644 --- a/src/pks/flow/constitutive_relations/wrm/rel_perm_evaluator.hh +++ b/src/pks/flow/constitutive_relations/wrm/rel_perm_evaluator.hh @@ -143,8 +143,8 @@ parameters to Brooks-Corey parameters. - - + + diff --git a/src/pks/flow/constitutive_relations/wrm/rel_perm_evaluator_reg.hh b/src/pks/flow/constitutive_relations/wrm/rel_perm_evaluator_reg.hh index 8292da1c5..be1ee796e 100644 --- a/src/pks/flow/constitutive_relations/wrm/rel_perm_evaluator_reg.hh +++ b/src/pks/flow/constitutive_relations/wrm/rel_perm_evaluator_reg.hh @@ -14,7 +14,7 @@ namespace Flow { // registry of method Utils::RegisteredFactory - RelPermEvaluator::factory_("relative permeability, van Genuchten"); + RelPermEvaluator::factory_("relative permeability, water retention model"); } // namespace Flow } // namespace Amanzi diff --git a/src/pks/flow/constitutive_relations/wrm/rel_perm_frzBC_evaluator.hh b/src/pks/flow/constitutive_relations/wrm/rel_perm_frzBC_evaluator.hh index aca583e54..c50c08018 100644 --- a/src/pks/flow/constitutive_relations/wrm/rel_perm_frzBC_evaluator.hh +++ b/src/pks/flow/constitutive_relations/wrm/rel_perm_frzBC_evaluator.hh @@ -112,8 +112,8 @@ parameters to Brooks-Corey parameters. - - + + diff --git a/src/pks/flow/constitutive_relations/wrm/rel_perm_frzBC_evaluator_reg.hh b/src/pks/flow/constitutive_relations/wrm/rel_perm_frzBC_evaluator_reg.hh index e3bd8198e..3780d1633 100644 --- a/src/pks/flow/constitutive_relations/wrm/rel_perm_frzBC_evaluator_reg.hh +++ b/src/pks/flow/constitutive_relations/wrm/rel_perm_frzBC_evaluator_reg.hh @@ -14,7 +14,7 @@ namespace Flow { // registry of method Utils::RegisteredFactory - RelPermFrzBCEvaluator::factory_("relative permeability, freezing Brooks Corey"); + RelPermFrzBCEvaluator::factory_("relative permeability, freezing Brooks-Corey"); } // namespace Flow } // namespace Amanzi diff --git a/src/pks/flow/constitutive_relations/wrm/wrm_brooks_corey.cc b/src/pks/flow/constitutive_relations/wrm/wrm_brooks_corey.cc index 998ae0f3d..388356468 100644 --- a/src/pks/flow/constitutive_relations/wrm/wrm_brooks_corey.cc +++ b/src/pks/flow/constitutive_relations/wrm/wrm_brooks_corey.cc @@ -30,9 +30,9 @@ WRMBrooksCorey::WRMBrooksCorey(Teuchos::ParameterList& plist) : plist_(plist) void WRMBrooksCorey::InitializeFromPlist_() { - lambda_ = plist_.get("Brooks Corey lambda [-]"); + lambda_ = plist_.get("Brooks-Corey lambda [-]"); b_ = 1. / lambda_; // clapp hornberger b - p_sat_ = plist_.get("Brooks Corey saturated matric suction [Pa]"); + p_sat_ = plist_.get("Brooks-Corey saturated matric suction [Pa]"); sr_ = plist_.get("residual saturation [-]", 0.0); s0_ = 1.0 - plist_.get("smoothing interval width [saturation]", 0.0); diff --git a/src/pks/flow/constitutive_relations/wrm/wrm_brooks_corey.hh b/src/pks/flow/constitutive_relations/wrm/wrm_brooks_corey.hh index fcfc7a4ca..c235c751a 100644 --- a/src/pks/flow/constitutive_relations/wrm/wrm_brooks_corey.hh +++ b/src/pks/flow/constitutive_relations/wrm/wrm_brooks_corey.hh @@ -8,7 +8,7 @@ Bo Gao (gaob@ornl.gov) */ -//! WRMBrooksCorey : water retention model using Brooks Corey's parameterization +//! WRMBrooksCorey : water retention model using Brooks-Corey's parameterization /*! Brooks-Corey's water retention curve, typically used to determine relative @@ -19,8 +19,8 @@ to Brooks-Corey parameters. .. admonition:: WRM-Brooks-Corey-spec * `"region`" ``[string]`` Region to which this applies - * `"Brooks Corey lambda [-]`" ``[double]`` Brooks Corey's lambda - * `"Brooks Corey saturated matric suction [Pa]`" ``[double]`` Brooks Corey + * `"Brooks-Corey lambda [-]`" ``[double]`` Brooks-Corey's lambda + * `"Brooks-Corey saturated matric suction [Pa]`" ``[double]`` Brooks-Corey saturated matric suction in Pa END @@ -35,8 +35,8 @@ Example: - - + + diff --git a/src/pks/flow/constitutive_relations/wrm/wrm_evaluator.hh b/src/pks/flow/constitutive_relations/wrm/wrm_evaluator.hh index ff2b73901..5fabbbf16 100644 --- a/src/pks/flow/constitutive_relations/wrm/wrm_evaluator.hh +++ b/src/pks/flow/constitutive_relations/wrm/wrm_evaluator.hh @@ -114,8 +114,7 @@ class WRMEvaluator : public EvaluatorSecondaryMonotypeCV { Key cap_pres_key_; private: - static Utils::RegisteredFactory factory_; - static Utils::RegisteredFactory factory2_; + static Utils::RegisteredFactory reg_; }; } // namespace Flow diff --git a/src/pks/flow/constitutive_relations/wrm/wrm_evaluator_reg.hh b/src/pks/flow/constitutive_relations/wrm/wrm_evaluator_reg.hh index c5647d14c..f07f4bfb3 100644 --- a/src/pks/flow/constitutive_relations/wrm/wrm_evaluator_reg.hh +++ b/src/pks/flow/constitutive_relations/wrm/wrm_evaluator_reg.hh @@ -13,8 +13,7 @@ namespace Amanzi { namespace Flow { // registry of method -Utils::RegisteredFactory WRMEvaluator::factory_("WRM"); -Utils::RegisteredFactory WRMEvaluator::factory2_("wrm"); +Utils::RegisteredFactory WRMEvaluator::reg_("water retention model"); } // namespace Flow } // namespace Amanzi diff --git a/src/pks/flow/constitutive_relations/wrm/wrm_permafrost_evaluator_reg.hh b/src/pks/flow/constitutive_relations/wrm/wrm_permafrost_evaluator_reg.hh index ceb139ced..5547a12c9 100644 --- a/src/pks/flow/constitutive_relations/wrm/wrm_permafrost_evaluator_reg.hh +++ b/src/pks/flow/constitutive_relations/wrm/wrm_permafrost_evaluator_reg.hh @@ -21,7 +21,7 @@ namespace Flow { // registry of method Utils::RegisteredFactory - WRMPermafrostEvaluator::factory_("permafrost WRM"); + WRMPermafrostEvaluator::factory_("water retention model with ice"); } // namespace Flow } // namespace Amanzi diff --git a/src/pks/surface_balance/constitutive_relations/land_cover/land_cover_evaluator_reg.hh b/src/pks/surface_balance/constitutive_relations/land_cover/land_cover_evaluator_reg.hh index 9e923ee0f..275d04c2e 100644 --- a/src/pks/surface_balance/constitutive_relations/land_cover/land_cover_evaluator_reg.hh +++ b/src/pks/surface_balance/constitutive_relations/land_cover/land_cover_evaluator_reg.hh @@ -63,7 +63,7 @@ Utils::RegisteredFactory PETPriestleyTaylorEvaluator::reg_("potential evapotranspiration, Priestley-Taylor"); Utils::RegisteredFactory - EvaporationDownregulationEvaluator::reg_("evaporation downregulation via soil resistance"); + EvaporationDownregulationEvaluator::reg_("evaporation downregulation, soil resistance"); Utils::RegisteredFactory PlantWiltingFactorEvaluator::reg_("plant wilting factor"); @@ -72,10 +72,10 @@ Utils::RegisteredFactory RootingDepthFractionEvaluator::reg_("root fraction"); Utils::RegisteredFactory - TranspirationDistributionEvaluator::reg_("transpiration distribution via rooting depth"); + TranspirationDistributionEvaluator::reg_("transpiration distribution, rooting depth"); Utils::RegisteredFactory TranspirationDistributionRelPermEvaluator::reg_( - "transpiration distribution via relative permeability"); + "transpiration distribution, relative permeability"); Utils::RegisteredFactory SnowMeltRateEvaluator::reg_("snow melt rate"); diff --git a/testing/ats-regression-tests b/testing/ats-regression-tests index b95c84799..8a960a511 160000 --- a/testing/ats-regression-tests +++ b/testing/ats-regression-tests @@ -1 +1 @@ -Subproject commit b95c84799dac84a270dd039b28d9af872d96f0de +Subproject commit 8a960a5119568a6e193dff5801045edda46c4e06 diff --git a/tools/input_converters/xml-1.4-master.py b/tools/input_converters/xml-1.4-master.py index f796472bf..b397ef0aa 100644 --- a/tools/input_converters/xml-1.4-master.py +++ b/tools/input_converters/xml-1.4-master.py @@ -18,6 +18,10 @@ from amanzi_xml.common import parameter, parameter_list from convert_parameters_vg2bc import get_bc_param_from_vg + +# +# helper functions +# def rename_element(xml, old, new): try: child = asearch.child_by_name(xml, old) @@ -26,7 +30,24 @@ def rename_element(xml, old, new): else: child.setName(new) -def find_wrm_list(xml): +def retype_evaluator(xml, old_type, new_type): + for e in asearch.find_path(xml, ["state", "evaluators"], no_skip=True): + e_type = e.getElement("evaluator type") + if e_type.getValue() == old_type: + e_type.setValue(new_type) + +def replace_string_in_name(xml, old, new): + for match in xml.findall('.//'): + if old in match.getName(): + match.setName(match.getName().replace(old, new)) + +def replace_string_in_value(xml, old, new): + for match in xml.findall('.//'): + if isinstance(match, parameter.Parameter) and match.getType() == 'string' and old in match.getValue(): + match.setValue(match.getValue().replace(old, new)) + + +def _find_wrm_list(xml): """Finds the list, either in a flow PK or in a saturation evaluator""" try: return asearch.find_path(xml, ["PKs", "water retention evaluator"]) @@ -41,33 +62,6 @@ def find_wrm_list(xml): return None -def mafic_to_cap_pres(xml): - """Converts mafic potential --> capillary pressure in land cover list""" - try: - lc_list = asearch.find_path(xml, ["state", "initial conditions", "land cover types"], no_skip=True) - except aerrors.MissingXMLError: - return - for lc in lc_list: - rename_element(lc, "mafic potential at fully closed stomata [Pa]", - "capillary pressure at fully closed stomata [Pa]") - rename_element(lc, "mafic potential at fully open stomata [Pa]", - "capillary pressure at fully open stomata [Pa]") - - - -def rooting_depth_fraction(xml): - """Variable default name change: rooting depth fraction --> root fraction""" - try: - rf = asearch.find_path(xml, ["state", "evaluators", "rooting_depth_fraction"], no_skip=True) - except aerrors.MissingXMLError: - pass - else: - etype = rf.getElement("evaluator type") - if etype.getValue() == "rooting depth fraction": - etype.setValue("root fraction") - rf.setName("root_fraction") - - def _has_surface_temp(sT): if sT.getElement("evaluator type").getValue() == "independent variable": try: @@ -187,28 +181,33 @@ def surface_temp(xml): else: if st.getValue() == "surface-temperature": st.setValue("snow-temperature") - -def transpiration_relperm(xml): - """Change the transpiration eval from the old default to the new default. - Old was based on only TRF, new is based on both TRF and soil k_rel - """ +def mafic_to_cap_pres(xml): + """Converts mafic potential --> capillary pressure in land cover list""" try: - trans = asearch.find_path(xml, ["state", "evaluators", "transpiration"], no_skip=True) + lc_list = asearch.find_path(xml, ["state", "initial conditions", "land cover types"], no_skip=True) except aerrors.MissingXMLError: return + for lc in lc_list: + rename_element(lc, "mafic potential at fully closed stomata [Pa]", + "capillary pressure at fully closed stomata [Pa]") + rename_element(lc, "mafic potential at fully open stomata [Pa]", + "capillary pressure at fully open stomata [Pa]") + + +def transpiration_relperm(xml): + """Change the transpiration eval from the old default to the new default. - tt = trans.getElement("evaluator type") - if tt.getValue() == "transpiration distribution via rooting depth": - tt.setValue("transpiration distribution via relative permeability") + Old was based on only TRF, new is based on both TRF and soil k_rel + """ + retype_evaluator(xml, "transpiration distribution, rooting depth", + "transpiration distribution, relative permeability") try: - wp = asearch.find_path(xml, ["state", "evaluators", "plant_wilting_factor"], no_skip=True) + asearch.find_path(xml, ["state", "evaluators"]).pop("plant_wilting_factor") except aerrors.MissingXMLError: pass - else: - asearch.find_path(xml, ["state", "evaluators"]).pop("plant_wilting_factor") def add_soil_resistance(xml, rs_option="Sakagucki-Zeng"): @@ -228,7 +227,7 @@ def add_soil_resistance(xml, rs_option="Sakagucki-Zeng"): seb_eval_list = next(e for e in eval_list if e.getElement("evaluator type").getValue() in ['surface energy balance, two components', 'surface energy balance, three components', - 'evaporation downregulation via soil resistance']) + 'evaporation downregulation, soil resistance']) except StopIteration: # no evap, so no soil resistance return @@ -279,7 +278,7 @@ def add_wrm_to_model_parameters(xml): Moves Richards PK-->water retention evaluator-->model parameters list to state->model parameters. """ - wrm_list = find_wrm_list(xml) + wrm_list = _find_wrm_list(xml) if wrm_list is None: return @@ -293,8 +292,12 @@ def add_wrm_to_model_parameters(xml): state_list = asearch.find_path(xml, ["state"]) model_par_list = state_list.sublist("model parameters") if not model_par_list.isElement("WRM parameters"): - wrm_param_list = asearch.remove_element(wrm_list, ["WRM parameters"], False, False) - model_par_list.append(wrm_param_list) + try: + wrm_param_list = asearch.remove_element(wrm_list, ["WRM parameters"], False, False) + except aerrors.MissingXMLError: + pass + else: + model_par_list.append(wrm_param_list) def del_lc_params(xml): @@ -344,7 +347,7 @@ def add_rel_perm(xml, relp_option="relative permeability, van Genuchten"): if relp_option == "relative permeability, van Genuchten": relp_list.append(parameter.StringParameter("model parameters", "WRM parameters")) else: - assert(relp_option == "relative permeability, freezing Brooks Corey") + assert(relp_option == "relative permeability, freezing Brooks-Corey") relp_list.append(parameter.StringParameter("model parameters", "freezing rel perm parameters")) relp_list.append(parameter.DoubleParameter("omega [-]", 2)) @@ -360,13 +363,15 @@ def move_wrm_relperm_params_to_relperm(xml, relp_name, par): if relp_list.isElement(par): return - wrm_list = find_wrm_list(xml) + wrm_list = _find_wrm_list(xml) if wrm_list is None: return if wrm_list.isElement(par): relp_list.append(wrm_list.pop(par)) - + + + def move_wrm_to_state_evaluators(xml): """Last step -- moves the list out of Richards PK to state""" @@ -377,9 +382,9 @@ def move_wrm_to_state_evaluators(xml): wrm = pk.pop("water retention evaluator") wrm.setName("saturation_liquid") if pk_type == "permafrost flow": - wrm.setParameter("evaluator type", "string", "permafrost WRM") + wrm.setParameter("evaluator type", "string", "water retention model with ice") else: - wrm.setParameter("evaluator type", "string", "WRM") + wrm.setParameter("evaluator type", "string", "water retention model") wrm2 = copy.deepcopy(wrm) wrm2.setName("saturation_gas") @@ -420,37 +425,33 @@ def copy_element(a_soil_list, var_name, var_type): m = s.getElement("van Genuchten m [-]").getValue() n = 1 / (1 - m) bc_satp, bc_lambda_recip = get_bc_param_from_vg(alpha, n) - slist.append(parameter.DoubleParameter("Brooks Corey saturated matric suction [Pa]", bc_satp)) - slist.append(parameter.DoubleParameter("Brooks Corey lambda [-]", 1 / bc_lambda_recip)) + slist.append(parameter.DoubleParameter("Brooks-Corey saturated matric suction [Pa]", bc_satp)) + slist.append(parameter.DoubleParameter("Brooks-Corey lambda [-]", 1 / bc_lambda_recip)) -def rename_wrm_rel_perm_evaluator(xml): - for rel_perm_eval in asearch.find_path(xml, ["state", "evaluators"], no_skip=True): - eval_type = rel_perm_eval.getElement("evaluator type") - if eval_type.getValue() == "WRM rel perm": - eval_type.setValue("relative permeability, van Genuchten") - - def lowercase_wrmtype(xml): - def _wrmtype(match, wrmtype_uppercase): - name = match.getName() - if wrmtype_uppercase in name: - name = name.replace(wrmtype_uppercase, 'wrm type') - match.setName(name) - - matches = xml.findall('.//') - for match in matches: - for i in ['WRM Type', 'WRM type']: - _wrmtype(match, i) + rename_element(xml, "WRM type", "wrm type") + rename_element(xml, "WRM Type", "wrm type") + rename_element(xml, "permafrost WRM type", "permafrost wrm type") + rename_element(xml, "permafrost WRM Type", "permafrost wrm type") + + +def brooks_corey(xml): + replace_string_in_name(xml, "Brooks Corey", "Brooks-Corey") + replace_string_in_value(xml, "Brooks Corey", "Brooks-Corey") def update(xml, transpiration_distribution=False, frozen_krel=False, soil_res='Sakagucki-Zeng'): """generic update calls all needed things""" mafic_to_cap_pres(xml) - rooting_depth_fraction(xml) + retype_evaluator(xml, "rooting depth fraction", "root fraction") surface_temp(xml) + retype_evaluator(xml, "transpiration distribution via rooting depth", "transpiration distribution, rooting depth") + retype_evaluator(xml, "transpiration distribution via relative permeability", "transpiration distribution, relative permeability") + retype_evaluator(xml, "evaporation downregulation via soil resistance", "evaporation downregulation, soil resistance") + if transpiration_distribution: transpiration_relperm(xml) @@ -459,19 +460,23 @@ def update(xml, transpiration_distribution=False, frozen_krel=False, del_lc_params(xml) if frozen_krel: - relp_name = add_rel_perm(xml, "relative permeability, freezing Brooks Corey") + relp_name = add_rel_perm(xml, "relative permeability, freezing Brooks-Corey") add_frz_relp_to_model_parameters(xml) else: - relp_name = add_rel_perm(xml, "relative permeability, van Genuchten") + relp_name = add_rel_perm(xml, "relative permeability, water retention model") if relp_name is not None: for par in ["minimum rel perm cutoff", "use surface rel perm"]: move_wrm_relperm_params_to_relperm(xml, relp_name, par) move_wrm_to_state_evaluators(xml) - rename_wrm_rel_perm_evaluator(xml) + retype_evaluator(xml, "WRM rel perm", "relative permeability, water retention model") + retype_evaluator(xml, "relative permeability, van Genuchten", "relative permeability, water retention model") + retype_evaluator(xml, "WRM", "water retention model") + retype_evaluator(xml, "permafrost WRM", "water retention model with ice") lowercase_wrmtype(xml) - + brooks_corey(xml) + if __name__ == "__main__": import argparse