Ejemplo n.º 1
0
def get_vertical_profile_xy(filepath, name, time, xloc, zloc):
    """Return the profile along the y direction at given x and z locations.

    The function loads the solution of from the volume probe at a given time.
    The solution is first interpolated along the z direction and then,
    along the x direction.

    Parameters
    ----------
    filepath : pathlib.Path
        Path of the file with the volume probe data.
    name : str
        Name of the variable to load.
    time : float
        Time value at which to load the data.
    xloc : float
        Location along the x direction at which to interpolate data.
    zloc : float
        Location along the z direction at which to interpolate data.

    Returns
    -------
    numpy.ndarray
        y locations along the profile as a 1D array of floats.
    numpy.ndarray
        Values of the interpolated variable as a 1D array of floats.

    """
    probe = petibmpy.ProbeVolume(name, name)
    (x, y, z), u = probe.read_hdf5(filepath, time)
    u = petibmpy.linear_interpolation(u, z, zloc)
    u = numpy.swapaxes(u, 0, 1)
    u = petibmpy.linear_interpolation(u, x, xloc)
    assert y.size == u.size
    return y, u
probes = []  # will store info about the probes

# Set probe information for the x- and y- components of the velocity.
fields = ['u', 'v']
for field in fields:
    filepath = datadir / 'grid.h5'
    grid = petibmpy.read_grid_hdf5(filepath, field)
    xlocs = [1.0, 2.0, 3.0, 4.0, 5.0]
    for i, xloc in enumerate(xlocs):
        name = f'probe{i + 1}-{field}'
        box = ((xloc, xloc), (-3.0, 3.0), (S / 2, S / 2))
        probe = petibmpy.ProbeVolume(name,
                                     field,
                                     box=box,
                                     adjust_box=True,
                                     grid=grid,
                                     n_sum=nt_period,
                                     path=f'{name}.h5')
        probes.append(probe)

# Set probe information for the z-component of the velocity.
fields = ['w']
for field in fields:
    filepath = datadir / 'grid.h5'
    grid = petibmpy.read_grid_hdf5(filepath, field)
    xlocs = [1.0, 2.0, 3.0, 4.0, 5.0]
    for i, xloc in enumerate(xlocs):
        name = f'probe{i + 1}-{field}'
        box = ((xloc, xloc), (0.0, 0.0), (-3.0, 3.0))
        probe = petibmpy.ProbeVolume(name,
def load_probe_solution(filepath, t, field):
    return petibmpy.ProbeVolume(field, field).read_hdf5(filepath, t)
import numpy
import pathlib

import petibmpy

name = 'p'  # name of the field variable to load
time = 200.0  # final probe record
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 data from last record of the probe.
filepath = datadir / 'probe-p.h5'
probe = petibmpy.ProbeVolume(name, name)
(x, y), p = probe.read_hdf5(filepath, time)

# Define circle outside support region of delta function.
dx = 1.5 / 90  # grid-spacing in the uniform region
R = 0.5 + 3 * dx  # radius 3 cells away from real boundary
nb = 100
theta = numpy.linspace(0.0, 2 * numpy.pi, num=nb + 1)[:-1]
xc, yc = 0.0, 0.0
xb, yb = xc + R * numpy.cos(theta), yc + R * numpy.sin(theta)

# Interpolate the field on extended boundary.
pb = numpy.empty_like(xb)
for i, (xbi, ybi) in enumerate(zip(xb, yb)):
    pi = petibmpy.linear_interpolation(p, y, ybi)
    pb[i] = petibmpy.linear_interpolation(pi, x, xbi)
"""Write the YAML configuration file for the probes."""

import pathlib

import petibmpy


# Create configuration for a volume probe.
probe = petibmpy.ProbeVolume('probe-p', 'p',
                             box=((-0.75, 0.75), (-0.75, 0.75)),
                             viewer='hdf5', path='probe-p.h5',
                             n_sum=1000)
# Save configuration into YAML file.
simudir = pathlib.Path(__file__).absolute().parents[1]
filepath = simudir / 'probes.yaml'
petibmpy.probes_yaml_dump(probe, filepath)