Loading...
Loading...
Plan and evaluate mesh generation for numerical simulations — estimate grid resolution from physics scales (interface width, boundary layers, wavelengths), check aspect ratios and skewness against quality thresholds, choose between structured, unstructured, and adaptive mesh refinement strategies, and compute grid sizing for 1D/2D/3D domains. Use when setting up a new mesh, diagnosing poor solver convergence caused by mesh quality, deciding how many points to place across a phase-field interface or boundary layer, or preparing a mesh convergence study, even if the user only asks "what resolution do I need" or "why is my solver failing."
npx skill4agent add heshamfs/materials-simulation-skills mesh-generation| Input | Description | Example |
|---|---|---|
| Domain size | Physical dimensions | |
| Feature size | Smallest feature to resolve | |
| Points per feature | Resolution requirement | |
| Aspect ratio limit | Maximum dx/dy ratio | |
| Quality threshold | Skewness limit | |
What is the smallest feature size?
├── Interface width → dx ≤ width / 5
├── Boundary layer → dx ≤ layer_thickness / 10
├── Wave length → dx ≤ lambda / 20
└── Diffusion length → dx ≤ sqrt(D × dt) / 2| Problem | Recommended Mesh |
|---|---|
| Simple geometry, uniform | Structured Cartesian |
| Complex geometry | Unstructured triangular/tetrahedral |
| Boundary layers | Hybrid (structured near walls) |
| Adaptive refinement | Quadtree/Octree or AMR |
inputsresultsresult["results"]["..."]| Script | |
|---|---|
| |
| |
mesh_quality.pyskewness0.0high_skewnessaspect_ratiosize_anisotropy1 - 1/aspect_ratioscripts/grid_sizing.pyscripts/mesh_quality.pypython3 scripts/grid_sizing.py --length 0.001 --resolution 200 --json# Compute grid sizing for 1D domain
python3 scripts/grid_sizing.py --length 1.0 --resolution 200 --json
# Check mesh quality (3D cell)
python3 scripts/mesh_quality.py --dx 1.0 --dy 0.5 --dz 0.5 --json
# High aspect ratio check (2D cell; --dz omitted is treated as 2D)
python3 scripts/mesh_quality.py --dx 1.0 --dy 0.1 --json2| Error message | Cause | Resolution |
|---|---|---|
| Non-positive domain size | Use a positive value |
| Non-positive resolution ( | Use a positive integer |
| Unsupported dimension count | Use |
| | Use a finite positive value |
| Input above the resource-exhaustion bound | Use a smaller value |
| Aspect Ratio | Quality | Impact |
|---|---|---|
| 1:1 | Excellent | Optimal accuracy |
| 1:1 - 3:1 | Good | Acceptable |
| 3:1 - 5:1 | Fair | May affect accuracy |
| > 5:1 | Poor | Solver issues likely |
max(|90° - θ_i|) / 90°references/quality_metrics.mdmesh_quality.pyskewness = 0.0dx/dy/dz| Skewness | Quality | Impact |
|---|---|---|
| 0 - 0.25 | Excellent | Optimal |
| 0.25 - 0.50 | Good | Acceptable |
| 0.50 - 0.80 | Fair | May affect accuracy |
| > 0.80 | Poor | Likely problems |
Note: cell elongation is not skewness. An anisotropic but orthogonal cell (e.g. a wall-aligned boundary-layer cell) has high/aspect_ratiobut zero skewness, and is often perfectly acceptable.size_anisotropy
| Application | Points per Feature |
|---|---|
| Phase-field interface | 5-10 |
| Boundary layer | 10-20 |
| Shock | 3-5 (with capturing) |
| Wave propagation | 10-20 per wavelength |
| Smooth gradients | 5-10 |
dxcountsgrid_sizing.py --jsongrid_sizing.py--dx--lengthnotescountsaspect_ratioquality_flagsmesh_quality.py --jsonhigh_aspect_ratioskewness = 0.0dx| Tempting shortcut | Why it's wrong / what to do |
|---|---|
" | |
| "Two grids gave nearly the same answer, so the mesh is converged." | Two grids cannot establish the observed order or the asymptotic range. Use ≥3 successively refined grids and confirm the quantity of interest is converging before quoting any result as mesh-independent. |
"High | Elongation is not skewness. A wall-aligned boundary-layer cell with AR up to ~100 is acceptable when aligned with the flow/field; check |
"I'll set one | |
" | Points-per-domain is not points-per-feature. A fine global |
| "The mesh is fine enough, so I can ignore the time step." | Mesh resolution and temporal stability are coupled: shrinking |
lengthresolutiondxdydzdims{1, 2, 3}argparseallowed-toolsBasheval()exec()shell=TrueReadWritegrid_sizing.py--lengthdx--length 0.10 --dx 5e-5--length 0.05 --dx 5e-5references/mesh_types.mdreferences/quality_metrics.mdsize_anisotropymesh_quality.py --dz