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
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
def _load_eles(self, rallocs, mesh, initsoln, nregs, nonce): basismap = {b.name: b for b in subclasses(BaseShape, just_leaf=True)} # Look for and load each element type from the mesh elemap = {} for f in mesh: m = re.match(f'spt_(.+?)_p{rallocs.prank}$', f) if m: # Element type t = m.group(1) elemap[t] = self.elementscls(basismap[t], mesh[f], self.cfg) # Construct a proxylist to simplify collective operations eles = proxylist(elemap.values()) # Set the initial conditions if initsoln: # Load the config and stats files from the solution solncfg = Inifile(initsoln['config']) solnsts = Inifile(initsoln['stats']) # Get the names of the conserved variables (fields) solnfields = solnsts.get('data', 'fields', '') currfields = ','.join(eles[0].convarmap[eles[0].ndims]) # Ensure they match up if solnfields and solnfields != currfields: raise RuntimeError('Invalid solution for system') # Process the solution for etype, ele in elemap.items(): soln = initsoln[f'soln_{etype}_p{rallocs.prank}'] ele.set_ics_from_soln(soln, solncfg) else: eles.set_ics_from_cfg() # Allocate these elements on the backend for etype, ele in elemap.items(): k = f'spt_{etype}_p{rallocs.prank}' try: curved = ~mesh[k, 'linear'] linoff = np.max(*np.nonzero(curved), initial=-1) + 1 except KeyError: linoff = ele.neles ele.set_backend(self.backend, nregs, nonce, linoff) return eles, elemap
def _load_eles(self, rallocs, mesh, initsoln, nregs, nonce): basismap = {b.name: b for b in subclasses(BaseShape, just_leaf=True)} # Look for and load each element type from the mesh elemap = OrderedDict() for f in mesh: m = re.match('spt_(.+?)_p{0}$'.format(rallocs.prank), f) if m: # Element type t = m.group(1) elemap[t] = self.elementscls(basismap[t], mesh[f], self.cfg) # Construct a proxylist to simplify collective operations eles = proxylist(elemap.values()) # Set the initial conditions if initsoln: # Load the config and stats files from the solution solncfg = Inifile(initsoln['config']) solnsts = Inifile(initsoln['stats']) # Get the names of the conserved variables (fields) solnfields = solnsts.get('data', 'fields', '') currfields = ','.join(eles[0].convarmap[eles[0].ndims]) # Ensure they match up if solnfields and solnfields != currfields: raise RuntimeError('Invalid solution for system') # Process the solution for etype, ele in elemap.items(): soln = initsoln['soln_{0}_p{1}'.format(etype, rallocs.prank)] ele.set_ics_from_soln(soln, solncfg) else: eles.set_ics_from_cfg() # Compute the index of first strictly interior element intoffs = self._compute_int_offsets(rallocs, mesh) # Allocate these elements on the backend for etype, ele in elemap.items(): ele.set_backend(self.backend, nregs, nonce, intoffs[etype]) return eles, elemap
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
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
def _load_eles(self, rallocs, mesh, initsoln, nreg): basismap = {b.name: b for b in subclasses(BaseShape, just_leaf=True)} # Look for and load each element type from the mesh elemap = OrderedDict() for f in mesh: m = re.match('spt_(.+?)_p%d$' % rallocs.prank, f) if m: # Element type t = m.group(1) elemap[t] = self.elementscls(basismap[t], mesh[f], self.cfg) # Construct a proxylist to simplify collective operations eles = proxylist(elemap.values()) # Set the initial conditions either from a pyfrs file or from # explicit expressions in the config file if initsoln: # Load the config and stats files from the solution solncfg = Inifile(initsoln['config']) solnsts = Inifile(initsoln['stats']) # Get the names of the conserved variables (fields) solnfields = solnsts.get('data', 'fields', '') currfields = ','.join(eles[0].convarmap[eles[0].ndims]) # Ensure they match up if solnfields and solnfields != currfields: raise RuntimeError('Invalid solution for system') # Process the solution for k, ele in elemap.items(): soln = initsoln['soln_%s_p%d' % (k, rallocs.prank)] ele.set_ics_from_soln(soln, solncfg) else: eles.set_ics_from_cfg() # Allocate these elements on the backend eles.set_backend(self.backend, nreg) return eles, elemap
class BaseWriter(object): """Functionality for post-processing PyFR data to visualisation formats""" def __init__(self, args): """Loads PyFR mesh and solution files A check is made to ensure the solution was computed on the mesh. :param args: Command line arguments passed from scripts/postp.py :type args: class 'argparse.Namespace' """ self.outf = args.outf # Load mesh and solution files self.soln = read_pyfr_data(args.solnf) self.mesh = read_pyfr_data(args.meshf) # Get element types and array shapes self.mesh_inf = self.mesh.array_info self.soln_inf = self.soln.array_info # Dimensions self.ndims = next(iter(self.mesh_inf.values()))[1][2] self.nvars = next(iter(self.soln_inf.values()))[1][1] # 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 config file self.cfg = Inifile(self.soln['config']) # System and elements classs self.systemscls = subclass_where( BaseSystem, name=self.cfg.get('solver', 'system') ) self.elementscls = self.systemscls.elementscls