Tutorial 9 - Simulate a cylindrical cell

Introduction

In this tutorial, we simulate a cylindrical cell. We use the same material property as in the other tutorials
jsonstruct_material = parseBattmoJson('Examples/jsondatafiles/sample_input.json');
Next, we load and parse a json file where we have chosen some parameters for the multilayer pouch domain. Note that all the parameters are described in a json schema, see Geometry.schema.json, even if the simplest way to proceed is to start with an example, in this case given by 4680-geometry.json.
jsonfilename = 'Examples/JsonDataFiles/4680-geometry.json';
jsonstruct_geometry = parseBattmoJson(jsonfilename);
We change some parameters to get a smaller model and simulation time.
jsonstruct_geometry.Geometry.rOuter = jsonstruct_geometry.Geometry.rInner + 4*milli*meter;
jsonstruct_geometry.Geometry.nL = 2;
jsonstruct_geometry.Geometry.nas = 20;
We use FlatJsonViewer.m to flatten the json structure and print it to screen.
fjv = flattenJson(jsonstruct_geometry);
fjv.print();
T = 25×2 table
 parameter nameparameter value
1'include_current_collectors'1
2'Geometry.case''jellyRoll'
3'Geometry.rInner'0.0020
4'Geometry.rOuter'0.0060
5'Geometry.L'0.0700
6'Geometry.nas'20
7'Geometry.nL'2
8'NegativeElectrode.Coating.thickness'9.4000e-05
9'NegativeElectrode.Coating.N'3
10'NegativeElectrode.Coating.SolidDiffusion.N'5
11'NegativeElectrode.CurrentCollector.thickness'2.5000e-05
12'NegativeElectrode.CurrentCollector.N'3
13'NegativeElectrode.CurrentCollector.tabparams.usetab'1
14'NegativeElectrode.CurrentCollector.tabparams.width'0.0035
We load and parse the control protocol
jsonfilename = fullfile('Examples', 'jsondatafiles', 'cc_discharge_control.json');
jsonstruct_control = parseBattmoJson(jsonfilename);
We load and parse the simulation settings. This is optional. Typically, reasonable choices are made by default.
jsonfilename = fullfile('Examples', 'jsondatafiles', 'simulation_parameters.json');
jsonstruct_simparams = parseBattmoJson(jsonfilename);
Now, we can merge these parameter definitions into a single parameter set to obtain a jsonstruct that has all the input needed by the simulator.
jsonstruct = mergeJsonStructs({jsonstruct_geometry , ...
jsonstruct_material , ...
jsonstruct_control , ...
jsonstruct_simparams}, 'warn', false);

Setup the model for inspection

When we run the simulation using function runBatteryJson.m, the model is setup. In the case where we want to setup the model for inspection, prior to simulation, we can use the function setupModelFromJson.m
model = setupModelFromJson(jsonstruct);
We use the plotBatteryGrid.m function to show the grid
plotBatteryGrid(model)
% make the axis tight and set the camera viewing angle
axis tight
view(45,45)

Run the simulation

