Numerical Integration 标志

Numerical Integration

社区
HeshamFS
numerical-integration

为 ODE 和 PDE 模拟选择并配置时间积分方法:在显式 Runge-Kutta、BDF、Rosenbrock 和 Adams 系列方法中进行选择,设置相对和绝对误差容限,使用 P/PI 步长控制器实现自适应步长控制,为混合刚性与非刚性项规划 IMEX 算子分裂,并估算分裂误差。适用于为新模拟选择积分器、诊断步长被拒或容限不满足的问题、为相场或反应扩散问题设置算子分裂,或在显式和隐式时间推进之间进行选择;即使用户只说“求解器一直拒绝步长”或“我该用哪种 ODE 方法?”也适用。

Add to TypingMind

概览

发布者HeshamFS
代码仓库materials-simulation-skills
技能名称numerical-integration
星标数
83
复刻数
6
附带文件
13
许可协议Apache-2.0
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 13 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 HeshamFS 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Numerical Integration AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/HeshamFS/materials-simulation-skills/tree/main/skills/core-numerical/numerical-integration
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

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/numerical-integration .claude/skills/numerical-integration
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Numerical Integration,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Numerical Integration。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Numerical Integration 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Numerical Integration

Goal

Provide a reliable workflow to select integrators, set tolerances, and manage adaptive time stepping for time-dependent simulations.

Requirements

  • Python 3.10+
  • NumPy (for some scripts)
  • No heavy dependencies for core functionality

Inputs to Gather

InputDescriptionExample
Problem typeODE/PDE, stiff/non-stiffstiff PDE
Jacobian availableCan compute ∂f/∂u?yes
Target accuracyDesired error level1e-6
ConstraintsMemory, implicit allowed?implicit OK
Time scaleCharacteristic time1e-3 s

Decision Guidance

Choosing an Integrator

Is the problem stiff?
├── YES → Is Jacobian available?
│   ├── YES → Use Rosenbrock or BDF
│   └── NO → Use BDF with numerical Jacobian
└── NO → Is high accuracy needed?
    ├── YES → Use RK45 or DOP853
    └── NO → Use RK4 or Adams-Bashforth

Stiff vs Non-Stiff Detection

SymptomLikely StiffAction
dt shrinks to tiny valuesYesSwitch to implicit
Eigenvalues span many decadesYesUse BDF/Radau
Smooth solution, reasonable dtNoStay explicit

Script Outputs (JSON Fields)

ScriptKey Outputs
scripts/error_norm.pyerror_norm, scale_min, scale_max
scripts/adaptive_step_controller.pyaccept, dt_next, factor
scripts/integrator_selector.pyrecommended, alternatives, notes
scripts/imex_split_planner.pyimplicit_terms, explicit_terms, splitting_strategy
scripts/splitting_error_estimator.pyerror_estimate, substeps

Workflow

  1. Classify stiffness - Check eigenvalue spread or use stiffness_detector
  2. Choose tolerances - See references/tolerance_guidelines.md
  3. Select integrator - Run scripts/integrator_selector.py
  4. Compute error norms - Use scripts/error_norm.py for step acceptance
  5. Adapt step size - Use scripts/adaptive_step_controller.py
  6. Plan IMEX/splitting - If mixed stiff/nonstiff, use scripts/imex_split_planner.py
  7. Validate convergence - Repeat with tighter tolerances

Conversational Workflow Example

User: I'm solving the Allen-Cahn equation with a stiff double-well potential. What integrator should I use?

Agent workflow:

  1. Check integrator options:
    bash
    python3 scripts/integrator_selector.py --stiff --jacobian-available --accuracy high --json
  2. Plan the IMEX splitting (diffusion implicit, reaction explicit):
    bash
    python3 scripts/imex_split_planner.py --stiff-terms diffusion --nonstiff-terms reaction --coupling weak --json
  3. Recommend: Use IMEX-BDF2 with diffusion term implicit, double-well reaction explicit.

Pre-Integration Checklist

  • Identify stiffness and dominant time scales
  • Set rtol/atol consistent with physics and units
  • Confirm integrator compatibility with stiffness
  • Use error norm to accept/reject steps
  • Verify convergence with tighter tolerance run

CLI Examples

bash
# Select integrator for stiff problem with Jacobian
python3 scripts/integrator_selector.py --stiff --jacobian-available --accuracy high --json

# Compute scaled error norm
python3 scripts/error_norm.py --error 0.01,0.02 --solution 1.0,2.0 --rtol 1e-3 --atol 1e-6 --json

# Adaptive step control with PI controller
python3 scripts/adaptive_step_controller.py --dt 1e-2 --error-norm 0.8 --order 4 --controller pi --json

# Plan IMEX splitting
python3 scripts/imex_split_planner.py --stiff-terms diffusion,elastic --nonstiff-terms reaction --coupling strong --json

