Пример #1
0
class BaseWriter(object):
    def __init__(self, args):
        from pyfr.solvers.base import BaseSystem

        self.outf = args.outf

        # Load the mesh and solution files
        self.soln = NativeReader(args.solnf)
        self.mesh = NativeReader(args.meshf)

        # Check solution and mesh are compatible
        if self.mesh['mesh_uuid'] != self.soln['mesh_uuid']:
            raise RuntimeError('Solution "%s" was not computed on mesh "%s"' %
                               (args.solnf, args.meshf))

        # Load the configuration and stats files
        self.cfg = Inifile(self.soln['config'])
        self.stats = Inifile(self.soln['stats'])

        # Data file prefix (defaults to soln for backwards compatibility)
        self.dataprefix = self.stats.get('data', 'prefix', 'soln')

        # Get element types and array shapes
        self.mesh_inf = self.mesh.array_info('spt')
        self.soln_inf = self.soln.array_info(self.dataprefix)

        # Dimensions
        self.ndims = next(iter(self.mesh_inf.values()))[1][2]
        self.nvars = next(iter(self.soln_inf.values()))[1][1]

        # System and elements classes
        self.systemscls = subclass_where(
            BaseSystem, name=self.cfg.get('solver', 'system')
        )
        self.elementscls = self.systemscls.elementscls
Пример #2
0
class BaseWriter(object):
    def __init__(self, args):
        from pyfr.solvers.base import BaseSystem

        self.outf = args.outf

        # Load the mesh and solution files
        self.soln = NativeReader(args.solnf)
        self.mesh = NativeReader(args.meshf)

        # Check solution and mesh are compatible
        if self.mesh['mesh_uuid'] != self.soln['mesh_uuid']:
            raise RuntimeError('Solution "%s" was not computed on mesh "%s"' %
                               (args.solnf, args.meshf))

        # Load the configuration and stats files
        self.cfg = Inifile(self.soln['config'])
        self.stats = Inifile(self.soln['stats'])

        # Data file prefix (defaults to soln for backwards compatibility)
        self.dataprefix = self.stats.get('data', 'prefix', 'soln')

        # Get element types and array shapes
        self.mesh_inf = self.mesh.array_info('spt')
        self.soln_inf = self.soln.array_info(self.dataprefix)

        # Dimensions
        self.ndims = next(iter(self.mesh_inf.values()))[1][2]
        self.nvars = next(iter(self.soln_inf.values()))[1][1]

        # System and elements classes
        self.systemscls = subclass_where(BaseSystem,
                                         name=self.cfg.get('solver', 'system'))
        self.elementscls = self.systemscls.elementscls
Пример #3
0
def process_partition(args):
    # Ensure outd is a directory
    if not os.path.isdir(args.outd):
        raise ValueError('Invalid output directory')

    # Partition weights
    if ':' in args.np:
        pwts = [int(w) for w in args.np.split(':')]
    else:
        pwts = [1]*int(args.np)

    # Element weights
    if args.elewts:
        ewts = {e: int(w) for e, w in (ew.split(':') for ew in args.elewts)}
    else:
        ewts = {'quad': 6, 'tri': 3, 'tet': 3, 'hex': 18, 'pri': 10, 'pyr': 6}

    # Partitioner-specific options
    opts = dict(s.split(':', 1) for s in args.popts)

    # Create the partitioner
    if args.partitioner:
        part = get_partitioner(args.partitioner, pwts, ewts, opts=opts)
    else:
        for name in sorted(cls.name for cls in subclasses(BasePartitioner)):
            try:
                part = get_partitioner(name, pwts, ewts)
                break
            except OSError:
                pass
        else:
            raise RuntimeError('No partitioners available')

    # Partition the mesh
    mesh, rnum, part_soln_fn = part.partition(NativeReader(args.mesh))

    # Prepare the solutions
    solnit = (part_soln_fn(NativeReader(s)) for s in args.solns)

    # Output paths/files
    paths = it.chain([args.mesh], args.solns)
    files = it.chain([mesh], solnit)

    # Iterate over the output mesh/solutions
    for path, data in zip(paths, files):
        # Compute the output path
        path = os.path.join(args.outd, os.path.basename(path.rstrip('/')))

        # Save to disk
        write_pyfrms(path, data)

    # Write out the renumbering table
    if args.rnumf:
        print('etype,pold,iold,pnew,inew', file=args.rnumf)

        for etype, emap in sorted(rnum.items()):
            for k, v in sorted(emap.items()):
                print(etype, *k, *v, sep=',', file=args.rnumf)
