Пример #1
0
 def test_read_write_grid_hdf5(self):
     """Test I/O functions for HDF5 format."""
     filepath = pathlib.Path('grid.h5')
     for dim in [2, 3]:
         coords = [self.x, self.y, self.z][:dim]
         petibmpy.write_grid_hdf5(filepath, 'name', *coords)
         coords2 = petibmpy.read_grid_hdf5(filepath, 'name')
         self.assertEqual(len(coords2), len(coords))
         for i in range(dim):
             self.assertTrue(numpy.allclose(coords2[i], coords[i]))
     filepath.unlink()
Пример #2
0
name = 'wx_cc'
simudir = pathlib.Path(__file__).absolute().parents[1]
datadir = simudir / 'output'
gridpath = datadir / 'grid.h5'
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)
Пример #3
0
import petibmpy

name = 'wz'  # name of the field variable

# Get directories.
simudir = pathlib.Path(__file__).absolute().parents[1]
datadir = simudir / 'output' / 'solution'
outdir = simudir / 'output' / 'postprocessing' / (name + '_avg')
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 + '-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)