Skip to content

Test the FieldHeader getter operator #2348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/ansys/dpf/core/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from ansys import dpf
from ansys.dpf.core import dimensionality, errors, meshed_region, scoping, time_freq_support
from ansys.dpf.core.available_result import Homogeneity
from ansys.dpf.core.check_version import version_requires
from ansys.dpf.core.common import (
_get_size_of_list,
locations,
Expand All @@ -50,6 +51,7 @@
from ansys.dpf.gate.errors import DPFServerException

if TYPE_CHECKING: # pragma: nocover
from ansys.dpf.core.data_tree import DataTree
from ansys.dpf.core.dpf_operator import Operator
from ansys.dpf.core.meshed_region import MeshedRegion
from ansys.dpf.core.results import Result
Expand Down Expand Up @@ -804,6 +806,23 @@
def meshed_region(self, value: MeshedRegion):
self._set_support(support=value, support_type="MESHED_REGION")

@property
@version_requires("11.0")
def header(self) -> DataTree:
"""Field Header, which stores metadata of the Field.

Returns
-------
:class:`ansys.dpf.core.data_tree.DataTree`

"""
from ansys.dpf.core import dpf_operator

Check warning on line 819 in src/ansys/dpf/core/field.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/field.py#L819

Added line #L819 was not covered by tests

op = dpf_operator.Operator("field::get_attribute", server=self._server)
op.connect(0, self)
op.connect(1, "header")
return op.get_output(0, types.data_tree)

Check warning on line 824 in src/ansys/dpf/core/field.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/field.py#L821-L824

Added lines #L821 - L824 were not covered by tests

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

Expand Down
21 changes: 21 additions & 0 deletions tests/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ def stress_field(allkindofcomplexity, server_type):
return stress.outputs.fields_container()[0]


@pytest.fixture()
def strain_field(allkindofcomplexity, server_type):
model = dpf.core.Model(allkindofcomplexity, server=server_type)
strain = model.results.elastic_strain()
return strain.outputs.fields_container()[0]


def test_create_field(server_type):
field = dpf.core.Field(server=server_type)
assert field._internal_obj is not None
Expand Down Expand Up @@ -1444,3 +1451,17 @@ def test_set_units(server_type):
# use wrong type of arguments
with pytest.raises(ValueError):
field.unit = 1.0


def test_field_header(strain_field):
if server_meet_version("11.0", strain_field._server):
header = strain_field.header
assert header.has("version")
assert header.get_as("version", core.types.int) == 0
assert header.has("effnu")
assert header.get_as("effnu", core.types.double) == pytest.approx(0.33)
assert header.has("strain")
assert header.get_as("strain", core.types.int) == 1
else:
with pytest.raises(DpfVersionNotSupported):
header = strain_field.header
Loading