Skip to content

Handling simulation outputs

In this tutorial we will explore the outputs of a simulation for interesting tasks:

  • Plot voltage and current curves

  • Plot overpotentials

  • Plot cell states in space and time

  • Save outputs

  • Load outputs.

Lets start with loading some pre-defined cell parameters, cycling protocols, and running a simulation.

julia
using BattMo, GLMakie

cell_parameters = load_cell_parameters(; from_default_set = "chen_2020")
cycling_protocol = load_cycling_protocol(; from_default_set = "cc_discharge")

model = LithiumIonBattery()

sim = Simulation(model, cell_parameters, cycling_protocol);

output = solve(sim);
✔️ Validation of ModelSettings passed: No issues found.
──────────────────────────────────────────────────
✔️ Validation of CellParameters passed: No issues found.
──────────────────────────────────────────────────
✔️ Validation of CyclingProtocol passed: No issues found.
──────────────────────────────────────────────────
✔️ Validation of SimulationSettings passed: No issues found.
──────────────────────────────────────────────────
✔️ Validation of SolverSettings passed: No issues found.
──────────────────────────────────────────────────
Jutul: Simulating 2 hours, 12 minutes as 163 report steps
╭────────────────┬───────────┬───────────────┬──────────╮
 Iteration type   Avg/step   Avg/ministep     Total 
 146 steps  146 ministeps  (wasted) 
├────────────────┼───────────┼───────────────┼──────────┤
 Newton         │   2.32192 │       2.32192 │  339 (0) │
 Linearization  │   3.32192 │       3.32192 │  485 (0) │
 Linear solver  │   2.32192 │       2.32192 │  339 (0) │
 Precond apply  │       0.0 │           0.0 │    0 (0) │
╰────────────────┴───────────┴───────────────┴──────────╯
╭───────────────┬────────┬────────────┬──────────╮
 Timing type      Each    Relative     Total 
     ms  Percentage        ms 
├───────────────┼────────┼────────────┼──────────┤
 Properties    │ 0.0440 │     2.40 % │  14.9223 │
 Equations     │ 0.6422 │    50.13 % │ 311.4450 │
 Assembly      │ 0.2640 │    20.61 % │ 128.0189 │
 Linear solve  │ 0.2783 │    15.18 % │  94.3281 │
 Linear setup  │ 0.0000 │     0.00 % │   0.0000 │
 Precond apply │ 0.0000 │     0.00 % │   0.0000 │
 Update        │ 0.0555 │     3.03 % │  18.8062 │
 Convergence   │ 0.0753 │     5.88 % │  36.5324 │
 Input/Output  │ 0.0296 │     0.70 % │   4.3196 │
 Other         │ 0.0379 │     2.07 % │  12.8584 │
├───────────────┼────────┼────────────┼──────────┤
 Total         │ 1.8325 │   100.00 % │ 621.2308 │
╰───────────────┴────────┴────────────┴──────────╯

Now we'll have a look into what the output entail. The ouput is of type SimulationOutput and contains multiple output quantity dicts, the full input dict and some other structures. Lets print the properties of the SimulationOutput.

julia
propertynames(output)
(:time_series, :states, :metrics, :input, :jutul_output, :model, :simulation)

In terms of simulation results, we can see that the output structure includes time series data, states data and metrics data. Furthermore, it includes the full input dict, some output structure from Jutul, the model instance, and the simulation instance. Let's for now have a look into the simulation results and see how we can access certain output quantities.

In BattMo, we make a distinction between three types of results:

  • time series: includes all quantities that only depend on time. For example, time itself, cell voltage, current, capacity, etc.

  • states: includes all the state quantities like for example, concentration, potential, charge, etc. These quantities can depend on time, position, and radius.

  • metrics: includes all the from output quantities calculated cell metrics like discharge capacity, charge energy, round trip efficiency, etc. These metrics depend on the cycle number.

The have an overview of all the quantities that are available you can run:

julia
print_info(output)

Case: TIME_SERIES
================================================================================================================================================================
Variable                                                         Unit                          Shape
----------------------------------------------------------------------------------------------------------------------------------------------------------------
CumulativeCapacity                                               Ah                            (nTime,)
Current                                                          A                             (nTime,)
CycleNumber                                                      1                             (nTime,)
NetCapacity                                                      Ah                            (nTime,)
Time                                                             s                             (nTime,)
Voltage                                                          V                             (nTime,)
================================================================================================================================================================

Case: METRICS
================================================================================================================================================================
Variable                                                         Unit                          Shape
----------------------------------------------------------------------------------------------------------------------------------------------------------------
ChargeCapacity                                                   Ah                            (nCycleIndex,)
ChargeEnergy                                                     J                             (nCycleIndex,)
CycleIndex                                                       1                             (nCycleIndex,)
DischargeCapacity                                                Ah                            (nCycleIndex,)
DischargeEnergy                                                  J                             (nCycleIndex,)
RoundTripEfficiency                                              %                             (nCycleIndex,)
================================================================================================================================================================

Case: STATES
================================================================================================================================================================
Variable                                                         Unit                          Shape
----------------------------------------------------------------------------------------------------------------------------------------------------------------
ElectrolyteCharge                                                C                             (nTime, nPosition)
ElectrolyteConcentration                                         mol·m⁻³                       (nTime, nPosition)
ElectrolyteConductivity                                          S·m⁻¹                         (nTime, nPosition)
ElectrolyteDiffusivity                                           m²·s                          (nTime, nPosition)
ElectrolyteMass                                                  g                             (nTime, nPosition)
ElectrolytePotential                                             V                             (nTime, nPosition)
NegativeElectrodeActiveMaterialCharge                            C                             (nTime, nPosition)
NegativeElectrodeActiveMaterialDiffusionCoefficient              m²·s⁻¹                        (nTime, nPosition)
NegativeElectrodeActiveMaterialOpenCircuitPotential              mol·m⁻²·s⁻¹                   (nTime, nPosition)
NegativeElectrodeActiveMaterialParticleConcentration             mol·L⁻¹                       (nTime, nPosition, nNegativeElectrodeActiveMaterialRadius)
NegativeElectrodeActiveMaterialPotential                         V                             (nTime, nPosition)
NegativeElectrodeActiveMaterialRadius                            m                             (nNegativeElectrodeActiveMaterialRadius,)
NegativeElectrodeActiveMaterialReactionRateConstant              V                             (nTime, nPosition)
NegativeElectrodeActiveMaterialSurfaceConcentration              mol·L⁻¹                       (nTime, nPosition)
NegativeElectrodeActiveMaterialTemperature                       T                             (nTime, nPosition)
Position                                                         m                             (nPosition,)
PositiveElectrodeActiveMaterialCharge                            C                             (nTime, nPosition)
PositiveElectrodeActiveMaterialDiffusionCoefficient              m²·s⁻¹                        (nTime, nPosition)
PositiveElectrodeActiveMaterialOpenCircuitPotential              V                             (nTime, nPosition)
PositiveElectrodeActiveMaterialParticleConcentration             mol·L⁻¹                       (nTime, nPosition, nPositiveElectrodeActiveMaterialRadius)
PositiveElectrodeActiveMaterialPotential                         V                             (nTime, nPosition)
PositiveElectrodeActiveMaterialRadius                            m                             (nPositiveElectrodeActiveMaterialRadius,)
PositiveElectrodeActiveMaterialReactionRateConstant              mol·m⁻²·s⁻¹                   (nTime, nPosition)
PositiveElectrodeActiveMaterialSurfaceConcentration              mol·L⁻¹                       (nTime, nPosition)
PositiveElectrodeActiveMaterialTemperature                       T                             (nTime, nPosition)
================================================================================================================================================================

To get more information on particular output variables, for example all that have concentration in their name:

julia
print_info("concentration", view = "OutputVariable")

----------------------------------------------------------------------------------------------------
📈  Output Variable:  NegativeElectrodeActiveMaterialSurfaceConcentration
----------------------------------------------------------------------------------------------------
    🔹 Name               NegativeElectrodeActiveMaterialSurfaceConcentration
    🔹 Category           OutputVariable
    🔹 Description        Concentration of lithium ions at the surface of negative electrode particles.
    🔹 Type               Vector{Real}
    🔹 Shape              (nTime, nPosition)
    🔹 Unit               mol·L⁻¹

----------------------------------------------------------------------------------------------------
📈  Output Variable:  PositiveElectrodeActiveMaterialParticleConcentration
----------------------------------------------------------------------------------------------------
    🔹 Name               PositiveElectrodeActiveMaterialParticleConcentration
    🔹 Category           OutputVariable
    🔹 Description        Radial distribution of lithium concentration in positive electrode particles.
    🔹 Type               Vector{Real}
    🔹 Shape              (nTime, nPosition, nPositiveElectrodeActiveMaterialRadius)
    🔹 Unit               mol·L⁻¹

----------------------------------------------------------------------------------------------------
📈  Output Variable:  ElectrolyteConcentration
----------------------------------------------------------------------------------------------------
    🔹 Name               ElectrolyteConcentration
    🔹 Category           OutputVariable
    🔹 Description        Concentration of lithium ions in the electrolyte.
    🔹 Type               Vector{Real}
    🔹 Shape              (nTime, nPosition)
    🔹 Unit               mol·m⁻³

----------------------------------------------------------------------------------------------------
📈  Output Variable:  PositiveElectrodeActiveMaterialSurfaceConcentration
----------------------------------------------------------------------------------------------------
    🔹 Name               PositiveElectrodeActiveMaterialSurfaceConcentration
    🔹 Category           OutputVariable
    🔹 Description        Concentration of lithium ions at the surface of positive electrode particles.
    🔹 Type               Vector{Real}
    🔹 Shape              (nTime, nPosition)
    🔹 Unit               mol·L⁻¹

----------------------------------------------------------------------------------------------------
📈  Output Variable:  NegativeElectrodeActiveMaterialParticleConcentration
----------------------------------------------------------------------------------------------------
    🔹 Name               NegativeElectrodeActiveMaterialParticleConcentration
    🔹 Category           OutputVariable
    🔹 Description        Radial distribution of lithium concentration in negative electrode particles.
    🔹 Type               Vector{Real}
    🔹 Shape              (nTime, nPosition, nNegativeElectrodeActiveMaterialRadius)
    🔹 Unit               mol·L⁻¹

========================================================================================================================

As the time series, states, and metrics structures are dicts we can retrieve quantities by accessing their key. Let's for example create a simple voltage vs capacity plot.

julia
voltage = output.time_series["Voltage"]
capacity = output.time_series["CumulativeCapacity"]

fig = Figure()
ax = Axis(fig[1, 1], ylabel = "Voltage / V", xlabel = "Capacity / Ah", title = "Discharge curve")
lines!(ax, capacity, voltage)
display(fig)
GLMakie.Screen(...)

Or lets plot the lithium concentration versus the active material particle radius of the positive electrode close to the separator at the and of the discharge:

julia
radius = output.states["PositiveElectrodeActiveMaterialRadius"]
positive_electrode_concentration = output.states["PositiveElectrodeActiveMaterialParticleConcentration"]

simulation_settings = output.input["SimulationSettings"] # Retrieve the default simulation settings to get the grid point number that we need.

grid_point = simulation_settings["NegativeElectrodeCoatingGridPoints"] + simulation_settings["SeparatorGridPoints"] + 1 # First grid point of the positive electrode

concentration_at_grid_point = positive_electrode_concentration[end, grid_point, :]

fig = Figure()
ax = Axis(fig[1, 1], ylabel = "Lithium concentration / mol·L⁻¹", xlabel = "Particle radius / m", title = "Positive electrode concentration")
lines!(ax, radius, concentration_at_grid_point)
display(fig)
GLMakie.Screen(...)

Example on GitHub

If you would like to run this example yourself, it can be downloaded from the BattMo.jl GitHub repository as a script.


This page was generated using Literate.jl.