diff --git a/src/ansys/simai/core/data/post_processings.py b/src/ansys/simai/core/data/post_processings.py index a47afd7..f6e141e 100644 --- a/src/ansys/simai/core/data/post_processings.py +++ b/src/ansys/simai/core/data/post_processings.py @@ -480,7 +480,7 @@ def surface_vtp( The default is ``True``. If ``False``, the postprocessing is not computed, and ``None`` is returned if it does not exist yet. pp_location: the post-processing data location. It can be one of - :class:`PPSurfaceLocation`, otherwise a nvalidArgument error + :class:`PPSurfaceLocation`, otherwise an InvalidArgument error is raised. Default is PPSurfaceLocation.ON_CELLS. Returns: diff --git a/src/ansys/simai/core/data/selection_post_processings.py b/src/ansys/simai/core/data/selection_post_processings.py index c767466..2f95bd7 100644 --- a/src/ansys/simai/core/data/selection_post_processings.py +++ b/src/ansys/simai/core/data/selection_post_processings.py @@ -25,10 +25,10 @@ from ansys.simai.core.data.lists import ExportablePPList, PPList from ansys.simai.core.data.post_processings import ( GlobalCoefficients, + PPSurfaceLocation, Slice, SurfaceEvol, SurfaceVTP, - SurfaceVTPTDLocation, VolumeVTU, ) @@ -145,7 +145,9 @@ def volume_vtu(self) -> PPList[VolumeVTU]: """ return PPList(selection=self._selection, post=lambda pred: pred.post.volume_vtu()) - def surface_vtp(self) -> PPList[SurfaceVTP]: + def surface_vtp( + self, pp_location: PPSurfaceLocation = PPSurfaceLocation.ON_CELLS + ) -> 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 @@ -160,29 +162,16 @@ def surface_vtp(self) -> PPList[SurfaceVTP]: The computation is launched only on first call of this method. Subsequent calls do not relaunch it. - Returns: - :py:class:`~ansys.simai.core.data.lists.PPList` instance of - :py:class:`~ansys.simai.core.data.post_processings.SurfaceVTP` objects. - """ - return PPList(selection=self._selection, post=lambda pred: pred.post.surface_vtp()) - - def predict_as_learnt(self) -> PPList[SurfaceVTPTDLocation]: - """Compute or get the result of each prediction's surface in the VTP format. - - This is a non-blocking method. It returns a - :py:class:`~ansys.simai.core.data.lists.PPList` instance of - :py:class:`~ansys.simai.core.data.post_processings.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. + Args: + pp_location: the post-processing data location. It can be one of + :class:`~ansys.simai.core.data.post_processings.PPSurfaceLocation`, + otherwise an InvalidArgument error is raised. + Default is PPSurfaceLocation.ON_CELLS. Returns: :py:class:`~ansys.simai.core.data.lists.PPList` instance of :py:class:`~ansys.simai.core.data.post_processings.SurfaceVTP` objects. """ - return PPList(selection=self._selection, post=lambda pred: pred.post.predict_as_learnt()) + return PPList( + selection=self._selection, post=lambda pred: pred.post.surface_vtp(True, pp_location) + ) diff --git a/tests/test_selection_post_processings.py b/tests/test_selection_post_processings.py index 54c1bfe..231c63c 100644 --- a/tests/test_selection_post_processings.py +++ b/tests/test_selection_post_processings.py @@ -25,6 +25,8 @@ from ansys.simai.core.data.post_processings import ( GlobalCoefficients, + PostProcessingAsLearnt, + PPSurfaceLocation, Slice, SurfaceEvol, SurfaceVTP, @@ -181,6 +183,33 @@ def test_selection_post_processing_surface_vtp(test_selection): assert isinstance(pp, SurfaceVTP) +@responses.activate +def test_selection_post_processing_surface_vtp_predict_as_learnt(test_selection): + """WHEN I call post.post.surface_vtp() on a selection + THEN the /SurfaceVTPTDLocation endpoint is called for each prediction in the selection + AND I get a list of PostProcessingVTUExport objects in return + """ + assert len(test_selection.points) == 2 + + responses.add( + responses.POST, + "https://test.test/predictions/pred1/post-processings/SurfaceVTPTDLocation", + json={"id": "vtu01", "status": "queued"}, + status=200, + ) + responses.add( + responses.POST, + "https://test.test/predictions/pred2/post-processings/SurfaceVTPTDLocation", + json={"id": "vtu02", "status": "queued"}, + status=200, + ) + post_processings = test_selection.post.surface_vtp(pp_location=PPSurfaceLocation.AS_LEARNT) + assert isinstance(post_processings, PPList) + assert len(post_processings) == 2 + for pp in post_processings: + assert isinstance(pp, PostProcessingAsLearnt) + + @responses.activate def test_selection_post_processing_error(test_selection): """WHEN I call post.post.volume_vtu() on a selection