output = runBatteryJson(jsonstruct);
Solving timestep 01/45: -> 3 Seconds, 937 Milliseconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.128861e-17.
Solving timestep 02/45: 3 Seconds, 937 Milliseconds -> 7 Seconds, 875 Milliseconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.234549e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.394861e-17.
Solving timestep 03/45: 7 Seconds, 875 Milliseconds -> 15 Seconds, 750 Milliseconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.228591e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.083314e-17.
Solving timestep 04/45: 15 Seconds, 750 Milliseconds -> 31 Seconds, 500 Milliseconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.120649e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.086115e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.065573e-17.
Solving timestep 05/45: 31 Seconds, 500 Milliseconds -> 63 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.033616e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.990685e-17.
Solving timestep 06/45: 63 Seconds -> 126 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.011744e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.013179e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.993270e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.000818e-17.
Solving timestep 07/45: 126 Seconds -> 252 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.980465e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.974570e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.976764e-17.
Solving timestep 08/45: 252 Seconds -> 378 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.970595e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.973025e-17.
Solving timestep 09/45: 378 Seconds -> 504 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 10/45: 504 Seconds -> 630 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 11/45: 630 Seconds -> 756 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 12/45: 756 Seconds -> 882 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 13/45: 882 Seconds -> 1008 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 14/45: 1008 Seconds -> 1134 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 15/45: 1134 Seconds -> 1260 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 16/45: 1260 Seconds -> 1386 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 17/45: 1386 Seconds -> 1512 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 18/45: 1512 Seconds -> 1638 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 19/45: 1638 Seconds -> 1764 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 20/45: 1764 Seconds -> 1890 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 21/45: 1890 Seconds -> 2016 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 22/45: 2016 Seconds -> 2142 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 23/45: 2142 Seconds -> 2268 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 24/45: 2268 Seconds -> 2394 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 25/45: 2394 Seconds -> 2520 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 26/45: 2520 Seconds -> 2646 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 27/45: 2646 Seconds -> 2772 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 28/45: 2772 Seconds -> 2898 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 29/45: 2898 Seconds -> 3024 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 30/45: 3024 Seconds -> 3150 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 31/45: 3150 Seconds -> 3276 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.966431e-17.
Solving timestep 32/45: 3276 Seconds -> 3402 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.970718e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.980207e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.980207e-17.
Solver failure after 2 iterations for timestep of length 34 Seconds, 719 Milliseconds. Cutting timestep. Failure reason: Linear system rhs have infinite entries Cutting timestep.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.999222e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.999222e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.999222e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.999222e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.999222e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.999222e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.999222e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.999222e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.999222e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.999222e-17.
Solver did not converge in 10 iterations for timestep of length 17 Seconds, 359 Milliseconds. Cutting timestep.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.037252e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.037252e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.037252e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.037252e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.037252e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.037252e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.037252e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.037252e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 9.520403e-49.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 7.977404e-44.
Solver did not converge in 10 iterations for timestep of length 8 Seconds, 679 Milliseconds. Cutting timestep.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.113312e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.113312e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.100903e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.100903e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.051012e-17.
Warning: Matrix is singular to working precision.
Solver failure after 1 iterations for timestep of length 7 Seconds, 350 Milliseconds. Cutting timestep. Failure reason: Linear solver produced non-finite values. Cutting timestep.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.140832e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.069308e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.069308e-17.
Solver failure after 2 iterations for timestep of length 6 Seconds, 106 Milliseconds. Cutting timestep. Failure reason: Linear system rhs have infinite entries Cutting timestep.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.177424e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.177424e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.177424e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.134177e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.134177e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.068023e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.035361e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.020753e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.021618e-17.
Solving timestep 33/45: 3402 Seconds -> 3528 Seconds
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.019379e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.023172e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.023172e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.023172e-17.
Warning: Matrix is singular to working precision.
Solver failure after 3 iterations for timestep of length 10 Seconds, 651 Milliseconds. Cutting timestep. Failure reason: Linear solver produced non-finite values. Cutting timestep.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.085152e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.064320e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.064320e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.064320e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.054492e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.054492e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.054492e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.053117e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.055028e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.064948e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.077903e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.092639e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.108663e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.125745e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.143776e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.162695e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.182435e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.182435e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.208770e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.221929e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.245704e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.270271e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.295200e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.320747e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.347083e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.374302e-17.
*** Simulation complete. Solved 33 control steps in 377 Seconds, 975 Milliseconds (termination triggered by stopFunction) ***

Visualize the Results

extract the time and voltage quantities
states = output.states;
 
time = cellfun(@(state) state.time, states);
voltage = cellfun(@(state) state.('Control').E, states);
We plot the discharge curve in a new figure
figure();
plot((time/hour), voltage, '-', 'linewidth', 3)
xlabel('Time / h')
ylabel('Cell Voltage / V')
title('Voltage');
For a given time step, we plot the concentration on the grid in the negative and positive electrodes.
% Set the timestep we want to visualize
timestep = 20;
 
% get the state of the simulation at the given timestep
state = states{timestep};
 
% create a new figure
figure()
 
% plot the surface concentration of lithium in the negative electrode active material
plotCellData(model.NegativeElectrode.Coating.grid, ...
state.NegativeElectrode.Coating.ActiveMaterial.SolidDiffusion.cSurface/(mol/litre), ...
'edgecolor', 'none');
 
% plot the surface concentration of lithium in the positive electrode active material
plotCellData(model.PositiveElectrode.Coating.grid, ...
state.PositiveElectrode.Coating.ActiveMaterial.SolidDiffusion.cSurface/(mol/litre), ...
'edgecolor', 'none')
 
title('Active Material Surface Lithium Concentration / mol \cdot L^{-1}');
% add a colorbar
colorbar()
view(45,45)