The model already contains a consistent geometry, element, and material. Now we must decide how much discretization you need. We will not choose a mesh for its appearance: we will build a comparable family, we will audit it and let a Physical magnitude determines when refining stops substantially changing the response.
Your mission
You will generate three structured hexahedral meshes, you will check their topology and quality, you will measure the tip displacement with the same test case and select the first mesh whose variation compared to the next is less than 2%.
Central rule: an attractive mesh does not demonstrate convergence; a small difference is also meaningless if the cases represent different problems.
Objectives
By completing M04 you will be able to demonstrate that:
- You distinguish refinement, quality and convergence.
- You build a hexahedral mesh using parametric divisions.
- You explain the difference between a global control and one applied to specific lines.
- You audit topology, attributes, and shape warnings before solving.
- You keep geometry, material, load and measurement point constant.
- You calculate the change relative to the next finer mesh.
- You select a mesh by a stated criterion or conclude that the study is insufficient.
Prerequisites and downloads
- Have completed M03 and recognize
SOLID185,TYPEandMAT. - Remember from M02 that a selection is a temporary state and must be recovered with
ALLSEL,ALL. - Having run the first simulation of M00. Your solution block is reused as an instrument, not new content.
04_start.mac— starting point.04_mesh_convergence.mac— complete study.04_bug_hunt.mac— five deliberate contaminations.04_challenge.mac— challenge with non-divisible sizes.04_expected_results.csv— acceptance contract.
How to use this lesson
| Track | Duration | Scope |
|---|---|---|
| Quick win | 35–40 min | Prediction, first mesh, and mesh audit record. |
| Complete | 70–75 min | Also, 40/320/2560 family, convergence and challenge with mesh_h limit. |
Recommendation: a beautiful mesh does not demonstrate convergence. You need a comparable family and a monitored magnitude with explicit tolerance.
Session map
- Mission: targets, downloads and refinement prediction.
- Mental model: quality, convergence, and a defensible decision.
- Demo: meshing, quality, family and convergence.
- Bug hunting: incomparable meshes and invented convergence.
- Challenge: mesh_h which does not cleanly split the part.
- Mastery: final test that records demonstrated mastery and recommends M05.
Prediction — How much does it cost to divide h by two?
If we refined a line, we would double its number of elements. But our beam occupies three
dimensions. By dividing the size by two we double simultaneously
div_x, div_y and div_z:
2 × 2 × 2 = 8The calculation time does not have to grow exactly with that proportion: it also intervenes the degrees of freedom, connectivity, memory and the solver. But the geometric growth explains why “refining just in case” is an expensive strategy.
Mental model — Three different questions
| Concept | Question | Evidence |
|---|---|---|
| Refinement | Have we increased the resolution? | Divisions, nodes and elements. |
| Quality | Are the elements geometrically acceptable? | SHPP,SUMMARY and CHECK. |
| Convergence | Is a relevant physical quantity stabilized? | Variation of displacement between meshes. |
None of the three tests replace the others
A million distorted elements do not make a good mesh. A perfect mesh but too thick can give a stiff response. Two equal results do not prove either nothing if the length or load were changed simultaneously.
Anatomy of a comparable family
A convergence study changes only one decision: discretization. In all three cases we will keep exactly:
- geometry
1.0 × 0.10 × 0.05 m; SOLID185with the same formulation;- steel with
EX=210E9 PaandPRXY=0.30; - fixed support, the total force of
-1000 Nand its direction; - the coordinate of the node used to measure the displacement.
We will also preserve the element family and meshing strategy. Compare tetrahedra thick linear lines with thin hexahedrons would mix two changes and make it difficult to interpret the cause.
Step 1 — From nominal size to divisions
For the base family, the dimensions are exact multiples of the three sizes:
div_x=beam_l/mesh_h
div_y=beam_h/mesh_h
div_z=beam_b/mesh_h
We don't call nx, ny and nz to these parameters:
MAPDL reserves those names for intrinsic nodal coordinate functions.
mesh_h | nx × ny × nz | Elements | Nodes |
|---|---|---|---|
| 0.0500m | 20 × 2 × 1 | 40 | 126 |
| 0.0250m | 40 × 4 × 2 | 320 | 615 |
| 0.0125m | 80 × 8 × 4 | 2560 | 3645 |
For a structured block, the theoretical counts are:
n_elements = div_x*div_y*div_z
n_nodes = (div_x+1)*(div_y+1)*(div_z+1)These equations provide a strong check: if they do not match, the resulting mesh does not have the structure that the script claimed to build.
L×H; convergence is decided with CSV, not visual smoothness.
Step 2 — ESIZE vs LESIZE
ESIZE,mesh_size(i)
ESIZE declares the default global size. MAPDL calculates divisions from
of that value, rounding them when necessary. However, a global control does not express
alone how we want to distribute elements in each direction.
LSEL,S,LENGTH,,beam_l
LESIZE,ALL,,,div_x(i),,1
LSEL,S,LENGTH,,beam_h
LESIZE,ALL,,,div_y(i),,1
LSEL,S,LENGTH,,beam_b
LESIZE,ALL,,,div_z(i),,1
ALLSEL,ALL
LSEL groups lines by geometric meaning, not by ID.
LESIZE,ALL applies integer divisions to selected lines. The argument
KFORC=1 forces you to replace any previous division, something necessary after
to clean one mesh and prepare the next.
Step 3 — Require mapped hexahedrons
MSHAPE,0,3D
MSHKEY,1
VMESH,ALL
MSHAPE,0,3D requests hexahedrons and MSHKEY,1 requires mapped meshing.
We do not use MSHKEY,2, because allowing a free mesh as an alternative could
hide a flaw in our preparation. The rectangular block is mappable and the edges
opposites receive the same number of divisions.
A free mesh is not "bad." Here we use a regular structure to isolate the effect of the size. In an industrial geometry, the strategy must adapt to the form.
Step 4 — Create the mesh audit record
Before solving, each mesh must demonstrate four properties:
*GET,n_nodes(i),NODE,0,COUNT
*GET,n_elems(i),ELEM,0,COUNT
ESEL,S,TYPE,,1
*GET,n_type1(i),ELEM,0,COUNT
ALLSEL,ALL
ESEL,S,MAT,,1
*GET,n_mat1(i),ELEM,0,COUNT
ALLSEL,ALLThe test passes only when:
n_elems = div_x*div_y*div_z
n_nodes = (div_x+1)*(div_y+1)*(div_z+1)
n_type1 = n_elems
n_mat1 = n_elemsThis is how we connect M04 with M03: a finer mesh that loses its attributes is not an improvement of the same model, but another model.
Step 5 — Turn quality into a test
SHPP,DEFAULT
SHPP,ON
...
SHPP,SUMMARY
CHECK,ESEL,WARN
*GET,n_shape_bad(i),ELEM,0,COUNT
ALLSEL,ALL
SHPP,SUMMARY lists the shape-test summary for the selected elements.
Then CHECK,ESEL,WARN does something especially useful: it deselects elements
with no issues and retains only those that produce warnings or errors. Therefore,
n_shape_bad=0 is a condition that can be checked automatically.
CHECK modifies the selection
If you do not execute ALLSEL,ALL afterward, the test case could operate only
on the problematic elements or on an empty set.
Step 6 — The inherited test case
To measure convergence we need a physical response. The next block reuses the vertical route that you already executed in M00:
NSEL,S,LOC,X,0
D,ALL,ALL,0
ALLSEL,ALL
NSEL,S,LOC,X,beam_l
*GET,n_tip,NODE,0,COUNT
force_per_node=tip_force/n_tip
F,ALL,FY,force_per_node
ALLSEL,ALL
FINISH
/SOLU
ANTYPE,STATIC,NEW
SOLVE
FINISH
/POST1
SET,LAST
*GET,uy_tip(i),NODE,probe_node,U,YIn M04 this block works like a laboratory instrument: all its inputs remain constants and only returns one reading. M05 will explain and audit the boundary conditions; M06, the solution and balance; M07, the extraction and validation of results.
The measurement node is selected by X=beam_l, Y=0 and Z=0.
That coordinate exists in all meshes. Writing an ID would mix refinement with a change
accidental of the observed point.
Step 7 — Clean without destroying the geometry
/PREP7
ALLSEL,ALL
DDELE,ALL,ALL
FDELE,ALL,ALL
CMDELE,fixed_nodes
CMDELE,tip_nodes
VCLEAR,ALL
VCLEAR,ALL removes the elements and nodes associated with the volume, but retains
the solid model and its attributes. Change ESIZE without cleaning and remeshing no
refines an existing mesh: only changes a preference for future operations.
Step 8 — Automate the family
*DIM,mesh_size,ARRAY,3
mesh_size(1)=0.0500
mesh_size(2)=0.0250
mesh_size(3)=0.0125
*DO,i,1,3
! divisions, meshing, audit, measurement, and cleanup
*ENDDOThe loop does not create three separate handwritten studies. It ensures that all cases follow exactly the same sequence and reduces the chances of changing a condition inadvertently.
Step 9 — Measure convergence
change_pct(1)=ABS(uy_tip(2)-uy_tip(1))/ABS(uy_tip(2))*100
change_pct(2)=ABS(uy_tip(3)-uy_tip(2))/ABS(uy_tip(3))*100
change_pct(3)=-1
Each mesh is compared to the next finest, used as an improved estimate. The last
it cannot be compared with itself; the value -1 means "without comparison",
not perfect convergence.
Step 10 — Make a defensible decision
The algorithm runs through the comparisons from the most economical mesh:
selected_case=0
! If change 1→2 < 2% and both meshes pass:
! selected_case=1
! Otherwise, test change 2→3.
! If that also fails:
! selected_case=0We never automatically choose mesh 3 because it is the finest available. If the last comparison exceeds the threshold, the study is inconclusive and needs another mesh.
Why don't we use maximum stress?
Ideal fixed support introduces an abrupt transition between fully constrained nodes and free material. A point stress next to that boundary can grow or move during refinement, even when the global displacement is already stable. Choosing it as the only criterion would confuse convergence of a global magnitude with potentially singular local behavior.
In M07 we will compare stresses in justifiable regions and separate nominal stress, physical concentration and numerical singularity.
The CSV as a record of the study
04_mesh_convergence.mac generates m04_mesh_study.csv:
case,mesh_h,nx,ny,nz,n_nodes,n_elements,n_type1,n_mat1,uy_tip,change_to_next_pct,mesh_pass,selected
It must contain three rows. Only one may have selected=1; it is also valid for
all are zero if no comparison satisfies. The CSV records intent, cost, audit,
response and decision in the same reproducible evidence.
Validated reference result
In MAPDL Student 2025 R2, variations of approximately
1.168 % and 0.501 %. With a threshold of 2%, the algorithm selects
case 1. The result is deliberately interesting: “first acceptable mesh” is not
means "finest mesh available."
Bug hunting
Run 04_bug_hunt.mac and write for each defect: symptom, cause, evidence
and correction. Look for five contaminations:
- The length declared for the second case no longer matches that of the first.
- It changes
ESIZEunexecutedVCLEARand mesh again. - Applies
-1000 Nto each tip node instead of conserving total force. - The measuring point is identified by a fixed ID.
- The mesh with the most elements is chosen without calculating any physical variation.
Verifiable challenge — When mesh_h does not divide the part exactly
Complete 04_challenge.mac with sizes 0.04, 0.02 and
0.01 m. In the first case, beam_h/mesh_h=2.5: one line cannot
contain two and a half elements.
Your script should:
- Declare a policy to convert each quotient to an integer number of divisions.
- Inform the nominal size and the divisions actually used.
- Build the mesh without line, node or element IDs.
- Recheck the topological equations with the adopted integers.
- Generate the same CSV and select a mesh only if it meets the 2%.
The decision is part of the model
Rounding to the nearest integer approximates the nominal size. Always rounding up ensures that the actual size does not exceed it. Either choice must be explicit and applied consistently; do not silently delegate the decision to the mesher.
Self-assessment
- Why do approximately eight times as many elements appear when dividing the size by two?
- What practical difference exists between
ESIZEandLESIZE? - Which set remains active after
CHECK,ESEL,WARN? - Why can't the last mesh have a change with respect to itself?
- What should you conclude if
selected_case=0?
See short answers
- Because the divisions are duplicated in three directions:
2³=8. ESIZEis global;LESIZEcontrols selected lines and can impose divisions.- Only items that produce warnings or check errors.
- Convergence needs independent finer estimation.
- That the study does not allow a choice: another mesh must be added or the family must be revised.
Evidence of learning
m04_mesh_study.csvwith three cases.- Topological counts coincident with divisions.
- Summary
SHPPandn_shape_bad=0. - A graph of
|uy_tip|versus the number of elements. - The selected mesh and a justification based on cost and variation.
- The diagnosis of the five defects.
Exit checklist
- ☐ My three cases only differ in the discretization.
- ☐ The divisions are obtained from parameters and not from IDs.
- ☐ The real topology matches the expected one.
- ☐ TYPE, MAT and form approve before solving.
- ☐ The total load and the measurement point remain constant.
- ☐ Each change uses the next finer mesh as its reference.
- ☐ I accept
selected_case=0as a valid conclusion. - ☐ I do not use the singular stress of the fixed support as a criterion.
Technical traceability
The lesson uses Modeling and Meshing Guide for the mapped strategy;
Command Reference 2024 R1 for ESIZE, LESIZE,
MSHAPE, MSHKEY, SHPP, CHECK and
VCLEAR; and Element Reference for SOLID185.
Next step: M05
The test case has kept its boundary conditions constant. In M05 we will stop treating them as a preconfigured black box: we will translate the physical diagram into constraints and loads, and audit their resultant before solving.