Exemplo n.º 1
0
def euler_forward(GR, HGHT, TRACER, UWIND, VWIND, WIND, UFLX, VFLX, UFLXMP,
                  VFLXMP, UUFLX, UVFLX, VUFLX, VVFLX, HSURF,
                  i_spatial_discretization):

    if i_spatial_discretization == 'UPWIND':
        dHGHTdt, dUFLXMPdt, dVFLXMPdt, dTRACERdt = tendencies_upwind(
            GR, HGHT, TRACER, HSURF, UWIND, VWIND, WIND, UFLX, VFLX, UFLXMP,
            VFLXMP, UUFLX, UVFLX, VUFLX, VVFLX)

        UFLXMP, VFLXMP, HGHT, TRACER = proceed_timestep_upwind(
            GR, UFLXMP, VFLXMP, HGHT, TRACER, dHGHTdt, dUFLXMPdt, dVFLXMPdt,
            dTRACERdt)

        UWIND, VWIND = diagnose_fields_upwind(GR, HGHT, TRACER, UWIND, VWIND,
                                              UFLXMP, VFLXMP, HSURF)

    elif i_spatial_discretization == 'JACOBSON':
        dHGHTdt, dUFLXdt, dVFLXdt, dTRACERdt = tendencies_jacobson(
            GR, HGHT, TRACER, HSURF, UWIND, VWIND, WIND, UFLX, VFLX)

        UWIND, VWIND, HGHT, TRACER = proceed_timestep_jacobson(
            GR, UWIND, VWIND, HGHT, TRACER, dHGHTdt, dUFLXdt, dVFLXdt,
            dTRACERdt)

        #UWIND, VWIND = diagnose_fields_jacobson(GR, HGHT, TRACER,
        #                UWIND, VWIND, UFLX, VFLX, HSURF)

    return (HGHT, TRACER, UWIND, VWIND, UFLX, VFLX, UFLXMP, VFLXMP, UUFLX,
            UVFLX, VUFLX, VVFLX, HSURF)
