outdir = datadir / 'postprocessing' / name outdir.mkdir(parents=True, exist_ok=True) # Read the cell-centered grid. x, y, z = petibmpy.read_grid_hdf5(gridpath, 'p') # Read the grid of the x-component of the vorticity. grid_wx = petibmpy.read_grid_hdf5(gridpath, 'wx') # Save the grid on which is defined the Q-criterion. gridpath = outdir / 'grid.h5' petibmpy.write_grid_hdf5(gridpath, name, x, y, z) # List of time-step indices to process. timesteps = [7750, 7875, 8000, 8250, 8375, 8500, 8625, 8750, 8875] interp_args = dict(bounds_error=False, method='linear', fill_value=None) for timestep in timesteps: print('[time step {}] Computing the cell-centered x-vorticity ...' .format(timestep)) filepath = datadir / '{:0>7}.h5'.format(timestep) # Load and interpolate the x-vorticity field on the cell-centered grid. wx = petibmpy.read_field_hdf5(filepath, 'wx') wx = petibmpy.interpolate3d(wx, grid_wx, (x, y, z), **interp_args) # Save the cell-centered x-vorticity field into file. filepath = outdir / '{:0>7}.h5'.format(timestep) petibmpy.write_field_hdf5(filepath, name, wx) # Write the XDMF file to visualize with VisIt. filepath = outdir / (name + '.xmf') petibmpy.write_xdmf(filepath, outdir, gridpath, name, states=timesteps)
def test_read_write_field_hdf5(self): """Test the I/O functions.""" petibmpy.write_field_hdf5(self.filepath, self.name, self.values) values = petibmpy.read_field_hdf5(self.filepath, self.name) self.assertTrue(numpy.allclose(values, self.values)) self.filepath.unlink()
# Read 3D grid and write 2D grid. gridpath = simudir / 'output' / 'grid.h5' x, y, _ = petibmpy.read_grid_hdf5(gridpath, name) gridpath = outdir / 'grid.h5' petibmpy.write_grid_hdf5(gridpath, name + '-avg', x, y) # Get temporal parameters. filepath = simudir / 'config.yaml' with open(filepath, 'r') as infile: config = yaml.load(infile, Loader=yaml.FullLoader)['parameters'] dt = config['dt'] timesteps = [80000, 100000] # Average the scalar field along the z-direction and write field. for timestep in timesteps: print('[time step {}]'.format(timestep)) filepath = datadir / '{:0>7}.h5'.format(timestep) data = petibmpy.read_field_hdf5(filepath, name) data_avg = numpy.mean(data, axis=0) filepath = outdir / '{:0>7}.h5'.format(timestep) petibmpy.write_field_hdf5(filepath, name + '-avg', data_avg) # Write XDMF file to visualize field with VisIt. filepath = outdir / (name + '-avg.xmf') petibmpy.write_xdmf(filepath, outdir, gridpath, name + '-avg', dt, states=timesteps)
gridpath = outdir / 'grid.h5' petibmpy.write_grid_hdf5(gridpath, name, x, y, z) # Get temporal parameters. filepath = simudir / 'config.yaml' with open(filepath, 'r') as infile: config = yaml.load(infile, Loader=yaml.FullLoader)['parameters'] nstart, nt, nsave = config['startStep'], config['nt'], config['nsave'] timesteps = list(range(nstart, nstart + nt + 1, nsave)) interp_args = dict(bounds_error=False, method='linear', fill_value=None) for timestep in timesteps: print('[time step {}] Computing the Q-criterion ...'.format(timestep)) filepath = datadir / '{:0>7}.h5'.format(timestep) # Load and interpolate the velocity field on the cell-centered grid. u = petibmpy.read_field_hdf5(filepath, 'u') u = petibmpy.interpolate3d(u, grid_u, (x, y, z), **interp_args) v = petibmpy.read_field_hdf5(filepath, 'v') v = petibmpy.interpolate3d(v, grid_v, (x, y, z), **interp_args) w = petibmpy.read_field_hdf5(filepath, 'w') w = petibmpy.interpolate3d(w, grid_w, (x, y, z), **interp_args) # Compute the Q-criterion. qcrit = petibmpy.qcriterion((u, v, w), (x, y, z)) # Save the Q-criterion into file. filepath = outdir / '{:0>7}.h5'.format(timestep) petibmpy.write_field_hdf5(filepath, name, qcrit) # Write the XDMF file to visualize with VisIt. filepath = outdir / (name + '.xmf') petibmpy.write_xdmf(filepath, outdir, gridpath, name, states=timesteps)
# Get directories. simudir = pathlib.Path(__file__).absolute().parents[1] datadir = simudir / 'output' / 'solution' outdir = simudir / 'output' / 'postprocessing' / name outdir.mkdir(parents=True, exist_ok=True) # Read 3D grid and write 2D grid. gridpath = simudir / 'output' / 'grid.h5' x, y = petibmpy.read_grid_hdf5(gridpath, name) gridpath = outdir / 'grid.h5' petibmpy.write_grid_hdf5(gridpath, name, x, y) # Get temporal parameters. filepath = simudir / 'config.yaml' with open(filepath, 'r') as infile: config = yaml.load(infile, Loader=yaml.FullLoader)['parameters'] dt = config['dt'] states = sorted([int(p.stem) for p in datadir.iterdir()]) for state in states: print('[time step {}]'.format(state)) filename = '{:0>7}.h5'.format(state) filepath = datadir / filename data = petibmpy.read_field_hdf5(filepath, name) filepath = outdir / filename petibmpy.write_field_hdf5(filepath, name, data) # Write XDMF file to visualize field with VisIt. filepath = outdir / (name + '.xmf') petibmpy.write_xdmf(filepath, outdir, gridpath, name, dt, states=states)