Skip to content

Repository files navigation

PathSim-Batt Logo

Battery simulation blocks for PathSim

PyPILicense

DocumentationPathSim HomepageGitHub


PathSim-Batt extends the PathSim simulation framework with battery cell blocks backed by PyBaMM. All blocks follow the standard PathSim interface and can be wired into any simulation diagram.

Install

pip install pathsim-batt

Quick start

importpybammfrompathsimimportConnection, Simulationfrompathsim.blocksimportConstantfrompathsim.solversimportESDIRK43frompathsim_battimportCellElectrothermalcell=CellElectrothermal(initial_soc=1.0) # defaults: SPMe + Chen2020I_src=Constant(5.0) # 5 A dischargeT_src=Constant(298.15) # 25 °C ambientsim=Simulation(
blocks=[I_src, T_src, cell],
connections=[Connection(I_src, cell["I"]), Connection(T_src, cell["T_amb"])],
dt=1.0,
Solver=ESDIRK43,
)
sim.run(3600)
print(f"V = {cell.outputs[0]:.3f} V T = {cell.outputs[1]:.1f} K SOC = {cell.outputs[3]:.3f}")

Choosing a block

Two decisions determine the right block: thermal ownership and integration strategy.

BlockThermalStrategyUse when
CellElectrothermalPyBaMM (internal)Monolithic ODESingle cell, coupled electro-thermal, ODE model
CellElectrical + LumpedThermalPathSim (external)Monolithic ODEPack-level, custom cooling, ODE model
CellCoSimElectrothermalPyBaMM (internal)Co-simulationDAE models (DFN, lead_acid.Full), mixed solvers
CellCoSimElectrical + LumpedThermalPathSim (external)Co-simulationDAE models with external thermal network

LumpedThermal is a single-node thermal block (mass, Cp, UA, T0) that receives Q_dot from a CellElectrical block and feeds back cell temperature.

PyBaMM model compatibility

Thermal sub-model and heat-source options are injected automatically — pass the bare model class with no options=.

PyBaMM modelDefault parameter setCellElectricalCellElectrothermalCellCoSimElectricalCellCoSimElectrothermal
lithium_ion.SPMChen2020
lithium_ion.SPMeChen2020
lithium_ion.DFNChen2020❌ DAE❌ DAE
lead_acid.LOQSSulzer2019✅ ¹✅ ¹✅ ²✅ ²
lead_acid.FullSulzer2019❌ DAE❌ DAE
equivalent_circuit.TheveninECM_Example✅ ³✅ ³

¹ PyBaMM < 26.7 only — from 26.7 on LOQS is a DAE, use a CellCoSim* block instead.

² PyBaMM < 26.7 only — pass pybamm_solver=pybamm.CasadiSolver(mode="safe"); the default IDAKLUSolver errors on LOQS. Fixed in 26.7.

³ initial_soc=1.0 fails because PyBaMM requires event values to be strictly positive at t=0; the "Maximum SoC" event is zero exactly at full charge. Any value below 1.0 (e.g. initial_soc=0.99) works.

importpybammfrompathsim_battimportCellElectrothermal, CellCoSimElectrical# Custom chemistry / parameter setcell=CellElectrothermal(
model=pybamm.lithium_ion.SPMe(),
parameter_values=pybamm.ParameterValues("Mohtat2020"),
)
# Lead-acid via co-simulation (DAE model)cell=CellCoSimElectrical(
model=pybamm.lead_acid.Full(),
parameter_values=pybamm.ParameterValues("Sulzer2019"),
dt=1.0,
)
# Equivalent circuit modelcell=CellElectrical(
model=pybamm.equivalent_circuit.Thevenin(),
parameter_values=pybamm.ParameterValues("ECM_Example"),
initial_soc=0.9,
)

License

MIT

About

Battery toolbox for PathSim

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages