Skip to content

Commit 5326a43

Browse files
authored
Add 'force_disable_result_extrapolation' property (#846)
Add the 'force_disable_result_extrapolation' property to the Model class. The property was added for the ACP server version 25.2. Other changes: - Clean up the 'test_unittest' test case. - Move 'check_property' into 'test_model.py' since it is only used there. Rename it to '_check_property' to indicate that it is a private function.
1 parent 3b9f4bb commit 5326a43

File tree

3 files changed

+43
-97
lines changed

3 files changed

+43
-97
lines changed

src/ansys/acp/core/_tree_objects/model.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ class Model(TreeObject):
246246
minimum_analysis_ply_thickness :
247247
Section computation minimum analysis ply thickness (in length
248248
unit of model).
249+
force_disable_result_extrapolation :
250+
Force the result extrapolation to be disabled ('ERESX,NO' command)
251+
when exporting to APDL or CDB format. Available since ACP server
252+
version 25.2.
249253
"""
250254

251255
__slots__: Iterable[str] = tuple()
@@ -263,6 +267,7 @@ def __init__(
263267
angle_tolerance: float = 1.0,
264268
relative_thickness_tolerance: float = 0.01,
265269
minimum_analysis_ply_thickness: float = 1e-6,
270+
force_disable_result_extrapolation: bool = False,
266271
) -> None:
267272
super().__init__(name=name)
268273

@@ -271,6 +276,7 @@ def __init__(
271276
self.angle_tolerance = angle_tolerance
272277
self.relative_thickness_tolerance = relative_thickness_tolerance
273278
self.minimum_analysis_ply_thickness = minimum_analysis_ply_thickness
279+
self.force_disable_result_extrapolation = force_disable_result_extrapolation
274280

275281
def _get_stub(self) -> model_pb2_grpc.ObjectServiceStub:
276282
return cast(model_pb2_grpc.ObjectServiceStub, super()._get_stub())
@@ -295,6 +301,11 @@ def _create_stub(self) -> model_pb2_grpc.ObjectServiceStub:
295301
minimum_analysis_ply_thickness: ReadWriteProperty[float, float] = grpc_data_property(
296302
"properties.minimum_analysis_ply_thickness"
297303
)
304+
force_disable_result_extrapolation: ReadWriteProperty[bool, bool] = grpc_data_property(
305+
"properties.force_disable_result_extrapolation",
306+
readable_since="25.2",
307+
writable_since="25.2",
308+
)
298309

299310
@staticmethod
300311
def _set_unit_system_data_attribute(pb_obj: ObjectInfo, name: str, value: _PROTOBUF_T) -> None:

tests/unittests/helpers.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

tests/unittests/test_model.py

Lines changed: 32 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import os
2626
import pathlib
2727
import tempfile
28+
from typing import Any, TypeVar
2829

2930
import numpy as np
3031
import numpy.testing
@@ -33,83 +34,56 @@
3334
from ansys.acp.core import ElementalDataType, UnitSystemType
3435
from ansys.acp.core.mesh_data import VectorData
3536

36-
from .helpers import check_property
37+
T = TypeVar("T")
3738

3839

39-
def test_unittest(acp_instance, model_data_dir):
40+
def _check_property(obj: Any, *, name: str, value: T, set_value: T | None = None):
41+
assert hasattr(obj, name), f"Object '{obj}' has no property named '{name}'"
42+
assert (
43+
getattr(obj, name) == value
44+
), f"Test of property '{name}' failed! value '{getattr( obj, name )}' instead of '{value}'."
45+
if set_value is not None:
46+
setattr(obj, name, set_value)
47+
assert (
48+
getattr(obj, name) == set_value
49+
), f"Setter of property '{name}' failed! value '{getattr(obj, name)}' instead of '{value}'."
50+
51+
52+
def test_unittest(acp_instance, model_data_dir, raises_before_version):
4053
"""
4154
Test basic properties of the model object
4255
"""
56+
4357
input_file_path = model_data_dir / "ACP-Pre.h5"
4458
model = acp_instance.import_model(name="kiteboard", path=input_file_path, format="ansys:h5")
4559

46-
# TODO: re-activate these tests when the respective features are implemented
47-
# assert model.unit_system.type == "mks"
48-
49-
check_property(model, name="name", value="kiteboard", set_value="kiteboard_renamed")
50-
# TODO: re-activate these tests when the respective features are implemented
51-
# check_property(model, name="save_path", value="")
52-
# check_property(model, name="format", value="ansys:h5")
53-
# check_property(model, name="cache_update_results", value=True, set_value=False),
54-
# check_property(model, name="path", value=input_file_path),
55-
check_property(model, name="use_nodal_thicknesses", value=False, set_value=True),
56-
check_property(model, name="draping_offset_correction", value=False, set_value=True),
57-
check_property(model, name="angle_tolerance", value=1.0, set_value=2.0),
58-
check_property(model, name="relative_thickness_tolerance", value=0.01, set_value=0.03)
59-
60-
# TODO: re-activate these tests when the respective features are implemented
61-
# The minimum analysis ply thickness is an absolute value, and depends on the
62-
# unit system being set. This is currently not implemented in PyACP, hence the
63-
# values are wrong (it's not using the expected unit system).
64-
# check_property(model, name="minimum_analysis_ply_thickness", value=1e-09, set_value=2e-09)
65-
# check_property(
66-
# model,
67-
# name="reference_surface_bounding_box",
68-
# value=(
69-
# (-0.6750000000000003, -0.2, 0.0005419999999999998),
70-
# (0.6750000000000003, 0.20000000000000007, 0.0005420000000000003),
71-
# ),
72-
# )
60+
_check_property(model, name="name", value="kiteboard", set_value="kiteboard_renamed")
61+
_check_property(model, name="use_nodal_thicknesses", value=False, set_value=True),
62+
_check_property(model, name="draping_offset_correction", value=False, set_value=True),
63+
_check_property(model, name="angle_tolerance", value=1.0, set_value=2.0),
64+
_check_property(model, name="relative_thickness_tolerance", value=0.01, set_value=0.03)
65+
with raises_before_version("25.2"):
66+
_check_property(
67+
model, name="force_disable_result_extrapolation", value=False, set_value=True
68+
)
7369

7470
with tempfile.TemporaryDirectory() as tmp_dir:
7571
working_dir = pathlib.Path(tmp_dir) / "workdir"
7672
os.makedirs(working_dir)
77-
# model.solver.working_dir = str(working_dir)
7873

7974
with tempfile.TemporaryDirectory() as local_working_dir:
8075
save_path = pathlib.Path(local_working_dir) / "test_model_serialization.acph5"
8176
model.save(save_path, save_cache=True)
8277
acp_instance.clear()
8378
model = acp_instance.import_model(path=save_path)
8479

85-
# TODO: re-activate these tests when the respective features are implemented
86-
# assert model.unit_system.type == "mks"
87-
88-
check_property(model, name="name", value="kiteboard_renamed")
89-
# TODO: re-activate these tests when the respective features are implemented
90-
# check_property(model, name="save_path", value=save_path)
91-
# check_property(model, name="format", value="ansys:h5")
92-
# check_property(model, name="cache_update_results", value=False)
93-
# check_property(model, name="path", value=input_file_path)
94-
check_property(model, name="use_nodal_thicknesses", value=True)
95-
check_property(model, name="draping_offset_correction", value=True)
96-
check_property(model, name="angle_tolerance", value=2.0)
97-
check_property(model, name="relative_thickness_tolerance", value=0.03)
98-
99-
# TODO: re-activate these tests when the respective features are implemented
100-
# check_property(model, name="minimum_analysis_ply_thickness", value=2e-09)
101-
# check_property(
102-
# model,
103-
# name="reference_surface_bounding_box",
104-
# value=(
105-
# (-0.6750000000000003, -0.2, 0.0005419999999999998),
106-
# (0.6750000000000003, 0.20000000000000007, 0.0005420000000000003),
107-
# ),
108-
# )
109-
110-
# rel_path_posix = pathlib.Path(relpath_if_possible(model.solver.working_dir)).as_posix()
111-
# # To ensure platform independency we store file paths using POSIX format
112-
# assert model.solver.working_dir == rel_path_posix
80+
_check_property(model, name="name", value="kiteboard_renamed")
81+
_check_property(model, name="use_nodal_thicknesses", value=True)
82+
_check_property(model, name="draping_offset_correction", value=True)
83+
_check_property(model, name="angle_tolerance", value=2.0)
84+
_check_property(model, name="relative_thickness_tolerance", value=0.03)
85+
with raises_before_version("25.2"):
86+
_check_property(model, name="force_disable_result_extrapolation", value=True)
11387

11488

11589
def test_export_analysis_model(acp_instance, model_data_dir):

0 commit comments

Comments
 (0)