コード例 #1
0
ファイル: curvilinear.py プロジェクト: wesleybowman/qgsolver
def curvilinear_runs(ncores_x=8, ncores_y=8, ping_mpi_cfg=False):
    ''' Tests with curvilinear grid
    ''' 
    
    if ping_mpi_cfg:
        # escape before computing
        return ncores_x, ncores_y
    
    else:
        # proceeds with computations            
    
        qg = qg_model(hgrid = 'curv_metrics.nc', vgrid = 'curv_metrics.nc',
                      f0N2_file = 'curv_pv.nc',
                      K = 1.e3, dt = 0.5*86400.e0)
        qg.case='curv'
        #
        qg.set_q(file_q='curv_pv.nc')
        qg.invert_pv()
        write_nc([qg.PSI, qg.Q], ['psi', 'q'], 'data/output.nc', qg)
        
        test=1
        if test==0:
            # one time step and store
            qg.tstep(1)
            write_nc([qg.PSI, qg.Q], ['psi', 'q'], 'data/output.nc', qg, create=False)
        elif test==1:
            while qg.tstepper.t/86400. < 200 :
                qg.tstep(1)
                write_nc([qg.PSI, qg.Q], ['psi', 'q'], 'data/output.nc', qg, create=False)
    
        return qg
コード例 #2
0
def uniform_grid_runs(ncores_x=16, ncores_y=16, ping_mpi_cfg=False):
    """
    Tests with uniform grid, closed domains
    """

    start_time = time.time()
    cur_time = start_time

    #
    ncores_x = 2
    ncores_y = 2
    hgrid = {'Nx': 128, 'Ny': 128}
    vgrid = {'Nz': 5}

    if ping_mpi_cfg:
        # escape before computing
        return ncores_x, ncores_y
    else:

        with benchmark() as b:

            # proceeds with computations
            qg = qg_model(hgrid=hgrid,
                          vgrid=vgrid,
                          boundary_types={'periodic': True},
                          K=0.e0,
                          dt=0.5 * 86400.e0,
                          ncores_x=ncores_x,
                          ncores_y=ncores_y,
                          verbose=1,
                          solver='lgmres')
            # default is right preconditioning for: fgmres, qcg
            # default is left  preconditioning for: gmres, bicg
            # bcgsl
            # restart: can you see with one time step effect?
        #
        delt_init = b.delt

        # pv inversion in order to compute psi
        qg.set_q()
        qg.invert_pv()
        #
        bstate = qg.set_bstate(psi0=0., q0=0., beta=1.e-11)

        with benchmark() as b:
            #
            # 100 time step and store
            qg.tstep(5, bstate=bstate)
        #
        delt_compute = b.delt

        if qg._verbose > 0:
            print('----------------------------------------------------')
            print('Elapsed time for all %.1f s \n' % (time.time() - cur_time))

        verbose = qg._verbose
        del qg

        return delt_init, delt_compute, verbose
コード例 #3
0
ファイル: test_basic.py プロジェクト: wesleybowman/qgsolver
def test_L(ncores_x=2, ncores_y=4, ping_mpi_cfg=False):

    if ping_mpi_cfg:
        # escape before computing
        return ncores_x, ncores_y

    else:
        # proceeds with computations

        start_time = time.time()
        cur_time = start_time

        # hgrid = {'Lx':(512-1)*2.e3, 'Ly':(1440-1)*2.e3, 'H':4.e3, \
        #          'Nx':512, 'Ny':1440, 'Nz':100}
        hgrid = {
            'Lx': (256 - 1) * 4.e3,
            'Ly': (720 - 1) * 4.e3,
            'H': 4.e3,
            'Nx': 256,
            'Ny': 720,
            'Nz': 50
        }
        # vgrid = 'data/jet_cfg1_wp5_2km_k1e7_TSUP5_2000a3000j_zlvl_pv.nc'
        vgrid = 'data/jet_cfg1_wp5_4km_k3.2e8_0a1500j_zlvl_pv.nc'
        qg = qg_model(hgrid=hgrid,
                      vgrid=vgrid,
                      f0N2_file=vgrid,
                      K=1.e0,
                      dt=0.5 * 86400.e0)
        qg.case = 'roms'
        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0:
            print 'Elapsed time for qg_model ', str(time.time() - cur_time)
        cur_time = time.time()

        qg.set_psi(file_psi=vgrid)
        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0:
            print 'Elapsed time for set_psi ', str(time.time() - cur_time)
        cur_time = time.time()

        qg.pvinv.L.mult(qg.PSI, qg.Q)
        qg.invert_pv()
        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0:
            print 'Elapsed time for invert_pv ', str(time.time() - cur_time)

        write_nc([qg.PSI, qg.Q], ['psi', 'q'], 'data/Lpsi_invPV.nc', qg)
