Mesh Generation
Goal
Provide a consistent workflow for selecting mesh resolution and checking mesh quality for PDE simulations.
Requirements
- Python 3.10+
- 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
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 |
Security
Input Validation
- All inputs (
length, resolution, dx, dy, dz) are validated as finite positive numbers with upper bounds to prevent resource exhaustion
dims is restricted to {1, 2, 3}
argparse type parameters reject non-numeric input at the CLI boundary before any processing occurs
File Access
- Scripts read no external files; all inputs are provided via CLI arguments
- Scripts write only to stdout (JSON output); no files are created unless the agent explicitly uses the Write tool
Tool Restrictions
- Read: Used to inspect script source, references, and user configuration files
- Write: Used to save grid sizing results or mesh quality reports; writes are scoped to the user's working directory
- Grep/Glob: Used to locate relevant files and search references
- The skill's
allowed-tools excludes Bash to prevent the agent from executing arbitrary commands when processing user-provided inputs
Safety Measures
- No
eval(), exec(), or dynamic code generation
- All subprocess calls use explicit argument lists (no
shell=True)
- Reduced tool surface (no Bash) means the agent should use
Read and Write to prepare inputs and capture outputs rather than constructing shell commands from user text
- All output is deterministic JSON with no shell-interpretable content
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 unstructured
references/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
1---2name: mesh-generation3description: >4 Plan and evaluate mesh generation for numerical simulations — estimate grid5 resolution from physics scales (interface width, boundary layers, wavelengths),6 check aspect ratios and skewness against quality thresholds, choose between7 structured, unstructured, and adaptive mesh refinement strategies, and compute8 grid sizing for 1D/2D/3D domains. Use when setting up a new mesh, diagnosing9 poor solver convergence caused by mesh quality, deciding how many points to10 place across a phase-field interface or boundary layer, or preparing a mesh11 convergence study, even if the user only asks "what resolution do I need"12 or "why is my solver failing."13allowed-tools: Read, Write, Grep, Glob14metadata:15 source: https://skillmd.com/skills/zuoguyoupan2023/mesh-generation16 author: HeshamFS17 version: "1.1.0"18 security_tier: medium19 security_reviewed: true20 tested_with:21 - claude-code22 - gemini-cli23 - vs-code-copilot24 eval_cases: 425 last_reviewed: "2026-03-26"26---2728# Mesh Generation2930## Goal3132Provide a consistent workflow for selecting mesh resolution and checking mesh quality for PDE simulations.3334## Requirements3536- Python 3.10+37- No external dependencies (uses stdlib)3839## Inputs to Gather4041| Input | Description | Example |42|-------|-------------|---------|43| Domain size | Physical dimensions | `1.0 × 1.0 m` |44| Feature size | Smallest feature to resolve | `0.01 m` |45| Points per feature | Resolution requirement | `10 points` |46| Aspect ratio limit | Maximum dx/dy ratio | `5:1` |47| Quality threshold | Skewness limit | `< 0.8` |4849## Decision Guidance5051### Resolution Selection5253```54What is the smallest feature size?55├── Interface width → dx ≤ width / 556├── Boundary layer → dx ≤ layer_thickness / 1057├── Wave length → dx ≤ lambda / 2058└── Diffusion length → dx ≤ sqrt(D × dt) / 259```6061### Mesh Type Selection6263| Problem | Recommended Mesh |64|---------|------------------|65| Simple geometry, uniform | Structured Cartesian |66| Complex geometry | Unstructured triangular/tetrahedral |67| Boundary layers | Hybrid (structured near walls) |68| Adaptive refinement | Quadtree/Octree or AMR |6970## Script Outputs (JSON Fields)7172| Script | Key Outputs |73|--------|-------------|74| `scripts/grid_sizing.py` | `dx`, `nx`, `ny`, `nz`, `notes` |75| `scripts/mesh_quality.py` | `aspect_ratio`, `skewness`, `quality_flags` |7677## Workflow78791. **Estimate resolution** - From physics scales802. **Compute grid sizing** - Run `scripts/grid_sizing.py`813. **Check quality metrics** - Run `scripts/mesh_quality.py`824. **Adjust if needed** - Fix aspect ratios, reduce skewness835. **Validate** - Mesh convergence study8485## Conversational Workflow Example8687**User**: I need to mesh a 1mm × 1mm domain for a phase-field simulation with interface width of 10 μm.8889**Agent workflow**:901. Compute grid sizing:91 ```bash92 python3 scripts/grid_sizing.py --length 0.001 --resolution 200 --json93 ```942. Verify interface is resolved: dx = 5 μm, interface width = 10 μm → 2 points per interface width.953. Recommend: Increase to 500 points (dx = 2 μm) for 5 points across interface.9697## Pre-Mesh Checklist9899- [ ] Define target resolution per feature/interface100- [ ] Ensure dx meets stability constraints (see numerical-stability)101- [ ] Check aspect ratio < limit (typically 5:1)102- [ ] Check skewness < threshold (typically 0.8)103- [ ] Validate mesh convergence with refinement study104105## CLI Examples106107```bash108# Compute grid sizing for 1D domain109python3 scripts/grid_sizing.py --length 1.0 --resolution 200 --json110111# Check mesh quality112python3 scripts/mesh_quality.py --dx 1.0 --dy 0.5 --dz 0.5 --json113114# High aspect ratio check115python3 scripts/mesh_quality.py --dx 1.0 --dy 0.1 --json116```117118## Error Handling119120| Error | Cause | Resolution |121|-------|-------|------------|122| `length must be positive` | Invalid domain size | Use positive value |123| `resolution must be > 1` | Insufficient points | Use at least 2 |124| `dx, dy must be positive` | Invalid spacing | Use positive values |125126## Interpretation Guidance127128### Aspect Ratio129130| Aspect Ratio | Quality | Impact |131|--------------|---------|--------|132| 1:1 | Excellent | Optimal accuracy |133| 1:1 - 3:1 | Good | Acceptable |134| 3:1 - 5:1 | Fair | May affect accuracy |135| > 5:1 | Poor | Solver issues likely |136137### Skewness138139| Skewness | Quality | Impact |140|----------|---------|--------|141| 0 - 0.25 | Excellent | Optimal |142| 0.25 - 0.50 | Good | Acceptable |143| 0.50 - 0.80 | Fair | May affect accuracy |144| > 0.80 | Poor | Likely problems |145146### Resolution Guidelines147148| Application | Points per Feature |149|-------------|-------------------|150| Phase-field interface | 5-10 |151| Boundary layer | 10-20 |152| Shock | 3-5 (with capturing) |153| Wave propagation | 10-20 per wavelength |154| Smooth gradients | 5-10 |155156## Security157158### Input Validation159- All inputs (`length`, `resolution`, `dx`, `dy`, `dz`) are validated as finite positive numbers with upper bounds to prevent resource exhaustion160- `dims` is restricted to `{1, 2, 3}`161- `argparse` type parameters reject non-numeric input at the CLI boundary before any processing occurs162163### File Access164- Scripts read no external files; all inputs are provided via CLI arguments165- Scripts write only to stdout (JSON output); no files are created unless the agent explicitly uses the Write tool166167### Tool Restrictions168- **Read**: Used to inspect script source, references, and user configuration files169- **Write**: Used to save grid sizing results or mesh quality reports; writes are scoped to the user's working directory170- **Grep/Glob**: Used to locate relevant files and search references171- The skill's `allowed-tools` excludes `Bash` to prevent the agent from executing arbitrary commands when processing user-provided inputs172173### Safety Measures174- No `eval()`, `exec()`, or dynamic code generation175- All subprocess calls use explicit argument lists (no `shell=True`)176- Reduced tool surface (no Bash) means the agent should use `Read` and `Write` to prepare inputs and capture outputs rather than constructing shell commands from user text177- All output is deterministic JSON with no shell-interpretable content178179## Limitations180181- **2D/3D only**: No unstructured mesh generation182- **Quality metrics**: Basic aspect ratio and skewness only183- **No mesh generation**: Sizing recommendations only184185## References186187- `references/mesh_types.md` - Structured vs unstructured188- `references/quality_metrics.md` - Aspect ratio/skewness thresholds189190## Version History191192- **v1.1.0** (2024-12-24): Enhanced documentation, decision guidance, examples193- **v1.0.0**: Initial release with 2 mesh quality scripts