Ejemplo n.º 1
0
def distribute_fort(farray,
                    target_path,
                    filename='var.dat',
                    arrs=[
                        'uu', 'rho', 'lnrho', 'ss', 'lnTT', 'aa', 'bb', 'ecr',
                        'fcr', 'shock', 'netheat', 'cooling'
                    ],
                    persist=None,
                    nghosts=3):
    """ take new shape farray and write fortran binary files to new processor
    array
    if farray contains variables not listed in arr, submit arr of correct 
    strings listed in farray order
    if fparray to be included the f.write list will need to be extended below
    and parr array of strings inserted to header
    if persist not None submit tuple triplets of value, type integer id
    """
    os.chdir(target_path)
    datadir = os.getcwd() + '/data/'
    if not os.path.exists(datadir):
        print('error: target_path does not exist')
    dim = pc.read_dim()
    if dim.precision == 'D':
        prec = np.float64
        intp = np.int64
    else:
        prec = np.float32
        intp = np.int32
    nx = (farray.x.size - 2 * nghosts) / dim.nprocx
    ny = (farray.y.size - 2 * nghosts) / dim.nprocy
    nz = (farray.z.size - 2 * nghosts) / dim.nprocz
    if hasattr(farray, 'deltay'):
        tmp_arr = np.zeros(nx + ny + nz + 6 * nghosts + 5)
    else:
        tmp_arr = np.zeros(nx + ny + nz + 6 * nghosts + 4)
    for ipx in range(0, dim.nprocx):
        ix = np.arange(nx + 2 * nghosts) + ipx * nx
        tmpx = farray.f[:, :, :, ix]
        for ipy in range(0, dim.nprocy):
            iy = np.arange(ny + 2 * nghosts) + ipy * ny
            tmpy = tmpx[:, :, iy]
            for ipz in range(0, dim.nprocz):
                iproc = ipx + dim.nprocx * ipy + dim.nprocx * dim.nprocy * ipz
                iz = np.arange(nz + 2 * nghosts) + ipz * nz
                f = ftn(datadir + 'proc' + str(iproc) + '/' + filename, 'w')
                #f = ftn(datadir+'proc'+str(iproc)+'/'+filename, 'w',
                #        header_dtype=np.uint64)
                print('writing ' + datadir + 'proc' + str(iproc) + '/' +
                      filename)
                f.write_record(tmpy[:, iz])
                tmp_arr[0] = farray.t
                tmp_arr[1:nx + 1 + 2 * nghosts] = farray.x[ix]
                tmp_arr[1 + nx + 2 * nghosts:ny + nx + 1 +
                        4 * nghosts] = farray.y[iy]
                tmp_arr[1 + nx + ny + 4 * nghosts:nx + ny + nz + 1 +
                        6 * nghosts] = farray.z[iz]
                tmp_arr[1 + nx + ny + nz + 6 * nghosts:nx + ny + nz + 2 +
                        6 * nghosts] = farray.dx
                tmp_arr[2 + nx + ny + nz + 6 * nghosts:nx + ny + nz + 3 +
                        6 * nghosts] = farray.dy
                tmp_arr[3 + nx + ny + nz + 6 * nghosts:nx + ny + nz + 4 +
                        6 * nghosts] = farray.dz
                if hasattr(farray, 'deltay'):
                    tmp_arr[4 + nx + ny + nz + 6 * nghosts:nx + ny + nz + 5 +
                            6 * nghosts] = farray.deltay
                f.write_record(tmp_arr)
                #f.write_record(np.float32(farray.t))
                #f.write_record(farray.x[ix])
                #f.write_record(farray.y[iy])
                #f.write_record(farray.z[iz])
                #f.write_record(farray.dx)
                #f.write_record(farray.dy)
                #f.write_record(farray.dz)
                #if hasattr(farray,'deltay'):
                #    f.write_record(farray.deltay)
                if not persist == None:
                    for pers in persist:
                        f.write_record(pers[0])
                        f.write_record(pers[1])
                f.close()
