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: Polyhedral connectivity #3631

Merged
merged 1 commit into from
Jan 13, 2025
Merged
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 @@ -20,7 +20,7 @@ classifiers = [
"Operating System :: OS Independent",
]
dependencies = [
"ansys-api-fluent>=0.3.31",
"ansys-api-fluent>=0.3.32",
"ansys-platform-instancemanagement~=1.0",
"ansys-tools-filetransfer>=0.1,<0.3",
"ansys-units>=0.3.3,<0.5",
Expand Down
52 changes: 40 additions & 12 deletions src/ansys/fluent/core/services/field_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Wrappers over FieldData gRPC service of Fluent."""

from dataclasses import dataclass
from dataclasses import dataclass, field
from enum import Enum
from functools import reduce
import io
Expand Down Expand Up @@ -1003,6 +1003,19 @@ class CellElementType(Enum):
QUADRATIC_WEDGE = 12


@dataclass
class Facet:
"""Facet class within a mesh element.

Attributes:
-----------
node_indices : list[int]
0-based node indices of the facet.
"""

node_indices: list[int]


@dataclass
class Element:
"""Element class for mesh.
Expand All @@ -1012,12 +1025,15 @@ class Element:
element_type : CellElementType
Element type of the element.
node_indices : list[int]
0-based node indices of the element.
0-based node indices of the element. Populated for standard elements.
facets : list[Facet]
List of facets of the element. Populated for polyhedral elements.
"""

_id: int
element_type: CellElementType
node_indices: list[int]
node_indices: list[int] = field(default_factory=list)
facets: list[Facet] = field(default_factory=list)


@dataclass
Expand Down Expand Up @@ -1425,13 +1441,25 @@ def get_mesh(self, zone_id: int) -> Mesh:
domain_id=1, thread_id=zone_id
)
response = self._service.get_solver_mesh_elements(request)
elements = response.elements
elements = [
Element(
_id=element.id,
element_type=CellElementType(element.element_type),
node_indices=[(id - 1) for id in element.node_ids],
)
for element in elements
]
elements_pb = 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])
facets.append(facet)
element = Element(
_id=element_pb.id,
element_type=element_type,
facets=facets,
)
else:
element = Element(
_id=element_pb.id,
element_type=element_type,
node_indices=[(id - 1) for id in element_pb.node_ids],
)
elements.append(element)
return Mesh(nodes=nodes, elements=elements)
4 changes: 3 additions & 1 deletion tests/test_field_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,9 @@ def test_mesh_data(static_mixer_case_session):
assert len(mesh.nodes) == 82247
assert len(mesh.elements) == 22771
assert mesh.elements[0].element_type == CellElementType.POLYHEDRON
assert len(mesh.elements[0].node_indices) > 0
assert len(mesh.elements[0].node_indices) == 0
assert len(mesh.elements[0].facets) == 9
assert len(mesh.elements[0].facets[0].node_indices) == 4
assert min(mesh.nodes, key=lambda x: x.x).x == pytest_approx(-1.999075e-03)
assert max(mesh.nodes, key=lambda x: x.x).x == pytest_approx(1.999125e-03)
assert min(mesh.nodes, key=lambda x: x.y).y == pytest_approx(-3.000000e-03)
Expand Down
Loading