Beispiel #1
0
def snow_distribution(xml):
    for snow_dist_pk in asearch.generateElementByNamePath(
            xml, "PKs/snow distribution"):
        snow_dist_pk.append(
            parameter.DoubleParameter("distribution time", 86400.0))
        if snow_dist_pk.isElement("primary variable key") and \
             asearch.childByName(snow_dist_pk,"primary variable key").get("value") == "surface-precipitation_snow" and \
             snow_dist_pk.isElement("conserved quantity key") and \
             asearch.childByName(snow_dist_pk,"conserved quantity key").get("value") == "precipitation-snow":
            asearch.childByName(snow_dist_pk, "conserved quantity key").set(
                "value", "surface-precipitation-snow")

    for ssk in asearch.generateElementByNamePath(
            xml, "state/field evaluators/surface-snow_skin_potential"):
        if not ssk.isElement("dt factor"):
            ssk.append(parameter.DoubleParameter("dt factor", 86400.0))
        else:
            asearch.childByName(ssk, "dt factor").set("value", "86400.0")

    for ssc in asearch.generateElementByNamePath(
            xml, "state/field evaluators/surface-snow_conductivity"):
        if not ssc.isElement("include dt factor"):
            ssc.append(parameter.BoolParameter("include dt factor", True))
        else:
            asearch.childByName(ssc, "include dt factor").set("value", "true")

        if not ssc.isElement("dt factor"):
            ssc.append(parameter.DoubleParameter("dt factor", 86400.0))
        else:
            asearch.childByName(ssc, "dt factor").set("value", "86400.0")
Beispiel #2
0
def snow_distribution(xml):
    for snow_dist_pk in asearch.generateElementByNamePath(xml, "PKs/snow distribution"):
        snow_dist_pk.append(parameter.DoubleParameter("distribution time", 86400.0))
        if snow_dist_pk.isElement("primary variable key") and \
             asearch.childByName(snow_dist_pk,"primary variable key").get("value") == "surface-precipitation_snow" and \
             snow_dist_pk.isElement("conserved quantity key") and \
             asearch.childByName(snow_dist_pk,"conserved quantity key").get("value") == "precipitation-snow":
            asearch.childByName(snow_dist_pk,"conserved quantity key").set("value", "surface-precipitation-snow")
        
    for ssk in asearch.generateElementByNamePath(xml, "state/field evaluators/surface-snow_skin_potential"):
        if not ssk.isElement("dt factor"):
            ssk.append(parameter.DoubleParameter("dt factor", 86400.0))
        else:
            asearch.childByName(ssk, "dt factor").set("value","86400.0")

    for ssc in asearch.generateElementByNamePath(xml, "state/field evaluators/surface-snow_conductivity"):
        if not ssc.isElement("include dt factor"):
            ssc.append(parameter.BoolParameter("include dt factor", True))
        else:
            asearch.childByName(ssc, "include dt factor").set("value","true")

        if not ssc.isElement("dt factor"):
            ssc.append(parameter.DoubleParameter("dt factor", 86400.0))
        else:
            asearch.childByName(ssc, "dt factor").set("value","86400.0")
Beispiel #3
0
def primary_variable(xml):
    for pv in asearch.generateElementByNamePath(xml, "primary variable"):
        pv.setName("primary variable key")
    for pv in asearch.generateElementByNamePath(xml, "primary variable key"):
        if pv.value == "ponded_depth":
            pv.setValue("surface-ponded_depth")
        if pv.value == "snow_depth":
            pv.setValue("surface-snow_depth")
Beispiel #4
0
def primary_variable(xml):
    for pv in asearch.generateElementByNamePath(xml, "primary variable"):
        pv.setName("primary variable key")
    for pv in asearch.generateElementByNamePath(xml, "primary variable key"):
        if pv.value == "ponded_depth":
            pv.setValue("surface-ponded_depth")
        if pv.value == "snow_depth":
            pv.setValue("surface-snow_depth")