コード例 #4
0
def nemo_input_runs(ncores_x=2, ncores_y=6, ping_mpi_cfg=False):
    ''' Tests with curvilinear grid
    '''

    # LMX domain: Nx=1032, Ny=756, Nz=300

    # vertical subdomain
    # vdom = {'kdown': 0, 'kup': 50-1, 'k0': 200 }    # linux
    vdom = {'kdown': 0, 'kup': 50 - 1, 'k0': 98}  # linux with mask
    # vdom = {'kdown': 0, 'kup': 100-1, 'k0': 115 }     # Datarmor
    # horizontal subdomain
    # hdom = {'istart': 0, 'iend': 100-1, 'i0': 450,'jstart': 0, 'jend': 100-1,  'j0': 300}   # linux
    hdom = {
        'istart': 0,
        'iend': 100 - 1,
        'i0': 410,
        'jstart': 0,
        'jend': 100 - 1,
        'j0': 590
    }  # linux with mask
    # hdom = {'istart': 0, 'iend': 270-1, 'i0': 135,'jstart': 0, 'jend': 384-1,  'j0': 165}     # medium datarmor
    # hdom = {'istart': 0, 'iend': 672-1, 'i0': 230,'jstart': 0, 'jend': 256-1,  'j0': 200}   # large datarmor
    # 448=8x56
    # 512=8x64

    # set tiling
    ncores_x = 2
    ncores_y = 4  #   linux
    # ncores_x=2; ncores_y=8   #   medium datarmor
    # ncores_x=21; ncores_y=8  # large datarmor

    if ping_mpi_cfg:
        # escape before computing
        return ncores_x, ncores_y

    else:
        # proceeds with computations
        start_time = time.time()
        cur_time = start_time

        # MPI decomposition of the domain
        # case must be defined before ncores for run_caparmor.py
        casename = 'nemo'

        # Top and Bottom boundary condition type: 'N' for Neumann, 'D' for Dirichlet
        bdy_type = {'top': 'N', 'bottom': 'N'}

        datapath = 'data/'
        # datapath = '/home7/pharos/othr/NATL60/DIAG_DIMUP/qgsolver/mode2_fcTrue_fvertTrue/'
        # datapath = '/home7/pharos/othr/NATL60/DIAG_DIMUP/qgsolver/mode2_fcTrue_fvertTrue_new/'
        hgrid = datapath + 'nemo_metrics.nc'
        vgrid = datapath + 'nemo_metrics.nc'
        file_q = datapath + 'nemo_pv.nc'
        file_psi = datapath + 'nemo_psi.nc'
        file_rho = datapath + 'nemo_rho.nc'
        qg = qg_model(hgrid=hgrid,
                      vgrid=vgrid,
                      f0N2_file=file_q,
                      K=1.e0,
                      dt=0.5 * 86400.e0,
                      vdom=vdom,
                      hdom=hdom,
                      ncores_x=ncores_x,
                      ncores_y=ncores_y,
                      bdy_type_in=bdy_type,
                      substract_fprime=True)
        qg.case = casename

        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0:
            print 'Elapsed time for qg_model ', str(time.time() - cur_time)
        cur_time = time.time()

        qg.set_q(file_q=file_q)
        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0:
            print 'Elapsed time for set_q ', str(time.time() - cur_time)
        cur_time = time.time()

        qg.set_psi(file_psi=file_psi)
        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0:
            print 'Elapsed time for set_psi ', str(time.time() - cur_time)
        cur_time = time.time()

        qg.set_rho(file_rho=file_rho)
        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0:
            print 'Elapsed time for set_rho ', str(time.time() - cur_time)
        cur_time = time.time()

        write_nc([qg.PSI, qg.Q], ['psi', 'q'], 'data/input.nc', qg)

        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0:
            print 'Elapsed time for write_nc ', str(time.time() - cur_time)
        cur_time = time.time()

        qg.invert_pv()
        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0:
            print 'Elapsed time for invert_pv ', str(time.time() - cur_time)
        cur_time = time.time()

        write_nc([qg.PSI, qg.Q], ['psi', 'q'], 'data/output.nc', qg)
        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0:
            print 'Elapsed time for write_nc ', str(time.time() - cur_time)
        cur_time = time.time()

        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0: print 'Elapsed time  ', str(cur_time - start_time)

        return qg
