generated from ansys/template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
284 additions
and
4 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
""" | ||
.. _ref_file_io: | ||
================================================================ | ||
Exporting mesh in different file formats | ||
================================================================ | ||
**Summary**: This example showcases the process of generating a mesh for block model | ||
and exporting the mesh for different file formats. | ||
Objective | ||
~~~~~~~~~~ | ||
The example demonstrates how to export mesh files for different mesh file formats | ||
like *.cdb, *.cas , *.pmdat etc. | ||
.. image:: ../../../images/generic_solid_block.png | ||
:align: center | ||
:width: 800 | ||
:alt: Generic F1 rear wing. | ||
Procedure | ||
~~~~~~~~~~ | ||
* Launch an Ansys Prime Server instance and instantiate the meshing utilities | ||
from the ``lucid`` class. | ||
* Import the CAD geometry file for the solid block. | ||
* Generate surface mesh with a constant mesh size of 2mm. | ||
* Generate volume mesh using tetrahedral elements and default settings . | ||
* Export the mesh file as pmdat, cdb and cas format. | ||
* Import the mesh file. | ||
* Exit the PyPrimeMesh session. | ||
""" | ||
|
||
############################################################################### | ||
# Launch Ansys Prime Server | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# Import all necessary modules and | ||
# 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 | ||
|
||
import ansys.meshing.prime as prime | ||
from ansys.meshing.prime.graphics import Graphics | ||
|
||
prime_client = prime.launch_prime() | ||
model = prime_client.model | ||
mesh_util = prime.lucid.Mesh(model=model) | ||
display = Graphics(model) | ||
|
||
############################################################################### | ||
# Import geometry | ||
# ~~~~~~~~~~~~~~~ | ||
# Download the block CAD file named `pyprime_block_import.fmd` and | ||
# Import the geometry into pyprimemesh. | ||
# Display part details | ||
|
||
mesh_util.read(file_name=prime.examples.download_block_model_scdoc()) | ||
print(model) | ||
|
||
############################################################################### | ||
# Generate Mesh | ||
# ~~~~~~~~~~~~~~~ | ||
# Using Lucid api, generate a tri surface mesh that | ||
# has a constant mesh size of 2mm . | ||
# Display the surface mesh generated on the block and face-zonelet | ||
# with named selection "my_group" . | ||
# Generate volume mesh with default meshing algorithms. | ||
|
||
mesh_util.surface_mesh(min_size=2.0) | ||
|
||
display() | ||
|
||
display(scope=prime.ScopeDefinition(model, label_expression="my_group")) | ||
|
||
mesh_util.volume_mesh() | ||
|
||
############################################################################### | ||
# Export mesh as PyPrimeMesh (*.pmdat) native format mesh file | ||
# ~~~~~~~~~~~~~~~ | ||
# PyPrimeMesh allows user to export mesh in its native format name pmdat. | ||
# This configuration allows retaining the topology data along with mesh data. | ||
# Similarly PyPrimeMesh allows export of mesh as *.cdb and *.cas. | ||
# While exporting the mesh to Ansys MAPDL, the labels are converted to components containing nodes. | ||
# Export of mesh to Ansys Fluent requires distinct non overlapping zones. For this the labels are | ||
# converted to face zones. The topology data present is removed automatically when exporting to | ||
# MAPDL and Fluent formats. | ||
|
||
# Export as PyPrimeMesh (*.pmdat) native format mesh file | ||
temp_folder = tempfile.TemporaryDirectory() | ||
mesh_file_pmdat = os.path.join(temp_folder.name, "pyprime_block_mesh.pmdat") | ||
mesh_util.write(mesh_file_pmdat) | ||
assert os.path.exists(mesh_file_pmdat) | ||
print("\nExported file:\n", mesh_file_pmdat) | ||
|
||
############################################################################### | ||
# Export mesh as Ansys MAPDL (*.cdb) format mesh file | ||
# ~~~~~~~~~~~~~~~ | ||
# PyPrimeMesh allows export of mesh as *.cdb and *.cas. | ||
# While exporting the mesh to Ansys MAPDL, the labels are converted to components containing nodes. | ||
|
||
# mesh_file_cdb = os.path.join(temp_folder.name, "pyprime_block_mesh.cdb") | ||
# mesh_util.write(mesh_file_cdb) | ||
# assert os.path.exists(mesh_file_cdb) | ||
# print("\nExported file:\n", mesh_file_cdb) | ||
|
||
############################################################################### | ||
# Export mesh Fluent (*.cas) format mesh file | ||
# ~~~~~~~~~~~~~~~ | ||
# Export of mesh to Ansys Fluent requires distinct non overlapping zones. For this the labels are | ||
# converted to face zones. The topology data present is removed automatically when exporting to | ||
# MAPDL and Fluent formats. | ||
|
||
mesh_util.create_zones_from_labels("my_group") | ||
print(model) | ||
|
||
# Export as Fluent (*.cas) format mesh file | ||
mesh_file_cas = os.path.join(temp_folder.name, "pyprime_block_mesh.cas") | ||
mesh_util.write(mesh_file_cas) | ||
assert os.path.exists(mesh_file_cas) | ||
print("\nExported file:\n", mesh_file_cas) | ||
|
||
############################################################################### | ||
# Reading cdb and cas mesh files | ||
# ~~~~~~~~~~~~~~~ | ||
# Read the exported MADP mesh format file, it would be observed that | ||
# the labels are exported as components of nodes. | ||
# Display the imported geometry. | ||
# Similarly after reading the Fluent format mesh file, its observed | ||
# the zone name is retained and the remaining face zonelets that are not | ||
# associated with a face zone(s) are merged to create a new zone named `wall` | ||
|
||
# mesh_util.read(mesh_file_cdb, append=False) | ||
# print(model) | ||
|
||
mesh_util.read(mesh_file_cas, append=False) | ||
print(model) | ||
|
||
############################################################################### | ||
# Reading native mesh file geometry | ||
# ~~~~~~~~~~~~~~~ | ||
# Read the exported PyPrimeMesh(pmdat) native mesh format file, it would be observed that | ||
# part contains both topology as well as mesh data. | ||
# The topology data consist of facet data this is called as geom_zonelets, | ||
# and the mesh generated exists as mesh zonelets. Here , while deleting the topology | ||
# we are deleting the geom zonelets and retaining the mesh data. | ||
|
||
mesh_util.read(mesh_file_pmdat, append=False) | ||
|
||
print(model) | ||
for part in model.parts: | ||
if len(part.get_topo_faces()) > 0: | ||
part.delete_topo_entities( | ||
prime.DeleteTopoEntitiesParams( | ||
model, delete_geom_zonelets=True, delete_mesh_zonelets=False | ||
) | ||
) | ||
print(model) | ||
|
||
############################################################################### | ||
# Exit PyPrimeMesh | ||
# ~~~~~~~~~~~~~~~~ | ||
|
||
prime_client.exit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters