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 andBoundaryConditions
instance.- run_prediction(boundary_conditions: Dict[str, Number])#
Run the prediction on the geometry for this boundary condition.
- property prediction: Prediction | None#
Prediction
instance corresponding to the point orNone
if no prediction has yet been run.
- class Selection#
Provides a
Selection
object, which is a collection ofPoints
instances.Selections are built from a list of
Geometries
instances and a list ofBoundaryConditions
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.
- wait() None #
Wait for all ongoing operations (predictions and postprocessings) in the selection to finish.
- Raises:
ansys.simai.core.errors.SimAIError – If a single error occurred when computing this selection’s operations.
ansys.simai.core.errors.MultipleErrors – If multiple exceptions occurred when computing this selection’s operations.
- 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_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 ofGlobalCoefficients
objects without waiting. ThosePostProcessing
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 thewait()
method.The computation is launched only on the first call of this method. Subsequent calls do not relaunch it.
- Returns:
ExportablePPList
instance ofGlobalCoefficients
objects.- Return type:
- 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 ofSlice
objects without waiting. ThosePostProcessing
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 thewait()
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.
- 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 ofSurfaceEvol
objects without waiting. ThosePostProcessing
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 thewait()
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:
- Returns:
ExportablePPList
instance ofSurfaceEvol
objects.- Return type:
- 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 ofSurfaceVTP
objects without waiting. ThosePostProcessing
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 thewait()
method.The computation is launched only on first call of this method. Subsequent calls do not relaunch it.
- Returns:
PPList
instance ofSurfaceVTP
objects.- Return type:
- 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 ofVolumeVTU
objects without waiting. ThosePostProcessing
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 thewait()
method.The computation is launched only on the first call of this method. Subsequent calls do not relaunch it.
Collections#
- class PPList#
Provides a subclass of the
list
class for storing postprocessings and adding a few shortcut methods.As a
list
subclass, thePPList
class supports any list operation. Its elements can be iterated on and accessed by index.- wait()#
Wait for all concerned postprocessings to finish.
- class ExportablePPList#
Provides a subclass of the
PPList
class for downloading the results of a group of postprocessings.As a
list
subclass, theExportablePPList
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:
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.
- in_memory() BytesIO #
Load the postprocessing data in memory.
- Returns:
io.BytesIO
object containing the postprocessing data.- Return type:
BytesIO