コード例 #5
0
def uniform_grid_runs(ncores_x=16, ncores_y=16, ping_mpi_cfg=False):
    """
    Tests with uniform grid, closed domains
    """

    start_time = time.time()
    cur_time = start_time

    # grid
    # nhoes: 512³,  512 procs, 1000³, 4096 procs
    # LMX case: Nx=1032=2³x3x43, Ny=756=2²x3³x7, Nz=300
    #hgrid = {'Nx':1032, 'Ny':756}
    #vgrid = {'Nz':300}
    #

    #
    ncores_x = 2
    ncores_y = 2
    hgrid = {'Nx': 256, 'Ny': 256}
    vgrid = {'Nz': 5}

    # :
    #ncores_x=16; ncores_y=16
    #hgrid = {'Nx':512, 'Ny':512}
    #vgrid = {'Nz':100}
    #vgrid = {'Nz':200}

    # requires 16x8:
    #ncores_x=16; ncores_y=8
    #hgrid = {'Nx':512, 'Ny':512}
    #vgrid = {'Nz':300}

    # requires 16x16
    #ncores_x=16; ncores_y=16
    #hgrid = {'Nx':1024, 'Ny':512}
    #vgrid = {'Nz':300}

    if ping_mpi_cfg:
        # escape before computing
        return ncores_x, ncores_y
    else:

        # proceeds with computations
        qg = qg_model(hgrid=hgrid,
                      vgrid=vgrid,
                      boundary_types={'periodic': True},
                      K=0.e0,
                      dt=0.5 * 86400.e0,
                      ncores_x=ncores_x,
                      ncores_y=ncores_y,
                      verbose=1,
                      solver='bcgsl')
        # default is right preconditioning for: fgmres, qcg
        # default is left  preconditioning for: gmres, bicg
        # restart: can you see with one time step effect?

        # pv inversion
        qg.set_q()
        qg.invert_pv()
        qg.write_state(filename='data/output.nc')
        #
        if True:
            bstate = qg.set_bstate(psi0=0., q0=0., beta=1.e-11)
            #
            # bstate=None # turns off background state
            if False:
                # add the background state to qg.state, debug
                add(qg.state, bstate, da=None)
                qg.write_state(filename='data/output.nc', append=True)
                #
                qg.invert_pv(bstate=bstate)
                #qg.invert_pv(bstate=bstate, addback_bstate=False) # test

        #
        test = 0
        if test == 0:
            # one time step and store
            qg.tstep(10, bstate=bstate)
            qg.write_state(filename='data/output.nc', append=True)
        elif test == 1:
            while qg.tstepper.t / 86400. < 200:
                qg.tstep(2)
                qg.write_state(filename='data/output.nc', append=True)

        if qg._verbose > 0:
            print('----------------------------------------------------')
            print('Elapsed time for all ', str(time.time() - cur_time))

        return qg
