Skip to content
differentiation-schemes logo

Differentiation Schemes

differentiation-schemes

Select and apply numerical differentiation schemes for PDE/ODE discretization. Use when choosing finite difference/volume/spectral schemes, building stencils, handling boundaries, estimating truncation error, or analyzing dispersion and dissipation.

SKILL.md

Full skill instructions

Differentiation Schemes

Goal

Provide a reliable workflow to select a differentiation scheme, generate stencils, and assess accuracy for simulation discretization.

Requirements

  • Python 3.8+
  • NumPy (for stencil computations)
  • No heavy dependencies

Inputs to Gather

InputDescriptionExample
Derivative orderFirst, second, etc.1 or 2
Target accuracyOrder of truncation error2 or 4
Grid typeUniform, nonuniformuniform
Boundary typePeriodic, Dirichlet, Neumannperiodic
SmoothnessSmooth or discontinuoussmooth

Decision Guidance

Scheme Selection Flowchart

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

Quick Reference

SituationRecommended Scheme
Smooth, periodicCentral, spectral
Smooth, boundedCentral + one-sided BCs
Advection-dominatedUpwind
Shocks/​frontsTVD, WENO
High accuracy neededCompact (Padé), spectral

Script Outputs (JSON Fields)

ScriptKey Outputs
scripts/​stencil_generator.pyoffsets, coefficients, order, accuracy
scripts/​scheme_selector.pyrecommended, alternatives, notes
scripts/​truncation_error.pyerror_scale, order, notes

Workflow

  1. Identify requirements - derivative order, accuracy, smoothness
  2. Select scheme - Run scripts/​scheme_selector.py
  3. Generate stencils - Run scripts/​stencil_generator.py
  4. Estimate error - Run scripts/​truncation_error.py
  5. Validate - Test with manufactured solutions or grid refinement

Conversational Workflow Example

User: I need to discretize a second derivative for a diffusion equation on a uniform grid. I want 4th-order accuracy.

Agent workflow:

  1. Select appropriate scheme:
    python3 scripts/​scheme_selector.py --smooth --periodic --order 2 --accuracy 4 --json
    
  2. Generate the stencil:
    python3 scripts/​stencil_generator.py --order 2 --accuracy 4 --scheme central --json
    
  3. Result: 5-point stencil with coefficients [-1/​12, 4/​3, -5/​2, 4/​3, -1/​12] / dx².

Pre-Discretization Checklist

  • Confirm derivative order and target accuracy
  • Choose scheme appropriate to smoothness and boundaries
  • Generate and inspect stencils at boundaries
  • Estimate truncation error vs physics scales
  • Verify with grid refinement study

CLI Examples

# 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 Handling

ErrorCauseResolution
order must be positiveInvalid derivative orderUse 1, 2, 3, ...
accuracy must be even for centralOdd accuracy requestedUse 2, 4, 6, ...
Unknown schemeInvalid scheme typeUse central, upwind, compact

Interpretation Guidance

Stencil Properties

PropertyMeaning
Symmetric offsetsCentral scheme (no directional bias)
Asymmetric offsetsOne-sided or upwind scheme
More pointsHigher accuracy but wider stencil

Truncation Error Scaling

Accuracy OrderError Scales AsRefinement Factor
2nd orderO(dx²)2× refinement → 4× error reduction
4th orderO(dx⁴)2× refinement → 16× error reduction
6th orderO(dx⁶)2× refinement → 64× error reduction

Common Stencils

DerivativeAccuracyPointsCoefficients (× 1/​dx or 1/​dx²)
1st23[-1/​2, 0, 1/​2]
1st45[1/​12, -2/​3, 0, 2/​3, -1/​12]
2nd23[1, -2, 1]
2nd45[-1/​12, 4/​3, -5/​2, 4/​3, -1/​12]

Limitations

  • Boundary handling: Stencil generator provides interior stencils; boundaries need special treatment
  • Nonuniform grids: Standard stencils assume uniform spacing
  • Spectral: Not covered by stencil generator

References

  • references/​stencil_catalog.md - Common stencils
  • references/​boundary_handling.md - One-sided schemes
  • references/​scheme_selection.md - FD/​FV/​spectral comparison
  • references/​error_guidance.md - Truncation error scaling

Version History

  • v1.1.0 (2024-12-24): Enhanced documentation, decision guidance, examples
  • v1.0.0: Initial release with 3 differentiation scripts

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View