numerical-methods-implementation
Skill0 starsChanged 2 days agoMITView on GitHub
Write the discretisation yourself: stencil and scheme choice, CFL and stability analysis, direct versus iterative solves with preconditioning, and convergence order measured by manufactured solution. Use when the solver is yours to write.
In this repository55 other files it gives its agents.
- advanced-optimizationSkill
- bayesian-inferenceSkill
- bayesian-pinnSkill
- bayesian-ude-workflowSkill
- catalyst-reactionsSkill
- continuum-mechanics-and-rheologySkill
- control-theorySkill
- creating-julia-appSkill
- debugging-toolkitSkill
- differential-equationsSkill
- differentiationSkill
- equation-discoverySkill
- experiment-trackingSkill
- fem-feaSkill
- julia-graph-neural-networksSkill
- julia-languageSkill
- julia-ml-and-dlSkill
- julia-model-deploymentSkill
- julia-paper-implementationSkill
- julia-pro-helpSkill
- julia-pro-modeSkill
- julia-reinforcement-learningSkill
- modeling-toolkitSkill
- neural-pdeSkill
- nonlinear-dynamicsSkill
- package-development-workflowSkill
- performance-tuningSkill
- physical-learning-systemsSkill
- playbook-debugSkill
- playbook-model-validateSkill
- playbook-package-releaseSkill
- playbook-paper-implementSkill
- playbook-perfSkill
- playbook-test-specSkill
- principle-both-sidesSkill
- principle-breakingSkill
- principle-file-is-truthSkill
- principle-gateSkill
- principle-limitsSkill
- principle-loud-failureSkill
- principle-one-stepSkill
- principle-proof-listSkill
- principle-rebuttalSkill
- principle-runtime-surfaceSkill
- principle-three-boundsSkill
- principle-three-clocksSkill
- scientific-visualizationSkill
- sciml-and-diffeqSkill
- setup-julia-proSkill
- signal-processingSkill
- simulation-and-hpcSkill
- statistical-physicsSkill
- symbolic-mathSkill
- web-development-juliaSkill
- zarr-cloud-arraysSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 22
Check stability: before trusting any long run — CFL for explicit hyperbolic, von Neumann for linear constant-coefficient, energy method for …
- Very specific: line 78
Refining only the time step: If dt is not tied to h (or the scheme is IMEX), the spatial order never shows.
- Distinctive: line 80
A preconditioner that changes the answer: Check the iterative solve against a direct one on a small instance.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Writing the discretisation yourself
This page is for the case where no library owns the stepper: a custom scheme, a bespoke boundary condition, a solver inside a performance-critical loop. If a library can solve it, use differential-equations and spend the effort on the model instead.
Depth
| Topic | Where |
| ODE/DAE/SDE solver choice and options | differential-equations |
| PDE in symbolic form, method of lines | modeling-toolkit |
| FEM specifically | fem-fea |
| making the compiled loop fast | performance-tuning |
The order of work
- Discretise the continuous equation, including boundaries, before writing a time loop. Done when every term of the PDE has a discrete counterpart and each boundary condition is imposed by a named method (ghost cell, algebraic elimination, weak form).
- Check consistency with a manufactured solution: pick a smooth
u, substitute into the PDE to get a source term, solve, and compare. Done when the error falls at the designed rate ashanddtshrink. - Check stability before trusting any long run — CFL for explicit hyperbolic, von Neumann for linear constant-coefficient, energy method for the rest. Done when the stable step size is derived and the code refuses to exceed it.
- Measure the order, do not assume it. Two grids minimum, three preferred. Done when the observed order matches the design order within 0.1–0.2 and the deviation is explained.
- Check what must be conserved, at every output. Done when mass/energy drift is a measured rate, not an eyeball.
Discretisation choice
| Scheme | Buys | Costs |
| finite difference | simplest on tensor grids, easy high order | geometry is a rectangle; conservation needs a conservative form |
| finite volume | local conservation by construction | reconstruction and limiters are where the bugs live |
| spectral / pseudospectral | exponential convergence for smooth solutions | Gibbs ringing at shocks; global transform cost |
| FEM | arbitrary geometry, weak handling of natural BCs | assembly and quadrature code, mass-matrix solves |
| method of lines | reuse an adaptive ODE solver | the solver sees a stiff system and will pick implicit steps |
For transport, write the flux form (∂_t u + ∂_x f(u) = 0) so the discrete sum telescopes to boundary fluxes; the non-conservative form loses conservation at the level of rounding and the loss is invisible until long times. For advection–diffusion, a central difference on the advective term is unstable above cell Péclet number 2 — upwind, or a flux limiter.
Time stepping
| Regime | Choice | Why |
| explicit, hyperbolic | SSP-RK2/RK3 with CFL ≤ 1 (dimension-dependent) | stability region covers the imaginary axis |
| stiff from diffusion or chemistry | BDF or an implicit RK (Radau) | stability region covers the negative real axis far out |
| both at once | IMEX: implicit diffusion, explicit advection | one linear solve per step instead of a nonlinear one |
| multiple physical processes | Strang splitting, second order | each sub-solver keeps its own stable step; splitting error is second order only if symmetric |
Explicit stability bounds are dimension-dependent: the diffusion limit is dt ≤ h²/(2d·D) for d dimensions, and forgetting the d is the classic factor-of-two-to-three surprise.
Linear solves inside the step
| Matrix | Method | Note |
| dense, one-off | LU with partial pivoting | cond estimate from the factorisation is nearly free |
| SPD | Cholesky | half the work, and failure is a gift: it proves non-SPD |
| sparse, one-off | sparse LU / UMFPACK | fill-in dominates; reorder before blaming the solver |
| sparse, many right-hand sides | factorise once, solve many | rebuilding the factorisation per step is the usual 100× |
| large SPD, iterative | CG with a preconditioner | without one, CG on a Poisson matrix takes O(1/h) iterations |
| nonsymmetric, iterative | GMRES with restart | watch the restart length; a stalled residual is often the preconditioner |
An implicit step is a linear solve plus a Newton loop when the operator is nonlinear, so the cost is (Newton iterations) × (solve). Report both, and check the Newton residual against the step tolerance: a Newton loop that stops early makes the scheme first order regardless of its design.
Measuring convergence
# manufactured solution: u(x,t) = sin(pi*x)*exp(-t), source added to the RHS
errs = Float64[]
for n in (40, 80, 160, 320)
h = 1 / n
push!(errs, maximum(abs.(solve_mms(n) .- exact.(grid(n), t_end))))
end
orders = log2.(errs[1:end-1] ./ errs[2:end]) # expect ~2 for a second-order schemelog2(err_i/err_{i+1}) is the observed order. A value below the design order means a boundary treatment, a limiter, or a non-smooth coefficient is eating it; a value above means the grids are in the asymptotic range not yet, or the error is dominated by the time step rather than h.
Traps
- Refining only the time step. If
dtis not tied toh(or the scheme is IMEX), the spatial order never shows. - Measuring against an exact solution on a coarse grid. The asymptotic regime starts when the error is smooth; two grids is the minimum, three is the honest number.
- A preconditioner that changes the answer. Check the iterative solve against a direct one on a small instance; a converged-to-the-wrong-operator solve looks identical to a good one.
- Stability tested only on the linearised problem. Nonlinear instability (aliasing, negative concentrations) appears where the linear analysis says nothing — add a positivity or boundedness check on the output.
Done when
The condition number of every linear solve is known (cond(A), and a preconditioner when it is large); the timestep satisfies a derived bound for the scheme in use; the conserved quantity is checked at every output, not only at the end; the observed convergence order is measured on at least three grids against a manufactured solution and matches the design order; and tightening every tolerance once leaves the answer unchanged.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