コード例 #6
0
def roms_input_runs(ncores_x=4, ncores_y=6, ping_mpi_cfg=False):
    ''' Tests with roms configuration (spatially uniform, vertically stretched)
    '''

    #ncores_x=2; ncores_y=4; # desktop
    #ncores_x=32; ncores_y=12; # datarmor

    if ping_mpi_cfg:
        # escape before computing
        return ncores_x, ncores_y

    else:

        # proceeds with computations
        start_time = time.time()
        cur_time = start_time

        # Top and Bottom boundary condition type: 'N' for Neumann, 'D' for Dirichlet
        #bdy_type = {'top': 'N_PSI', 'bottom': 'N_PSI'}
        #bdy_type = {'top': 'N_PSI', 'bottom': 'D'}
        #bdy_type = {'top': 'D', 'bottom': 'N_PSI'} # dirichlet on top
        bdy_type = {'top': 'D', 'bottom': 'D'}  # dirichlet on top/bottom

        # vertical subdomain
        vdom = {'Nz': 48}

        # horizontal subdomain
        hdom = {'Nx': 100, 'Ny': 150}

        datapath = '../input/'
        outdir = '../output/'
        hgrid = datapath + 'roms_metrics.nc'
        vgrid = datapath + 'roms_metrics.nc'
        file_q = datapath + 'roms_pv.nc'
        file_psi = datapath + 'roms_psi.nc'
        file_bg = datapath + 'roms_bg.nc'

        params = {
            'ncores_x': ncores_x,
            'ncores_y': ncores_y,
            'hgrid': hgrid,
            'vgrid': vgrid,
            'vdom': vdom,
            'hdom': hdom,
            'mask': True,
            'f0N2_file': file_q,
            'K': 2000.e0,
            'dt': 0.02 * d2s,
            'verbose': 1
        }

        ##
        qg = qg_model(boundary_types=bdy_type, **params)

        # start filling in variables
        qg.set_q(file=file_q)
        qg.set_psi(file=file_psi)
        qg.write_state(filename=outdir + 'input.nc')

        # substract background state
        bstate = qg.set_bstate(file=file_bg)
        add(qg.state, bstate, da=None, a2=-1.)
        qg.write_state(filename=outdir + 'input.nc', append=True)

        # reset PV from psi
        #qg.pvinv.q_from_psi(qg.state.Q, qg.state.PSI)

        # make copy of the original state
        state0 = qg.state.copy(qg.da)

        ## PV inversion

        qg.invert_pv()
        qg.write_state(filename=outdir + 'output_full.nc')

        # set lateral boundary conditions to 0
        # this does not work as top and bottom boundary conditions are also using the PSI provided
        #qg.state = state0.copy(qg.da)
        #qg.invert_pv(PSI=qg.state.PSI*0)
        #qg.write_state(filename=outdir+'output_full_lat0.nc')

        ## PV inversion without PV

        qg.state = state0.copy(qg.da)
        qg.state.Q = qg.state.Q * 0
        qg.invert_pv()
        qg.write_state(filename=outdir + 'output_bsqg.nc')

        # set lateral boundary conditions to 0
        # this does not work as top and bottom boundary conditions are also using the PSI provided
        #qg.state = state0.copy(qg.da)
        #qg.state.Q = qg.state.Q*0
        #qg.invert_pv(PSI=qg.state.PSI*0)
        #qg.write_state(filename=outdir+'output_bsqg_lat0.nc')

        if qg._verbose > 0:
            print('----------------------------------------------------')
            print('Elapsed time for all ', str(time.time() - cur_time))

        return qg