Пример #4
0
    def process_restart(self, args):
        mesh = NativeReader(args.mesh)
        soln = NativeReader(args.soln)

        # Ensure the solution is from the mesh we are using
        if soln['mesh_uuid'] != mesh['mesh_uuid']:
            raise RuntimeError('Invalid solution for mesh.')

        self._process_common(args, mesh, soln, self.cfg)
Пример #5
0
def process_partition(args):
    # Ensure outd is a directory
    if not os.path.isdir(args.outd):
        raise ValueError('Invalid output directory')

    # Partition weights
    if ':' in args.np:
        pwts = [int(w) for w in args.np.split(':')]
    else:
        pwts = [1]*int(args.np)

    # Partitioner-specific options
    opts = dict(s.split(':', 1) for s in args.popts)

    # Create the partitioner
    if args.partitioner:
        part = get_partitioner(args.partitioner, pwts, order=args.order,
                               opts=opts)
    else:
        for name in sorted(cls.name for cls in subclasses(BasePartitioner)):
            try:
                part = get_partitioner(name, pwts, order=args.order)
                break
            except OSError:
                pass
        else:
            raise RuntimeError('No partitioners available')

    # Partition the mesh
    mesh, rnum, part_soln_fn = part.partition(NativeReader(args.mesh))

    # Prepare the solutions
    solnit = (part_soln_fn(NativeReader(s)) for s in args.solns)

    # Output paths/files
    paths = it.chain([args.mesh], args.solns)
    files = it.chain([mesh], solnit)

    # Iterate over the output mesh/solutions
    for path, data in zip(paths, files):
        # Compute the output path
        path = os.path.join(args.outd, os.path.basename(path.rstrip('/')))

        # Save to disk
        with h5py.File(path, 'w') as f:
            for k, v in data.items():
                f[k] = v

    # Write out the renumbering table
    if args.rnumf:
        print('etype,pold,iold,pnew,inew', file=args.rnumf)

        for etype, emap in sorted(rnum.items()):
            for k, v in sorted(emap.items()):
                print(','.join(map(str, (etype, *k, *v))), file=args.rnumf)
Пример #6
0
def process_restart(args):
    mesh = NativeReader(args.mesh)
    soln = NativeReader(args.soln)

    # Ensure the solution is from the mesh we are using
    if soln['mesh_uuid'] != mesh['mesh_uuid']:
        raise RuntimeError('Invalid solution for mesh.')

    # Process the config file
    if args.cfg:
        cfg = Inifile.load(args.cfg)
    else:
        cfg = Inifile(soln['config'])

    _process_common(args, mesh, soln, cfg)
Пример #7
0
def Read_stats(vari,Mesh=Mesh):
    
    filename='avg-' + vari +'.pyfrs'
    url=f'DNS-1/2/Channel_180/statistics/avg-' + vari + '.pyfrs' 
    bucket.download_file(url,f'avg-' + Var + '.pyfrs')
    
    
    nx=62
    ny=19
    nz=60
    
    soln = NativeReader(filename)
    #cfg=Inifile(soln['stats'])
    #vari=cfg.get('data','fields')
    #vari = [s.strip() for s in vari.split(',')]
    
    
    dre = h5py.File(filename, 'r')
    sol=[]
    for i in range(npart):
        part=f'tavg_hex_p{i}'
        tmp=dre[part]
        gtmp=tmp[()]
        if i==0:
            sol= gtmp
        else:
            sol=np.concatenate( (sol, gtmp),2)
    
    sol=sol[:,:,Mesh]
    nk,nv,_=sol.shape[:]
    sol=np.reshape(sol,(nk,nv,ny,nz,nx),order='F')
    
    u=build_fields(sol,0)
    
    return u
Пример #8
0
 def parse(self, cmd_args):
     self.args = self.ap.parse_args(cmd_args)
     if self.args.cfg:
         self.cfg = Inifile.load(self.args.cfg)
     else:
         soln = NativeReader(self.args.soln)
         self.cfg = Inifile(soln['config'])
