{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "# Tutorial 2 \\- Change the Control Protocol\n", "\n", "## Introduction\n", "\n", "In this tutorial, we will use a P2D model to simulate the discharge of an NMC\\-Graphite cell at different rates. After completing this tutorial, you should have a working knowledge of:\n", "\n", "- Basics of the control protocol definitions in BattMo\n", "- The link between battery discharge rate and simulation time\n", "- How to setup and execute a parameter sweep\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": [ "## Explore the Control Protocol\n", "\n", "The control protocol is defined in the JSON parameter file and parsed into the MATLAB structure. Once the JSON parameter file has been read into MATLAB as a jsonstruct, its properties can be modified programmatically.\n", "\n", "\n", "Let's begin by exploring the control protocol definition with the following 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", "Here, we can see that the control policy follows the schema for a constant current discharge (CCDischarge). The three main control parameters in this schema are the CRate, lowerCutoffVoltage, and upperCutoffVoltage. Let's first try changing the protocol to discharge at a rate of C/10 to a lower cutoff voltage of 3 V.\n", "" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "source": [ "jsonstruct.Control.CRate = 0.1;\n", "jsonstruct.Control.lowerCutoffVoltage = 3.0;" ], "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "Remember that if we change the rate of the discharge then we also need to change the duration of the simulation. To do this we can explore the TimeStepping property of the structure.\n", "" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "source": [ "disp(jsonstruct.TimeStepping)" ], "outputs": [ { "data": { "text/plain": [ " totalTime: 5040\n", " numberOfTimeSteps: 150\n", " useRampup: 1" ] }, "metadata": {}, "execution_count": 4, "output_type": "execute_result" } ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "The total duration of the simulation is given by the totalTime property. We can adjust it to an appropriate duration using the following command.\n", "" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "source": [ "jsonstruct.TimeStepping.totalTime = (1./jsonstruct.Control.CRate) .* 3600 .* 1.1;" ], "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "This sets the total time of the simulation to be 10% longer than the expected duration based on the C\\-Rate. We can then run the simulation and plot the discharge curve.\n", "" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "source": [ "output = runBatteryJson(jsonstruct);" ], "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "retrieve the states from the simulation result\n", "" ] }, { "cell_type": "code", "execution_count": 7, "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", "\n", "% plot the discharge curve in a new figure\n", "figure();\n", "plot((time/hour), voltage, '-', 'linewidth', 3)\n", "xlabel('Time / h')\n", "ylabel('Cell Voltage / V')\n", "title('Cell Discharge at C/10')" ], "outputs": [ { "data": { "text/html": [ "