コード例 #7
0
def nemo_input_runs(ncores_x=ncores_x, ncores_y=ncores_y, ping_mpi_cfg=False):
    """ Set up processing parameters and run qg solver.
    """

    # activate bg or other field
    fpsi_bg = False
    fpsi_ot = False
    for key, value in bdy_type.items():
        if value in ['NBG', 'DBG']:
            fpsi_bg = True
        if value in ['NOT', 'DOT']:
            fpsi_ot = True

    if ping_mpi_cfg:
        # escape before computing
        return ncores_x, ncores_y

    else:
        # proceeds with computations
        start_time = time.time()
        cur_time = start_time

        # MPI decomposition of the domain
        # case must be defined before ncores for run_caparmor.py
        casename = 'nemo'

        hgrid = datapath + 'nemo_metrics.nc'
        vgrid = datapath + 'nemo_metrics.nc'

        # equivalent boundary condition (to initialize qg solver)
        bdy_type_tmp = copy.copy(bdy_type)
        for key, value in bdy_type_tmp.items():
            if value in ['N', 'NBG', 'NOT']:
                bdy_type_tmp[key] = 'N'
            if value in ['D', 'DBG', 'DOT']:
                bdy_type_tmp[key] = 'D'

        qg = qg_model(hgrid=hgrid,
                      vgrid=vgrid,
                      f0N2_file=file_q,
                      K=1.e0,
                      dt=0.5 * 86400.e0,
                      vdom=vdom,
                      hdom=hdom,
                      ncores_x=ncores_x,
                      ncores_y=ncores_y,
                      bdy_type_in=bdy_type_tmp,
                      substract_fprime=True)

        # reset boundary condition to prescribed value
        qg.bdy_type.update(bdy_type)

        qg.case = casename

        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0:
            print 'Elapsed time for qg_model ', str(time.time() - cur_time)
        cur_time = time.time()

        #         # read 3D variables (variable is set to None if optional and non-existing)
        #         read_nc_3D(qg, ['PSI', 'PSI_BG', 'PSI_OT', 'Q', 'RHO'],
        #                    [file_psi, file_psi_bg, file_psi_ot, file_q, file_rho])

        # initialize 3D-variables

        # set analytically
        #         qg.set_q_analytically()
        #         qg.set_rho_analytically()
        #         qg.set_psi_analytically()

        read_petsc(qg, fpsi_bg, fpsi_ot, file_q, file_rho, file_psi,
                   file_psi_bg, file_psi_ot)

        # build the list of variables to write in input.nc
        if not fpsi_bg and not fpsi_ot:
            petsc_writein = [qg.PSI, qg.Q]
            vname_writein = ['psi', 'q']
        elif fpsi_bg and not fpsi_ot:
            petsc_writein = [qg.PSI, qg.PSI_BG, qg.Q]
            vname_writein = ['psi', 'psi_bg', 'q']
        elif not fpsi_bg and fpsi_ot:
            petsc_writein = [qg.PSI, qg.PSI_OT, qg.Q]
            vname_writein = ['psi', 'psi_ot', 'q']
        elif fpsi_bg and fpsi_ot:
            petsc_writein = [qg.PSI, qg.PSI_BG, qg.PSI_OT, qg.Q]
            vname_writein = ['psi', 'psi_bg', 'psi_ot', 'q']

        write_nc(petsc_writein, vname_writein, 'data/input.nc', qg)

        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0:
            print 'Elapsed time for write_nc ', str(time.time() - cur_time)
        cur_time = time.time()

        if qg._verbose > 1:
            print 'Inversion done'

        #qg.pvinv.solve(qg)
        pvinv_solver(qg, fpsi_bg, fpsi_ot)

        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0:
            print 'Elapsed time for invert_pv ', str(time.time() - cur_time)
        cur_time = time.time()

        write_nc([qg.PSI, qg.Q], ['psi', 'q'], 'data/output.nc', qg)
        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0:
            print 'Elapsed time for write_nc ', str(time.time() - cur_time)
        cur_time = time.time()

        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0: print 'Elapsed time  ', str(cur_time - start_time)

        return qg
コード例 #8
0
ファイル: test_basic.py プロジェクト: wesleybowman/qgsolver
def uniform_grid_runs(ncores_x=16, ncores_y=16, ping_mpi_cfg=False):
    """
    Tests with uniform grid, closed domains
    """

    start_time = time.time()
    cur_time = start_time

    # MPI decomposition of the domain
    # case must be defined before ncores for run_caparmor.py
    casename = 'uniform'

    # grid
    # nhoes: 512³,  512 procs, 1000³, 4096 procs
    # LMX case: Nx=1032=2³x3x43, Ny=756=2²x3³x7, Nz=300
    #hgrid = {'Nx':1032, 'Ny':756}
    #vgrid = {'Nz':300}
    #

    #
    #ncores_x=8; ncores_y=2
    #hgrid = {'Nx':256, 'Ny':256}
    #vgrid = {'Nz':50}

    # :
    ncores_x = 16
    ncores_y = 16
    hgrid = {'Nx': 512, 'Ny': 512}
    #vgrid = {'Nz':100}
    vgrid = {'Nz': 200}

    # requires 16x8:
    #ncores_x=16; ncores_y=8
    #hgrid = {'Nx':512, 'Ny':512}
    #vgrid = {'Nz':300}

    # requires 16x16
    #ncores_x=16; ncores_y=16
    #hgrid = {'Nx':1024, 'Ny':512}
    #vgrid = {'Nz':300}
    # crashes with io

    # no io
    # 512 x 512 x 100 on 8x8: 160 s, 136 iter
    # 512 x 512 x 300 on 8x8: crash, out of memory
    #     -------     on 16x8: 237 s, 144 iter
    # 1024 x 512 x 300 on 16 x 8: crash, out of memory
    #     -------     on 16x16: 379s s, 236 iter

    if ping_mpi_cfg:
        # escape before computing
        return ncores_x, ncores_y

    else:
        # proceeds with computations
        qg = qg_model(hgrid=hgrid,
                      vgrid=vgrid,
                      K=0.e0,
                      dt=0.5 * 86400.e0,
                      ncores_x=ncores_x,
                      ncores_y=ncores_y)
        qg.case = 'uniform'
        #
        qg.set_q()
        qg.set_rho()
        qg.set_psi()
        qg.invert_pv()
        write_nc([qg.PSI, qg.Q], ['psi', 'q'], 'data/output.nc', qg)

        if qg._verbose > 0:
            print '----------------------------------------------------'
            print 'Elapsed time for all ', str(time.time() - cur_time)

        #
        test = -1
        if test == 0:
            # one time step and store
            qg.tstep(1)
            write_nc([qg.PSI, qg.Q], ['psi', 'q'],
                     'data/output.nc',
                     qg,
                     create=False)
        elif test == 1:
            # write/read/write
            qg.tstep(1)
            write_nc([qg.PSI, qg.Q], ['psi', 'q'],
                     'data/output1.nc',
                     qg,
                     create=True)
            qg.set_q(file_q='data/output.nc')
            qg.tstep(1)
            write_nc([qg.PSI, qg.Q], ['psi', 'q'],
                     'data/output1.nc',
                     qg,
                     create=False)
        elif test == 2:
            while qg.tstepper.t / 86400. < 200:
                qg.tstep(1)
                write_nc([qg.PSI, qg.Q], ['psi', 'q'],
                         'data/output.nc',
                         qg,
                         create=False)

        return qg