Beispiel #5
0
def snow_distribution(xml):
    for snow_dist_pk in asearch.generateElementByNamePath(xml, "PKs/snow distribution"):
        if snow_dist_pk.isElement("primary variable key") and \
             asearch.childByName(snow_dist_pk,"primary variable key").get("value") == "surface-precipitation_snow":
            asearch.childByName(snow_dist_pk,"primary variable key").set("value", "snow-precipitation")
        if snow_dist_pk.isElement("conserved quantity key") and \
             asearch.childByName(snow_dist_pk,"conserved quantity key").get("value") == "surface-precipitation_snow":
            asearch.childByName(snow_dist_pk,"conserved quantity key").set("value", "snow-precipitation")
        if snow_dist_pk.isElement("domain name") and \
           asearch.childByName(snow_dist_pk,"domain name").get("value") == "surface":
            asearch.childByName(snow_dist_pk,"domain name").set("value", "snow")
    
    for ssk in asearch.generateElementByNamePath(xml, "state/field evaluators/snow-conductivity"):
        if ssk.isElement("height key"):
            asearch.childByName(ssk, "height key").set("value", "snow-precipitation")
Beispiel #6
0
def snow_depth(xml):
    for seb_pk in asearch.generateElementByNamePath(xml, "PKs/SEB"):
        if seb_pk.isElement("primary variable key") and \
             asearch.childByName(seb_pk,"primary variable key").get("value") == "surface-snow_depth" and \
             seb_pk.isElement("conserved quantity key") and \
             asearch.childByName(seb_pk,"conserved quantity key").get("value") == "snow_depth":
            asearch.childByName(seb_pk,"conserved quantity key").set("value", "surface-snow_depth")
Beispiel #7
0
def fixSolvers(xml):
    for diff in search.generateElementByNamePath(xml, "Diffusion"):
        _fixDiffusion(diff, False, True)

    need_pc = True
    for pk in search.generateElementByNamePath(xml, "PK type"):
        if pk.get("value") == "new permafrost model no SC" or \
           pk.get("value") == "subsurface permafrost" or \
           pk.get("value") == "coupled water":
            need_pc = False
    for diff in search.generateElementByNamePath(xml, "Diffusion PC"):
        _fixDiffusion(diff, need_pc, True)

    for solver in search.generateElementByNamePath(xml, "Coupled PC"):
        _fixPC(solver.sublist("preconditioner"), "boomer amg", True)

    for solver in search.generateElementByNamePath(xml, "Coupled Solver"):
        _fixLinOp(solver)
def update(xml, clobber=True):
    for lin_op_list in asearch.generateElementByNamePath(xml, "linear solver"):
        if asearch.childByNamePath(lin_op_list, "iterative method").get("value") == "nka":
            lin_op_list.setParameter("iterative method", "string", "gmres")
            lin_op_list.pop("nka parameters")
            lin_op_list.append(get_gmres())
        elif clobber and asearch.childByNamePath(lin_op_list, "iterative method").get("value") == "gmres":
            lin_op_list.pop("gmres parameters")
            lin_op_list.append(get_gmres())
Beispiel #9
0
def fixVerboseObject(xml):
    for vo in asearch.generateElementByNamePath(xml, "VerboseObject"):
        vo.set("name", "verbose object")
        try:
            vlev = asearch.childByNamePath(vo, "Verbosity Level")
        except aerrors.MissingXMLError:
            pass
        else:
            vlev.set("name", "verbosity level")
Beispiel #10
0
def write_new_xml(testname, testlog):
    """Adds the needed magic to a new xml file."""
    print("Renaming: {0}.xml to {0}_orig.xml".format(testname), file=testlog)
    os.rename(testname + ".xml", testname + "_orig.xml")

    xml = aio.fromFile(testname + "_orig.xml", True)

    # vis by list of cycles
    try:
        vis = asearch.getElementByNamePath(xml, "visualization")
    except aerrors.MissingXMLError:
        pass
    else:
        for i in range(len(vis)):
            vis.pop(vis[0].get('name'))
        vis.setParameter("cycles", "Array(int)", find_vis_cycles(testname))
        vis.setParameter("file name base", "string", "visdump")

    try:
        viss = asearch.getElementByNamePath(xml, "visualization surface")
    except aerrors.MissingXMLError:
        pass
    else:
        for i in range(len(viss)):
            viss.pop(viss[0].get('name'))
        viss.setParameter("cycles", "Array(int)", find_vis_cycles(testname))
        viss.setParameter("file name base", "string", "visdump_surface")

    # update timestep controller, nonlinear solvers
    for ti in asearch.generateElementByNamePath(xml, "time integrator"):
        asearch.generateElementByNamePath(
            ti, "limit iterations").next().setValue(100)
        asearch.generateElementByNamePath(
            ti, "diverged tolerance").next().setValue(1.e10)

        asearch.getElementByNamePath(
            ti, "timestep controller type").setValue("from file")
        ts_hist = ti.sublist("timestep controller from file parameters")
        ts_hist.setParameter("file name", "string",
                             "../data/{0}_dts.h5".format(testname))

    print("Writing: {0}.xml".format(testname), file=testlog)
    aio.toFile(xml, "{0}.xml".format(testname))
