Skip to content
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

feat: exposing quantity types in PyDPF Core #1965

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d1a7e88
feat: exposing quantity types in PyDPF Core
a-bouth Dec 12, 2024
0c06eab
feat: Update after PR Review
a-bouth Dec 13, 2024
adf46c5
feat: Update after PR Review (2)
a-bouth Dec 13, 2024
ba084f2
feat: Update after PR Review (3)
a-bouth Dec 13, 2024
bb05ddb
feat: Update after PR Review (4)
a-bouth Dec 13, 2024
8d009e9
Merge branch 'master' into feat/exposing_quantity_types
a-bouth Dec 16, 2024
dd7ed4f
feat: Added Fields Container to `any` cast
a-bouth Dec 18, 2024
799227f
Merge branch 'feat/exposing_quantity_types' of https://github.com/ans…
a-bouth Dec 18, 2024
2a1477d
feat: exposing quantity_type in the GRPC API
a-bouth Dec 18, 2024
418cb8d
Merge branch 'master' into feat/exposing_quantity_types
a-bouth Dec 18, 2024
0b18c4b
feat: using right name for quantity_types
a-bouth Dec 19, 2024
984d9dd
Merge branch 'feat/exposing_quantity_types' of https://github.com/ans…
a-bouth Dec 19, 2024
329f94a
feat: fixing exposure of quantity types
a-bouth Dec 19, 2024
58b007c
feat: Added gRPC methods for Any cast for FieldsContainer
a-bouth Dec 19, 2024
4e147e3
Merge branch 'master' into feat/exposing_quantity_types
a-bouth Dec 20, 2024
11e6e48
Merge branch 'master' into feat/exposing_quantity_types
a-bouth Jan 6, 2025
a9153eb
Merge branch 'master' into feat/exposing_quantity_types
a-bouth Jan 20, 2025
85c0130
feat: removed an useless comment
a-bouth Jan 22, 2025
856293d
Merge branch 'master' into feat/exposing_quantity_types
a-bouth Jan 22, 2025
a6749ac
feat: fixed style check
a-bouth Jan 22, 2025
8dc0755
Merge branch 'feat/exposing_quantity_types' of https://github.com/ans…
a-bouth Jan 22, 2025
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
54 changes: 54 additions & 0 deletions src/ansys/dpf/core/field_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,60 @@ def dimensionality(self):
self._api.csfield_definition_fill_dimensionality(self, dim, nature, dim.internal_size)
return Dimensionality(dim.tolist(), natures(int(nature)))

@property
def quantity_type(self):
"""Getter for Quantity Types

Returns
-------
str
All quantity types of the elementary data for this FieldDefinition.
"""
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

def add_quantity_type(self, quantity_type_to_add):
"""Add a new Quantity Type

Parameters
----------
quantity_type_to_add: str
Quantity type to add
"""
self._api.csfield_definition_set_quantity_type(self, quantity_type_to_add)

def num_quantity_types(self):
"""Number of available quantity types

Returns
-------
num_quantity_types : int
Number of quantity types
"""
num_quantity_types = self._api.csfield_definition_get_num_available_quantity_types(self)
return num_quantity_types

def is_of_quantity_type(self, quantity_type):
"""Check if the field definition is of a given quantity type

Parameters
----------
quantity_type: str
Quantity type to check

Returns
-------
is_of_quantity_type : bool
True if the field definition is of the given quantity type
"""
is_of_quantity_type = self._api.csfield_definition_is_of_quantity_type(self, quantity_type)
return is_of_quantity_type

@unit.setter
def unit(self, value):
self._api.csfield_definition_set_unit(self, value, None, 0, 0, 0)
Expand Down
3 changes: 1 addition & 2 deletions src/ansys/dpf/gate/generated/field_definition_capi.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,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
28 changes: 28 additions & 0 deletions tests/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,34 @@ def test_create_and_update_field_definition(server_type):
assert fieldDef.location == locations.nodal


def test_field_definition_quantity_type(server_type):
fieldDef = FieldDefinition(server=server_type)

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

# Testing the getter
assert fieldDef.quantity_type[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

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

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

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


@conftest.raises_for_servers_version_under("4.0")
def test_create_and_set_get_name_field_definition(server_type):
fieldDef = FieldDefinition(server=server_type)
Expand Down
Loading