{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "# Tutorial 5 \\- Simulate CC\\-CV Cycling\n", "\n", "## Introduction\n", "\n", "In this tutorial, we will use a P2D model to simulate CC\\-CV cycling. After completing this tutorial, you should have a working knowledge of:\n", "\n", "- How to define and modify cycling protocols in BattMo\n", "\n", "We'll use the same model from Tutorial 1.\n", "" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "source": [ "jsonstruct = parseBattmoJson('Examples/jsondatafiles/sample_input.json');" ], "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "Parameters are defined in the JSON parameter file and parsed into the MATLAB structure. Once the JSON file has been read into MATLAB as a jsonstruct, its properties can be modified programmatically.\n", "\n", "## Explore the Control Definition\n", "\n", "Let's begin by reviewing the control protocol in BattMo, with the command:\n", "" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "source": [ "disp(jsonstruct.Control)" ], "outputs": [ { "data": { "text/plain": [ " controlPolicy: 'CCDischarge'\n", " DRate: 1\n", " lowerCutoffVoltage: 3\n", " upperCutoffVoltage: 4.1000\n", " dIdtLimit: 0.0100\n", " dEdtLimit: 0.0100\n", " rampupTime: 0.1000" ] }, "metadata": {}, "execution_count": 2, "output_type": "execute_result" } ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "We see that the default control protocol is set to a constant current (galvanostatic) discharge. To change to a CC\\-CV cycling protocol, we can use the command:\n", "" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "source": [ "cccv_control_protocol = parseBattmoJson('cccv_control.json');\n", "jsonstruct_modified = mergeJsonStructs({cccv_control_protocol, jsonstruct});" ], "outputs": [ { "data": { "text/plain": [ "mergeJsonStructs: Parameter Control.controlPolicy is assigned twice with different values. Value from first jsonstruct is used.\n", "mergeJsonStructs: Parameter Control.lowerCutoffVoltage is assigned twice with different values. Value from first jsonstruct is used.\n", "mergeJsonStructs: Parameter Control.upperCutoffVoltage is assigned twice with different values. Value from first jsonstruct is used.\n", "mergeJsonStructs: Parameter Control.dIdtLimit is assigned twice with different values. Value from first jsonstruct is used.\n", "mergeJsonStructs: Parameter Control.dEdtLimit is assigned twice with different values. Value from first jsonstruct is used." ] }, "metadata": {}, "execution_count": 3, "output_type": "execute_result" } ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "Now we can explore the modified control protocol definition with the command:\n", "" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "source": [ "disp(jsonstruct_modified.Control)" ], "outputs": [ { "data": { "text/plain": [ " controlPolicy: 'CCCV'\n", " initialControl: 'discharging'\n", " numberOfCycles: 5\n", " CRate: 0.5000\n", " DRate: 1\n", " lowerCutoffVoltage: 2.8000\n", " upperCutoffVoltage: 4.2000\n", " dIdtLimit: 2.0000e-06\n", " dEdtLimit: 2.0000e-06\n", " rampupTime: 0.1000" ] }, "metadata": {}, "execution_count": 4, "output_type": "execute_result" } ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "Let's run the simulation and plot the cell voltage curve.\n", "" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "source": [ "% run the simulation\n", "output = runBatteryJson(jsonstruct_modified);" ], "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "get the states\n", "" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "source": [ "states = output.states;\n", "\n", "% extract the time and voltage quantities\n", "time = cellfun(@(state) state.time, states);\n", "voltage = cellfun(@(state) state.('Control').E, states);\n", "current = cellfun(@(state) state.('Control').I, states);\n", "\n", "% calculate the capacity\n", "capacity = time .* current;\n", "\n", "% plot the discharge curve in the figure\n", "plot(time/hour, voltage, '-', 'linewidth', 3)\n", "\n", "% add plot annotations\n", "xlabel('Capacity / mA \\cdot h')\n", "ylabel('Cell Voltage / V')" ], "outputs": [ { "data": { "text/html": [ "