296 lines
8.6 KiB
Plaintext
296 lines
8.6 KiB
Plaintext
function FUNC_DEVICE_2X2(instPath)
|
|
{
|
|
inst = read(instPath);
|
|
eval(inst);
|
|
|
|
jsonload(jsonPath);
|
|
|
|
HwaferMax = 0;
|
|
for(idx=1;idx<=length(layers.numbers);idx=idx+1){
|
|
|
|
if (iscell(layers.numbers)){
|
|
layer = num2str(layers.numbers{idx}) + ":" + num2str(layers.datatype{idx});}
|
|
|
|
else{
|
|
layer = num2str(layers.numbers(idx)) + ":" + num2str(layers.datatype(idx));}
|
|
|
|
if (iscell(layers.heights)){
|
|
Hwafer = layers.heights{idx}*1e-6;}
|
|
else{
|
|
Hwafer = layers.heights(idx)*1e-6;}
|
|
|
|
|
|
gdsimport(gdspath, devName, layer,wafer.material, 0, Hwafer);
|
|
#gdsimport(folder + devName + ".gds", devName, layer,wafer.material, 0, Hwafer);
|
|
#set("name","device");
|
|
|
|
if (Hwafer>HwaferMax)
|
|
{
|
|
HwaferMax = Hwafer;
|
|
}
|
|
}
|
|
|
|
## output ports
|
|
|
|
# HwaferMax = Hwafer;
|
|
zOffset = HwaferMax/2*1e+6;
|
|
mx_simu_area('FDTD',[FDTD.x,FDTD.y,FDTD.z+zOffset]*1e-6,
|
|
[FDTD.dx,FDTD.dy,FDTD.dz]*1e-6,FDTD.mesh_order,[40,40,40]*1e-6,'PML',10e+5);
|
|
|
|
portList = ports.names;
|
|
|
|
for (idx=1;idx<=length(portList);idx=idx+1)
|
|
{
|
|
portName = portList{idx};
|
|
|
|
eval("port_struct = ports."+portName+";");
|
|
|
|
if (port_struct.a < 0) { port_struct.a = port_struct.a + 360; }
|
|
|
|
if ( 45<=port_struct.a and port_struct.a<135 )
|
|
{
|
|
portsType = -2;
|
|
portsSZ = [port_struct.width,0,port_struct.height]*1e-6;
|
|
}
|
|
else if (225<=port_struct.a and port_struct.a<315)
|
|
{
|
|
portsType = 2;
|
|
portsSZ = [port_struct.width,0,port_struct.height]*1e-6;
|
|
}
|
|
|
|
else if (135<=port_struct.a and port_struct.a<225)
|
|
{
|
|
portsType = 1;
|
|
portsSZ = [0,port_struct.width,port_struct.height]*1e-6;
|
|
}
|
|
|
|
else if (port_struct.a<45 or port_struct.a>=315)
|
|
{
|
|
portsType =-1;
|
|
portsSZ = [0,port_struct.width,port_struct.height]*1e-6;
|
|
}
|
|
|
|
|
|
mx_power_monitor(portName,[port_struct.x,port_struct.y,zOffset]*1e-6,
|
|
portsSZ,abs(portsType)) ;
|
|
set("override global monitor settings",1);
|
|
set("frequency points",FDTD.Trans_sample_points);
|
|
|
|
mx_mode_expansion(portName+'_modes',[port_struct.x,port_struct.y,zOffset]*1e-6,
|
|
portsSZ,abs(portsType),0,
|
|
[abs(port_struct.radius)*1e-6,
|
|
sign(port_struct.radius)*sign(portsType)*180],1,FDTD.wl*1e-6,portName);
|
|
|
|
|
|
if (iscell(modes)){modes = [modes{1}];}
|
|
|
|
set("selected mode numbers",modes);
|
|
|
|
if ( abs(port_struct.a) <= 45 or abs(port_struct.a) > 315)
|
|
{
|
|
set('theta',port_struct.a);
|
|
set('phi',0);
|
|
}
|
|
|
|
else if ( abs(port_struct.a) > 135 and abs(port_struct.a) <= 225)
|
|
{
|
|
set('theta',port_struct.a);
|
|
set('phi',0);
|
|
}
|
|
|
|
else{
|
|
set('theta',90-port_struct.a);
|
|
set('phi',90);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
mx_power_monitor('z1',[mont.z1.x,mont.z1.y,zOffset]*1e-6,
|
|
[mont.z1.dx,mont.z1.dy,0]*1e-6,3) ;
|
|
set("override global monitor settings",1);
|
|
set("frequency points",FDTD.Field_sample_points);
|
|
|
|
## adding input ports
|
|
|
|
input_struct = ports.a1;
|
|
if (input_struct.a < 0) { input_struct.a = input_struct.a + 360; }
|
|
|
|
if ( 45<=input_struct.a and input_struct.a<135 )
|
|
{
|
|
inputType = -2;
|
|
portsSZ = [input_struct.width,0,input_struct.height]*1e-6;
|
|
input_theta = 90-input_struct.a;
|
|
input_phi = 0;
|
|
}
|
|
else if (225<=input_struct.a and input_struct.a<315)
|
|
{
|
|
inputType = 2;
|
|
portsSZ = [input_struct.width,0,input_struct.height]*1e-6;
|
|
input_theta = 270-input_struct.a;
|
|
input_phi = 0;
|
|
}
|
|
|
|
else if (135<=input_struct.a and input_struct.a<225)
|
|
{
|
|
inputType = -1;
|
|
portsSZ = [0,input_struct.width,input_struct.height]*1e-6;
|
|
input_theta = input_struct.a - 180;
|
|
input_phi = 0;
|
|
|
|
}
|
|
|
|
else if (input_struct.a<45 or input_struct.a>=315)
|
|
{
|
|
inputType = 1;
|
|
portsSZ = [0,input_struct.width,input_struct.height]*1e-6;
|
|
input_theta = input_struct.a;
|
|
input_phi = 0;
|
|
}
|
|
|
|
mx_mode_source('a1_input',[input_struct.x,input_struct.y,zOffset]*1e-6,
|
|
portsSZ,inputType,0,
|
|
[abs(input_struct.radius)*1e-6,sign(input_struct.radius)*sign(inputType)*90],FDTD.sourceMode,FDTD.wl*1e-6);
|
|
set("theta",input_theta);
|
|
set("phi",input_phi);
|
|
|
|
## setting FDTD configurations
|
|
|
|
select("FDTD");
|
|
|
|
set("background material",clad.material);
|
|
|
|
if (FDTD.GPUOn == 1){
|
|
|
|
setnamed("FDTD", "express mode", true);
|
|
setresource("FDTD","GPU", true);
|
|
setresource("FDTD", 1, "GPU Device", "Auto");
|
|
set('z min bc','PML');
|
|
}
|
|
else {
|
|
setnamed("FDTD", "express mode", false);
|
|
setresource("FDTD","GPU", false);
|
|
|
|
if (length(layers.numbers)==1){
|
|
set('z min bc','symmetric');}
|
|
else {set('z min bc','PML');}
|
|
|
|
}
|
|
|
|
save(folder+"\\"+devName+"_simu.fsp");
|
|
#save("DEVICE_2X2.fsp");
|
|
|
|
}
|
|
|
|
function DATA_RETRIEVE_DEVICE_2X2(instPath)
|
|
{
|
|
|
|
inst = read(instPath);
|
|
eval(inst);
|
|
jsonload(jsonPath);
|
|
|
|
portList = ports.names;
|
|
|
|
save_cmd = "";
|
|
|
|
for (idx=1;idx<=length(portList);idx=idx+1)
|
|
|
|
{
|
|
portData = struct;
|
|
portData.name = portList{idx};
|
|
|
|
portData.power = getresult(portData.name,"T");
|
|
portData.modes = getresult(portData.name+"_modes","expansion for input");
|
|
E = getresult(portData.name,"E");
|
|
H = getresult(portData.name,"H");
|
|
|
|
x = E.x;
|
|
y = E.y;
|
|
z = E.z;
|
|
|
|
cx = floor(length(x)/2)+1;
|
|
cy = floor(length(y)/2)+1;
|
|
cz = floor(length(z)/2)+1;
|
|
|
|
## wavelength length
|
|
sz_wl = size(E.E,4);
|
|
|
|
step = floor((sz_wl-1)/(FDTD.Field_sample_points-1));
|
|
idxSect = [1:step:sz_wl+1];
|
|
|
|
E_save = E;
|
|
H_save = H;
|
|
|
|
E_save = matrixdataset;
|
|
E_save.addparameter("x",E.x);
|
|
E_save.addparameter("y",E.y);
|
|
E_save.addparameter("z",E.z);
|
|
E_save.addparameter("lambda",E.lambda(1:step:end));
|
|
E_save.addattribute("E",E.E(:,:,:,1:step:end,:));
|
|
|
|
H_save = matrixdataset;
|
|
H_save.addparameter("x",H.x);
|
|
H_save.addparameter("y",H.y);
|
|
H_save.addparameter("z",H.z);
|
|
H_save.addparameter("lambda",H.lambda(idxSect));
|
|
H_save.addattribute("H",H.H(:,:,:,idxSect,:));
|
|
|
|
portData.E = E_save;
|
|
portData.H = H_save;
|
|
|
|
## Center electric field of the monitor
|
|
Ecenter = E.E(cx,cy,cz,:,:); ## (x,y,z,wl,Ex/Ex/Ez)
|
|
Hcenter = H.H(cx,cy,cz,:,:); ## (x,y,z,wl,Ex/Ex/Ez)
|
|
portData.Ecenter = Ecenter;
|
|
portData.Hcenter = Hcenter;
|
|
|
|
eval(portData.name + " = portData;");
|
|
save_cmd = save_cmd + portData.name + ",";
|
|
|
|
}
|
|
|
|
if (find(portList=="a1") and find(portList=="b1")){
|
|
Ephase_11 = unwrap(angle(b1.Ecenter) - angle(a1.Ecenter));
|
|
Hphase_11 = unwrap(angle(b1.Hcenter) - angle(a1.Hcenter));
|
|
save_cmd = save_cmd + "Ephase_11" + "," + "Hphase_11" + ",";
|
|
|
|
}
|
|
|
|
if (find(portList=="a2") and find(portList=="b2")){
|
|
Ephase_22 = unwrap(angle(b2.Ecenter) - angle(a2.Ecenter));
|
|
Hphase_22 = unwrap(angle(b2.Hcenter) - angle(a2.Hcenter));
|
|
save_cmd = save_cmd + "Ephase_22" + "," + "Hphase_22" + ",";
|
|
}
|
|
|
|
if (find(portList=="a1") and find(portList=="b2")){
|
|
Ephase_12 = unwrap(angle(b2.Ecenter) - angle(a1.Ecenter));
|
|
Hphase_12 = unwrap(angle(b2.Hcenter) - angle(a1.Hcenter));
|
|
save_cmd = save_cmd + "Ephase_12" + "," + "Hphase_12" + ",";
|
|
}
|
|
|
|
if (find(portList=="a2") and find(portList=="b1")){
|
|
Ephase_21 = unwrap(angle(b1.Ecenter) - angle(a2.Ecenter));
|
|
Hphase_21 = unwrap(angle(b1.Hcenter) - angle(a2.Hcenter));
|
|
save_cmd = save_cmd + "Ephase_21" + "," + "Hphase_21" + ",";
|
|
}
|
|
|
|
z1= struct;
|
|
z1.E = getresult("z1","E");
|
|
z1.H = getresult("z1","H");
|
|
Ex = getresult("z1","Ex");
|
|
Ey = getresult("z1","Ey");
|
|
Ez = getresult("z1","Ez");
|
|
|
|
savefname = devName+"_results.mat";
|
|
|
|
#matlabsave(savefname,b1,b2,z1);
|
|
|
|
eval("matlabsave(savefname,"+save_cmd+"z1);");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|