Mode field data saving for contour plot and vector plot


#1

Dear lumerical team
I am using script to calculate modes and save the mode field data for Matlab contour plot. I am using fiber design and my structure has 15-20 modes (for example a fiber containing 20 modes). my script is

clear;

findmodes;
E=getresult("FDE::data::mode1","E");

# Get field and position vectors
Ex=pinch(E.Ex);
Ey=pinch(E.Ey);

x=E.x;
y=E.y;

# Specify the resolution of the plot  
res_x=30;
res_y=20;
 
# Define uniform vectors
x2=linspace(x(1),x(length(x)),res_x);
y2=linspace(y(1),y(length(y)),res_y);
  
xmesh = meshgridx(x2,y2);
ymesh = meshgridy(x2,y2);
 
# Interpolate fields on new uniform vectors
Ex2=interp(Ex, x, y, x2, y2);
Ey2=interp(Ey, x, y, x2, y2);
matlabsave("monitor_data",Ex2,Ey2,xmesh,ymesh);

from the above script I can calculate mode1 data and save. But I want to measure 15-20 modes (i.e. mode1, mode2, mode3, mode4, mode5, mode6 mode7, mode8… etc) and want to save the data at a time. can someone guide me how to do all modes save at a time by modifying the script.

with advance thanks


Vector plot
#2

Hi,

I have modified the code to give an example of saving the data from 5 modes, but you can change the number of modes on line 3:

clear;

num_modes = 5; # number of modes to export data for

for(i=1:num_modes){ # loop through num
    findmodes;
    E=getresult("FDE::data::mode"+num2str(i),"E");
    
    # Get field and position vectors
    Ex=pinch(E.Ex);
    Ey=pinch(E.Ey);
    
    x=E.x;
    y=E.y;
    
    # Specify the resolution of the plot  
    res_x=30;
    res_y=20;
     
    # Define uniform vectors
    x2=linspace(x(1),x(length(x)),res_x);
    y2=linspace(y(1),y(length(y)),res_y);
      
    xmesh = meshgridx(x2,y2);
    ymesh = meshgridy(x2,y2);
     
    # Interpolate fields on new uniform vectors
    eval("Ex2_"+num2str(i)+"=interp(Ex, x, y, x2, y2);");
    eval("Ey2_"+num2str(i)+"=interp(Ey, x, y, x2, y2);");  
}

matlabsave("monitor_data");

I added a for loop to loop through the specified number of modes, and used the “eval” script function to create different variable names for each mode as it loops, so it should now calculate results Ex2_1, Ex2_2, Ex2_3, … etc. where there is a different result variable for each mode number.

Then in the matlabsave command at the end, I did not specify the variable names to export so all variables in the workspace will be exported. I did this to avoid having to type out all the result names manually, but you can still do that if you want to.

Please let me know if there are questions about the code!


#3

Thank you and it working for my file very well.