API Reference

This section is generated automatically using Sphinx autodoc. For full details, see the docstrings in the source code.

Surface field interpolation utilities.

This module provides tools for interpolating volume fields onto surfaces, separating interpolation logic from geometry to allow flexible sampling strategies.

class pyOFTools.interpolation.SurfaceInterpolator(scheme: Literal['cell', 'cellPoint', 'cellPointFace'] = 'cellPoint', use_point_data: bool = False)[source]

Handles interpolation of volume fields onto surfaces.

This class separates the interpolation logic from surface geometry, allowing the same surface to be used with different fields and interpolation schemes without rebuilding the surface.

Attributes:

scheme: OpenFOAM interpolation scheme name use_point_data: Whether to interpolate to surface points (True) or face centers (False)

Example:
>>> from pybFoam import fvMesh, Time, volScalarField
>>> from pybFoam.sampling import sampledPlane
>>> from pyOFTools.interpolation import SurfaceInterpolator
>>>
>>> # Setup mesh and surface
>>> time = Time(".", ".")
>>> mesh = fvMesh(time)
>>> surface = create_plane_surface(mesh, "plane", (0.5, 0, 0), (1, 0, 0))
>>>
>>> # Create interpolator
>>> interpolator = SurfaceInterpolator(scheme="cellPoint", use_point_data=False)
>>>
>>> # Interpolate field
>>> field = volScalarField.from_registry(mesh, "p")
>>> interpolated_values = interpolator.interpolate(field, surface)
interpolate(field: pybFoam.volScalarField | pybFoam.volVectorField | pybFoam.volTensorField | pybFoam.volSymmTensorField, surface: pybFoam.sampling.sampledSurface) pybFoam.scalarField | pybFoam.vectorField | pybFoam.tensorField | pybFoam.symmTensorField[source]

Interpolate a volume field onto a surface.

Args:

field: OpenFOAM volume field to interpolate surface: sampledSurface to interpolate onto

Returns:

Interpolated field values on the surface (on faces or points depending on use_point_data)

Raises:

TypeError: If field type is not supported

pyOFTools.interpolation.create_interpolated_dataset(field: VolFieldType, surface: sampling.sampledSurface, interpolator: SurfaceInterpolator, name: str | None = None) SurfaceDataSet[source]

Convenience function to create a SurfaceDataSet with interpolated values.

This function combines surface geometry and field interpolation into a single dataset object that can be used with the pyOFTools workflow system.

Args:

field: Volume field to interpolate surface: Surface to interpolate onto interpolator: Interpolator instance to use name: Name for the dataset (defaults to field name)

Returns:

SurfaceDataSet with interpolated field values and geometry

Example:
>>> from pyOFTools.interpolation import create_interpolated_dataset, SurfaceInterpolator
>>> from pyOFTools.surfaces import create_plane_surface
>>>
>>> # Create surface and interpolator
>>> surface = create_plane_surface(mesh, "plane", (0.5, 0, 0), (1, 0, 0))
>>> interpolator = SurfaceInterpolator(scheme="cellPoint")
>>>
>>> # Create dataset
>>> field = volScalarField.from_registry(mesh, "alpha.water")
>>> dataset = create_interpolated_dataset(field, surface, interpolator, name="alpha")
>>>
>>> # Use in workflow
>>> from pyOFTools.workflow import WorkFlow
>>> from pyOFTools.aggregators import Sum
>>> workflow = WorkFlow(initial_dataset=dataset).then(Sum())
>>> result = workflow.execute()
class pyOFTools.geometry.BoundaryMesh(*args, **kwargs)[source]
property positions: pybFoam.vectorField
class pyOFTools.geometry.FvMeshInternalAdapter(mesh: pybFoam.fvMesh)[source]
property positions: pybFoam.vectorField
property volumes: pybFoam.scalarField
class pyOFTools.geometry.InternalMesh(*args, **kwargs)[source]
property positions: pybFoam.vectorField
property volumes: pybFoam.scalarField
class pyOFTools.geometry.SampledSetAdapter(sampled_set: pybFoam.sampling.sampledSet)[source]

