Agent skill
numerical-stability
Analyze numerical stability for time-dependent PDE simulations — check CFL and Fourier criteria, perform von Neumann stability analysis, detect stiffness, evaluate matrix conditioning, and recommend explicit vs implicit time-stepping schemes. Use when selecting time steps, diagnosing numerical blow-up or solver divergence, checking convergence criteria, or evaluating scheme stability for advection, diffusion, or reaction problems, even if the user doesn't explicitly mention "stability" or "CFL."
Install this agent skill to your Project
npx add-skill https://github.com/HeshamFS/materials-simulation-skills/tree/main/skills/core-numerical/numerical-stability
Metadata
Additional technical details for this skill
- author
- HeshamFS
- version
- 1.1.0
- eval cases
- 2
- tested with
-
[ "claude-code", "gemini-cli", "vs-code-copilot" ] - last reviewed
- 2026-03-26
- security tier
- high
- security reviewed
- YES
SKILL.md
Numerical Stability
Goal
Provide a repeatable checklist and script-driven checks to keep time-dependent simulations stable and defensible.
Requirements
- Python 3.8+
- NumPy (for matrix_condition.py and von_neumann_analyzer.py)
- See
scripts/requirements.txtfor dependencies
Inputs to Gather
| Input | Description | Example |
|---|---|---|
Grid spacing dx |
Spatial discretization | 0.01 m |
Time step dt |
Temporal discretization | 1e-4 s |
Velocity v |
Advection speed | 1.0 m/s |
Diffusivity D |
Thermal/mass diffusivity | 1e-5 m²/s |
Reaction rate k |
First-order rate constant | 100 s⁻¹ |
| Dimensions | 1D, 2D, or 3D | 2 |
| Scheme type | Explicit or implicit | explicit |
Decision Guidance
Choosing Explicit vs Implicit
Is the problem stiff (fast + slow dynamics)?
├── YES → Use implicit or IMEX scheme
│ └── Check conditioning with matrix_condition.py
└── NO → Is CFL/Fourier satisfied with reasonable dt?
├── YES → Use explicit scheme (cheaper per step)
└── NO → Consider implicit or reduce dx
Stability Limit Quick Reference
| Physics | Number | Explicit Limit (1D) | Formula |
|---|---|---|---|
| Advection | CFL | C ≤ 1 | C = v·dt/dx |
| Diffusion | Fourier | Fo ≤ 0.5 | Fo = D·dt/dx² |
| Reaction | Reaction | R ≤ 1 | R = k·dt |
Multi-dimensional correction: For d dimensions, diffusion limit is Fo ≤ 1/(2d).
Script Outputs (JSON Fields)
| Script | Key Outputs |
|---|---|
scripts/cfl_checker.py |
metrics.cfl, metrics.fourier, recommended_dt, stable |
scripts/von_neumann_analyzer.py |
results.max_amplification, results.stable |
scripts/matrix_condition.py |
results.condition_number, results.is_symmetric |
scripts/stiffness_detector.py |
results.stiffness_ratio, results.stiff, results.recommendation |
Workflow
- Identify dominant physics (advection vs diffusion vs reaction)
- Run CFL checker with
scripts/cfl_checker.py - Compare to limits and adjust
dtif needed - Check stiffness with
scripts/stiffness_detector.pyif multiple scales - Analyze custom schemes with
scripts/von_neumann_analyzer.py - Check conditioning with
scripts/matrix_condition.pyfor implicit solves - Document the stability verdict and recommended time step
Conversational Workflow Example
User: My phase-field simulation is blowing up after 100 steps. I'm using explicit Euler with dx=0.01, dt=1e-4, and diffusivity D=1e-3.
Agent workflow:
- Check stability criteria:
bash
python3 scripts/cfl_checker.py --dx 0.01 --dt 1e-4 --diffusivity 1e-3 --dimensions 2 --json - Interpret results:
- Fourier number:
Fo = 1e-3 × 1e-4 / (0.01)² = 1.0 - 2D limit:
Fo ≤ 0.25 - Violation: Fo = 1.0 > 0.25, unstable!
- Fourier number:
- Recommend fix:
- Reduce dt to
2.5e-5(to get Fo = 0.25) - Or increase dx, or switch to implicit
- Reduce dt to
Pre-Simulation Stability Checklist
- Identify dominant physics and nondimensional groups
- Compute CFL/Fourier/Reaction numbers with
cfl_checker.py - If explicit and limit violated, reduce
dtor change scheme - If stiffness ratio > 1000, select implicit/stiff integrator
- For custom schemes, verify amplification factor ≤ 1
- Document stability reasoning with inputs and outputs
CLI Examples
# Check CFL/Fourier for 2D diffusion-advection
python3 scripts/cfl_checker.py --dx 0.1 --dt 0.01 --velocity 1.0 --diffusivity 0.1 --dimensions 2 --json
# Von Neumann analysis for custom 3-point stencil
python3 scripts/von_neumann_analyzer.py --coeffs 0.2,0.6,0.2 --dx 1.0 --nk 128 --json
# Detect stiffness from eigenvalue estimates
python3 scripts/stiffness_detector.py --eigs=-1,-1000 --json
# Check matrix conditioning for implicit system
python3 scripts/matrix_condition.py --matrix A.npy --norm 2 --json
Error Handling
| Error | Cause | Resolution |
|---|---|---|
dx and dt must be positive |
Zero or negative values | Provide valid positive numbers |
No stability criteria applied |
Missing velocity/diffusivity | Provide at least one physics parameter |
Matrix file not found |
Invalid path | Check matrix file exists |
Could not compute eigenvalues |
Singular or ill-formed matrix | Check matrix validity |
Interpretation Guidance
| Scenario | Meaning | Action |
|---|---|---|
stable: true |
All checked criteria satisfied | Proceed with simulation |
stable: false |
At least one limit violated | Reduce dt or change scheme |
stable: null |
No criteria could be applied | Provide more physics inputs |
| Stiffness ratio > 1000 | Problem is stiff | Use implicit integrator |
| Condition number > 10⁶ | Ill-conditioned | Use scaling/preconditioning |
Security
Input Validation
- All numeric parameters (
dx,dt,velocity,diffusivity,dimensions) are validated as finite positive numbers before any computation --dimensionsis restricted to{1, 2, 3}- Comma-separated eigenvalue lists (
--eigs) are capped at 10,000 entries and validated as finite numbers - Stencil coefficient lists (
--coeffs) are length-limited and validated as finite floats
File Access
matrix_condition.pyreads a single matrix file (.npyformat) specified by--matrix; no directory traversal beyond the given path- Matrix files are rejected if they exceed 500 MB before parsing
np.load()is called withallow_pickle=Falseto prevent arbitrary code execution via crafted.npyfiles- 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
- Bash: Used to execute the four Python analysis scripts (
cfl_checker.py,von_neumann_analyzer.py,matrix_condition.py,stiffness_detector.py) with explicit argument lists - Write: Used to save analysis results or generated reports; writes are scoped to the user's working directory
- Grep/Glob: Used to locate relevant files and search references
Safety Measures
- No
eval(),exec(), or dynamic code generation - All subprocess calls use explicit argument lists (no
shell=True) - Matrix dimension limits (100,000 per dimension) prevent memory exhaustion
- JSON output mode (
--json) produces structured, parseable results without shell-interpretable content
Limitations
- Explicit schemes only for CFL/Fourier checks (implicit is unconditionally stable)
- Von Neumann analysis assumes linear, constant-coefficient, periodic BCs
- Stiffness detection requires eigenvalue estimates from user
References
references/stability_criteria.md- Decision thresholds and formulasreferences/common_pitfalls.md- Frequent failure modes and fixesreferences/scheme_catalog.md- Stability properties of common schemes
Version History
- v1.1.0 (2024-12-24): Enhanced documentation, decision guidance, examples
- v1.0.0: Initial release with 4 stability analysis scripts
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
post-processing
Extract, analyze, and summarize simulation output data — pull spatial fields at specific timesteps, compute time-series trends and detect steady state, extract line profiles through the domain, generate statistical summaries and distributions, calculate derived quantities (gradients, fluxes, volume fractions, interface area), compare results against analytical solutions or experimental data, and produce automated analysis reports. Use when interpreting finished simulation results, checking mass or energy conservation, comparing two runs or meshes, extracting interface profiles from phase-field output, or preparing publication-quality analysis, even if the user only says "what do my results look like" or "did my simulation reach steady state."
performance-profiling
Identify computational bottlenecks, analyze parallel scaling, estimate memory requirements, and generate optimization recommendations for materials simulations — parse timing logs to find dominant phases (solver, assembly, I/O), evaluate strong and weak scaling efficiency, profile memory from mesh and field parameters, and detect bottlenecks with actionable fix suggestions. Use when a simulation is running slower than expected, investigating MPI scaling efficiency, planning HPC resource allocation, deciding whether to tune the preconditioner or reduce I/O frequency, or estimating if a problem fits in available RAM, even if the user only says "my simulation is too slow" or "how many nodes do I need."
parameter-optimization
Explore and optimize simulation parameters via design of experiments (DOE), sensitivity analysis, and optimizer selection — generate Latin Hypercube, quasi-random, or factorial sample plans, rank parameter influence with sensitivity scores, recommend Bayesian optimization, CMA-ES, or gradient- based methods based on dimension and budget, and fit surrogate models for expensive evaluations. Use when calibrating material properties against experimental data, planning a parameter sweep, performing uncertainty quantification, or choosing an optimization strategy for a simulation with a limited evaluation budget, even if the user only says "which parameters matter most" or "how do I calibrate my model."
simulation-validator
Validate simulations across three stages — run pre-flight checks on configuration files (parameter ranges, required fields, disk space), monitor runtime logs for residual growth, NaN/Inf, and adaptive dt collapse, and perform post-flight validation of results (physical bounds, mass/energy conservation, convergence). Diagnose failed simulations with probable-cause analysis and recommended fixes. Use when preparing to launch a simulation, checking whether a running job is healthy, verifying that finished results are trustworthy, or debugging a crash or blow-up, even if the user only says "my simulation crashed" or "can I trust these results."
simulation-orchestrator
Orchestrate multi-simulation campaigns — generate parameter sweep configurations (grid, linspace, or Latin Hypercube sampling), initialize and track batch job campaigns, monitor job completion status, and aggregate results with summary statistics across all runs. Use when running a parameter study across dt, kappa, or other simulation inputs, managing dozens or hundreds of simulation configurations, combining outputs from completed batch runs to find the best result, or automating the generate-run-collect workflow for systematic studies, even if the user only says "I need to try many parameter combinations" or "how do I organize a sweep."
ontology-explorer
Parse, navigate, and query materials science ontology structures — browse class hierarchies, inspect individual classes and their properties, look up object and data property definitions with domain/range, search for ontology terms by keyword, and parse or summarize raw OWL/XML files. Supports the OCDO ecosystem (CMSO, ASMO, CDCO, PODO, PLDO, LDO). Use when exploring what classes or properties an ontology provides, finding the right CMSO term for a crystal structure or simulation concept, understanding parent-child class relationships, or onboarding to an unfamiliar materials ontology, even if the user only says "what ontology terms describe my FCC copper simulation" or "show me the CMSO class hierarchy."
Didn't find tool you were looking for?