示例#1
0
def degrade(**kwargs):
    f_orig=kwargs['file']
    dir=kwargs['dir']
    id=kwargs['id']
    itime=int(f_orig[-8:-4])
    print f_orig,dir,id,itime

    par=rh.parse_par(f_orig)
    dm=par['domain1']
    Nx=np.array([dm['Nx1'],dm['Nx2'],dm['Nx3']])
    Ng=np.array([dm['NGrid_x1'],dm['NGrid_x2'],dm['NGrid_x3']])
    Nb=Nx/Ng

    grids,NG=rh.calculate_grid(Nx,Nb)

    rstdata=rh.read(f_orig,grids,NG,verbose=True)
    ns=0
    for f in rstdata:
        if f.startswith('SCALAR'): ns+=1
    if kwargs['noscalar']: ns=0
    print 'nscalars:',ns
    
    rstdata_degrade=rh.degrade(rstdata,scalar=ns)
    if kwargs['hydro']:
        fc_varnames=['1-FIELD','2-FIELD','3-FIELD']
        for f in fc_varnames:
            if f in rstdata_degrade: 
                print 'removing {}'.format(f)
                del rstdata_degrade[f]
    grids_deg,NG_deg=rh.calculate_grid(Nx/2,[32,32,64])

    pardata=rh.parse_misc_info(f_orig)
    par=pardata['par']
    par=par.replace('Nx1           = %d' % Nx[0],'Nx1           = %d' % (Nx[0]/2))
    par=par.replace('Nx2           = %d' % Nx[1],'Nx2           = %d' % (Nx[1]/2))
    par=par.replace('Nx3           = %d' % Nx[2],'Nx3           = %d' % (Nx[2]/2))
    par=par.replace('NGrid_x1      = %d' % NG[0],'NGrid_x1      = %d' % NG_deg[0])
    par=par.replace('NGrid_x2      = %d' % NG[1],'NGrid_x2      = %d' % NG_deg[1])
    par=par.replace('NGrid_x3      = %d' % NG[2],'NGrid_x3      = %d' % NG_deg[2])
    par=par.replace('AutoWithNProc = %d' % NG[0]*NG[1]*NG[2],'AutoWithNProc = 0')
    pardata['par']=par

    rh.write_allfile(pardata,rstdata_degrade,grids_deg,\
        dname=dir,id=id,itime=itime,verbose=True,scalar=ns)
示例#2
0
def merge(**kwargs):
    f_lowres = kwargs['file']
    dir = kwargs['dir']
    id = kwargs['id']
    itime = int(f_lowres[-8:-4])
    print f_lowres, dir, id, itime

    par = rh.parse_par(f_lowres)
    dm = par['domain1']
    Nx = np.array([dm['Nx1'], dm['Nx2'], dm['Nx3']])
    Ng = np.array([dm['NGrid_x1'], dm['NGrid_x2'], dm['NGrid_x3']])
    Nb = Nx / Ng

    grids, NG = rh.calculate_grid(Nx, Nb)

    rstdata_low = rh.read(f_lowres, grids, NG, verbose=True)
    ns = 0
    for f in rstdata_low:
        if f.startswith('SCALAR'): ns += 1
    if kwargs['noscalar']: ns = 0
    print 'nscalars:', ns

    pardata_low = rh.parse_misc_info(f_lowres)
    par = pardata_low['par']

    new_Nx = Nx
    new_NB = Nx
    new_grids, new_NG = rh.calculate_grid(new_Nx, new_NB)

    par = par.replace('NGrid_x1      = %d' % NG[0],
                      'NGrid_x1      = %d' % new_NG[0])
    par = par.replace('NGrid_x2      = %d' % NG[1],
                      'NGrid_x2      = %d' % new_NG[1])
    par = par.replace('NGrid_x3      = %d' % NG[2],
                      'NGrid_x3      = %d' % new_NG[2])
    par = par.replace('AutoWithNProc = %d' % NG[0] * NG[1] * NG[2],
                      'AutoWithNProc = 0')
    pardata_low['par'] = par

    rh.write_allfile(pardata_low,rstdata_low,new_grids,\
        dname=dir,id=id,itime=itime,verbose=True,scalar=ns)
