def checkManning(xml): fe_list = asearch.find_path(xml, ["state", "field evaluators"]) for eval in fe_list: ename = eval.getName() if ename.endswith( 'manning_coefficient') and not ename.startswith('snow'): eval_type = eval.getElement('field evaluator type') if eval_type.getValue() == 'independent variable': func_reg = eval.getElement("function") for reg in func_reg: comp_entries = asearch.findall_name(reg, ['components']) if len(comp_entries) > 1: # previous iterations of this script were broken... for entry in comp_entries[1:]: reg.remove(entry) fixed = False if not fixed: try: comp = reg.getElement('component') except aerrors.MissingXMLError: pass else: reg.pop('component') assert len(asearch.findall_name(reg, 'components')) == 0 reg.append( parameter.ArrayStringParameter( 'components', ['cell', 'boundary_face'])) fixed = True if not fixed: try: comp = reg.getElement('components') except aerrors.MissingXMLError: pass else: reg.pop('components') assert len(asearch.findall_name(reg, 'components')) == 0 reg.append( parameter.ArrayStringParameter( 'components', ['cell', 'boundary_face'])) fixed = True if not fixed: print(reg.__str__().decode('utf-8')) raise aerrors.MissingXMLError( 'Missing "component" or "components"')
def createFunctionSpec(spec_name, region, component, func): """Create a Function spec on a 'region' and 'component'""" if type(region) is str: region_p = parameter.StringParameter("region", region) else: region_p = parameter.ArrayStringParameter("regions", region) if type(component) is str: component_p = parameter.StringParameter("component", component) else: component_p = parameter.ArrayStringParameter("components", component) pl = parameter_list.ParameterList(spec_name) pl.append(region_p) pl.append(entity_p) pl.sublist("function").append(func) return pl
def eval_snow_swe(): swe = parameter_list.ParameterList("snow-swe") swe.append( parameter.StringParameter("field evaluator type", "multiplicative evaluator")) swe.append( parameter.ArrayStringParameter( "evaluator dependencies", ["snow-depth", "snow-density", "snow-cell_volume"])) swe.append(parameter.DoubleParameter("coefficient", 1.e-3)) return swe
def checkManning(xml): fe_list = asearch.gen_by_path(xml, ["state", "field evaluators"]) for eval in fe_list: if eval.get("name").endswith('manning_coefficient'): eval_type = eval.getElement('field evaluator type') if eval_type.getValue() == 'independent variable': func_reg = eval.getElement("function") for reg in func_reg: fixed = False if not fixed: try: comp = reg.getElement('component') except aerrors.MissingXMLError: pass else: reg.pop('component') reg.append( parameter.ArrayStringParameter( 'components', ['cell', 'boundary_face'])) fixed = True if not fixed: try: comp = reg.getElement('components') except aerrors.MissingXMLError: pass else: reg.pop('components') reg.append( parameter.ArrayStringParameter( 'components', ['cell', 'boundary_face'])) fixed = True if not fixed: print(reg.__str__().decode('utf-8')) raise aerrors.MissingXMLError( 'Missing "component" or "components"')