Logo vun Differentiation Schemes

Differentiation Schemes

Communautéit
HeshamFS
differentiation-schemes

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."

Iwwersiicht

EditeurHeshamFS
Repositorymaterials-simulation-skills
Skill-Nummdifferentiation-schemes
Stären
83
Forks
6
Matgeliwwert Fichieren
9
LizenzApache-2.0
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • 9 matgeliwwert Dateien

    Skripten, Virlagen a Referenzen, déi de Modell beim Schaffe liese kann. D'Dateie kënnen nëmme gelies ginn a ginn ni ausgeféiert.

  • Open Source

    Vum HeshamFS op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Differentiation Schemes an TypingMind, fir e mat all LLM ze benotzen, oder füügt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vun GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier hei drënner an a bestätegt.
    https://github.com/HeshamFS/materials-simulation-skills/tree/main/skills/core-numerical/differentiation-schemes
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill afügen → Vu GitHub-URL, pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an de Skill-Verzeechnes vun deem KI-Agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/HeshamFS/materials-simulation-skills.git /tmp/materials-simulation-skills
mkdir -p .claude/skills
cp -r /tmp/materials-simulation-skills/skills/core-numerical/differentiation-schemes .claude/skills/differentiation-schemes
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Differentiation Schemes an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Differentiation Schemes automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Differentiation Schemes net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Keys.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

Differentiation Schemes

Goal

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

Requirements

  • Python 3.10+
  • 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, scheme
scripts/scheme_selector.pyrecommended, alternatives, notes
scripts/truncation_error.pyerror_scale, order, reduction_if_halved

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 (boundary type was not stated; if the domain is bounded rather than periodic, add --boundary to surface one-sided/ghost-cell guidance, or ask the user):
    bash
    python3 scripts/scheme_selector.py --smooth --order 2 --accuracy 4 --json
  2. Generate the stencil:
    bash
    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

bash
# 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 --accuracy 2 --scale 1.0 --json

Error Handling

ErrorCauseResolution
order must be positiveInvalid derivative orderUse 1, 2, 3, ... (max 6)
order must be <= 6Derivative order too largeUse 1–6
accuracy must be even for centralOdd accuracy requested for central schemeUse 2, 4, 6, ...
scheme must be central, forward, or backwardInvalid --scheme valueUse central, forward, or backward

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]

Verification checklist

Before trusting a generated stencil or accepting a scheme recommendation, record concrete evidence for each item below:

  • Ran stencil_generator.py --json and confirmed results.accuracy matches the requested order AND that len(results.offsets) equals the expected stencil width (e.g. 5 points for a 4th-order central second derivative); for a central scheme also verified the offsets are symmetric about 0.
  • Sanity-checked the returned coefficients against references/stencil_catalog.md: confirmed they sum to ~0 (consistency: the operator annihilates a constant) and reproduce a known catalog stencil for at least one standard case (e.g. 2nd-order d²/dx² gives [1, -2, 1]/dx²).
  • For a central scheme, confirmed --accuracy is even (odd values exit 2 with accuracy must be even for central); recorded the actual exit code rather than assuming the requested order was achieved.
  • Recorded the error_scale, order, and reduction_if_halved from truncation_error.py and confirmed reduction_if_halved == 2**accuracy, then compared error_scale against the smallest physical feature size (dx/L_feature from references/error_guidance.md) to confirm the grid actually resolves the physics.
  • Ran an independent grid-refinement / manufactured-solution study on >=3 grids (the scripts do NOT do this) and confirmed the observed order p_obs = log(e_h/e_{h/2})/log(2) is within ~10% of the formal accuracy before quoting that order.
  • For a bounded (non-periodic) domain, confirmed boundary stencils were generated/selected explicitly (--scheme forward|backward or --boundary guidance) per references/boundary_handling.md, since the interior stencil alone does not define the scheme order at the boundary.
  • For non-smooth fields (shocks/fronts), confirmed scheme_selector.py did NOT recommend high-order central FD and that a limiter/WENO/upwind path was chosen instead.

Common pitfalls & rationalizations

