Skip to content

Commit

Permalink
Merge branch 'feat/higher_level_exception_health_check' of https://gi…
Browse files Browse the repository at this point in the history
…thub.com/ansys/pyfluent into feat/higher_level_exception_health_check
  • Loading branch information
hpohekar committed Jan 17, 2025
2 parents e5062ca + 974f156 commit a7f376a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/ansys/fluent/core/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def get_default_config() -> dict:
'maxBytes': 10485760}},
'loggers': {'pyfluent.datamodel': {'handlers': ['pyfluent_file'],
'level': 'DEBUG'},
'pyfluent.field_data': {'handlers': ['pyfluent_file'],
'level': 'DEBUG'},
'pyfluent.general': {'handlers': ['pyfluent_file'],
'level': 'DEBUG'},
'pyfluent.launcher': {'handlers': ['pyfluent_file'],
Expand Down
3 changes: 3 additions & 0 deletions src/ansys/fluent/core/logging_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ loggers:
pyfluent.post_objects:
level: DEBUG
handlers: [pyfluent_file]
pyfluent.field_data:
level: DEBUG
handlers: [pyfluent_file]
39 changes: 26 additions & 13 deletions src/ansys/fluent/core/services/field_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from enum import Enum
from functools import reduce
import io
import logging
from typing import Callable, Dict, List, Tuple
import weakref

Expand All @@ -22,6 +23,8 @@
from ansys.fluent.core.services.streaming import StreamingService
from ansys.fluent.core.utils.deprecate import deprecate_argument, deprecate_arguments

logger = logging.getLogger("pyfluent.field_data")


def override_help_text(func, func_to_be_wrapped):
"""Override function help text."""
Expand Down Expand Up @@ -1074,10 +1077,9 @@ class Mesh:
Attributes:
-----------
nodes : list[Node]
List of nodes in the mesh. Sorted by Fluent's node ID.
List of nodes in the mesh.
elements : list[Element]
List of elements in the mesh. Unsorted as we want to correlate with the
solution data retrieved via svar service.
List of elements in the mesh.
"""

nodes: list[Node]
Expand Down Expand Up @@ -1480,25 +1482,34 @@ def get_mesh(self, zone: str | int) -> Mesh:
raise NotImplementedError("Face zone mesh is not supported.")

# Mesh data is retrieved from the root domain in Fluent
request = FieldDataProtoModule.GetSolverMeshNodesRequest(
logger.info(f"Getting nodes data for zone {zone_info._id}")
nodes_request = FieldDataProtoModule.GetSolverMeshNodesRequest(
domain_id=ROOT_DOMAIN_ID, thread_id=zone_info._id
)
response = self._service.get_solver_mesh_nodes(request)
nodes = response.nodes
nodes = [Node(_id=node.id, x=node.x, y=node.y, z=node.z) for node in nodes]
nodes = sorted(nodes, key=lambda x: x._id)
request = FieldDataProtoModule.GetSolverMeshElementsRequest(
nodes_response = self._service.get_solver_mesh_nodes(nodes_request)
logger.info("Nodes data received")
logger.info(f"Getting elements for zone {zone_info._id}")
elements_request = FieldDataProtoModule.GetSolverMeshElementsRequest(
domain_id=ROOT_DOMAIN_ID, thread_id=zone_info._id
)
response = self._service.get_solver_mesh_elements(request)
elements_pb = response.elements
elements_response = self._service.get_solver_mesh_elements(elements_request)
logger.info("Elements data received")
logger.info("Constructing nodes structure in PyFluent")
nodes = nodes_response.nodes
nodes = [Node(_id=node.id, x=node.x, y=node.y, z=node.z) for node in nodes]
node_index_by_id = {node._id: index for index, node in enumerate(nodes)}
logger.info("Nodes structure constructed")
logger.info("Constructing elements structure in PyFluent")
elements_pb = elements_response.elements
elements = []
for element_pb in elements_pb:
element_type = CellElementType(element_pb.element_type)
if element_type == CellElementType.POLYHEDRON:
facets = []
for facet_pb in element_pb.facets:
facet = Facet(node_indices=[(id - 1) for id in facet_pb.node])
facet = Facet(
node_indices=[node_index_by_id[id] for id in facet_pb.node]
)
facets.append(facet)
element = Element(
_id=element_pb.id,
Expand All @@ -1509,7 +1520,9 @@ def get_mesh(self, zone: str | int) -> Mesh:
element = Element(
_id=element_pb.id,
element_type=element_type,
node_indices=[(id - 1) for id in element_pb.node_ids],
node_indices=[node_index_by_id[id] for id in element_pb.node_ids],
)
elements.append(element)
logger.info("Elements structure constructed")
logger.info("Returning mesh")
return Mesh(nodes=nodes, elements=elements)

0 comments on commit a7f376a

Please sign in to comment.