mesh-generation
npx machina-cli add skill HeshamFS/materials-simulation-skills/mesh-generation --openclawMesh Generation
Goal
Provide a consistent workflow for selecting mesh resolution and checking mesh quality for PDE simulations.
Requirements
- Python 3.8+
- No external dependencies (uses stdlib)
Inputs to Gather
| Input | Description | Example |
|---|---|---|
| Domain size | Physical dimensions | 1.0 × 1.0 m |
| Feature size | Smallest feature to resolve | 0.01 m |
| Points per feature | Resolution requirement | 10 points |
| Aspect ratio limit | Maximum dx/dy ratio | 5:1 |
| Quality threshold | Skewness limit | < 0.8 |
Decision Guidance
Resolution Selection
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
Mesh Type Selection
| 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 |
Script Outputs (JSON Fields)
| Script | Key Outputs |
|---|---|
scripts/grid_sizing.py | dx, nx, ny, nz, notes |
scripts/mesh_quality.py | aspect_ratio, skewness, quality_flags |
Workflow
- Estimate resolution - From physics scales
- Compute grid sizing - Run
scripts/grid_sizing.py - Check quality metrics - Run
scripts/mesh_quality.py - Adjust if needed - Fix aspect ratios, reduce skewness
- Validate - Mesh convergence study
Conversational Workflow Example
User: I need to mesh a 1mm × 1mm domain for a phase-field simulation with interface width of 10 μm.
Agent workflow:
- Compute grid sizing:
python3 scripts/grid_sizing.py --length 0.001 --resolution 200 --json - Verify interface is resolved: dx = 5 μm, interface width = 10 μm → 2 points per interface width.
- Recommend: Increase to 500 points (dx = 2 μm) for 5 points across interface.
Pre-Mesh Checklist
- Define target resolution per feature/interface
- Ensure dx meets stability constraints (see numerical-stability)
- Check aspect ratio < limit (typically 5:1)
- Check skewness < threshold (typically 0.8)
- Validate mesh convergence with refinement study
CLI Examples
# Compute grid sizing for 1D domain
python3 scripts/grid_sizing.py --length 1.0 --resolution 200 --json
# Check mesh quality
python3 scripts/mesh_quality.py --dx 1.0 --dy 0.5 --dz 0.5 --json
# High aspect ratio check
python3 scripts/mesh_quality.py --dx 1.0 --dy 0.1 --json
Error Handling
| Error | Cause | Resolution |
|---|---|---|
length must be positive | Invalid domain size | Use positive value |
resolution must be > 1 | Insufficient points | Use at least 2 |
dx, dy must be positive | Invalid spacing | Use positive values |
Interpretation Guidance
Aspect Ratio
| 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 |
Skewness
| 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 |
Resolution Guidelines
| 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 |
Limitations
- 2D/3D only: No unstructured mesh generation
- Quality metrics: Basic aspect ratio and skewness only
- No mesh generation: Sizing recommendations only
References
references/mesh_types.md- Structured vs unstructuredreferences/quality_metrics.md- Aspect ratio/skewness thresholds
Version History
- v1.1.0 (2024-12-24): Enhanced documentation, decision guidance, examples
- v1.0.0: Initial release with 2 mesh quality scripts
Source
git clone https://github.com/HeshamFS/materials-simulation-skills/blob/main/skills/core-numerical/mesh-generation/SKILL.mdView on GitHub Overview
Provides a consistent workflow to select mesh resolution and assess mesh quality for PDE simulations. It guides estimating feature-based spacing, choosing mesh types, and planning adaptive refinement, with validation through a mesh convergence study.
How This Skill Works
Key inputs include domain size, feature size, points per feature, aspect ratio limit, and a quality threshold. The workflow runs grid_sizing.py to compute dx, nx, ny, nz, then uses mesh_quality.py to assess aspect ratio and skewness. If metrics exceed thresholds, recommendations are issued to adjust the mesh before running a convergence study.
When to Use It
- Choosing mesh resolution for a PDE discretization based on the smallest features and required accuracy.
- Ensuring aspect ratio stays within acceptable limits to avoid solver issues.
- Estimating mesh quality constraints before a simulation run.
- Planning adaptive mesh refinement (AMR) or quad/octree strategies for complex geometries.
- Preparing and validating a pre-mesh checklist to ensure stability and convergence.
Quick Start
- Step 1: Estimate resolution from physics scales (smallest feature, interface width).
- Step 2: Run python3 scripts/grid_sizing.py --length <L> --resolution <points> --json to obtain dx, nx, ny, nz and notes.
- Step 3: Run python3 scripts/mesh_quality.py --dx <dx> --dy <dy> --dz <dz> --json, adjust as needed, and perform a convergence study.
Best Practices
- Define target resolution per feature using the smallest physical feature and interface width as a guide.
- Verify dx meets stability/accuracy constraints early in the workflow (consult numerical-stability guidance).
- Monitor aspect ratio (< 5:1) and skewness (< 0.8) and adjust mesh accordingly.
- Prefer structured meshes for simple geometries and unstructured meshes for complex geometries, with hybrids near boundaries.
- Run a mesh convergence study to confirm that refinement improves solution accuracy and is cost-effective.
Example Use Cases
- Phase-field simulation on a 1 mm × 1 mm domain with a 10 μm interface; compute grid sizing, resolve with dx = 5 μm (2 points per interface) and refine to dx = 2 μm for 5 points across the interface.
- Plan adaptive refinement using quad/octree or AMR to capture sharp gradients while keeping resources manageable.
- Resolve boundary layers by ensuring dx ≤ layer_thickness / 10 near walls for viscous-dominated flows.
- Apply an unstructured mesh strategy for a complex geometry where a structured grid is impractical.
- Check and adjust an anisotropic domain to keep the aspect ratio below the specified limit before simulation.