/*
 * streamer_in_transformer_oil.java
 */

import com.comsol.model.*;
import com.comsol.model.util.*;

/** Model exported on May 16 2026, 19:42 by COMSOL 6.4.0.422. */
public class streamer_in_transformer_oil {

  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 Axisymmetric.
//    In the Select Physics tree, select Electric Discharge > Electric Discharge (edis).
//    Click Add.
//    Click Study.
//    In the Select Study tree, select General Studies > Time Dependent.
//    Click Done.

    model.component().create("comp1", true);

    model.component("comp1").geom().create("geom1", 2);
    model.component("comp1").geom("geom1").axisymmetric(true);

    model.component("comp1").mesh().create("mesh1");

    model.component("comp1").physics().create("edis", "ElectricDischarge", "geom1");

    model.study().create("std1");
    model.study("std1").create("time", "Transient");

//    In the Model Builder window, under Component 1 (comp1), click Geometry 1.
//    In the Settings window for Geometry, locate the Units section.
//    From the Length unit list, select mm.

    model.component("comp1").geom("geom1").lengthUnit("mm");

//    In the Geometry toolbar, click Rectangle.

    model.component("comp1").geom("geom1").create("r1", "Rectangle");

//    In the Settings window for Rectangle, locate the Size and Shape section.
//    In the Width text field, type 15.

    model.component("comp1").geom("geom1").feature("r1").set("size", new double[]{15, 1});

//    In the Height text field, type 30.

    model.component("comp1").geom("geom1").feature("r1").set("size", new double[]{15, 30});

//    Click to expand the Layers section.
//    Select the Layers to the left checkbox.

    model.component("comp1").geom("geom1").feature("r1").set("layerleft", true);

//    Clear the Layers on bottom checkbox.

    model.component("comp1").geom("geom1").feature("r1").set("layerbottom", false);

//    In the table, enter the following settings:

    model.component("comp1").geom("geom1").feature("r1").setIndex("layer", 0.1, 0);

//    In the Geometry toolbar, click Rectangle.

    model.component("comp1").geom("geom1").run("r1");
    model.component("comp1").geom("geom1").create("r2", "Rectangle");

//    In the Settings window for Rectangle, locate the Size and Shape section.
//    In the Width text field, type 0.3.

    model.component("comp1").geom("geom1").feature("r2").set("size", new double[]{0.3, 1});

//    In the Height text field, type 3.

    model.component("comp1").geom("geom1").feature("r2").set("size", new double[]{0.3, 3});

//    Locate the Position section.
//    In the z text field, type 27.

    model.component("comp1").geom("geom1").feature("r2").set("pos", new double[]{0, 27});

//    In the Geometry toolbar, click Ellipse.

    model.component("comp1").geom("geom1").run("r2");
    model.component("comp1").geom("geom1").create("e1", "Ellipse");

//    In the Settings window for Ellipse, locate the Size and Shape section.
//    In the a-semiaxis text field, type 0.3.

    model.component("comp1").geom("geom1").feature("e1").set("semiaxes", new double[]{0.3, 1});

//    In the b-semiaxis text field, type 2.

    model.component("comp1").geom("geom1").feature("e1").set("semiaxes", new double[]{0.3, 2});

//    Locate the Position section.
//    In the z text field, type 27.

    model.component("comp1").geom("geom1").feature("e1").set("pos", new double[]{0, 27});

//    In the Geometry toolbar, click Rectangle.

    model.component("comp1").geom("geom1").run("e1");
    model.component("comp1").geom("geom1").create("r3", "Rectangle");

//    In the Settings window for Rectangle, locate the Size and Shape section.
//    In the Width text field, type 0.1.

    model.component("comp1").geom("geom1").feature("r3").set("size", new double[]{0.1, 1});

//    In the Height text field, type 0.6-1/1000.

    model.component("comp1").geom("geom1").feature("r3").set("size", new String[]{"0.1", "0.6-1/1000"});

//    Locate the Position section.
//    In the z text field, type 24.4.

    model.component("comp1").geom("geom1").feature("r3").set("pos", new double[]{0, 24.4});

//    Locate the Layers section.
//    Clear the Layers on bottom checkbox.

    model.component("comp1").geom("geom1").feature("r3").set("layerbottom", false);

//    Select the Layers to the left checkbox.

    model.component("comp1").geom("geom1").feature("r3").set("layerleft", true);

//    In the table, enter the following settings:

