Postprocessings#

Directory#

class PostProcessingDirectory(client: ansys.simai.core.client.SimAIClient)#
delete(post_processing: PostProcessing | str)#

Delete a postprocessing.

Parameters:

post_processing (PostProcessing | str) – ID or model of the postprocessing.

get(id: str) PostProcessing#

Get a specific postprocessing object from the server.

Parameters:

id (str) – ID of the postprocessing.

Returns:

PostProcessing with the given ID if it exists.

Raises:

NotFoundError – No postprocessing with the given ID exists.

Return type:

PostProcessing

list(post_processing_type: Type[PostProcessing] | None = None, prediction: Prediction | str | None = None, workspace: Workspace | str | None = None) List[PostProcessing]#

List the postprocessings in the current workspace or associated with a prediction.

Optionally you can choose to list only postprocessings of a specific type. For the name of the available postprocessings, see Available postprocessings.

Parameters:
  • post_processing_type (Type[PostProcessing] | None) – Type of postprocessing to list.

  • prediction (Prediction | str | None) – ID or model of a prediction. If a value is specified, only postprocessings associated with this prediction are returned.

  • workspace (Workspace | str | None) – ID or model of a workspace. If a value is specified, only postprocessings associated with this workspace are returned.

Raises:

Example

import ansys.simai.core

simai = ansys.simai.core_from_config()
prediction = simai.predictions.list()[0]
post_processings = simai.post_processings.list(
    ansys.simai.core.SurfaceEvol, prediction.id
)
run(post_processing_type: str | Type[PostProcessing], prediction: Prediction | str, parameters: Dict[str, Any] | None = None, **kwargs) PostProcessing#

Run a postprocessing on a prediction.

For the name and the parameters expected by the postprocessings, see Available postprocessings and Nested prediction namespace. Note that the case of the class names must be respected.

Parameters:
  • post_processing_type (str | Type[PostProcessing]) – Type of postprocessing to run as a string or as the class itself.

  • prediction (Prediction | str) – ID or model of the prediction to run the postprocessing for.

  • parameters (Dict[str, Any] | None) – Parameters to apply to the postprocessing, if needed. Alternatively, parameters can be passed as kwargs.

  • **kwargs – Unpacked parameters for the postprocessing.

Examples

import ansys.simai.core

simai = ansys.simai.core_from_config()
prediction = simai.predictions.list()[0]
simai.post_processings.run(
    ansys.simai.core.Slice, prediction, {"axis": "x", coordinate: 50}
)

Using kwargs:

simai.post_processings.run(ansys.simai.core.Slice, prediction, axis="x", coordinate=50)
property info: List[Dict[str, Any]]#

Dictionary containing information about the available postprocessings and their parameters.

Example

from pprint import pprint
import ansys.simai.core

simai = ansys.simai.core.from_config()
post_processing_info = simai.post_processings.info
pprint(post_processing_info)

Model#

class PostProcessing#

Provides the local representation of a PostProcessing object.

This is an abstract class. Depending on the postprocessing, a different implementation is returned. For more information, see Available postprocessings.

delete()#

Delete the postprocessing and its result data.

Raises:

NotFoundError – If the postprocessing has already been deleted.

abstract property data#

Get the data generated by the postprocessing.

The return type may vary depending on the postprocessing. It can be a dictionary or, if the data is binary, a DownloadableResult object, which provides helpers to download the data into a file or in memory.

property parameters: Dict[str, Any] | None#

Parameters used to run the postprocessing.

property prediction: Prediction#

Parent prediction.

The parent prediction is queried if it is not already known by the current SimAPI client session.

See also

property prediction_id: str#

Parent prediction’s ID.

See also

property type: str#

Type of postprocessing that this object represents.

Nested prediction namespace#

class PredictionPostProcessings#

Acts as the namespace inside Prediction objects.

This class allows you to analyze the results of a prediction.

It can be accessed from any prediction object through its post property:

Example

sim = simai.predictions.get("<prediction_id>")
# Run the global coefficients
coefs = sim.post.global_coefficients()
global_coefficients(run: bool = True) GlobalCoefficients | None#

Compute or get the global coefficients of the prediction.

This is a non-blocking method. It returns the GlobalCoefficients object without waiting. This object may not have data right away if the computation is still in progress. Data is filled asynchronously once the computation is finished. The state of computation can be monitored with the is_ready flag or waited upon with the wait() method.

Computation is launched only on first call of this method. Subsequent calls do not relaunch it.

Parameters:

