ibfoamrig.core.FoamCase#
- class ibfoamrig.core.FoamCase(path, label='', distribution='org')[source]#
Bases:
objectAn 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:
- 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:
- read_field(name, time='latest')[source]#
Reads a field file from a time directory.
- Parameters:
- Returns:
The internal field.
- Raises:
TimeNotFoundError – If the time directory does not exist.
FileNotFoundError – If the field file does not exist.
FoamParseError – If the file cannot be parsed.
- Return type:
- 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
Cfield, written bypostProcess -func writeCellCentres. Cell volumes are added if aVfield exists.- Parameters:
- Returns:
The field data, with cells in mesh order.
- Raises:
TimeNotFoundError – If the time directory does not exist.
FileNotFoundError – If the cell centres or a field are missing.
ValueError – If a field does not match the number of cells.
- Return type:
- field_data(table, *, fields=None)[source]#
Loads a table written by a function object.
- Parameters:
- Returns:
The loaded field data.
- Raises:
FileNotFoundError – If the table does not exist.
FoamParseError – If a requested column is missing.
- Return type:
- residuals(function='residuals')[source]#
Loads the residuals written by the residuals function object.
A restarted run writes one
residuals.datper 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:
NotImplementedError – For
"com"cases, whose output format is not supported yet.FileNotFoundError – If no residual file exists.
FoamParseError – If a file is malformed.
- Return type:
- interpolation(table, cells)[source]#
Loads IBM interpolation info and joins the cell centres.
- Parameters:
- Returns:
The interpolation data, one row per boundary cell.
- Raises:
FileNotFoundError – If the table does not exist.
ValueError – If a boundary cell is missing from
cells.
- Return type:
- 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), seeibfoamrig.io.read_stl.- Raises:
FileNotFoundError – If the file does not exist.
FoamParseError – If the file holds no triangles.
- Return type:
- 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
-1elsewhere, so only positive values are included.- Parameters:
- Returns:
Cell count, mean, minimum and maximum over the boundary cells.
- Raises:
TimeNotFoundError – If the time directory does not exist.
FileNotFoundError – If the field file does not exist.
ValueError – If the field is not a scalar or has no positive values.
- Return type:
- 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:
FileNotFoundError – If the script does not exist.
ScriptError – If the script cannot be started ot exits with a non-zero code.