Skip to content

Commit

Permalink
Update allowed values check for Commands. (#1633)
Browse files Browse the repository at this point in the history
* help

* help context

* DMMeta

* help context

* help context

* help context

* help context

* help context

* help context

* Multiphysics

* UI changes

* UI changes

* UI changes

* UI DM changes

* UI DM changes

* UI DM changes

* UI DM changes

* UI DM changes

* Update allowed values check for Commands.

* Update return type of get_scalar_fields_range

* Align structure of surface data with rest.

* Changes for UI e.g. reference access, attributes etc.

* Change format of get_vector_field_data()

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Minor correction.

* Update return types for field info.

---------

Co-authored-by: Aseem Jain <[email protected]>
Co-authored-by: Your Name <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Jun 6, 2023
1 parent 2850b74 commit 6dc3153
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 37 deletions.
18 changes: 14 additions & 4 deletions src/ansys/fluent/core/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,20 @@ def _execute(_self, *args, **kwargs):
if arg_value is not None:
for attr, attr_value in attr_data.items():
if attr == "allowed_values":
if arg_value not in attr_value(_self.obj):
raise RuntimeError(
f"{arg} value {arg_value} is not within allowed values."
)
allowed_values = attr_value(_self.obj)
if isinstance(arg_value, list):
if not all(
elem in allowed_values for elem in arg_value
):
raise RuntimeError(
f"All values of {arg} value {arg_value} is not within allowed values."
)
else:
if arg_value not in allowed_values:
raise RuntimeError(
f"{arg} value {arg_value} is not within allowed values."
)

elif attr == "range":
if type(arg_value) != int and type(arg_value) != float:
raise RuntimeError(
Expand Down
42 changes: 23 additions & 19 deletions src/ansys/fluent/core/services/field_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class FieldInfo:
Methods
-------
get_scalar_fields_range(field: str, node_value: bool, surface_ids: List[int])
get_scalar_fields_range(fields: List[str], node_value: bool, surface_ids: List[int])
-> List[float]
Get the range (minimum and maximum values) of the field.
Expand All @@ -93,34 +93,38 @@ def __init__(self, service: FieldDataService):
self._service = service

def get_scalar_fields_range(
self, field: str, node_value: bool = False, surface_ids: List[int] = None
) -> List[float]:
self, fields: List[str], node_value: bool = False, surface_ids: List[int] = None
) -> Dict[str, List[float]]:
"""Get the range (minimum and maximum values) of the field.
Parameters
----------
field: str
Name of the field
fields: List[str]
List containing field names
node_value: bool
surface_ids : List[int], optional
List of surface IDS for the surface data.
Returns
-------
List[float]
Union[List[float], Dict[str, List[float]]]
"""
if not surface_ids:
surface_ids = []
request = FieldDataProtoModule.GetRangeRequest()
request.fieldName = field
request.nodeValue = node_value
request.surfaceid.extend(
[FieldDataProtoModule.SurfaceId(id=int(id)) for id in surface_ids]
)
response = self._service.get_scalar_fields_range(request)
return [response.minimum, response.maximum]
range_data = {}
for field in fields:
if not surface_ids:
surface_ids = []
request = FieldDataProtoModule.GetRangeRequest()
request.fieldName = field
request.nodeValue = node_value
request.surfaceid.extend(
[FieldDataProtoModule.SurfaceId(id=int(id)) for id in surface_ids]
)
response = self._service.get_scalar_fields_range(request)
range_data[field] = [response.minimum, response.maximum]

return range_data

def get_scalar_fields_info(self) -> dict:
def get_scalar_fields_info(self) -> Dict[str, Dict]:
"""Get fields information (field name, domain, and section).
Returns
Expand All @@ -138,7 +142,7 @@ def get_scalar_fields_info(self) -> dict:
for field_info in response.fieldInfo
}

def get_vector_fields_info(self) -> dict:
def get_vector_fields_info(self) -> Dict[str, Dict]:
"""Get vector fields information (vector components).
Returns
Expand All @@ -156,7 +160,7 @@ def get_vector_fields_info(self) -> dict:
for vector_field_info in response.vectorFieldInfo
}

def get_surfaces_info(self) -> dict:
def get_surfaces_info(self) -> Dict[str, Dict]:
"""Get surfaces information (surface name, ID, and type).
Returns
Expand Down
25 changes: 11 additions & 14 deletions src/ansys/fluent/core/utils/dump_session_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,13 @@ def get_surface_data(self, surface_ids, data_types) -> list[Union[np.array, None
SurfaceDataType.FacesNormal: "face-normal",
}

surfaces_data = []
surfaces_data_int = []

for data_type in data_types:
for surface_id in surface_ids:
surfaces_data_int.append(
self._session_data["fields"][tag_id][surface_id][
enum_to_field_name[data_type]
]
)

surfaces_data.append(surfaces_data_int[:])
surfaces_data_int = []
surfaces_data = [
self._session_data["fields"][tag_id][surface_id][
enum_to_field_name[data_type]
]
for data_type in data_types
for surface_id in surface_ids
]

return surfaces_data

Expand All @@ -158,7 +152,10 @@ def get_vector_field_data(
tag_id = (("type", "vector-field"),)

vector_field_data = [
self._session_data["fields"][tag_id][surface_id][field_name]
(
self._session_data["fields"][tag_id][surface_id][field_name],
self._session_data["fields"][tag_id][surface_id]["vector-scale"],
)
for field_name in field_names
for surface_id in surface_ids
]
Expand Down

0 comments on commit 6dc3153

Please sign in to comment.