コード例 #1
0
 def test_interpolate3d(self):
     """Test the function to interpolate a 3D field onto a grid."""
     nz, ny, nx = numpy.shape(self.values)
     x = numpy.linspace(-1.0, 1.0, num=nx)
     y = numpy.linspace(-5.0, 5.0, num=ny)
     z = numpy.linspace(-10.0, 10.0, num=nz)
     # Interpolate on the same grid.
     values2 = petibmpy.interpolate3d(self.values, (x, y, z), (x, y, z))
     self.assertTrue(numpy.allclose(values2, self.values))
コード例 #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
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)