示例#3
0
def refine(**kwargs):
    f_lowres = kwargs['file']
    pdir = os.path.dirname(f_lowres) + '/'
    pid = os.path.basename(f_lowres).split('.')[0]
    dir = kwargs['dir']
    id = kwargs['id']
    itime = int(f_lowres[-8:-4])
    print(f_lowres, pdir, pid)
    print(dir, id, itime)

    files = glob.glob('{}*{}'.format(f_lowres[:-9], f_lowres[-9:]))
    nf = len(files)

    par = rh.parse_par(f_lowres)
    sghost = kwargs['starghost']
    ns = int(par['configure']['nscalars'])
    if kwargs['nscalars'] >= 0: ns = kwargs['nscalars']
    print(sghost, ns)

    dm = par['domain1']
    Nx = np.array([dm['Nx1'], dm['Nx2'], dm['Nx3']])
    Ng = np.array([dm['NGrid_x1'], dm['NGrid_x2'], dm['NGrid_x3']])
    Nb = Nx / Ng
    if not (Ng.prod() == nf):
        print("something wrong...", Ng, nf)
        return

    grids, NG = rh.calculate_grid(Nx, Nb)
    if kwargs['split']:  # just to split restart files
        grids_refine, NG_refine = rh.calculate_grid(Nx,
                                                    [Nb[0] / 2, Nb[1], Nb[2]])
    else:  # refine (2x higher resolution)
        grids_refine, NG_refine = rh.calculate_grid(Nx * 2, [64, 64, 64])

    pardata = rh.parse_misc_info(f_lowres)

    par = pardata['par'].decode()
    print(par)
    if not kwargs['split']:
        par = par.replace('Nx1           = %d' % Nx[0],
                          'Nx1           = %d' % (Nx[0] * 2))
        par = par.replace('Nx2           = %d' % Nx[1],
                          'Nx2           = %d' % (Nx[1] * 2))
        par = par.replace('Nx3           = %d' % Nx[2],
                          'Nx3           = %d' % (Nx[2] * 2))
    par = par.replace('NGrid_x1      = %d' % NG[0],
                      'NGrid_x1      = %d' % NG_refine[0])
    par = par.replace('NGrid_x2      = %d' % NG[1],
                      'NGrid_x2      = %d' % NG_refine[1])
    par = par.replace('NGrid_x3      = %d' % NG[2],
                      'NGrid_x3      = %d' % NG_refine[2])
    par = par.replace('AutoWithNProc = %d' % NG[0] * NG[1] * NG[2],
                      'AutoWithNProc = 0')
    pardata['par'] = par.encode()

    print(par[par.rfind('<domain1'):par.rfind('<problem')])

    for g_orig in grids:
        if g_orig['id'] == 0:
            fname_orig = '{}{}.{:04d}.rst'.format(pdir, pid, itime)
        else:
            fname_orig = '{}{}-id{}.{:04d}.rst'.format(pdir, pid, g_orig['id'],
                                                       itime)
        print(fname_orig)
        fm, rstdata = rh.read_rst_grid(fname_orig, starghost=sghost)

        if kwargs['split']:
            is_refine = g_orig['is']
            ie_refine = is_refine + g_orig['Nx']
        else:
            is_refine = g_orig['is'] * 2
            ie_refine = is_refine + g_orig['Nx'] * 2

        grids_part = []
        for g_new in grids_refine:
            if ((g_new['is'] - is_refine + 1) *
                (g_new['is'] - ie_refine + 1) <= 0).all():
                #print g
                grids_part.append(g_new)
        if kwargs['split']:
            rstdata_refine = rstdata
        else:
            rstdata_refine = rh.refine(rstdata, scalar=ns)
        if kwargs['hydro']:
            fc_varnames = ['1-FIELD', '2-FIELD', '3-FIELD']
            for f in fc_varnames:
                if f in rstdata_refine:
                    print('removing {}'.format(f))
                    del rstdata_refine[f]

        rh.write_allfile(pardata,rstdata_refine,grids_part,grid_disp=is_refine,\
                      id=id,dname=dir,\
                      itime=itime,verbose=True,scalar=ns)
