Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 3
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)