{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "# Tutorial 7 \\- A Simple P4D Simulation\n", "\n", "## Introduction\n", "\n", "In this tutorial, we will use a simple P4D simulation to explore the effects of battery cell architecture. After completing this tutorial, you should have a working knowledge of:\n", "\n", "- How to setup and run a P4D simulation of a single cell in BattMo\n", "- Advanced usage of combining model descriptions from multiple sources\n", "## Construct the Model from Different Sources\n", "\n", "Let's say that you parameterize some cell materials and put that data in a JSON file. Then you get some description of your cell geometry, and you put that data in another JSON file. Now you want to combine those descriptions into a single model and simulate it using some pre\\-defined contol protocol and simulation settings in other files. How can we combine those easily, without having to do any recoding?\n", "\n", "\n", "To do that, we can simply make use of the mergeJsonStructs function in **BattMo**.\n", "\n", "\n", "First, let’s define our cell materials. We have provided a JSON file that contains material properties for a NMC and Graphite active materials, which we can parse as a **BattMo** structure:\n", "" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "source": [ "% parse material definitions as a BattMo structure\n", "jsonfilename = 'ParameterData/BatteryCellParameters/LithiumIonBatteryCell/lithium_ion_battery_nmc_graphite.json';\n", "jsonstruct_material = parseBattmoJson(jsonfilename);" ], "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "Next, we have defined the cell geometry properties in a separate JSON file that we can also parse into **BattMo**:\n", "" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "source": [ "% parse cell geometry specifications as a BattMo structure\n", "jsonfilename = 'Examples/jsondatafiles/geometry3d.json';\n", "jsonstruct_geometry = parseBattmoJson(jsonfilename);" ], "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "Let's have a closer look at the cell geometry specification.\n", "" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "source": [ "disp(jsonstruct_geometry.Geometry)" ], "outputs": [ { "data": { "text/plain": [ " case: '3D-demo'\n", " width: 0.0100\n", " height: 0.0200\n", " Nw: 10\n", " Nh: 10" ] }, "metadata": {}, "execution_count": 3, "output_type": "execute_result" } ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "Here we can see that the width and height dimensions of the cell are defined, along with the number of discretizations in each direction, and a case description. The case sets the type of simulation to be performed. Here it is set to '3D\\-demo', to BattMo knows to setp a P4D mesh.\n", "\n", "\n", "We can take the same approach for the remaining parameters, as shown below, for the control protocol, simulation settings, and output settings:\n", "" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "source": [ "% control protocol\n", "jsonfilename = fullfile('Examples', 'jsondatafiles', 'cc_discharge_control.json');\n", "jsonstruct_control = parseBattmoJson(jsonfilename);\n", "\n", "% simulation settings\n", "jsonfilename = fullfile('Examples', 'jsondatafiles', 'simulation_parameters.json');\n", "jsonstruct_simparams = parseBattmoJson(jsonfilename);\n", "\n", "% output settings\n", "jsonfilename = fullfile('Examples', 'jsondatafiles', 'extra_output.json');\n", "jsonstruct_output = parseBattmoJson(jsonfilename);" ], "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "Now, we can merge these parameter definitions into a single parameter set and run the simulation:\n", "" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "source": [ "% combine the parameter structures from the different sources into a single\n", "% BattMo structure\n", "jsonstruct = mergeJsonStructs({jsonstruct_geometry , ...\n", " jsonstruct_material , ...\n", " jsonstruct_control , ...\n", " jsonstruct_simparams, ...\n", " jsonstruct_output , ...\n", " });" ], "outputs": [ { "data": { "text/plain": [ "mergeJsonStructs: Parameter include_current_collectors is assigned twice with different values. Value from first jsonstruct is used.\n", "mergeJsonStructs: Parameter ThermalModel.externalHeatTransferCoefficient is assigned twice with different values. Value from first jsonstruct is used." ] }, "metadata": {}, "execution_count": 5, "output_type": "execute_result" } ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "we store the output as a cell array so we can compare results across different simulation runs in this tutorial; here we instantiate an empty cell array\n", "" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "source": [ "output = cell(2,1);\n", "\n", "% run the simulation\n", "output{1} = runBatteryJson(jsonstruct);" ], "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualize the Results\n", "\n", "We plot the model using [plotBatteryGrid](https://github.com/BattMoTeam/BattMo/blob/main/Utilities/Visualization/plotBatteryGrid.m) (note that the different axis are scaled differently)\n", "" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "source": [ "% create a shorthand variable for the model\n", "model = output{1}.model;\n", "\n", "% use the plotBatteryGrid function to show the grid\n", "plotBatteryGrid(model)" ], "outputs": [ { "data": { "text/plain": [ "ans = \n", " Figure (10) with properties:\n", " Number: 10\n", " Name: ''\n", " Color: [1 1 1]\n", " Position: [1411 753 618 463]\n", " Units: 'pixels'\n", " Use GET to show all properties" ] }, "metadata": {}, "execution_count": 7, "output_type": "execute_result" } ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "source": [ "\n", "% make the axis tight and set the camera viewing angle\n", "axis tight\n", "view(45,45)" ], "outputs": [ { "data": { "text/html": [ "