|
22 | 22 |
|
23 | 23 | """FieldDefinition.""" |
24 | 24 |
|
| 25 | +from __future__ import annotations |
| 26 | + |
25 | 27 | from argparse import ArgumentError |
26 | 28 | import traceback |
27 | 29 | import warnings |
28 | 30 |
|
29 | 31 | from ansys.dpf.core import server as server_module |
30 | 32 | from ansys.dpf.core.available_result import Homogeneity |
31 | | -from ansys.dpf.core.check_version import version_requires |
| 33 | +from ansys.dpf.core.check_version import server_meet_version_and_raise, version_requires |
32 | 34 | from ansys.dpf.core.common import natures, shell_layers |
33 | 35 | from ansys.dpf.core.dimensionality import Dimensionality |
34 | 36 | from ansys.dpf.gate import ( |
@@ -206,14 +208,37 @@ def is_of_quantity_type(self, quantity_type): |
206 | 208 | return is_of_quantity_type |
207 | 209 |
|
208 | 210 | @unit.setter |
209 | | - def unit(self, value): |
| 211 | + def unit(self, value: str | tuple[Homogeneity, str]): |
| 212 | + """Change the unit for the field definition. |
| 213 | +
|
| 214 | + A single string is interpreted as a known physical unit with an associated homogeneity. |
| 215 | +
|
| 216 | + For DPF 11.0 (2026 R1) and above: A tuple of two strings is interpreted as a homogeneity and a unit name. |
| 217 | + If the homogeneity is :py:attr:`Homogeneity.dimensionless`, then the unit string is kept as a name. |
| 218 | + Otherwise, the homogeneity is ignored, and the unit string interpreted as a known physical unit with an associated homogeneity. |
| 219 | +
|
| 220 | + Parameters |
| 221 | + ---------- |
| 222 | + value: |
| 223 | + Units for the field. |
| 224 | +
|
| 225 | + Notes |
| 226 | + ----- |
| 227 | + Setting a named dimensionless unit requires DPF 11.0 (2026 R1) or above. |
| 228 | +
|
| 229 | + """ |
210 | 230 | # setter with explicit homogeneity: homogeneity is taken into account if it is dimensionless |
211 | 231 | if ( |
212 | 232 | isinstance(value, tuple) |
213 | 233 | and len(value) == 2 |
214 | 234 | and isinstance(value[0], Homogeneity) |
215 | 235 | and isinstance(value[1], str) |
216 | 236 | ): |
| 237 | + server_meet_version_and_raise( |
| 238 | + required_version="11.0", |
| 239 | + server=self._server, |
| 240 | + msg="Setting a named dimensionless unit requires DPF 11.0 (2026 R1) or above.", |
| 241 | + ) |
217 | 242 | # csfield_definition_set_unit will ignore the homogeneity if it is not dimensionless |
218 | 243 | self._api.csfield_definition_set_unit(self, value[1], None, value[0].value, 0, 0) |
219 | 244 | # standard unit setter, using string interpreter |
|
0 commit comments