Exemplo n.º 2
0
def step_RK4(GR, subgrids, COLP, PHI, PHIVB, POTT, POTTVB, UWIND, VWIND, WWIND,
             UFLX, VFLX, HSURF, PVTF, PVTFVB, dPOTTdt_RAD, dPOTTdt_MIC, QV, QC,
             dQVdt_MIC, dQCdt_MIC):

    # INITIAL FIELDS
    UWIND_START = copy.deepcopy(UWIND)
    VWIND_START = copy.deepcopy(VWIND)
    COLP_START = copy.deepcopy(COLP)
    POTT_START = copy.deepcopy(POTT)
    POTTVB_START = copy.deepcopy(POTTVB)
    QV_START = copy.deepcopy(QV)
    QC_START = copy.deepcopy(QC)

    # INTERMEDIATE FIELDS
    UWIND_INT = copy.deepcopy(UWIND)
    VWIND_INT = copy.deepcopy(VWIND)
    COLP_INT = copy.deepcopy(COLP)
    POTT_INT = copy.deepcopy(POTT)
    QV_INT = copy.deepcopy(QV)
    QC_INT = copy.deepcopy(QC)

    ########## level 1
    dCOLPdt, dUFLXdt, dVFLXdt, \
    dPOTTdt, WWIND, \
    dQVdt, dQCdt = tendencies_jacobson(GR, subgrids,
                                        COLP, POTT, POTTVB, HSURF,
                                        UWIND, VWIND, WWIND,
                                        UFLX, VFLX, PHI, PVTF, PVTFVB,
                                        dPOTTdt_RAD, dPOTTdt_MIC,
                                        QV, QC, dQVdt_MIC, dQCdt_MIC)

    dUFLX = GR.dt * dUFLXdt
    dVFLX = GR.dt * dVFLXdt
    dCOLP = GR.dt * dCOLPdt
    dPOTT = GR.dt * dPOTTdt
    dQV = GR.dt * dQVdt
    dQC = GR.dt * dQCdt

    # TIME STEPPING
    COLP_INT, UWIND_INT, VWIND_INT, POTT_INT, QV_INT, QC_INT = \
    RK_time_step(GR, COLP_START, UWIND_START, VWIND_START, POTT_START, QV_START, QC_START, \
                COLP_INT, UWIND_INT, VWIND_INT, POTT_INT, QV_INT, QC_INT, \
                dCOLP, dUFLX, dVFLX, dPOTT, dQV, dQC, 2)

    COLP, UWIND, VWIND, POTT, QV, QC = \
    RK_time_step(GR, COLP_START, UWIND_START, VWIND_START, POTT_START, QV_START, QC_START,\
                COLP, UWIND, VWIND, POTT, QV, QC, \
                dCOLP, dUFLX, dVFLX, dPOTT, dQV, dQC, 6)

    PHI, PHIVB, PVTF, PVTFVB, POTTVB = \
            diagnose_fields_jacobson(GR, PHI, PHIVB, COLP_INT, POTT_INT,
                                        HSURF, PVTF, PVTFVB, POTTVB)

    ########## level 2
    dCOLPdt, dUFLXdt, dVFLXdt, \
    dPOTTdt, WWIND, \
    dQVdt, dQCdt = tendencies_jacobson(GR, subgrids,
                                        COLP_INT, POTT_INT, POTTVB, HSURF,
                                        UWIND_INT, VWIND_INT, WWIND,
                                        UFLX, VFLX, PHI, PVTF, PVTFVB,
                                        dPOTTdt_RAD, dPOTTdt_MIC,
                                        QV, QC, dQVdt_MIC, dQCdt_MIC)

    dUFLX = GR.dt * dUFLXdt
    dVFLX = GR.dt * dVFLXdt
    dCOLP = GR.dt * dCOLPdt
    dPOTT = GR.dt * dPOTTdt
    dQV = GR.dt * dQVdt
    dQC = GR.dt * dQCdt

    COLP_INT, UWIND_INT, VWIND_INT, POTT_INT, QV_INT, QC_INT = \
    RK_time_step(GR, COLP_START, UWIND_START, VWIND_START, POTT_START, QV_START, QC_START,\
                COLP_INT, UWIND_INT, VWIND_INT, POTT_INT, QV_INT, QC_INT,\
                dCOLP, dUFLX, dVFLX, dPOTT, dQV, dQC, 2)

    COLP_OLD = copy.deepcopy(COLP)
    COLP, UWIND, VWIND, POTT, QV, QC = \
    RK_time_step(GR, COLP_OLD, UWIND, VWIND, POTT, QV, QC, \
                COLP, UWIND, VWIND, POTT, QV, QC, \
                dCOLP, dUFLX, dVFLX, dPOTT, dQV, dQC, 3)

    PHI, PHIVB, PVTF, PVTFVB, POTTVB = \
            diagnose_fields_jacobson(GR, PHI, PHIVB, COLP_INT, POTT_INT,
                                        HSURF, PVTF, PVTFVB, POTTVB)

    ########## level 3
    dCOLPdt, dUFLXdt, dVFLXdt, \
    dPOTTdt, WWIND, \
    dQVdt, dQCdt = tendencies_jacobson(GR, subgrids,
                                        COLP_INT, POTT_INT, POTTVB, HSURF,
                                        UWIND_INT, VWIND_INT, WWIND,
                                        UFLX, VFLX, PHI, PVTF, PVTFVB,
                                        dPOTTdt_RAD, dPOTTdt_MIC,
                                        QV, QC, dQVdt_MIC, dQCdt_MIC)

    dUFLX = GR.dt * dUFLXdt
    dVFLX = GR.dt * dVFLXdt
    dCOLP = GR.dt * dCOLPdt
    dPOTT = GR.dt * dPOTTdt
    dQV = GR.dt * dQVdt
    dQC = GR.dt * dQCdt


    COLP_INT, UWIND_INT, VWIND_INT, POTT_INT, QV_INT, QC_INT = \
    RK_time_step(GR, COLP_START, UWIND_START, VWIND_START, POTT_START, QV_START, QC_START,\
                COLP_INT, UWIND_INT, VWIND_INT, POTT_INT, QV_INT, QC_INT,\
                dCOLP, dUFLX, dVFLX, dPOTT, dQV, dQC, 1)

    COLP_OLD = copy.deepcopy(COLP)
    COLP, UWIND, VWIND, POTT, QV, QC = \
    RK_time_step(GR, COLP_OLD, UWIND, VWIND, POTT, QV, QC,\
                COLP, UWIND, VWIND, POTT, QV, QC,\
                dCOLP, dUFLX, dVFLX, dPOTT, dQV, dQC, 3)

    PHI, PHIVB, PVTF, PVTFVB, POTTVB = \
            diagnose_fields_jacobson(GR, PHI, PHIVB, COLP_INT, POTT_INT,
                                        HSURF, PVTF, PVTFVB, POTTVB)

    ########## level 4
    dCOLPdt, dUFLXdt, dVFLXdt, \
    dPOTTdt, WWIND, \
    dQVdt, dQCdt = tendencies_jacobson(GR, subgrids,
                                        COLP_INT, POTT_INT, POTTVB, HSURF,
                                        UWIND_INT, VWIND_INT, WWIND,
                                        UFLX, VFLX, PHI, PVTF, PVTFVB,
                                        dPOTTdt_RAD, dPOTTdt_MIC,
                                        QV, QC, dQVdt_MIC, dQCdt_MIC)

    dUFLX = GR.dt * dUFLXdt
    dVFLX = GR.dt * dVFLXdt
    dCOLP = GR.dt * dCOLPdt
    dPOTT = GR.dt * dPOTTdt
    dQV = GR.dt * dQVdt
    dQC = GR.dt * dQCdt

    COLP_OLD = copy.deepcopy(COLP)
    COLP, UWIND, VWIND, POTT, QV, QC = \
    RK_time_step(GR, COLP_OLD, UWIND, VWIND, POTT, QV, QC,\
                COLP, UWIND, VWIND, POTT, QV, QC,\
                dCOLP, dUFLX, dVFLX, dPOTT, dQV, dQC, 6)

    PHI, PHIVB, PVTF, PVTFVB, POTTVB = \
            diagnose_fields_jacobson(GR, PHI, PHIVB, COLP, POTT, \
                                    HSURF, PVTF, PVTFVB, POTTVB)

    return (COLP, PHI, PHIVB, POTT, POTTVB, UWIND, VWIND, WWIND, UFLX, VFLX,
            QV, QC)
