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.
- 98.9%hexahedra
- 5.97 s3 mm batch
- 0.83–1.0Jacobian
- 3 / 5 / 7mm sizes
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.
CAM_SHAFT.STEP / Assem1.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)
Screenshots from the three mapped volumes:
| 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. That is 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. 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.
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