Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
24 changes: 24 additions & 0 deletions src/ansys/dpf/core/property_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ansys.dpf.core.common import natures, locations, _get_size_of_list
from ansys.dpf.core import scoping, dimensionality
from ansys.dpf.core.field_base import _FieldBase, _LocalFieldBase
from ansys.dpf.core.field_definition import FieldDefinition
from ansys.dpf.gate import (
property_field_abstract_api,
property_field_capi,
Expand Down Expand Up @@ -69,6 +70,7 @@ def __init__(
field=property_field,
server=server,
)
self._field_definition = self._load_field_definition()

@property
def _api(self) -> property_field_abstract_api.PropertyFieldAbstractAPI:
Expand Down Expand Up @@ -101,6 +103,12 @@ def _field_create_internal_obj(
else:
return api.csproperty_field_new(nentities, nentities * dim.component_count)

def _load_field_definition(self):
"""Attempt to load the field definition for this field."""
# try:
out = self._api.csproperty_field_get_shared_field_definition(self)
return FieldDefinition(out, self._server)

@property
def location(self):
"""Location of the property field.
Expand Down Expand Up @@ -299,6 +307,22 @@ def as_local_field(self):
"""
return _LocalPropertyField(self)

@property
def name(self):
"""Name of the property field."""
return self._field_definition.name

@name.setter
def name(self, value):
"""Change the name of the property field

Parameters
----------
value : str
Name of the property field.
"""
self._field_definition._api.csfield_definition_set_name(self._field_definition, name=value)


class _LocalPropertyField(_LocalFieldBase, PropertyField):
"""Caches the internal data of a field so that it can be modified locally.
Expand Down
6 changes: 6 additions & 0 deletions tests/test_propertyfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def test_set_get_data_property_field(server_type):
assert np.allclose(field.data, data)


def test_set_get_name_property_field(server_type):
field = dpf.core.PropertyField(server=server_type)
field.name = "test"
assert field.name == "test"


def test_create_property_field_push_back(server_type):
f_vec = core.PropertyField(1, core.natures.vector, core.locations.nodal, server=server_type)
f_vec.append([1, 2, 4], 1)
Expand Down