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: Retrieve mesh data in solution mode #3618

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mkundu1
Copy link
Contributor

@mkundu1 mkundu1 commented Jan 6, 2025

import pyvista as pv
import numpy as np
import ansys.fluent.core as pyfluent
from ansys.fluent.core.services.field_data import CellElementType

def convert_fluent_element_type_to_pv_cell_type(element_type):
    if element_type == CellElementType.TETRAHEDRON:
        return pv.CellType.TETRA
    if element_type == CellElementType.HEXAHEDRON:
        return pv.CellType.HEXAHEDRON
    # Add other element types
    raise ValueError(f"Unknown element type {element_type}")

solver = pyfluent.launch_fluent(processor_count=4)
solver.settings.file.read_case(file_name="d:/work/elbow.cas.h5")
mesh = solver.fields.field_data.get_mesh(zone_id=2)
points = np.array([(node.x, node.y, node.z) for node in mesh.nodes])
cells = np.array([[len(element.node_indices)] + element.node_indices for element in mesh.elements]).ravel()
cell_types = [convert_fluent_element_type_to_pv_cell_type(element.element_type) for element in mesh.elements]
grid = pv.UnstructuredGrid(cells, cell_types, points)
pv.plot(grid, show_edges=True)

image

@mkundu1 mkundu1 force-pushed the feat/solver-mesh-data branch from e7a9d1d to 3907f75 Compare January 7, 2025 18:15
z: float


class CellElementType(Enum):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shall have FaceElementType when we support that in future.


_id: int
element_type: CellElementType
node_indices: list[int]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Connectivity for polyhedral cells is not yet properly supported. This class will be bit more complex when we support that in future.

)
for element in elements
]
elements = sorted(elements, key=lambda x: x._id)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: It would be more performant to do the 0-based indexing and sorting in the server-side. Maybe we can eliminate ids at the protobuf layer also.

@mkundu1 mkundu1 marked this pull request as ready for review January 7, 2025 18:21
@mkundu1 mkundu1 linked an issue Jan 7, 2025 that may be closed by this pull request
@mkundu1
Copy link
Contributor Author

mkundu1 commented Jan 7, 2025

I have noted down the future tasks for this feature: #3585 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fetch mesh data on-demand in solution mode
3 participants