示例#4
0
def main(**kwargs):
    f_lowres=kwargs['file']
    id=kwargs['id']
    print f_lowres,id

    par=rh.parse_par(f_lowres)
    dm=par['domain1']
    Nx=np.array([dm['Nx1'],dm['Nx2'],dm['Nx3']])
    Ng=np.array([dm['NGrid_x1'],dm['NGrid_x2'],dm['NGrid_x3']])
#    Ng=np.array([1,1,1])
    Nb=Nx/Ng

    grids,NG=rh.calculate_grid(Nx,Nb)

    rstdata_low=rh.read(f_lowres,grids,NG,verbose=True)
    ns=0
    for f in rstdata_low:
        if f.startswith('SCALAR'): ns+=1
    if kwargs['noscalar']: ns=0
    print 'nscalars:',ns
    
    #cropping
    if kwargs['crop']: 
        z1=Nx[2]/2-Nx[2]/4
        z2=Nx[2]/2+Nx[2]/4
        x3_orig=[dm['x3min'],dm['x3max']]
        dx=(dm['x3max']-dm['x3min'])/Nx[2]
        xc_pos=np.arange(x3_orig[0],x3_orig[1],dx)+0.5*dx
        x3_new=[xc_pos[z1],xc_pos[z2-1]]
        print z1,z2,xc_pos[0],xc_pos[-1],xc_pos[z1],xc_pos[z2-1]
        rstdata_low=crop(rstdata_low,z1,z2)
    if kwargs['refine']: 
        rstdata_high=rh.refine(rstdata_low,scalar=ns)
    else:
        rstdata_high=rstdata_low
    for i,d in enumerate([rstdata_low,rstdata_high]):
        Bx=d['1-FIELD']
        By=d['2-FIELD']
        Bz=d['3-FIELD']
        dBx = np.diff(Bx,axis=2)
        dBy = np.diff(By,axis=1)
        dBz = np.diff(Bz,axis=0)
        dB=dBx+dBy+dBz
        print np.abs(dB).max(),dB.std()

    pardata_low=rh.parse_misc_info(f_lowres)
    par=pardata_low['par']

    new_Nx=np.array(rstdata_high['DENSITY'].shape)[::-1]
    new_NB=np.array([64,64,64])
    new_grids,new_NG=rh.calculate_grid(new_Nx,new_NB)

    par=par.replace('Nx1           = %d' % Nx[0],'Nx1           = %d' % new_Nx[0])
    par=par.replace('Nx2           = %d' % Nx[1],'Nx2           = %d' % new_Nx[1])
    par=par.replace('Nx3           = %d' % Nx[2],'Nx3           = %d' % new_Nx[2])
    if kwargs['crop']: 
        par=par.replace('x3min         = %d' % x3_orig[0],'x3min         = %d' % x3_new[0])
        par=par.replace('x3max         = %d' % x3_orig[1],'x3max         = %d' % x3_new[1])
    par=par.replace('NGrid_x1      = %d' % NG[0],'NGrid_x1      = %d' % new_NG[0])
    par=par.replace('NGrid_x2      = %d' % NG[1],'NGrid_x2      = %d' % new_NG[1])
    par=par.replace('NGrid_x3      = %d' % NG[2],'NGrid_x3      = %d' % new_NG[2])
    par=par.replace('AutoWithNProc = %d' % NG[0]*NG[1]*NG[2],'AutoWithNProc = 0')
    pardata_low['par']=par

    print par[par.rfind('<domain1'):par.rfind('<problem')]

    rh.write_allfile(pardata_low,rstdata_high,new_grids,\
#    dname='/nobackup/ckim14/%s/rst/' % id,id=id,verbose=True,scalar=ns)
#    dname='/u/ckim14/rst/',id=id,verbose=True,scalar=ns)
#    dname='/tigress/PERSEUS/changgoo/%s/rst/' % id,id=id,verbose=True,scalar=ns)
    dname='/scratch/gpfs/changgoo/%s/rst/' % id,id=id,verbose=True,scalar=ns)