Selections#

Selection basics#

The Selection class allows you to run a large number of operations in parallel by manipulating whole collections of SimAI models (Geometries, Predictions, and Post-Processings instances).

You create a selection by combining a list of Geometry instances with a list of BoundaryConditions instances:

from ansys.simai.core.data.selections import Selection

geometries = simai.geometries.list()[:4]
boundary_conditions = [dict(Vx=vx) for vx in [12.2, 12.4, 12.6]]
selection = Selection(geometries, boundary_conditions)

The resulting selection contains all possible combinations between the geometries and boundary conditions. Each of those combinations is a Point instance, which can be viewed as a potential Prediction instance.

At first, all predictions may not exist. However, you can use the run_predictions() method to run them:

# run all predictions
selection.run_predictions()

all_predictions = selection.predictions

Selection API reference#

In essence, a Selection instance is a collection of points instances.

class Point#

Provides a Point object, where a prediction can be run.

A point is at the intersection of a Geometry isstance and BoundaryConditions instance.

run_prediction(boundary_conditions: Dict[str, Number])#

Run the prediction on the geometry for this boundary condition.

property boundary_conditions: Dict[str, Number]#

BoundaryConditions object for the Point instance.

property geometry: Geometry#

Geometry object for the Point instance.

property prediction: Prediction | None#

Prediction instance corresponding to the point or None if no prediction has yet been run.

class Selection#

Provides a Selection object, which is a collection of Points instances.

Selections are built from a list of Geometries instances and a list of BoundaryConditions instances.

The resulting selection contains all combinations between the geometries and the boundary conditions.

Parameters:
  • geometries (Geometry | List[Geometry]) – Geometries to include in the selection.

  • boundary_conditions (Dict[str, Number] | List[Dict[str, Number]]) – Boundary conditions to include in the selection.

  • tolerance (float | None) – Optional delta to apply to boundary condition equality. The default is 10**-6. If the difference between two boundary conditions is lower than the tolerance, the two boundary conditions are considered as equal.

get_runnable_predictions() List[Point]#

List of all Points instances in the selection where predictions haven’t been run yet.

reload() None#

Refreshes the predictions in the selection.

This method loads any predictions run from another session and removes possible deleted predictions.

run_predictions() None#

Run all missing predictions in the selection.

wait() None#

Wait for all ongoing operations (predictions and postprocessings) in the selection to finish.

Raises:
property boundary_conditions: List[Dict[str, Number]]#

List of all existing BoundaryConditions instances in the selection.

property geometries: List[Geometry]#

List of all existing Geometries instances in the selection.

property points: List[Point]#

List of all Points instances in the selection.

property points_with_prediction: List[Point | None]#

List of all Points instances in the selection where predictions exist.

property points_without_prediction: List[Point | None]#

List of all Points instances in the selection where predictions don’t exist.

property post: SelectionPostProcessingsMethods#

Namespace containing methods to access and run postprocessings for the predictions in the selection.

For more information, see the SelectionPostProcessingsMethods class.

property predictions: List[Prediction]#

List of all existing Prediction instances in the selection.

Postprocessing basics#

The post namespace allows you to run and access all postprocessings for existing predictions. For available postprocessings, see the SelectionPostProcessingsMethods class.

coeffs = selection.post.global_coefficients()

coeffs.data  # is a list of results of each post-processings.

You can use the export() method to export results in batch for exportable postprocessings (GlobalCoefficients and SurfaceEvol instances):

selection.post.surface_evol(axis="x", delta=13.5).export("xlsx").download(
    "/path/to/file.xlsx"
)

Note that a CSV export generates a ZIP file containing multiple CSV files. You can read them directly using Python’s zipfile<https://docs.python.org/3/library/zipfile.html> module:

import zipfile
import csv
from io import TextIOWrapper

data = selection.post.global_coefficients().export("csv.zip").in_memory()

with zipfile.ZipFile(data) as archive:
    csv_data = csv.reader(TextIOWrapper(archive.open("Global_Coeffs.csv")))

    # or with pandas:
    import pandas as pd

    df_geom = pd.read_csv(archive.open("Geometries.csv"))

You can download binary postprocessings results by looping on the list:

for vtu in selection.post.volume_vtu():
    vtu.data.download(f"/path/to/vtu_{vtu.id}")

Postprocessing API reference#

class SelectionPostProcessingsMethods#

Acts as a namespace inside Selection objects, allowing you to access or run postprocessings on whole selections.

global_coefficients() ExportablePPList[GlobalCoefficients]#

Compute or get the global coefficients of the selected predictions.

This is a non-blocking method. It returns an ExportablePPList instance of GlobalCoefficients objects without waiting. Those PostProcessing objects 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 waited upon with the wait() method.

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

Returns:

ExportablePPList instance of GlobalCoefficients objects.

Return type:

ExportablePPList[GlobalCoefficients]

slice(axis: str, coordinate: float) PPList[Slice]#

Compute or get a slice from each prediction in the selection.

This is a non-blocking method. It returns a PPList instance of Slice objects without waiting. Those PostProcessing objects 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 waited upon with the wait() method.

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

The slices are in the NPZ format.

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

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

Returns:

PPList list of Slice objects.

Return type:

PPList[Slice]

surface_evol(axis: str, delta: float) ExportablePPList[SurfaceEvol]#

Compute or get the SurfaceEvol of the predictions for specific parameters.

This is a non-blocking method. It returns an ExportablePPList instance of SurfaceEvol objects without waiting. Those PostProcessing objects 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 waited upon with the wait() method.

The computation is launched only on the 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 the SurfaceEvol on.

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

Returns:

ExportablePPList instance of SurfaceEvol objects.

Return type:

ExportablePPList[SurfaceEvol]

surface_vtp() PPList[SurfaceVTP]#

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

This is a non-blocking method. It returns a PPList instance of SurfaceVTP objects without waiting. Those PostProcessing objects 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 waited upon with the wait() method.

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

Returns:

PPList instance of SurfaceVTP objects.

Return type:

PPList[SurfaceVTP]

volume_vtu() PPList[VolumeVTU]#

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

This is a non-blocking method. It returns a PPList instance of VolumeVTU objects without waiting. Those PostProcessing objects 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 waited upon with the wait() method.

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

Returns:

PPList instance of VolumeVTU objects.

Return type:

PPList[VolumeVTU]

Collections#

class PPList#

Provides a subclass of the list class for storing postprocessings and adding a few shortcut methods.

As a list subclass, the PPList class supports any list operation. Its elements can be iterated on and accessed by index.

wait()#

Wait for all concerned postprocessings to finish.

property data: List[Dict[str, List]] | List[DownloadableResult]#

List containing the data of the underlying postprocessings.

This is a blocking method, which returns once the data of all postprocessings is ready.

class ExportablePPList#

Provides a subclass of the PPList class for downloading the results of a group of postprocessings.

As a list subclass, the ExportablePPList class supports any list operation. Its elements can be iterated on and accessed by index.

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 exported 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

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