switchtolayout;

sim_xmax = 30e-06;
padding = 5e-06;

cell2 = [si_ktn_overlap - si_taper_length, 1, 0];
cell3 = [si_taper_length, 49, 1];
cell4 = [right_taper_xmin - left_taper_xmax, 1, 0];
cell5 = [si_taper_length, 49, 1];
cell6 = [si_ktn_overlap - si_taper_length, 1, 0];

cells = [cell2; cell3];
# cells = [cell2; cell3; cell4; cell5; cell6];

select("EME");
delete;
addeme;
set("x min", left_taper_xmax - si_ktn_overlap);
set("y",0);
set("y span",ktn_waveguide_width + 4.5e-06);
set("z min", -(si_waveguide_thickness + 0.8e-06));
set("z max", si_ktn_gap + ktn_thickness + 1e-06);
set("y min bc", "Anti-Symmetric");
set("y max bc", "PML");
set("z min bc", "PML");
set("z max bc", "PML");
set("define y mesh by", "maximum mesh step");
set("define z mesh by", "maximum mesh step");
set("dy", 0.02e-06);
set("dz", 0.02e-06);
set("wavelength", 1550e-09);

# Define EME setup
set("energy conservation", "none");
set("number of cell groups", 2);
set("fit materials with multi-coefficient model", true);
set("fit analytic materials", true);
set("wavelength start", 1.2e-06);
set("wavelength stop", 1.8e-06);
set("display cells", true);
set("group spans", cells(:,1));
set("cells", cells(:,2));
set("number of modes for all cell groups", 25);
set("subcell method", cells(:,3));


select("EME::Ports::port_1");
set("port location", "left");

select("EME::Ports::port_2");
set("port location", "right");


select("output");
delete;
addemeprofile;
set("name", "output");
set("name","output");
set("monitor type", "2D X-normal");  # 2D x-normal
set("x", right_taper_xmin + si_ktn_overlap);
set("y", 0);
set("y span", si_waveguide_width + 10e-06);
set("z",-si_waveguide_thickness/2);
set("z span",si_waveguide_thickness + 1e-06);
set("save data", true);
set("filename", "output.mat");

select("input");
delete;
addemeprofile;
set("name","input");
set("monitor type", "2D X-normal");  # 2D x-normal
set("x", left_taper_xmax - si_ktn_overlap);
set("y", 0);
set("y span", si_waveguide_width + 10e-06);
set("z",-si_waveguide_thickness/2);
set("z span",si_waveguide_thickness + 1e-06);
set("save data", true);
set("filename", "input.mat");


