Skip to content

Commit

Permalink
feat: fixing exposure of quantity types
Browse files Browse the repository at this point in the history
  • Loading branch information
a-bouth committed Dec 19, 2024
1 parent 984d9dd commit 329f94a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/ansys/dpf/core/field_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def dimensionality(self):

# @version_requires("4.0") #TODO
@property
def quantity_type(self):
def quantity_types(self):
"""Getter for Quantity Types
Returns
Expand All @@ -166,7 +166,6 @@ def quantity_type(self):
quantity_types = []
for i in range(self.num_quantity_types()):
qt = self._api.csfield_definition_get_quantity_type(self, i)
print(qt)
quantity_types.append(str(qt))

return quantity_types
Expand Down
8 changes: 4 additions & 4 deletions src/ansys/dpf/gate/field_definition_grpcapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ def csfield_definition_fill_unit(fieldDef, symbol, size, homogeneity, factor, sh

@staticmethod
def csfield_definition_get_quantity_type(fieldDef, index):
return _get_stub(fieldDef._server).List(fieldDef._internal_obj).quantity_type[index]
return _get_stub(fieldDef._server).List(fieldDef._internal_obj).quantity_types.quantity_types[index]

@staticmethod
def csfield_definition_set_quantity_type(fieldDef, quantityType):
FieldDefinitionGRPCAPI._modify_field_def(fieldDef, quantity_type=quantityType)

@staticmethod
def csfield_definition_get_num_available_quantity_types(fieldDef):
return len(_get_stub(fieldDef._server).List(fieldDef._internal_obj).quantity_type)
return len(_get_stub(fieldDef._server).List(fieldDef._internal_obj).quantity_types.quantity_types)

@staticmethod
def csfield_definition_is_of_quantity_type(fieldDef, quantityType):
return quantityType in _get_stub(fieldDef._server).List(fieldDef._internal_obj).quantity_type
return quantityType in _get_stub(fieldDef._server).List(fieldDef._internal_obj).quantity_types.quantity_types

@staticmethod
def csfield_definition_get_shell_layers(fieldDef):
Expand Down Expand Up @@ -107,6 +107,6 @@ def _modify_field_def(
if name != None:
request.name.string = name
if quantity_type != None:
request.quantity_types.quantity_types = quantity_type
request.quantity_types.quantity_types.append(quantity_type)

_get_stub(fieldDef._server).Update(request)
6 changes: 3 additions & 3 deletions tests/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,18 +526,18 @@ def test_field_definition_quantity_type(server_type):
fieldDef.add_quantity_type(qt)

# Testing the getter
assert fieldDef.quantity_type[0] == qt
assert fieldDef.quantity_types[0] == qt

# Adding a second quantity type
qt2 = "another_quantity_type"
fieldDef.add_quantity_type(qt2)

# Testing the getter again
assert fieldDef.quantity_type[1] == qt2
assert fieldDef.quantity_types[1] == qt2

# Testing the getter with an index out of range
with pytest.raises(Exception):
fieldDef.quantity_type[2]
fieldDef.quantity_types[2]

# Getting the number of available quantity types
assert fieldDef.num_quantity_types() == 2
Expand Down

0 comments on commit 329f94a

Please sign in to comment.