    model.component("comp1").geom("geom1").feature("r3").setIndex("layer", 0.03, 0);

//    In the Geometry toolbar, click Booleans and Partitions and choose Difference.

    model.component("comp1").geom("geom1").run("r3");
    model.component("comp1").geom("geom1").create("dif1", "Difference");

//    Select the object r1.

    model.component("comp1").geom("geom1").feature("dif1").selection("input").set("r1");

//    In the Settings window for Difference, locate the Difference section.
//    Select the Activate Selection toggle button for Objects to subtract.
//    Select the objects e1, r2.

    model.component("comp1").geom("geom1").feature("dif1").selection("input2").set("e1", "r2");

//    Click Build All Objects.

    model.component("comp1").geom("geom1").runPre("fin");

//    In the Definitions toolbar, click Analytic.

    model.component("comp1").func().create("an1", "Analytic");

//    In the Settings window for Analytic, type Vapp in the Function name text field.

    model.component("comp1").func("an1").set("funcname", "Vapp");

//    Locate the Definition section.
//    In the Expression text field, type 130*(exp(-t/100)-exp(-t/10)).

    model.component("comp1").func("an1").set("expr", "130*(exp(-t/100)-exp(-t/10))");

//    In the Arguments text field, type t.

    model.component("comp1").func("an1").set("args", "t");

//    Locate the Units section.
//    In the Function text field, type kV.

    model.component("comp1").func("an1").set("fununit", "kV");

//    In the table, enter the following settings:

    model.component("comp1").func("an1").setIndex("argunit", "ns", 0);
    model.component("comp1").func("an1").setIndex("plotargs", "90[ns]", 0, 2);

//    Locate the Plot Parameters section.
//    In the table, enter the following settings:
//    Click Plot.
//    Click the Zoom Extents button in the Graphics toolbar.

    model.component("comp1").geom("geom1").run();

//    Click the Show More Options button in the Model Builder toolbar.
//    In the Show More Options dialog, select Physics > Stabilization in the tree.
//    In the tree, select the checkbox for the Physics > Stabilization node.
//    Click OK.
//    In the Model Builder window, under Component 1 (comp1), click Electric Discharge (edis).
//    In the Settings window for Electric Discharge, locate the Physical Model section.
//    Clear the Gas checkbox.

    model.component("comp1").physics("edis").prop("PhysicalModel").set("Gas", false);

//    Select the Liquid checkbox.

    model.component("comp1").physics("edis").prop("PhysicalModel").set("Liquid", true);

//    Click to expand the Inconsistent Stabilization section.
//    Select the Isotropic diffusion checkbox.

    model.component("comp1").physics("edis").prop("Stabilization").set("IsotropicDiffusion", true);

//    In the Materials toolbar, click Add Material to open the Add Material window.
//    In the tree, select Electric Discharge > Liquids > Transformer Oil.
//    Right-click and choose Add to Component 1 (comp1).

    model.component("comp1").material().create("mat1", "Common");
    model.component("comp1").material("mat1").propertyGroup()
         .create("ChargeTransportLiquids", "ChargeTransportLiquids", "Charge transport in liquids");
    model.component("comp1").material("mat1").label("Transformer Oil");
    model.component("comp1").material("mat1").set("phase", "liquid");
    model.component("comp1").material("mat1").propertyGroup("def").set("relpermittivity", "");
    model.component("comp1").material("mat1").propertyGroup("def").set("electricconductivity", "");
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("relpermittivity", new String[]{"2.2", "0", "0", "0", "2.2", "0", "0", "0", "2.2"});
    model.component("comp1").material("mat1").propertyGroup("def")
         .set("electricconductivity", new String[]{"1e-12[S/m]", "0", "0", "0", "1e-12[S/m]", "0", "0", "0", "1e-12[S/m]"});
    model.component("comp1").material("mat1").propertyGroup("ChargeTransportLiquids")
         .set("mu_e", new String[]{"1e-4[m^2/V/s]", "0", "0", "0", "1e-4[m^2/V/s]", "0", "0", "0", "1e-4[m^2/V/s]"});
    model.component("comp1").material("mat1").propertyGroup("ChargeTransportLiquids")
         .set("mu_p", new String[]{"1e-9[m^2/V/s]", "0", "0", "0", "1e-9[m^2/V/s]", "0", "0", "0", "1e-9[m^2/V/s]"});
    model.component("comp1").material("mat1").propertyGroup("ChargeTransportLiquids")
         .set("mu_n", new String[]{"1e-9[m^2/V/s]", "0", "0", "0", "1e-9[m^2/V/s]", "0", "0", "0", "1e-9[m^2/V/s]"});
    model.component("comp1").material("mat1").propertyGroup("ChargeTransportLiquids")
         .set("beta_ep", "1.64e-17[m^3/s]");
    model.component("comp1").material("mat1").propertyGroup("ChargeTransportLiquids")
         .set("beta_pn", "1.64e-17[m^3/s]");
    model.component("comp1").material("mat1").propertyGroup("ChargeTransportLiquids").set("tau_a", "200[ns]");
    model.component("comp1").material("mat1").propertyGroup("ChargeTransportLiquids").set("n_ioni", "1e23[1/m^3]");
    model.component("comp1").material("mat1").propertyGroup("ChargeTransportLiquids").set("a", "3[\u00c5]");
    model.component("comp1").material("mat1").propertyGroup("ChargeTransportLiquids").set("m_eff", "0.1*me_const");
    model.component("comp1").material("mat1").propertyGroup("ChargeTransportLiquids").set("phi_Delta", "7[V]");
    model.component("comp1").material("mat1").propertyGroup("ChargeTransportLiquids").set("phi_gamma", "0.07[V]");

//    In the Materials toolbar, click Add Material to close the Add Material window.
//    In the Physics toolbar, click Attributes and choose Electrode.