コード例 #9
0
ファイル: test_basic.py プロジェクト: wesleybowman/qgsolver
def roms_input_runs(ncores_x=2, ncores_y=4, ping_mpi_cfg=False):
    ''' Tests with roms configuration (spatially uniform, vertically stretched)
    '''

    if ping_mpi_cfg:
        # escape before computing
        return ncores_x, ncores_y

    else:
        # proceeds with computations

        start_time = time.time()
        cur_time = start_time

        # MPI decomposition of the domain
        # case must be defined before ncores for run_caparmor.py
        casename = 'roms'

        # vertical subdomain
        # vdom = {'kdown': 0, 'kup': 49, 'k0': 0 }
        vdom = {'kdown': 25, 'kup': 35, 'k0': 15}

        # horizontal subdomain
        # hdom = {'istart': 0, 'iend': 255, 'i0': 0, 'jstart':0, 'jend':721,  'j0': 0}
        hdom = {
            'istart': 50,
            'iend': 200,
            'i0': 40,
            'jstart': 100,
            'jend': 600,
            'j0': 90
        }

        # hgrid = {'Lx':(512-1)*2.e3, 'Ly':(1440-1)*2.e3, 'H':4.e3, \
        #          'Nx':512, 'Ny':1440, 'Nz':100}
        hgrid = {
            'Lx': (256 - 1) * 4.e3,
            'Ly': (720 - 1) * 4.e3,
            'Nx0': 256,
            'Ny0': 722
        }
        # vgrid = 'data/jet_cfg1_wp5_2km_k1e7_TSUP5_2000a3000j_zlvl_pv.nc'
        vgrid = 'data/jet_cfg1_wp5_4km_k3.2e8_0a1500j_zlvl_pv.nc'
        qg = qg_model(hgrid=hgrid,
                      vgrid=vgrid,
                      f0N2_file=vgrid,
                      K=1.e0,
                      dt=0.5 * 86400.e0,
                      vdom=vdom,
                      hdom=hdom,
                      ncores_x=ncores_x,
                      ncores_y=ncores_y)
        qg.case = casename

        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0:
            print 'Elapsed time for qg_model ', str(time.time() - cur_time)
        cur_time = time.time()

        qg.set_q(file_q=vgrid)
        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0:
            print 'Elapsed time for set_q ', str(time.time() - cur_time)
        cur_time = time.time()

        qg.set_psi(file_psi=vgrid)
        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0:
            print 'Elapsed time for set_psi ', str(time.time() - cur_time)
        cur_time = time.time()

        qg.set_rho(file_rho=vgrid)
        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0:
            print 'Elapsed time for set_rho ', str(time.time() - cur_time)
        cur_time = time.time()

        qg.invert_pv()
        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0:
            print 'Elapsed time for invert_pv ', str(time.time() - cur_time)
        cur_time = time.time()

        write_nc([qg.PSI, qg.Q], ['psi', 'q'], 'data/output.nc', qg)
        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0:
            print 'Elapsed time for write_nc ', str(time.time() - cur_time)
        cur_time = time.time()

        if qg.rank == 0:
            print '----------------------------------------------------'
        if qg.rank == 0: print 'Elapsed time  ', str(cur_time - start_time)

        return qg
コード例 #10
0
def uniform_grid_runs(ncores_x=16, ncores_y=16, ping_mpi_cfg=False):
    """
    Tests with uniform grid, closed domains
    """

    start_time = time.time()
    cur_time = start_time

    # grid
    # nhoes: 512³,  512 procs, 1000³, 4096 procs
    # LMX case: Nx=1032=2³x3x43, Ny=756=2²x3³x7, Nz=300
    #hgrid = {'Nx':1032, 'Ny':756}
    #vgrid = {'Nz':300}
    #

    #
    ncores_x = 2
    ncores_y = 2
    hgrid = {'Nx': 256, 'Ny': 256}
    vgrid = {'Nz': 5}

    if ping_mpi_cfg:
        # escape before computing
        return ncores_x, ncores_y
    else:

        # proceeds with computations
        qg = qg_model(hgrid=hgrid,
                      vgrid=vgrid,
                      boundary_types={'periodic': True},
                      ncores_x=ncores_x,
                      ncores_y=ncores_y,
                      verbose=1)

        # pv inversion
        qg.set_q()
        PSI = qg.state.PSI
        Q = qg.state.Q
        qg.write_state(filename='data/output.nc')  # 1

        # axpy(self, alpha, Vec x)
        PSI.axpy(2., Q)  # PSI = PSI + 2*Q = 2Q
        qg.write_state(filename='data/output.nc', append=True)  # 2
        PSI.axpy(2., Q)  # PSI = PSI + 2*Q = 4*Q
        qg.write_state(filename='data/output.nc', append=True)  # 3
        # Computes y = alpha x + y
        # http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecAXPY.html

        # waxpy(self, alpha, Vec x, Vec y)
        PSI.waxpy(2., Q, Q)  # PSI = 2*Q + Q = 3*Q
        qg.write_state(filename='data/output.nc', append=True)  #4
        # Computes w = alpha x + y.
        # http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecWAXPY.html#VecWAXPY

        # copy
        Q.copy(PSI)  # PSI = Q  !! i.e. reverse assignement
        qg.write_state(filename='data/output.nc', append=True)  #4

        if qg._verbose > 0:
            print('----------------------------------------------------')
            print('Elapsed time for all ', str(time.time() - cur_time))

        return qg
コード例 #11
0
def roms_input_runs(ncores_x=2, ncores_y=4, ping_mpi_cfg=False):
    ''' Tests with roms configuration (spatially uniform, vertically stretched)
    '''

    if ping_mpi_cfg:
        # escape before computing
        return ncores_x, ncores_y

    else:
        # proceeds with computations

        start_time = time.time()
        cur_time = start_time

        # MPI decomposition of the domain
        # case must be defined before ncores for run_caparmor.py
        casename = 'roms'

        # Top and Bottom boundary condition type: 'N' for Neumann, 'D' for Dirichlet
        bdy_type = {'top': 'D', 'bottom': 'D', 'periodic': True}
        #bdy_type = {'top':'D', 'bottom':'D'}

        # vertical subdomain
        #vdom = {'kdown': 0, 'kup': 49, 'k0': 0 }
        # vdom = {'kdown': 0, 'kup': 30, 'k0': 10 }
        #vdom = {'Nz': 30}
        vdom = {'Nz': 50}

        # horizontal subdomain
        # hdom = {'istart': 0, 'iend': 255, 'i0': 0, 'jstart':0, 'jend':721,  'j0': 0}
        # hdom = {'Nx': 256, 'j0':300, 'Ny':200}
        hdom = {'Nx': 256, 'Ny': 720}
        # 256 = 2^8
        # 720 = 2^4 x 3^2 x 5

        datapath = '../input/'
        outdir = '../output/'
        hgrid = datapath + 'roms_metrics.nc'
        vgrid = datapath + 'roms_metrics.nc'
        file_psi = datapath + 'roms_psi.nc'
        file_q = datapath + 'roms_pv.nc'
        qg = qg_model(hgrid=hgrid,
                      vgrid=vgrid,
                      f0N2_file=file_q,
                      K=20.e0,
                      vdom=vdom,
                      hdom=hdom,
                      ncores_x=ncores_x,
                      ncores_y=ncores_y,
                      bdy_type_in=bdy_type,
                      substract_fprime=True,
                      verbose=1,
                      flag_pvinv=False,
                      flag_omega=True)
        qg.case = casename

        # prepare inversion
        qg.set_psi(file_psi=file_psi)
        qg.set_w()
        write_nc([qg.PSI, qg.W], ['psi', 'w'], outdir + 'input.nc', qg)

        # invert and store
        qg.invert_omega()
        write_nc([qg.W], ['w'], outdir + 'output.nc', qg)

        return qg
