Skip to content

Commit

Permalink
feat: Update after PR Review
Browse files Browse the repository at this point in the history
  • Loading branch information
a-bouth committed Dec 13, 2024
1 parent d1a7e88 commit 0c06eab
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 69 deletions.
39 changes: 19 additions & 20 deletions src/ansys/dpf/core/field_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,36 +153,35 @@ def dimensionality(self):
self._api.csfield_definition_fill_dimensionality(self, dim, nature, dim.internal_size)
return Dimensionality(dim.tolist(), natures(int(nature)))

def get_quantity_type(self, index=0):
"""Getter for Quantity Type
Parameters
----------
index: Index of the quantity type to return
@property
def quantity_type(self):
"""Getter for Quantity Types
Returns
-------
quantity_type : Quantity Type
Quantity type of the elementary data at a given index.
str
All quantity types of the elementary data for this FieldDefinition.
"""
if index < 0:
raise ValueError("Index must be greater than or equal to 0")
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))

quantity_type = self._api.csfield_definition_get_quantity_type(self, index)
return str(quantity_type)
return quantity_types

def set_quantity_type(self, quantity_type):
"""Setter for Quantity Type
def add_quantity_type(self, quantity_type_to_add):
"""Add a new Quantity Type
Parameters
----------
quantity_type: Quantity Type
Quantity type to set
quantity_type_to_add: str
Quantity type to add
"""
self._api.csfield_definition_set_quantity_type(self, quantity_type)
self._api.csfield_definition_set_quantity_type(self, quantity_type_to_add)

def get_num_available_quantity_types(self):
"""Getter for the number of available quantity types
def num_quantity_types(self):
"""Number of available quantity types
Returns
-------
Expand All @@ -197,7 +196,7 @@ def is_of_quantity_type(self, quantity_type):
Parameters
----------
quantity_type: Quantity Type
quantity_type: str
Quantity type to check
Returns
Expand Down
41 changes: 1 addition & 40 deletions src/ansys/dpf/gate/generated/field_definition_capi.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,35 +184,6 @@ def csfield_definition_get_shell_layers(res):
if errorSize.value != 0:
raise errors.DPFServerException(sError.value)
return res

@staticmethod
def csfield_definition_get_quantity_type(res, index):
errorSize = ctypes.c_int(0)
sError = ctypes.c_wchar_p()
res = capi.dll.CSFieldDefinition_GetQuantityType(res._internal_obj if res is not None else None, index, ctypes.byref(utils.to_int32(errorSize)), ctypes.byref(sError))
if errorSize.value != 0:
raise errors.DPFServerException(sError.value)
newres = ctypes.cast(res, ctypes.c_char_p).value.decode("utf-8") if res else None
capi.dll.DataProcessing_String_post_event(res, ctypes.byref(errorSize), ctypes.byref(sError))
return newres

@staticmethod
def csfield_definition_get_num_available_quantity_types(fieldDef):
errorSize = ctypes.c_int(0)
sError = ctypes.c_wchar_p()
res = capi.dll.CSFieldDefinition_GetNumAvailableQuantityTypes(fieldDef._internal_obj if fieldDef is not None else None, ctypes.byref(utils.to_int32(errorSize)), ctypes.byref(sError))
if errorSize.value != 0:
raise errors.DPFServerException(sError.value)
return res

@staticmethod
def csfield_definition_is_of_quantity_type(fieldDef, quantityType):
errorSize = ctypes.c_int(0)
sError = ctypes.c_wchar_p()
res = capi.dll.CSFieldDefinition_GetNumAvailableQuantityTypes(fieldDef._internal_obj if fieldDef is not None else None, utils.to_char_ptr(quantityType), ctypes.byref(utils.to_int32(errorSize)), ctypes.byref(sError))
if errorSize.value != 0:
raise errors.DPFServerException(sError.value)
return res

@staticmethod
def csfield_definition_get_location(res):
Expand Down Expand Up @@ -270,15 +241,6 @@ def csfield_definition_set_shell_layers(fieldDef, shellLayers):
raise errors.DPFServerException(sError.value)
return res

@staticmethod
def csfield_definition_set_quantity_type(fieldDef, quantityType):
errorSize = ctypes.c_int(0)
sError = ctypes.c_wchar_p()
res = capi.dll.CSFieldDefinition_SetQuantityType(fieldDef._internal_obj if fieldDef is not None else None, utils.to_char_ptr(quantityType), ctypes.byref(utils.to_int32(errorSize)), ctypes.byref(sError))
if errorSize.value != 0:
raise errors.DPFServerException(sError.value)
return res

@staticmethod
def csfield_definition_set_location(fieldDef, location):
errorSize = ctypes.c_int(0)
Expand Down Expand Up @@ -389,5 +351,4 @@ def dimensionality_get_num_comp_for_object(api_to_use, nature, size, vsize):
res = capi.dll.Dimensionality_GetNumComp_for_object(api_to_use._internal_obj if api_to_use is not None else None, utils.to_int32(nature), utils.to_int32_ptr(size), utils.to_int32(vsize), ctypes.byref(utils.to_int32(errorSize)), ctypes.byref(sError))
if errorSize.value != 0:
raise errors.DPFServerException(sError.value)
return res

return res
15 changes: 6 additions & 9 deletions tests/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,27 +522,24 @@ def test_field_definition_quantity_type(server_type):

# Testing the setter
qt = "my_quantity_type"
fieldDef.set_quantity_type(qt)
fieldDef.add_quantity_type(qt)

# Testing the getter
assert fieldDef.get_quantity_type(0) == qt
assert fieldDef.quantity_type[0] == qt

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

# Testing the getter again
assert fieldDef.get_quantity_type(1) == qt2
assert fieldDef.quantity_type[1] == qt2

# Testing the getter with an index out of range
assert fieldDef.get_quantity_type(2) == None

# Testing the getter with a negative index
with pytest.raises(Exception):
fieldDef.get_quantity_type(-1)
fieldDef.quantity_type[2]

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

# Checking if the field definition is of a given quantity type
assert fieldDef.is_of_quantity_type(qt)
Expand Down

0 comments on commit 0c06eab

Please sign in to comment.