Note
This notebook is already available in your BattMo installation. In Matlab, run
open exploreOutput
Simulation Output Structure
We load some simulation input data and run the simulation. We obtain an output structure in return.
[1]:
jsonstruct = parseBattmoJson('Examples/Documentation/jsonfiles/explore_output_example.json');
output = runBattery(jsonstruct);
Output structure overview
The output structure contains the results of the simulation, the simulation model and the simulation setup. We have in particular the following
output.model: The simulation modeloutput.simsetup: The simulation setupoutput.jsonstruct: The json input fileoutput.time: Time structure of the resultsoutput.E: Voltage for each time stepoutput.I: Current for each time stepoutput.states: The states structure with the internal state of the battery for each time step
Current and Voltage
The readily available results are the current and voltage with the corresponding time structure
[2]:
time = output.time;
E = output.E;
I = output.I;
figure
subplot(2,1,1)
plot(time/hour, E);
grid on
xlabel 'time / h';
ylabel 'potential / V';
subplot(2,1,2)
plot(time/hour, I);
grid on
xlabel 'time / h';
ylabel 'Current / I';
[2]:
Simulation Model
The simulation model is an output of the simulation.
[3]:
model = output.model;
We can use it to plot the battery model, using the dedicated function plotBatteryGrid.
[4]:
plotBatteryGrid(model);
[4]:
Battery States
The states give us insight into the internal state of the battery for each time step.
[5]:
states = output.states;
The states are stored in a cell array. The index is the same as the time output. For a given state, the data is stored following the same architecture as the overall battery model, see here
Let us consider the state computed at the last time step.
[6]:
state = states{end}
[6]:
state = struct with fields:
NegativeElectrode: [1x1 struct]
PositiveElectrode: [1x1 struct]
Electrolyte: [1x1 struct]
ThermalModel: [1x1 struct]
Control: [1x1 struct]
time: 3.5517e+03
We obtain the following variable, which are (except time and control type) the state or primary variables. They correspond to the unknowns in the modeling equations we solve. It is possible to recover also the intermediate variables as illustrated below.
state.NegativeElectrode.Coating.ActiveMaterial.SolidDiffusion.cSurfacestate.NegativeElectrode.Coating.ActiveMaterial.SolidDiffusion.cstate.NegativeElectrode.Coating.phistate.NegativeElectrode.CurrentCollector.phistate.PositiveElectrode.Coating.ActiveMaterial.SolidDiffusion.cSurfacestate.PositiveElectrode.Coating.ActiveMaterial.SolidDiffusion.cstate.PositiveElectrode.Coating.phistate.PositiveElectrode.CurrentCollector.scaledDeltaPhistate.Electrolyte.phistate.Electrolyte.cstate.ThermalModel.Tstate.Control.Estate.Control.Istate.Control.ctrlTypestate.time
Let us plot the concentration in the electrolyte. The units are always defaulted to SI units. Note also the difference of scale for the different spatial directions.
[7]:
figure
plotCellData(model.Electrolyte.grid, state.Electrolyte.c);
colorbar
view([50, 40]);
[7]:
Simulation Setup
The simulation setup contains all the information to re-run a simulation. It means the model, of course, but also the initial state, the schedule (time stepping choices) and the solver parameters.
[8]:
simsetup = output.simsetup();
states = simsetup.run();
Json Input
The jsonstruct that is returned in the output is the same as the one we sent as input but it is augmented with all the default values
full set of state variables
In the simulation, intermediate variables are computed to assemble the equations. They can be relevant to explore your solution. They are not included by default because they require extra time to be computed. If you are interested in those, you can add the following entry in your json input structure
[9]:
jsonstruct.Output.includeIntermediateVariables = true;
output = runBattery(jsonstruct);
It is also possible to do the same manually after the simulation
[10]:
for istate = 1 : numel(states)
states{istate} = model.addVariables(states{istate});
end
For example, for the negative electrode interface, we get the following variables, among which the OCP and the intercalation flux, which is the reaction rate of Lithium intercalation (mol/m^2/s).
[11]:
state = states{end};
disp(state.NegativeElectrode.Coating.ActiveMaterial.Interface)
[11]:
phiElectrode: [300x1 double]
cElectrodeSurface: [300x1 double]
phiElectrolyte: [300x1 double]
cElectrolyte: [300x1 double]
OCP0: [300x1 double]
T: [300x1 double]
OCP: [300x1 double]
eta: [300x1 double]
j0: [300x1 double]
intercalationFlux: [300x1 double]