← Portfolio GitHub ↗
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.

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 from STEP.

Batch times from the log

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

Size 3.0 mm 5.0 mm 7.0 mm
Mesh + export 5.97 s 2.89 s 2.48 s
CDB size 18.85 MB 4.89 MB 1.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)

3 mm 5 mm 7 mm
Hexas 62,309 14,612 4,920
Pentas 1,762 744 432
Solid total 64,071 15,356 5,352
Hex share 97.3% 95.2% 91.9%
Shell quads / trias 16,428 / 228 6,016 / 144 3,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 — the number the report quotes as ">98% hex."

Quality envelopes

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

Check Size 5 (shell / vol) Size 7 Bar
Aspect ratio 1.02–1.65 / 1.03–1.85 1.02–1.65 ideal < 3
Jacobian 0.825–1.00 / 0.977–1.00 0.825–1.00 > 0.7
Skewness 0.003–0.477 0.003–0.477 < 0.5
Warpage 0.003–0.430 0.003–0.430 < 0.5

Size 3 solids Jacobian 0.835–1.00 (shells down to 0.717 near high curvature). No inverted elements.

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 drawn for the report; the live script still talks to ansa.base / ansa.mesh / constants.NASTRAN directly, and needs a licensed ANSA install to run — there's no standalone environment.

UML of ANSAMeshingWorkflow and managers
Suggested FileManager/EntityManager/MeshManager split vs. the single main() the live script uses.

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 PSHELL/PSOLID IDs, the lobe+shaft split, and the quality thresholds are tuned to this one camshaft — a different part means re-identifying property IDs. The win is: same Python object, three densities, quality that actually hits the NASTRAN/ANSA bars, and a log you can read when it doesn't.

← Projects