/*
 * eeprom.java
 */

import com.comsol.model.*;
import com.comsol.model.util.*;

/** Model exported on May 14 2026, 09:17 by COMSOL 6.4.0.420. */
public class eeprom {

  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 2D.
//    In the Select Physics tree, select Semiconductor > Semiconductor (semi).
//    Click Add.
//    Click Study.
//    In the Select Study tree, select General Studies > Stationary.
//    Click Done.

    model.component().create("comp1", true);

    model.component("comp1").geom().create("geom1", 2);

    model.component("comp1").mesh().create("mesh1");

    model.component("comp1").physics().create("semi", "Semiconductor", "geom1");

    model.study().create("std1");
    model.study("std1").create("stat", "Stationary");

//    For convenience, the device geometry will be inserted from an existing file. Once the geometry sequence is inserted it can be explored, in the usual way by clicking through the nodes in the Model Builder, if desired.
//    In the Geometry toolbar, click Insert Sequence and choose Insert Sequence.

    model.component("comp1").geom("geom1").insertFile("eeprom_geom_sequence.mph", "geom1");

//    Browse to the model's Application Library folder and double-click the file eeprom_geom_sequence.mph.
//    Add a line to help make mesh later.
//    In the Geometry toolbar, click More Primitives and choose Line Segment.

    model.component("comp1").geom("geom1").run("pt1");
    model.component("comp1").geom("geom1").create("ls1", "LineSegment");

//    In the Settings window for Line Segment, locate the Starting Point section.
//    From the Specify list, select Coordinates.

    model.component("comp1").geom("geom1").feature("ls1").set("specify1", "coord");

//    In the x text field, type 0.05.

    model.component("comp1").geom("geom1").feature("ls1").set("coord1", new double[]{0.05, 0});

//    In the y text field, type -0.01.

    model.component("comp1").geom("geom1").feature("ls1").set("coord1", new double[]{0.05, -0.01});

//    Locate the Endpoint section.
//    From the Specify list, select Coordinates.

    model.component("comp1").geom("geom1").feature("ls1").set("specify2", "coord");

//    In the x text field, type 0.85.

    model.component("comp1").geom("geom1").feature("ls1").set("coord2", new double[]{0.85, 0});

//    In the y text field, type -0.01.

    model.component("comp1").geom("geom1").feature("ls1").set("coord2", new double[]{0.85, -0.01});

//    Click Build All Objects.

    model.component("comp1").geom("geom1").runPre("fin");

//    In the Geometry toolbar, click Virtual Operations and choose Mesh Control Edges.

    model.component("comp1").geom("geom1").run("fin");
    model.component("comp1").geom("geom1").create("mce1", "MeshControlEdges");

//    On the object fin, select Boundaries 18, 22.

    model.component("comp1").geom("geom1").feature("mce1").selection("input").set("fin", 18, 22);

//    It might be easier to select the correct boundaries by using the <l>Selection List</l> window. To open this window, in the <l>Home</l> toolbar click <l>Windows</l> and choose <l>Selection List</l>. (If you are running the cross-platform desktop, you find <l>Windows</l> in the main menu.)
//    Add materials to the geometry, the Silicon (Si) material from the semiconductor material menu will be used for the semiconductor region and a blank material with the permittivity of Silicon Oxide (SiO2) will be used for the oxide layer.

    model.component("comp1").geom("geom1").run();

//    In the Materials toolbar, click Add Material to open the Add Material window.
//    In the tree, select Semiconductors > Si - Silicon.
//    Click Add to Component in the window toolbar.

