Ejemplo n.º 1
0
def gpbld3_hardness_test():
    "Test the hardness implementation in the optimized version of GPBLD."
    ctx = PISM.context_from_options(PISM.PETSc.COMM_WORLD, "GPBLD3_test")
    EC = ctx.enthalpy_converter()
    gpbld = PISM.GPBLD("stress_balance.sia.", ctx.config(), EC)
    gpbld3 = PISM.GPBLD3("stress_balance.sia.", ctx.config(), EC)

    import numpy as np
    N = 11
    T_pa = np.linspace(-30, 0, N)
    depth = np.linspace(0, 4000, N)
    omega = np.linspace(0, 0.02, N)

    for d in depth:
        p = EC.pressure(d)
        Tm = EC.melting_temperature(p)
        for Tpa in T_pa:
            T = Tm + Tpa
            for o in omega:
                if T >= Tm:
                    E = EC.enthalpy(T, o, p)
                else:
                    E = EC.enthalpy(T, 0.0, p)

                regular = gpbld.hardness(E, p)
                optimized = gpbld3.hardness(E, p)
                assert np.fabs(regular - optimized) / regular < 4e-15
Ejemplo n.º 2
0
def gpbld3_vs_gpbld_test():
    "Test the optimized version of GPBLD by comparing it to the one that uses libm."
    ctx = PISM.context_from_options(PISM.PETSc.COMM_WORLD, "GPBLD3_test")
    EC = ctx.enthalpy_converter()
    gpbld = PISM.GPBLD("stress_balance.sia.", ctx.config(), EC)
    gpbld3 = PISM.GPBLD3("stress_balance.sia.", ctx.config(), EC)

    import numpy as np
    N = 11
    T_pa = np.linspace(-30, 0, N)
    depth = np.linspace(0, 4000, N)
    omega = np.linspace(0, 0.02, N)
    sigma = [1e4, 5e4, 1e5, 1.5e5]

    gs = 1e-3

    for d in depth:
        p = EC.pressure(d)
        Tm = EC.melting_temperature(p)
        for Tpa in T_pa:
            T = Tm + Tpa
            for o in omega:
                if T >= Tm:
                    E = EC.enthalpy(T, o, p)
                else:
                    E = EC.enthalpy(T, 0.0, p)
                for s in sigma:
                    regular = gpbld.flow(s, E, p, gs)
                    optimized = gpbld3.flow(s, E, p, gs)
                    assert np.fabs(regular - optimized) / regular < 2e-14
Ejemplo n.º 3
0
def gpbld3_error_report():
    """Print max. absolute and relative difference between GPBLD and
    GPBLD3. Uses 101*101*101*101 samples in a "reasonable" range of
    pressure-adjusted temperatures, depth, water fraction, and
    effective stress. This takes about 15 minutes to complete.
    """
    ctx = PISM.context_from_options(PISM.PETSc.COMM_WORLD, "GPBLD3_test")
    EC = ctx.enthalpy_converter()
    gpbld = PISM.GPBLD("stress_balance.sia.", ctx.config(), EC)
    gpbld3 = PISM.GPBLD3("stress_balance.sia.", ctx.config(), EC)

    import numpy as np
    N = 31
    T_pa = np.linspace(-30, 0, N)
    depth = np.linspace(0, 5000, N)
    omega = np.linspace(0, 0.02, N)
    sigma = np.linspace(0, 5e5, N)

    gs = 1e-3

    max_difference = 0.0
    max_rel_difference = 0.0

    for d in depth:
        p = EC.pressure(d)
        Tm = EC.melting_temperature(p)
        for Tpa in T_pa:
            T = Tm + Tpa
            for o in omega:
                if T >= Tm:
                    E = EC.enthalpy(T, o, p)
                else:
                    E = EC.enthalpy(T, 0.0, p)
                for s in sigma:
                    regular = gpbld.flow(s, E, p, gs)
                    optimized = gpbld3.flow(s, E, p, gs)
                    max_difference = max(np.fabs(regular - optimized),
                                         max_difference)
                    if regular > 0.0:
                        max_rel_difference = max(
                            np.fabs(regular - optimized) / regular,
                            max_rel_difference)

    print "%d (%e) samples" % (N**4, N**4)
    print "max difference", max_difference
    print "max relative difference", max_rel_difference