Exemplo n.º 3
0
def matsuno(GR, HGHT, TRACER, UWIND, VWIND, WIND, UFLX, VFLX, UFLXMP, VFLXMP,
            UUFLX, UVFLX, VUFLX, VVFLX, HSURF, i_spatial_discretization):

    if i_spatial_discretization == 'UPWIND':
        ########## ESTIMATE
        dHGHTdt, dUFLXMPdt, dVFLXMPdt, dTRACERdt = tendencies_upwind(
            GR, HGHT, TRACER, HSURF, UWIND, VWIND, WIND, UFLX, VFLX, UFLXMP,
            VFLXMP, UUFLX, UVFLX, VUFLX, VVFLX)

        # has to happen after masspoint_flux_tendency function
        UFLXMP_OLD = copy.deepcopy(UFLXMP)
        VFLXMP_OLD = copy.deepcopy(VFLXMP)
        HGHT_OLD = copy.deepcopy(HGHT)
        TRACER_OLD = copy.deepcopy(TRACER)

        UFLXMP, VFLXMP, HGHT, TRACER = proceed_timestep_upwind(
            GR, UFLXMP, VFLXMP, HGHT, TRACER, dHGHTdt, dUFLXMPdt, dVFLXMPdt,
            dTRACERdt)

        UWIND, VWIND = diagnose_fields_upwind(GR, HGHT, TRACER, UWIND, VWIND,
                                              UFLXMP, VFLXMP, HSURF)

        ########## FINAL
        dHGHTdt, dUFLXMPdt, dVFLXMPdt, dTRACERdt = tendencies_upwind(
            GR, HGHT, TRACER, HSURF, UWIND, VWIND, WIND, UFLX, VFLX, UFLXMP,
            VFLXMP, UUFLX, UVFLX, VUFLX, VVFLX)

        UFLXMP, VFLXMP, HGHT, TRACER = proceed_timestep_upwind(
            GR, UFLXMP_OLD, VFLXMP_OLD, HGHT_OLD, TRACER_OLD, dHGHTdt,
            dUFLXMPdt, dVFLXMPdt, dTRACERdt)

        UWIND, VWIND = diagnose_fields_upwind(GR, HGHT, TRACER, UWIND, VWIND,
                                              UFLXMP, VFLXMP, HSURF)

    elif i_spatial_discretization == 'JACOBSON':
        ########## ESTIMATE
        dHGHTdt, dUFLXdt, dVFLXdt, dTRACERdt = tendencies_jacobson(
            GR, HGHT, TRACER, HSURF, UWIND, VWIND, WIND, UFLX, VFLX)

        # has to happen after masspoint_flux_tendency function
        UWIND_OLD = copy.deepcopy(UWIND)
        VWIND_OLD = copy.deepcopy(VWIND)
        HGHT_OLD = copy.deepcopy(HGHT)
        TRACER_OLD = copy.deepcopy(TRACER)

        UWIND, VWIND, HGHT, TRACER = proceed_timestep_jacobson(
            GR, UWIND, VWIND, HGHT, TRACER, dHGHTdt, dUFLXdt, dVFLXdt,
            dTRACERdt)

        #UWIND, VWIND = diagnose_fields_jacobson(GR, HGHT, TRACER,
        #                UWIND, VWIND, UFLX, VFLX, HSURF)

        ########## FINAL
        dHGHTdt, dUFLXdt, dVFLXdt, dTRACERdt = tendencies_jacobson(
            GR, HGHT, TRACER, HSURF, UWIND, VWIND, WIND, UFLX, VFLX)

        UWIND, VWIND, HGHT, TRACER = proceed_timestep_jacobson(
            GR, UWIND_OLD, VWIND_OLD, HGHT_OLD, TRACER_OLD, dHGHTdt, dUFLXdt,
            dVFLXdt, dTRACERdt)

        #UWIND, VWIND = diagnose_fields_jacobson(GR, HGHT, TRACER,
        #                UWIND, VWIND, UFLX, VFLX, HSURF)

    return (HGHT, TRACER, UWIND, VWIND, UFLX, VFLX, UFLXMP, VFLXMP, UUFLX,
            UVFLX, VUFLX, VVFLX, HSURF)