Adapter for OpenFOAM sampledSet to provide SetGeometry protocol.

This adapter wraps a pybFoam.sampling.sampledSet instance and provides a convenient interface for accessing set geometry information (points and distance).

Example:
>>> from pybFoam import fvMesh, Time
>>> from pybFoam.sampling import meshSearch, sampledSet, UniformSetConfig
>>> from pyOFTools.geometry import SampledSetAdapter
>>>
>>> time = Time(".", ".")
>>> mesh = fvMesh(time)
>>> search = meshSearch(mesh)
>>>
>>> # Create a line sampledSet
>>> config = UniformSetConfig(
...     axis="distance",
...     start=[0, 0, 0],
...     end=[1, 0, 0],
...     nPoints=50
... )
>>> set_dict = config.to_foam_dict()
>>> line = sampledSet.New("myLine", mesh, search, set_dict)
>>>
>>> # Wrap in adapter
>>> adapter = SampledSetAdapter(line)
>>>
>>> # Access geometry
>>> positions = adapter.positions  # vectorField of sample points
>>> distances = adapter.distance   # scalarField of cumulative distances
property distance: pybFoam.scalarField

Return cumulative distance along the set.

property positions: pybFoam.vectorField

Return sample point positions.

class pyOFTools.geometry.SampledSurfaceAdapter(surface: pybFoam.sampling.sampledSurface)[source]

Adapter for OpenFOAM sampledSurface to provide SurfaceMesh protocol.

This adapter wraps a pybFoam.sampling.sampledSurface instance and provides a convenient interface for accessing surface geometry information.

Example:
>>> from pybFoam import sampling, fvMesh, Time, dictionary, word, vector
>>> from pyOFTools.geometry import SampledSurfaceAdapter
>>>
>>> time = Time(".", ".")
>>> mesh = fvMesh(time)
>>>
>>> # Create a plane surface
>>> plane_dict = dictionary()
>>> plane_dict.set("type", word("plane"))
>>> plane_dict.set("basePoint", vector(0.5, 0, 0))
>>> plane_dict.set("normalVector", vector(1, 0, 0))
>>>
>>> surface = sampling.sampledPlane(word("myPlane"), mesh, plane_dict)
>>> adapter = SampledSurfaceAdapter(surface)
>>>
>>> # Access geometry
>>> face_centers = adapter.positions
>>> area = adapter.total_area
property face_area_magnitudes: pybFoam.scalarField

Return face area magnitudes.

property face_areas: pybFoam.vectorField

Return face area vectors.

property face_centers: pybFoam.vectorField

Return face center positions (same as positions).

property name: str

Return the name of the surface.

property points: pybFoam.vectorField

Return surface points (vertices).

property positions: pybFoam.vectorField

Return face center positions of the surface.

property total_area: float

Return total surface area.

update() bool[source]

Update surface if needed.

Returns:

True if surface was updated, False otherwise.

class pyOFTools.geometry.SetGeometry(*args, **kwargs)[source]

Protocol for sampled set geometry.

Represents the geometric information of a sampledSet: an ordered collection of sample points (along lines, curves, or clouds) with a distance metric. Not a mesh in the connectivity sense, but a geometric point collection.

property distance: pybFoam.scalarField

Cumulative distance along the set (or arbitrary metric for clouds).

property positions: pybFoam.vectorField

Sample point positions in 3D space.

class pyOFTools.geometry.SurfaceMesh(*args, **kwargs)[source]

Protocol for surface meshes with geometry information.

property face_area_magnitudes: pybFoam.scalarField

Face area magnitudes.

property face_areas: pybFoam.vectorField

Face area vectors.

property positions: pybFoam.vectorField

Face center positions of the surface.

property total_area: float

Total surface area.