skills/core-numerical/differentiation-schemes/SKILL.md
Select and apply numerical differentiation schemes for PDE and ODE discretization — generate finite-difference stencils at arbitrary order and accuracy, choose between central, upwind, compact (Pade), and spectral methods, handle boundary stencils, and estimate truncation error scaling. Use when discretizing spatial derivatives, picking a scheme for advection- or diffusion-dominated problems, building custom stencils for nonstandard operators, or comparing dispersion and dissipation properties of candidate schemes, even if the user just says "how do I approximate this derivative" or "my solution is too diffusive."
npx skillsauth add HeshamFS/materials-simulation-skills differentiation-schemesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Provide a reliable workflow to select a differentiation scheme, generate stencils, and assess accuracy for simulation discretization.
| Input | Description | Example |
|-------|-------------|---------|
| Derivative order | First, second, etc. | 1 or 2 |
| Target accuracy | Order of truncation error | 2 or 4 |
| Grid type | Uniform, nonuniform | uniform |
| Boundary type | Periodic, Dirichlet, Neumann | periodic |
| Smoothness | Smooth or discontinuous | smooth |
Is the field smooth?
├── YES → Is domain periodic?
│ ├── YES → Use central differences or spectral
│ └── NO → Use central interior + one-sided at boundaries
└── NO → Are there shocks/discontinuities?
├── YES → Use upwind, TVD, or WENO
└── NO → Use central with limiters
| Situation | Recommended Scheme | |-----------|-------------------| | Smooth, periodic | Central, spectral | | Smooth, bounded | Central + one-sided BCs | | Advection-dominated | Upwind | | Shocks/fronts | TVD, WENO | | High accuracy needed | Compact (Padé), spectral |
| Script | Key Outputs |
|--------|-------------|
| scripts/stencil_generator.py | offsets, coefficients, order, accuracy |
| scripts/scheme_selector.py | recommended, alternatives, notes |
| scripts/truncation_error.py | error_scale, order, notes |
scripts/scheme_selector.pyscripts/stencil_generator.pyscripts/truncation_error.pyUser: I need to discretize a second derivative for a diffusion equation on a uniform grid. I want 4th-order accuracy.
Agent workflow:
python3 scripts/scheme_selector.py --smooth --periodic --order 2 --accuracy 4 --json
python3 scripts/stencil_generator.py --order 2 --accuracy 4 --scheme central --json
[-1/12, 4/3, -5/2, 4/3, -1/12] / dx².# Select scheme for smooth periodic problem
python3 scripts/scheme_selector.py --smooth --periodic --order 1 --accuracy 4 --json
# Generate central difference stencil for first derivative
python3 scripts/stencil_generator.py --order 1 --accuracy 2 --scheme central --json
# Generate 4th-order second derivative stencil
python3 scripts/stencil_generator.py --order 2 --accuracy 4 --scheme central --json
# Estimate truncation error
python3 scripts/truncation_error.py --dx 0.01 --order 2 --accuracy 2 --scale 1.0 --json
| Error | Cause | Resolution |
|-------|-------|------------|
| order must be positive | Invalid derivative order | Use 1, 2, 3, ... |
| accuracy must be even for central | Odd accuracy requested | Use 2, 4, 6, ... |
| Unknown scheme | Invalid scheme type | Use central, upwind, compact |
| Property | Meaning | |----------|---------| | Symmetric offsets | Central scheme (no directional bias) | | Asymmetric offsets | One-sided or upwind scheme | | More points | Higher accuracy but wider stencil |
| Accuracy Order | Error Scales As | Refinement Factor | |----------------|-----------------|-------------------| | 2nd order | O(dx²) | 2× refinement → 4× error reduction | | 4th order | O(dx⁴) | 2× refinement → 16× error reduction | | 6th order | O(dx⁶) | 2× refinement → 64× error reduction |
| Derivative | Accuracy | Points | Coefficients (× 1/dx or 1/dx²) | |------------|----------|--------|-------------------------------| | 1st | 2 | 3 | [-1/2, 0, 1/2] | | 1st | 4 | 5 | [1/12, -2/3, 0, 2/3, -1/12] | | 2nd | 2 | 3 | [1, -2, 1] | | 2nd | 4 | 5 | [-1/12, 4/3, -5/2, 4/3, -1/12] |
--order (derivative order) is validated as a positive integer with an upper bound--accuracy is validated as a positive even integer for central schemes--scheme is validated against a fixed allowlist (central, upwind, compact)--dx and --scale are validated as finite positive numbersstencil_generator.py, scheme_selector.py, truncation_error.py) with explicit argument listseval(), exec(), or dynamic code generationshell=True)references/stencil_catalog.md - Common stencilsreferences/boundary_handling.md - One-sided schemesreferences/scheme_selection.md - FD/FV/spectral comparisonreferences/error_guidance.md - Truncation error scalingdevelopment
Plan verification and validation campaigns for simulation codes using manufactured solutions, canonical benchmark problems, grid/time refinement, uncertainty propagation, and pass/fail acceptance criteria. Use when an agent needs to prove a solver, model, or result is trustworthy rather than only plausible.
testing
Map computational materials tasks onto workflow engines such as atomate2, jobflow, AiiDA, pyiron, or a simple one-off script. Use when deciding how to structure a reproducible campaign, DAG, restart strategy, provenance record, storage layout, or migration path from ad hoc scripts to managed workflows.
development
Plan molecular dynamics post-processing for materials simulations, including RDF, MSD and diffusion, VACF/VDOS, coordination numbers, bond-angle distributions, stress-strain curves, equilibration detection, PBC unwrapping, and trajectory format choices. Use before writing MD analysis scripts or trusting trajectory-derived results.
development
Triage cross-code simulation failures and propose safe retry ladders for nonconvergence, NaN/Inf, exploding energies, unstable timesteps, pressure blow-up, missing potentials, bad pseudopotentials, corrupted output, and incomplete runs. Use when an agent sees a failed or suspicious materials simulation and needs a defensible first response.