run (bool) – Boolean indicating whether to compute or get the postprocessing. The default is True. If False, the postprocessing is not computed, and None is returned if it does not exist yet.

Returns:

GlobalCoefficients object that eventually contains the global coefficients with its pressure and velocity components. Returns None if run=False and the postprocessing does not exist.

Return type:

GlobalCoefficients | None

list(post_processing_type: Type[PostProcessing] | None = None) List[PostProcessing]#

List the postprocessings associated with the prediction.

See post_processings.list

slice(axis: str, coordinate: float, format: str = 'png', run: bool = True) Slice | None#

Compute or get a slice for specific plane parameters.

This is a non-blocking method. It returns the Slice object without waiting. This object may not have data right away if computation is still in progress. Data is filled asynchronously once the computation is finished. The state of computation can be monitored with the is_ready flag or waited upon with the wait() method.

The computation is launched only on first call of this method with a specific set of parameters. Subsequent calls with the same parameters do not relaunch it.

The slice is in the NPZ format.

Parameters:
  • axis (str) – Axis to slice.

  • coordinate (float) – Coordinate along the given axis to slice at.

  • format (str) – Format of the output. The default is 'png'. Options are 'png' and 'vtp'.

  • run (bool) – Boolean indicating whether to compute or get the postprocessing. The default is True. If False, the postprocessing is not computed, and None is returned if it does not exist yet.

Returns:

Slice object that allows downloading the binary data. Returns None if run=False and the postprocessing does not exist.

Return type:

Slice | None

Example

Make a slice and open it in a new window using the Pillow library.

import ansys.simai.core
from PIL import Image

simai = ansys.simai.core.from_config()
prediction = simai.predictions.list()[0]
slice_data = prediction.post.slice("x", 50).data.in_memory()
slice = Image.open(slice_data)
slice.show()
surface_evol(axis: str, delta: float, run: bool = True) SurfaceEvol | None#

Compute or get the SurfaceEvol for specific parameters.

This is a non-blocking method. It returns the SurfaceEvol object without waiting. This object may not have data right away if computation is still in progress. Data is filled asynchronously once the computation is finished. The state of computation can be monitored with the is_ready flag or waited upon with the wait() method.

The computation is launched only on first call of this method with a specific set of parameters. Subsequent calls with the same parameters do not relaunch it.

Parameters:
  • axis (str) – Axis to compute the surface evol for.

  • delta (float) – Increment of the abscissa in meters.

  • run (bool) – Boolean indicating whether to compute or get the postprocessing. The default is True. If False, the postprocessing is not computed, and None is returned if it does not exist yet.

Returns:

SurfaceEvol that allows access to the values. Returns None if run=False and the postprocessing does not exist.

Return type:

SurfaceEvol | None

surface_vtp(run: bool = True) SurfaceVTP | None#

Compute or get the result of the prediction’s surface in VTP format.

This is a non-blocking method. It returns the PostProcessingVTP object without waiting. This object may not have data right away if the computation is still in progress. Data is filled asynchronously once the computation is finished. The state of computation can be monitored with the is_ready flag or waited upon with the wait() method.

The computation is launched only on first call of this method. Subsequent calls do not relaunch it.

Parameters:

run (bool) – Boolean indicating whether to compute or get the postprocessing. The default is True. If False, the postprocessing is not computed, and None is returned if it does not exist yet.

Returns:

SurfaceVTP object that allows downloading the binary data. Returns None if run=False and the postprocessing does not exist.

Return type:

SurfaceVTP | None

Examples

Run and download a surface VTP.

import ansys.simai.core

simai = ansys.simai.core.from_config()
prediction = simai.predictions.list()[0]
surface_vtp = prediction.post.surface_vtp().data.download("/tmp/simai.vtp")

Run a surface VTP and open a plot using PyVista.

import ansys.simai.core
import pyvista
import tempfile

simai = ansys.simai.core.from_config()
prediction = simai.predictions.list()[0]
surface_vtp_data = prediction.post.surface_vtp().data
# I don't want to save the file locally but pyvista doesn't read file-objects
# Using temporary file as a workaround but a real path can be used instead
with tempfile.NamedTemporaryFile(suffix=".vtp") as temp_vtp_file:
    surface_vtp_data.download(temp_vtp_file.name)
    surface_vtp = pyvista.read(temp_vtp_file.name)
    surface_vtp.plot()
volume_vtu(run: bool = True) VolumeVTU | None#

Compute or get the result of the prediction’s volume in VTU format.

