Note
Go to the end to download the full example code.
Mesh a mixing elbow for a flow analysis#
Summary: This example demonstrates how to mesh a mixing elbow for a flow analysis.
Objective#
This example meshes a mixing elbow with polyhedral elements and wall boundary
layer refinement. It uses several meshing utilities available in the lucid
class for
convenience and ease.
Procedure#
Launch Ansys Prime Server and instantiate meshing utilities from the
lucid
class.Import the geometry and create face zones from labels imported from the geometry.
Surface mesh geometry with curvature sizing.
Volume mesh with polyhedral elements and boundary layer refinement.
Print statistics on the generated mesh.
Write a CAS file for use in the Fluent solver.
Exit the PyPrimeMesh session.
Launch Ansys Prime Server#
Import all necessary modules.
Launch an instance of Ansys Prime Server.
Connect the PyPrimeMesh client and get the model.
Instantiate meshing utilities from the lucid
class.
import os
import tempfile
from ansys.meshing import prime
from ansys.meshing.prime.graphics import PrimePlotter
prime_client = prime.launch_prime()
model = prime_client.model
mesh_util = prime.lucid.Mesh(model=model)
Using Ansys Prime Server from container ansys-prime-server-3
Import geometry#
Download the elbow geometry (FMD) file exported by SpaceClaim. Import the geometry. Create face zones from labels imported from the geometry for use in Fluent solver.
# For Windows OS users, scdoc is also available:
# mixing_elbow = prime.examples.download_elbow_scdoc()
mixing_elbow = prime.examples.download_elbow_fmd()
mesh_util.read(file_name=mixing_elbow)
mesh_util.create_zones_from_labels("inlet,outlet")
Surface mesh#
Surface mesh the geometry setting minimum and maximum sizing to use for curvature refinement.
mesh_util.surface_mesh(min_size=5, max_size=20)
Volume mesh#
Volume mesh with polyhedral elements and boundary layer refinement.
Fill the volume with polyhedral and prism mesh
specifying the location and number of layers for prisms.
Use expressions to define the surfaces to have prisms grown
where * !inlet !outlet
states all not inlet or outlet
.
mesh_util.volume_mesh(
volume_fill_type=prime.VolumeFillType.POLY,
prism_surface_expression="* !inlet !outlet",
prism_layers=3,
)
# Display the mesh
pl = PrimePlotter(allow_picking=True)
pl.plot(model)
pl.show()
Print mesh statistics#
# Get meshed part
part = model.get_part_by_name("flow_volume")
# Get statistics on the mesh
part_summary_res = part.get_summary(prime.PartSummaryParams(model=model))
# Get element quality on all parts in the model
search = prime.VolumeSearch(model=model)
params = prime.VolumeQualitySummaryParams(
model=model,
scope=prime.ScopeDefinition(model=model, part_expression="*"),
cell_quality_measures=[prime.CellQualityMeasure.SKEWNESS],
quality_limit=[0.95],
)
results = search.get_volume_quality_summary(params=params)
# Print statistics on meshed part
print(part_summary_res)
print("\nMaximum skewness: ", results.quality_results_part[0].max_quality)
message :
Part Name: flow_volume
Part ID: 2
13 Topo Edges
9 Topo Faces
1 Topo Volumes
0 Edge Zones
Edge Zone Name(s) : []
2 Face Zones
Face Zone Name(s) : [inlet, outlet]
1 Volume Zones
Volume Zone Name(s) : [volume]
2 Label(s)
Names: [inlet, outlet]
Bounding box (-203.2 -228.6 -50.8)
(203.169 203.2 50.8)
Mesh Summary:
38522 Nodes
3249 Poly Faces
0 Quad Faces
0 Tri Faces
3249 Faces
12090 Poly Cells
0 Hex Cells
0 Prism Cells
0 Pyramid Cells
0 Tet Cells
12090 Cells
0 out of 9 TopoFaces are unmeshed
n_topo_edges : 13
n_topo_faces : 9
n_topo_volumes : 1
n_edge_zonelets : 0
n_face_zonelets : 0
n_cell_zonelets : 0
n_edge_zones : 0
n_face_zones : 2
n_volume_zones : 1
n_labels : 2
n_nodes : 38522
n_faces : 3249
n_cells : 12090
n_tri_faces : 0
n_poly_faces : 3249
n_quad_faces : 0
n_second_order_tri_faces : 0
n_second_order_quad_faces : 0
n_tet_cells : 0
n_pyra_cells : 0
n_prism_cells : 0
n_poly_cells : 12090
n_hex_cells : 0
n_second_order_tet_cells : 0
n_second_order_pyra_cells : 0
n_second_order_prism_cells : 0
n_second_order_hex_cells : 0
n_unmeshed_topo_faces : 0
Maximum skewness: 0.680207
Write mesh#
Write a CAS file for use in the Fluent solver.
with tempfile.TemporaryDirectory() as temp_folder:
mesh_file = os.path.join(temp_folder, "mixing_elbow.cas")
mesh_util.write(mesh_file)
assert os.path.exists(mesh_file)
print("\nExported file:\n", mesh_file)
Exported file:
/tmp/tmpkpkzfxbk/mixing_elbow.cas
Exit PyPrimeMesh#
prime_client.exit()
Total running time of the script: (0 minutes 18.480 seconds)