    model.component("comp1").physics("edis").feature("liquid1").create("ece1", "Electrode", 1);

//    Select Boundaries 14, 17, 18.

    model.component("comp1").physics("edis").feature("liquid1").feature("ece1").selection().set(14, 17, 18);

//    In the Settings window for Electrode, locate the Terminal section.
//    In the \[V_0\] text field, type Vapp(t).

    model.component("comp1").physics("edis").feature("liquid1").feature("ece1").set("V0", "Vapp(t)");

//    Locate the Charge Transport section.
//    From the Boundary condition for positive ions list, select Number density.

    model.component("comp1").physics("edis").feature("liquid1").feature("ece1").set("pBnd", "NumberDensity");

//    In the Model Builder window, click Liquid 1.
//    In the Physics toolbar, click Attributes and choose Electrode.

    model.component("comp1").physics("edis").feature("liquid1").create("ece2", "Electrode", 1);

//    Click the Zoom Extents button in the Graphics toolbar.
//    Select Boundaries 2, 11.

    model.component("comp1").physics("edis").feature("liquid1").feature("ece2").selection().set(2, 11);

//    In the Settings window for Electrode, locate the Charge Transport section.
//    From the Boundary condition for electrons list, select Number density.

    model.component("comp1").physics("edis").feature("liquid1").feature("ece2").set("eBnd", "NumberDensity");

//    From the Boundary condition for negative ions list, select Number density.

    model.component("comp1").physics("edis").feature("liquid1").feature("ece2").set("nBnd", "NumberDensity");

//    In the Mesh toolbar, click Mapped.

    model.component("comp1").mesh("mesh1").create("map1", "Map");

//    Click the Zoom Box button in the Graphics toolbar.
//    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 Domain 2.

    model.component("comp1").mesh("mesh1").feature("map1").selection().set(2);

//    Right-click Mapped 1 and choose Distribution.

    model.component("comp1").mesh("mesh1").feature("map1").create("dis1", "Distribution");

//    Select Boundaries 4, 6.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis1").selection().set(4, 6);

//    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 40.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis1").set("elemcount", 40);

//    Select the Reverse direction checkbox.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis1").set("reverse", true);

//    In the Element ratio text field, type 5.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis1").set("elemratio", 5);

//    In the Model Builder window, right-click Mapped 1 and choose Distribution.

    model.component("comp1").mesh("mesh1").feature("map1").create("dis2", "Distribution");

//    Select Boundaries 3, 7.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis2").selection().set(3, 7);

//    In the Settings window for Distribution, locate the Distribution section.
//    In the Number of elements text field, type 400.

    model.component("comp1").mesh("mesh1").feature("map1").feature("dis2").set("numelem", 400);

//    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 Domain 3.

    model.component("comp1").mesh("mesh1").feature("ftri1").selection().set(3);

//    Right-click Free Triangular 1 and choose Size.

    model.component("comp1").mesh("mesh1").feature("ftri1").create("size1", "Size");

//    In the Settings window for Size, locate the Element Size section.
//    Click the Custom button.