Beispiel #11
0
def seepage_face_bcs(xml):
    for bclist in asearch.generateElementByNamePath(xml, "boundary conditions"):
        if bclist.isElement("seepage face"):
            agroup = bclist.sublist("seepage face")[0]
            if agroup.isElement("boundary pressure"):
                bclist.sublist("seepage face").set("name", "seepage face pressure")
            elif agroup.isElement("boundary head"):
                bclist.sublist("seepage face").set("name", "seepage face head")
            else:
                raise RuntimeError("unknown seepage condition")
def update(xml, clobber=True):
    for lin_op_list in asearch.generateElementByNamePath(xml, "linear solver"):
        if asearch.childByNamePath(lin_op_list,
                                   "iterative method").get("value") == "nka":
            lin_op_list.setParameter("iterative method", "string", "gmres")
            lin_op_list.pop("nka parameters")
            lin_op_list.append(get_gmres())
        elif clobber and asearch.childByNamePath(
                lin_op_list, "iterative method").get("value") == "gmres":
            lin_op_list.pop("gmres parameters")
            lin_op_list.append(get_gmres())
Beispiel #13
0
def snow_distribution(xml):
    for snow_dist_pk in asearch.generateElementByNamePath(
            xml, "PKs/snow distribution"):
        if snow_dist_pk.isElement("primary variable key") and \
             asearch.childByName(snow_dist_pk,"primary variable key").get("value") == "surface-precipitation_snow":
            asearch.childByName(snow_dist_pk, "primary variable key").set(
                "value", "snow-precipitation")
        if snow_dist_pk.isElement("conserved quantity key") and \
             asearch.childByName(snow_dist_pk,"conserved quantity key").get("value") == "surface-precipitation_snow":
            asearch.childByName(snow_dist_pk, "conserved quantity key").set(
                "value", "snow-precipitation")
        if snow_dist_pk.isElement("domain name") and \
           asearch.childByName(snow_dist_pk,"domain name").get("value") == "surface":
            asearch.childByName(snow_dist_pk,
                                "domain name").set("value", "snow")

    for ssk in asearch.generateElementByNamePath(
            xml, "state/field evaluators/snow-conductivity"):
        if ssk.isElement("height key"):
            asearch.childByName(ssk, "height key").set("value",
                                                       "snow-precipitation")
Beispiel #14
0
def lower_case(xml):
    """Converts an xml object, in-place"""

    try:
        regions = xml_search.getElementByNamePath(xml, "Regions")
    except xml_errors.MissingXMLError:
        pass

    else:
        for label in changes_regions:
            for param in xml_search.generateElementByNamePath(regions, label):
                param.set('name', label.lower())

        for param in xml_search.generateElementByNamePath(
                xml, "Region: Plane/location"):
            param.set('name', 'point')
        for param in xml_search.generateElementByNamePath(
                xml, "Region: Plane/direction"):
            param.set('name', 'normal')
        regions.set('name', "regions")

    try:
        mesh = xml_search.getElementByNamePath(xml, "Mesh")
    except xml_errors.MissingXMLError:
        pass
    else:
        for label in changes_mesh:
            for param in xml_search.generateElementByNamePath(mesh, label):
                param.set('name', label.lower())

        mesh.set('name', "mesh")

    try:
        domain = xml_search.getElementByNamePath(xml, "Domain")
    except xml_errors.MissingXMLError:
        pass
    else:
        xml.remove(domain)
Beispiel #15
0
def lower_case(xml):
    """Converts an xml object, in-place"""

    try:
        regions = xml_search.getElementByNamePath(xml, "Regions")
    except xml_errors.MissingXMLError:
        pass

    else:
        for label in changes_regions:
            for param in xml_search.generateElementByNamePath(regions, label):
                param.set('name', label.lower())

        for param in xml_search.generateElementByNamePath(xml, "Region: Plane/location"):
            param.set('name', 'point')
        for param in xml_search.generateElementByNamePath(xml, "Region: Plane/direction"):
            param.set('name', 'normal')
        regions.set('name', "regions")

        
    try:
        mesh = xml_search.getElementByNamePath(xml, "Mesh")
    except xml_errors.MissingXMLError:
        pass
    else:
        for label in changes_mesh:
            for param in xml_search.generateElementByNamePath(mesh, label):
                param.set('name', label.lower())

        mesh.set('name', "mesh")

    try:
        domain = xml_search.getElementByNamePath(xml, "Domain")
    except xml_errors.MissingXMLError:
        pass
    else:
        xml.remove(domain)
Beispiel #16
0
def seb(xml):
    pk_list = [pk for pk in asearch.generateElementByNamePath(xml, "PKs")]
    assert (len(pk_list) == 1)
    pk_list = pk_list[0]

    seb_pk = None
    flow_sub_pk = None
    flow_surf_pk = None
    energy_sub_pk = None
    energy_surf_pk = None
    # make sure we can find all of them!
    for pk in pk_list:
        if asearch.childByName(
                pk, "PK type").get("value") == "surface balance implicit":
            if seb_pk is not None:
                raise RuntimeError("Cannot deal with SEB changes!")
            seb_pk = pk
        elif asearch.childByName(pk,
                                 "PK type").get("value") == "permafrost flow":
            if flow_sub_pk is not None:
                raise RuntimeError("Cannot deal with SEB changes!")
            flow_sub_pk = pk
        elif asearch.childByName(
                pk, "PK type").get("value") == "overland flow with ice":
            if flow_surf_pk is not None:
                raise RuntimeError("Cannot deal with SEB changes!")
            flow_surf_pk = pk
        elif asearch.childByName(
                pk, "PK type").get("value") == "three-phase energy":
            if energy_sub_pk is not None:
                raise RuntimeError("Cannot deal with SEB changes!")
            energy_sub_pk = pk
        elif asearch.childByName(pk,
                                 "PK type").get("value") == "surface energy":
            if energy_surf_pk is not None:
                raise RuntimeError("Cannot deal with SEB changes!")
            energy_surf_pk = pk

    if seb_pk is None or flow_sub_pk is None or flow_surf_pk is None or energy_sub_pk is None or energy_surf_pk is None:
        return

    # check the source terms for all
    def set_source_term(pk):
        if not pk.isElement("source term"):
            pk.append(parameter.BoolParameter("source term", True))
        else:
            asearch.childByName(pk, "source term").set("value", "true")

    set_source_term(flow_sub_pk)
    set_source_term(flow_surf_pk)
    set_source_term(energy_sub_pk)
    set_source_term(energy_surf_pk)

    if not flow_sub_pk.isElement("mass source key"):
        flow_sub_pk.append(
            parameter.StringParameter("mass source key", "mass_source"))
    if not flow_surf_pk.isElement("source key"):
        flow_surf_pk.append(
            parameter.StringParameter("source key", "surface-mass_source"))
    if not flow_surf_pk.isElement("mass source in meters"):
        flow_surf_pk.append(
            parameter.BoolParameter("mass source in meters", True))
    if not energy_sub_pk.isElement("energy source"):
        energy_sub_pk.append(
            parameter.StringParameter("energy source", "total_energy_source"))
    if not energy_surf_pk.isElement("energy source"):
        energy_surf_pk.append(
            parameter.StringParameter("energy source",
                                      "surface-total_energy_source"))

    eval_list = [
        ev for ev in asearch.generateElementByNamePath(
            xml, "state/field evaluators")
    ]
    assert (len(eval_list) == 1)
    eval_list = eval_list[0]
    try:
        eval_list.pop("surface-total_energy_source")
    except aerrors.MissingXMLError:
        pass
    try:
        eval_list.pop("surface-mass_source_enthalpy")
    except aerrors.MissingXMLError:
        pass
    try:
        eval_list.pop("surface-source_internal_energy")
    except aerrors.MissingXMLError:
        pass

    molar_dens = asearch.childByName(eval_list, "surface-source_molar_density")
    if molar_dens.isElement("temperature key"):
        asearch.childByName(molar_dens,
                            "temperature key").set("value",
                                                   "surface-temperature")
    else:
        molar_dens.append(
            parameter.StringParameter("temperature key",
                                      "surface-temperature"))
def pks(xml):
    pk_tree = asearch.childByNamePath(xml, "cycle driver/PK tree")
    for pk_type in asearch.generateElementByNamePath(pk_tree, "PK type"):
        if pk_type.getValue() == 'surface balance implicit':
            pk_type.setValue('surface balance implicit subgrid')
    
    pks = asearch.childByName(xml, "PKs")
    for pk in pks:
        pk_type = asearch.childByName(pk, "PK type")
        if pk_type.get('value') == 'permafrost flow':
            try:
                source_term = asearch.childByName(pk, "source term")
            except aerrors.MissingXMLError:
                pass
            else:
                source_term.setValue(False)

        elif pk_type.get('value') == 'overland flow with ice':
            try:
                source_term = asearch.childByName(pk, "source term")
            except aerrors.MissingXMLError:
                pk.append(parameter.BoolParameter("source term", True))
            else:
                source_term.setValue(True)

            try:
                source_is_diff = asearch.childByName(pk, "source term is differentiable")
            except aerrors.MissingXMLError:
                pk.append(parameter.BoolParameter("source term is differentiable", False))
            else:
                source_is_diff.setValue(False)

        elif pk_type.get('value') == 'three-phase energy':
            try:
                source_term = asearch.childByName(pk, "source term")
            except aerrors.MissingXMLError:
                pass
            else:
                source_term.setValue(False)

        elif pk_type.get('value') == 'surface energy':
            try:
                source_term = asearch.childByName(pk, "source term")
            except aerrors.MissingXMLError:
                pk.append(parameter.BoolParameter("source term", True))
            else:
                source_term.setValue(True)

            try:
                source_is_diff = asearch.childByName(pk, "source term is differentiable")
            except aerrors.MissingXMLError:
                pk.append(parameter.BoolParameter("source term is differentiable", True))
            else:
                source_is_diff.setValue(True)

            try:
                source_fd = asearch.childByName(pk, "source term finite difference")
            except aerrors.MissingXMLError:
                pk.append(parameter.BoolParameter("source term finite difference", True))
            else:
                source_fd.setValue(True)
                
        elif pk_type.get('value') == 'surface balance implicit':
            pk_seb = parameter_list.ParameterList(pk.get('name'))
            pk_seb.append(parameter.StringParameter('PK type', 'surface balance implicit subgrid'))
            pk_seb.append(parameter.StringParameter('layer name', 'snow'))
            pk_seb.append(parameter.StringParameter('domain name', 'snow'))
            pk_seb.append(parameter.StringParameter('primary variable key', 'snow-depth'))
            pk_seb.append(parameter.StringParameter('conserved quantity key', 'snow-swe'))
            pk_seb.append(parameter.StringParameter('source key', 'snow-source_sink'))
            pk_seb.append(parameter.BoolParameter('source term is differentiable', False))
            
            pk_seb.append(pk.pop('initial condition'))

            try:
                pk_seb.append(pk.pop('verbose object'))
            except aerrors.MissingXMLError:
                pass

            try:
                dc = pk.pop('debug cells')
            except aerrors.MissingXMLError:
                dc = None
            else:
                pk_seb.append(copy.copy(dc))

            pc = pk_seb.sublist('preconditioner')
            pc.append(parameter.StringParameter('preconditioner type', 'identity'))

            ls = pk_seb.sublist('linear solver')
            ls.append(parameter.StringParameter('iterative method', 'nka'))
            nka = ls.sublist('nka parameters')
            nka.append(parameter.DoubleParameter('error tolerance', 1.e-6))
            nka.append(parameter.IntParameter('maximum number of iterations', 10))
            pks.pop(pk.get('name'))
            pks.append(pk_seb)

    return dc
Beispiel #18
0
def fixTIList(xml):
    for ti_list in search.generateElementByNamePath(xml, "time integrator"):
        _fixTIList(ti_list)
Beispiel #19
0
def compressibility(xml):
    for c in asearch.generateElementByNamePath(xml, "pore compressibility"):
        c.set("name", "pore compressibility [Pa^-1]")