    model.component("comp1").material().create("mat1", "Common");
    model.component("comp1").material("mat1").propertyGroup()
         .create("AroraMobilityModel", "AroraMobilityModel", "Arora mobility model");
    model.component("comp1").material("mat1").propertyGroup()
         .create("PowerLawMobilityModel", "PowerLawMobilityModel", "Power law mobility model");
    model.component("comp1").material("mat1").propertyGroup().create("Auger", "Auger", "Auger recombination");
    model.component("comp1").material("mat1").propertyGroup().create("Direct", "Direct", "Direct recombination");
    model.component("comp1").material("mat1").propertyGroup()
         .create("SRH", "SRH", "Shockley\u2013Read\u2013Hall recombination");
    model.component("comp1").material("mat1").propertyGroup()
         .create("FletcherMobilityModel", "FletcherMobilityModel", "Fletcher mobility model");
    model.component("comp1").material("mat1").propertyGroup()
         .create("CaugheyThomasMobilityModel", "CaugheyThomasMobilityModel", "Caughey\u2013Thomas mobility model");
    model.component("comp1").material("mat1").propertyGroup()
         .create("SemicondMaterial", "SemicondMaterial", "Semiconductor material");
    model.component("comp1").material("mat1").propertyGroup()
         .create("LombardiSurfaceMobilityModel", "LombardiSurfaceMobilityModel", "Lombardi surface mobility model");
    model.component("comp1").material("mat1").propertyGroup()
         .create("ImpactIonization", "ImpactIonization", "Impact ionization");
    model.component("comp1").material("mat1").propertyGroup()
         .create("SlotboomModel", "SlotboomModel", "Slotboom model");
    model.component("comp1").material("mat1").propertyGroup()
         .create("JainRoulstonModel", "JainRoulstonModel", "Jain\u2013Roulston model");
    model.component("comp1").material("mat1").propertyGroup()
         .create("KlaassenUnifiedMobilityModel", "KlaassenUnifiedMobilityModel", "Klaassen unified mobility model");
    model.component("comp1").material("mat1").label("Si - Silicon");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("relpermittivity", new String[]{"11.7", "0", "0", "0", "11.7", "0", "0", "0", "11.7"});
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("thermalconductivity", new String[]{"131[W/(m*K)]", "0", "0", "0", "131[W/(m*K)]", "0", "0", "0", "131[W/(m*K)]"});
    model.component("comp1").material("mat1").propertyGroup("def").set("density", "2329[kg/m^3]");
    model.component("comp1").material("mat1").propertyGroup("def").set("heatcapacity", "700[J/(kg*K)]");
    model.component("comp1").material("mat1").propertyGroup("AroraMobilityModel")
         .set("mun0_ref_arora", "1252[cm^2/(V*s)]");
    model.component("comp1").material("mat1").propertyGroup("AroraMobilityModel")
         .set("mup0_ref_arora", "407[cm^2/(V*s)]");
    model.component("comp1").material("mat1").propertyGroup("AroraMobilityModel")
         .set("mun_min_ref_arora", "88[cm^2/(V*s)]");
    model.component("comp1").material("mat1").propertyGroup("AroraMobilityModel")
         .set("mup_min_ref_arora", "54.3[cm^2/(V*s)]");
    model.component("comp1").material("mat1").propertyGroup("AroraMobilityModel")
         .set("Nn0_ref_arora", "1.26e17[1/cm^3]");
    model.component("comp1").material("mat1").propertyGroup("AroraMobilityModel")
         .set("Np0_ref_arora", "2.35e17[1/cm^3]");
    model.component("comp1").material("mat1").propertyGroup("AroraMobilityModel").set("alpha0_arora", "0.88");
    model.component("comp1").material("mat1").propertyGroup("AroraMobilityModel").set("beta1_arora", "-0.57");
    model.component("comp1").material("mat1").propertyGroup("AroraMobilityModel").set("beta2_arora", "-2.33");
    model.component("comp1").material("mat1").propertyGroup("AroraMobilityModel").set("beta3_arora", "-2.33");
    model.component("comp1").material("mat1").propertyGroup("AroraMobilityModel").set("beta4_arora", "-0.146");
    model.component("comp1").material("mat1").propertyGroup("AroraMobilityModel").set("Tref_arora", "300[K]");
    model.component("comp1").material("mat1").propertyGroup("PowerLawMobilityModel")
         .set("mun0_pl", "1448[cm^2/(V*s)]");
    model.component("comp1").material("mat1").propertyGroup("PowerLawMobilityModel")
         .set("mup0_pl", "473[cm^2/(V*s)]");
    model.component("comp1").material("mat1").propertyGroup("PowerLawMobilityModel").set("alphan_pl", "2.33");
    model.component("comp1").material("mat1").propertyGroup("PowerLawMobilityModel").set("alphap_pl", "2.23");
    model.component("comp1").material("mat1").propertyGroup("PowerLawMobilityModel").set("Tref_pl", "300[K]");
    model.component("comp1").material("mat1").propertyGroup("Auger").set("Cn", "2.8e-31[cm^6/s]");
    model.component("comp1").material("mat1").propertyGroup("Auger").set("Cp", "9.9e-32[cm^6/s]");
    model.component("comp1").material("mat1").propertyGroup("Direct").set("C", "0[cm^3/s]");
    model.component("comp1").material("mat1").propertyGroup("SRH").set("taun", "10[us]");
    model.component("comp1").material("mat1").propertyGroup("SRH").set("taup", "10[us]");
    model.component("comp1").material("mat1").propertyGroup("FletcherMobilityModel")
         .set("F1_fl", "1.04e21[1/(cm^1*V*s)]");
    model.component("comp1").material("mat1").propertyGroup("FletcherMobilityModel").set("F2_fl", "7.45e13[1/cm^2]");
    model.component("comp1").material("mat1").propertyGroup("FletcherMobilityModel").set("Tref_fl", "300[K]");
    model.component("comp1").material("mat1").propertyGroup("CaugheyThomasMobilityModel").set("alphan0_ct", "1.11");
    model.component("comp1").material("mat1").propertyGroup("CaugheyThomasMobilityModel").set("alphap0_ct", "1.21");
    model.component("comp1").material("mat1").propertyGroup("CaugheyThomasMobilityModel").set("vn0_ct", "1e7[cm/s]");
    model.component("comp1").material("mat1").propertyGroup("CaugheyThomasMobilityModel")
         .set("vp0_ct", "8.37e6[cm/s]");
    model.component("comp1").material("mat1").propertyGroup("CaugheyThomasMobilityModel").set("betan1_ct", "0.66");
    model.component("comp1").material("mat1").propertyGroup("CaugheyThomasMobilityModel").set("betap1_ct", "0.17");
    model.component("comp1").material("mat1").propertyGroup("CaugheyThomasMobilityModel").set("betan2_ct", "-0.87");
    model.component("comp1").material("mat1").propertyGroup("CaugheyThomasMobilityModel").set("betap2_ct", "-0.52");
    model.component("comp1").material("mat1").propertyGroup("CaugheyThomasMobilityModel").set("Tref_ct", "300[K]");
    model.component("comp1").material("mat1").propertyGroup("SemicondMaterial").set("Eg0", "1.12[V]");
    model.component("comp1").material("mat1").propertyGroup("SemicondMaterial").set("chi0", "4.05[V]");
    model.component("comp1").material("mat1").propertyGroup("SemicondMaterial")
         .set("Nv", "(T/300[K])^(3/2)*1.04e19[1/cm^3]");
    model.component("comp1").material("mat1").propertyGroup("SemicondMaterial")
         .set("Nc", "(T/300[K])^(3/2)*2.8e19[1/cm^3]");
    model.component("comp1").material("mat1").propertyGroup("SemicondMaterial").set("mun", "1450[cm^2/(V*s)]");
    model.component("comp1").material("mat1").propertyGroup("SemicondMaterial").set("mup", "500[cm^2/(V*s)]");
    model.component("comp1").material("mat1").propertyGroup("SemicondMaterial").addInput("temperature");
    model.component("comp1").material("mat1").propertyGroup("LombardiSurfaceMobilityModel")
         .set("deltan_ls", "5.82e14[V/s]");
    model.component("comp1").material("mat1").propertyGroup("LombardiSurfaceMobilityModel")
         .set("deltap_ls", "2.05e14[V/s]");
    model.component("comp1").material("mat1").propertyGroup("LombardiSurfaceMobilityModel")
         .set("mun1_ls", "4.75e7[cm^2/(V*s)]");
    model.component("comp1").material("mat1").propertyGroup("LombardiSurfaceMobilityModel")
         .set("mup1_ls", "9.93e7[cm^2/(V*s)]");
    model.component("comp1").material("mat1").propertyGroup("LombardiSurfaceMobilityModel")
         .set("mun2_ls", "1.74e5[cm^2/(V*s)]");
    model.component("comp1").material("mat1").propertyGroup("LombardiSurfaceMobilityModel")
         .set("mup2_ls", "8.84e5[cm^2/(V*s)]");
    model.component("comp1").material("mat1").propertyGroup("LombardiSurfaceMobilityModel").set("alphan_ls", "0.125");
    model.component("comp1").material("mat1").propertyGroup("LombardiSurfaceMobilityModel")
         .set("alphap_ls", "0.0317");
    model.component("comp1").material("mat1").propertyGroup("LombardiSurfaceMobilityModel").set("Tref_ls", "1[K]");
    model.component("comp1").material("mat1").propertyGroup("LombardiSurfaceMobilityModel").set("Eref_ls", "1[V/cm]");
    model.component("comp1").material("mat1").propertyGroup("LombardiSurfaceMobilityModel")
         .set("Nref_ls", "1[1/cm^3]");
    model.component("comp1").material("mat1").propertyGroup("ImpactIonization").set("an", "0.426[1/V]");
    model.component("comp1").material("mat1").propertyGroup("ImpactIonization").set("ap", "0.243[1/V]");
    model.component("comp1").material("mat1").propertyGroup("ImpactIonization").set("bn", "4.81E5[V/cm]");
    model.component("comp1").material("mat1").propertyGroup("ImpactIonization").set("bp", "6.53E5[V/cm]");
    model.component("comp1").material("mat1").propertyGroup("ImpactIonization").set("cnii", "3.05E-4[1/K]");
    model.component("comp1").material("mat1").propertyGroup("ImpactIonization").set("cpii", "5.35E-4[1/K]");
    model.component("comp1").material("mat1").propertyGroup("ImpactIonization").set("dn", "6.86E-4[1/K]");
    model.component("comp1").material("mat1").propertyGroup("ImpactIonization").set("dp", "5.67E-4[1/K]");
    model.component("comp1").material("mat1").propertyGroup("SlotboomModel").set("Eref_sb", "0.00692[V]");
    model.component("comp1").material("mat1").propertyGroup("SlotboomModel").set("Nref_sb", "1.3e17[1/cm^3]");
    model.component("comp1").material("mat1").propertyGroup("SlotboomModel").set("alpha_sb", "0.5");
    model.component("comp1").material("mat1").propertyGroup("JainRoulstonModel").set("An_jr", "3.5e-8[V]");
    model.component("comp1").material("mat1").propertyGroup("JainRoulstonModel").set("Bn_jr", "0[V]");
    model.component("comp1").material("mat1").propertyGroup("JainRoulstonModel").set("Cn_jr", "0[V]");
    model.component("comp1").material("mat1").propertyGroup("JainRoulstonModel").set("Ap_jr", "3.5e-8[V]");
    model.component("comp1").material("mat1").propertyGroup("JainRoulstonModel").set("Bp_jr", "0[V]");
    model.component("comp1").material("mat1").propertyGroup("JainRoulstonModel").set("Cp_jr", "0[V]");
    model.component("comp1").material("mat1").propertyGroup("JainRoulstonModel").set("Nref_jr", "1[1/cm^3]");
    model.component("comp1").material("mat1").propertyGroup("JainRoulstonModel").set("alpha_jr", "0.5");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel").set("T_ref_kl", "300[K]");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel")
         .set("mu_e_max_kl", "1414.0[cm^2/V/s]");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel")
         .set("mu_h_max_kl", "470.5[cm^2/V/s]");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel")
         .set("mu_e_min_kl", "68.5[cm^2/V/s]");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel")
         .set("mu_h_min_kl", "44.9[cm^2/V/s]");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel")
         .set("theta_e_kl", "2.285");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel")
         .set("theta_h_kl", "2.247");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel")
         .set("alpha_e_1_kl", "0.711");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel")
         .set("alpha_h_1_kl", "0.719");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel")
         .set("N_ref_e_1_kl", "9.20e16[cm^-3]");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel")
         .set("N_ref_h_1_kl", "2.23e17[cm^-3]");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel").set("c_D_kl", "0.21");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel").set("c_A_kl", "0.50");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel")
         .set("N_ref_D_kl", "4.0e20[cm^-3]");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel")
         .set("N_ref_A_kl", "7.2e20[cm^-3]");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel").set("f_BH_kl", "3.828");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel").set("f_CW_kl", "2.459");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel")
         .set("N_BH_kl", "1.36e20[cm^-3]");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel").set("P_CW_kl", "3.97e13");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel").set("s_1_kl", "0.89233");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel").set("s_2_kl", "0.41372");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel").set("s_3_kl", "0.19778");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel").set("s_4_kl", "0.28227");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel").set("s_5_kl", "0.005978");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel").set("s_6_kl", "1.80618");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel").set("s_7_kl", "0.72169");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel").set("r_1_kl", "0.7643");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel").set("r_2_kl", "2.2999");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel").set("r_3_kl", "6.5502");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel").set("r_4_kl", "2.3670");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel").set("r_5_kl", "-0.01552");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel").set("r_6_kl", "0.6478");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel").set("m_e_kl", "me_const");
    model.component("comp1").material("mat1").propertyGroup("KlaassenUnifiedMobilityModel")
         .set("m_h_kl", "1.258*me_const");

//    In the Model Builder window, right-click Component 1 (comp1) > Materials and choose Blank Material.

    model.component("comp1").material().create("mat2", "Common");

//    Select Domains 3, 7.

    model.component("comp1").material("mat2").selection().set(3, 7);

//    In the Settings window for Material, locate the Material Contents section.
//    In the table, enter the following settings:

    model.component("comp1").material("mat2").propertyGroup("def").set("relpermittivity", new String[]{"4.2"});

//    In the Materials toolbar, click Add Material to close the Add Material window.
//    Enter some parameters which will be used to define the charge and voltages applied to the model.
//    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:

    model.param().set("Qgate", "0[C]");
    model.param().descr("Qgate", "Gate charge");
    model.param().set("Vcontrol", "0.1[V]");
    model.param().descr("Vcontrol", "Control voltage");
    model.param().set("Vd", "10[mV]");
    model.param().descr("Vd", "Drain voltage");
    model.param().set("Vmax", "23.7[V]");
    model.param().descr("Vmax", "Transient voltage maximum");
    model.param().set("A_fn", "1.23e-6[A/V^2]");
    model.param().descr("A_fn", "A tunneling coefficient");
    model.param().set("B_fn", "237[MV/cm]");
    model.param().descr("B_fn", "B tunneling coefficient");

//    Create the time dependent voltage pulse which will be used in the program and erase event simulations.
//    In the Home toolbar, click Functions and choose Global > Rectangle.

    model.func().create("rect1", "Rectangle");

//    In the Settings window for Rectangle, locate the Parameters section.
//    In the Lower limit text field, type 2e-6.

    model.func("rect1").set("lower", "2e-6");

//    In the Upper limit text field, type 5.6e-6.

    model.func("rect1").set("upper", "5.6e-6");

//    Click to expand the Smoothing section.
//    In the Size of transition zone text field, type 1.6e-6.

    model.func("rect1").set("smooth", "1.6e-6");

//    In the Model Builder window, right-click Global Definitions and choose Variables.

    model.variable().create("var1");

//    In the Settings window for Variables, locate the Variables section.
//    In the table, enter the following settings:

    model.variable("var1").set("Vcontrol_t", "Vmax*rect1(t/1[s])");
    model.variable("var1").descr("Vcontrol_t", "Time dependent voltage pulse");

//    In the Label text field, type Control voltage pulse.

    model.variable("var1").label("Control voltage pulse");

//    Configure the physics in the Semiconductor interface. First remove the control and floating contacts from the interface selection. This is equivalent to assuming that they are perfect conductors.
//    In the Model Builder window, under Component 1 (comp1), click Semiconductor (semi).
//    In the Settings window for Semiconductor, locate the Domain Selection section.
//    From the Selection list, select Manual.

    model.component("comp1").physics("semi").selection().set(1, 2, 3, 4, 5, 6, 7, 8, 9);

//    Select Domains 1, 2, 3, 6, 7, 8, 9.

    model.component("comp1").physics("semi").selection().set(1, 2, 3, 6, 7, 8, 9);

//    Add a Charge Conservation feature to the oxide layer.
//    In the Physics toolbar, click Domains and choose Charge Conservation.

    model.component("comp1").physics("semi").create("ccn1", "ChargeConservation", 2);

//    Select Domains 3, 7.

    model.component("comp1").physics("semi").feature("ccn1").selection().set(3, 7);

//    Next create the doping profile. The doping profile has three components: a background doping level throughout the entire semiconductor region; two doped regions, one at either side of the semiconductor region, which make up the source and drain contacts for the transistor; and a shallow doped region from which charge tunnels into the floating gate.
//    First apply a constant p-type background doping concentration.
//    In the Physics toolbar, click Domains and choose Analytic Doping Model.

    model.component("comp1").physics("semi").create("adm1", "AnalyticDopingModel", 2);

//    In the Settings window for Analytic Doping Model, locate the Domain Selection section.
//    From the Selection list, select All domains.

    model.component("comp1").physics("semi").feature("adm1").selection().all();

//    Now create the n-type source and drain doping. Typically these doping regions would be created using an ion implantation process. This is approximated in the model by using an Analytical Doping Model feature to specify regions of constant doping and then using a Geometric Doping Model to create a Gaussian profile away from the edge of these regions.
//    In the Physics toolbar, click Domains and choose Analytic Doping Model.

    model.component("comp1").physics("semi").create("adm2", "AnalyticDopingModel", 2);

//    Select Domains 2, 8, 9.

    model.component("comp1").physics("semi").feature("adm2").selection().set(2, 8, 9);

//    In the Settings window for Analytic Doping Model, locate the Impurity section.
//    From the Impurity type list, select Donor doping (n-type).

    model.component("comp1").physics("semi").feature("adm2").set("impurityType", "donor");

//    In the \[N_{D0}\] text field, type 5e17[1/cm^3].

    model.component("comp1").physics("semi").feature("adm2").set("NDc", "5e17[1/cm^3]");

//    In the Physics toolbar, click Domains and choose Geometric Doping Model.

    model.component("comp1").physics("semi").create("gdm1", "GeometricDopingModel", 2);

//    Select Domains 1, 6.

    model.component("comp1").physics("semi").feature("gdm1").selection().set(1, 6);

//    In the Settings window for Geometric Doping Model, locate the Impurity section.
//    From the Impurity type list, select Donor doping (n-type).

    model.component("comp1").physics("semi").feature("gdm1").set("impurityType", "donor");

//    In the \[N_{D0}\] text field, type 5e17[1/cm^3].

    model.component("comp1").physics("semi").feature("gdm1").set("NDgen", "5e17[1/cm^3]");

//    Locate the Profile section.
//    From the Specify profile length scale list, select Decay length.

    model.component("comp1").physics("semi").feature("gdm1").set("JunctionOrLength", "decay_length");

//    In the \[l_{d}\] text field, type 0.02[um].

    model.component("comp1").physics("semi").feature("gdm1").set("l_gen", "0.02[um]");

//    In the Model Builder window, expand the Geometric Doping Model 1 node, then click Boundary Selection for Doping Profile 1.
//    Select Boundaries 4, 16, 31, 32, 35, 43, 45.

    model.component("comp1").physics("semi").feature("gdm1").feature("gdmbs1").selection()
         .set(4, 16, 31, 32, 35, 43, 45);

//    Now create the doped region below the tunnel barrier into the floating contact. As this doping region is shallower than the source and drain regions it would typically be added with a second implantation process. As before, a combination of a uniform region, specified with an Analytic Doping Model, and a Gaussian profile, specified with a Geometric Doping Model, are used.
//    In the Physics toolbar, click Domains and choose Analytic Doping Model.

    model.component("comp1").physics("semi").create("adm3", "AnalyticDopingModel", 2);

//    Select Domains 6, 9.

    model.component("comp1").physics("semi").feature("adm3").selection().set(6, 9);

//    In the Settings window for Analytic Doping Model, locate the Impurity section.
//    From the Impurity type list, select Donor doping (n-type).

    model.component("comp1").physics("semi").feature("adm3").set("impurityType", "donor");

//    In the \[N_{D0}\] text field, type 1e18[1/cm^3].

    model.component("comp1").physics("semi").feature("adm3").set("NDc", "1e18[1/cm^3]");

//    In the Physics toolbar, click Domains and choose Geometric Doping Model.

    model.component("comp1").physics("semi").create("gdm2", "GeometricDopingModel", 2);

//    Select Domains 1, 2, 8.

    model.component("comp1").physics("semi").feature("gdm2").selection().set(1, 2, 8);

//    In the Settings window for Geometric Doping Model, locate the Impurity section.
//    From the Impurity type list, select Donor doping (n-type).

    model.component("comp1").physics("semi").feature("gdm2").set("impurityType", "donor");

//    In the \[N_{D0}\] text field, type 1e18[1/cm^3].

    model.component("comp1").physics("semi").feature("gdm2").set("NDgen", "1e18[1/cm^3]");

//    Locate the Profile section.
//    From the Specify profile length scale list, select Decay length.

    model.component("comp1").physics("semi").feature("gdm2").set("JunctionOrLength", "decay_length");

//    In the \[l_{d}\] text field, type 0.02[um].

    model.component("comp1").physics("semi").feature("gdm2").set("l_gen", "0.02[um]");

//    In the Model Builder window, expand the Geometric Doping Model 2 node, then click Boundary Selection for Doping Profile 1.
//    Select Boundaries 18, 24, 33, 44.

    model.component("comp1").physics("semi").feature("gdm2").feature("gdmbs1").selection().set(18, 24, 33, 44);

//    The boundary conditions for the Semiconductor interface need to be specified. These define the floating and control gates as well as the source and drain terminals and the tunneling barrier.
//    Add a Metal Contact boundary for the source.
//    In the Physics toolbar, click Boundaries and choose Metal Contact.

    model.component("comp1").physics("semi").create("mc1", "MetalContact", 1);

//    Select Boundary 39.

    model.component("comp1").physics("semi").feature("mc1").selection().set(39);

//    In the Settings window for Metal Contact, type Source in the Label text field.

    model.component("comp1").physics("semi").feature("mc1").label("Source");

//    Add a Metal Contact boundary to ground the base of the device.
//    In the Physics toolbar, click Boundaries and choose Metal Contact.

    model.component("comp1").physics("semi").create("mc2", "MetalContact", 1);

//    Select Boundary 2.

    model.component("comp1").physics("semi").feature("mc2").selection().set(2);

//    In the Settings window for Metal Contact, type Base in the Label text field.

    model.component("comp1").physics("semi").feature("mc2").label("Base");

//    Add a Metal Contact boundaries for the drain. Two boundary conditions are required, one for the stationary study and one for the time dependent study.
//    In the Physics toolbar, click Boundaries and choose Metal Contact.

    model.component("comp1").physics("semi").create("mc3", "MetalContact", 1);

//    Select Boundary 5.

    model.component("comp1").physics("semi").feature("mc3").selection().set(5);

//    In the Settings window for Metal Contact, locate the Terminal section.
//    In the \[V_0\] text field, type Vd.

    model.component("comp1").physics("semi").feature("mc3").set("V0", "Vd");

//    In the Label text field, type Drain (Stationary).

    model.component("comp1").physics("semi").feature("mc3").label("Drain (Stationary)");

//    In the Physics toolbar, click Boundaries and choose Metal Contact.

    model.component("comp1").physics("semi").create("mc4", "MetalContact", 1);

//    Select Boundary 5.

    model.component("comp1").physics("semi").feature("mc4").selection().set(5);

//    In the Settings window for Metal Contact, locate the Terminal section.
//    In the \[V_0\] text field, type Vd.

    model.component("comp1").physics("semi").feature("mc4").set("V0", "Vd");

//    In the Terminal name text field, type 3.

    model.component("comp1").physics("semi").feature("mc4").set("TerminalName", 3);

//    In the Label text field, type Drain (Time Dependent).

    model.component("comp1").physics("semi").feature("mc4").label("Drain (Time Dependent)");

//    Add Terminal boundary conditions to the boundaries of the control contact. Two features are required, one for the stationary study and one for the time dependent study.
//    In the Physics toolbar, click Boundaries and choose Terminal.

    model.component("comp1").physics("semi").create("term1", "Terminal", 1);

//    Select Boundaries 13, 14, 15, 30.

    model.component("comp1").physics("semi").feature("term1").selection().set(13, 14, 15, 30);

//    In the Settings window for Terminal, locate the Terminal section.
//    From the Terminal type list, select Voltage.

    model.component("comp1").physics("semi").feature("term1").set("TerminalType", "Voltage");

//    In the \[V_0\] text field, type Vcontrol.

    model.component("comp1").physics("semi").feature("term1").set("V0", "Vcontrol");

//    In the Label text field, type Control gate (Stationary).

    model.component("comp1").physics("semi").feature("term1").label("Control gate (Stationary)");

//    In the Physics toolbar, click Boundaries and choose Terminal.

    model.component("comp1").physics("semi").create("term2", "Terminal", 1);

//    Select Boundaries 13, 14, 15, 30.

    model.component("comp1").physics("semi").feature("term2").selection().set(13, 14, 15, 30);

//    In the Settings window for Terminal, locate the Terminal section.
//    In the Terminal name text field, type 4.

    model.component("comp1").physics("semi").feature("term2").set("TerminalName", 4);

//    From the Terminal type list, select Voltage.

    model.component("comp1").physics("semi").feature("term2").set("TerminalType", "Voltage");

//    In the \[V_0\] text field, type Vcontrol_t.

    model.component("comp1").physics("semi").feature("term2").set("V0", "Vcontrol_t");