    model.component("comp1").mesh("mesh1").feature("ftri1").feature("size1").set("custom", true);

//    Locate the Element Size Parameters section.
//    Select the Maximum element size checkbox.

    model.component("comp1").mesh("mesh1").feature("ftri1").feature("size1").set("hmaxactive", true);

//    In the associated text field, type 1/300.

    model.component("comp1").mesh("mesh1").feature("ftri1").feature("size1").set("hmax", "1/300");

//    In the Mesh toolbar, click Free Triangular.

    model.component("comp1").mesh("mesh1").create("ftri2", "FreeTri");

//    In the Settings window for Free Triangular, click Build All.

    model.component("comp1").mesh("mesh1").run();

//    In the Mesh toolbar, click Boundary Layers.

    model.component("comp1").mesh("mesh1").create("bl1", "BndLayer");
    model.component("comp1").mesh("mesh1").feature("bl1").create("blp", "BndLayerProp");
    model.component("comp1").mesh("mesh1").feature("bl1").selection().geom(2);
    model.component("comp1").mesh("mesh1").feature("bl1").selection().set();
    model.component("comp1").mesh("mesh1").feature("bl1").selection().allGeom();

//    In the Model Builder window, click Boundary Layer Properties.
//    Select Boundary 17.

    model.component("comp1").mesh("mesh1").feature("bl1").feature("blp").selection().set(17);

//    In the Settings window for Boundary Layer Properties, locate the Layers section.
//    In the Number of layers text field, type 3.

    model.component("comp1").mesh("mesh1").feature("bl1").feature("blp").set("blnlayers", 3);

//    In the Stretching factor text field, type 1.5.

    model.component("comp1").mesh("mesh1").feature("bl1").feature("blp").set("blstretch", 1.5);

//    Click Build All.

    model.component("comp1").mesh("mesh1").run();

//    Click the Zoom Extents button in the Graphics toolbar.
//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Model Builder window, under Study 1, click Step 1: Time Dependent.
//    In the Settings window for Time Dependent, locate the Study Settings section.
//    From the Time unit list, select ns.

    model.study("std1").feature("time").set("tunit", "ns");

//    In the Output times text field, type range(0,10,90).

    model.study("std1").feature("time").set("tlist", "range(0,10,90)");

//    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 Show Default Solver.

    model.study("std1").showAutoSequences("all");

//    In the Model Builder window, expand the Solution 1 (sol1) node.
//    Setting a maximum timestep variable based on the built-in dielectric relaxation time can help improve both efficiency and accuracy.
//    In the Model Builder window, under Study 1 > Solver Configurations > Solution 1 (sol1), click Time-Dependent Solver 1.
//    In the Settings window for Time-Dependent Solver, click to expand the Time Stepping section.
//    From the Maximum step constraint list, select Expression.

    model.sol("sol1").feature("t1").set("maxstepconstraintbdf", "expr");

//    In the Maximum step text field, type min(0.1[ns],comp1.edis.minDRT*0.8).

    model.sol("sol1").feature("t1").set("maxstepexpressionbdf", "min(0.1[ns],comp1.edis.minDRT*0.8)");

//    The PARDISO direct solver is usually a bit faster and leaner on memory than the default direct solver (MUMPS) on this type of model.
//    In the Model Builder window, under Study 1 > Solver Configurations > Solution 1 (sol1) > Time-Dependent Solver 1, click Direct.
//    In the Settings window for Direct, locate the General section.
//    From the Solver list, select PARDISO.

    model.sol("sol1").feature("t1").feature("dDef").set("linsolver", "pardiso");

//    In the Study toolbar, click Compute.

    model.study("std1").createAutoSequences("all");

    model.sol("sol1").runAll();

//    In the Model Builder window, expand the Results node.
//    In the Model Builder window, expand the Results > Datasets node, then click Study 1/Solution 1 (sol1).
//    In the Results toolbar, click Attributes and choose Selection.
//    In the Settings window for Selection, locate the Geometric Entity Selection section.
//    From the Geometric entity level list, select Domain.

    model.result().dataset("dset1").selection().geom("geom1", 2);

//    Select Domains 2, 3, 4.

    model.result().dataset("dset1").selection().geom("geom1", 2);
    model.result().dataset("dset1").selection().set(2, 3, 4);

//    In the Results toolbar, click More Datasets and choose Mirror 2D.