# Estimate splitting error
python3 scripts/splitting_error_estimator.py --dt 1e-4 --scheme strang --commutator-norm 50 --target-error 1e-6 --json

Error Handling

ErrorCauseResolution
rtol must be a non-negative finite number / atol must be a non-negative finite numberInvalid tolerancesUse non-negative finite values
error_norm must be finite and non-negativeNegative or non-finite error normCheck error computation
scale must be positive; with min_scale=0 ensure atol>0 or rtol*|y|>0All scale entries collapsed to 0 (e.g. rtol=0, atol=0, default min_scale=0)Set atol>0, rtol>0, or --min-scale > 0
argument --controller: invalid choice: ... (choose from p, pi)Invalid controller typeUse p or pi
Provide at least one stiff or non-stiff termEmpty term listSpecify stiff or nonstiff terms

Interpretation Guidance

Error Norm Values

Error NormMeaningAction
< 1.0Step acceptableAccept, maybe increase dt
≈ 1.0At tolerance boundaryAccept with current dt
> 1.0Step rejectedReject, reduce dt

Controller Selection

ControllerCLI valuePropertiesBest For
P (elementary / integral)p (default)Simple, some overshootNon-stiff, moderate accuracy
PI (proportional-integral)piSmooth, robust (requires --prev-error)General use

PID control is described in references/error_control.md for reference only; the adaptive_step_controller.py CLI implements p and pi controllers.

IMEX Strategy

CouplingStrategy
WeakSimple operator splitting
ModerateStrang splitting
StrongFully coupled IMEX-RK

Verification checklist

  • 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.
  • 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.
  • 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).
  • 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).
  • 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).
  • 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.

Common pitfalls & rationalizations

Tempting shortcutWhy it's wrong / what to do
"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).
"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.
"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.
"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.
"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.
"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.

Security

Input Validation

  • All numeric inputs (dt, rtol, atol, error_norm, stiffness_ratio, commutator_norm, etc.) are validated as finite numbers at the function boundary
  • 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 lists
  • Comma-separated value lists are capped at 100,000 entries to prevent resource exhaustion
  • Numeric bounds enforced: dimension capped at 10 billion, order at 20, stiffness_ratio at 1e30
  • --controller is validated against a fixed allowlist (p, pi)
  • --scheme is validated against known splitting schemes (lie, strang)

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
  • Write: Used to save integrator recommendations or splitting plans; writes are scoped to the user's working directory
  • Grep/Glob: Used to locate relevant files and search references
  • The skill's allowed-tools excludes Bash to prevent the agent from executing arbitrary commands when processing user-provided inputs

Safety Measures

  • No eval(), exec(), or dynamic code generation
  • All subprocess calls use explicit argument lists (no shell=True)
  • Reduced tool surface (no Bash) limits the agent to read/write operations only
  • Term names are sanitized before use, preventing shell metacharacter injection

Limitations

  • No automatic stiffness detection: Use stiffness_detector from numerical-stability
  • Splitting assumes separability: Terms must be cleanly separable
  • Jacobian requirement: Some methods need analytical or numerical Jacobian

References

  • references/method_catalog.md - Integrator options and properties
  • references/tolerance_guidelines.md - Choosing rtol/atol
  • references/error_control.md - Error norm and adaptation formulas
  • references/imex_guidelines.md - Stiff/non-stiff splitting
  • references/splitting_catalog.md - Operator splitting patterns
  • references/multiphase_field_patterns.md - Phase-field specific splits

Version History

  • v1.2.3 (2026-10-19): Compute Euclidean error norms without avoidable squaring overflow or underflow.

  • 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 outputs

  • 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 scripts

  • v1.1.0 (2024-12-24): Enhanced documentation, decision guidance, examples

  • v1.0.0: Initial release with 5 integration scripts

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Numerical Integration AI 技能有什么作用?

为 ODE 和 PDE 模拟选择并配置时间积分方法:在显式 Runge-Kutta、BDF、Rosenbrock 和 Adams 系列方法中进行选择,设置相对和绝对误差容限,使用 P/PI 步长控制器实现自适应步长控制,为混合刚性与非刚性项规划 IMEX 算子分裂,并估算分裂误差。适用于为新模拟选择积分器、诊断步长被拒或容限不满足的问题、为相场或反应扩散问题设置算子分裂,或在显式和隐式时间推进之间进行选择;即使用户只说“求解器一直拒绝步长”或“我该用哪种 ODE 方法?”也适用。

为什么在 TypingMind 中使用 Numerical Integration?

因为您只需安装一次,就能搭配任何模型使用。Numerical Integration 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Numerical Integration?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/HeshamFS/materials-simulation-skills/tree/main/skills/core-numerical/numerical-integration。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Numerical Integration?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Numerical Integration 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Numerical Integration 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Numerical Integration AI 技能免费吗?

是的。HeshamFS 已在 GitHub 上根据 Apache-2.0 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