Structures · ANSA Python API · 2024–25

Scripting hex meshes in ANSA

A camshaft comes in as STEP. The script maps the shells, fills hex, caps NASTRAN aspect at 2.3, and writes three CDB decks. One object. Three sizes. A log you can actually read.

Aerospace Structures (AS244AI) EL · with Akula Uday Kiran, Movva Sai Lalitha Devi, and Tejas L. Guide: Dr. Benjamin Rohit.

Clicking through ANSA for every CAD revision is how you lose an afternoon. This wraps the Python API so the same camshaft (two lobes + shaft) gets a mapped block mesh, a volume hex fill, and a .cdb at 3, 5, and 7 mm in one run.

The class is MeshProcessor. It pulls PSHELL 1/2 (lobe and shaft faces: 18 + 4) and PSOLID 3/4/5 (lob1, lob2, shaft1), maps the shells, remeshes the volumes with quality criterion 3 / target 2 / max aspect 2.3, logs every step, exports.

CAD model of the two-lobe camshaft
The part: two cam lobes on a shaft. Imported as STEP (CAM_SHAFT.STEP / Assem1.STEP).

Batch times from the log

One script, three sizes, NASTRAN deck, ANSYS CDB out. Logged 1 July 2025:

Size3.0 mm5.0 mm7.0 mm
Mesh + export5.97 s2.89 s2.48 s
CDB size18.85 MB4.89 MB1.90 MB

That is the point of the API: minutes of GUI work become a few seconds you can re-run when the STEP changes.

Element counts (Assem1 cam)

Screenshots from the three mapped volumes:

3 mm5 mm7 mm
Hexas62,30914,6124,920
Pentas1,762744432
Solid total64,07115,3565,352
Hex share97.3%95.2%91.9%
Shell quads / trias16,428 / 2286,016 / 1443,168 / 104

A later CAM_SHAFT deck used for the quality overlay sits at 29,020 hex / 29,352 solids = 98.9% hexahedra, 9,630 quads and 24 trias on the skin. That is the number the report quotes as “>98% hex.”

Quality envelopes

ANSA QGRAPH, NASTRAN aspect, FLUENT skew, ANSA Jacobian. From the report tables:

CheckSize 5 (shell / vol)Size 7Bar
Aspect ratio1.02–1.65 / 1.03–1.851.02–1.65ideal < 3
Jacobian0.825–1.00 / 0.977–1.000.825–1.00> 0.7
Skewness0.003–0.4770.003–0.477< 0.5
Warpage0.003–0.4300.003–0.430< 0.5

Size 3 solids Jacobian 0.835–1.00 (shells down to 0.717 near high curvature). No inverted elements. The conclusion in the report is the one on the homepage card: aspect under 2, Jacobian 0.83–1.0, skewness under 0.5, hex dominant.

How the script is built

Object-oriented on purpose so the same object can run three sizes. File I/O, entity collection, and meshing are split (FileManager, EntityManager, MeshManager) in the UML we drew for the report. The live script still talks to ansa.base / ansa.mesh / constants.NASTRAN.

UML of ANSAMeshingWorkflow and managers
Workflow: load STEP → shells → map blocks → solids → remesh volumes → export. Suggested split vs a single main().

Logging is file-based with timestamps so a failed size does not erase the successful ones. Export is ANSYS CDB so the deck can go straight into a structural run.

This is an EL report for Aerospace Structures, not a production mesher for every CAD family. The geometry is a camshaft. The win is: same Python object, three densities, quality that actually hits the NASTRAN/ANSA bars, and a log you can read when it does not.

← Projects