Beispiel #20
0
def seb(xml):
    pk_list = [pk for pk in asearch.generateElementByNamePath(xml, "PKs")]
    assert(len(pk_list) == 1)
    pk_list = pk_list[0]

    seb_pk = None
    flow_sub_pk = None
    flow_surf_pk = None
    energy_sub_pk = None
    energy_surf_pk = None
    # make sure we can find all of them!
    for pk in pk_list:
        if asearch.childByName(pk,"PK type").get("value") == "surface balance implicit":
            if seb_pk is not None:
                raise RuntimeError("Cannot deal with SEB changes!")
            seb_pk = pk
        elif asearch.childByName(pk,"PK type").get("value") == "permafrost flow":
            if flow_sub_pk is not None:
                raise RuntimeError("Cannot deal with SEB changes!")
            flow_sub_pk = pk
        elif asearch.childByName(pk,"PK type").get("value") == "overland flow with ice":
            if flow_surf_pk is not None:
                raise RuntimeError("Cannot deal with SEB changes!")
            flow_surf_pk = pk
        elif asearch.childByName(pk,"PK type").get("value") == "three-phase energy":
            if energy_sub_pk is not None:
                raise RuntimeError("Cannot deal with SEB changes!")
            energy_sub_pk = pk
        elif asearch.childByName(pk,"PK type").get("value") == "surface energy":
            if energy_surf_pk is not None:
                raise RuntimeError("Cannot deal with SEB changes!")
            energy_surf_pk = pk

    if seb_pk is None or flow_sub_pk is None or flow_surf_pk is None or energy_sub_pk is None or energy_surf_pk is None:
        return

    # check the source terms for all
    def set_source_term(pk):
        if not pk.isElement("source term"):
            pk.append(parameter.BoolParameter("source term", True))
        else:
            asearch.childByName(pk, "source term").set("value","true")
    set_source_term(flow_sub_pk)
    set_source_term(flow_surf_pk)
    set_source_term(energy_sub_pk)
    set_source_term(energy_surf_pk)

    if not flow_sub_pk.isElement("mass source key"):
        flow_sub_pk.append(parameter.StringParameter("mass source key", "mass_source"))
    if not flow_surf_pk.isElement("source key"):
        flow_surf_pk.append(parameter.StringParameter("source key", "surface-mass_source"))
    if not flow_surf_pk.isElement("mass source in meters"):
        flow_surf_pk.append(parameter.BoolParameter("mass source in meters", True))
    if not energy_sub_pk.isElement("energy source"):
        energy_sub_pk.append(parameter.StringParameter("energy source", "total_energy_source"))
    if not energy_surf_pk.isElement("energy source"):
        energy_surf_pk.append(parameter.StringParameter("energy source", "surface-total_energy_source"))

    eval_list = [ev for ev in asearch.generateElementByNamePath(xml, "state/field evaluators")]
    assert(len(eval_list) == 1)
    eval_list = eval_list[0]
    try:
        eval_list.pop("surface-total_energy_source")
    except aerrors.MissingXMLError:
        pass
    try:
        eval_list.pop("surface-mass_source_enthalpy")
    except aerrors.MissingXMLError:
        pass
    try:
        eval_list.pop("surface-source_internal_energy")
    except aerrors.MissingXMLError:
        pass

    molar_dens = asearch.childByName(eval_list, "surface-source_molar_density")
    if molar_dens.isElement("temperature key"):
        asearch.childByName(molar_dens, "temperature key").set("value", "surface-temperature")
    else:
        molar_dens.append(parameter.StringParameter("temperature key", "surface-temperature"))
Beispiel #21
0
def end_time_units(xml):
    for end_time in asearch.generateElementByNamePath(xml, "cycle driver/end time units"):
        if end_time.get("value") == "yr":
            end_time.set("value", "y")
def pks(xml):
    pk_tree = asearch.childByNamePath(xml, "cycle driver/PK tree")
    for pk_type in asearch.generateElementByNamePath(pk_tree, "PK type"):
        if pk_type.getValue() == 'surface balance implicit':
            pk_type.setValue('surface balance implicit subgrid')

    pks = asearch.childByName(xml, "PKs")
    for pk in pks:
        pk_type = asearch.childByName(pk, "PK type")
        if pk_type.get('value') == 'permafrost flow':
            try:
                source_term = asearch.childByName(pk, "source term")
            except aerrors.MissingXMLError:
                pass
            else:
                source_term.setValue(False)

        elif pk_type.get('value') == 'overland flow with ice':
            try:
                source_term = asearch.childByName(pk, "source term")
            except aerrors.MissingXMLError:
                pk.append(parameter.BoolParameter("source term", True))
            else:
                source_term.setValue(True)

            try:
                source_is_diff = asearch.childByName(
                    pk, "source term is differentiable")
            except aerrors.MissingXMLError:
                pk.append(
                    parameter.BoolParameter("source term is differentiable",
                                            False))
            else:
                source_is_diff.setValue(False)

        elif pk_type.get('value') == 'three-phase energy':
            try:
                source_term = asearch.childByName(pk, "source term")
            except aerrors.MissingXMLError:
                pass
            else:
                source_term.setValue(False)

        elif pk_type.get('value') == 'surface energy':
            try:
                source_term = asearch.childByName(pk, "source term")
            except aerrors.MissingXMLError:
                pk.append(parameter.BoolParameter("source term", True))
            else:
                source_term.setValue(True)

            try:
                source_is_diff = asearch.childByName(
                    pk, "source term is differentiable")
            except aerrors.MissingXMLError:
                pk.append(
                    parameter.BoolParameter("source term is differentiable",
                                            True))
            else:
                source_is_diff.setValue(True)

            try:
                source_fd = asearch.childByName(
                    pk, "source term finite difference")
            except aerrors.MissingXMLError:
                pk.append(
                    parameter.BoolParameter("source term finite difference",
                                            True))
            else:
                source_fd.setValue(True)

        elif pk_type.get('value') == 'surface balance implicit':
            pk_seb = parameter_list.ParameterList(pk.get('name'))
            pk_seb.append(
                parameter.StringParameter('PK type',
                                          'surface balance implicit subgrid'))
            pk_seb.append(parameter.StringParameter('layer name', 'snow'))
            pk_seb.append(parameter.StringParameter('domain name', 'snow'))
            pk_seb.append(
                parameter.StringParameter('primary variable key',
                                          'snow-depth'))
            pk_seb.append(
                parameter.StringParameter('conserved quantity key',
                                          'snow-swe'))
            pk_seb.append(
                parameter.StringParameter('source key', 'snow-source_sink'))
            pk_seb.append(
                parameter.BoolParameter('source term is differentiable',
                                        False))

            pk_seb.append(pk.pop('initial condition'))

            try:
                pk_seb.append(pk.pop('verbose object'))
            except aerrors.MissingXMLError:
                pass

            try:
                dc = pk.pop('debug cells')
            except aerrors.MissingXMLError:
                dc = None
            else:
                pk_seb.append(copy.copy(dc))

            pc = pk_seb.sublist('preconditioner')
            pc.append(
                parameter.StringParameter('preconditioner type', 'identity'))

            ls = pk_seb.sublist('linear solver')
            ls.append(parameter.StringParameter('iterative method', 'nka'))
            nka = ls.sublist('nka parameters')
            nka.append(parameter.DoubleParameter('error tolerance', 1.e-6))
            nka.append(
                parameter.IntParameter('maximum number of iterations', 10))
            pks.pop(pk.get('name'))
            pks.append(pk_seb)

    return dc
Beispiel #23
0
def end_time_units(xml):
    for end_time in asearch.generateElementByNamePath(
            xml, "cycle driver/end time units"):
        if end_time.get("value") == "yr":
            end_time.set("value", "y")
Beispiel #24
0
def compressibility(xml):
    for c in asearch.generateElementByNamePath(xml, "pore compressibility"):
        c.set("name", "pore compressibility [Pa^-1]")
Beispiel #25
0
def diffusion(xml):
    for diff in asearch.generateElementByNamePath(xml, "Diffusion"):
        diff.set("name", "diffusion")
    for diff in asearch.generateElementByNamePath(xml, "Diffusion PC"):
        diff.set("name", "diffusion preconditioner")
Beispiel #26
0
def diffusion(xml):
    for diff in asearch.generateElementByNamePath(xml, "Diffusion"):
        diff.set("name", "diffusion")
    for diff in asearch.generateElementByNamePath(xml, "Diffusion PC"):
        diff.set("name", "diffusion preconditioner")