BattMo.jl is a framework for continuum modelling of lithium-ion batteries written in Julia

The Battery Modelling Toolbox (BattMo) is a resource for continuum modelling of electrochemical devices in MATLAB. The initial development features a pseudo X-dimensional (PXD) framework for the Doyle-Fuller-Newman model of lithium-ion battery cells. This is currently a early release that implements a subset of features from the MATLAB version of BattMo with improved numerical performance. BattMo.jl is based on Jutul.jl and uses finite-volume discretizations and automatic differentiation to simulate models in 1D, 2D and 3D.

The current implementation has two options for setting up simulation cases:

  • You can read in input data prepared in the MATLAB version of BattMo (general 3D grids)
  • Or you can use the common BattMo JSON format to run cases (primarily 1D grids)


This package is registered in the General Julia registry. To add it to your Julia environment, open Julia and run

using Pkg; Pkg.add("BattMo")

Getting started

For an example of usage, you can add the GLMakie plotting package:

using Pkg

You can then run the following to simulate the predefined p2d_40 case:

using BattMo
# Simulate case
states, reports, extra, exported = run_battery("p2d_40");
# Plot result
using GLMakie
voltage = map(state -> state[:BPP][:Phi][1], states)
t = cumsum(extra[:timesteps])
fig = Figure()
ax = Axis(fig[1, 1], ylabel = "Voltage / V", xlabel = "Time / s", title = "Discharge curve")
lines!(ax, t, voltage)

This should produce the following plot: Discharge curve

3D simulation example

This example uses plotting from Jutul, so we need to add that package to our environment.

using Pkg

Run a 3D model and plot the results in an interactive viewer.

using BattMo
# Simulate case
states, reports, extra, exported = run_battery("3d_demo_case");
# Parts of the battery overlap in physical space - shift them a bit and plot
# with Jutul's interactive GLMakie plotting viewer.
using GLMakie
using Jutul
dx = [0.02 0 0]
shift = Dict()
shift[:NAM] = dx
shift[:PAM] = dx
shift[:CC] = dx
shift[:PP] = dx
plot_multimodel_interactive(extra[:model], states, shift = shift, colormap = :curl)

3D plot


BattMo has received funding from the European Union’s Horizon 2020 innovation program under grant agreement numbers:

  • 875527 HYDRA
  • 957189 BIG-MAP