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: Add units and units_quantity in FieldInfo message #3568

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ packages = [

[tool.poetry.dependencies]
python = ">=3.10,<4.0"
ansys-api-fluent = "^0.3.28"
ansys-api-fluent = "^0.3.30"
ansys-platform-instancemanagement = "~=1.0"
ansys-tools-filetransfer = ">=0.1,<0.3"
ansys-units = "^0.3.3"
Expand Down
23 changes: 5 additions & 18 deletions src/ansys/fluent/core/post_objects/post_helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Provides a module for post objects."""

import re
from ansys.fluent.core.solver.flunits import get_si_unit_for_fluent_quantity


class IncompleteISOSurfaceDefinition(RuntimeError):
Expand Down Expand Up @@ -131,20 +131,7 @@ def get_vector_fields(self):

def get_field_unit(self, field):
"""Returns the unit of the field."""
quantity = self._field_unit_quantity(field)
if quantity == "*null*":
return ""
scheme_eval_str = f"(units/get-pretty-wb-units-from-dimension (units/inquire-dimension '{quantity}))"
return " ".join(self._scheme_str_to_py_list(scheme_eval_str))

def _field_unit_quantity(self, field):
scheme_eval_str = f"(cdr (assq 'units (%fill-render-info '{field})))"
return self._scheme_str_to_py_list(scheme_eval_str)[0]

def _scheme_str_to_py_list(self, scheme_eval_str):
session = self.obj.get_root().session
if hasattr(session, "scheme_eval"):
str_val = session.scheme_eval.string_eval(scheme_eval_str)
return list(filter(None, re.split(r'[\s()"\']', str_val)))
else:
return ["*null*"]
fields_info = self.field_info.get_fields_info()
for field_info in fields_info:
if field_info["solverName"] == field:
return get_si_unit_for_fluent_quantity(field_info["units_quantity"])
23 changes: 23 additions & 0 deletions src/ansys/fluent/core/services/field_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def __init__(
stub=FieldGrpcModule.FieldDataStub(intercept_channel), metadata=metadata
)

def get_fields_info(self, request):
"""GetFieldsInfo RPC of FieldData service."""
return self._stub.GetFieldsInfo(request, metadata=self._metadata)

def get_scalar_field_range(self, request):
"""GetRange RPC of FieldData service."""
return self._stub.GetRange(request, metadata=self._metadata)
Expand Down Expand Up @@ -88,6 +92,9 @@ class FieldInfo:

Methods
-------
get_fields_info(field: str) -> List[dict]
Get fields info.

get_scalar_field_range(field: str, node_value: bool, surface_ids: List[int])
-> List[float]
Get the range (minimum and maximum values) of the field.
Expand All @@ -111,6 +118,22 @@ def __init__(
self._service = service
self._is_data_valid = is_data_valid

def get_fields_info(self, field: str) -> List[dict]:
"""Get fields info.

Parameters
----------
field: str
Field name

Returns
-------
List[dict]
"""
request = FieldDataProtoModule.GetFieldsInfo()
response = self._service.get_fields_info(request)
return response["fieldInfo"]

def get_scalar_field_range(
self, field: str, node_value: bool = False, surface_ids: List[int] = None
) -> List[float]:
Expand Down
Loading