This is a non-blocking method. It returns the PostProcessingVTU object without waiting. This object may not have data right away if the computation is still in progress. Data is filled asynchronously once the computation is finished. The state of computation can be monitored with the is_ready flag or waited upon with the wait() method.

The computation is launched only on first call of this method. Subsequent calls do not relaunch it.

Parameters:

run (bool) – Boolean indicating whether to compute or get the postprocessing. The default is True. If False, the postprocessing is not computed, and None is returned if it does not exist yet.

Returns:

VolumeVTU object that allows downloading the binary data.

Return type:

VolumeVTU | None

Examples

Run and download a volume VTU

import ansys.simai.core

simai = ansys.simai.core.from_config()
prediction = simai.predictions.list()[0]
volume_vtu = prediction.post.volume_vtu().data.download("/tmp/simai.vtu")

Run a volume VTU and open a plot using PyVista.

import ansys.simai.core
import pyvista
import tempfile

simai = ansys.simai.core.from_config()
prediction = simai.predictions.list()[0]
volume_vtu_data = prediction.post.volume_vtu().data
# I don't want to save the file locally but pyvista doesn't read file-objects
# Using temporary file as a workaround but a real path can be used instead
with tempfile.NamedTemporaryFile(suffix=".vtu") as temp_vtu_file:
    volume_vtu_data.download(temp_vtu_file.name)
    volume_vtu = pyvista.read(temp_vtu_file.name)
    volume_vtu.plot()

Available postprocessings#

Note

Depending on the capabilities of your model, some of these objects may not be available in your workspace. You can use the info() method to see which ones are available.

class GlobalCoefficients#

Provides the representation of the global coefficients of a prediction.

The data attribute contains a dictionary representing the global coefficients with its pressure and velocity components.

This class is generated through the PredictionPostProcessings.global_coefficients() method.

export(format: str | None = 'json') DownloadableResult#

Export the postprocessing results in the desired format.

Accessing this property blocks until the data is ready.

Parameters:

format (str | None) – Format to export the data in. The default is 'json'. Options are 'csv.zip', 'json', and 'xlsx'. Note that the 'csv.zip' option exports a ZIP file containing multiple CSV sheets.

Returns:

DownloadableResult object for downloading the exported data into a file or access it in memory.

Return type:

DownloadableResult

property data: Dict[str, List]#

Dictionary containing the global coefficients, including pressure and velocity components.

Accessing this property blocks until the data is ready.

class SurfaceEvol#

Provides the representation of the SurfaceEvol object.

This class is generated through PredictionPostProcessings.surface_evol()

as_dict() Dict[str, Any]#

Download the SurfaceEvol JSON data and load it as a Python dictionary.

Accessing this help method blocks until the data is ready.

export(format: str | None = 'json') DownloadableResult#

Export the postprocessing results in the desired format.

Accessing this property blocks until the data is ready.

Parameters:

format (str | None) – Format to export the data in. The default is 'json'. Options are 'csv.zip', 'json', and 'xlsx'. Note that the 'csv.zip' option exports a ZIP file containing multiple CSV sheets.

Returns:

DownloadableResult object for downloading the exported data into a file or access it in memory.

Return type:

DownloadableResult

property data: DownloadableResult#

DownloadableResult object that allows access to the SurfaceEvol JSON data, both directly in memory any by downloading it into a file.

Accessing this property blocks until the data is ready.

class Slice#

Provides a representation of a slice from the prediction in PNG or VTP format.

This class is generated through the PredictionPostProcessings.slice() method.

property data: DownloadableResult#

DownloadableResult object that allows access to slice data, both directly in memory and by downloading it into a file.

Accessing this property blocks until the data is ready.

Returns:

A DownloadableResult

class SurfaceVTP#

Provides for exporting the surface of the prediction in VTP format.

This class is generated through the surface_vtp() method.

class VolumeVTU#

Provides for exporting the volume of the prediction in VTU format.

This class is generated through the PredictionPostProcessings.volume_vtu() method.

Helpers#

class DownloadableResult#

Provides the object representing a result data for a postprocessing in binary format.

download(file: BinaryIO | RawIOBase | BufferedIOBase | Path | str | PathLike) None#

Download the postprocessing data to the specified file or path.

Parameters:

file (BinaryIO | RawIOBase | BufferedIOBase | Path | str | PathLike) – Binary file-object or path of the file to download the data into.

in_memory() BytesIO#

Load the postprocessing data in memory.

Returns:

io.BytesIO object containing the postprocessing data.

Return type:

BytesIO