switchtolayout;
deleteall;

# Parameters defined from slides
si_tip_width = 150e-09;
si_waveguide_width = 500e-09;
si_taper_length = 100e-06;
si_ktn_overlap = 160e-06;
si_ktn_gap = 0e-09;
ktn_waveguide_width = 1.5e-06;
ktn_thickness = 360e-09;


# Parameters defined by me
si_rect_length = 200e-06;
si_taper_gap = 100e-06;
si_waveguide_thickness = 220e-09;
cladding_thickness = 1e-06;
si_yoffset = 0e-09;

addstructuregroup;
group = "model";
set("name", group);
set("x", 0);
set("y", 0);
set("z", 0);

# Buid structures Si & SiO2
addpoly;
left_taper = "left taper";
left_taper_xmin = -(si_taper_gap/2 + si_taper_length);
left_taper_xmax = -(si_taper_gap/2);
vertices = [left_taper_xmin, si_waveguide_width/2;left_taper_xmax, si_tip_width/2;left_taper_xmax, -si_tip_width/2;left_taper_xmin, -si_waveguide_width/2];
set("name", left_taper);
setnamed(left_taper, "x", 0);
setnamed(left_taper, "y", si_yoffset);
setnamed(left_taper, "vertices", vertices);
setnamed(left_taper, "z min", -si_waveguide_thickness);
setnamed(left_taper, "z max", 0);
setnamed(left_taper, "material", "Si (Silicon) - Palik");
setnamed(left_taper, "override mesh order from material database", true);
setnamed(left_taper, "mesh order", 2);
addtogroup(group);

addrect;
left_rect = "left rect";
set("name", left_rect);
setnamed(left_rect, "x max", left_taper_xmin);
setnamed(left_rect, "x min", left_taper_xmin - si_rect_length);
setnamed(left_rect, "y", si_yoffset);
setnamed(left_rect, "y span", si_waveguide_width);
setnamed(left_rect, "z min", -si_waveguide_thickness);
setnamed(left_rect, "z max", 0);
setnamed(left_rect, "material", "Si (Silicon) - Palik");
setnamed(left_rect, "override mesh order from material database", true);
setnamed(left_rect, "mesh order", 2);
addtogroup(group);


addpoly;
right_taper = "right taper";
right_taper_xmin = si_taper_gap/2;
right_taper_xmax = si_taper_gap/2 + si_taper_length;
vertices = [right_taper_xmin, si_tip_width/2;right_taper_xmax, si_waveguide_width/2;right_taper_xmax, -si_waveguide_width/2;right_taper_xmin, -si_tip_width/2];
set("name", right_taper);
setnamed(right_taper, "x", 0);
setnamed(right_taper, "y", si_yoffset);
setnamed(right_taper, "vertices", vertices);
setnamed(right_taper, "z min", -si_waveguide_thickness);
setnamed(right_taper, "z max", 0);
setnamed(right_taper, "material", "Si (Silicon) - Palik");
setnamed(right_taper, "override mesh order from material database", true);
setnamed(right_taper, "mesh order", 2);
addtogroup(group);

addrect;
right_rect = "right rect";
set("name", right_rect);
setnamed(right_rect, "x min", right_taper_xmax);
setnamed(right_rect, "x max", right_taper_xmax + si_rect_length);
setnamed(right_rect, "y", si_yoffset);
setnamed(right_rect, "y span", si_waveguide_width);
setnamed(right_rect, "z min", -si_waveguide_thickness);
setnamed(right_rect, "z max", 0);
setnamed(right_rect, "material", "Si (Silicon) - Palik");
setnamed(right_rect, "override mesh order from material database", true);
setnamed(right_rect, "mesh order", 2);
addtogroup(group);


addrect;
cladding = "cladding";
set("name", cladding);
setnamed(cladding, "x min", left_taper_xmin - si_rect_length);
setnamed(cladding, "x max", right_taper_xmax + si_rect_length);
setnamed(cladding, "y", 0);
setnamed(cladding, "y span", 100e-06);
setnamed(cladding, "z max", si_ktn_gap);
setnamed(cladding, "z min", si_ktn_gap - cladding_thickness - 0.5e-06);
setnamed(cladding, "material", "SiO2 (Glass) - Palik Copy 1");
setnamed(cladding, "override mesh order from material database", true);
setnamed(cladding, "mesh order", 3);
setnamed(cladding, "render type", "wireframe");
addtogroup(group);


# Build structure - KTN
addrect;
ktn = "ktn waveguide";
set("name", ktn);
setnamed(ktn, "x min", left_taper_xmax - si_ktn_overlap);
setnamed(ktn, "x max", right_taper_xmin + si_ktn_overlap);
setnamed(ktn, "y", 0);
setnamed(ktn, "y span", ktn_waveguide_width);
setnamed(ktn, "z min", si_ktn_gap);
setnamed(ktn, "z max", si_ktn_gap + ktn_thickness);
setnamed(ktn, "index", 2.29);
setnamed(ktn, "alpha", 0.5);
addtogroup(group);


#addmesh;
#left_mesh = "left mesh";
#set("name", left_mesh);
#setnamed(left_mesh, "x min", left_taper_xmax - si_ktn_overlap - 1e-06);
#setnamed(left_mesh, "x max", left_taper_xmax + 1e-06);
#setnamed(left_mesh, "y", 0);
#setnamed(left_mesh, "y span", ktn_waveguide_width + 1e-06);
#setnamed(left_mesh, "z min", -si_waveguide_thickness - 0.3e-06);
#setnamed(left_mesh, "z max", si_ktn_gap + ktn_thickness + 0.3e-06);
#setnamed(left_mesh, "dx", 0.01e-06);
#setnamed(left_mesh, "dy", 0.01e-06);
#setnamed(left_mesh, "dz", 0.01e-06);

#addmesh;
#right_mesh = "right mesh";
#set("name", right_mesh);
#setnamed(right_mesh, "x min", right_taper_xmin - 1e-06);
#setnamed(right_mesh, "x max", right_taper_xmin + si_ktn_overlap + 1e-06);
#setnamed(right_mesh, "y", 0);
#setnamed(right_mesh, "y span", ktn_waveguide_width + 1e-06);
#setnamed(right_mesh, "z min", -si_waveguide_thickness - 0.3e-06);
#setnamed(right_mesh, "z max", si_ktn_gap + ktn_thickness + 0.3e-06);
#setnamed(right_mesh, "dx", 0.01e-06);
#setnamed(right_mesh, "dy", 0.01e-06);
#setnamed(right_mesh, "dz", 0.01e-06);




