Пример #1
0
 def test_write_xdmf_3d(self):
     """Test the function `write_xdmf` for a 3D configuration."""
     names = ['p', 'u', 'v', 'w']
     for name in names:
         datadir = pathlib.Path('none')
         nstart, nt, nsave = 0, 1000, 100
         filepath1 = pathlib.Path(name + '1.xmf')
         petibmpy.write_xdmf(filepath1, datadir, self.gridpath_3d, name,
                             nstart=nstart, nt=nt, nsave=nsave)
         filepath2 = pathlib.Path(name + '2.xmf')
         states = list(range(nstart, nt + 1, nsave))
         petibmpy.write_xdmf(filepath2, datadir, self.gridpath_3d, name,
                             states=states)
         self.assertTrue(filecmp.cmp(filepath1, filepath2))
         filepath1.unlink()
         filepath2.unlink()
Пример #2
0
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)
Пример #3
0
# 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)