ibfoamrig.core.FoamCase#

class ibfoamrig.core.FoamCase(path, label='', distribution='org')[source]#

Bases: object

An OpenFOAM case directory.

Variables:
  • path (pathlib.Path) – Path to the case directory.

  • label (str) – Name of the case in plots and messages. Defaults to the name of the case directory.

  • distribution (ibfoamrig.typing.Distribution) – OpenFOAM distribution that ran the case.

times(*, no_zero=False)[source]#

Lists the time directories in ascending order.

Parameters:

no_zero (bool) – If True, the zero time directory is left out.

Returns:

The time directories, empty if there are none.

Return type:

list[TimeDirectory]

time(time='latest')[source]#

Finds a time directory.

Parameters:

time (TimeSpec) – "latest", a directory name or a time value.

Returns:

The matching time directory.

Raises:

TimeNotFoundError – If no time directory matches.

Return type:

TimeDirectory

read_field(name, time='latest')[source]#

Reads a field file from a time directory.

Parameters:
  • name (str) – Field name.

  • time (TimeSpec) – The time directory, see time.

Returns:

The internal field.

Raises:
Return type:

FoamField

fields_at(names, time='latest', *, centres='C', volumes='V')[source]#

Builds field data from the field files of a time directory.

The cell centres come from the C field, written by postProcess -func writeCellCentres. Cell volumes are added if a V field exists.

Parameters:
  • names (list[str]) – Fields to include.

  • time (TimeSpec) – The time directory, see time.

  • centres (str) – Name of the cell-centre field.

  • volumes (str | None) – Name of the cell-volume field, or None to skip it.

Returns:

The field data, with cells in mesh order.

Raises:
Return type:

FieldData

field_data(table, *, fields=None)[source]#

Loads a table written by a function object.

Parameters:
  • table (StrPath) – Path to the table, relative to the case directory.

  • fields (list[str] | None) – Field columns to keep. If None, all are loaded.

Returns:

The loaded field data.

Raises:
Return type:

FieldData

residuals(function='residuals')[source]#

Loads the residuals written by the residuals function object.

A restarted run writes one residuals.dat per start time. They are joined in time order. Where runs overlap, the later run is kept.

Parameters:

function (str) – Name of the function object.

Returns:

The residuals of the whole run.

Raises:
Return type:

ResidualData

interpolation(table, cells)[source]#

Loads IBM interpolation info and joins the cell centres.

Parameters:
  • table (StrPath) – Path to the interpolation info, relative to the case directory.

  • cells (FieldData) – Field data of this case providing the cell centres.

Returns:

The interpolation data, one row per boundary cell.

Raises:
Return type:

InterpolationData

surface(path)[source]#

Reads an STL surface of the case.

Parameters:

path (StrPath) – Path to the STL file, relative to the case directory.

Returns:

Vertex coordinates with shape (n, 3, 3), see ibfoamrig.io.read_stl.

Raises:
Return type:

ndarray[tuple[Any, …], dtype[float64]]

boundary_stats(field='yPlusi', time='latest')[source]#

Summarises a field over the IBM boundary cells.

The solver writes boundary fields such as with a positive values in boundary cells and zero or -1 elsewhere, so only positive values are included.

Parameters:
  • field (str) – Name of the field.

  • time (TimeSpec) – The time directory, see time.

Returns:

Cell count, mean, minimum and maximum over the boundary cells.

Raises:
Return type:

FieldStats

run(script, *args)[source]#

Runs a script with the case directory as working directory.

The script’s output does to the terminal as usual.

Parameters:

script (StrPath) – Path to an executable script. A relative path is resolved against the case directory, e.g. "Allrun".

Raises: