Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
17 changes: 17 additions & 0 deletions examples/04-Fluid-Examples/00-explore-fluid-simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@
# Check the available phases
print(simulation.phases)

###############################################################################
# Extract the mesh
# ----------------
###############################################################################
# Extract the full mesh
print(simulation.mesh)
simulation.mesh.plot()
###############################################################################
# Extract the mesh for a given zone
cell_zone_mesh = simulation.zone_mesh(zone_id=2)
print(cell_zone_mesh)
cell_zone_mesh.plot()

face_zone_mesh = simulation.zone_mesh(zone_id=9)
print(face_zone_mesh)
face_zone_mesh.plot()


###############################################################################
# Extract a result
Expand Down
10 changes: 10 additions & 0 deletions src/ansys/dpf/post/fluid_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ansys.dpf import core as dpf
from ansys.dpf.post import locations
from ansys.dpf.post.dataframe import DataFrame
from ansys.dpf.post.mesh import Mesh
from ansys.dpf.post.mesh_info import FluidMeshInfo
from ansys.dpf.post.phase import PhasesDict
from ansys.dpf.post.selection import Selection
Expand Down Expand Up @@ -177,6 +178,15 @@ def mesh_info(self) -> FluidMeshInfo:
self._mesh_info = FluidMeshInfo(self._model.metadata.mesh_info)
return self._mesh_info

def zone_mesh(self, zone_id: int) -> Mesh:
"""Return the mesh of the given zone."""
if zone_id not in self.cell_zones.keys():
if zone_id not in self.face_zones.keys():
raise ValueError(f"'{zone_id}' is not a valid zone ID.")
mesh_provider = self._model.metadata.mesh_provider
mesh_provider.inputs.region_scoping(zone_id)
return Mesh(mesh_provider.eval())

@property
def cell_zones(self) -> dict:
"""Return a dictionary of the cell zones in the simulation."""
Expand Down
12 changes: 12 additions & 0 deletions tests/test_fluid_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,15 @@ def test_plot_result_on_zones(self, fluent_simulation):
qualifiers={"zone": list(fluent_simulation.face_zones.keys())}
)
temperature.plot()

def test_fluid_simulation_zone_mesh(self, fluent_simulation):
# Cell zone mesh
cell_zone_mesh = fluent_simulation.zone_mesh(zone_id=13)
assert cell_zone_mesh.num_elements == 6080
assert cell_zone_mesh.num_nodes == 7293
assert cell_zone_mesh.num_faces == 19388
# Face zone mesh
face_zone_mesh = fluent_simulation.zone_mesh(zone_id=4)
assert face_zone_mesh.num_elements == 0
assert face_zone_mesh.num_nodes == 429
assert face_zone_mesh.num_faces == 380