    model.result().dataset().create("mir1", "Mirror2D");

//    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");
    model.result("pg1").run();

//    In the Settings window for 2D Plot Group, locate the Plot Settings section.
//    Clear the Plot dataset edges checkbox.

    model.result("pg1").set("edges", false);
    model.result("pg1").run();

//    In the Model Builder window, click Surface 1.
//    In the Settings window for Surface, locate the Data section.
//    From the Dataset list, select Mirror 2D 1.

    model.result("pg1").feature("surf1").set("data", "mir1");
    model.result("pg1").run();

//    In the Model Builder window, right-click 2D Plot Group 1 and choose Surface.

    model.result("pg1").create("surf2", "Surface");
    model.result("pg1").feature("surf2").set("evaluationsettings", "parent");

//    In the Settings window for Surface, locate the Expression section.
//    In the Expression text field, type edis.normE.

    model.result("pg1").feature("surf2").set("expr", "edis.normE");

//    In the Unit field, type kV/mm.

    model.result("pg1").feature("surf2").set("unit", "kV/mm");

//    In the 2D Plot Group 1 toolbar, click Plot.

    model.result("pg1").run();
    model.result("pg1").run();

//    In the Model Builder window, click Surface 1.
//    In the Settings window for Surface, locate the Coloring and Style section.
//    From the Color table list, select WaveLight.

    model.result("pg1").feature("surf1").set("colortable", "WaveLight");
    model.result("pg1").run();

//    In the Model Builder window, click Surface 2.
//    In the Settings window for Surface, locate the Coloring and Style section.
//    From the Color table list, select RainbowLight.

    model.result("pg1").feature("surf2").set("colortable", "RainbowLight");
    model.result("pg1").run();

//    Click the Zoom Extents button in the Graphics toolbar.
//    In the Model Builder window, click 2D Plot Group 1.
//    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, locate the Legend section.
//    From the Position list, select Lower left.

    model.result("pg2").set("legendpos", "lowerleft");

//    Right-click 1D Plot Group 2 and choose Line Graph.

    model.result("pg2").create("lngr1", "LineGraph");
    model.result("pg2").feature("lngr1").set("markerpos", "datapoints");
    model.result("pg2").feature("lngr1").set("linewidth", "preference");
    model.result("pg2").feature("lngr1").set("evaluationsettings", "parent");

//    Select Boundaries 3, 5.

    model.result("pg2").feature("lngr1").selection().set(3, 5);

//    In the Settings window for Line Graph, locate the y-Axis Data section.
//    In the Expression text field, type edis.Ez.

    model.result("pg2").feature("lngr1").set("expr", "edis.Ez");

//    In the Unit field, type kV/mm.

    model.result("pg2").feature("lngr1").set("unit", "kV/mm");

//    Click to expand the Legends section.
//    Select the Show legends checkbox.

    model.result("pg2").feature("lngr1").set("legend", true);

//    In the 1D Plot Group 2 toolbar, click Plot.

    model.result("pg2").run();
    model.result("pg2").run();

//    In the Model Builder window, right-click Results > 1D Plot Group 2 and choose Duplicate.

    model.result().duplicate("pg3", "pg2");
    model.result("pg3").run();

//    In the Model Builder window, click 1D Plot Group 3.
//    In the Settings window for 1D Plot Group, locate the Legend section.
//    From the Position list, select Upper left.

    model.result("pg3").set("legendpos", "upperleft");
    model.result("pg3").run();

//    In the Model Builder window, click Line Graph 1.
//    In the Settings window for Line Graph, locate the y-Axis Data section.
//    In the Expression text field, type edis.n_e.

    model.result("pg3").feature("lngr1").set("expr", "edis.n_e");

//    In the Unit field, type 1/cm^3.

    model.result("pg3").feature("lngr1").set("unit", "1/cm^3");

//    Click the y-Axis Log Scale button in the Graphics toolbar.

    model.result("pg3").set("ylog", true);

//    In the 1D Plot Group 3 toolbar, click Plot.

    model.result("pg3").run();
    model.result("pg1").run();

    model.title("Positive Streamer Propagation in Transformer Oil");

    model
         .description("This example simulates the propagation of a positive streamer in transformer oil under a lightning impulse voltage. The space charge density and the electric field are obtained. The simulated streamer radius agrees well with the measured values.");

    return model;
  }

  public static void main(String[] args) {
    run();
  }

}
