1---2name: numerical-integration3description: Select and configure time integration methods for ODE and PDE simulations — choose among explicit Runge-Kutta, BDF, Rosenbrock, and Adams families, set relative and absolute error tolerances, implement adaptive step-size control with P/PI step-size controllers, plan IMEX operator splitting for mixed stiff and non-stiff terms, and estimate splitting errors. Use when picking an integrator for a new simulation, diagnosing step rejections or tolerance failures, setting up operator splitting for phase-field or reaction-diffusion problems, or deciding between explicit and implicit time marching, even if the user only says "my solver keeps rejecting steps" or "which ODE method should I use."4---56# Numerical Integration78## Goal910Provide a reliable workflow to select integrators, set tolerances, and manage adaptive time stepping for time-dependent simulations.1112## Requirements1314- Python 3.10+15- NumPy (for some scripts)16- No heavy dependencies for core functionality1718## Inputs to Gather1920| Input | Description | Example |21|-------|-------------|---------|22| Problem type | ODE/PDE, stiff/non-stiff | `stiff PDE` |23| Jacobian available | Can compute ∂f/∂u? | `yes` |24| Target accuracy | Desired error level | `1e-6` |25| Constraints | Memory, implicit allowed? | `implicit OK` |26| Time scale | Characteristic time | `1e-3 s` |2728## Decision Guidance2930### Choosing an Integrator3132```33Is the problem stiff?34├── YES → Is Jacobian available?35│ ├── YES → Use Rosenbrock or BDF36│ └── NO → Use BDF with numerical Jacobian37└── NO → Is high accuracy needed?38 ├── YES → Use RK45 or DOP85339 └── NO → Use RK4 or Adams-Bashforth40```4142### Stiff vs Non-Stiff Detection4344| Symptom | Likely Stiff | Action |45|---------|--------------|--------|46| dt shrinks to tiny values | Yes | Switch to implicit |47| Eigenvalues span many decades | Yes | Use BDF/Radau |48| Smooth solution, reasonable dt | No | Stay explicit |4950## Script Outputs (JSON Fields)5152| Script | Key Outputs |53|--------|-------------|54| `scripts/error_norm.py` | `error_norm`, `scale_min`, `scale_max` |55| `scripts/adaptive_step_controller.py` | `accept`, `dt_next`, `factor` |56| `scripts/integrator_selector.py` | `recommended`, `alternatives`, `notes` |57| `scripts/imex_split_planner.py` | `implicit_terms`, `explicit_terms`, `splitting_strategy` |58| `scripts/splitting_error_estimator.py` | `error_estimate`, `substeps` |5960## Workflow61621. **Classify stiffness** - Check eigenvalue spread or use stiffness_detector632. **Choose tolerances** - See `references/tolerance_guidelines.md`643. **Select integrator** - Run `scripts/integrator_selector.py`654. **Compute error norms** - Use `scripts/error_norm.py` for step acceptance665. **Adapt step size** - Use `scripts/adaptive_step_controller.py`676. **Plan IMEX/splitting** - If mixed stiff/nonstiff, use `scripts/imex_split_planner.py`687. **Validate convergence** - Repeat with tighter tolerances6970## Conversational Workflow Example7172**User**: I'm solving the Allen-Cahn equation with a stiff double-well potential. What integrator should I use?7374**Agent workflow**:751. Check integrator options:76 ```bash77 python3 scripts/integrator_selector.py --stiff --jacobian-available --accuracy high --json78 ```792. Plan the IMEX splitting (diffusion implicit, reaction explicit):80 ```bash81 python3 scripts/imex_split_planner.py --stiff-terms diffusion --nonstiff-terms reaction --coupling weak --json82 ```833. Recommend: Use IMEX-BDF2 with diffusion term implicit, double-well reaction explicit.8485## Pre-Integration Checklist8687- [ ] Identify stiffness and dominant time scales88- [ ] Set `rtol`/`atol` consistent with physics and units89- [ ] Confirm integrator compatibility with stiffness90- [ ] Use error norm to accept/reject steps91- [ ] Verify convergence with tighter tolerance run9293## CLI Examples9495```bash96# Select integrator for stiff problem with Jacobian97python3 scripts/integrator_selector.py --stiff --jacobian-available --accuracy high --json9899# Compute scaled error norm100python3 scripts/error_norm.py --error 0.01,0.02 --solution 1.0,2.0 --rtol 1e-3 --atol 1e-6 --json101102# Adaptive step control with PI controller103python3 scripts/adaptive_step_controller.py --dt 1e-2 --error-norm 0.8 --order 4 --controller pi --json104105# Plan IMEX splitting106python3 scripts/imex_split_planner.py --stiff-terms diffusion,elastic --nonstiff-terms reaction --coupling strong --json107108# Estimate splitting error109python3 scripts/splitting_error_estimator.py --dt 1e-4 --scheme strang --commutator-norm 50 --target-error 1e-6 --json110```111112## Error Handling113114| Error | Cause | Resolution |115|-------|-------|------------|116| `rtol must be a non-negative finite number` / `atol must be a non-negative finite number` | Invalid tolerances | Use non-negative finite values |117| `error_norm must be finite and non-negative` | Negative or non-finite error norm | Check error computation |118| `scale must be positive; with min_scale=0 ensure atol>0 or rtol*\|y\|>0` | All scale entries collapsed to 0 (e.g. `rtol=0`, `atol=0`, default `min_scale=0`) | Set `atol>0`, `rtol>0`, or `--min-scale` > 0 |119| `argument --controller: invalid choice: ... (choose from p, pi)` | Invalid controller type | Use `p` or `pi` |120| `Provide at least one stiff or non-stiff term` | Empty term list | Specify stiff or nonstiff terms |121122## Interpretation Guidance123124### Error Norm Values125126| Error Norm | Meaning | Action |127|------------|---------|--------|128| < 1.0 | Step acceptable | Accept, maybe increase dt |129| ≈ 1.0 | At tolerance boundary | Accept with current dt |130| > 1.0 | Step rejected | Reject, reduce dt |131132### Controller Selection133134| Controller | CLI value | Properties | Best For |135|------------|-----------|------------|----------|136| P (elementary / integral) | `p` (default) | Simple, some overshoot | Non-stiff, moderate accuracy |137| PI (proportional-integral) | `pi` | Smooth, robust (requires `--prev-error`) | General use |138139> PID control is described in `references/error_control.md` for reference only; the140> `adaptive_step_controller.py` CLI implements `p` and `pi` controllers.141142### IMEX Strategy143144| Coupling | Strategy |145|----------|----------|146| Weak | Simple operator splitting |147| Moderate | Strang splitting |148| Strong | Fully coupled IMEX-RK |149150## Verification checklist151152- [ ] Recorded the scaled `error_norm` (and `scale_min`/`scale_max`) from `scripts/error_norm.py` and confirmed `scale_min > 0`, so no component reduced to atol-only scaling by accident.153- [ ] Confirmed each accepted step has `error_norm <= accept_threshold` (default 1.0) per `scripts/adaptive_step_controller.py`; logged any `accept: false` steps and the resulting `dt_next`/`factor` rather than forcing the step through.154- [ ] For the PI controller, supplied `--prev-error` and verified `controller_used` reported `pi` (not the silent `p` fallback that occurs when `--prev-error` is omitted).155- [ ] Ran `scripts/integrator_selector.py` with the actual `--stiff`/`--jacobian-available`/`--accuracy` flags matching the problem and recorded `recommended` plus the `notes` (e.g. the "expect smaller dt" warning for stiff-without-implicit).156- [ ] For operator splitting, recorded `error_estimate`, `substeps`, and `dt_effective` from `scripts/splitting_error_estimator.py` and confirmed `error_estimate <= target-error` after substepping, using the correct `--scheme` order (lie=1, strang=2).157- [ ] Ran the convergence validation (Workflow step 7): repeated with tighter `rtol`/`atol` and confirmed the solution change is below the target accuracy, rather than trusting a single tolerance run.158159## Common pitfalls & rationalizations160161| Tempting shortcut | Why it's wrong / what to do |162|-------------------|-----------------------------|163| "I picked an implicit/BDF method, so any `dt` is fine." | Unconditional *stability* is not *accuracy*; large `dt` still inflates temporal error. Check `error_norm` against the accept threshold and run the tighter-tolerance convergence check (Workflow step 7). |164| "`error_norm` came back < 1, so the step and the whole run are correct." | The norm only certifies the local step under the chosen `rtol`/`atol`. A loose tolerance passes every step while the global solution is wrong — tighten tolerances and confirm convergence before trusting results. |165| "I'll use the PI controller for smoother stepping" but omit `--prev-error`. | Without `--prev-error` the script silently falls back to the P controller (`controller_used: p`). You get no PI benefit. Pass the previous accepted `error_norm` and verify `controller_used: pi`. |166| "Strang vs Lie splitting won't matter much here." | Splitting error scales as `commutator_norm * dt^(order+1)` with order 1 (lie) vs 2 (strang). For a nonzero commutator the schemes differ by a full power of `dt` — run `splitting_error_estimator.py` with the actual `--commutator-norm` and `--target-error` instead of guessing. |167| "The selector recommended IMEX/RK-Chebyshev, so I'll just run explicitly without a Jacobian." | That branch fires only for stiff problems *without* implicit solves and the script warns "expect smaller dt." Read the `notes`: provide a Jacobian/Jv product and use BDF/Radau if implicit solves are feasible. |168| "It ran to the final time without crashing, so the integration is valid." | Completion is not correctness. Verify step acceptance (`error_norm <= threshold`), splitting error within `target-error`, and convergence under tighter tolerances; for conservative problems pass `--conservative` to `imex_split_planner.py` and check conserved quantities. |169170## Security171172### Input Validation173- All numeric inputs (`dt`, `rtol`, `atol`, `error_norm`, `stiffness_ratio`, `commutator_norm`, etc.) are validated as finite numbers at the function boundary174- `imex_split_planner.py` validates term names against `[a-zA-Z_][a-zA-Z0-9_ -]*` with length and count limits, preventing injection payloads in user-supplied term lists175- Comma-separated value lists are capped at 100,000 entries to prevent resource exhaustion176- Numeric bounds enforced: `dimension` capped at 10 billion, `order` at 20, `stiffness_ratio` at 1e30177- `--controller` is validated against a fixed allowlist (`p`, `pi`)178- `--scheme` is validated against known splitting schemes (`lie`, `strang`)179180### File Access181- Scripts read no external files; all inputs are provided via CLI arguments182- Scripts write only to stdout (JSON output); no files are created unless the agent explicitly uses the Write tool183184### Tool Restrictions185- **Read**: Used to inspect script source, references, and user configuration files186- **Write**: Used to save integrator recommendations or splitting plans; writes are scoped to the user's working directory187- **Grep/Glob**: Used to locate relevant files and search references188- The skill's `allowed-tools` excludes `Bash` to prevent the agent from executing arbitrary commands when processing user-provided inputs189190### Safety Measures191- No `eval()`, `exec()`, or dynamic code generation192- All subprocess calls use explicit argument lists (no `shell=True`)193- Reduced tool surface (no Bash) limits the agent to read/write operations only194- Term names are sanitized before use, preventing shell metacharacter injection195196## Limitations197198- **No automatic stiffness detection**: Use stiffness_detector from numerical-stability199- **Splitting assumes separability**: Terms must be cleanly separable200- **Jacobian requirement**: Some methods need analytical or numerical Jacobian201202## References203204- `references/method_catalog.md` - Integrator options and properties205- `references/tolerance_guidelines.md` - Choosing rtol/atol206- `references/error_control.md` - Error norm and adaptation formulas207- `references/imex_guidelines.md` - Stiff/non-stiff splitting208- `references/splitting_catalog.md` - Operator splitting patterns209- `references/multiphase_field_patterns.md` - Phase-field specific splits210211## Version History212213- **v1.2.2** (2026-06-24): Added Verification checklist and Common pitfalls & rationalizations sections grounding step acceptance, PI controller usage, integrator selection, and splitting-error checks in the scripts' actual outputs214- **v1.2.0** (2026-06-23): Fixed PI controller coefficient/sign to standard form, fixed error_norm scale-collapse crash, corrected error-message and controller documentation to match the scripts215- **v1.1.0** (2024-12-24): Enhanced documentation, decision guidance, examples216- **v1.0.0**: Initial release with 5 integration scripts