コード例 #12
0
def roms_input_runs(ncores_x=32, ncores_y=12, ping_mpi_cfg=False):
    ''' Tests with roms configuration (spatially uniform, vertically stretched)
    '''

    #ncores_x=2; ncores_y=4; # desktop
    #ncores_x=32; ncores_y=12; # datarmor

    if ping_mpi_cfg:
        # escape before computing
        return ncores_x, ncores_y

    else:

        # proceeds with computations
        start_time = time.time()
        cur_time = start_time

        # Top and Bottom boundary condition type: 'N' for Neumann, 'D' for Dirichlet
        bdy_type = {'top': 'N_PSI', 'bottom': 'N_PSI', 'periodic': True}

        # vertical subdomain
        vdom = {'Nz': 50}

        # horizontal subdomain
        hdom = {'Nx': 256, 'Ny': 720}
        # 256 = 2^8
        # 720 = 2^4 x 3^2 x 5

        datapath = '../input/'
        outdir = '../output/'
        hgrid = datapath + 'roms_metrics.nc'
        vgrid = datapath + 'roms_metrics.nc'
        file_q = datapath + 'roms_pv.nc'
        file_psi = datapath + 'roms_psi.nc'
        #file_rho = datapath+'roms_rho.nc'
        file_bg = datapath + 'roms_bg.nc'

        qg = qg_model(ncores_x=ncores_x,
                      ncores_y=ncores_y,
                      hgrid=hgrid,
                      vgrid=vgrid,
                      vdom=vdom,
                      hdom=hdom,
                      mask=True,
                      boundary_types=bdy_type,
                      f0N2_file=file_q,
                      K=200.e0,
                      dt=0.02 * d2s,
                      verbose=1)

        # start filling in variables
        qg.set_q(file=file_q)
        qg.set_psi(file=file_psi)
        #qg.set_rho(file=file_rho)
        #qg.write_state(filename=outdir+'output0.nc')
        qg.write_state(filename=outdir + 'input.nc')
        # substract background state
        bstate = qg.set_bstate(file=file_bg)
        add(qg.state, bstate, da=None, a2=-1.)
        #qg.state += -bstate
        qg.write_state(filename=outdir + 'input.nc', append=True)
        # after PV inversion
        qg.invert_pv()
        qg.write_state(filename=outdir + 'input.nc', append=True)

        # compute CFL
        CFL = qg.compute_CFL()
        if qg._verbose > 0: print('CFL=' + str(CFL))

        #
        test = 2
        if test == 0:
            #Should be updated
            # one time step and store
            #qg.tstep(1, rho_sb=True, bstate=bstate)
            #qg.write_state(filename=outdir+'output.nc', append=True)
            pass
        elif test == 1:
            #Should be updated
            #while qg.tstepper.t/86400. < 200 :
            #    qg.tstep(50, rho_sb=True, bstate=bstate)
            #    qg.write_state(filename=outdir+'output.nc', append=True)
            pass
        elif test == 2:
            Ndays = 100.  # in days
            dt_out = .1  # in days
            #
            idx = 1
            di = int(dt_out * d2s / qg.tstepper.dt)
            while qg.tstepper.t / d2s < Ndays:
                qg.write_state(filename=outdir + 'output_%.3i.nc' % idx)
                #
                qg.tstep(di, rho_sb=True, bstate=bstate)
                KE = qg.compute_KE()
                if qg._verbose > 0: print(' KE = %.6e' % KE)
                idx += 1

        if qg._verbose > 0:
            print('----------------------------------------------------')
            print('Elapsed time for all ', str(time.time() - cur_time))

        return qg