{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "# Tutorial 1 \\- Your First BattMo Model\n", "\n", "## Introduction\n", "\n", "Let’s make your first **BattMo** model! ?⚡?\n", "\n", "\n", "In this tutorial, we will build, run, and visualize a simple pseudo\\-two\\-dimensional (P2D) simulation for a Li\\-ion battery cell. We will first introduce how **BattMo** handles model parameters, then run the simulation, dashboard the results, and explore the details of the simulation output.\n", "\n", "## Define Parameters\n", "\n", "**BattMo** uses JSON to manage parameters. This allows you to easily save, document, and share complete parameter sets from specific simulations. We have used long and explicit key names for good readability. If you are new to JSON, you can learn more about it [here](https://www.w3schools.com/js/js_json_intro.asp). Details on the BattMo specification are available in the [JSON input specification](http://json.html/#json-input-specification).\n", "\n", "\n", "For this example, we provide a sample JSON file [sample\\_input.json](https://github.com/BattMoTeam/BattMo/blob/main/Examples/JsonDataFiles/sample_input.json) that describes a simple NMC\\-Graphite cell.\n", "\n", "\n", "We load and parse the JSON input file into **BattMo** using the command:\n", "" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "source": [ "jsonstruct = parseBattmoJson('Examples/JsonDataFiles/sample_input.json');" ], "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "This transforms the parameter data as a [MATLAB structure](https://se.mathworks.com/help/matlab/structures.html) jsonstruct that is used to setup the simulation. We can explore the structure within the MATLAB Command Window by navigating the different levels of the structure.\n", "" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "source": [ "disp(jsonstruct)" ], "outputs": [ { "data": { "text/plain": [ " use_thermal: 0\n", " include_current_collectors: 0\n", " Geometry: [1x1 struct]\n", " NegativeElectrode: [1x1 struct]\n", " PositiveElectrode: [1x1 struct]\n", " Separator: [1x1 struct]\n", " Control: [1x1 struct]\n", " Electrolyte: [1x1 struct]\n", " ThermalModel: [1x1 struct]\n", " TimeStepping: [1x1 struct]\n", " Output: [1x1 struct]\n", " SOC: 0.9900\n", " initT: 298.1500" ] }, "metadata": {}, "execution_count": 2, "output_type": "execute_result" } ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "We can see that the structure contains various attributes for the different aspects of the model. For example, if we want to know the thickness of the negative electrode coating, we can navigate the hierarchy to find it:\n", "" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "source": [ "disp(jsonstruct.NegativeElectrode.Coating.thickness)" ], "outputs": [ { "data": { "text/plain": [ " 6.4000e-05" ] }, "metadata": {}, "execution_count": 3, "output_type": "execute_result" } ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "Unless otherwise specified, BattMo uses [SI base units](https://www.nist.gov/si-redefinition/definitions-si-base-units) for physical quantities.\n", "\n", "## Run Simulation\n", "\n", "We can run the simulation with the command:\n", "" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "source": [ "output = runBatteryJson(jsonstruct);" ], "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Show the Dashboard\n", "\n", "We can dashboard the main results using [plotDashboard](https://github.com/BattMoTeam/BattMo/blob/main/Utilities/Visualization/plotDashboard.m). Here, for example at time step 10,\n", "" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "source": [ "plotDashboard(output.model, output.states, 'step', 10);" ], "outputs": [ { "data": { "text/html": [ "