pybamm
它能做什么
这个工具可以模拟锂离子电池在充电、放电和静置过程中的表现,还可以将模拟结果与真实的电池数据进行比较。
适用场景
- ✓模拟电池的充电和放电循环。
- ✓查看电池电压随时间的变化。
- ✓将模拟结果与实际电池测试数据进行对比。
技能链接
https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/pybamm/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请使用 SPM 模型模拟一块锂离子电池的充电、放电和静置过程。额定容量为 5Ah,初始荷电状态(SOC)为 80%,充电和放电均以 0.5C 进行,各持续 600 秒,两者之间静置 120 秒。”
每周 5 个新技能,1 分钟读完。
工作原理
你需要提供电池的相关信息,以及电池的使用方式(即实验方案)。工具会使用名为 PyBaMM 的程序运行模拟并生成结果。如果你提供了真实数据,还可以将结果与之进行比较。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
PyBaMM battery experiments
When to use
Use this skill to model single-cell constant-current charge/discharge and rest, examine voltage and charge trajectories, or compare SPM/DFN predictions to cycling measurements. The helper runs real PyBaMM experiments and three numerical resolutions; it does not control a battery cycler or establish an operating envelope for hardware.
Runtime and tested case
uv venv --python 3.12 battery-env
uv pip install --python battery-env/bin/python pybamm==26.9.0.0 pybammsolvers==0.10.0
This release requires pybammsolvers>=0.10.0, NumPy 2 or newer, and CasADi 3.8.1.
The tested environment used Python 3.12.10, NumPy 2.5.3 and SciPy 1.18.1. IDAKLU is the
recommended solver; CasadiSolver and ScipySolver are deprecated in this release. Refer to
the 26.9.0.0 manual below, since latest can describe unreleased APIs.
The included assets/chen2020-protocol.json is a synthetic isothermal 298.15-K SPM case: 80% initial SOC, discharge at 0.5C for 600 s, rest for 120 s, charge at 0.5C for 600 s. Chen2020 supplies an LG M50 parameterization with 5-Ah nominal capacity; here 0.5C means 2.5 A. This is an executable reference example, not a claim that an arbitrary user's cell has those parameters. The helper disables PyBaMM usage telemetry unless the caller has already explicitly configured that variable.
Workflow
- Establish the cell chemistry, geometry, nominal capacity, initial state, temperature and current-sign convention. Use an appropriate parameter set and explain its source. Distinguish a paper's fitted parameters from measurements of this particular cell. Do not transplant degradation parameters without checking their meaning and applicable conditions.
- Convert the requested protocol to the JSON contract in references/protocol-and-comparison.md. Positive simulation current discharges; negative current charges. Every step has a finite duration. A specified voltage cutoff can end it earlier; the report records actual termination times. C-rates use the selected set's nominal capacity. A change in that capacity changes current.
- Choose SPM when its reduced transport assumptions are adequate; use DFN when resolving electrolyte/electrode transport matters. The helper's tested models are isothermal and exclude aging, mechanics, plating and pack control. Increasing rate can invalidate SPM predictions even if numerical convergence is excellent.
- Run the helper. It validates protocol fields, rejects unknown or overridden-by-protocol parameter inputs, uses IDAKLU, and snapshots the base parameters after SOC initialization. Keep the protocol with that snapshot: experiment steps supply their own currents. Infeasible or skipped steps are errors, rather than silently presenting a partial protocol as complete.
- Read the two numerical comparisons separately: baseline versus tighter tolerances isolates solver error; tight tolerances on the original versus doubled mesh isolates discretization. Compare voltage differences and event-time differences against the accuracy the question needs. Refine again when these are too large; one doubling does not prove convergence.
- If measurements are available, check current, time origin, temperature, SOC and capacity before interpreting residuals. Supply matching seconds, volts and amps. The helper reports voltage RMSE/MAE/bias and current RMSE, preserving residuals. A small voltage error under a mismatched input current does not validate the model. This workflow compares curves; it does not claim to identify unique kinetic parameters from voltage alone.
Run and inspect
From the skill directory, point battery-env/bin/python at the environment created above:
battery-env/bin/python scripts/simulate_battery.py assets/chen2020-protocol.json \
--output battery-reference
# measured.csv is user data with time_s,voltage_V,current_A columns.
battery-env/bin/python scripts/simulate_battery.py protocol.json \
--measured measured.csv --mesh-points 30 --output battery-comparison
The first command was executed as written with an external output location. The second uses illustrative user filenames; the measurement path was exercised against a frozen synthetic reference curve in the tests. Output directories must be new.
| Artifact | Interpretation |
|---|
…
常见问题
SPM 和 DFN 是什么?
SPM 和 DFN 是两种用于模拟电池行为的数学模型。SPM 比较简单、速度更快,而 DFN 更加详细,在某些情况下更为准确。
“C-rate”是什么?
C-rate 表示电池充电或放电的速度,相对于其总容量而言。例如,对于 5Ah 的电池,1C 对应的电流为 5A。
我可以用它来控制真实的电池吗?
不可以,这个工具仅用于模拟和分析,无法直接控制电池硬件。
详情
作者的原始描述
Simulates lithium-ion battery charge, discharge and rest experiments with PyBaMM, records parameter-set provenance, checks mesh and solver sensitivity, and compares predicted voltage curves with measured cycling data. Use for SPM or DFN electrochemical battery modeling, C-rate protocols, voltage cutoffs, parameter studies and numerical validation of battery simulations.
热度
- GitHub 星标
- 51k
- 排名
- #3536
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …