/*
 * nimh_battery_1d.java
 */

import com.comsol.model.*;
import com.comsol.model.util.*;

/** Model exported on May 15 2026, 11:25 by COMSOL 6.4.0.421. */
public class nimh_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 > Battery with Binary Electrolyte (batbe).
//    Click Add.
//    Click Study.
//    In the Select Study tree, select Preset Studies for Selected Physics Interfaces > Time Dependent with Initialization.
//    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("batbe", "BatteryBinaryElectrolyte", "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 nimh_battery_1d_parameters.txt.
//    To import content from file, use:
//    model.param().loadFile("FILENAME");
    model.param().set("L_neg", "350[um]", "Thickness, negative electrode");
    model.param().set("L_sep", "250[um]", "Thickness, separator");
    model.param().set("L_pos", "843[um]", "Thickness, positive electrode");
    model.param().set("sigmas_neg", "1000[S/cm]", "Electric conductivity, negative electrode");
    model.param().set("sigmas_pos", "25[S/cm]", "Electric conductivity, positive electrode");
    model.param().set("eps_l_neg", "0.4", "Electrolyte volume fraction, negative electrode");
    model.param().set("eps_l_pos", "0.3", "Electrolyte volume fraction, positive electrode");
    model.param().set("alpha_a_neg", "0.25", "Anodic transfer coefficient, negative electrode");
    model.param().set("alpha_a_pos", "0.13", "Anodic transfer coefficient, positive electrode");
    model.param().set("alpha_c_neg", "0.54", "Cathodic transfer coefficient, negative electrode");
    model.param().set("alpha_c_pos", "0.074", "Cathodic transfer coefficient, positive electrode");
    model.param().set("r_neg", "1.5[um]", "Electrode particle radius, negative electrode");
    model.param().set("r_pos", "2.5e-6[m]", "Electrode particle radius, positive electrode");
    model.param().set("i0_ref_neg", "8[A/m^2]", "Reference exchange current density, negative electrode");
    model.param().set("i0_ref_pos", "1[A/m^2]", "Reference exchange current density, positive electrode");
    model.param().set("T", "298[K]", "Operating temperature");
    model.param().set("cl_init", "6.91[mol/dm^3]", "Initial electrolyte concentration");
    model.param().set("M_K", "39.1[g/mol]", "Potassium molar mass");
    model.param().set("M_OH", "17[g/mol]", "Anion molar mass");
    model.param().set("M_H2O", "18[g/mol]", "Solvent molar mass");
    model.param().set("C1", "43[mA/cm^2]", "1 h discharge current");
    model.param().set("eps_s_neg", "0.5", "Electrode volume fraction, negative electrode");
    model.param().set("eps_s_pos", "0.5", "Electrode volume fraction, positive electrode");
    model.param().set("cl_ref", "6.91[mol/dm^3]", "Electrolyte salt reference concentration");
    model.param().set("c0_ref", "5e4[mol/m^3]", "Solvent (water) reference concentration");

//    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);

//    In the Home toolbar, click Build All.

    model.component("comp1").geom("geom1").run("fin");

//    Load the variables for this model from a text file.
//    In the Definitions toolbar, click Local Variables.

    model.component("comp1").variable().create("var1");

//    In the Settings window for Variables, locate the Variables section.
//    Click Load from File.
//    Browse to the model's Application Library folder and double-click the file nimh_battery_1d_variables.txt.
//    To import content from file, use:
//    model.component("comp1").variable("var1").loadFile("FILENAME");
    model.component("comp1").variable("var1")
         .set("cs_max_neg", "mat2.def.csmax", "Max intercalating concentration, negative electrode");
    model.component("comp1").variable("var1")
         .set("cs_max_pos", "mat3.def.csmax", "Max intercalating concentration, positive electrode");
    model.component("comp1").variable("var1")
         .set("cs_init_neg", "0.95*cs_max_neg", "Initial state of charge concentration, negative electrode");
    model.component("comp1").variable("var1")
         .set("cs_init_pos", "0.01*cs_max_pos", "Initial state of charge concentration, positive electrode");

//    In the Definitions toolbar, click Nonlocal Couplings and choose Integration.

    model.component("comp1").cpl().create("intop1", "Integration");
    model.component("comp1").cpl("intop1").set("axisym", true);

//    In the Settings window for Integration, locate the Source Selection section.
//    From the Geometric entity level list, select Boundary.

    model.component("comp1").cpl("intop1").selection().geom("geom1", 0);

//    Select Boundary 4.

    model.component("comp1").cpl("intop1").selection().set(4);

//    In the Operator name text field, type PositiveCC.

    model.component("comp1").cpl("intop1").set("opname", "PositiveCC");

//    Load the materials from the material library.
//    In the Materials toolbar, click Add Material to open the Add Material window.
//    In the tree, select Battery > Electrolytes > KOH (Liquid).
//    Right-click and choose Add to Component 1 (comp1).

    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("def").func().create("int3", "Interpolation");
    model.component("comp1").material("mat1").propertyGroup()
         .create("ElectrolyteConductivity", "ElectrolyteConductivity", "Electrolyte conductivity");
    model.component("comp1").material("mat1").propertyGroup()
         .create("SpeciesProperties", "SpeciesProperties", "Species properties");
    model.component("comp1").material("mat1").label("KOH (Liquid)");
    model.component("comp1").material("mat1").comments("\n");
    model.component("comp1").material("mat1").propertyGroup("def").func("int1").set("funcname", "A_rho");
    model.component("comp1").material("mat1").propertyGroup("def").func("int1")
         .set("table", new String[][]{{"0", "-0.5031"}, 
         {"5", "-0.4821"}, 
         {"10", "-0.5026"}, 
         {"15", "-0.482"}, 
         {"20", "-0.4824"}, 
         {"25", "-0.4931"}, 
         {"30", "-0.4812"}, 
         {"35", "-0.4918"}, 
         {"40", "-0.4863"}, 
         {"45", "-0.4912"}, 
         {"50", "-0.4756"}, 
         {"55", "-0.4898"}, 
         {"60", "-0.4916"}, 
         {"65", "-0.4906"}, 
         {"70", "-0.4876"}, 
         {"80", "-0.4942"}, 
         {"90", "-0.5021"}, 
         {"100", "-0.501"}, 
         {"150", "-0.5206"}, 
         {"200", "-0.5538"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("int1").set("filecolumns", 2);
    model.component("comp1").material("mat1").propertyGroup("def").func("int1")
         .set("columnKeys", new String[]{"col1", "col2"});
    model.component("comp1").material("mat1").propertyGroup("def").func("int1").set("fununit", new String[]{"1"});
    model.component("comp1").material("mat1").propertyGroup("def").func("int1").set("argunit", new String[]{"1"});
    model.component("comp1").material("mat1").propertyGroup("def").func("int2").set("funcname", "B_rho");
    model.component("comp1").material("mat1").propertyGroup("def").func("int2")
         .set("table", new String[][]{{"0", "45.876"}, 
         {"5", "45.648"}, 
         {"10", "45.889"}, 
         {"15", "45.659"}, 
         {"20", "45.649"}, 
         {"25", "45.761"}, 
         {"30", "45.568"}, 
         {"35", "45.698"}, 
         {"40", "45.601"}, 
         {"45", "45.62"}, 
         {"50", "45.336"}, 
         {"55", "45.543"}, 
         {"60", "45.53"}, 
         {"65", "45.45"}, 
         {"70", "45.396"}, 
         {"80", "45.409"}, 
         {"90", "45.432"}, 
         {"100", "45.361"}, 
         {"150", "45.217"}, 
         {"200", "45.173"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("int2").set("filecolumns", 2);
    model.component("comp1").material("mat1").propertyGroup("def").func("int2")
         .set("columnKeys", new String[]{"col1", "col2"});
    model.component("comp1").material("mat1").propertyGroup("def").func("int2")
         .set("funcnames", new String[]{"col1", "int2", "col2", "int1"});
    model.component("comp1").material("mat1").propertyGroup("def").func("int2").set("fununit", new String[]{"1"});
    model.component("comp1").material("mat1").propertyGroup("def").func("int2").set("argunit", new String[]{"1"});
    model.component("comp1").material("mat1").propertyGroup("def").func("int3").set("funcname", "C_rho");
    model.component("comp1").material("mat1").propertyGroup("def").func("int3")
         .set("table", new String[][]{{"0", "1004.4"}, 
         {"5", "1003.8"}, 
         {"10", "1002.5"}, 
         {"15", "1002"}, 
         {"20", "1001"}, 
         {"25", "999.63"}, 
         {"30", "998.66"}, 
         {"35", "996.7"}, 
         {"40", "994.89"}, 
         {"45", "992.84"}, 
         {"50", "991.51"}, 
         {"55", "988.4"}, 
         {"60", "985.91"}, 
         {"65", "983.39"}, 
         {"70", "980.71"}, 
         {"80", "974.59"}, 
         {"90", "967.98"}, 
         {"100", "960.99"}, 
         {"150", "919.52"}, 
         {"200", "869.35"}});
    model.component("comp1").material("mat1").propertyGroup("def").func("int3").set("filecolumns", 2);
    model.component("comp1").material("mat1").propertyGroup("def").func("int3")
         .set("columnKeys", new String[]{"col1", "col2"});
    model.component("comp1").material("mat1").propertyGroup("def").func("int3")
         .set("funcnames", new String[]{"col1", "int3", "col2", "int1"});
    model.component("comp1").material("mat1").propertyGroup("def").func("int3").set("fununit", new String[]{"1"});
    model.component("comp1").material("mat1").propertyGroup("def").func("int3").set("argunit", new String[]{"1"});
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("diffusion", new String[]{"3.75e-9[m^2/s]", "0", "0", "0", "3.75e-9[m^2/s]", "0", "0", "0", "3.75e-9[m^2/s]"});
    model.component("comp1").material("mat1").propertyGroup("def")
         .setPropertyInfo("diffusion", "B. Paxton and J. Newman,  J. Electrochem. Soc., vol. 144, no. 11, (1997) 3818\u20133831, ");
    model.component("comp1").material("mat1").propertyGroup("def").set("T_reg", "min(max(T,0[degC]),200[degC])");
    model.component("comp1").material("mat1").propertyGroup("def").descr("T_reg", "");
    model.component("comp1").material("mat1").propertyGroup("def").set("M_reg", "min(max(c,1e-6[M]),12[M])/1[M]");
    model.component("comp1").material("mat1").propertyGroup("def").descr("M_reg", "");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("density", "(A_rho(T_degC)*M_reg^2+B_rho(T_degC)*M_reg+C_rho(T_degC))*1[kg/m^3]");
    model.component("comp1").material("mat1").propertyGroup("def")
         .setPropertyInfo("density", "R.J. Gilliama, J.W. Graydonb, D.W. Kirkb, S.J. Thorpea, Int. J. Hydrogen Energy 32 (2007) 359 \u2013 364");
    model.component("comp1").material("mat1").propertyGroup("def").set("T_degC", "(T_reg-0[degC])/1[K]");
    model.component("comp1").material("mat1").propertyGroup("def").descr("T_degC", "");
    model.component("comp1").material("mat1").propertyGroup("def").addInput("concentration");
    model.component("comp1").material("mat1").propertyGroup("def").addInput("temperature");
    model.component("comp1").material("mat1").propertyGroup("ElectrolyteConductivity")
         .set("sigmal", new String[]{"(A*M+B*M^2+C*M*T_K+D*M/T_K+E*M^3+F*M^2*T_K^2)*1[S/cm]", "0", "0", "0", "(A*M+B*M^2+C*M*T_K+D*M/T_K+E*M^3+F*M^2*T_K^2)*1[S/cm]", "0", "0", "0", "(A*M+B*M^2+C*M*T_K+D*M/T_K+E*M^3+F*M^2*T_K^2)*1[S/cm]"});
    model.component("comp1").material("mat1").propertyGroup("ElectrolyteConductivity")
         .setPropertyInfo("sigmal", "R.J. Gilliama, J.W. Graydonb, D.W. Kirkb, S.J. Thorpea, Int. J. Hydrogen Energy 32 (2007) 359 \u2013 364");
    model.component("comp1").material("mat1").propertyGroup("ElectrolyteConductivity").set("T_K", "def.T_reg/1[K]");
    model.component("comp1").material("mat1").propertyGroup("ElectrolyteConductivity").descr("T_K", "");
    model.component("comp1").material("mat1").propertyGroup("ElectrolyteConductivity").set("M", "def.M_reg");
    model.component("comp1").material("mat1").propertyGroup("ElectrolyteConductivity").descr("M", "");
    model.component("comp1").material("mat1").propertyGroup("ElectrolyteConductivity").set("A", "-2.041");
    model.component("comp1").material("mat1").propertyGroup("ElectrolyteConductivity").descr("A", "");
    model.component("comp1").material("mat1").propertyGroup("ElectrolyteConductivity").set("B", "-0.0028");
    model.component("comp1").material("mat1").propertyGroup("ElectrolyteConductivity").descr("B", "");
    model.component("comp1").material("mat1").propertyGroup("ElectrolyteConductivity").set("C", "0.005332");
    model.component("comp1").material("mat1").propertyGroup("ElectrolyteConductivity").descr("C", "");
    model.component("comp1").material("mat1").propertyGroup("ElectrolyteConductivity").set("D", "207.2");
    model.component("comp1").material("mat1").propertyGroup("ElectrolyteConductivity").descr("D", "");
    model.component("comp1").material("mat1").propertyGroup("ElectrolyteConductivity").set("E", "0.001043");
    model.component("comp1").material("mat1").propertyGroup("ElectrolyteConductivity").descr("E", "");
    model.component("comp1").material("mat1").propertyGroup("ElectrolyteConductivity").set("F", "-0.0000003");
    model.component("comp1").material("mat1").propertyGroup("ElectrolyteConductivity").descr("F", "");
    model.component("comp1").material("mat1").propertyGroup("ElectrolyteConductivity").addInput("concentration");
    model.component("comp1").material("mat1").propertyGroup("ElectrolyteConductivity").addInput("temperature");
    model.component("comp1").material("mat1").propertyGroup("SpeciesProperties").set("transpNum", "0.22");
    model.component("comp1").material("mat1").propertyGroup("SpeciesProperties")
         .setPropertyInfo("transpNum", "B. Paxton and J. Newman,  J. Electrochem. Soc., vol. 144, no. 11, (1997) 3818\u20133831, ");
    model.component("comp1").material("mat1").propertyGroup("SpeciesProperties").set("fcl", "2");
    model.component("comp1").material("mat1").propertyGroup("SpeciesProperties")
         .setPropertyInfo("fcl", "B. Paxton and J. Newman,  J. Electrochem. Soc., vol. 144, no. 11, (1997) 3818\u20133831, ");

//    In the tree, select Battery > Electrodes > HxLiN5 (Negative, NiMH Battery).
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat2", "Common");
    model.component("comp1").material("mat2").propertyGroup("def").func().create("int1", "Interpolation");
    model.component("comp1").material("mat2").propertyGroup()
         .create("ElectrodePotential", "ElectrodePotential", "Equilibrium potential");
    model.component("comp1").material("mat2").propertyGroup()
         .create("OperationalSOC", "OperationalSOC", "Operational electrode state of charge");
    model.component("comp1").material("mat2").propertyGroup()
         .create("EquilibriumConcentration", "EquilibriumConcentration", "Equilibrium concentration");
    model.component("comp1").material("mat2").propertyGroup()
         .create("EquilibriumPotentialWithDOCInput", "EquilibriumPotentialWithDOCInput", "Equilibrium potential (using degree of conversion as model input)");
    model.component("comp1").material("mat2").propertyGroup()
         .create("EquilibriumDegreeOfConversion", "EquilibriumDegreeOfConversion", "Equilibrium degree of conversion");
    model.component("comp1").material("mat2").label("HxLiN5 (Negative, NiMH Battery)");
    model.component("comp1").material("mat2").comments("\n");
    model.component("comp1").material("mat2").propertyGroup("def").func("int1").set("funcname", "Eeq");
    model.component("comp1").material("mat2").propertyGroup("def").func("int1")
         .set("table", new String[][]{{"0.0100", "-0.5104"}, 
         {"0.0200", "-0.6421"}, 
         {"0.0300", "-0.7304"}, 
         {"0.0400", "-0.7896"}, 
         {"0.0500", "-0.8293"}, 
         {"0.0600", "-0.8559"}, 
         {"0.0700", "-0.8737"}, 
         {"0.0800", "-0.8857"}, 
         {"0.0900", "-0.8937"}, 
         {"0.1000", "-0.8991"}, 
         {"0.1100", "-0.9027"}, 
         {"0.1200", "-0.9051"}, 
         {"0.1300", "-0.9067"}, 
         {"0.1400", "-0.9078"}, 
         {"0.1500", "-0.9085"}, 
         {"0.1600", "-0.9090"}, 
         {"0.1700", "-0.9093"}, 
         {"0.1800", "-0.9096"}, 
         {"0.1900", "-0.9097"}, 
         {"0.2000", "-0.9098"}, 
         {"0.2200", "-0.9099"}, 
         {"0.5000", "-0.9100"}, 
         {"0.7800", "-0.9101"}, 
         {"0.8000", "-0.9102"}, 
         {"0.8100", "-0.9103"}, 
         {"0.8200", "-0.9104"}, 
         {"0.8300", "-0.9107"}, 
         {"0.8400", "-0.9110"}, 
         {"0.8500", "-0.9115"}, 
         {"0.8600", "-0.9122"}, 
         {"0.8700", "-0.9133"}, 
         {"0.8800", "-0.9149"}, 
         {"0.8900", "-0.9173"}, 
         {"0.9000", "-0.9209"}, 
         {"0.9100", "-0.9263"}, 
         {"0.9200", "-0.9343"}, 
         {"0.9300", "-0.9463"}, 
         {"0.9400", "-0.9641"}, 
         {"0.9500", "-0.9907"}, 
         {"0.9600", "-1.0304"}, 
         {"0.9700", "-1.0896"}, 
         {"0.9800", "-1.1779"}, 
         {"0.9900", "-1.3096"}});
    model.component("comp1").material("mat2").propertyGroup("def").func("int1").set("extrap", "linear");
    model.component("comp1").material("mat2").propertyGroup("def").func("int1").set("fununit", new String[]{"V"});
    model.component("comp1").material("mat2").propertyGroup("def").func("int1").set("argunit", new String[]{"1"});
    model.component("comp1").material("mat2").propertyGroup("def").func("int1").set("defineinv", true);
    model.component("comp1").material("mat2").propertyGroup("def").func("int1").set("funcinvname", "Eeq_inv");
    model.component("comp1").material("mat2").propertyGroup("def")
         .set("electricconductivity", new String[]{"1000[S/cm]", "0", "0", "0", "1000[S/cm]", "0", "0", "0", "1000[S/cm]"});
    model.component("comp1").material("mat2").propertyGroup("def")
         .set("diffusion", new String[]{"2e-12[m^2/s]", "0", "0", "0", "2e-12[m^2/s]", "0", "0", "0", "2e-12[m^2/s]"});
    model.component("comp1").material("mat2").propertyGroup("def")
         .setPropertyInfo("diffusion", "B. Paxton and J. Newman, \u201cModelling Nickel/Metal Hydride Batteries,\u201d J. Electrochem. Soc., vol. 144, p. 3818, 1997.");
    model.component("comp1").material("mat2").propertyGroup("def").set("density", "7490[kg/m^3]");
    model.component("comp1").material("mat2").propertyGroup("def")
         .setPropertyInfo("density", "W. B. Gu and C. Y. Wang, \u201cThermal-Electrochemical Modeling of Battery Systems,\u201d J. Electrochem. Soc., vol. 147, p. 2910, 2000.");
    model.component("comp1").material("mat2").propertyGroup("def").set("heatcapacity", "350[J/(kg*K)]");
    model.component("comp1").material("mat2").propertyGroup("def")
         .setPropertyInfo("heatcapacity", "W. B. Gu and C. Y. Wang, \u201cThermal-Electrochemical Modeling of Battery Systems,\u201d J. Electrochem. Soc., vol. 147, p. 2910, 2000.");
    model.component("comp1").material("mat2").propertyGroup("def").set("csmax", "0.1025e6[mol/m^3]");
    model.component("comp1").material("mat2").propertyGroup("def").descr("csmax", "");
    model.component("comp1").material("mat2").propertyGroup("ElectrodePotential").identifier("eeq");
    model.component("comp1").material("mat2").propertyGroup("ElectrodePotential").set("Eeq", "def.Eeq(doc)");
    model.component("comp1").material("mat2").propertyGroup("ElectrodePotential")
         .setPropertyInfo("Eeq", "P. Albertus, J. Christensen, and J. Newman, \u201cModelling Side Reactions and Nonisothermal Effects in Nickel Metal-Hydride Batteries,\u201d J. Electrochem. Soc., vol. 155, p. A48, 2008.");
    model.component("comp1").material("mat2").propertyGroup("ElectrodePotential").set("dEeqdT", "-0.836e-3[V/K]");
    model.component("comp1").material("mat2").propertyGroup("ElectrodePotential")
         .setPropertyInfo("dEeqdT", "W. B. Gu and C. Y. Wang, \u201cThermal-Electrochemical Modeling of Battery Systems,\u201d J. Electrochem. Soc., vol. 147, p. 2910, 2000.");
    model.component("comp1").material("mat2").propertyGroup("ElectrodePotential").set("cEeqref", "def.csmax");
    model.component("comp1").material("mat2").propertyGroup("ElectrodePotential")
         .setPropertyInfo("cEeqref", "P. Albertus, J. Christensen, and J. Newman, \u201cModelling Side Reactions and Nonisothermal Effects in Nickel Metal-Hydride Batteries,\u201d J. Electrochem. Soc., vol. 155, p. A48, 2008.");
    model.component("comp1").material("mat2").propertyGroup("ElectrodePotential").set("doc", "c/cEeqref");
    model.component("comp1").material("mat2").propertyGroup("ElectrodePotential")
         .descr("doc", "Degree of conversion");
    model.component("comp1").material("mat2").propertyGroup("ElectrodePotential").addInput("concentration");
    model.component("comp1").material("mat2").propertyGroup("OperationalSOC").identifier("opsoc");
    model.component("comp1").material("mat2").propertyGroup("OperationalSOC").set("socmax", "def.Eeq_inv(E_min)");
    model.component("comp1").material("mat2").propertyGroup("OperationalSOC").set("socmin", "def.Eeq_inv(E_max)");
    model.component("comp1").material("mat2").propertyGroup("OperationalSOC").set("E_max", "-0.6[V]");
    model.component("comp1").material("mat2").propertyGroup("OperationalSOC").set("E_min", "-1.2[V]");
    model.component("comp1").material("mat2").propertyGroup("EquilibriumConcentration")
         .set("csEq", "def.csmax*def.Eeq_inv(V)");
    model.component("comp1").material("mat2").propertyGroup("EquilibriumConcentration")
         .addInput("electricpotential");
    model.component("comp1").material("mat2").propertyGroup("EquilibriumPotentialWithDOCInput")
         .set("Eeq", "def.Eeq(doc)");
    model.component("comp1").material("mat2").propertyGroup("EquilibriumPotentialWithDOCInput")
         .set("dEeqdT", "-0.836e-3[V/K]");
    model.component("comp1").material("mat2").propertyGroup("EquilibriumPotentialWithDOCInput")
         .addInput("degreeofconversion");
    model.component("comp1").material("mat2").propertyGroup("EquilibriumDegreeOfConversion")
         .set("docEq", "def.Eeq_inv(V)");
    model.component("comp1").material("mat2").propertyGroup("EquilibriumDegreeOfConversion")
         .addInput("electricpotential");

//    In the tree, select Battery > Electrodes > NiOHO-Hx (Positive discharge, NiMH Battery).
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat3", "Common");
    model.component("comp1").material("mat3").propertyGroup("def").func().create("int1", "Interpolation");
    model.component("comp1").material("mat3").propertyGroup()
         .create("ElectrodePotential", "ElectrodePotential", "Equilibrium potential");
    model.component("comp1").material("mat3").propertyGroup()
         .create("OperationalSOC", "OperationalSOC", "Operational electrode state of charge");
    model.component("comp1").material("mat3").propertyGroup()
         .create("EquilibriumConcentration", "EquilibriumConcentration", "Equilibrium concentration");
    model.component("comp1").material("mat3").propertyGroup()
         .create("EquilibriumPotentialWithDOCInput", "EquilibriumPotentialWithDOCInput", "Equilibrium potential (using degree of conversion as model input)");
    model.component("comp1").material("mat3").propertyGroup()
         .create("EquilibriumDegreeOfConversion", "EquilibriumDegreeOfConversion", "Equilibrium degree of conversion");
    model.component("comp1").material("mat3").label("NiOHO-Hx (Positive discharge, NiMH Battery)");
    model.component("comp1").material("mat3").propertyGroup("def").func("int1").set("funcname", "Eeq");
    model.component("comp1").material("mat3").propertyGroup("def").func("int1")
         .set("table", new String[][]{{"0.0100", "0.1710"}, 
         {"0.0200", "0.2199"}, 
         {"0.0300", "0.2499"}, 
         {"0.0400", "0.2695"}, 
         {"0.0500", "0.2827"}, 
         {"0.0600", "0.2921"}, 
         {"0.0700", "0.2992"}, 
         {"0.0800", "0.3047"}, 
         {"0.0900", "0.3092"}, 
         {"0.1000", "0.3131"}, 
         {"0.1100", "0.3166"}, 
         {"0.1200", "0.3197"}, 
         {"0.1300", "0.3227"}, 
         {"0.1400", "0.3255"}, 
         {"0.1500", "0.3282"}, 
         {"0.1600", "0.3309"}, 
         {"0.1700", "0.3335"}, 
         {"0.1800", "0.3360"}, 
         {"0.1900", "0.3385"}, 
         {"0.2000", "0.3410"}, 
         {"0.2100", "0.3434"}, 
         {"0.2200", "0.3458"}, 
         {"0.2300", "0.3482"}, 
         {"0.2400", "0.3506"}, 
         {"0.2500", "0.3529"}, 
         {"0.2600", "0.3552"}, 
         {"0.2700", "0.3574"}, 
         {"0.2800", "0.3595"}, 
         {"0.2900", "0.3615"}, 
         {"0.3000", "0.3635"}, 
         {"0.3100", "0.3654"}, 
         {"0.3200", "0.3671"}, 
         {"0.3300", "0.3687"}, 
         {"0.3400", "0.3702"}, 
         {"0.3500", "0.3716"}, 
         {"0.3600", "0.3728"}, 
         {"0.3700", "0.3739"}, 
         {"0.3800", "0.3749"}, 
         {"0.3900", "0.3758"}, 
         {"0.4000", "0.3766"}, 
         {"0.4100", "0.3773"}, 
         {"0.4200", "0.3780"}, 
         {"0.4300", "0.3786"}, 
         {"0.4400", "0.3791"}, 
         {"0.4500", "0.3796"}, 
         {"0.4600", "0.3802"}, 
         {"0.4700", "0.3807"}, 
         {"0.4800", "0.3812"}, 
         {"0.4900", "0.3818"}, 
         {"0.5000", "0.3824"}, 
         {"0.5100", "0.3830"}, 
         {"0.5200", "0.3836"}, 
         {"0.5300", "0.3843"}, 
         {"0.5400", "0.3850"}, 
         {"0.5500", "0.3858"}, 
         {"0.5600", "0.3865"}, 
         {"0.5700", "0.3873"}, 
         {"0.5800", "0.3882"}, 
         {"0.5900", "0.3890"}, 
         {"0.6000", "0.3899"}, 
         {"0.6100", "0.3908"}, 
         {"0.6200", "0.3918"}, 
         {"0.6300", "0.3927"}, 
         {"0.6400", "0.3936"}, 
         {"0.6500", "0.3946"}, 
         {"0.6600", "0.3956"}, 
         {"0.6700", "0.3966"}, 
         {"0.6800", "0.3976"}, 
         {"0.6900", "0.3986"}, 
         {"0.7000", "0.3996"}, 
         {"0.7100", "0.4007"}, 
         {"0.7200", "0.4018"}, 
         {"0.7300", "0.4029"}, 
         {"0.7400", "0.4040"}, 
         {"0.7500", "0.4051"}, 
         {"0.7600", "0.4063"}, 
         {"0.7700", "0.4076"}, 
         {"0.7800", "0.4089"}, 
         {"0.7900", "0.4103"}, 
         {"0.8000", "0.4117"}, 
         {"0.8100", "0.4132"}, 
         {"0.8200", "0.4149"}, 
         {"0.8300", "0.4167"}, 
         {"0.8400", "0.4186"}, 
         {"0.8500", "0.4207"}, 
         {"0.8600", "0.4231"}, 
         {"0.8700", "0.4257"}, 
         {"0.8800", "0.4287"}, 
         {"0.8900", "0.4320"}, 
         {"0.9000", "0.4359"}, 
         {"0.9100", "0.4404"}, 
         {"0.9200", "0.4456"}, 
         {"0.9300", "0.4517"}, 
         {"0.9400", "0.4589"}, 
         {"0.9500", "0.4676"}, 
         {"0.9600", "0.4781"}, 
         {"0.9700", "0.4911"}, 
         {"0.9800", "0.5079"}, 
         {"0.9900", "0.5314"}});
    model.component("comp1").material("mat3").propertyGroup("def").func("int1").set("extrap", "linear");
    model.component("comp1").material("mat3").propertyGroup("def").func("int1").set("fununit", new String[]{"V"});
    model.component("comp1").material("mat3").propertyGroup("def").func("int1").set("argunit", new String[]{""});
    model.component("comp1").material("mat3").propertyGroup("def").func("int1").set("defineinv", true);
    model.component("comp1").material("mat3").propertyGroup("def").func("int1").set("funcinvname", "Eeq_inv");
    model.component("comp1").material("mat3").propertyGroup("def")
         .set("electricconductivity", new String[]{"25[S/cm]", "0", "0", "0", "25[S/cm]", "0", "0", "0", "25[S/cm]"});
    model.component("comp1").material("mat3").propertyGroup("def")
         .set("diffusion", new String[]{"1e-12[m^2/s]", "0", "0", "0", "1e-12[m^2/s]", "0", "0", "0", "1e-12[m^2/s]"});
    model.component("comp1").material("mat3").propertyGroup("def")
         .setPropertyInfo("diffusion", "B. Paxton and J. Newman, \u201cModelling Nickel/Metal Hydride Batteries,\u201d J. Electrochem. Soc., vol. 144, p. 3818, 1997");
    model.component("comp1").material("mat3").propertyGroup("def").set("density", "3550[kg/m^3]");
    model.component("comp1").material("mat3").propertyGroup("def")
         .setPropertyInfo("density", "W. B. Gu and C. Y. Wang, \u201cThermal-Electrochemical Modeling of Battery Systems,\u201d J. Electrochem. Soc., vol. 147, p. 2910, 2000.");
    model.component("comp1").material("mat3").propertyGroup("def").set("heatcapacity", "880[J/(kg*K)]");
    model.component("comp1").material("mat3").propertyGroup("def")
         .setPropertyInfo("heatcapacity", "W. B. Gu and C. Y. Wang, \u201cThermal-Electrochemical Modeling of Battery Systems,\u201d J. Electrochem. Soc., vol. 147, p. 2910, 2000.");
    model.component("comp1").material("mat3").propertyGroup("def").set("csmax", "0.0383[mol/cm^3]");
    model.component("comp1").material("mat3").propertyGroup("def").descr("csmax", "");
    model.component("comp1").material("mat3").propertyGroup("ElectrodePotential").identifier("eeq");
    model.component("comp1").material("mat3").propertyGroup("ElectrodePotential").set("Eeq", "def.Eeq(1-doc)");
    model.component("comp1").material("mat3").propertyGroup("ElectrodePotential")
         .setPropertyInfo("Eeq", "P. Albertus, J. Christensen, and J. Newman, \u201cModelling Side Reactions and Nonisothermal Effects in Nickel Metal-Hydride Batteries,\u201d J. Electrochem. Soc., vol. 155, p. A48, 2008.");
    model.component("comp1").material("mat3").propertyGroup("ElectrodePotential").set("dEeqdT", "-1.35e-3[V/K]");

    return model;
  }

  public static Model run2(Model model) {
    model.component("comp1").material("mat3").propertyGroup("ElectrodePotential")
         .setPropertyInfo("dEeqdT", "W. B. Gu and C. Y. Wang, \u201cThermal-Electrochemical Modeling of Battery Systems,\u201d J. Electrochem. Soc., vol. 147, p. 2910, 2000.");
    model.component("comp1").material("mat3").propertyGroup("ElectrodePotential").set("cEeqref", "def.csmax");
    model.component("comp1").material("mat3").propertyGroup("ElectrodePotential")
         .setPropertyInfo("cEeqref", "P. Albertus, J. Christensen, and J. Newman, \u201cModelling Side Reactions and Nonisothermal Effects in Nickel Metal-Hydride Batteries,\u201d J. Electrochem. Soc., vol. 155, p. A48, 2008.");
    model.component("comp1").material("mat3").propertyGroup("ElectrodePotential").set("doc", "c/cEeqref");
    model.component("comp1").material("mat3").propertyGroup("ElectrodePotential")
         .descr("doc", "Degree of conversion");
    model.component("comp1").material("mat3").propertyGroup("ElectrodePotential").addInput("concentration");
    model.component("comp1").material("mat3").propertyGroup("OperationalSOC").identifier("opsoc");
    model.component("comp1").material("mat3").propertyGroup("OperationalSOC").set("socmax", "def.Eeq_inv(E_min)");
    model.component("comp1").material("mat3").propertyGroup("OperationalSOC").set("socmin", "def.Eeq_inv(E_max)");
    model.component("comp1").material("mat3").propertyGroup("OperationalSOC").set("E_max", "0.53[V]");
    model.component("comp1").material("mat3").propertyGroup("OperationalSOC").set("E_min", "0.18[V]");
    model.component("comp1").material("mat3").propertyGroup("EquilibriumConcentration")
         .set("csEq", "def.csmax*(1-def.Eeq_inv(V))");
    model.component("comp1").material("mat3").propertyGroup("EquilibriumConcentration")
         .addInput("electricpotential");
    model.component("comp1").material("mat3").propertyGroup("EquilibriumPotentialWithDOCInput")
         .set("Eeq", "def.Eeq(1-doc)");
    model.component("comp1").material("mat3").propertyGroup("EquilibriumPotentialWithDOCInput")
         .set("dEeqdT", "-1.35e-3[V/K]");
    model.component("comp1").material("mat3").propertyGroup("EquilibriumPotentialWithDOCInput")
         .addInput("degreeofconversion");
    model.component("comp1").material("mat3").propertyGroup("EquilibriumDegreeOfConversion")
         .set("docEq", "(1-def.Eeq_inv(V))");
    model.component("comp1").material("mat3").propertyGroup("EquilibriumDegreeOfConversion")
         .addInput("electricpotential");

//    In the Materials toolbar, click Add Material to close the Add Material window.
//    In the Settings window for Battery with Binary Electrolyte, locate the Species section.
//    In the \[M_{\textrm{An-}}\] text field, type M_OH.

    model.component("comp1").physics("batbe").prop("BatBeSpecies").set("ManMinus", "M_OH");

//    In the \[M_{\textrm{Cat+}}\] text field, type M_K.

    model.component("comp1").physics("batbe").prop("BatBeSpecies").set("McatPlus", "M_K");

//    In the \[M_{\textrm 0}\] text field, type M_H2O.

    model.component("comp1").physics("batbe").prop("BatBeSpecies").set("M0", "M_H2O");

//    In the Model Builder window, under Component 1 (comp1) > Battery with Binary Electrolyte (batbe), 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("batbe").feature("sep1").set("epsl", 1);

//    In the Physics toolbar, click Domains and choose Porous Electrode.

    model.component("comp1").physics("batbe").create("pce1", "PorousElectrode", 1);

//    Select Domain 1.

    model.component("comp1").physics("batbe").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 sigmas_neg.

    model.component("comp1").physics("batbe").feature("pce1")
         .set("sigma", new String[]{"sigmas_neg", "0", "0", "0", "sigmas_neg", "0", "0", "0", "sigmas_neg"});

//    Locate the Porous Matrix Properties section.
//    In the \[\epsilon_{\textrm{s}}\] text field, type eps_s_neg.

    model.component("comp1").physics("batbe").feature("pce1").set("epss", "eps_s_neg");

//    In the \[\epsilon_{\textrm{l}}\] text field, type eps_l_neg.

    model.component("comp1").physics("batbe").feature("pce1").set("epsl", "eps_l_neg");

//    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 HxLiN5 (Negative, NiMH Battery) (mat2).

    model.component("comp1").physics("batbe").feature("pce1").feature("pin1").set("ParticleMaterial", "mat2");

//    Locate the Species Settings section.
//    In the \[c_{\textrm{s,init}}\] text field, type cs_init_neg.

    model.component("comp1").physics("batbe").feature("pce1").feature("pin1").set("csinit", "cs_init_neg");

//    Locate the Particle Transport Properties section.
//    In the \[r_{\textrm{p}}\] text field, type r_neg.

    model.component("comp1").physics("batbe").feature("pce1").feature("pin1").set("rp", "r_neg");

//    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 HxLiN5 (Negative, NiMH Battery) (mat2).

    model.component("comp1").physics("batbe").feature("pce1").feature("per1").set("MaterialOption", "mat2");

//    Locate the Electrode Kinetics section.
//    In the \[i_{\textrm{0,ref}}\left(T\right)\] text field, type i0_ref_neg.

    model.component("comp1").physics("batbe").feature("pce1").feature("per1").set("i0_ref", "i0_ref_neg");

//    In the \[\alpha_{\textrm{a}}\] text field, type alpha_a_neg.

    model.component("comp1").physics("batbe").feature("pce1").feature("per1").set("alphaa", "alpha_a_neg");

//    In the \[\alpha_{\textrm{c}}\] text field, type alpha_c_neg.

    model.component("comp1").physics("batbe").feature("pce1").feature("per1").set("alphac", "alpha_c_neg");

//    In the \[c_{\textrm{l,ref}}\] text field, type cl_ref.

    model.component("comp1").physics("batbe").feature("pce1").feature("per1").set("cl_ref", "cl_ref");

//    In the \[c_{\textrm{0,ref}}\] text field, type c0_ref.

    model.component("comp1").physics("batbe").feature("pce1").feature("per1").set("c0_ref", "c0_ref");

//    In the Physics toolbar, click Domains and choose Porous Electrode.

    model.component("comp1").physics("batbe").create("pce2", "PorousElectrode", 1);

//    Select Domain 3.

    model.component("comp1").physics("batbe").feature("pce2").selection().set(3);

//    In the Settings window for Porous Electrode, locate the Electrode Properties section.
//    In the \[\sigma_{\textrm{s}}\] text field, type sigmas_pos.

    model.component("comp1").physics("batbe").feature("pce2")
         .set("sigma", new String[]{"sigmas_pos", "0", "0", "0", "sigmas_pos", "0", "0", "0", "sigmas_pos"});

//    Locate the Porous Matrix Properties section.
//    In the \[\epsilon_{\textrm{s}}\] text field, type eps_s_pos.

    model.component("comp1").physics("batbe").feature("pce2").set("epss", "eps_s_pos");

//    In the \[\epsilon_{\textrm{l}}\] text field, type eps_l_pos.

    model.component("comp1").physics("batbe").feature("pce2").set("epsl", "eps_l_pos");

//    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 NiOHO-Hx (Positive discharge, NiMH Battery) (mat3).

    model.component("comp1").physics("batbe").feature("pce2").feature("pin1").set("ParticleMaterial", "mat3");

//    Locate the Species Settings section.
//    In the \[c_{\textrm{s,init}}\] text field, type cs_init_pos.

    model.component("comp1").physics("batbe").feature("pce2").feature("pin1").set("csinit", "cs_init_pos");

//    Locate the Particle Transport Properties section.
//    In the \[r_{\textrm{p}}\] text field, type r_pos.

    model.component("comp1").physics("batbe").feature("pce2").feature("pin1").set("rp", "r_pos");

//    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 NiOHO-Hx (Positive discharge, NiMH Battery) (mat3).

    model.component("comp1").physics("batbe").feature("pce2").feature("per1").set("MaterialOption", "mat3");

//    Locate the Electrode Kinetics section.
//    In the \[i_{\textrm{0,ref}}\left(T\right)\] text field, type i0_ref_pos.

    model.component("comp1").physics("batbe").feature("pce2").feature("per1").set("i0_ref", "i0_ref_pos");

//    In the \[\alpha_{\textrm{a}}\] text field, type alpha_a_pos.

    model.component("comp1").physics("batbe").feature("pce2").feature("per1").set("alphaa", "alpha_a_pos");

//    In the \[\alpha_{\textrm{c}}\] text field, type alpha_c_pos.

    model.component("comp1").physics("batbe").feature("pce2").feature("per1").set("alphac", "alpha_c_pos");

//    In the \[c_{\textrm{l,ref}}\] text field, type cl_ref.

    model.component("comp1").physics("batbe").feature("pce2").feature("per1").set("cl_ref", "cl_ref");

//    In the \[c_{\textrm{0,ref}}\] text field, type c0_ref.

    model.component("comp1").physics("batbe").feature("pce2").feature("per1").set("c0_ref", "c0_ref");

//    In the Physics toolbar, click Boundaries and choose Electric Ground.

    model.component("comp1").physics("batbe").create("egnd1", "ElectricGround", 0);

//    Select Boundary 1.

    model.component("comp1").physics("batbe").feature("egnd1").selection().set(1);

//    In the Physics toolbar, click Boundaries and choose Electrode Current Density.

    model.component("comp1").physics("batbe").create("ecd1", "ElectrodeNormalCurrentDensity", 0);

//    Select Boundary 4.

    model.component("comp1").physics("batbe").feature("ecd1").selection().set(4);

//    In the Settings window for Electrode Current Density, locate the Electrode Current Density section.
//    In the \[i_{n\textrm{,s}}\] text field, type -C1/10.

    model.component("comp1").physics("batbe").feature("ecd1").set("nis", "-C1/10");

//    Set up the initial value for the electrolyte concentration. The initial values for the potentials, corresponding to the initial state of charge values for the electrodes, will be calculated automatically in the Current Distribution Initialization study step.
//    In the Model Builder window, click Initial Values 1.
//    In the Settings window for Initial Values, locate the Initial Values section.
//    In the \[cl\] text field, type cl_init.

    model.component("comp1").physics("batbe").feature("init1").set("cl", "cl_init");

//    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 solver to solve for the specified discharge rate.
//    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,600,36000).

    model.study("std1").feature("time").set("tlist", "range(0,600,36000)");

//    In the Study toolbar, click Show Default Solver.

    model.study("std1").showAutoSequences("all");

//    In the Model Builder window, expand the Solution 1 (sol1) node.
//    Right-click Study 1 > Solver Configurations > Solution 1 (sol1) > Time-Dependent Solver 1 and choose Stop Condition.

    model.sol("sol1").feature("t1").create("st1", "StopCondition");

//    In the Settings window for Stop Condition, locate the Stop Expressions section.
//    Click Add.

    model.sol("sol1").feature("t1").feature("st1").setIndex("stopcondarr", "", 0);
    model.sol("sol1").feature("t1").feature("st1").setIndex("stopcondterminateon", "true", 0);
    model.sol("sol1").feature("t1").feature("st1").setIndex("stopcondActive", true, 0);
    model.sol("sol1").feature("t1").feature("st1").setIndex("stopconddesc", "Stop expression 1", 0);
    model.sol("sol1").feature("t1").feature("st1").setIndex("stopcondarr", "", 0);
    model.sol("sol1").feature("t1").feature("st1").setIndex("stopcondterminateon", "true", 0);
    model.sol("sol1").feature("t1").feature("st1").setIndex("stopcondActive", true, 0);
    model.sol("sol1").feature("t1").feature("st1").setIndex("stopconddesc", "Stop expression 1", 0);

//    In the table, enter the following settings:

    model.sol("sol1").feature("t1").feature("st1").setIndex("stopcondarr", "comp1.PositiveCC(comp1.phis)<0.99", 0);

//    Specify that the solution is to be stored both before and after the stop condition is reached.
//    Locate the Output at Stop section.
//    From the Add solution list, select Steps before and after stop.

    model.sol("sol1").feature("t1").feature("st1").set("storestopcondsol", "stepbefore_stepafter");

//    Clear the Add information checkbox.

    model.sol("sol1").feature("t1").feature("st1").set("stopcondwarn", false);

//    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 (batbe)");
    model.result("pg1").set("titletype", "none");
    model.result("pg1").set("showlegends", false);
    model.result("pg1").create("ptgr1", "PointGraph");
    model.result("pg1").feature("ptgr1").set("expr", new String[]{"phis"});
    model.result("pg1").feature("ptgr1").selection().set(4);
    model.result("pg1").feature("ptgr1").set("xdatasolnumtype", "level1");
    model.result("pg1").feature("ptgr1").set("legend", true);
    model.result("pg1").feature("ptgr1").set("autopoint", false);
    model.result("pg1").feature("ptgr1").set("autosolution", false);
    model.result("pg1").feature("ptgr1").set("autodescr", true);
    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[]{"batbe.soc_average_pce1", "batbe.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 (batbe)");
    model.result().create("pg3", "PlotGroup1D");
    model.result("pg3").set("data", "dset1");
    model.result("pg3").label("Electrode Potential with Respect to Adjacent Reference (batbe)");
    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[]{"batbe.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 (batbe)");
    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 (batbe)");
    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[]{"batbe.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 (batbe)");
    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[]{"batbe.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();

//    In the Settings window for 1D Plot Group, type Cell voltage in the Label text field.

    model.result("pg1").label("Cell voltage");

//    Click to expand the Title section.
//    From the Title type list, select Manual.

    model.result("pg1").set("titletype", "manual");

//    In the Title text area, type Cell voltages for different discharge rates.

    model.result("pg1").set("title", "Cell voltages for different discharge rates");

//    Locate the Plot Settings section.
//    Select the x-axis label checkbox.

    model.result("pg1").set("xlabelactive", true);

//    In the associated text field, type Utilization.

    model.result("pg1").set("xlabel", "Utilization");

//    Select the y-axis label checkbox.

    model.result("pg1").set("ylabelactive", true);

//    In the associated text field, type Cell voltage (V).

    model.result("pg1").set("ylabel", "Cell voltage (V)");

//    Locate the Legend section.
//    Select the Show legends checkbox.

    model.result("pg1").set("showlegends", true);
    model.result("pg1").run();

//    In the Model Builder window, expand the Cell voltage node, then click Point Graph 1.
//    In the Settings window for Point Graph, locate the x-Axis Data section.
//    From the Parameter list, select Expression.

    model.result("pg1").feature("ptgr1").set("xdata", "expr");

//    In the Expression text field, type t/36000.

    model.result("pg1").feature("ptgr1").set("xdataexpr", "t/36000");

//    Click to expand the Legends section.
//    From the Legends list, select Manual.

    model.result("pg1").feature("ptgr1").set("legendmethod", "manual");

//    In the table, enter the following settings:

    model.result("pg1").feature("ptgr1").setIndex("legends", "C/10", 0);

//    Now, modify the current density to study a different discharge rate, and create a new study to compare the results.
//    In the Model Builder window, under Component 1 (comp1) > Battery with Binary Electrolyte (batbe), click Electrode Current Density 1.
//    In the Settings window for Electrode Current Density, locate the Electrode Current Density section.
//    In the \[i_{n\textrm{,s}}\] text field, type -C1.

    model.component("comp1").physics("batbe").feature("ecd1").set("nis", "-C1");

//    Make a copy of the solution and resolve the problem.
//    In the Study toolbar, click Create Solution Copy.

    model.sol("sol1").copySolution("sol3");

//    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 range(0,60,3600).

    model.study("std1").feature("time").set("tlist", "range(0,60,3600)");

//    In the Study toolbar, click Compute.

    model.study("std1").createAutoSequences("all");

    model.sol("sol1").runAll();

    model.result("pg1").run();
    model.result("pg1").run();

//    In the Model Builder window, right-click Results > Cell voltage > Point Graph 1 and choose Duplicate.

    model.result("pg1").feature().duplicate("ptgr2", "ptgr1");
    model.result("pg1").run();
    model.result("pg1").run();

//    In the Settings window for Point Graph, locate the x-Axis Data section.
//    In the Expression text field, type t/3600.

    model.result("pg1").feature("ptgr1").set("xdataexpr", "t/3600");

//    Locate the Legends section.
//    In the table, enter the following settings:

    model.result("pg1").feature("ptgr1").setIndex("legends", "1C", 0);
    model.result("pg1").run();

//    In the Model Builder window, click Point Graph 2.
//    In the Settings window for Point Graph, locate the Data section.
//    From the Dataset list, select Study 1/Solution 1 - Copy 1 (sol3).

    model.result("pg1").feature("ptgr2").set("data", "dset3");

//    In the Cell voltage toolbar, click Plot.

    model.result("pg1").run();
    model.result("pg2").run();

//    In the Model Builder window, under Results, click Average Electrode State of Charge (batbe).
//    In the Settings window for 1D Plot Group, locate the Title section.
//    From the Title type list, select Label.

    model.result("pg2").set("titletype", "label");

//    In the Average Electrode State of Charge (batbe) toolbar, click Plot.

    model.result("pg2").run();
    model.result("pg4").run();
    model.result("pg5").run();
    model.result("pg6").run();

//    In the Home toolbar, click Add Plot Group and choose 1D Plot Group.

    model.result().create("pg7", "PlotGroup1D");
    model.result("pg7").run();

//    In the Settings window for 1D Plot Group, locate the Data section.
//    From the Time selection list, select From list.

    model.result("pg7").setIndex("looplevelinput", "manual", 0);

//    In the Times (s) list, select 600.

    model.result("pg7").setIndex("looplevel", new int[]{11}, 0);

//    select 600 in the Times (s) list.
//    Locate the Title section.
//    From the Title type list, select Manual.

    model.result("pg7").set("titletype", "manual");

//    In the Title text area, type Comparison of voltage losses at t=600 s.

    model.result("pg7").set("title", "Comparison of voltage losses at t=600 s");

//    Locate the Plot Settings section.
//    Select the x-axis label checkbox.

    model.result("pg7").set("xlabelactive", true);

//    In the associated text field, type x (m).

    model.result("pg7").set("xlabel", "x (m)");

//    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)");

//    Right-click 1D Plot Group 7 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 Selection section.
//    From the Selection list, select All domains.

    model.result("pg7").feature("lngr1").selection().all();

//    Click to expand the Legends section.
//    Select the Show legends checkbox.

    model.result("pg7").feature("lngr1").set("legend", true);

//    From the Legends list, select Manual.

    model.result("pg7").feature("lngr1").set("legendmethod", "manual");

//    In the table, enter the following settings:

    model.result("pg7").feature("lngr1").setIndex("legends", "Electrolyte potential -0.91 V", 0);

//    Locate the y-Axis Data section.
//    In the Expression text field, type phil-0.91.

    model.result("pg7").feature("lngr1").set("expr", "phil-0.91");
    model.result("pg7").run();

//    In the Model Builder window, right-click 1D Plot Group 7 and choose Line Graph.

    model.result("pg7").create("lngr2", "LineGraph");
    model.result("pg7").feature("lngr2").set("markerpos", "datapoints");
    model.result("pg7").feature("lngr2").set("linewidth", "preference");
    model.result("pg7").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("pg7").feature("lngr2").selection().all();

//    Locate the y-Axis Data section.
//    In the Expression text field, type batbe.eta_per1.

    model.result("pg7").feature("lngr2").set("expr", "batbe.eta_per1");

//    Locate the Legends section.
//    Select the Show legends checkbox.

    model.result("pg7").feature("lngr2").set("legend", true);

//    From the Legends list, select Manual.

    model.result("pg7").feature("lngr2").set("legendmethod", "manual");

//    In the table, enter the following settings:

    model.result("pg7").feature("lngr2").setIndex("legends", "Overpotential", 0);

//    In the 1D Plot Group 7 toolbar, click Plot.

    model.result("pg7").run();
    model.result("pg7").run();

//    In the Model Builder window, under Results, click 1D Plot Group 7.
//    In the Settings window for 1D Plot Group, type Voltage losses in the Label text field.

    model.result("pg7").label("Voltage losses");
    model.result("pg6").run();

    model.title("1D Isothermal Nickel\u2013Metal Hydride Battery");

    model
         .description("This example uses the Battery with Binary Electrolyte interface for studying the discharge of a nickel\u2013metal hydride battery. The geometry is in one dimension and the model is isothermal.");

    return model;
  }

  public static void main(String[] args) {
    Model model = run();
    run2(model);
  }

}
