/*
 * li_battery_1d.java
 */

import com.comsol.model.*;
import com.comsol.model.util.*;

/** Model exported on May 15 2026, 10:58 by COMSOL 6.4.0.421. */
public class li_battery_1d {

  public static Model run() {
    Model model = ModelUtil.create("Model");

//    From the File menu, choose New.
//    In the New window, click Model Wizard.
//    In the Model Wizard window, click 1D.
//    In the Select Physics tree, select Electrochemistry > Batteries > Lithium-Ion Battery (liion).
//    Click Add.
//    Click Study.
//    In the Select Study tree, select Preset Studies for Selected Physics Interfaces > Time Dependent with Initialization.
//    (The <l>Time Dependent with Initialization study</l> will perform a time-dependent simulation, using an initialization study step to calculate the initial potentials in the cell.)
//    Click Done.

    model.component().create("comp1", true);

    model.component("comp1").geom().create("geom1", 1);

    model.component("comp1").mesh().create("mesh1");

    model.component("comp1").physics().create("liion", "LithiumIonBatteryMPH", "geom1");

    model.study().create("std1");
    model.study("std1").create("cdi", "CurrentDistributionInitialization");
    model.study("std1").feature("cdi").set("solnum", "auto");
    model.study("std1").feature("cdi").set("notsolnum", "auto");
    model.study("std1").feature("cdi").set("outputmap", new String[]{});
    model.study("std1").feature("cdi").set("ngenAUX", "1");
    model.study("std1").feature("cdi").set("goalngenAUX", "1");
    model.study("std1").feature("cdi").set("ngenAUX", "1");
    model.study("std1").feature("cdi").set("goalngenAUX", "1");
    model.study("std1").create("time", "Transient");
    model.study("std1").feature("time").set("initialtime", "0");
    model.study("std1").feature("time").set("solnum", "auto");
    model.study("std1").feature("time").set("notsolnum", "auto");
    model.study("std1").feature("time").set("outputmap", new String[]{});

//    In the Model Builder window, under Global Definitions, click Parameters 1.
//    In the Settings window for Parameters, locate the Parameters section.
//    Click Load from File.
//    Browse to the model's Application Library folder and double-click the file li_battery_1d_parameters.txt.
//    To import content from file, use:
//    model.param().loadFile("FILENAME");
    model.param().set("i_1C", "17.5[A/m^2]", "1C current density");
    model.param().set("Ds_neg", "3.9e-14[m^2/s]", "Solid phase Li-diffusivity negative electrode");
    model.param().set("Ds_pos", "1e-13[m^2/s]", "Solid phase Li-diffusivity positive electrode");
    model.param().set("rp_neg", "12.5e-6[m]", "Particle radius negative electrode");
    model.param().set("rp_pos", "8e-6[m]", "Particle radius positive electrode");
    model.param().set("T", "298[K]", "Temperature");
    model.param().set("epsl_pos", "0.63", "Electrolyte phase volume fraction, positive electrode");
    model.param()
         .set("epss_pos", "1-epsl_pos-epss_filler_pos", "Electrode phase volume fraction, positive electrode");
    model.param().set("epss_filler_pos", "0.073", "Conductive filler phase volume fraction, positive electrode");
    model.param().set("cl_0", "2000[mol/m^3]", "Initial electrolyte salt concentration");
    model.param().set("epsl_neg", "0.503", "Electrolyte phase volume fraction, negative electrode");
    model.param().set("epss_filler_neg", "0.026", "Conductive filler phase volume fraction, negative");
    model.param().set("epss_neg", "1-epsl_neg-epss_filler_neg", "Solid phase vol-fraction negative electrode");
    model.param().set("csmax_neg", "26390[mol/m^3]", "Max solid phase concentration, negative electrode");
    model.param().set("csmax_pos", "22860[mol/m^3]", "Max solid phase concentration, positive electrode");
    model.param().set("cs0_neg", "14870[mol/m^3]", "Initial concentration negative active electrode material");
    model.param().set("cs0_pos", "3900[mol/m^3]", "Initial concentration positive active electrode material");
    model.param().set("Ks_neg", "100[S/m]", "Solid phase conductivity negative electrode");
    model.param().set("Ks_pos", "100[S/m]", "Solid phase conductivity positive electrode");
    model.param()
         .set("i0_neg_ref", "0.11[mA/cm^2]", "Exchange current density at reference conditions, negative electrode");
    model.param()
         .set("i0_pos_ref", "0.08[mA/cm^2]", "Exchange current density at reference conditions, positive electrode");
    model.param().set("cl_ref", "2000[mol/m^3]", "Reference electrolyte salt concentration");
    model.param().set("cs_neg_ref", "14870[mol/m^3]", "Reference concentration negative active electrode material");
    model.param().set("cs_pos_ref", "3900[mol/m^3]", "Reference concentration negative active electrode material");
    model.param()
         .set("k_neg", "i0_neg_ref/(F_const*(cs_neg_ref[m^3/mol])^0.5*((csmax_neg-cs_neg_ref)[m^3/mol])^0.5)[mol/m^3]", "Rate constant, negative electrode");
    model.param()
         .set("k_pos", "i0_pos_ref/(F_const*(cs_pos_ref[m^3/mol])^0.5*((csmax_pos-cs_pos_ref)[m^3/mol])^0.5)[mol/m^3]", "Rate constant, positive electrode");
    model.param().set("brugg", "3.3", "Bruggeman coefficient");
    model.param().set("t_disch", "2000[s]", "Discharge duration");
    model.param().set("t_ocp", "300[s]", "Open circuit (rest) duration");
    model.param().set("t_charge", "2000[s]", "Charge duration");
    model.param().set("L_neg", "100e-6[m]", "Length of negative electrode");
    model.param().set("L_sep", "52e-6[m]", "Length of separator");
    model.param().set("L_pos", "174e-6[m]", "Length of positive electrode");
    model.param().set("C", "1", "C-rate factor for the parametric study");
    model.param().set("A_cell", "1[m^2]", "Cell area (dummy value)");
    model.param().set("I_1C", "i_1C*A_cell", "C-rate current");

//    The geometry contains three domains. Create the geometry by specifying the lengths of the domains.
//    In the Model Builder window, right-click Component 1 (comp1) > Geometry 1 and choose Interval.

    model.component("comp1").geom("geom1").create("i1", "Interval");

//    In the Settings window for Interval, locate the Interval section.
//    From the Specify list, select Interval lengths.

    model.component("comp1").geom("geom1").feature("i1").set("specify", "len");

//    In the table, enter the following settings:

    model.component("comp1").geom("geom1").feature("i1").setIndex("len", "L_neg", 0);
    model.component("comp1").geom("geom1").feature("i1").setIndex("len", "L_sep", 1);
    model.component("comp1").geom("geom1").feature("i1").setIndex("len", "L_pos", 2);

//    Click Build Selected.

    model.component("comp1").geom("geom1").run("i1");

//    This model uses an interpolation function, imported from a text file, for the equilibrium potential of the negative electrode material.
//    In the Home toolbar, click Functions and choose Global > Interpolation.

    model.func().create("int1", "Interpolation");

//    In the Settings window for Interpolation, locate the Definition section.
//    From the Data source list, select File.

    model.func("int1").set("source", "file");

//    Click Browse.
//    Browse to the model's Application Library folder and double-click the file li_battery_1d_Eeq_neg.txt.

    model.func("int1").set("filename", "li_battery_1d_Eeq_neg.txt");

//    Click Import.

    model.func("int1").importData();

//    In the Function name text field, type Eeq_neg.

    model.func("int1").set("funcname", "Eeq_neg");

//    Locate the Interpolation and Extrapolation section.
//    From the Interpolation list, select Cubic spline.

    model.func("int1").set("interp", "cubicspline");

//    From the Extrapolation list, select Nearest function.

    model.func("int1").set("extrap", "interior");

//    Locate the Units section.
//    In the Function table, enter the following settings:

    model.func("int1").setIndex("fununit", "V", 0);

//    Click Plot.
//    This model also uses battery materials available in the material library.

    model.component("comp1").geom("geom1").run();

//    Select LMO as the positive electrode material
//    In the Materials toolbar, click Add Material to open the Add Material window.
//    In the tree, select Battery > Electrodes > LMO, LiMn2O4 Spinel (Positive, Li-ion Battery).
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat1", "Common");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("int1", "Interpolation");
    model.component("comp1").material("mat1").propertyGroup("def").func().create("int2", "Interpolation");
    model.component("comp1").material("mat1").propertyGroup()
         .create("ElectrodePotential", "ElectrodePotential", "Equilibrium potential");
    model.component("comp1").material("mat1").propertyGroup()
         .create("OperationalSOC", "OperationalSOC", "Operational electrode state of charge");
    model.component("comp1").material("mat1").propertyGroup()
         .create("EquilibriumConcentration", "EquilibriumConcentration", "Equilibrium concentration");
    model.component("comp1").material("mat1").propertyGroup()
         .create("EquilibriumPotentialWithDOCInput", "EquilibriumPotentialWithDOCInput", "Equilibrium potential (using degree of conversion as model input)");
    model.component("comp1").material("mat1").propertyGroup()
         .create("EquilibriumDegreeOfConversion", "EquilibriumDegreeOfConversion", "Equilibrium degree of conversion");
    model.component("comp1").material("mat1").label("LMO, LiMn2O4 Spinel (Positive, Li-ion Battery)");
    model.component("comp1").material("mat1").propertyGroup("def").func("int1").set("funcname", "Eeq");
    model.component("comp1").material("mat1").propertyGroup("def").func("int1")
         .set("table", new String[][]{{"0.1750", "4.2763"}, 
         {"0.1950", "4.1898"}, 
         {"0.2150", "4.1507"}, 
         {"0.2350", "4.133"}, 
         {"0.2550", "4.1248"}, 
         {"0.2750", "4.1209"}, 
         {"0.2950", "4.119"}, 
         {"0.3150", "4.1179"}, 
         {"0.3350", "4.1171"}, 
         {"0.3550", "4.1165"}, 
         {"0.3750", "4.116"}, 
         {"0.3950", "4.1153"}, 
         {"0.4150", "4.1145"}, 
         {"0.4350", "4.1135"}, 
         {"0.4550", "4.1121"}, 
         {"0.4750", "4.1099"}, 
         {"0.4950", "4.1066"}, 
         {"0.5150", "4.1014"}, 
         {"0.5350", "4.0934"}, 
         {"0.5550", "4.082"}, 
         {"0.5750", "4.067"}, 
         {"0.5950", "4.05"}, 
         {"0.6150", "4.0333"}, 
         {"0.6350", "4.0192"}, 
         {"0.6550", "4.0087"}, 
         {"0.6750", "4.0012"}, 
         {"0.6950", "3.996"}, 
         {"0.7150", "3.9923"}, 
         {"0.7350", "3.9893"}, 
         {"0.7550", "3.9867"}, 
         {"0.7750", "3.9841"}, 
         {"0.7950", "3.9813"}, 
         {"0.8150", "3.9783"}, 
         {"0.8350", "3.9747"}, 
         {"0.8550", "3.9705"}, 
         {"0.8750", "3.9652"}, 
         {"0.8950", "3.9585"}, 
         {"0.9150", "3.9493"}, 
         {"0.9350", "3.9361"}, 
         {"0.9550", "3.9144"}, 
         {"0.9750", "3.869"}, 
         {"0.9950", "3.5944"}, 
         {"", ""}});
    model.component("comp1").material("mat1").propertyGroup("def").func("int1").set("extrap", "linear");
    model.component("comp1").material("mat1").propertyGroup("def").func("int1").set("fununit", new String[]{"V"});
    model.component("comp1").material("mat1").propertyGroup("def").func("int1").set("argunit", new String[]{""});
    model.component("comp1").material("mat1").propertyGroup("def").func("int1").set("defineinv", true);
    model.component("comp1").material("mat1").propertyGroup("def").func("int1").set("funcinvname", "Eeq_inv");
    model.component("comp1").material("mat1").propertyGroup("def").func("int2").set("funcname", "dEeqdT");
    model.component("comp1").material("mat1").propertyGroup("def").func("int2")
         .set("table", new String[][]{{"0.15", "0.15e-3"}, 
         {"0.18", "0.25e-3"}, 
         {"0.20", "0.21e-3"}, 
         {"0.209", "0.19e-3"}, 
         {"0.26", "0.175e-3"}, 
         {"0.28", "0.166e-3"}, 
         {"0.30", "0.155e-3"}, 
         {"0.35", "0.11e-3"}, 
         {"0.394", "0.095e-3"}, 
         {"0.41", "0.05e-3"}, 
         {"0.437", "0.02e-3"}, 
         {"0.445", "0"}, 
         {"0.46", "-0.048e-3"}, 
         {"0.48", "-0.15e-3"}, 
         {"0.50", "-0.255e-3"}, 
         {"0.515", "-0.3e-3"}, 
         {"0.545", "-0.3e-3"}, 
         {"0.553", "-0.22e-3"}, 
         {"0.58", "-0.145e-3"}, 
         {"0.592", "-0.10e-3"}, 
         {"0.60", "0"}, 
         {"0.62", "0.08e-3"}, 
         {"0.64", "0.12e-3"}, 
         {"0.70", "0.124e-3"}, 
         {"0.72", "0.10e-3"}, 
         {"0.73", "0.05e-3"}, 
         {"0.76", "0"}, 
         {"0.78", "-0.057e-3"}, 
         {"0.81", "-0.08e-3"}, 
         {"0.86", "-0.10e-3"}, 
         {"0.91", "-0.16e-3"}, 
         {"0.96", "-0.22e-3"}, 
         {"0.98", "-0.30e-3"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("int2").set("interp", "piecewisecubic");
    model.component("comp1").material("mat1").propertyGroup("def").func("int2").set("fununit", new String[]{"V/K"});
    model.component("comp1").material("mat1").propertyGroup("def").func("int2").set("argunit", new String[]{""});
    model.component("comp1").material("mat1").propertyGroup("def").set("youngsmodulus", "");
    model.component("comp1").material("mat1").propertyGroup("def").set("poissonsratio", "");
    model.component("comp1").material("mat1").propertyGroup("def").set("youngsmodulus", "194[GPa]");
    model.component("comp1").material("mat1").propertyGroup("def")
         .setPropertyInfo("youngsmodulus", "Yue Qi et al 2014 J. Electrochem. Soc. 161 F3010");
    model.component("comp1").material("mat1").propertyGroup("def").set("poissonsratio", "0.26");
    model.component("comp1").material("mat1").propertyGroup("def")
         .setPropertyInfo("poissonsratio", "Yue Qi et al 2014 J. Electrochem. Soc. 161 F3010");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("electricconductivity", new String[]{"1.3e-3[S/cm]", "0", "0", "0", "1.3e-3[S/cm]", "0", "0", "0", "1.3e-3[S/cm]"});
    model.component("comp1").material("mat1").propertyGroup("def")
         .setPropertyInfo("electricconductivity", "Electrochemical and Electronic Charge Transport Properties of Ni-Doped LiMn2O4 Spinel Obtained from Polyol-Mediated Synthesis, Shuo Yang et al, Materials 2018, 11(5), 806");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("diffusion", new String[]{"1e-14*exp(20000/8.314*(1/(T_ref/1[K])-1/(T2/1[K])))[m^2/s]", "0", "0", "0", "1e-14*exp(20000/8.314*(1/(T_ref/1[K])-1/(T2/1[K])))[m^2/s]", "0", "0", "0", "1e-14*exp(20000/8.314*(1/(T_ref/1[K])-1/(T2/1[K])))[m^2/s]"});
    model.component("comp1").material("mat1").propertyGroup("def")
         .setPropertyInfo("diffusion", "V. Srinivasan and C.Y. Wang, \"Analysis of Electrochemical and Thermal Behavior of Li-Ion Cells,\" J. Electrochem. Soc., vol. 150, p. A98, 2003");
    model.component("comp1").material("mat1").propertyGroup("def").set("density", "4140[kg/m^3]");
    model.component("comp1").material("mat1").propertyGroup("def")
         .setPropertyInfo("density", "N. Nitta, F. Wu, J. Tae Lee, and G. Yushin, Materials Today, Volume 18, Number 5, June 2015");
    model.component("comp1").material("mat1").propertyGroup("def").set("T_ref", "298[K]");
    model.component("comp1").material("mat1").propertyGroup("def").descr("T_ref", "");
    model.component("comp1").material("mat1").propertyGroup("def").set("T2", "min(393.15,max(T,223.15))");
    model.component("comp1").material("mat1").propertyGroup("def").descr("T2", "");
    model.component("comp1").material("mat1").propertyGroup("def").set("csmax", "22860[mol/m^3]");
    model.component("comp1").material("mat1").propertyGroup("def").descr("csmax", "");
    model.component("comp1").material("mat1").propertyGroup("def").addInput("temperature");
    model.component("comp1").material("mat1").propertyGroup("ElectrodePotential").identifier("eeq");
    model.component("comp1").material("mat1").propertyGroup("ElectrodePotential")
         .set("Eeq", "def.Eeq(doc)+def.dEeqdT(doc)*(T-298[K])");
    model.component("comp1").material("mat1").propertyGroup("ElectrodePotential")
         .setPropertyInfo("Eeq", "V. Srinivasan and C.Y. Wang, \"Analysis of Electrochemical and Thermal Behavior of Li-Ion Cells,\" J. Electrochem. Soc., vol. 150, p. A98, 2003");
    model.component("comp1").material("mat1").propertyGroup("ElectrodePotential").set("dEeqdT", "def.dEeqdT(doc)");
    model.component("comp1").material("mat1").propertyGroup("ElectrodePotential")
         .setPropertyInfo("dEeqdT", "V. Srinivasan and C.Y. Wang, \"Analysis of Electrochemical and Thermal Behavior of Li-Ion Cells,\" J. Electrochem. Soc., vol. 150, p. A98, 2003");
    model.component("comp1").material("mat1").propertyGroup("ElectrodePotential").set("cEeqref", "def.csmax");
    model.component("comp1").material("mat1").propertyGroup("ElectrodePotential")
         .setPropertyInfo("cEeqref", "V. Srinivasan and C.Y. Wang, \"Analysis of Electrochemical and Thermal Behavior of Li-Ion Cells,\" J. Electrochem. Soc., vol. 150, p. A98, 2003");
    model.component("comp1").material("mat1").propertyGroup("ElectrodePotential").set("doc", "c/cEeqref");
    model.component("comp1").material("mat1").propertyGroup("ElectrodePotential")
         .descr("doc", "Degree of conversion (state of lithiation)");
    model.component("comp1").material("mat1").propertyGroup("ElectrodePotential").addInput("concentration");
    model.component("comp1").material("mat1").propertyGroup("ElectrodePotential").addInput("temperature");
    model.component("comp1").material("mat1").propertyGroup("OperationalSOC").identifier("opsoc");
    model.component("comp1").material("mat1").propertyGroup("OperationalSOC").set("socmax", "def.Eeq_inv(E_min)");
    model.component("comp1").material("mat1").propertyGroup("OperationalSOC").set("socmin", "def.Eeq_inv(E_max)");
    model.component("comp1").material("mat1").propertyGroup("OperationalSOC").set("E_max", "4.2[V]");
    model.component("comp1").material("mat1").propertyGroup("OperationalSOC").set("E_min", "3.9[V]");
    model.component("comp1").material("mat1").propertyGroup("EquilibriumConcentration")
         .set("csEq", "def.csmax*def.Eeq_inv(V)");
    model.component("comp1").material("mat1").propertyGroup("EquilibriumConcentration")
         .addInput("electricpotential");
    model.component("comp1").material("mat1").propertyGroup("EquilibriumPotentialWithDOCInput")
         .set("Eeq", "def.Eeq(doc)+def.dEeqdT(doc)*(T-298[K])");
    model.component("comp1").material("mat1").propertyGroup("EquilibriumPotentialWithDOCInput")
         .set("dEeqdT", "def.dEeqdT(doc)");
    model.component("comp1").material("mat1").propertyGroup("EquilibriumPotentialWithDOCInput")
         .addInput("degreeofconversion");
    model.component("comp1").material("mat1").propertyGroup("EquilibriumPotentialWithDOCInput")
         .addInput("temperature");
    model.component("comp1").material("mat1").propertyGroup("EquilibriumDegreeOfConversion")
         .set("docEq", "def.Eeq_inv(V)");
    model.component("comp1").material("mat1").propertyGroup("EquilibriumDegreeOfConversion")
         .addInput("electricpotential");

//    Note: In the Materials node, <c>cEeqref</c> denotes the maximum lithium concentration in the active material.
//    Select Domain 3.

    model.component("comp1").material("mat1").selection().set(3);

//    In the Model Builder window, expand the LMO, LiMn2O4 Spinel (Positive, Li-ion Battery) (mat1) node.
//    In the Model Builder window, expand the Component 1 (comp1) > Materials > LMO, LiMn2O4 Spinel (Positive, Li-ion Battery) (mat1) > Basic (def) node, then click Interpolation 1 (Eeq, Eeq_inv).
//    In the Settings window for Interpolation, click to expand the Plot Parameters section.
//    Clear the Include right extrapolation checkbox.

    model.component("comp1").material("mat1").propertyGroup("def").func("int1").set("plotrightextrap", false);

//    Click Plot.
//    Select LiPF6 in 1:2 EC:DMC and p(VdF-HFP) as the electrolyte.
//    In the tree, select Battery > Electrolytes > LiPF6 in 1:2 EC:DMC and p(VdF-HFP) (Polymer, Li-ion Battery).
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat2", "Common");
    model.component("comp1").material("mat2").propertyGroup()
         .create("ElectrolyteConductivity", "ElectrolyteConductivity", "Electrolyte conductivity");
    model.component("comp1").material("mat2").propertyGroup("ElectrolyteConductivity").func()
         .create("int1", "Interpolation");
    model.component("comp1").material("mat2").propertyGroup()
         .create("SpeciesProperties", "SpeciesProperties", "Species properties");
    model.component("comp1").material("mat2").propertyGroup()
         .create("ElectrolyteSaltConcentration", "ElectrolyteSaltConcentration", "Electrolyte salt concentration");
    model.component("comp1").material("mat2").label("LiPF6 in 1:2 EC:DMC and p(VdF-HFP) (Polymer, Li-ion Battery)");
    model.component("comp1").material("mat2").comments("\n");
    model.component("comp1").material("mat2").propertyGroup("def")
         .set("diffusion", new String[]{"7.5e-11[m^2/s]", "0", "0", "0", "7.5e-11[m^2/s]", "0", "0", "0", "7.5e-11[m^2/s]"});
    model.component("comp1").material("mat2").propertyGroup("def")
         .setPropertyInfo("diffusion", "M. Doyle, J. Newman, A.S. Gozdz, C.N. Schmutz, and J.M. Tarascon, \u201cComparison of Modeling Predictions with Experimental Data from Plastic Lithium Ion Cells,\u201d J. Electrochem. Soc., vol. 143, p. 1890, 1996.\n");
    model.component("comp1").material("mat2").propertyGroup("ElectrolyteConductivity").func("int1")
         .set("funcname", "sigmal_int1");
    model.component("comp1").material("mat2").propertyGroup("ElectrolyteConductivity").func("int1")
         .set("table", new String[][]{{"0", "0.0108"}, 
         {"0.2000", "0.1259"}, 
         {"0.4000", "0.2055"}, 
         {"0.6000", "0.2553"}, 
         {"0.8000", "0.2810"}, 
         {"1.0000", "0.2873"}, 
         {"1.2000", "0.2788"}, 
         {"1.4000", "0.2595"}, 
         {"1.6000", "0.2331"}, 
         {"1.8000", "0.2027"}, 
         {"2.0000", "0.1710"}, 
         {"2.200", "0.1403"}, 
         {"2.4000", "0.1123"}, 
         {"2.6000", "0.0885"}, 
         {"2.8000", "0.0696"}, 
         {"3.0000", "0.0563"}});
    model.component("comp1").material("mat2").propertyGroup("ElectrolyteConductivity").func("int1")
         .set("fununit", new String[]{""});
    model.component("comp1").material("mat2").propertyGroup("ElectrolyteConductivity").func("int1")
         .set("argunit", new String[]{""});
    model.component("comp1").material("mat2").propertyGroup("ElectrolyteConductivity")
         .set("sigmal", new String[]{"sigmal_int1(c/c_ref)", "0", "0", "0", "sigmal_int1(c/c_ref)", "0", "0", "0", "sigmal_int1(c/c_ref)"});
    model.component("comp1").material("mat2").propertyGroup("ElectrolyteConductivity")
         .setPropertyInfo("sigmal", "M. Doyle, J. Newman, A.S. Gozdz, C.N. Schmutz, and J.M. Tarascon, \u201cComparison of Modeling Predictions with Experimental Data from Plastic Lithium Ion Cells,\u201d J. Electrochem. Soc., vol. 143, p. 1890, 1996.\n");
    model.component("comp1").material("mat2").propertyGroup("ElectrolyteConductivity").set("c_ref", "1000[mol/m^3]");
    model.component("comp1").material("mat2").propertyGroup("ElectrolyteConductivity").descr("c_ref", "");
    model.component("comp1").material("mat2").propertyGroup("ElectrolyteConductivity").addInput("concentration");
    model.component("comp1").material("mat2").propertyGroup("SpeciesProperties").set("transpNum", "0.363");
    model.component("comp1").material("mat2").propertyGroup("SpeciesProperties")
         .setPropertyInfo("transpNum", "M. Doyle, J. Newman, A.S. Gozdz, C.N. Schmutz, and J.M. Tarascon, \u201cComparison of Modeling Predictions with Experimental Data from Plastic Lithium Ion Cells,\u201d J. Electrochem. Soc., vol. 143, p. 1890, 1996.\n");
    model.component("comp1").material("mat2").propertyGroup("SpeciesProperties").set("fcl", "0");
    model.component("comp1").material("mat2").propertyGroup("SpeciesProperties")
         .setPropertyInfo("fcl", "M. Doyle, J. Newman, A.S. Gozdz, C.N. Schmutz, and J.M. Tarascon, \u201cComparison of Modeling Predictions with Experimental Data from Plastic Lithium Ion Cells,\u201d J. Electrochem. Soc., vol. 143, p. 1890, 1996.\n");
    model.component("comp1").material("mat2").propertyGroup("ElectrolyteSaltConcentration").identifier("cElsalt");
    model.component("comp1").material("mat2").propertyGroup("ElectrolyteSaltConcentration")
         .set("cElsalt", "1000[mol/m^3]");
    model.component("comp1").material("mat2").propertyGroup("ElectrolyteSaltConcentration")
         .setPropertyInfo("cElsalt", "M. Doyle, J. Newman, A.S. Gozdz, C.N. Schmutz, and J.M. Tarascon, \u201cComparison of Modeling Predictions with Experimental Data from Plastic Lithium Ion Cells,\u201d J. Electrochem. Soc., vol. 143, p. 1890, 1996.\n");

//    In the Materials toolbar, click Add Material to close the Add Material window.
//    Click in the Graphics window and then press Ctrl+A to select all Domains.

    model.component("comp1").material("mat2").selection().set(1, 2, 3);

//    In the Model Builder window, expand the LiPF6 in 1:2 EC:DMC and p(VdF-HFP) (Polymer, Li-ion Battery) (mat2) node.
//    In the Model Builder window, expand the Component 1 (comp1) > Materials > LiPF6 in 1:2 EC:DMC and p(VdF-HFP) (Polymer, Li-ion Battery) (mat2) > Electrolyte conductivity (ionc) node, then click Interpolation 1 (sigmal_int1).
//    In the Settings window for Interpolation, click Plot.
//    In the Model Builder window, under Component 1 (comp1), click Lithium-Ion Battery (liion).
//    In the Settings window for Lithium-Ion Battery, locate the Cross-Sectional Area section.
//    In the \[A_{\textrm{c}}\] text field, type A_cell.

    model.component("comp1").physics("liion").prop("Ac").set("Ac", "A_cell");

//    In the Model Builder window, under Component 1 (comp1) > Lithium-Ion Battery (liion), click Separator 1.
//    In the Settings window for Separator, locate the Porous Matrix Properties section.
//    In the \[\epsilon_{\textrm{l}}\] text field, type 1.

    model.component("comp1").physics("liion").feature("sep1").set("epsl", 1);

//    In the Physics toolbar, click Domains and choose Porous Electrode.

    model.component("comp1").physics("liion").create("pce1", "PorousElectrode", 1);

//    Select Domain 1.

    model.component("comp1").physics("liion").feature("pce1").selection().set(1);

//    In the Settings window for Porous Electrode, locate the Electrode Properties section.
//    In the \[\sigma_{\textrm{s}}\] text field, type Ks_neg.

    model.component("comp1").physics("liion").feature("pce1")
         .set("sigma", new String[]{"Ks_neg", "0", "0", "0", "Ks_neg", "0", "0", "0", "Ks_neg"});

//    Locate the Porous Matrix Properties section.
//    In the \[\epsilon_{\textrm{s}}\] text field, type epss_neg.

    model.component("comp1").physics("liion").feature("pce1").set("epss", "epss_neg");

//    In the \[\epsilon_{\textrm{l}}\] text field, type epsl_neg.

    model.component("comp1").physics("liion").feature("pce1").set("epsl", "epsl_neg");

//    Locate the Effective Transport Parameter Correction section.
//    From the Electrolyte conductivity list, select User defined.

    model.component("comp1").physics("liion").feature("pce1").set("IonicCorrModel", "userdef");

//    In the \[f_{\textrm{l}}\] text field, type epsl_neg^brugg.

    model.component("comp1").physics("liion").feature("pce1").set("fl", "epsl_neg^brugg");

//    From the Electric conductivity list, select No correction.

    model.component("comp1").physics("liion").feature("pce1").set("ElectricCorrModel", "NoCorr");

//    From the Diffusion list, select User defined.

    model.component("comp1").physics("liion").feature("pce1").set("DiffusionCorrModel", "userdef");

//    In the \[f_{\textrm{Dl}}\] text field, type epsl_neg^brugg.

    model.component("comp1").physics("liion").feature("pce1").set("fDl", "epsl_neg^brugg");

//    In the Model Builder window, click Particle Intercalation 1.
//    In the Settings window for Particle Intercalation, locate the Species Settings section.
//    In the \[c_{\textrm{s,init}}\] text field, type cs0_neg.

    model.component("comp1").physics("liion").feature("pce1").feature("pin1").set("csinit", "cs0_neg");

//    From the \[c_{\textrm{s,max}}\] list, select User defined.

    model.component("comp1").physics("liion").feature("pce1").feature("pin1").set("cEeqref_mat", "userdef");

//    In the associated text field, type csmax_neg.

    model.component("comp1").physics("liion").feature("pce1").feature("pin1").set("cEeqref", "csmax_neg");

//    Locate the Particle Transport Properties section.
//    From the \[D_{\textrm{s}}\] list, select User defined.

    model.component("comp1").physics("liion").feature("pce1").feature("pin1").set("Ds_mat", "userdef");

//    In the associated text field, type Ds_neg.

    model.component("comp1").physics("liion").feature("pce1").feature("pin1").set("Ds", "Ds_neg");

//    In the \[r_{\textrm{p}}\] text field, type rp_neg.

    model.component("comp1").physics("liion").feature("pce1").feature("pin1").set("rp", "rp_neg");

//    Click to expand the Operational SOCs for Initial Cell Charge Distribution section.
//    From the \[soc_{\textrm{min}}\] list, select User defined.

    model.component("comp1").physics("liion").feature("pce1").feature("pin1").set("socmin_mat", "userdef");

//    From the \[soc_{\textrm{max}}\] list, select User defined.

    model.component("comp1").physics("liion").feature("pce1").feature("pin1").set("socmax_mat", "userdef");

//    In the Model Builder window, click Porous Electrode Reaction 1.
//    In the Settings window for Porous Electrode Reaction, locate the Equilibrium Potential section.
//    From the \[E_{\textrm{eq}}\] list, select User defined.

    model.component("comp1").physics("liion").feature("pce1").feature("per1").set("Eeq_mat", "userdef");

//    In the associated text field, type Eeq_neg(liion.cs_surface/csmax_neg).

    model.component("comp1").physics("liion").feature("pce1").feature("per1")
         .set("Eeq", "Eeq_neg(liion.cs_surface/csmax_neg)");

//    Locate the Electrode Kinetics section.
//    From the Exchange current density type list, select Rate constant.

    model.component("comp1").physics("liion").feature("pce1").feature("per1").set("i0refType", "FromRateConstant");

//    In the \[k\] text field, type k_neg.

    model.component("comp1").physics("liion").feature("pce1").feature("per1").set("k", "k_neg");

//    In the \[c_{\textrm{l,ref}}\] text field, type cl_ref.

    model.component("comp1").physics("liion").feature("pce1").feature("per1").set("cl_ref", "cl_ref");

//    Click to expand the Heat of Reaction section.
//    From the \[\] list, select User defined.

    model.component("comp1").physics("liion").feature("pce1").feature("per1").set("dEeqdT_mat", "userdef");

//    In the Physics toolbar, click Domains and choose Porous Electrode.

    model.component("comp1").physics("liion").create("pce2", "PorousElectrode", 1);

//    Select Domain 3.

    model.component("comp1").physics("liion").feature("pce2").selection().set(3);

//    In the <l>Materials</l> node, the electrolyte material has been assigned to all domains. You hence need to set the electrode material selection manually, which in this case is LMO electrode material.
//    In the Settings window for Porous Electrode, locate the Electrode Properties section.
//    In the \[\sigma_{\textrm{s}}\] text field, type Ks_pos.

    model.component("comp1").physics("liion").feature("pce2")
         .set("sigma", new String[]{"Ks_pos", "0", "0", "0", "Ks_pos", "0", "0", "0", "Ks_pos"});

//    Locate the Porous Matrix Properties section.
//    In the \[\epsilon_{\textrm{l}}\] text field, type epsl_pos.

    model.component("comp1").physics("liion").feature("pce2").set("epsl", "epsl_pos");

    return model;
  }

  public static Model run2(Model model) {

//    In the \[\epsilon_{\textrm{s}}\] text field, type epss_pos.

    model.component("comp1").physics("liion").feature("pce2").set("epss", "epss_pos");

//    Locate the Effective Transport Parameter Correction section.
//    From the Electrolyte conductivity list, select User defined.

    model.component("comp1").physics("liion").feature("pce2").set("IonicCorrModel", "userdef");

//    In the \[f_{\textrm{l}}\] text field, type epsl_pos^brugg.

    model.component("comp1").physics("liion").feature("pce2").set("fl", "epsl_pos^brugg");

//    From the Electric conductivity list, select No correction.

    model.component("comp1").physics("liion").feature("pce2").set("ElectricCorrModel", "NoCorr");

//    From the Diffusion list, select User defined.

    model.component("comp1").physics("liion").feature("pce2").set("DiffusionCorrModel", "userdef");

//    In the \[f_{\textrm{Dl}}\] text field, type epsl_pos^brugg.

    model.component("comp1").physics("liion").feature("pce2").set("fDl", "epsl_pos^brugg");

//    In the Model Builder window, click Particle Intercalation 1.
//    In the Settings window for Particle Intercalation, locate the Material section.
//    From the Particle material list, select LMO, LiMn2O4 Spinel (Positive, Li-ion Battery) (mat1).

    model.component("comp1").physics("liion").feature("pce2").feature("pin1").set("ParticleMaterial", "mat1");

//    Locate the Species Settings section.
//    In the \[c_{\textrm{s,init}}\] text field, type cs0_pos.

    model.component("comp1").physics("liion").feature("pce2").feature("pin1").set("csinit", "cs0_pos");

//    Locate the Particle Transport Properties section.
//    From the \[D_{\textrm{s}}\] list, select User defined.

    model.component("comp1").physics("liion").feature("pce2").feature("pin1").set("Ds_mat", "userdef");

//    In the associated text field, type Ds_pos.

    model.component("comp1").physics("liion").feature("pce2").feature("pin1").set("Ds", "Ds_pos");

//    In the \[r_{\textrm{p}}\] text field, type rp_pos.

    model.component("comp1").physics("liion").feature("pce2").feature("pin1").set("rp", "rp_pos");

//    Changing to quadratic elements in the particle dimension improves accuracy.
//    Click to expand the Particle Discretization section.
//    In the \[N_{\textrm{ord}}\] text field, type 2.

    model.component("comp1").physics("liion").feature("pce2").feature("pin1").set("Nord", 2);

//    In the Model Builder window, click Porous Electrode Reaction 1.
//    In the Settings window for Porous Electrode Reaction, locate the Material section.
//    From the Material list, select LMO, LiMn2O4 Spinel (Positive, Li-ion Battery) (mat1).

    model.component("comp1").physics("liion").feature("pce2").feature("per1").set("MaterialOption", "mat1");

//    Locate the Electrode Kinetics section.
//    From the Exchange current density type list, select Rate constant.

    model.component("comp1").physics("liion").feature("pce2").feature("per1").set("i0refType", "FromRateConstant");

//    In the \[k\] text field, type k_pos.

    model.component("comp1").physics("liion").feature("pce2").feature("per1").set("k", "k_pos");

//    In the \[c_{\textrm{l,ref}}\] text field, type cl_ref.

    model.component("comp1").physics("liion").feature("pce2").feature("per1").set("cl_ref", "cl_ref");

//    In the Physics toolbar, click Boundaries and choose Electric Ground.

    model.component("comp1").physics("liion").create("egnd1", "ElectricGround", 0);

//    Select Boundary 1.

    model.component("comp1").physics("liion").feature("egnd1").selection().set(1);

//    Define a load cycle consisting of a discharge, a rest, a charge and a rest step as follows:
//    In the Physics toolbar, click Boundaries and choose Load Cycle.

    model.component("comp1").physics("liion").create("lc1", "LoadCycle", 0);

//    Select Boundary 4.

    model.component("comp1").physics("liion").feature("lc1").selection().set(4);

//    In the Settings window for Load Cycle, locate the Load Type section.
//    From the list, select Galvanostatic.

    model.component("comp1").physics("liion").feature("lc1").set("LoadType", "Galvanostatic");

//    Locate the Continuation Conditions section.
//    Select the Use elapsed time only checkbox.

    model.component("comp1").physics("liion").feature("lc1").set("useTimeConditionsOnly", true);

//    Using only elapsed time conditions will allow for implementing the load cycle using explicitly timed events, which is slightly more accurate.
//    In the Physics toolbar, click Attributes and choose Current.

    model.component("comp1").physics("liion").feature("lc1").create("curr1", "Current", -1);

//    In the Settings window for Current, locate the Current section.
//    In the \[I_\textrm{set}\] text field, type -I_1C.

    model.component("comp1").physics("liion").feature("lc1").feature("curr1").set("setVal", "-I_1C");

//    Locate the Continuation Conditions section.
//    Select the Elapsed time checkbox.

    model.component("comp1").physics("liion").feature("lc1").feature("curr1").set("TimeCondition", true);

//    In the \[t_\textrm{max}\] text field, type t_disch.

    model.component("comp1").physics("liion").feature("lc1").feature("curr1").set("tmax", "t_disch");

//    In the Model Builder window, click Load Cycle 1.
//    In the Physics toolbar, click Attributes and choose Rest.

    model.component("comp1").physics("liion").feature("lc1").create("rest1", "Rest", -1);

//    In the Settings window for Rest, locate the Continuation Conditions section.
//    In the \[t_\textrm{max}\] text field, type t_ocp.

    model.component("comp1").physics("liion").feature("lc1").feature("rest1").set("tmax", "t_ocp");

//    In the Model Builder window, click Load Cycle 1.
//    In the Physics toolbar, click Attributes and choose Current.

    model.component("comp1").physics("liion").feature("lc1").create("curr2", "Current", -1);

//    In the Settings window for Current, locate the Current section.
//    In the \[I_\textrm{set}\] text field, type I_1C.

    model.component("comp1").physics("liion").feature("lc1").feature("curr2").set("setVal", "I_1C");

//    Locate the Continuation Conditions section.
//    Select the Elapsed time checkbox.

    model.component("comp1").physics("liion").feature("lc1").feature("curr2").set("TimeCondition", true);

//    In the \[t_\textrm{max}\] text field, type t_charge.

    model.component("comp1").physics("liion").feature("lc1").feature("curr2").set("tmax", "t_charge");

//    In the Model Builder window, click Load Cycle 1.
//    In the Physics toolbar, click Attributes and choose Rest.

    model.component("comp1").physics("liion").feature("lc1").create("rest2", "Rest", -1);

//    In the Settings window for Rest, locate the Continuation Conditions section.
//    Clear the Elapsed time checkbox.

    model.component("comp1").physics("liion").feature("lc1").feature("rest2").set("TimeCondition", false);

//    By disabling all continuation conditions on the final step in the load cycle, the sequence will run only once. The length of the last rest step will be defined by the end simulation time set in the solver later.
//    In the Model Builder window, under Component 1 (comp1) > Lithium-Ion Battery (liion), click Initial Values 1.
//    In the Settings window for Initial Values, locate the Initial Values section.
//    In the \[cl\] text field, type cl_0.

    model.component("comp1").physics("liion").feature("init1").set("cl", "cl_0");

//    Set up the temperature value used in the entire model.
//    In the Model Builder window, under Global Definitions, click Default Model Inputs.
//    In the Settings window for Default Model Inputs, locate the Browse Model Inputs section.
//    In the tree, select General > Temperature (K) - minput.T.
//    Find the Expression for remaining selection subsection.
//    In the Temperature text field, type T.

    model.common("cminpt").set("modified", new String[][]{{"temperature", "T"}});

//    First set up a study to investigate the defined discharge/charge cycle.
//    In the Model Builder window, under Study 1, click Step 2: Time Dependent.
//    In the Settings window for Time Dependent, locate the Study Settings section.
//    In the Output times text field, type range(0,10,8000).

    model.study("std1").feature("time").set("tlist", "range(0,10,8000)");

//    In the Study toolbar, click Compute.

    model.study("std1").createAutoSequences("all");

    model.sol("sol1").runAll();

    model.result().create("pg1", "PlotGroup1D");
    model.result("pg1").set("data", "dset1");
    model.result("pg1").label("Boundary Electrode Potential with Respect to Ground (liion)");
    model.result("pg1").set("titletype", "none");
    model.result("pg1").set("legendpos", "middleright");
    model.result("pg1").create("glob1", "Global");
    model.result("pg1").feature("glob1").set("unit", new String[]{""});
    model.result("pg1").feature("glob1").set("expr", new String[]{"liion.lc1.E_app"});
    model.result("pg1").feature("glob1").set("descr", new String[]{"Applied voltage"});
    model.result("pg1").feature("glob1").set("xdatasolnumtype", "level1");
    model.result("pg1").feature("glob1").set("legend", true);
    model.result("pg1").feature("glob1").set("autosolution", false);
    model.result("pg1").feature("glob1").set("autodescr", true);
    model.result("pg1").set("legendpos", "middleright");
    model.result("pg1").create("glob2", "Global");
    model.result("pg1").feature("glob2").set("unit", new String[]{""});
    model.result("pg1").feature("glob2").set("expr", new String[]{"liion.lc1.I_app"});
    model.result("pg1").feature("glob2").set("descr", new String[]{"Applied current"});
    model.result("pg1").feature("glob2").set("xdatasolnumtype", "level1");
    model.result("pg1").feature("glob2").set("legend", true);
    model.result("pg1").feature("glob2").set("autosolution", false);
    model.result("pg1").feature("glob2").set("autodescr", true);
    model.result("pg1").set("twoyaxes", true);
    model.result("pg1").setIndex("plotonsecyaxis", true, 1, 1);
    model.result().create("pg2", "PlotGroup1D");
    model.result("pg2").set("data", "dset1");
    model.result("pg2").set("ylabel", "SOC (1)");
    model.result("pg2").set("titletype", "none");
    model.result("pg2").set("legendpos", "middleleft");
    model.result("pg2").create("glob1", "Global");
    model.result("pg2").feature("glob1").set("unit", new String[]{"", ""});
    model.result("pg2").feature("glob1")
         .set("expr", new String[]{"liion.soc_average_pce1", "liion.soc_average_pce2"});
    model.result("pg2").feature("glob1")
         .set("descr", new String[]{"Average SOC, Porous Electrode 1", "Average SOC, Porous Electrode 2"});
    model.result("pg2").feature("glob1").set("xdatasolnumtype", "level1");
    model.result("pg2").feature("glob1").set("legend", true);
    model.result("pg2").feature("glob1").set("autosolution", false);
    model.result("pg2").feature("glob1").set("autodescr", true);
    model.result("pg2").label("Average Electrode State of Charge (liion)");
    model.result().create("pg3", "PlotGroup1D");
    model.result("pg3").set("data", "dset1");
    model.result("pg3").label("Electrode Potential with Respect to Adjacent Reference (liion)");
    model.result("pg3").create("lngr1", "LineGraph");
    model.result("pg3").feature("lngr1").set("xdata", "expr");
    model.result("pg3").feature("lngr1").set("xdataexpr", "x");
    model.result("pg3").feature("lngr1").selection().geom("geom1", 1);
    model.result("pg3").feature("lngr1").selection().set(1, 2, 3);
    model.result("pg3").feature("lngr1").set("expr", new String[]{"liion.Evsref"});
    model.result("pg3").feature("lngr1").set("resolution", "norefine");
    model.result("pg3").feature("lngr1").create("col1", "Color");
    model.result("pg3").feature("lngr1").feature("col1").set("expr", "t");
    model.result("pg3").feature("lngr1").feature("col1").set("colorlegend", true);
    model.result("pg3").feature("lngr1").feature("col1").set("colortable", "Viridis");
    model.result("pg3").feature("lngr1").feature("col1").set("legendtitle", "Time");
    model.result("pg3").feature("lngr1").feature("col1").set("unit", "min");
    model.result("pg3").set("showlegendstitle", true);
    model.result("pg3").set("showlegendsunit", true);
    model.result("pg3").set("titletype", "none");
    model.result().create("pg4", "PlotGroup1D");
    model.result("pg4").set("data", "dset1");
    model.result("pg4").label("Electrolyte Salt Concentration (liion)");
    model.result("pg4").set("titletype", "none");
    model.result("pg4").create("lngr1", "LineGraph");
    model.result("pg4").feature("lngr1").set("xdata", "expr");
    model.result("pg4").feature("lngr1").set("xdataexpr", "x");
    model.result("pg4").feature("lngr1").selection().geom("geom1", 1);
    model.result("pg4").feature("lngr1").selection().set(1, 2, 3);
    model.result("pg4").feature("lngr1").set("expr", new String[]{"cl"});
    model.result("pg4").feature("lngr1").create("col1", "Color");
    model.result("pg4").feature("lngr1").feature("col1").set("expr", "t");
    model.result("pg4").feature("lngr1").feature("col1").set("colorlegend", true);
    model.result("pg4").feature("lngr1").feature("col1").set("colortable", "Viridis");
    model.result("pg4").feature("lngr1").feature("col1").set("legendtitle", "Time");
    model.result("pg4").feature("lngr1").feature("col1").set("unit", "min");
    model.result("pg4").set("showlegendstitle", true);
    model.result("pg4").set("showlegendsunit", true);
    model.result().create("pg5", "PlotGroup1D");
    model.result("pg5").set("data", "dset1");
    model.result("pg5").label("Volumetric Current Density (liion)");
    model.result("pg5").set("titletype", "none");
    model.result("pg5").create("lngr1", "LineGraph");
    model.result("pg5").feature("lngr1").set("xdata", "expr");
    model.result("pg5").feature("lngr1").set("xdataexpr", "x");
    model.result("pg5").feature("lngr1").selection().geom("geom1", 1);
    model.result("pg5").feature("lngr1").selection().set(1, 2, 3);
    model.result("pg5").feature("lngr1").set("expr", new String[]{"liion.ivtot"});
    model.result("pg5").feature("lngr1").set("resolution", "norefine");
    model.result("pg5").feature("lngr1").create("col1", "Color");
    model.result("pg5").feature("lngr1").feature("col1").set("expr", "t");
    model.result("pg5").feature("lngr1").feature("col1").set("colorlegend", true);
    model.result("pg5").feature("lngr1").feature("col1").set("colortable", "Viridis");
    model.result("pg5").feature("lngr1").feature("col1").set("legendtitle", "Time");
    model.result("pg5").feature("lngr1").feature("col1").set("unit", "min");
    model.result("pg5").set("showlegendstitle", true);
    model.result("pg5").set("showlegendsunit", true);
    model.result("pg5").set("titletype", "none");
    model.result().create("pg6", "PlotGroup1D");
    model.result("pg6").set("data", "dset1");
    model.result("pg6").label("Particle Surface State of Charge (liion)");
    model.result("pg6").create("lngr1", "LineGraph");
    model.result("pg6").feature("lngr1").set("xdata", "expr");
    model.result("pg6").feature("lngr1").set("xdataexpr", "x");
    model.result("pg6").feature("lngr1").selection().geom("geom1", 1);
    model.result("pg6").feature("lngr1").selection().set(1, 2, 3);
    model.result("pg6").feature("lngr1").set("expr", new String[]{"liion.socloc_surface"});
    model.result("pg6").feature("lngr1").set("resolution", "norefine");
    model.result("pg6").feature("lngr1").create("col1", "Color");
    model.result("pg6").feature("lngr1").feature("col1").set("expr", "t");
    model.result("pg6").feature("lngr1").feature("col1").set("colorlegend", true);
    model.result("pg6").feature("lngr1").feature("col1").set("colortable", "Viridis");
    model.result("pg6").feature("lngr1").feature("col1").set("legendtitle", "Time");
    model.result("pg6").feature("lngr1").feature("col1").set("unit", "min");
    model.result("pg6").set("showlegendstitle", true);
    model.result("pg6").set("showlegendsunit", true);
    model.result("pg6").set("titletype", "none");
    model.result("pg1").run();

//    A number of plots are created by default. The first plot shows the electrode potential versus time on the boundary where you applied the current density condition. Since you grounded the other electrode, this equals the cell voltage.

    model.result("pg1").run();

//    In the Model Builder window, under Results, click Boundary Electrode Potential with Respect to Ground (liion).
//    In the Settings window for 1D Plot Group, locate the Legend section.
//    From the Position list, select Lower right.

    model.result("pg1").set("legendpos", "lowerright");

//    In the Boundary Electrode Potential with Respect to Ground (liion) toolbar, click Plot.

    model.result("pg1").run();

//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg7", "PlotGroup1D");
    model.result("pg7").run();

//    In the Settings window for 1D Plot Group, type Voltage Losses Comparison in the Label text field.

    model.result("pg7").label("Voltage Losses Comparison");

//    Locate the Data section.
//    From the Dataset list, select None.

    model.result("pg7").set("data", "none");

//    Click to expand the Title section.
//    From the Title type list, select Label.

    model.result("pg7").set("titletype", "label");

//    Right-click Voltage Losses Comparison and choose Line Graph.

    model.result("pg7").create("lngr1", "LineGraph");
    model.result("pg7").feature("lngr1").set("markerpos", "datapoints");
    model.result("pg7").feature("lngr1").set("linewidth", "preference");
    model.result("pg7").feature("lngr1").set("evaluationsettings", "parent");

//    In the Settings window for Line Graph, locate the Data section.
//    From the Dataset list, select Study 1/Solution 1 (sol1).

    model.result("pg7").feature("lngr1").set("data", "dset1");

//    From the Time selection list, select From list.

    model.result("pg7").feature("lngr1").setIndex("looplevelinput", "manual", 0);

//    In the Times (s) list, select 10.

    model.result("pg7").feature("lngr1").setIndex("looplevel", new int[]{2}, 0);

//    select 10 in the Times (s) list.
//    Locate the Selection section.
//    From the Selection list, select All domains.

    model.result("pg7").feature("lngr1").selection().all();

//    Locate the y-Axis Data section.
//    In the Expression text field, type phil+0.157.

    model.result("pg7").feature("lngr1").set("expr", "phil+0.157");

//    Click to expand the Legends section.
//    Select the Show legends checkbox.

    model.result("pg7").feature("lngr1").set("legend", true);

//    From the Legends list, select Evaluated.

    model.result("pg7").feature("lngr1").set("legendmethod", "evaluated");

//    In the Legend text field, type \phi<sub>l</sub> + 0.157 mV eval(t,s,4) s.

    model.result("pg7").feature("lngr1").set("legendpattern", "\\phi<sub>l</sub> + 0.157 mV   eval(t,s,4) s");

//    Right-click Line Graph 1 and choose Duplicate.

    model.result("pg7").feature().duplicate("lngr2", "lngr1");
    model.result("pg7").run();

//    In the Settings window for Line Graph, locate the Data section.
//    In the Times (s) list, select 1990.

    model.result("pg7").feature("lngr2").setIndex("looplevel", new int[]{200}, 0);

//    select 1990 in the Times (s) list.
//    Locate the y-Axis Data section.
//    In the Expression text field, type phil+0.594.

    model.result("pg7").feature("lngr2").set("expr", "phil+0.594");

//    Locate the Legends section.
//    In the Legend text field, type \phi<sub>l</sub> + 0.594 mV eval(t,s,4) s.

    model.result("pg7").feature("lngr2").set("legendpattern", "\\phi<sub>l</sub> + 0.594 mV   eval(t,s,4) s");

//    Right-click Line Graph 2 and choose Duplicate.

    model.result("pg7").feature().duplicate("lngr3", "lngr2");
    model.result("pg7").run();

//    In the Settings window for Line Graph, locate the Data section.
//    In the Times (s) list, select 10, 1990.

    model.result("pg7").feature("lngr3").setIndex("looplevel", new int[]{2, 200}, 0);

//    Locate the y-Axis Data section.
//    In the Expression text field, type liion.eta_per1.

    model.result("pg7").feature("lngr3").set("expr", "liion.eta_per1");

//    Locate the Legends section.
//    In the Legend text field, type \eta<sub>tot</sub> eval(t,s,4) s.

    model.result("pg7").feature("lngr3").set("legendpattern", "\\eta<sub>tot</sub>   eval(t,s,4) s");
    model.result("pg7").run();

//    In the Model Builder window, click Voltage Losses Comparison.
//    In the Settings window for 1D Plot Group, locate the Plot Settings section.
//    Select the x-axis label checkbox.

    model.result("pg7").set("xlabelactive", true);

//    In the associated text field, type x.

    model.result("pg7").set("xlabel", "x");

//    Select the y-axis label checkbox.

    model.result("pg7").set("ylabelactive", true);

//    In the associated text field, type Voltage (V).

    model.result("pg7").set("ylabel", "Voltage (V)");

//    In the Voltage Losses Comparison toolbar, click Plot.

    model.result("pg7").run();
    model.result("pg4").run();

//    In the Model Builder window, click Electrolyte Salt Concentration (liion).
//    In the Settings window for 1D Plot Group, locate the Data section.
//    From the Time selection list, select From list.

    model.result("pg4").setIndex("looplevelinput", "manual", 0);

//    In the Times (s) list, select 1990, 2090, 2500, 3000, 3990.

    model.result("pg4").setIndex("looplevel", new int[]{200, 211, 253, 303, 402}, 0);
    model.result("pg4").run();

//    In the Model Builder window, expand the Electrolyte Salt Concentration (liion) node, then click Line Graph 1.
//    In the Settings window for Line Graph, click to expand the Legends section.

    model.result("pg4").run();

//    In the Model Builder window, expand the Line Graph 1 node, then click Color Expression 1.
//    In the Settings window for Color Expression, locate the Coloring and Style section.
//    From the Color table list, select Rainbow.

    model.result("pg4").feature("lngr1").feature("col1").set("colortable", "Rainbow");

//    From the Color table type list, select Discrete.

    model.result("pg4").feature("lngr1").feature("col1").set("colortabletype", "discrete");

//    In the Electrolyte Salt Concentration (liion) toolbar, click Plot.

    model.result("pg4").run();

//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg8", "PlotGroup1D");
    model.result("pg8").run();

//    In the Settings window for 1D Plot Group, locate the Data section.
//    From the Time selection list, select From list.

    model.result("pg8").setIndex("looplevelinput", "manual", 0);

//    In the Times (s) list, select 10, 1200, 1800.

    model.result("pg8").setIndex("looplevel", new int[]{2, 121, 181}, 0);

//    Click to expand the Title section.
//    From the Title type list, select Manual.

    model.result("pg8").set("titletype", "manual");

//    In the Title text area, type Electrode particle lithium concentration, surface (solid) and center (dashed).

    model.result("pg8")
         .set("title", "Electrode particle lithium concentration, surface (solid) and center (dashed)");

//    Locate the Plot Settings section.
//    Select the x-axis label checkbox.

    model.result("pg8").set("xlabelactive", true);

//    In the associated text field, type x.

    model.result("pg8").set("xlabel", "x");

//    Select the y-axis label checkbox.

    model.result("pg8").set("ylabelactive", true);

//    In the associated text field, type cs (mol//m<sup>3</sup>).

    model.result("pg8").set("ylabel", "cs (mol//m<sup>3</sup>)");

//    Right-click 1D Plot Group 8 and choose Line Graph.

    model.result("pg8").create("lngr1", "LineGraph");
    model.result("pg8").feature("lngr1").set("markerpos", "datapoints");
    model.result("pg8").feature("lngr1").set("linewidth", "preference");
    model.result("pg8").feature("lngr1").set("evaluationsettings", "parent");

//    In the Settings window for Line Graph, locate the Selection section.
//    From the Selection list, select All domains.

    model.result("pg8").feature("lngr1").selection().all();

//    Click Replace Expression in the upper-right corner of the y-Axis Data section.
//    From the menu, choose Component 1 (comp1) > Lithium-Ion Battery > Particle intercalation > liion.cs_surface - Insertion particle concentration, surface - mol/m³.

    model.result("pg8").feature("lngr1").set("expr", "liion.cs_surface");
    model.result("pg8").feature("lngr1").set("descr", "Insertion particle concentration, surface");

//    Locate the Legends section.
//    Select the Show legends checkbox.

    model.result("pg8").feature("lngr1").set("legend", true);
    model.result("pg8").run();

//    In the Model Builder window, right-click 1D Plot Group 8 and choose Line Graph.

    model.result("pg8").create("lngr2", "LineGraph");
    model.result("pg8").feature("lngr2").set("markerpos", "datapoints");
    model.result("pg8").feature("lngr2").set("linewidth", "preference");
    model.result("pg8").feature("lngr2").set("evaluationsettings", "parent");

//    In the Settings window for Line Graph, locate the Selection section.
//    From the Selection list, select All domains.

    model.result("pg8").feature("lngr2").selection().all();

//    Click Replace Expression in the upper-right corner of the y-Axis Data section.
//    From the menu, choose Component 1 (comp1) > Lithium-Ion Battery > Particle intercalation > liion.cs_center - Insertion particle concentration, center - mol/m³.

    model.result("pg8").feature("lngr2").set("expr", "liion.cs_center");
    model.result("pg8").feature("lngr2").set("descr", "Insertion particle concentration, center");

//    Click to expand the Coloring and Style section.
//    Find the Line style subsection.
//    From the Line list, select Dashed.

    model.result("pg8").feature("lngr2").set("linestyle", "dashed");

//    From the Color list, select Cycle (reset).

    model.result("pg8").feature("lngr2").set("linecolor", "cyclereset");

//    In the 1D Plot Group 8 toolbar, click Plot.

    model.result("pg8").run();

//    Click the Zoom Extents button in the Graphics toolbar.
//    Begin by adding a global current variable.
//    In the Model Builder window, under Global Definitions, click Parameters 1.
//    In the Settings window for Parameters, locate the Parameters section.
//    In the table, enter the following settings:
//    Now add a second Load Cycle boundary condition node for use in a second study.
//    In the Physics toolbar, click Boundaries and choose Load Cycle.

    model.component("comp1").physics("liion").create("lc2", "LoadCycle", 0);

//    In the Settings window for Load Cycle, type Load Cycle 2 - Study 2 in the Label text field.

    model.component("comp1").physics("liion").feature("lc2").label("Load Cycle 2 - Study 2");

//    Select Boundary 4.

    model.component("comp1").physics("liion").feature("lc2").selection().set(4);

//    Locate the Load Type section.
//    From the list, select Galvanostatic.

    model.component("comp1").physics("liion").feature("lc2").set("LoadType", "Galvanostatic");

//    Locate the Cycling Stop Condition section.
//    From the list, select Minimum voltage.

    model.component("comp1").physics("liion").feature("lc2").set("CyclingStopCondition", "MinVoltageCondition");

//    In the \[E_\textrm{min}\] text field, type 2[V].

    model.component("comp1").physics("liion").feature("lc2").set("Emin", "2[V]");

//    In the Physics toolbar, click Attributes and choose Current.

    model.component("comp1").physics("liion").feature("lc2").create("curr1", "Current", -1);

//    In the Settings window for Current, locate the Current section.
//    In the \[I_\textrm{set}\] text field, type -C*I_1C.

    model.component("comp1").physics("liion").feature("lc2").feature("curr1").set("setVal", "-C*I_1C");

//    In the Model Builder window, under Component 1 (comp1) > Lithium-Ion Battery (liion), click Load Cycle 1.
//    In the Settings window for Load Cycle, type Load Cycle 1 - Study 1 in the Label text field.

    model.component("comp1").physics("liion").feature("lc1").label("Load Cycle 1 - Study 1");

//    In the Home toolbar, click Add Study to open the Add Study window.
//    Find the Studies subsection.
//    In the Select Study tree, select Preset Studies for Selected Physics Interfaces > Time Dependent with Initialization.
//    Click Add Study in the window toolbar.

    model.study().create("std2");
    model.study("std2").create("cdi", "CurrentDistributionInitialization");
    model.study("std2").feature("cdi").set("solnum", "auto");
    model.study("std2").feature("cdi").set("notsolnum", "auto");
    model.study("std2").feature("cdi").set("outputmap", new String[]{});
    model.study("std2").feature("cdi").set("ngenAUX", "1");
    model.study("std2").feature("cdi").set("goalngenAUX", "1");
    model.study("std2").feature("cdi").set("ngenAUX", "1");
    model.study("std2").feature("cdi").set("goalngenAUX", "1");
    model.study("std2").create("time", "Transient");
    model.study("std2").feature("time").set("initialtime", "0");
    model.study("std2").feature("time").set("plotgrouparr", new String[]{"Default"});
    model.study("std2").feature("time").set("solnum", "auto");
    model.study("std2").feature("time").set("notsolnum", "auto");
    model.study("std2").feature("time").set("outputmap", new String[]{});

//    In the Home toolbar, click Add Study to close the Add Study window.
//    Disable the first Load Cycle node in this study.
//    In the Model Builder window, expand the Study 2 node, then click Step 1: Current Distribution Initialization.
//    In the Settings window for Current Distribution Initialization, locate the Physics and Variables Selection section.
//    Select the Modify model configuration for study step checkbox.

    model.study("std2").feature("cdi").set("useadvanceddisable", true);

//    In the tree, select Component 1 (comp1) > Lithium-Ion Battery (liion) > Load Cycle 1 - Study 1.
//    Right-click and choose Disable.

    model.study("std2").feature("cdi").set("disabledphysics", new String[]{"liion/lc1"});

//    In the Model Builder window, click Step 2: Time Dependent.
//    In the Settings window for Time Dependent, locate the Study Settings section.
//    In the Output times text field, type 0 4000/C.

    model.study("std2").feature("time").set("tlist", "0 4000/C");

//    Locate the Physics and Variables Selection section.
//    Select the Modify model configuration for study step checkbox.

    model.study("std2").feature("time").set("useadvanceddisable", true);

//    In the tree, select Component 1 (comp1) > Lithium-Ion Battery (liion) > Load Cycle 1 - Study 1.
//    Right-click and choose Disable.

    model.study("std2").feature("time").set("disabledphysics", new String[]{"liion/lc1"});

//    Similarly, if you choose to run Study 1 again later, you need to disable the second Load Cycle node in that study.
//    Next, modify the default solver.
//    In the Study toolbar, click Parametric Sweep.

    model.study("std2").create("param", "Parametric");

//    In the Settings window for Parametric Sweep, locate the Study Settings section.
//    Click Add.

    model.study("std2").feature("param").setIndex("pname", "i_1C", 0);
    model.study("std2").feature("param").setIndex("plistarr", "", 0);
    model.study("std2").feature("param").setIndex("punit", "A/m^2", 0);

    return model;
  }

  public static Model run3(Model model) {
    model.study("std2").feature("param").setIndex("pname", "i_1C", 0);
    model.study("std2").feature("param").setIndex("plistarr", "", 0);
    model.study("std2").feature("param").setIndex("punit", "A/m^2", 0);

//    In the table, enter the following settings:

    model.study("std2").feature("param").setIndex("pname", "C", 0);
    model.study("std2").feature("param").setIndex("plistarr", "0.1 1 2 4", 0);

//    Store the actual steps taken by the solver to make sure to capture any sudden steep voltage changes.
//    In the Study toolbar, click Show Default Solver.

    model.study("std2").showAutoSequences("all");

//    In the Model Builder window, expand the Solution 3 (sol3) node, then click Time-Dependent Solver 1.
//    In the Settings window for Time-Dependent Solver, locate the General section.
//    From the Times to store list, select Steps taken by solver.

    model.sol("sol3").feature("t1").set("tout", "tsteps");

//    Store only every third time step. This reduces the size of the stored solution and the size of model file.
//    In the Store every 𝑁th step text field, type 3.

    model.sol("sol3").feature("t1").set("tstepsstore", 3);

//    In the Model Builder window, click Study 2.
//    In the Settings window for Study, locate the Study Settings section.
//    Clear the Generate default plots checkbox.

    model.study("std2").setGenPlots(false);

//    In the Study toolbar, click Compute.

    model.study("std2").createAutoSequences("all");

    model.sol().create("sol5");
    model.sol("sol5").study("std2");
    model.sol("sol5").label("Parametric Solutions 1");

    model.batch("p1").feature("so1").set("psol", "sol5");
    model.batch("p1").run("compute");

//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg9", "PlotGroup1D");
    model.result("pg9").run();

//    In the Settings window for 1D Plot Group, locate the Data section.
//    From the Dataset list, select Study 2/Parametric Solutions 1 (sol5).

    model.result("pg9").set("data", "dset5");

//    This dataset contains the battery model solutions for the parametric sweep in Study 2.
//    Right-click 1D Plot Group 9 and choose Point Graph.

    model.result("pg9").create("ptgr1", "PointGraph");
    model.result("pg9").feature("ptgr1").set("markerpos", "datapoints");
    model.result("pg9").feature("ptgr1").set("linewidth", "preference");

//    Select Boundary 4.

    model.result("pg9").feature("ptgr1").selection().set(4);

//    In the Settings window for Point Graph, click Replace Expression in the upper-right corner of the y-Axis Data section.
//    From the menu, choose Component 1 (comp1) > Lithium-Ion Battery > phis - Electric potential - V.

    model.result("pg9").feature("ptgr1").set("expr", "phis");
    model.result("pg9").feature("ptgr1").set("descr", "Electric potential");

//    Locate the x-Axis Data section.
//    From the Parameter list, select Expression.

    model.result("pg9").feature("ptgr1").set("xdata", "expr");

//    To obtain the capacity along the horizontal axis, multiply the time in hours by the discharge current.
//    In the Expression text field, type (t[s]/1[h])*C*I_1C/A_cell.

    model.result("pg9").feature("ptgr1").set("xdataexpr", "(t[s]/1[h])*C*I_1C/A_cell");

//    Click to expand the Legends section.
//    Select the Show legends checkbox.

    model.result("pg9").feature("ptgr1").set("legend", true);

//    From the Legends list, select Evaluated.

    model.result("pg9").feature("ptgr1").set("legendmethod", "evaluated");

//    In the Legend text field, type eval(C) C.

    model.result("pg9").feature("ptgr1").set("legendpattern", "eval(C) C");

//    In the 1D Plot Group 9 toolbar, click Plot.

    model.result("pg9").run();

//    Finish the plot by adding a title and axis labels and adjusting the axis ranges.

    model.result("pg9").run();

//    In the Model Builder window, click 1D Plot Group 9.
//    In the Settings window for 1D Plot Group, locate the Title section.
//    From the Title type list, select Manual.

    model.result("pg9").set("titletype", "manual");

//    In the Title text area, type Discharge curves.

    model.result("pg9").set("title", "Discharge curves");

//    Locate the Plot Settings section.
//    Select the x-axis label checkbox.

    model.result("pg9").set("xlabelactive", true);

//    In the associated text field, type Capacity (Ah/m<sup>2</sup>).

    model.result("pg9").set("xlabel", "Capacity (Ah/m<sup>2</sup>)");

//    Select the y-axis label checkbox.

    model.result("pg9").set("ylabelactive", true);

//    In the associated text field, type Voltage (V).

    model.result("pg9").set("ylabel", "Voltage (V)");

//    Locate the Axis section.
//    Select the Manual axis limits checkbox.

    model.result("pg9").set("axislimits", true);

//    In the x minimum text field, type 0.

    model.result("pg9").set("xmin", 0);

//    In the x maximum text field, type 19.

    model.result("pg9").set("xmax", 19);

//    In the y minimum text field, type 2.0.

    model.result("pg9").set("ymin", "2.0");

//    In the y maximum text field, type 4.4.

    model.result("pg9").set("ymax", 4.4);

//    In the 1D Plot Group 9 toolbar, click Plot.

    model.result("pg9").run();
    model.result("pg1").run();
    model.result("pg1").label("Load Cycle Voltage and Current");
    model.result("pg7").run();
    model.result("pg7").label("Voltage Losses Comparison");
    model.result("pg8").run();
    model.result("pg8").label("Solid Lithium Concentration");
    model.result("pg9").run();
    model.result("pg9").label("Discharge Curve Comparison");

    model.study("std1").feature("cdi").set("useadvanceddisable", true);
    model.study("std1").feature("cdi").set("disabledphysics", new String[]{"liion/lc2"});
    model.study("std1").feature("time").set("useadvanceddisable", true);
    model.study("std1").feature("time").set("disabledphysics", new String[]{"liion/lc2"});

    model.func("int1").createPlot("pg10");

    model.result("pg10").run();
    model.result("pg10").set("titletype", "none");
    model.result("pg10").set("xlabelactive", true);
    model.result("pg10").set("xlabel", "c<sub>s</sub>/c<sub>s, max</sub> (1)");
    model.result("pg10").set("ylabelactive", true);
    model.result("pg10").set("ylabel", "E<sub>eq, neg</sub> (V)");
    model.result("pg10").run();

    model.component("comp1").material("mat1").propertyGroup("def").func("int1").createPlot("pg11");

    model.result("pg11").run();
    model.result("pg11").set("titletype", "none");
    model.result("pg11").set("xlabelactive", true);
    model.result("pg11").set("xlabel", "c<sub>s</sub>/c<sub>s, max</sub> (1)");
    model.result("pg11").set("ylabelactive", true);
    model.result("pg11").set("ylabel", "E<sub>eq, pos</sub> (V)");
    model.result("pg11").run();

    model.component("comp1").material("mat2").propertyGroup("ElectrolyteConductivity").func("int1")
         .createPlot("pg12");

    model.result("pg12").run();
    model.result("pg12").set("titletype", "none");
    model.result("pg12").set("xlabelactive", true);
    model.result("pg12").set("xlabel", "c<sub>l</sub> (mol/m<sup>3</sup>)");
    model.result("pg12").set("ylabelactive", true);
    model.result("pg12").set("ylabel", "\\sigma<sub>l</sub> (S/m)");
    model.result("pg12").run();
    model.result("pg10").run();
    model.result().remove("pg10");
    model.result().remove("pg11");
    model.result().remove("pg12");
    model.result().dataset().remove("int1_ds1");
    model.result().dataset().remove("int1_ds2");
    model.result().dataset().remove("int1_ds3");

    model.title("1D Isothermal Lithium-Ion Battery");

    model
         .description("This example demonstrates the Lithium-Ion Battery interface for studying the discharge and charge of a battery. The geometry is in one dimension and the model is isothermal.");

    return model;
  }

  public static void main(String[] args) {
    Model model = run();
    model = run2(model);
    run3(model);
  }

}