//    In the Label text field, type Control gate (Time Dependent).

    model.component("comp1").physics("semi").feature("term2").label("Control gate (Time Dependent)");

    return model;
  }

  public static Model run2(Model model) {

//    Add Insulator Tunneling boundary conditions to the boundary of the semiconductor material through which tunneling will occur.
//    In the Physics toolbar, click Boundaries and choose Insulator Interface.

    model.component("comp1").physics("semi").create("ii2", "InsulatorInterface", 1);

//    Select Boundary 21.

    model.component("comp1").physics("semi").feature("ii2").selection().set(21);

//    In the Settings window for Insulator Interface, locate the Tunneling section.
//    From the Tunneling type list, select Fowler–Nordheim tunneling.

    model.component("comp1").physics("semi").feature("ii2").set("TunnelingType", "FowlerNordheim");

//    Locate the Fowler–Nordheim Tunneling section.
//    In the \[A^{n}_{FN}\] text field, type A_fn.

    model.component("comp1").physics("semi").feature("ii2").set("AfnElectrons", "A_fn");

//    In the \[B^{\,n}_{FN}\] text field, type B_fn.

    model.component("comp1").physics("semi").feature("ii2").set("BfnElectrons", "B_fn");

//    In the Label text field, type Tunnel barrier.

    model.component("comp1").physics("semi").feature("ii2").label("Tunnel barrier");

//    Add the Floating Gate boundary condition to the boundaries of the floating gate.
//    In the Physics toolbar, click Boundaries and choose Floating Gate.

    model.component("comp1").physics("semi").create("fg1", "FloatingGate", 1);

//    Select Boundaries 10, 11, 12, 22, 23, 27, 28, 29.

    model.component("comp1").physics("semi").feature("fg1").selection().set(10, 11, 12, 22, 23, 27, 28, 29);

//    In the Settings window for Floating Gate, locate the Floating Gate section.
//    In the \[Q_{\mathrm{init}}\] text field, type Qgate.

    model.component("comp1").physics("semi").feature("fg1").set("Q_init", "Qgate");

//    In the Label text field, type Floating Gate.

    model.component("comp1").physics("semi").feature("fg1").label("Floating Gate");

//    Configure the mesh to be finer around the regions of interest, in particular the mesh density must be very high in the channel region under the gate and in the tunnel barrier region.
//    In the Model Builder window, right-click Component 1 (comp1) > Mesh 1 and choose Size.

    model.component("comp1").mesh("mesh1").create("size1", "Size");

//    In the Settings window for Size, locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Domain.

    model.component("comp1").mesh("mesh1").feature("size1").selection().geom("geom1", 2);

//    Select Domains 1, 3.

    model.component("comp1").mesh("mesh1").feature("size1").selection().set(1, 3);

//    Locate the Element Size section.
//    From the Predefined list, select Finer.

    model.component("comp1").mesh("mesh1").feature("size1").set("hauto", 3);

//    In the Model Builder window, right-click Mesh 1 and choose Size.

    model.component("comp1").mesh("mesh1").create("size2", "Size");

//    In the Settings window for Size, locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Boundary.

    model.component("comp1").mesh("mesh1").feature("size2").selection().geom("geom1", 1);

//    Select Boundaries 4, 5, 18, 24, 31, 32, 33, 35, 39, 43, 44, 45, 48.

    model.component("comp1").mesh("mesh1").feature("size2").selection()
         .set(4, 5, 18, 24, 31, 32, 33, 35, 39, 43, 44, 45, 48);

//    Locate the Element Size section.
//    From the Calibrate for list, select Semiconductor.

    model.component("comp1").mesh("mesh1").feature("size2").set("table", "semi");

//    From the Predefined list, select Fine.

    model.component("comp1").mesh("mesh1").feature("size2").set("hauto", 4);

//    Right-click Mesh 1 and choose Size.

    model.component("comp1").mesh("mesh1").create("size3", "Size");

//    In the Settings window for Size, locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Boundary.

    model.component("comp1").mesh("mesh1").feature("size3").selection().geom("geom1", 1);

//    Select Boundaries 10, 11, 12, 13, 14, 15, 28, 29, 30.

    model.component("comp1").mesh("mesh1").feature("size3").selection().set(10, 11, 12, 13, 14, 15, 28, 29, 30);

//    Locate the Element Size section.
//    Click the Custom button.

    model.component("comp1").mesh("mesh1").feature("size3").set("custom", true);

//    Locate the Element Size Parameters section.
//    Select the Maximum element size checkbox.

    model.component("comp1").mesh("mesh1").feature("size3").set("hmaxactive", true);

//    In the associated text field, type 0.01.

    model.component("comp1").mesh("mesh1").feature("size3").set("hmax", 0.01);

//    In the Mesh toolbar, click More Generators and choose Edge.

    model.component("comp1").mesh("mesh1").create("edg1", "Edge");

//    Select Boundaries 17, 19, 21, 26.

    model.component("comp1").mesh("mesh1").feature("edg1").selection().set(17, 19, 21, 26);

//    Right-click Edge 1 and choose Size.

    model.component("comp1").mesh("mesh1").feature("edg1").create("size1", "Size");

//    In the Settings window for Size, locate the Element Size section.
//    From the Calibrate for list, select Semiconductor.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("size1").set("table", "semi");

//    From the Predefined list, select Extra fine.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("size1").set("hauto", 2);

//    Click the Custom button.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("size1").set("custom", true);

//    Locate the Element Size Parameters section.
//    Select the Maximum element size checkbox.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("size1").set("hmaxactive", true);

//    In the associated text field, type 0.01.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("size1").set("hmax", 0.01);

//    In the Model Builder window, right-click Edge 1 and choose Size.

    model.component("comp1").mesh("mesh1").feature("edg1").create("size2", "Size");

//    In the Settings window for Size, locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Point.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("size2").selection().geom("geom1", 0);

//    Select Points 18, 22.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("size2").selection().set(18, 22);

//    Locate the Element Size section.
//    From the Calibrate for list, select Semiconductor.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("size2").set("table", "semi");

//    From the Predefined list, select Extra fine.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("size2").set("hauto", 2);

//    Click the Custom button.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("size2").set("custom", true);

//    Locate the Element Size Parameters section.
//    Select the Maximum element size checkbox.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("size2").set("hmaxactive", true);

//    In the associated text field, type 0.002.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("size2").set("hmax", 0.002);

//    Select the Maximum element growth rate checkbox.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("size2").set("hgradactive", true);

//    In the associated text field, type 1.05.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("size2").set("hgrad", 1.05);

//    In the Model Builder window, right-click Mesh 1 and choose Copying Operations > Copy Edge.

    model.component("comp1").mesh("mesh1").create("cpe1", "CopyEdge");

//    Select Boundary 17.

    model.component("comp1").mesh("mesh1").feature("cpe1").selection("source").set(17);

//    In the Settings window for Copy Edge, locate the Destination Boundaries section.
//    Select the Activate Selection toggle button.
//    Select Boundary 51.

    model.component("comp1").mesh("mesh1").feature("cpe1").selection("destination").set(51);

//    Right-click Mesh 1 and choose Copying Operations > Copy Edge.

    model.component("comp1").mesh("mesh1").create("cpe2", "CopyEdge");
    model.component("comp1").mesh("mesh1").feature("cpe2").selection("source").geom(1);
    model.component("comp1").mesh("mesh1").feature("cpe2").selection("destination").geom(1);

//    Select Boundaries 19, 21, 26.

    model.component("comp1").mesh("mesh1").feature("cpe2").selection("source").set(19, 21, 26);

//    In the Settings window for Copy Edge, locate the Destination Boundaries section.
//    Select the Activate Selection toggle button.
//    Select Boundary 52.

    model.component("comp1").mesh("mesh1").feature("cpe2").selection("destination").set(52);

//    In the Mesh toolbar, click Mapped.

    model.component("comp1").mesh("mesh1").create("map1", "Map");

//    In the Settings window for Mapped, locate the Domain Selection section.
//    From the Geometric entity level list, select Domain.

    model.component("comp1").mesh("mesh1").feature("map1").selection().geom("geom1", 2);

//    Select Domains 7, 10, 11.

    model.component("comp1").mesh("mesh1").feature("map1").selection().set(7, 10, 11);

//    Click to expand the Control Entities section.
//    From the Smooth across removed control entities list, select Off.

    model.component("comp1").mesh("mesh1").feature("map1").set("smoothcontrol", false);

//    Click to expand the Reduce Element Skewness section.
//    Select the Adjust edge mesh checkbox.

    model.component("comp1").mesh("mesh1").feature("map1").set("adjustedgdistr", true);

//    Right-click Mapped 1 and choose Distribution.

    model.component("comp1").mesh("mesh1").feature("map1").create("dis1", "Distribution");

//    Select Boundary 16.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis1").selection().set(16);

//    In the Settings window for Distribution, locate the Distribution section.
//    From the Distribution type list, select Predefined.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis1").set("type", "predefined");

//    In the Number of elements text field, type 6.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis1").set("elemcount", 6);

//    In the Element ratio text field, type 3.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis1").set("elemratio", 3);

//    From the Growth rate list, select Exponential.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis1").set("growthrate", "exponential");

//    In the Model Builder window, right-click Mapped 1 and choose Distribution.

    model.component("comp1").mesh("mesh1").feature("map1").create("dis2", "Distribution");

//    Select Boundary 20.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis2").selection().set(20);

//    In the Mesh toolbar, click Free Triangular.

    model.component("comp1").mesh("mesh1").create("ftri1", "FreeTri");

//    In the Settings window for Free Triangular, locate the Domain Selection section.
//    From the Geometric entity level list, select Domain.

    model.component("comp1").mesh("mesh1").feature("ftri1").selection().geom("geom1", 2);

//    Select Domains 1, 2, 3, 6, 8, 9.

    model.component("comp1").mesh("mesh1").feature("ftri1").selection().set(1, 2, 3, 6, 8, 9);

//    Click to expand the Control Entities section.
//    From the Smooth across removed control entities list, select Off.

    model.component("comp1").mesh("mesh1").feature("ftri1").set("smoothcontrol", false);

//    In the Mesh toolbar, click Build Mesh.

    model.component("comp1").mesh("mesh1").run();

//    The resulting mesh is shown below.
//    In the Model Builder window, click Information.
//    Confirm that the doping profile is implemented as intended. This is achieved by getting the initial value from the default study settings and plotting a 2D surface plot of the net doping concentration.
//    In the Model Builder window, click Study 1.
//    In the Settings window for Study, locate the Study Settings section.
//    Clear the Generate default plots checkbox.

    model.study("std1").setGenPlots(false);

//    In the Study toolbar, click Get Initial Value.

    model.study("std1").createAutoSequences("sol");
    model.study("std1").createAutoSequences("jobs");

    model.sol("sol1").runFromTo("st1", "v1");

//    In the Results toolbar, click 2D Plot Group.

    model.result().create("pg1", "PlotGroup2D");
    model.result("pg1").run();

//    Right-click 2D Plot Group 1 and choose Surface.

    model.result("pg1").create("surf1", "Surface");
    model.result("pg1").feature("surf1").set("evaluationsettings", "parent");

//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type semi.Ndoping.

    model.result("pg1").feature("surf1").set("expr", "semi.Ndoping");

//    In the 2D Plot Group 1 toolbar, click Plot.

    model.result("pg1").run();
    model.result("pg1").run();

//    In the Model Builder window, under Results, click 2D Plot Group 1.
//    In the Settings window for 2D Plot Group, type Doping in the Label text field.

    model.result("pg1").label("Doping");

//    The desired doping profile is shown above.
//    With the physics configured and doping confirmed the main studies can be performed. Set the stationary study to sweep <c>Vcontrol</c> from 0 to 3 V for two different values of <c>Qgate</c>. Note that the time dependent boundary conditions are disabled for this study.
//    In the Model Builder window, under Study 1, click Step 1: Stationary.
//    In the Settings window for Stationary, locate the Physics and Variables Selection section.
//    Select the Modify model configuration for study step checkbox.

    model.study("std1").feature("stat").set("useadvanceddisable", true);

//    In the tree, select Component 1 (comp1) > Semiconductor (semi) > Drain (Time Dependent).
//    Click Disable.

    model.study("std1").feature("stat").set("disabledphysics", new String[]{"semi/mc4"});

//    In the tree, select Component 1 (comp1) > Semiconductor (semi) > Control gate (Time Dependent).
//    Click Disable.

    model.study("std1").feature("stat").set("disabledphysics", new String[]{"semi/mc4", "semi/term2"});

//    Click to expand the Study Extensions section.
//    Select the Auxiliary sweep checkbox.

    model.study("std1").feature("stat").set("useparam", true);

//    Click Add.

    model.study("std1").feature("stat").setIndex("pname", "Qgate", 0);
    model.study("std1").feature("stat").setIndex("plistarr", "", 0);
    model.study("std1").feature("stat").setIndex("punit", "C", 0);
    model.study("std1").feature("stat").setIndex("pname", "Qgate", 0);
    model.study("std1").feature("stat").setIndex("plistarr", "", 0);
    model.study("std1").feature("stat").setIndex("punit", "C", 0);

//    In the table, enter the following settings:

    model.study("std1").feature("stat").setIndex("plistarr", "0 -2e-15", 0);

//    Click Add.

    model.study("std1").feature("stat").setIndex("pname", "Vcontrol", 1);
    model.study("std1").feature("stat").setIndex("plistarr", "", 1);
    model.study("std1").feature("stat").setIndex("punit", "V", 1);
    model.study("std1").feature("stat").setIndex("pname", "Vcontrol", 1);
    model.study("std1").feature("stat").setIndex("plistarr", "", 1);
    model.study("std1").feature("stat").setIndex("punit", "V", 1);

//    In the table, enter the following settings:

    model.study("std1").feature("stat").setIndex("plistarr", "range(0,0.1,3)", 1);

//    From the Sweep type list, select All combinations.

    model.study("std1").feature("stat").set("sweeptype", "filled");

//    From the Reuse solution from previous step list, select Auto.

    model.study("std1").feature("stat").set("preusesol", "auto");

//    Adjust scaling for better convergence.
//    In the Study toolbar, click Show Default Solver.

    model.study("std1").showAutoSequences("all");

//    In the Model Builder window, expand the Solution 1 (sol1) node, then click Dependent Variables 1.
//    In the Settings window for Dependent Variables, locate the Scaling section.
//    From the Method list, select None.

    model.sol("sol1").feature("v1").set("scalemethod", "none");

//    In the Model Builder window, expand the Study 1 > Solver Configurations > Solution 1 (sol1) > Dependent Variables 1 node, then click Electron Solution Variable (comp1.Ne).
//    In the Settings window for Field, locate the Scaling section.
//    From the Method list, select Manual.

    model.sol("sol1").feature("v1").feature("comp1_Ne").set("scalemethod", "manual");

//    In the Scale text field, type 1.0e24.

    model.sol("sol1").feature("v1").feature("comp1_Ne").set("scaleval", "1.0e24");

//    In the Model Builder window, under Study 1 > Solver Configurations > Solution 1 (sol1) > Dependent Variables 1, click Hole Solution Variable (comp1.Ph).
//    In the Settings window for Field, locate the Scaling section.
//    From the Method list, select Manual.

    model.sol("sol1").feature("v1").feature("comp1_Ph").set("scalemethod", "manual");

//    In the Scale text field, type 1.0e22.

    model.sol("sol1").feature("v1").feature("comp1_Ph").set("scaleval", "1.0e22");

//    In the Model Builder window, click Study 1.
//    In the Settings window for Study, type Stationary, sweep Vcontrol for fixed Qgate. in the Label text field.

    model.study("std1").label("Stationary, sweep Vcontrol for fixed Qgate.");

//    In the Study toolbar, click Compute.

    model.study("std1").createAutoSequences("all");

    model.sol("sol1").runAll();

    model.result("pg1").run();

//    Plot the I-V curves for each of the control voltages.
//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg2", "PlotGroup1D");
    model.result("pg2").run();

//    In the Settings window for 1D Plot Group, type Current vs. Voltage in the Label text field.

    model.result("pg2").label("Current vs. Voltage");

//    Right-click Current vs. Voltage and choose Global.

    model.result("pg2").create("glob1", "Global");
    model.result("pg2").feature("glob1").set("markerpos", "datapoints");
    model.result("pg2").feature("glob1").set("linewidth", "preference");

//    In the Settings window for Global, locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg2").feature("glob1").setIndex("expr", "semi.I0_1", 0);
    model.result("pg2").feature("glob1").setIndex("unit", "uA", 0);
    model.result("pg2").feature("glob1").setIndex("descr", "Source current", 0);

//    Click to expand the Legends section.
//    From the Legends list, select Evaluated.

    model.result("pg2").feature("glob1").set("legendmethod", "evaluated");

//    In the Legend text field, type Qgate= eval(Qgate, C) C.

    model.result("pg2").feature("glob1").set("legendpattern", "Qgate= eval(Qgate, C) C");
    model.result("pg2").run();

//    In the Model Builder window, click Current vs. Voltage.
//    In the Settings window for 1D Plot Group, locate the Plot Settings section.
//    Select the x-axis label checkbox.

    model.result("pg2").set("xlabelactive", true);

//    In the associated text field, type Control Voltage (V).

    model.result("pg2").set("xlabel", "Control Voltage (V)");

//    Click to expand the Title section.
//    From the Title type list, select Manual.

    model.result("pg2").set("titletype", "manual");

//    In the Title text area, type Source current as a function of Control Voltage.

    model.result("pg2").set("title", "Source current as a function of Control Voltage");

//    In the Current vs. Voltage toolbar, click Plot.

    model.result("pg2").run();

//    Add time dependent studies to perform the program and erase simulation.
//    The first time dependent study performs the Program event. In this study the control voltage pulse has positive sign and electrons tunnel out of the semiconductor across the tunnel barrier, resulting in negative charge being deposited on the floating contact.
//    In the Home toolbar, click Add Study to open the Add Study window.
//    Find the Studies subsection.
//    In the Select Study tree, select General Studies > Time Dependent.
//    Click Add Study in the window toolbar.

    model.study().create("std2");
    model.study("std2").create("time", "Transient");

//    In the Home toolbar, click Add Study to close the Add Study window.
//    In the Settings window for Time Dependent, locate the Study Settings section.
//    In the Output times text field, type range(0,0.1e-6,7e-6).

    model.study("std2").feature("time").set("tlist", "range(0,0.1e-6,7e-6)");

//    Click to expand the Values of Dependent Variables section.
//    Find the Initial values of variables solved for subsection.
//    From the Settings list, select User controlled.

    model.study("std2").feature("time").set("useinitsol", true);

//    From the Method list, select Solution.

    model.study("std2").feature("time").set("initmethod", "sol");

//    From the Study list, select Stationary, sweep Vcontrol for fixed Qgate., Stationary.

    model.study("std2").feature("time").set("initstudy", "std1");

//    From the Parameter value (Vcontrol (V),Qgate (C)) list, select 32: Vcontrol=0 V, Qgate=-2E-15 C.

    model.study("std2").feature("time").set("solnum", 32);

//    Click to expand the Study Extensions section.
//    Select the Auxiliary sweep checkbox.

    model.study("std2").feature("time").set("useparam", true);

//    Click Add.

    model.study("std2").feature("time").setIndex("pname", "Qgate", 0);
    model.study("std2").feature("time").setIndex("plistarr", "", 0);
    model.study("std2").feature("time").setIndex("punit", "C", 0);
    model.study("std2").feature("time").setIndex("pname", "Qgate", 0);
    model.study("std2").feature("time").setIndex("plistarr", "", 0);
    model.study("std2").feature("time").setIndex("punit", "C", 0);

//    In the table, enter the following settings:

    model.study("std2").feature("time").setIndex("pname", "Vmax", 0);
    model.study("std2").feature("time").setIndex("plistarr", "16.8[V]", 0);

//    Click Add.

    model.study("std2").feature("time").setIndex("pname", "Qgate", 1);
    model.study("std2").feature("time").setIndex("plistarr", "", 1);
    model.study("std2").feature("time").setIndex("punit", "C", 1);
    model.study("std2").feature("time").setIndex("pname", "Qgate", 1);
    model.study("std2").feature("time").setIndex("plistarr", "", 1);
    model.study("std2").feature("time").setIndex("punit", "C", 1);

//    In the table, enter the following settings:

    model.study("std2").feature("time").setIndex("pname", "A_fn", 1);
    model.study("std2").feature("time").setIndex("plistarr", "1.23e-6[A/V^2]", 1);

//    Click Add.

    model.study("std2").feature("time").setIndex("pname", "Qgate", 2);
    model.study("std2").feature("time").setIndex("plistarr", "", 2);
    model.study("std2").feature("time").setIndex("punit", "C", 2);
    model.study("std2").feature("time").setIndex("pname", "Qgate", 2);
    model.study("std2").feature("time").setIndex("plistarr", "", 2);
    model.study("std2").feature("time").setIndex("punit", "C", 2);

//    In the table, enter the following settings:

    model.study("std2").feature("time").setIndex("pname", "B_fn", 2);
    model.study("std2").feature("time").setIndex("plistarr", "237[MV/cm]", 2);

//    In the Model Builder window, click Study 2.
//    In the Settings window for Study, type Time dependent, Program event in the Label text field.

    model.study("std2").label("Time dependent, Program event");

//    Locate the Study Settings section.
//    Clear the Generate default plots checkbox.

    model.study("std2").setGenPlots(false);

//    In the Study toolbar, click Show Default Solver.

    model.study("std2").showAutoSequences("all");

//    In the Model Builder window, expand the Solution 2 (sol2) node, then click Time-Dependent Solver 1.
//    In the Settings window for Time-Dependent Solver, click to expand the Time Stepping section.
//    From the Steps taken by solver list, select Intermediate.

    model.sol("sol2").feature("t1").set("tstepsbdf", "intermediate");

//    In the Study toolbar, click Compute.

    model.study("std2").createAutoSequences("all");

    model.sol("sol2").runAll();

//    The second time dependent study performs the Erase event. This study starts with the device in the 'programmed' state and applies a control voltage pulse with negative sign. This causes electrons to tunnel out of the floating contact, reducing the magnitude of the floating gate charge near to zero.
//    In the Home toolbar, click Add Study to open the Add Study window.
//    Find the Studies subsection.
//    In the Select Study tree, select General Studies > Time Dependent.
//    Click Add Study in the window toolbar.

    model.study().create("std3");
    model.study("std3").create("time", "Transient");

//    In the Home toolbar, click Add Study to close the Add Study window.
//    In the Settings window for Time Dependent, locate the Study Settings section.
//    In the Output times text field, type range(0,0.1e-6,7e-6).

    model.study("std3").feature("time").set("tlist", "range(0,0.1e-6,7e-6)");

//    Locate the Values of Dependent Variables section.
//    Find the Initial values of variables solved for subsection.
//    From the Settings list, select User controlled.

    model.study("std3").feature("time").set("useinitsol", true);

//    From the Method list, select Solution.

    model.study("std3").feature("time").set("initmethod", "sol");

//    From the Study list, select Time dependent, Program event, Time Dependent.

    model.study("std3").feature("time").set("initstudy", "std2");

//    From the Selection list, select Last.

    model.study("std3").feature("time").set("solnum", "last");

//    Locate the Study Extensions section.
//    Select the Auxiliary sweep checkbox.

    model.study("std3").feature("time").set("useparam", true);

//    Click Add.

    model.study("std3").feature("time").setIndex("pname", "Qgate", 0);
    model.study("std3").feature("time").setIndex("plistarr", "", 0);
    model.study("std3").feature("time").setIndex("punit", "C", 0);
    model.study("std3").feature("time").setIndex("pname", "Qgate", 0);
    model.study("std3").feature("time").setIndex("plistarr", "", 0);
    model.study("std3").feature("time").setIndex("punit", "C", 0);

//    In the table, enter the following settings:

    model.study("std3").feature("time").setIndex("pname", "Vmax", 0);
    model.study("std3").feature("time").setIndex("plistarr", -15.34, 0);

//    Click Add.

    model.study("std3").feature("time").setIndex("pname", "Qgate", 1);
    model.study("std3").feature("time").setIndex("plistarr", "", 1);
    model.study("std3").feature("time").setIndex("punit", "C", 1);
    model.study("std3").feature("time").setIndex("pname", "Qgate", 1);
    model.study("std3").feature("time").setIndex("plistarr", "", 1);
    model.study("std3").feature("time").setIndex("punit", "C", 1);

//    In the table, enter the following settings:

    model.study("std3").feature("time").setIndex("pname", "A_fn", 1);
    model.study("std3").feature("time").setIndex("plistarr", "1.82e-7[A/V^2]", 1);

//    Click Add.

    model.study("std3").feature("time").setIndex("pname", "Qgate", 2);
    model.study("std3").feature("time").setIndex("plistarr", "", 2);
    model.study("std3").feature("time").setIndex("punit", "C", 2);
    model.study("std3").feature("time").setIndex("pname", "Qgate", 2);
    model.study("std3").feature("time").setIndex("plistarr", "", 2);
    model.study("std3").feature("time").setIndex("punit", "C", 2);

//    In the table, enter the following settings:

    model.study("std3").feature("time").setIndex("pname", "B_fn", 2);
    model.study("std3").feature("time").setIndex("plistarr", "188[MV/cm]", 2);

//    In the Model Builder window, click Study 3.
//    In the Settings window for Study, type Time dependent, Erase event in the Label text field.

    model.study("std3").label("Time dependent, Erase event");

//    Locate the Study Settings section.
//    Clear the Generate default plots checkbox.

    model.study("std3").setGenPlots(false);

//    In the Study toolbar, click Show Default Solver.

    model.study("std3").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 Time Stepping section.
//    From the Steps taken by solver list, select Intermediate.

    model.sol("sol3").feature("t1").set("tstepsbdf", "intermediate");

//    In the Study toolbar, click Compute.

    model.study("std3").createAutoSequences("all");

    model.sol("sol3").runAll();

//    Plot the tunnel current and the charge on the floating gate as functions of time during the Program and Erase events.
//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg3", "PlotGroup1D");
    model.result("pg3").run();

//    In the Settings window for 1D Plot Group, type Tunnel Current in the Label text field.

    model.result("pg3").label("Tunnel Current");

//    Locate the Data section.
//    From the Dataset list, select None.

    model.result("pg3").set("data", "none");

//    Locate the Title section.
//    From the Title type list, select Manual.

    model.result("pg3").set("titletype", "manual");

//    In the Title text area, type Tunnel current as a function of time.

    model.result("pg3").set("title", "Tunnel current as a function of time");

//    Locate the Plot Settings section.
//    Select the x-axis label checkbox.

    model.result("pg3").set("xlabelactive", true);

//    In the associated text field, type Time (us).

    model.result("pg3").set("xlabel", "Time (us)");

//    Select the y-axis label checkbox.

    model.result("pg3").set("ylabelactive", true);

//    In the associated text field, type Tunnel current (nA).

    model.result("pg3").set("ylabel", "Tunnel current (nA)");

//    Right-click Tunnel Current and choose Global.

    model.result("pg3").create("glob1", "Global");
    model.result("pg3").feature("glob1").set("markerpos", "datapoints");
    model.result("pg3").feature("glob1").set("linewidth", "preference");

//    In the Settings window for Global, locate the Data section.
//    From the Dataset list, select Time dependent, Program event/Solution 2 (sol2).

    model.result("pg3").feature("glob1").set("data", "dset2");

//    Locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg3").feature("glob1").setIndex("expr", "semi.ii2.I_tun", 0);
    model.result("pg3").feature("glob1").setIndex("unit", "nA", 0);
    model.result("pg3").feature("glob1").setIndex("descr", "Tunnel current", 0);

//    Locate the x-Axis Data section.
//    From the Axis source data list, select Time.

    model.result("pg3").feature("glob1").set("xdatasolnumtype", "level1");

//    From the Unit list, select µs.

    model.result("pg3").feature("glob1").set("xdataparamunit", "\u00b5s");

//    Locate the Legends section.
//    From the Legends list, select Manual.

    model.result("pg3").feature("glob1").set("legendmethod", "manual");

//    In the table, enter the following settings:

    model.result("pg3").feature("glob1").setIndex("legends", "Program event", 0);
    model.result("pg3").run();

//    In the Model Builder window, right-click Tunnel Current and choose Global.

    model.result("pg3").create("glob2", "Global");
    model.result("pg3").feature("glob2").set("markerpos", "datapoints");
    model.result("pg3").feature("glob2").set("linewidth", "preference");

//    In the Settings window for Global, locate the Data section.
//    From the Dataset list, select Time dependent, Erase event/Solution 3 (sol3).

    model.result("pg3").feature("glob2").set("data", "dset3");

//    Locate the y-Axis Data section.
//    In the table, enter the following settings:

    return model;
  }

  public static Model run3(Model model) {

    model.result("pg3").feature("glob2").setIndex("expr", "semi.ii2.I_tun", 0);
    model.result("pg3").feature("glob2").setIndex("unit", "nA", 0);
    model.result("pg3").feature("glob2").setIndex("descr", "Tunnel current", 0);

//    Locate the x-Axis Data section.
//    From the Axis source data list, select Time.

    model.result("pg3").feature("glob2").set("xdatasolnumtype", "level1");

//    From the Unit list, select µs.

    model.result("pg3").feature("glob2").set("xdataparamunit", "\u00b5s");

//    Locate the Legends section.
//    From the Legends list, select Manual.

    model.result("pg3").feature("glob2").set("legendmethod", "manual");

//    In the table, enter the following settings:

    model.result("pg3").feature("glob2").setIndex("legends", "Erase event", 0);

//    In the Tunnel Current toolbar, click Plot.

    model.result("pg3").run();

//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg4", "PlotGroup1D");
    model.result("pg4").run();

//    In the Settings window for 1D Plot Group, locate the Data section.
//    From the Dataset list, select None.

    model.result("pg4").set("data", "none");

//    Locate the Title section.
//    From the Title type list, select Manual.

    model.result("pg4").set("titletype", "manual");

//    In the Title text area, type Floating gate charge as a function of time.

    model.result("pg4").set("title", "Floating gate charge as a function of time");

//    Locate the Plot Settings section.
//    Select the x-axis label checkbox.

    model.result("pg4").set("xlabelactive", true);

//    In the associated text field, type Time (us).

    model.result("pg4").set("xlabel", "Time (us)");

//    Select the y-axis label checkbox.

    model.result("pg4").set("ylabelactive", true);

//    In the associated text field, type Charge on Floating Gate (pC).

    model.result("pg4").set("ylabel", "Charge on Floating Gate (pC)");

//    Right-click 1D Plot Group 4 and choose Global.

    model.result("pg4").create("glob1", "Global");
    model.result("pg4").feature("glob1").set("markerpos", "datapoints");
    model.result("pg4").feature("glob1").set("linewidth", "preference");

//    In the Settings window for Global, locate the Data section.
//    From the Dataset list, select Time dependent, Program event/Solution 2 (sol2).

    model.result("pg4").feature("glob1").set("data", "dset2");

//    Locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg4").feature("glob1").setIndex("expr", "semi.fg1.Q0", 0);
    model.result("pg4").feature("glob1").setIndex("unit", "pC", 0);
    model.result("pg4").feature("glob1").setIndex("descr", "Charge", 0);

//    Locate the x-Axis Data section.
//    From the Axis source data list, select Time.

    model.result("pg4").feature("glob1").set("xdatasolnumtype", "level1");

//    From the Unit list, select µs.

    model.result("pg4").feature("glob1").set("xdataparamunit", "\u00b5s");

//    Locate the Legends section.
//    From the Legends list, select Manual.

    model.result("pg4").feature("glob1").set("legendmethod", "manual");

//    In the table, enter the following settings:

    model.result("pg4").feature("glob1").setIndex("legends", "Program event", 0);

//    Right-click Global 1 and choose Duplicate.

    model.result("pg4").feature().duplicate("glob2", "glob1");
    model.result("pg4").run();

//    In the Settings window for Global, locate the Data section.
//    From the Dataset list, select Time dependent, Erase event/Solution 3 (sol3).

    model.result("pg4").feature("glob2").set("data", "dset3");

//    Locate the Legends section.
//    In the table, enter the following settings:

    model.result("pg4").feature("glob2").setIndex("legends", "Erase event", 0);

//    In the 1D Plot Group 4 toolbar, click Plot.

    model.result("pg4").run();
    model.result("pg4").run();

//    In the Model Builder window, right-click 1D Plot Group 4 and choose Rename.
//    In the Rename 1D Plot Group dialog, type Floating Gate Charge in the New label text field.
//    Click OK.

    model.result("pg4").label("Floating Gate Charge");

    model.title("Programming of a Floating Gate EEPROM Device");

    model
         .description("This example calculates the current and charge characteristics of a floating gate Electrically Erasable Programmable Read-Only Memory (EEPROM) device. A stationary study demonstrates the effects of varying the charge stored on the floating gate by computing Current-Voltage curves as a function of the control gate voltage for two different amounts of stored charge. Time dependent studies are then used to simulate transient voltage pulses on the control gate. These pulses cause current to tunnel between the floating gate and the semiconductor material, allowing the EEPROM device to be both programmed and erased.");

    return model;
  }

  public static void main(String[] args) {
    Model model = run();
    model = run2(model);
    run3(model);
  }

}