Пример #9
0
def Read_stats(vari, time_step=0, part=0):
    if part == 0:
        dire = rep + 'statistics/avg-'
        filename = dire + vari + f'-{time_step:4.0f}.pyfrs'
    else:
        dire = rep + 'statistics/accumulation/avg-'
        filename = dire + vari + f'.pyfrs'

    nx = 62
    ny = 19
    nz = 60

    soln = NativeReader(filename)
    #cfg=Inifile(soln['stats'])
    #vari=cfg.get('data','fields')
    #vari = [s.strip() for s in vari.split(',')]

    re = h5py.File(filename, 'r')
    sol = []
    for i in range(npart):
        part = f'tavg_hex_p{i}'
        tmp = re[part]
        gtmp = tmp[()]
        if i == 0:
            sol = gtmp
        else:
            sol = np.concatenate((sol, gtmp), 2)

    sol = sol[:, :, Mesh]
    nk, nv, _ = sol.shape[:]
    sol = np.reshape(sol, (nk, nv, ny, nz, nx), order='F')

    K = 0
    u = sol[:, int(K), :, :, :]
    n, ny, nz, nx = u.shape[:]
    n = int(np.asarray(np.cbrt(n), dtype=int))
    u = np.reshape(u, (n, n**2, ny, nz, nx), order='F')
    u = np.transpose(u, (1, 0, 2, 3, 4))
    u = np.reshape(u, (n, n, n, ny, nz, nx), order='F')
    u = np.transpose(u, (0, 3, 1, 2, 4, 5))
    u = np.reshape(u, (n * ny, n, n, nz, nx), order='F')
    u = np.squeeze(u[:, :, :, ::-1, :])
    u = np.reshape(u, (n * ny, n, nz * n, nx), order='F')
    u = np.transpose(u, (0, 2, 1, 3))
    u = np.reshape(u, (n * ny, nz * n, nx * n), order='F')
    u = np.transpose(u, (2, 0, 1))
    return u
Пример #10
0
def Read_solution(time_step, K=None):
    nx = 62
    ny = 19
    nz = 60

    dire = rep + 'solutions/Channel'
    filename = dire + f'-{time_step:010.4f}.pyfrs'

    soln = NativeReader(filename)
    cfg = Inifile(soln['stats'])
    vari = cfg.get('data', 'fields')
    vari = [s.strip() for s in vari.split(',')]
    if K == None:
        K = input(f'variables {vari} :')
        print(f'variable selected {vari[int(K)]}')

    re = h5py.File(filename, 'r')
    sol = []
    for i in range(npart):
        part = f'soln_hex_p{i}'
        tmp = re[part]
        gtmp = tmp[()]
        if i == 0:
            sol = gtmp
        else:
            sol = np.concatenate((sol, gtmp), 2)

    sol = sol[:, :, Mesh]
    nk, nv, _ = sol.shape[:]
    sol = np.reshape(sol, (nk, nv, ny, nz, nx), order='F')

    u = sol[:, int(K), :, :, :]
    n, ny, nz, nx = u.shape[:]
    n = int(np.asarray(np.cbrt(n), dtype=int))
    u = np.reshape(u, (n, n**2, ny, nz, nx), order='F')
    u = np.transpose(u, (1, 0, 2, 3, 4))
    u = np.reshape(u, (n, n, n, ny, nz, nx), order='F')
    u = np.transpose(u, (0, 3, 1, 2, 4, 5))
    u = np.reshape(u, (n * ny, n, n, nz, nx), order='F')
    u = np.squeeze(u[:, :, :, ::-1, :])
    u = np.reshape(u, (n * ny, n, nz * n, nx), order='F')
    u = np.transpose(u, (0, 2, 1, 3))
    u = np.reshape(u, (n * ny, nz * n, nx * n), order='F')
    u = np.transpose(u, (2, 0, 1))
    return u
Пример #11
0
def Read_solutions(time_step,Mesh=Mesh):
    #Mesh,Lx,Ly,Lz =extract_grid()
    nx=62
    ny=19
    nz=60
    
    filename = f'Channel-{time_step:010.4f}.pyfrs'
    
    
    url=f'DNS-1/2/Channel_180/snapshots/Channel-{time_step:010.4f}.pyfrs'
    bucket.download_file(url,f'Channel-{time_step:010.4f}.pyfrs')
    
    soln = NativeReader(filename)
    cfg=Inifile(soln['stats'])
    vari=cfg.get('data','fields')
    vari = [s.strip() for s in vari.split(',')]
    
    re = h5py.File(filename, 'r')
    sol=[]
    for i in range(npart):
        part=f'soln_hex_p{i}'
        tmp=re[part]
        gtmp=tmp[()]
        if i==0:
            sol= gtmp
        else:
            sol=np.concatenate( (sol, gtmp),2)
    
    sol=sol[:,:,Mesh]
    nk,nv,_=sol.shape[:]
    sol=np.reshape(sol,(nk,nv,ny,nz,nx),order='F')
    
    

    
    rho=build_fields(sol,0)
    rhou=build_fields(sol,1)
    rhov=build_fields(sol,2)
    rhow=build_fields(sol,3)
    E=build_fields(sol,4)
    
    os.remove(filename)
    return rho,rhou,rhov,rhow,E
Пример #12
0
def process_run(args):
    _process_common(
        args, NativeReader(args.mesh), None, Inifile.load(args.cfg)
    )
Пример #13
0
    def process_run(self, args):
        # can load from Inifile(string)
        # can also use inifile.set(section, option, value) to set things

        self._process_common(args, NativeReader(args.mesh), None, self.cfg)