/*
 * computing_plasma_impedance.java
 */

import com.comsol.model.*;
import com.comsol.model.util.*;

/** Model exported on May 15 2026, 12:52 by COMSOL 6.4.0.421. */
public class computing_plasma_impedance {

  public static Model run() {
    Model model = ModelUtil.create("Model");

//    From the File menu, choose New.
//    In the New window, click Model Wizard.
//    In order to illustrate the modeling steps required to model a simple capacitive discharge and compute its impedance at the fundamental frequency, this example will be 1D with a simple plasma chemistry. We first illustrate this procedure at low power, then again at high power.
//    In the Model Wizard window, click 1D.
//    In the Select Physics tree, select Plasma > Plasma, Time Periodic (ptp).
//    Click Add.
//    Click Study.
//    In the Select Study tree, select Preset Studies for Selected Physics Interfaces > Time Periodic.
//    Click Done.

    model.component().create("comp1", true);

    model.component("comp1").geom().create("geom1", 1);

    model.component("comp1").mesh().create("mesh1");

    model.component("comp1").physics().create("ptp", "ColdPlasmaTimePeriodic", "geom1");

    model.study().create("std1");
    model.study("std1").create("tper", "TimePeriodic");
    model.study("std1").feature("tper").set("solnum", "auto");
    model.study("std1").feature("tper").set("notsolnum", "auto");
    model.study("std1").feature("tper").set("outputmap", new String[]{});
    model.study("std1").feature("tper").set("ngenAUX", "1");
    model.study("std1").feature("tper").set("ngen", "2");
    model.study("std1").feature("tper").set("goalngenAUX", "1");
    model.study("std1").feature("tper").set("ngenAUX", "1");
    model.study("std1").feature("tper").set("ngen", "2");
    model.study("std1").feature("tper").set("goalngenAUX", "1");

//    The <l>Time Periodic</l> study computes the periodic steady state solution of the plasma. Add some parameters for the geometric size, power, frequency and pressure.
//    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("L", "0.025[m]");
    model.param().descr("L", "Discharge gap");
    model.param().set("de", "0.3[m]");
    model.param().descr("de", "Electrode diameter");
    model.param().set("As", "0.25*pi*de^2");
    model.param().descr("As", "Electrode area");
    model.param().set("P0", "10[W]");
    model.param().descr("P0", "Input power");
    model.param().set("f0", "13.56E6[Hz]");
    model.param().descr("f0", "Frequency");
    model.param().set("p0", "1[torr]");
    model.param().descr("p0", "Pressure");
    model.param().set("T0", "300[K]");
    model.param().descr("T0", "Temperature");

//    In the Model Builder window, right-click Component 1 (comp1) > Geometry 1 and choose Interval.

    model.component("comp1").geom("geom1").create("i1", "Interval");

//    In the Settings window for Interval, locate the Interval section.
//    In the table, enter the following settings:

    model.component("comp1").geom("geom1").feature("i1").setIndex("coord", "L", 1);

//    Click Build All Objects.

    model.component("comp1").geom("geom1").runPre("fin");

//    Click the Zoom Extents button in the Graphics toolbar.

    model.component("comp1").geom("geom1").run();

//    In the Model Builder window, under Component 1 (comp1), click Plasma, Time Periodic (ptp).
//    In the Settings window for Plasma, Time Periodic, locate the Cross-Section Area section.
//    In the \[A\] text field, type As.

    model.component("comp1").physics("ptp").prop("CrossSectionArea").set("A", "As");

//    Locate the Plasma Properties section.
//    Select the Use reduced electron transport properties checkbox.

    model.component("comp1").physics("ptp").prop("ElectronProperties").set("ReducedProps", true);

//    Locate the Extra Dimension Settings section.
//    In the \[P_{\textrm{xd}}\] text field, type 1/f0.

    model.component("comp1").physics("ptp").prop("ExtraDimensionSettings").set("Period_xd", "1/f0");

//    In the \[N\] text field, type 30.

    model.component("comp1").physics("ptp").prop("ExtraDimensionSettings").set("Nelemptp", 30);

//    Next, import cross section data for helium.
//    In the Physics toolbar, click Global and choose Cross Section Import.

    model.component("comp1").physics("ptp").create("xsec1", "CrossSectionImport", -1);

//    In the Settings window for Cross Section Import, locate the Cross Section Import section.
//    Click Browse.
//    Browse to the model's Application Library folder and double-click the file He_xsecs.txt.

    model.component("comp1").physics("ptp").feature("xsec1").set("Filepath", "He_xsecs.txt");

//    Click Import.

    model.component("comp1").physics("ptp").feature("xsec1").runCommand("importData");

//    In the Model Builder window, click Species: He.
//    In the Settings window for Species, locate the Species Formula section.
//    Select the From mass constraint checkbox.

    model.component("comp1").physics("ptp").feature("He").set("FromMassConstraint", true);

//    Locate the General Parameters section.
//    From the Preset species data list, select He.

    model.component("comp1").physics("ptp").feature("He").set("PresetSpeciesData", "He");

//    In the Model Builder window, click Species: Hes.
//    In the Settings window for Species, locate the General Parameters section.
//    From the Preset species data list, select He.

    model.component("comp1").physics("ptp").feature("Hes").set("PresetSpeciesData", "He");

//    The electric fields generated will be rather high in the sheath, so use the local field approximation for the ion temperature, and a lookup table for the ion mobility.
//    In the Model Builder window, click Species: He+.
//    In the Settings window for Species, locate the General Parameters section.
//    From the Preset species data list, select He.

    model.component("comp1").physics("ptp").feature("He_1p").set("PresetSpeciesData", "He");

//    Locate the Species Formula section.
//    Select the Initial value from electroneutrality constraint checkbox.

    model.component("comp1").physics("ptp").feature("He_1p").set("InitIon", true);

//    Locate the Mobility and Diffusivity Expressions section.
//    From the Specification list, select Specify mobility, compute diffusivity.

    model.component("comp1").physics("ptp").feature("He_1p")
         .set("MobilityDiffusivitySpecification", "SpecifyMobilityComputeDiffusivity");

//    From the Ion temperature list, select Use local field approximation.

    model.component("comp1").physics("ptp").feature("He_1p")
         .set("IonTemperatureSpecification", "LocalFieldApproximation");

//    Locate the Mobility Specification section.
//    From the Specify using list, select Helium ion in helium.

    model.component("comp1").physics("ptp").feature("He_1p").set("MobilitySpecification", "HeIoninHe");

//    In the Model Builder window, click Plasma Model 1.
//    In the Settings window for Plasma Model, locate the Model Inputs section.
//    In the \[T\] text field, type T0.

    model.component("comp1").physics("ptp").feature("pes1").set("T", "T0");

//    In the \[p_A\] text field, type p0.

    model.component("comp1").physics("ptp").feature("pes1").set("pA", "p0");

//    The electron mobility and other transport parameters can be automatically computed from the set of electron impact reactions.
//    Add surface reactions for the loss of ions and electronically excited helium atoms at the walls.
//    In the Physics toolbar, click Boundaries and choose Surface Reaction.

    model.component("comp1").physics("ptp").create("sr1", "SurfaceReaction", 0);

//    In the Settings window for Surface Reaction, locate the Boundary Selection section.
//    From the Selection list, select All boundaries.

    model.component("comp1").physics("ptp").feature("sr1").selection().all();

//    Locate the Reaction Formula section.
//    In the Formula text field, type He+=>He.

    model.component("comp1").physics("ptp").feature("sr1").set("formula", "He+=>He");

//    Locate the Reaction Parameters section.
//    In the \[\gamma_{\textrm{f}}\] text field, type 0.

    model.component("comp1").physics("ptp").feature("sr1").set("gammaf", 0);

//    Locate the Secondary Emission Parameters section.
//    In the \[\gamma_i\] text field, type 0.1.

    model.component("comp1").physics("ptp").feature("sr1").set("gammai", 0.1);

//    In the \[\varepsilon_i\] text field, type 5.8.

    model.component("comp1").physics("ptp").feature("sr1").set("ebari", 5.8);

//    Right-click 1: He+=>He and choose Duplicate.

    model.component("comp1").physics("ptp").feature().duplicate("sr2", "sr1");

//    In the Settings window for Surface Reaction, locate the Reaction Formula section.
//    In the Formula text field, type Hes=>He.

    model.component("comp1").physics("ptp").feature("sr2").set("formula", "Hes=>He");

//    Locate the Reaction Parameters section.
//    In the \[\gamma_{\textrm{f}}\] text field, type 1.

    model.component("comp1").physics("ptp").feature("sr2").set("gammaf", 1);

//    In the Physics toolbar, click Boundaries and choose Wall.

    model.component("comp1").physics("ptp").create("wall1", "WallDriftDiffusion", 0);

//    In the Settings window for Wall, locate the Boundary Selection section.
//    From the Selection list, select All boundaries.

    model.component("comp1").physics("ptp").feature("wall1").selection().all();

//    In the Physics toolbar, click Boundaries and choose Ground.

    model.component("comp1").physics("ptp").create("gnd1", "Ground", 0);

//    Select Boundary 2.

    model.component("comp1").physics("ptp").feature("gnd1").selection().set(2);

//    The most stable way of driving the electrode is to use a fixed power.
//    In the Physics toolbar, click Boundaries and choose Metal Contact.

    model.component("comp1").physics("ptp").create("mct1", "MetalContact", 0);

//    Select Boundary 1.

    model.component("comp1").physics("ptp").feature("mct1").selection().set(1);

//    In the Settings window for Metal Contact, locate the Terminal section.
//    From the Source list, select RF.

    model.component("comp1").physics("ptp").feature("mct1").set("Source", "RF");

//    Locate the RF Source section.
//    In the \[P_{\textrm{rf}}\] text field, type P0.

    model.component("comp1").physics("ptp").feature("mct1").set("Prf", "P0");

//    In the \[f_p\] text field, type f0.

    model.component("comp1").physics("ptp").feature("mct1").set("fp", "f0");

//    In the Mesh toolbar, click Edge.

    model.component("comp1").mesh("mesh1").create("edg1", "Edge");

//    Right-click Edge 1 and choose Distribution.

    model.component("comp1").mesh("mesh1").feature("edg1").create("dis1", "Distribution");

//    In the Settings window for Distribution, locate the Distribution section.
//    From the Distribution type list, select Predefined.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("dis1").set("type", "predefined");

//    In the Number of elements text field, type 125.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("dis1").set("elemcount", 125);

//    In the Element ratio text field, type 10.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("dis1").set("elemratio", 10);

//    Select the Symmetric distribution checkbox.

    model.component("comp1").mesh("mesh1").feature("edg1").feature("dis1").set("symmetric", true);

//    Click Build All.

    model.component("comp1").mesh("mesh1").run();

//    In the Model Builder window, click Study 1.
//    In the Settings window for Study, type Time Periodic in the Label text field.

    model.study("std1").label("Time Periodic");

//    In the Study toolbar, click Compute.

    model.study("std1").createAutoSequences("all");

    model.sol("sol1").runAll();

    model.result().create("pg1", "PlotGroup1D");
    model.result("pg1").set("data", "dset1");
    model.result("pg1").create("lngr1", "LineGraph");
    model.result("pg1").feature("lngr1").set("xdata", "expr");
    model.result("pg1").feature("lngr1").set("xdataexpr", "x");
    model.result("pg1").feature("lngr1").selection().geom("geom1", 1);
    model.result("pg1").feature("lngr1").selection().set(1);
    model.result("pg1").feature("lngr1").set("expr", new String[]{"ptp.neav"});
    model.result().create("pg2", "PlotGroup1D");
    model.result("pg2").set("data", "dset1");
    model.result("pg2").create("lngr1", "LineGraph");
    model.result("pg2").feature("lngr1").set("xdata", "expr");
    model.result("pg2").feature("lngr1").set("xdataexpr", "x");
    model.result("pg2").feature("lngr1").selection().geom("geom1", 1);
    model.result("pg2").feature("lngr1").selection().set(1);
    model.result("pg2").feature("lngr1").set("expr", new String[]{"ptp.Teav"});
    model.result().create("pg3", "PlotGroup1D");
    model.result("pg3").set("data", "dset1");
    model.result("pg3").create("lngr1", "LineGraph");
    model.result("pg3").feature("lngr1").set("xdata", "expr");
    model.result("pg3").feature("lngr1").set("xdataexpr", "x");
    model.result("pg3").feature("lngr1").selection().geom("geom1", 1);
    model.result("pg3").feature("lngr1").selection().set(1);
    model.result("pg3").feature("lngr1").set("expr", new String[]{"ptp.Vav"});
    model.result().create("pg4", "PlotGroup1D");
    model.result("pg4").set("data", "dset1");
    model.result("pg4").create("lngr1", "LineGraph");
    model.result("pg4").feature("lngr1").set("xdata", "expr");
    model.result("pg4").feature("lngr1").set("xdataexpr", new String[]{"x"});
    model.result("pg4").feature("lngr1").selection().all();
    model.result("pg4").feature("lngr1").set("expr", new String[]{"ptp.Pcap_av"});
    model.result("pg4").feature("lngr1").set("legend", true);
    model.result("pg4").feature("lngr1").set("legendmethod", "manual");
    model.result("pg4").feature("lngr1").setIndex("legends", "Electrons", 0);
    model.result("pg4").feature("lngr1").set("resolution", "norefine");
    model.result("pg4").create("lngr2", "LineGraph");
    model.result("pg4").feature("lngr2").set("xdata", "expr");
    model.result("pg4").feature("lngr2").set("xdataexpr", new String[]{"x"});
    model.result("pg4").feature("lngr2").selection().all();
    model.result("pg4").feature("lngr2").set("expr", new String[]{"ptp.Pcap_ions_av"});
    model.result("pg4").feature("lngr2").set("legend", true);
    model.result("pg4").feature("lngr2").set("legendmethod", "manual");
    model.result("pg4").feature("lngr2").setIndex("legends", "Ions", 0);
    model.result("pg4").feature("lngr2").set("resolution", "norefine");
    model.result("pg4").create("lngr3", "LineGraph");
    model.result("pg4").feature("lngr3").set("xdata", "expr");
    model.result("pg4").feature("lngr3").set("xdataexpr", new String[]{"x"});
    model.result("pg4").feature("lngr3").selection().all();
    model.result("pg4").feature("lngr3").set("expr", new String[]{"ptp.Pcap_ele_ions_av"});
    model.result("pg4").feature("lngr3").set("legend", true);
    model.result("pg4").feature("lngr3").set("legendmethod", "manual");
    model.result("pg4").feature("lngr3").setIndex("legends", "Electrons and ions", 0);
    model.result("pg4").feature("lngr3").set("resolution", "norefine");
    model.result("pg4").set("ylabelactive", true);
    model.result("pg4").set("ylabel", "Power Deposition (W/m<sup>3</sup>)");
    model.result("pg4").set("titletype", "none");
    model.result("pg4").label("Capacitive Power Deposition, Period Averaged (ptp)");
    model.result().create("pg5", "PlotGroup1D");
    model.result("pg5").set("data", "dset1");
    model.result("pg5").set("ylog", true);
    model.result("pg5").set("titletype", "manual");
    model.result("pg5").set("title", "Neutral Species Number Density, Period Averaged (1/m<sup>3</sup>)");
    model.result().create("pg6", "PlotGroup1D");
    model.result("pg6").set("data", "dset1");
    model.result("pg6").set("ylog", true);
    model.result("pg6").set("titletype", "manual");
    model.result("pg6").set("title", "Charged Species Number Density, Period Averaged (1/m<sup>3</sup>)");
    model.result("pg6").set("ylabel", "Number density (1/m<sup>3</sup>)");
    model.result("pg5").create("lngr1", "LineGraph");
    model.result("pg5").feature("lngr1").set("xdata", "expr");
    model.result("pg5").feature("lngr1").set("xdataexpr", new String[]{"x"});
    model.result("pg5").feature("lngr1").selection().all();
    model.result("pg5").feature("lngr1").set("expr", new String[]{"ptp.n_wHe_av"});
    model.result("pg5").feature("lngr1").set("legend", true);
    model.result("pg5").feature("lngr1").set("legendmethod", "manual");
    model.result("pg5").feature("lngr1").setIndex("legends", "wHe", 0);
    model.result("pg5").create("lngr2", "LineGraph");
    model.result("pg5").feature("lngr2").set("xdata", "expr");
    model.result("pg5").feature("lngr2").set("xdataexpr", new String[]{"x"});
    model.result("pg5").feature("lngr2").selection().all();
    model.result("pg5").feature("lngr2").set("expr", new String[]{"ptp.n_wHes_av"});
    model.result("pg5").feature("lngr2").set("legend", true);
    model.result("pg5").feature("lngr2").set("legendmethod", "manual");
    model.result("pg5").feature("lngr2").setIndex("legends", "wHes", 0);
    model.result("pg6").create("lngr1", "LineGraph");
    model.result("pg6").feature("lngr1").set("xdata", "expr");
    model.result("pg6").feature("lngr1").set("xdataexpr", new String[]{"x"});
    model.result("pg6").feature("lngr1").selection().all();
    model.result("pg6").feature("lngr1").set("expr", new String[]{"ptp.n_wHe_1p_av"});
    model.result("pg6").feature("lngr1").set("legend", true);
    model.result("pg6").feature("lngr1").set("legendmethod", "manual");
    model.result("pg6").feature("lngr1").setIndex("legends", "wHe_1p", 0);
    model.result("pg6").create("lngr2", "LineGraph");
    model.result("pg6").feature("lngr2").set("xdata", "expr");
    model.result("pg6").feature("lngr2").set("xdataexpr", new String[]{"x"});
    model.result("pg6").feature("lngr2").selection().all();
    model.result("pg6").feature("lngr2").set("expr", new String[]{"ptp.neav"});
    model.result("pg6").feature("lngr2").set("legend", true);
    model.result("pg6").feature("lngr2").set("legendmethod", "manual");
    model.result("pg6").feature("lngr2").setIndex("legends", "ne", 0);
    model.result("pg5").label("Neutral Species Number Density, Period Averaged (ptp)");
    model.result("pg6").label("Charged Species Number Density, Period Averaged (ptp)");
    model.result("pg1").label("Electron Density, Period Averaged (ptp)");
    model.result("pg2").label("Electron Temperature, Period Averaged (ptp)");
    model.result("pg3").label("Electric Potential, Period Averaged (ptp)");
    model.result().dataset().create("dset2", "Solution");
    model.result().dataset("dset2").set("solution", "sol1");
    model.result().dataset("dset2").set("geom", "ptp_xdim");
    model.result().create("pg7", "PlotGroup1D");
    model.result("pg7").set("data", "dset2");
    model.result("pg7").create("lngr1", "LineGraph");
    model.result("pg7").feature("lngr1").set("xdata", "expr");
    model.result("pg7").feature("lngr1").set("xdataexpr", new String[]{"x1_ptp"});
    model.result("pg7").feature("lngr1").selection().all();
    model.result("pg7").feature("lngr1").set("expr", new String[]{"ptp.mct1.V"});
    model.result("pg7").feature("lngr1").set("legend", true);
    model.result("pg7").feature("lngr1").set("legendmethod", "manual");
    model.result("pg7").feature("lngr1").setIndex("legends", "V", 0);
    model.result("pg7").create("lngr2", "LineGraph");
    model.result("pg7").feature("lngr2").set("xdata", "expr");
    model.result("pg7").feature("lngr2").set("xdataexpr", new String[]{"x1_ptp"});
    model.result("pg7").feature("lngr2").selection().all();
    model.result("pg7").feature("lngr2").set("expr", new String[]{"ptp.mct1.I"});
    model.result("pg7").feature("lngr2").set("resolution", "norefine");
    model.result("pg7").feature("lngr2").set("legend", true);
    model.result("pg7").feature("lngr2").set("legendmethod", "manual");
    model.result("pg7").feature("lngr2").setIndex("legends", "I", 0);
    model.result("pg7").set("twoyaxes", true);
    model.result("pg7").setIndex("plotonsecyaxis", true, 0, 1);
    model.result("pg7").set("titletype", "none");
    model.result("pg7").set("xlabelactive", true);
    model.result("pg7").set("xlabel", "Period fraction");
    model.result("pg7").label("Current and Voltage, Metal Contact 1 (ptp)");
    model.result("pg1").run();

//    So far, we have computed the periodic steady state solution only. In order to see the time-dependent behavior of the plasma, we need to convert the solution to the time domain. To do this, use the <l>Time Periodic to Time Dependent</l> study.

    model.result("pg2").run();
    model.result("pg3").run();
    model.result("pg4").run();
    model.result("pg5").run();
    model.result("pg6").run();
    model.result("pg7").run();

//    In the Home toolbar, click Add Study to open the Add Study window.
//    Find the Studies subsection.
//    In the Select Study tree, select Preset Studies for Selected Physics Interfaces > Time Periodic to Time Dependent.
//    Click Add Study in the window toolbar.

    model.study().create("std2");
    model.study("std2").create("tptd", "TimePeriodicToTimeDependent");
    model.study("std2").feature("tptd").set("initialtime", "0");
    model.study("std2").feature("tptd").set("solnum", "auto");
    model.study("std2").feature("tptd").set("notsolnum", "auto");
    model.study("std2").feature("tptd").set("outputmap", new String[]{});

//    In the Home toolbar, click Add Study to close the Add Study window.
//    The final output time should correspond to 1 RF cycle. The number of output times should typically be around 100. When computing the time periodic solution, only 30 points were used in the (hidden) time axis. When converting to the time domain, COMSOL will use linear interpolation of the solution between these points.
//    In the Settings window for Time Periodic to Time Dependent, locate the Study Settings section.
//    Click Range.
//    In the Range dialog, choose Number of values from the Entry method list.
//    In the Stop text field, type 1/f0.
//    In the Number of values text field, type 101.
//    Click Replace.

    model.study("std2").feature("tptd").set("tlist", "range(0,(1/f0-0)/100,1/f0)");

//    In the Settings window for Time Periodic to Time Dependent, click to expand the Values of Dependent Variables section.
//    Find the Values of variables not solved for subsection.
//    From the Settings list, select User controlled.

    model.study("std2").feature("tptd").set("usesol", true);

//    From the Method list, select Solution.

    model.study("std2").feature("tptd").set("notsolmethod", "sol");

//    From the Study list, select Time Periodic, Time Periodic.

    model.study("std2").feature("tptd").set("notstudy", "std1");

//    In the Model Builder window, click Study 2.
//    In the Settings window for Study, type Time Periodic to Time Dependent in the Label text field.

    model.study("std2").label("Time Periodic to Time Dependent");

//    Locate the Study Settings section.
//    Clear the Generate convergence plots checkbox.

    model.study("std2").setGenConv(false);

//    Clear the Generate default plots checkbox.

    model.study("std2").setGenPlots(false);

//    In the Study toolbar, click Compute.

    model.study("std2").createAutoSequences("all");

    model.sol("sol2").runAll();

//    Next, create an FFT plot of the electrode current, so the relative magnitude of the harmonic content can be visualized.
//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg8", "PlotGroup1D");
    model.result("pg8").run();

//    In the Settings window for 1D Plot Group, type Harmonic Content of the Current in the Label text field.

    model.result("pg8").label("Harmonic Content of the Current");

//    Locate the Data section.
//    From the Dataset list, select Time Periodic to Time Dependent/Solution 2 (sol2).

    model.result("pg8").set("data", "dset3");

//    Right-click Harmonic Content of the Current and choose Global.

    model.result("pg8").create("glob1", "Global");
    model.result("pg8").feature("glob1").set("markerpos", "datapoints");
    model.result("pg8").feature("glob1").set("linewidth", "preference");

//    In the Settings window for Global, click Replace Expression in the upper-right corner of the y-Axis Data section.
//    From the menu, choose Component 1 (comp1) > Plasma, Time Periodic > Metal Contact 1 > ptp.mct1.I - Current - A.

    model.result("pg8").feature("glob1").set("expr", new String[]{"ptp.mct1.I"});
    model.result("pg8").feature("glob1").set("descr", new String[]{"Current"});
    model.result("pg8").feature("glob1").set("unit", new String[]{"A"});

//    In the Harmonic Content of the Current toolbar, click Plot.

    model.result("pg8").run();

//    Locate the x-Axis Data section.
//    From the Parameter list, select Discrete Fourier transform.

    model.result("pg8").feature("glob1").set("xdata", "fourier");

//    From the Show list, select Frequency spectrum.

    model.result("pg8").feature("glob1").set("fouriershow", "spectrum");

//    In the Harmonic Content of the Current toolbar, click Plot.

    model.result("pg8").run();

//    Click the Zoom Extents button in the Graphics toolbar.
//    For this low power value, the harmonic at 3 times the fundamental is only around 1.9% of the fundamental.
//    Next, use the FFT study so that the impedance of the discharge can be computed at the fundamental.
//    In the Home toolbar, click Add Study to open the Add Study window.
//    Find the Studies subsection.
//    In the Select Study tree, select Empty Study.
//    Click Add Study in the window toolbar.

    model.study().create("std3");

//    In the Home toolbar, click Add Study to close the Add Study window.
//    In the Settings window for Study, type FFT Study to Compute Plasma Impedance in the Label text field.

    model.study("std3").label("FFT Study to Compute Plasma Impedance");

//    In the Study toolbar, click More Study Steps and choose Frequency Domain > Time to Frequency FFT.

    model.study("std3").create("tffft", "TimeToFreqFFT");

//    In the Settings window for Time to Frequency FFT, locate the Study Settings section.
//    In the End time text field, type 1/f0.

    model.study("std3").feature("tffft").set("fftendtime", "1/f0");

//    In the Maximum output frequency text field, type f0.

    model.study("std3").feature("tffft").set("fftmaxfreq", "f0");

//    From the Input study list, select Time Periodic to Time Dependent, Time Periodic to Time Dependent.

    model.study("std3").feature("tffft").set("fftinputstudy", "std2");

//    In the Study toolbar, click Compute.

    model.study("std3").createAutoSequences("all");

    model.sol("sol3").runAll();

    model.result().numerical().create("gev1", "EvalGlobal");
    model.result().numerical("gev1").set("expr", new String[]{"ptp.mct1.Z"});
    model.result().numerical("gev1").label("Impedance (ptp, dset4)");
    model.result().numerical("gev1").set("data", "dset4");
    model.result().numerical("gev1").set("descr", "Impedance");
    model.result().table().create("tbl1", "Table");
    model.result().table("tbl1").label("Impedance");
    model.result().numerical("gev1").set("table", "tbl1");

//    After computing, a <l>Global Evaluation</l> feature is automatically generated, with the default expression corresponding to the plasma impedance. Evaluate this to the results table.
//    In the Settings window for Global Evaluation, click Evaluate.

    model.result().numerical("gev1").set("table", "tbl1");
    model.result().numerical("gev1").setResult();

//    In order to recompute the plasma impedance for different operating conditions, it is necessary to run all three studies. To make this easier, a fourth study can be added, which uses the <l>Study reference</l> feature.
//    In the Home toolbar, click Add Study to open the Add Study window.
//    Find the Studies subsection.
//    In the Select Study tree, select Empty Study.
//    Click Add Study in the window toolbar.

    model.study().create("std4");

//    In the Home toolbar, click Add Study to close the Add Study window.
//    In the Settings window for Study, type Run all Studies in the Label text field.

    model.study("std4").label("Run all Studies");

//    Now reference the first three studies. When computing this study, it will run the other three studies in order.
//    In the Study toolbar, click More Study Extensions and choose Study Reference.

    model.study("std4").create("ref", "StudyReference");

//    In the Settings window for Study Reference, locate the Study Reference section.
//    From the Study reference list, select Time Periodic.

    model.study("std4").feature("ref").set("studyref", "std1");

//    In the Study toolbar, click More Study Extensions and choose Study Reference.

    model.study("std4").create("ref2", "StudyReference");

//    In the Settings window for Study Reference, locate the Study Reference section.
//    From the Study reference list, select Time Periodic to Time Dependent.

    model.study("std4").feature("ref2").set("studyref", "std2");

//    In the Study toolbar, click More Study Extensions and choose Study Reference.

    model.study("std4").create("ref3", "StudyReference");

//    In the Settings window for Study Reference, locate the Study Reference section.
//    From the Study reference list, select FFT Study to Compute Plasma Impedance.

    model.study("std4").feature("ref3").set("studyref", "std3");

//    Now change the input power and recompute the studies.
//    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("P0", "50[W]");

//    In the Study toolbar, click Compute.

    model.study("std4").createAutoSequences("all");

    model.batch("s1").run("compute");

//    Observe how the harmonic at 3 times the fundamental frequency has now increased to around 4.5% of the fundamental. This will cause significant problems with any potential matching network.

    model.result("pg8").run();

//    Finally, reevaluate the plasma impedance at this new power value.
//    In the Model Builder window, right-click Results > Derived Values > Impedance (ptp, dset4) and choose Evaluate > Impedance.

    model.result().numerical("gev1").set("table", "tbl1");
    model.result().numerical("gev1").appendResult();

    model.title("Computing the Plasma Impedance");

    model
         .description("This tutorial model demonstrates how to compute the impedance of a capacitively coupled plasma. The Time Periodic study computes the time periodic solution of the plasma. Subsequently, the solution is transformed to the time domain, after which the fast Fourier transform (FFT) solver is called. This allows the plasma impedance to be computed for a given set of input parameters. This impedance value is useful when designing matching networks.");

    return model;
  }

  public static void main(String[] args) {
    run();
  }

}