Exemplo n.º 4
0
def RK4(GR, HGHT, TRACER, UWIND, VWIND, WIND, UFLX, VFLX, UFLXMP, VFLXMP,
        UUFLX, UVFLX, VUFLX, VVFLX, HSURF, i_spatial_discretization):

    if i_spatial_discretization == 'UPWIND':
        ########## level 1
        dHGHTdt, dUFLXMPdt, dVFLXMPdt, dTRACERdt = tendencies_upwind(
            GR, HGHT, TRACER, HSURF, UWIND, VWIND, WIND, UFLX, VFLX, UFLXMP,
            VFLXMP, UUFLX, UVFLX, VUFLX, VVFLX)

        # has to happen after masspoint_flux_tendency function
        UFLXMP_OLD = copy.deepcopy(UFLXMP)
        VFLXMP_OLD = copy.deepcopy(VFLXMP)
        HGHT_OLD = copy.deepcopy(HGHT)
        TRACER_OLD = copy.deepcopy(TRACER)

        UFLXMP_INT = copy.deepcopy(UFLXMP)
        VFLXMP_INT = copy.deepcopy(VFLXMP)
        HGHT_INT = copy.deepcopy(HGHT)
        TRACER_INT = copy.deepcopy(TRACER)

        dUFLXMP = GR.dt * dUFLXMPdt
        dVFLXMP = GR.dt * dVFLXMPdt
        dHGHT = GR.dt * dHGHTdt
        dTRACER = GR.dt * dTRACERdt

        UFLXMP_INT[GR.iijj] = UFLXMP_OLD[GR.iijj] + dUFLXMP / 2
        VFLXMP_INT[GR.iijj] = VFLXMP_OLD[GR.iijj] + dVFLXMP / 2
        HGHT_INT[GR.iijj] = HGHT_OLD[GR.iijj] + dHGHT / 2
        TRACER_INT[GR.iijj] = TRACER_OLD[GR.iijj] + dTRACER / 2
        UFLXMP_INT = exchange_BC(GR, UFLXMP_INT)
        VFLXMP_INT = exchange_BC(GR, VFLXMP_INT)
        HGHT_INT = exchange_BC(GR, HGHT_INT)
        TRACER_INT = exchange_BC(GR, TRACER_INT)

        UFLXMP[GR.iijj] = UFLXMP_OLD[GR.iijj] + dUFLXMP / 6
        VFLXMP[GR.iijj] = VFLXMP_OLD[GR.iijj] + dVFLXMP / 6
        HGHT[GR.iijj] = HGHT_OLD[GR.iijj] + dHGHT / 6
        TRACER[GR.iijj] = TRACER_OLD[GR.iijj] + dTRACER / 6

        UWIND, VWIND = diagnose_fields_upwind(GR, HGHT_INT, TRACER_INT, UWIND,
                                              VWIND, UFLXMP_INT, VFLXMP_INT,
                                              HSURF)

        ########## level 2
        dHGHTdt, dUFLXMPdt, dVFLXMPdt, dTRACERdt = tendencies_upwind(
            GR, HGHT_INT, TRACER_INT, HSURF, UWIND, VWIND, WIND, UFLX, VFLX,
            UFLXMP_INT, VFLXMP_INT, UUFLX, UVFLX, VUFLX, VVFLX)

        dUFLXMP = GR.dt * dUFLXMPdt
        dVFLXMP = GR.dt * dVFLXMPdt
        dHGHT = GR.dt * dHGHTdt
        dTRACER = GR.dt * dTRACERdt

        UFLXMP_INT[GR.iijj] = UFLXMP_OLD[GR.iijj] + dUFLXMP / 2
        VFLXMP_INT[GR.iijj] = VFLXMP_OLD[GR.iijj] + dVFLXMP / 2
        HGHT_INT[GR.iijj] = HGHT_OLD[GR.iijj] + dHGHT / 2
        TRACER_INT[GR.iijj] = TRACER_OLD[GR.iijj] + dTRACER / 2
        UFLXMP_INT = exchange_BC(GR, UFLXMP_INT)
        VFLXMP_INT = exchange_BC(GR, VFLXMP_INT)
        HGHT_INT = exchange_BC(GR, HGHT_INT)
        TRACER_INT = exchange_BC(GR, TRACER_INT)

        UFLXMP[GR.iijj] = UFLXMP[GR.iijj] + dUFLXMP / 3
        VFLXMP[GR.iijj] = VFLXMP[GR.iijj] + dVFLXMP / 3
        HGHT[GR.iijj] = HGHT[GR.iijj] + dHGHT / 3
        TRACER[GR.iijj] = TRACER[GR.iijj] + dTRACER / 3

        UWIND, VWIND = diagnose_fields_upwind(GR, HGHT_INT, TRACER_INT, UWIND,
                                              VWIND, UFLXMP_INT, VFLXMP_INT,
                                              HSURF)

        ########## level 3
        dHGHTdt, dUFLXMPdt, dVFLXMPdt, dTRACERdt = tendencies_upwind(
            GR, HGHT_INT, TRACER_INT, HSURF, UWIND, VWIND, WIND, UFLX, VFLX,
            UFLXMP_INT, VFLXMP_INT, UUFLX, UVFLX, VUFLX, VVFLX)

        dUFLXMP = GR.dt * dUFLXMPdt
        dVFLXMP = GR.dt * dVFLXMPdt
        dHGHT = GR.dt * dHGHTdt
        dTRACER = GR.dt * dTRACERdt

        UFLXMP_INT[GR.iijj] = UFLXMP_OLD[GR.iijj] + dUFLXMP
        VFLXMP_INT[GR.iijj] = VFLXMP_OLD[GR.iijj] + dVFLXMP
        HGHT_INT[GR.iijj] = HGHT_OLD[GR.iijj] + dHGHT
        TRACER_INT[GR.iijj] = TRACER_OLD[GR.iijj] + dTRACER
        UFLXMP_INT = exchange_BC(GR, UFLXMP_INT)
        VFLXMP_INT = exchange_BC(GR, VFLXMP_INT)
        HGHT_INT = exchange_BC(GR, HGHT_INT)
        TRACER_INT = exchange_BC(GR, TRACER_INT)

        UFLXMP[GR.iijj] = UFLXMP[GR.iijj] + dUFLXMP / 3
        VFLXMP[GR.iijj] = VFLXMP[GR.iijj] + dVFLXMP / 3
        HGHT[GR.iijj] = HGHT[GR.iijj] + dHGHT / 3
        TRACER[GR.iijj] = TRACER[GR.iijj] + dTRACER / 3

        UWIND, VWIND = diagnose_fields_upwind(GR, HGHT_INT, TRACER_INT, UWIND,
                                              VWIND, UFLXMP_INT, VFLXMP_INT,
                                              HSURF)

        ########## level 4
        dHGHTdt, dUFLXMPdt, dVFLXMPdt, dTRACERdt = tendencies_upwind(
            GR, HGHT_INT, TRACER_INT, HSURF, UWIND, VWIND, WIND, UFLX, VFLX,
            UFLXMP_INT, VFLXMP_INT, UUFLX, UVFLX, VUFLX, VVFLX)

        dUFLXMP = GR.dt * dUFLXMPdt
        dVFLXMP = GR.dt * dVFLXMPdt
        dHGHT = GR.dt * dHGHTdt
        dTRACER = GR.dt * dTRACERdt

        UFLXMP[GR.iijj] = UFLXMP[GR.iijj] + dUFLXMP / 6
        VFLXMP[GR.iijj] = VFLXMP[GR.iijj] + dVFLXMP / 6
        HGHT[GR.iijj] = HGHT[GR.iijj] + dHGHT / 6
        TRACER[GR.iijj] = TRACER[GR.iijj] + dTRACER / 6
        UFLXMP = exchange_BC(GR, UFLXMP)
        VFLXMP = exchange_BC(GR, VFLXMP)
        HGHT = exchange_BC(GR, HGHT)
        TRACER = exchange_BC(GR, TRACER)

        UWIND, VWIND = diagnose_fields_upwind(GR, HGHT, TRACER, UWIND, VWIND,
                                              UFLXMP, VFLXMP, HSURF)

    elif i_spatial_discretization == 'JACOBSON':
        ########## level 1
        dHGHTdt, dUFLXdt, dVFLXdt, dTRACERdt = tendencies_jacobson(
            GR, HGHT, TRACER, HSURF, UWIND, VWIND, WIND, UFLX, VFLX)

        # has to happen after masspoint_flux_tendency function
        UWIND_START = copy.deepcopy(UWIND)
        VWIND_START = copy.deepcopy(VWIND)
        HGHT_START = copy.deepcopy(HGHT)
        TRACER_START = copy.deepcopy(TRACER)

        UWIND_INT = copy.deepcopy(UWIND)
        VWIND_INT = copy.deepcopy(VWIND)
        HGHT_INT = copy.deepcopy(HGHT)
        TRACER_INT = copy.deepcopy(TRACER)

        dUFLX = GR.dt * dUFLXdt
        dVFLX = GR.dt * dVFLXdt
        dHGHT = GR.dt * dHGHTdt
        dTRACER = GR.dt * dTRACERdt

        # TIME STEPPING
        HGHTA_is_START, HGHTA_js_START = interp_HGHTA(GR, HGHT_START)
        HGHT_INT[GR.iijj] = HGHT_START[GR.iijj] + dHGHT / 2
        HGHT_INT = exchange_BC(GR, HGHT_INT)
        HGHTA_is_NEW, HGHTA_js_NEW = interp_HGHTA(GR, HGHT_INT)
        UWIND_INT[GR.iisjj] = UWIND_START[GR.iisjj] * HGHTA_is_START/HGHTA_is_NEW \
                            + dUFLX/2/HGHTA_is_NEW
        VWIND_INT[GR.iijjs] = VWIND_START[GR.iijjs] * HGHTA_js_START/HGHTA_js_NEW \
                            + dVFLX/2/HGHTA_js_NEW
        UWIND_INT = exchange_BC(GR, UWIND_INT)
        VWIND_INT = exchange_BC(GR, VWIND_INT)
        TRACER_INT[GR.iijj] = TRACER_START[GR.iijj] + dTRACER / 2
        TRACER_INT = exchange_BC(GR, TRACER_INT)

        HGHTA_is_START, HGHTA_js_START = interp_HGHTA(GR, HGHT_START)
        HGHT[GR.iijj] = HGHT_START[GR.iijj] + dHGHT / 6
        HGHT = exchange_BC(GR, HGHT)
        HGHTA_is_NEW, HGHTA_js_NEW = interp_HGHTA(GR, HGHT)
        UWIND[GR.iisjj] = UWIND_START[GR.iisjj] * HGHTA_is_START/HGHTA_is_NEW \
                        + dUFLX/6/HGHTA_is_NEW
        VWIND[GR.iijjs] = VWIND_START[GR.iijjs] * HGHTA_js_START/HGHTA_js_NEW \
                            + dVFLX/6/HGHTA_js_NEW
        UWIND = exchange_BC(GR, UWIND)
        VWIND = exchange_BC(GR, VWIND)
        TRACER[GR.iijj] = TRACER_START[GR.iijj] + dTRACER / 6
        TRACER = exchange_BC(GR, TRACER)

        #UWIND, VWIND = diagnose_fields_jacobson(GR, HGHT_INT, TRACER_INT,
        #                UWIND, VWIND, UFLXMP_INT, VFLXMP_INT, HSURF)

        ########## level 2
        dHGHTdt, dUFLXdt, dVFLXdt, dTRACERdt = tendencies_jacobson(
            GR, HGHT_INT, TRACER_INT, HSURF, UWIND_INT, VWIND_INT, WIND, UFLX,
            VFLX)

        dUFLX = GR.dt * dUFLXdt
        dVFLX = GR.dt * dVFLXdt
        dHGHT = GR.dt * dHGHTdt
        dTRACER = GR.dt * dTRACERdt

        HGHT_INT[GR.iijj] = HGHT_START[GR.iijj] + dHGHT / 2
        HGHT_INT = exchange_BC(GR, HGHT_INT)
        HGHTA_is_NEW, HGHTA_js_NEW = interp_HGHTA(GR, HGHT_INT)
        UWIND_INT[GR.iisjj] = UWIND_START[GR.iisjj] * HGHTA_is_START/HGHTA_is_NEW \
                            + dUFLX/2/HGHTA_is_NEW
        VWIND_INT[GR.iijjs] = VWIND_START[GR.iijjs] * HGHTA_js_START/HGHTA_js_NEW \
                            + dVFLX/2/HGHTA_js_NEW
        UWIND_INT = exchange_BC(GR, UWIND_INT)
        VWIND_INT = exchange_BC(GR, VWIND_INT)
        TRACER_INT[GR.iijj] = TRACER_START[GR.iijj] + dTRACER / 2
        TRACER_INT = exchange_BC(GR, TRACER_INT)

        HGHT_OLD = copy.deepcopy(HGHT)
        HGHTA_is_OLD, HGHTA_js_OLD = interp_HGHTA(GR, HGHT_OLD)
        HGHT[GR.iijj] = HGHT[GR.iijj] + dHGHT / 3
        HGHT = exchange_BC(GR, HGHT)
        HGHTA_is_NEW, HGHTA_js_NEW = interp_HGHTA(GR, HGHT)
        UWIND[GR.iisjj] = UWIND[GR.iisjj] * HGHTA_is_OLD/HGHTA_is_NEW \
                        + dUFLX/3/HGHTA_is_NEW
        VWIND[GR.iijjs] = VWIND[GR.iijjs] * HGHTA_js_OLD/HGHTA_js_NEW \
                            + dVFLX/3/HGHTA_js_NEW
        UWIND = exchange_BC(GR, UWIND)
        VWIND = exchange_BC(GR, VWIND)
        TRACER[GR.iijj] = TRACER[GR.iijj] + dTRACER / 3
        TRACER = exchange_BC(GR, TRACER)

        #UWIND, VWIND = diagnose_fields_jacobson(GR, HGHT_INT, TRACER_INT,
        #                UWIND, VWIND, UFLXMP_INT, VFLXMP_INT, HSURF)

        ########## level 3
        dHGHTdt, dUFLXdt, dVFLXdt, dTRACERdt = tendencies_jacobson(
            GR, HGHT_INT, TRACER_INT, HSURF, UWIND_INT, VWIND_INT, WIND, UFLX,
            VFLX)

        dUFLX = GR.dt * dUFLXdt
        dVFLX = GR.dt * dVFLXdt
        dHGHT = GR.dt * dHGHTdt
        dTRACER = GR.dt * dTRACERdt

        HGHT_INT[GR.iijj] = HGHT_START[GR.iijj] + dHGHT
        HGHT_INT = exchange_BC(GR, HGHT_INT)
        HGHTA_is_NEW, HGHTA_js_NEW = interp_HGHTA(GR, HGHT_INT)
        UWIND_INT[GR.iisjj] = UWIND_START[GR.iisjj] * HGHTA_is_START/HGHTA_is_NEW \
                            + dUFLX/HGHTA_is_NEW
        VWIND_INT[GR.iijjs] = VWIND_START[GR.iijjs] * HGHTA_js_START/HGHTA_js_NEW \
                            + dVFLX/HGHTA_js_NEW
        UWIND_INT = exchange_BC(GR, UWIND_INT)
        VWIND_INT = exchange_BC(GR, VWIND_INT)
        TRACER_INT[GR.iijj] = TRACER_START[GR.iijj] + dTRACER
        TRACER_INT = exchange_BC(GR, TRACER_INT)

        HGHT_OLD = copy.deepcopy(HGHT)
        HGHTA_is_OLD, HGHTA_js_OLD = interp_HGHTA(GR, HGHT_OLD)
        HGHT[GR.iijj] = HGHT[GR.iijj] + dHGHT / 3
        HGHT = exchange_BC(GR, HGHT)
        HGHTA_is_NEW, HGHTA_js_NEW = interp_HGHTA(GR, HGHT)
        UWIND[GR.iisjj] = UWIND[GR.iisjj] * HGHTA_is_OLD/HGHTA_is_NEW \
                        + dUFLX/3/HGHTA_is_NEW
        VWIND[GR.iijjs] = VWIND[GR.iijjs] * HGHTA_js_OLD/HGHTA_js_NEW \
                            + dVFLX/3/HGHTA_js_NEW
        UWIND = exchange_BC(GR, UWIND)
        VWIND = exchange_BC(GR, VWIND)
        TRACER[GR.iijj] = TRACER[GR.iijj] + dTRACER / 3
        TRACER = exchange_BC(GR, TRACER)

        #UWIND, VWIND = diagnose_fields_jacobson(GR, HGHT_INT, TRACER_INT,
        #                UWIND, VWIND, UFLXMP_INT, VFLXMP_INT, HSURF)

        ########## level 4
        dHGHTdt, dUFLXdt, dVFLXdt, dTRACERdt = tendencies_jacobson(
            GR, HGHT_INT, TRACER_INT, HSURF, UWIND_INT, VWIND_INT, WIND, UFLX,
            VFLX)

        dUFLX = GR.dt * dUFLXdt
        dVFLX = GR.dt * dVFLXdt
        dHGHT = GR.dt * dHGHTdt
        dTRACER = GR.dt * dTRACERdt

        HGHT_OLD = copy.deepcopy(HGHT)
        HGHTA_is_OLD, HGHTA_js_OLD = interp_HGHTA(GR, HGHT_OLD)
        HGHT[GR.iijj] = HGHT[GR.iijj] + dHGHT / 6
        HGHT = exchange_BC(GR, HGHT)
        HGHTA_is_NEW, HGHTA_js_NEW = interp_HGHTA(GR, HGHT)
        UWIND[GR.iisjj] = UWIND[GR.iisjj] * HGHTA_is_OLD/HGHTA_is_NEW \
                        + dUFLX/6/HGHTA_is_NEW
        VWIND[GR.iijjs] = VWIND[GR.iijjs] * HGHTA_js_OLD/HGHTA_js_NEW \
                            + dVFLX/6/HGHTA_js_NEW
        UWIND = exchange_BC(GR, UWIND)
        VWIND = exchange_BC(GR, VWIND)
        TRACER[GR.iijj] = TRACER[GR.iijj] + dTRACER / 6
        TRACER = exchange_BC(GR, TRACER)

        #UWIND, VWIND = diagnose_fields_jacobson(GR, HGHT, TRACER,
        #                UWIND, VWIND, UFLXMP, VFLXMP, HSURF)

    return (HGHT, TRACER, UWIND, VWIND, UFLX, VFLX, UFLXMP, VFLXMP, UUFLX,
            UVFLX, VUFLX, VVFLX, HSURF)
