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.args = args 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 # 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 config file self.cfg = Inifile(self.soln["config"])
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.args = args 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 # 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 config file self.cfg = Inifile(self.soln['config'])
def process_restart(args): mesh = read_pyfr_data(args.mesh) soln = read_pyfr_data(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']) return mesh, soln, cfg
def process_restart(args): mesh = read_pyfr_data(args.mesh) soln = read_pyfr_data(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)
def process_tavg(args): infs = {} # Interrogate files passed by the shell for fname in args.infs: # Load solution files and obtain solution times inf = read_pyfr_data(fname) tinf = Inifile(inf['stats']).getfloat('solver-time-integrator', 'tcurr') # Retain if solution time is within limits if args.limits is None or args.limits[0] <= tinf <= args.limits[1]: infs[tinf] = inf # Verify that solutions were computed on the same mesh if inf['mesh_uuid'] != infs[infs.keys()[0]]['mesh_uuid']: raise RuntimeError('Solution files in scope were not computed ' 'on the same mesh') # Sort the solution times, check for sufficient files in scope stimes = sorted(infs.keys()) if len(infs) <= 1: raise RuntimeError('More than one solution file is required to ' 'compute an average') # Initialise progress bar, and the average with first solution pb = ProgressBar(0, 0, len(stimes), 0) avgs = {name: infs[stimes[0]][name].copy() for name in infs[stimes[0]]} solnfs = [name for name in avgs.keys() if name.startswith('soln')] # Weight the initialised trapezoidal mean dtnext = stimes[1] - stimes[0] for name in solnfs: avgs[name] *= 0.5*dtnext pb.advance_to(1) # Compute the trapezoidal mean up to the last solution file for i in xrange(len(stimes[2:])): dtlast = dtnext dtnext = stimes[i+2] - stimes[i+1] # Weight the current solution, then add to the mean for name in solnfs: avgs[name] += 0.5*(dtlast + dtnext)*infs[stimes[i+1]][name] pb.advance_to(i+2) # Weight final solution, update mean and normalise for elapsed time for name in solnfs: avgs[name] += 0.5*dtnext*infs[stimes[-1]][name] avgs[name] *= 1.0/(stimes[-1] - stimes[0]) pb.advance_to(i+3) # Compute and assign stats for a time-averaged solution stats = Inifile() stats.set('time-average', 'tmin', stimes[0]) stats.set('time-average', 'tmax', stimes[-1]) stats.set('time-average', 'ntlevels', len(stimes)) avgs['stats'] = stats.tostr() outf = open(args.outf, 'wb') np.savez(outf, **avgs)
def process_tavg(args): infs = {} # Interrogate files passed by the shell for fname in args.infs: # Load solution files and obtain solution times inf = read_pyfr_data(fname) tinf = Inifile(inf['stats']).getfloat('solver-time-integrator', 'tcurr') # Retain if solution time is within limits if args.limits is None or args.limits[0] <= tinf <= args.limits[1]: infs[tinf] = inf # Verify that solutions were computed on the same mesh if inf['mesh_uuid'] != infs[infs.keys()[0]]['mesh_uuid']: raise RuntimeError('Solution files in scope were not computed ' 'on the same mesh') # Sort the solution times, check for sufficient files in scope stimes = sorted(infs.keys()) if len(infs) <= 1: raise RuntimeError('More than one solution file is required to ' 'compute an average') # Initialise progress bar, and the average with first solution pb = ProgressBar(0, 0, len(stimes), 0) avgs = {name: infs[stimes[0]][name].copy() for name in infs[stimes[0]]} solnfs = [name for name in avgs.keys() if name.startswith('soln')] # Weight the initialised trapezoidal mean dtnext = stimes[1] - stimes[0] for name in solnfs: avgs[name] *= 0.5 * dtnext pb.advance_to(1) # Compute the trapezoidal mean up to the last solution file for i in xrange(len(stimes[2:])): dtlast = dtnext dtnext = stimes[i + 2] - stimes[i + 1] # Weight the current solution, then add to the mean for name in solnfs: avgs[name] += 0.5 * (dtlast + dtnext) * infs[stimes[i + 1]][name] pb.advance_to(i + 2) # Weight final solution, update mean and normalise for elapsed time for name in solnfs: avgs[name] += 0.5 * dtnext * infs[stimes[-1]][name] avgs[name] *= 1.0 / (stimes[-1] - stimes[0]) pb.advance_to(i + 3) # Compute and assign stats for a time-averaged solution stats = Inifile() stats.set('time-average', 'tmin', stimes[0]) stats.set('time-average', 'tmax', stimes[-1]) stats.set('time-average', 'ntlevels', len(stimes)) avgs['stats'] = stats.tostr() outf = open(args.outf, 'wb') np.savez(outf, **avgs)
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, opts) else: for name in sorted(cls.name for cls in subclasses(BasePartitioner)): try: part = get_partitioner(name, pwts) break except RuntimeError: pass else: raise RuntimeError("No partitioners available") # Partition the mesh mesh, part_soln_fn = part.partition(read_pyfr_data(args.mesh)) # Prepare the solutions solnit = (part_soln_fn(read_pyfr_data(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
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_by_name(args.partitioner, pwts, opts) else: for name in sorted(cls.name for cls in subclasses(BasePartitioner)): try: part = get_partitioner_by_name(name, pwts) break except RuntimeError: pass else: raise RuntimeError('No partitioners available') # Partition the mesh mesh, part_soln_fn = part.partition(read_pyfr_data(args.mesh)) # Prepare the solutions solnit = (part_soln_fn(read_pyfr_data(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 it.izip(paths, files): # Compute the output path path = os.path.join(args.outd, os.path.basename(path.rstrip('/'))) # Open and save with open(path, 'wb') as f: np.savez(f, **data)
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
def process_run(args): return read_pyfr_data(args.mesh), None, Inifile.load(args.cfg)
def process_tavg(args): infs = {} # Interrogate files passed by the shell for fname in args.infs: # Load solution files and obtain solution times inf = read_pyfr_data(fname) cfg = Inifile(inf["stats"]) tinf = cfg.getfloat("solver-time-integrator", "tcurr") # Retain if solution time is within limits if args.limits is None or args.limits[0] <= tinf <= args.limits[1]: infs[tinf] = inf # Verify that solutions were computed on the same mesh3 if inf["mesh_uuid"] != next(iter(infs.values()))["mesh_uuid"]: raise RuntimeError("Solution files in scope were not" " computed on the same mesh") # Sort the solution times, check for sufficient files in scope stimes = sorted(infs) if len(infs) <= 1: raise RuntimeError("More than one solution file is required to " "compute an average") # Initialise progress bar pb = ProgressBar(0, 0, len(stimes), 0) # Copy over the solutions from the first time dump solnfs = infs[stimes[0]].soln_files avgs = {s: infs[stimes[0]][s].copy() for s in solnfs} # Weight the initialised trapezoidal mean dtnext = stimes[1] - stimes[0] for name in solnfs: avgs[name] *= 0.5 * dtnext pb.advance_to(1) # Compute the trapezoidal mean up to the last solution file for i in range(len(stimes[2:])): dtlast = dtnext dtnext = stimes[i + 2] - stimes[i + 1] # Weight the current solution, then add to the mean for name in solnfs: avgs[name] += 0.5 * (dtlast + dtnext) * infs[stimes[i + 1]][name] pb.advance_to(i + 2) # Weight final solution, update mean and normalise for elapsed time for name in solnfs: avgs[name] += 0.5 * dtnext * infs[stimes[-1]][name] avgs[name] *= 1.0 / (stimes[-1] - stimes[0]) pb.advance_to(i + 3) # Compute and assign stats for a time-averaged solution stats = Inifile() stats.set("time-average", "tmin", stimes[0]) stats.set("time-average", "tmax", stimes[-1]) stats.set("time-average", "ntlevels", len(stimes)) avgs["stats"] = stats.tostr() # Copy over the ini file and mesh uuid avgs["config"] = infs[stimes[0]]["config"] avgs["mesh_uuid"] = infs[stimes[0]]["mesh_uuid"] # Save to disk with h5py.File(args.outf, "w") as f: for k, v in avgs.items(): f[k] = v
def process_run(args): _process_common(args, read_pyfr_data(args.mesh), None, Inifile.load(args.cfg))