Skip to content

Commit 76693f1

Browse files
committed
Catch server error on support type unavailable on Field.meshed_region getter
1 parent 3ffa89c commit 76693f1

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/ansys/dpf/core/field.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
field_capi,
4747
field_grpcapi,
4848
)
49+
from ansys.dpf.gate.errors import DPFServerException
4950

5051
if TYPE_CHECKING:
5152
from ansys.dpf.core.dpf_operator import Operator
@@ -716,16 +717,21 @@ def field_definition(self):
716717
def field_definition(self, value):
717718
return self._set_field_definition(value)
718719

719-
def _get_meshed_region(self):
720+
def _get_meshed_region(self) -> MeshedRegion:
720721
"""Retrieve the meshed region.
721722
722723
Returns
723724
-------
724725
:class:`ansys.dpf.core.meshed_region.MeshedRegion`
725726
726727
"""
728+
try:
729+
support = self._api.csfield_get_support_as_meshed_region(self)
730+
except DPFServerException as e:
731+
if "the field doesn't have this support type" in e.msg:
732+
support = None
727733
return meshed_region.MeshedRegion(
728-
mesh=self._api.csfield_get_support_as_meshed_region(self),
734+
mesh=support,
729735
server=self._server,
730736
)
731737

@@ -761,7 +767,7 @@ def time_freq_support(self, value):
761767
self._api.csfield_set_support(self, value)
762768

763769
@property
764-
def meshed_region(self):
770+
def meshed_region(self) -> MeshedRegion:
765771
"""Meshed region of the field.
766772
767773
Return
@@ -772,8 +778,8 @@ def meshed_region(self):
772778
return self._get_meshed_region()
773779

774780
@meshed_region.setter
775-
def meshed_region(self, value):
776-
self._set_support(value, "MESHED_REGION")
781+
def meshed_region(self, value: MeshedRegion):
782+
self._set_support(support=value, support_type="MESHED_REGION")
777783

778784
def __add__(self, field_b):
779785
"""Add two fields.

0 commit comments

Comments
 (0)