Tempting shortcutWhy it's wrong / what to do
"The stencil generator returned coefficients, so the scheme is the order I asked for."The accuracy field just echoes your request; it is not measured. Verify the achieved order with a grid-refinement study and confirm the coefficients match a catalog stencil and sum to ~0.
"I asked for 4th order on a central scheme with --accuracy 3, it'll just round up."It will not — central schemes reject odd accuracy with accuracy must be even for central (exit 2). Pass an even accuracy; an odd request is an error, not a silent upgrade.
"Higher accuracy order always means lower error here."truncation_error.py reports asymptotic scaling (scale * dx**accuracy); for a coarse grid or under-resolved feature the higher-order term need not dominate, and roundoff (O(ε/dx^p)) can win on very fine grids. Compare error_scale to the feature size, do not assume monotone improvement.
"Two grids agree closely, so it's converged."Two grids cannot estimate observed order or confirm the asymptotic range. Use >=3 grids and compute p_obs before claiming the formal order (see references/error_guidance.md).
"The interior stencil is 4th order, so my whole solve is 4th order."The generator emits interior stencils only; boundary closures often limit the global order. Generate one-sided/ghost-cell stencils explicitly and verify the boundary does not drop the observed order (references/boundary_handling.md).
"The field has a shock but a wide central stencil is more accurate, so use it."High-order central FD oscillates (Gibbs) at discontinuities. scheme_selector.py recommends FV with limiter/WENO or upwind for --discontinuous; follow it rather than maximizing formal order.
"Custom --offsets let me build any stencil I want."Offsets must be distinct, length-capped (51), and number more than the derivative order, or the script exits 2. A valid run still does not guarantee the intended accuracy — verify the coefficients and observed order.

Security

Input Validation

  • --order (derivative order) is validated as a positive integer with an upper bound (order <= 6)
  • --accuracy is validated as a positive integer (<= 8), and additionally must be even for central schemes
  • --scheme is validated against a fixed allowlist (central, forward, backward)
  • --offsets (custom stencil) is length-capped (max 51), parsed as distinct integers, and must exceed the derivative order
  • --dx and --scale are validated as finite, non-negative numbers (--dx strictly positive)
  • No user-supplied strings are interpolated into code paths or shell commands

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
  • Bash: Used to execute the three Python scripts (stencil_generator.py, scheme_selector.py, truncation_error.py) with explicit argument lists
  • Write: Used to save generated stencil coefficients or scheme recommendations; 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)
  • Stencil computation uses only small, bounded arrays (derivative order capped at 6, accuracy at 8, and custom offset lists capped at 51 points)
  • All output is deterministic JSON with no shell-interpretable content

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.2.2 (2026-06-24): Added a Verification checklist (evidence-based, tied to script JSON outputs and the references) and a Common pitfalls & rationalizations table.
  • v1.2.0 (2026-06-23): Enforced even-accuracy and order upper-bound validation, corrected Security/error-handling/output docs to match scripts, fixed CLI/eval examples, hardened input validation
  • v1.1.0 (2024-12-24): Enhanced documentation, decision guidance, examples
  • v1.0.0: Initial release with 3 differentiation scripts

Matgeliwwert Fichieren

De Modell liest dës Dateie bei Bedarf, wärend de Skill gelueden ass. Si ginn als liesbar Dateie bereetgestallt a ginn ni ausgeféiert.

Heefeg gestallte Froen

Wat mécht de KI-Skill Differentiation Schemes?

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 sol...

Firwat Differentiation Schemes op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Differentiation Schemes besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt amplaz vun engem Abonnement pro Benotzerplaz. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Differentiation Schemes an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/HeshamFS/materials-simulation-skills/tree/main/skills/core-numerical/differentiation-schemes an. TypingMind liest d'Datei SKILL.md, bündelt déi zougehéiereg Dateien an installéiert dat Ganzt als Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Differentiation Schemes benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Differentiation Schemes benotzen?

Esou vill Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Differentiation Schemes domat benotzen – GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama a méi – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Differentiation Schemes gratis?

Jo. De Skill gëtt vum HeshamFS ënner der Lizenz Apache-2.0 op GitHub publizéiert. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbaart Pak vun Instruktiounen, dat engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt en nokënnt a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a keng Lafzäitëmfeld a funktionéiere mat all Modell.

All weisen

Elo Ären eegene KI-Workspace ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