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)
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)
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, 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