Exemplo n.º 5
0
def step_matsuno(GR, GR_NEW, subgrids, F, NF):

    ##############################
    ##############################
    GR.timer.start('step')
    if comp_mode == 1:
        F.UWIND_OLD[:] = F.UWIND[:]
        F.VWIND_OLD[:] = F.VWIND[:]
        F.POTT_OLD[:] = F.POTT[:]
        F.QV_OLD[:] = F.QV[:]
        F.QC_OLD[:] = F.QC[:]
        F.COLP_OLD[:] = F.COLP[:]
    elif comp_mode == 2:
        if i_run_new_style == 1:
            set_equal[bpg, tpb](F.COLP_OLD, F.COLP)
            set_equal[bpg, tpb](F.UWIND_OLD, F.UWIND)
            set_equal[bpg, tpb](F.VWIND_OLD, F.VWIND)
            set_equal[bpg, tpb](F.POTT_OLD, F.POTT)
            set_equal[bpg, tpb](F.QV_OLD, F.QV)
            set_equal[bpg, tpb](F.QC_OLD, F.QC)
        else:
            set_equal_o[GR.griddim_is, GR.blockdim, GR.stream](F.UWIND_OLD,
                                                               F.UWIND)
            set_equal_o[GR.griddim_js, GR.blockdim, GR.stream](F.VWIND_OLD,
                                                               F.VWIND)
            set_equal_o[GR.griddim, GR.blockdim, GR.stream](F.POTT_OLD, F.POTT)
            set_equal_o[GR.griddim, GR.blockdim, GR.stream](F.QV_OLD, F.QV)
            set_equal_o[GR.griddim, GR.blockdim, GR.stream](F.QC_OLD, F.QC)
            set_equal2D[GR.griddim_xy, GR.blockdim_xy, GR.stream](F.COLP_OLD,
                                                                  F.COLP)
    GR.timer.stop('step')
    ##############################
    ##############################

    ############################################################
    ############################################################
    ##########     ESTIMATE
    ############################################################
    ############################################################

    ##############################
    ##############################
    tendencies_jacobson(GR, GR_NEW, F, subgrids, NF)
    if comp_mode == 1:
        F.COLP[:] = F.COLP_NEW[:]
    elif comp_mode == 2:
        if i_run_new_style == 1:
            set_equal[bpg, tpb](F.COLP, F.COLP_NEW)
        else:
            set_equal2D[GR.griddim_xy, GR.blockdim_xy, GR.stream](F.COLP,
                                                                  F.COLP_NEW)
    ##############################
    ##############################

    ##############################
    ##############################
    GR.timer.start('step')
    if comp_mode == 1:

        if i_run_new_style:

            NF.old_to_new(F, host=False)
            #NF.host['POTT'][:] = np.nan
            #NF.host['UWIND'][:] = np.nan
            #NF.host['VWIND'][:] = np.nan
            #n_iter = 10
            Prognostics.euler_forward(
                HOST, GR_NEW,
                **NF.get(Prognostics.fields_prognostic, target=HOST))
            #t0 = time.time()
            #for i in range(n_iter):
            #    Prognostics.euler_forward(HOST, GR_NEW,
            #            **NF.get(Prognostics.fields_prognostic, target=HOST))
            #print((time.time() - t0)/n_iter)
            NF.new_to_old(F, host=False)

            ## TODO
            #F.COLP          = F.COLP.squeeze()
            #F.dCOLPdt       = F.dCOLPdt.squeeze()
            #F.COLP_NEW      = F.COLP_NEW.squeeze()
            #F.COLP_OLD      = F.COLP_OLD.squeeze()
            #F.HSURF         = F.HSURF.squeeze()

            ##TODO
            #FIELD1 = np.asarray(F.VWIND)
            #print(np.nanmean((FIELD1)))
            #print()

            #F.UWIND, F.VWIND, F.COLP, F.POTT, F.QV, F.QC \
            #             = proceed_timestep_jacobson_c(GR,
            #                    F.UWIND_OLD, F.UWIND, F.VWIND_OLD, F.VWIND,
            #                    F.COLP_OLD, F.COLP, F.POTT_OLD, F.POTT,
            #                    F.QV_OLD, F.QV, F.QC_OLD, F.QC,
            #                    F.dUFLXdt, F.dVFLXdt, F.dPOTTdt, F.dQVdt, F.dQCdt)
            #F.UWIND = np.asarray(F.UWIND)
            #F.VWIND = np.asarray(F.VWIND)
            #F.COLP = np.asarray(F.COLP)
            #F.POTT = np.asarray(F.POTT)
            #F.QV = np.asarray(F.QV)
            #F.QC = np.asarray(F.QC)
            #t0 = time.time()
            #for i in range(n_iter):
            #    F.UWIND, F.VWIND, F.COLP, F.POTT, F.QV, F.QC \
            #             = proceed_timestep_jacobson_c(GR,
            #                    F.UWIND_OLD, F.UWIND, F.VWIND_OLD, F.VWIND,
            #                    F.COLP_OLD, F.COLP, F.POTT_OLD, F.POTT,
            #                    F.QV_OLD, F.QV, F.QC_OLD, F.QC,
            #                    F.dUFLXdt, F.dVFLXdt, F.dPOTTdt, F.dQVdt, F.dQCdt)
            #    F.UWIND = np.asarray(F.UWIND)
            #    F.VWIND = np.asarray(F.VWIND)
            #    F.COLP = np.asarray(F.COLP)
            #    F.POTT = np.asarray(F.POTT)
            #    F.QV = np.asarray(F.QV)
            #    F.QC = np.asarray(F.QC)
            #print((time.time() - t0)/n_iter)

            ##TODO
            #FIELD2 = np.asarray(F.VWIND)
            #print(np.nanmean((FIELD2)))
            #
            #print()
            #print(np.sum(np.isnan(FIELD2[:,:,:])) -\
            #             np.sum(np.isnan(FIELD1[:,:,:])))
            #print(np.nanmean(FIELD2[:,:,:] - FIELD1[:,:,:]))
            #quit()
        else:

            F.UWIND, F.VWIND, F.COLP, F.POTT, F.QV, F.QC \
                         = proceed_timestep_jacobson_c(GR,
                                F.UWIND_OLD, F.UWIND, F.VWIND_OLD, F.VWIND,
                                F.COLP_OLD, F.COLP, F.POTT_OLD, F.POTT,
                                F.QV_OLD, F.QV, F.QC_OLD, F.QC,
                                F.dUFLXdt, F.dVFLXdt, F.dPOTTdt, F.dQVdt, F.dQCdt)
            F.UWIND = np.asarray(F.UWIND)
            F.VWIND = np.asarray(F.VWIND)
            F.COLP = np.asarray(F.COLP)
            F.POTT = np.asarray(F.POTT)
            F.QV = np.asarray(F.QV)
            F.QC = np.asarray(F.QC)

    elif comp_mode == 2:
        if i_run_new_style:

            NF.old_to_new(F, host=False)
            #NF.device['POTT'][:] = np.nan
            #NF.device['UWIND'][:] = np.nan
            #NF.device['VWIND'][:] = np.nan
            #print('GPU')
            #n_iter = 10
            #t0 = time.time()
            Prognostics.euler_forward(
                DEVICE, GR_NEW,
                **NF.get(Prognostics.fields_prognostic, target=DEVICE))
            #for i in range(n_iter):
            #    Prognostics.euler_forward(DEVICE, GR_NEW,
            #            **NF.get(Prognostics.fields_prognostic, target=DEVICE))
            #print((time.time() - t0)/n_iter)
            NF.new_to_old(F, host=False)

            ##TODO
            #FIELD1 = np.asarray(F.UWIND)
            #print(np.nanmean((FIELD1)))
            #print()

            #t0 = time.time()
            #F.UWIND, F.VWIND, F.COLP, F.POTT, F.QV, F.QC \
            #             = proceed_timestep_jacobson_gpu(GR, GR.stream,
            #                    F.UWIND_OLD, F.UWIND, F.VWIND_OLD, F.VWIND,
            #                    F.COLP_OLD, F.COLP, F.POTT_OLD, F.POTT,
            #                    F.QV_OLD, F.QV, F.QC_OLD, F.QC,
            #                    F.dUFLXdt, F.dVFLXdt, F.dPOTTdt, F.dQVdt,
            #                    F.dQCdt, GR.Ad)
            #for i in range(n_iter):
            #    F.UWIND, F.VWIND, F.COLP, F.POTT, F.QV, F.QC \
            #                 = proceed_timestep_jacobson_gpu(GR, GR.stream,
            #                        F.UWIND_OLD, F.UWIND, F.VWIND_OLD, F.VWIND,
            #                        F.COLP_OLD, F.COLP, F.POTT_OLD, F.POTT,
            #                        F.QV_OLD, F.QV, F.QC_OLD, F.QC,
            #                        F.dUFLXdt, F.dVFLXdt, F.dPOTTdt, F.dQVdt,
            #                        F.dQCdt, GR.Ad)
            #print((time.time() - t0)/n_iter)

            ##TODO
            #FIELD2 = np.asarray(F.UWIND)
            #print(np.nanmean((FIELD2)))
            #
            #print()
            #print(np.sum(np.isnan(FIELD2[:,:,:])) -\
            #             np.sum(np.isnan(FIELD1[:,:,:])))
            #print(np.nanmean(FIELD2[:,:,:] - FIELD1[:,:,:]))
            ##print(np.sum(np.isnan(FIELD2[:,:])) - np.sum(np.isnan(FIELD1[:,:])))
            ##print(np.nanmean(FIELD2[:,:] - FIELD1[:,:]))
            #quit()

            #import matplotlib.pyplot as plt
            ##diff = FIELD2[:,:,k] - FIELD1[:,:,k]
            #diff = FIELD2[:,:] - FIELD1[:,:,0]
            #plt.contourf(diff)
            #plt.colorbar()
            #plt.show()
            #quit()

        else:
            F.UWIND, F.VWIND, F.COLP, F.POTT, F.QV, F.QC \
                         = proceed_timestep_jacobson_gpu(GR, GR.stream,
                                F.UWIND_OLD, F.UWIND, F.VWIND_OLD, F.VWIND,
                                F.COLP_OLD, F.COLP, F.POTT_OLD, F.POTT,
                                F.QV_OLD, F.QV, F.QC_OLD, F.QC,
                                F.dUFLXdt, F.dVFLXdt, F.dPOTTdt, F.dQVdt,
                                F.dQCdt, GR.Ad)

    GR.timer.stop('step')
    ##############################
    ##############################

    ##############################
    ##############################
    GR.timer.start('diag')
    diagnose_fields_jacobson(GR, GR_NEW, F, NF)
    GR.timer.stop('diag')
    ##############################
    ##############################

    ############################################################
    ############################################################
    ##########     FINAL
    ############################################################
    ############################################################

    ##############################
    ##############################
    tendencies_jacobson(GR, GR_NEW, F, subgrids, NF)
    if comp_mode == 1:
        F.COLP[:] = F.COLP_NEW[:]
    elif comp_mode == 2:
        if i_run_new_style == 1:
            set_equal[bpg, tpb](F.COLP, F.COLP_NEW)
        else:
            set_equal2D[GR.griddim_xy, GR.blockdim_xy, GR.stream](F.COLP,
                                                                  F.COLP_NEW)
    ##############################
    ##############################

    ##############################
    ##############################
    GR.timer.start('step')
    if comp_mode == 1:
        if i_run_new_style:

            NF.old_to_new(F, host=False)
            Prognostics.euler_forward(
                HOST, GR_NEW,
                **NF.get(Prognostics.fields_prognostic, target=HOST))
            NF.new_to_old(F, host=False)

        else:
            F.UWIND, F.VWIND, F.COLP, F.POTT, F.QV, F.QC \
                         = proceed_timestep_jacobson_c(GR,
                                F.UWIND_OLD, F.UWIND, F.VWIND_OLD, F.VWIND,
                                F.COLP_OLD, F.COLP, F.POTT_OLD, F.POTT,
                                F.QV_OLD, F.QV, F.QC_OLD, F.QC,
                                F.dUFLXdt, F.dVFLXdt, F.dPOTTdt, F.dQVdt, F.dQCdt)
            F.UWIND = np.asarray(F.UWIND)
            F.VWIND = np.asarray(F.VWIND)
            F.COLP = np.asarray(F.COLP)
            F.POTT = np.asarray(F.POTT)
            F.QV = np.asarray(F.QV)
            F.QC = np.asarray(F.QC)

    elif comp_mode == 2:
        if i_run_new_style:

            NF.old_to_new(F, host=False)
            Prognostics.euler_forward(
                DEVICE, GR_NEW,
                **NF.get(Prognostics.fields_prognostic, target=DEVICE))
            NF.new_to_old(F, host=False)

        else:
            F.UWIND, F.VWIND, F.COLP, F.POTT, F.QV, F.QC \
                 = proceed_timestep_jacobson_gpu(GR, GR.stream,
                        F.UWIND_OLD, F.UWIND, F.VWIND_OLD, F.VWIND,
                        F.COLP_OLD, F.COLP, F.POTT_OLD, F.POTT,
                        F.QV_OLD, F.QV, F.QC_OLD, F.QC,
                        F.dUFLXdt, F.dVFLXdt, F.dPOTTdt, F.dQVdt, F.dQCdt, GR.Ad)

    GR.timer.stop('step')
    ##############################
    ##############################

    ##############################
    ##############################
    GR.timer.start('diag')
    diagnose_fields_jacobson(GR, GR_NEW, F, NF)
    GR.timer.stop('diag')