Ejemplo n.º 2
0
def distribute_fort(
                     farray,
                     target_path,
                     filename='var.dat',
                     arrs=[
                            'uu',
                            'rho',
                            'lnrho',
                            'ss',
                            'lnTT',
                            'aa',
                            'bb',
                            'ecr',
                            'fcr',
                            'shock',
                            'netheat',
                            'cooling'
                          ],
                     persist=None,
                     nghosts=3
                   ):
    """ take new shape farray and write fortran binary files to new processor
    array
    if farray contains variables not listed in arr, submit arr of correct 
    strings listed in farray order
    if fparray to be included the f.write list will need to be extended below
    and parr array of strings inserted to header
    if persist not None submit tuple triplets of value, type integer id
    """
    os.chdir(target_path)
    datadir=os.getcwd()+'/data/'
    if not os.path.exists(datadir):
        print('error: target_path does not exist')
    dim=pc.read_dim()
    if dim.precision=='D':
        prec=np.float64
        intp=np.int64
    else:
        prec=np.float32
        intp=np.int32
    nx=(farray.x.size-2*nghosts)/dim.nprocx
    ny=(farray.y.size-2*nghosts)/dim.nprocy
    nz=(farray.z.size-2*nghosts)/dim.nprocz
    if hasattr(farray,'deltay'):
        tmp_arr=np.zeros(nx+ny+nz+6*nghosts+5)
    else:
        tmp_arr=np.zeros(nx+ny+nz+6*nghosts+4)
    for ipx in range(0,dim.nprocx):
        ix=np.arange(nx+2*nghosts)+ipx*nx
        tmpx=farray.f[:,:,:,ix]
        for ipy in range(0,dim.nprocy):
            iy=np.arange(ny+2*nghosts)+ipy*ny
            tmpy=tmpx[:,:,iy]
            for ipz in range(0,dim.nprocz):
                iproc=ipx+dim.nprocx*ipy+dim.nprocx*dim.nprocy*ipz
                iz=np.arange(nz+2*nghosts)+ipz*nz
                f = ftn(datadir+'proc'+str(iproc)+'/'+filename, 'w') 
                #f = ftn(datadir+'proc'+str(iproc)+'/'+filename, 'w',        
                #        header_dtype=np.uint64)
                print('writing '+datadir+'proc'+str(iproc)+'/'+filename)
                f.write_record(tmpy[:,iz])
                tmp_arr[0]=farray.t
                tmp_arr[1:nx+1+2*nghosts]=farray.x[ix]
                tmp_arr[1+nx+2*nghosts:ny+nx+1+4*nghosts]=farray.y[iy]
                tmp_arr[1+nx+ny+4*nghosts:nx+ny+nz+1+6*nghosts]=farray.z[iz]
                tmp_arr[1+nx+ny+nz+6*nghosts:nx+ny+nz+2+6*nghosts]=farray.dx
                tmp_arr[2+nx+ny+nz+6*nghosts:nx+ny+nz+3+6*nghosts]=farray.dy
                tmp_arr[3+nx+ny+nz+6*nghosts:nx+ny+nz+4+6*nghosts]=farray.dz
                if hasattr(farray,'deltay'):
                    tmp_arr[4+nx+ny+nz+6*nghosts:nx+ny+nz+5+6*nghosts]=farray.deltay
                f.write_record(tmp_arr)
                #f.write_record(np.float32(farray.t))
                #f.write_record(farray.x[ix])
                #f.write_record(farray.y[iy])
                #f.write_record(farray.z[iz])
                #f.write_record(farray.dx)
                #f.write_record(farray.dy)
                #f.write_record(farray.dz)
                #if hasattr(farray,'deltay'):
                #    f.write_record(farray.deltay)
                if not persist==None:
                    for pers in persist:
                        f.write_record(pers[0])
                        f.write_record(pers[1])
                f.close()