def load_field_3d(datadir, config, time, name):
    # Set parameters.
    time *= config.T  # convert to dimensional time
    timestep = int(time / config.dt)  # time-step index
    # Load gridline coordinates from file.
    filepath = datadir / 'grid.h5'
    x, y, z = petibmpy.read_grid_hdf5(filepath, name)
    # Shift z locations to match figures of Li & Dong (2016).
    z -= config.S / 2
    # Load 3D field solution from file.
    filepath = datadir / f'{timestep:0>7}.h5'
    field = petibmpy.read_field_hdf5(filepath, name)
    # Return grid and streamwise vorticity.
    return (x, y, z), field
Esempio n. 2
0
def petibm_load_grid_and_field(datadir, timestep, name):
    """Load the gridlines and values of a field at a given time step.

    Parameters
    ----------
    datadir : pathlib.Path
        Directory with the data to load.
    timestep : int
        Time-step index.
    name : str
        Name of the field to read, e.g. 'u', 'v', or 'p'.

    Returns
    -------
    tuple
        Gridline locations in each direction as a tuple of 1D arrays of floats.
    numpy.ndarray
        Field values at given time step.

    """
    grid = petibmpy.read_grid_hdf5(datadir / 'grid.h5', name)
    field = petibmpy.read_field_hdf5(datadir / f'{timestep:0>7}.h5', name)
    return grid, field
# Create data type to store information about annotation.
Annotation = collections.namedtuple('Annotation',
                                    ['text', 'xytext', 'xyarrow'])

# ----------------------------------------------------------------------------
# Plot the 2D slice of the streamwise vorticity in the y/z plane at x/c = 0.3.
# ----------------------------------------------------------------------------

# Load the gridline coordinates from file.
filepath = datadir / 'grid.h5'
x, y, z = petibmpy.read_grid_hdf5(filepath, 'wx')

# Load the field solution from file.
filepath = datadir / '{:0>7}.h5'.format(timestep)
wx = petibmpy.read_field_hdf5(filepath, 'wx')

# Interpolate the vorticity component in the y/z plane in the near wake.
xloc = 0.3  # location along the x direction (near wake)
wx_tmp = numpy.swapaxes(wx, -1, 0)
wx_xloc = petibmpy.linear_interpolation(wx_tmp, x, xloc)

# Create the Matplotlib figure.
fig, ax = pyplot.subplots(figsize=(4.0, 4.0))
ax.set_xlabel('z/c')
ax.set_ylabel('y/c')

# Add wing to the plot.
ax.add_patch(
    patches.Ellipse((0.0, 0.0),
                    config.S,
Esempio n. 4
0

name = 'wz'  # name of the vorticity variable
timestep = 20000  # final time-step index
show_figure = True  # if True, display the figure

# Set the simulation and data directories.
simudir = pathlib.Path(__file__).absolute().parents[1]
datadir = simudir / 'output'

# Load the gridlines from file.
filepath = datadir / 'grid.h5'
x, y = petibmpy.read_grid_hdf5(filepath, name)
# Load the vorticity field from file.
filepath = datadir / f'{timestep:0>7}.h5'
wz = petibmpy.read_field_hdf5(filepath, name)
# Load the boundary coordinates from file.
filepath = simudir / 'cylinder.body'
xb, yb = petibmpy.read_body(filepath, skiprows=1)

# Plot the contours of the vorticity field.
pyplot.rc('font', family='serif', size=16)
fig, ax = pyplot.subplots(figsize=(6.0, 6.0))
ax.set_xlabel('x / D')
ax.set_ylabel('y / D')
levels = numpy.arange(-3.0, 3.0 + 0.4 / 2, 0.4)
ax.contour(x, y, wz, levels=levels, colors='black')
ax.plot(xb, yb, color='red')
ax.axis('scaled', adjustable='box')
ax.set_xlim(-1.0, 5.0)
ax.set_ylim(-2.0, 2.0)
ax2.set_ylabel('v')

for Re, timestep in zip(Res, timesteps):
    # Load data from Ghia et al. (1982).
    adir = rootdir / 'data'
    filepath = adir / 'ghia_et_al_1982_lid_driven_cavity.dat'
    yu_g, uc_g, xv_g, vc_g = load_data_ghia_et_al_1982(filepath, str(Re))

    # Load gridlines and velocity fields.
    simudir = maindir / f'liddrivencavity2dRe{Re}'
    datadir = simudir / 'output'
    filepath = datadir / 'grid.h5'
    xu, yu = petibmpy.read_grid_hdf5(filepath, 'u')
    xv, yv = petibmpy.read_grid_hdf5(filepath, 'v')
    filepath = datadir / f'{timestep:0>7}.h5'
    u = petibmpy.read_field_hdf5(filepath, 'u')
    v = petibmpy.read_field_hdf5(filepath, 'v')

    # Interpolate solution at centerlines of the cavity.
    uc = petibmpy.linear_interpolation(u.T, xu, 0.5)
    vc = petibmpy.linear_interpolation(v, yv, 0.5)

    # Plot the velocity profiles.
    ax1.plot(yu, uc, label=f'Re = {Re}')
    label = ('Ghia et al. (1982)' if Re == Res[-1] else None)
    ax1.plot(yu_g,
             uc_g,
             label=label,
             linewidth=0,
             color='black',
             marker='o',
Esempio n. 6
0
import petibmpy

show_figure = True  # if True, display the figure(s)
simudir = pathlib.Path(__file__).absolute().parents[1]
datadir = simudir / 'output'

# Load the grid from file.
name = 'wz'  # name of the vorticity variable
filepath = datadir / 'grid.h5'
x, y = petibmpy.read_grid_hdf5(filepath, name)

# Load the vorticity at phase angles 0 deg during the last period.
timestep = 7500
filepath = datadir / '{:0>7}.h5'.format(timestep)
wz1 = petibmpy.read_field_hdf5(filepath, name)
# Load the body coordinates at the same time.
filepath = datadir / 'circle_{:0>7}.2D'.format(timestep)
body1 = petibmpy.read_body(filepath)

# Load the vorticity at phase angles 288 deg during the last period.
timestep = 9500
filepath = datadir / '{:0>7}.h5'.format(timestep)
wz2 = petibmpy.read_field_hdf5(filepath, name)
# Load the body coordinates at the same time.
filepath = datadir / 'circle_{:0>7}.2D'.format(timestep)
body2 = petibmpy.read_body(filepath)

# Plot the contours of the vorticity at the two time steps.
pyplot.rc('font', family='serif', size=12)
fig, (ax1, ax2) = pyplot.subplots(ncols=2, figsize=(8.0, 4.0))
Esempio n. 7
0
 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()