How to select a mode in a loop with variables

I want to know the effective index of the first TE mode. So I want a loop which will run up to the first TE polarization fraction greater than 0.5 and it stops after that. But I am unable to extract data (neff/TE polarization fraction) from a mode inside the loop using variable.

findmodes;
x=1;
a= getdata(‘mode1’,‘TE polarization fraction’);
for(0; a<0.5; 0)
{
x=x+1;
a= getdata(‘modex’,‘TE polarization fraction’);

    }

b= getdata(‘modex’,‘neff’);

Hi @ee17d011,

The easiest way to do this would be to use symmetry boundary conditions to make sure only TE modes are found, then find the effective index of the first mode. For example, if your TE mode is polarized in the x direction and your waveguide is symmetric in the x direction, you would use antisymmetric BCs in the x direction.

If that won’t work for you, the error in your script is due to the fact you are using "modex" as the mode name. You need to use "mode" + num2str(x) if you want the mode names to be "mode1", "mode2", etc. This script should work:

findmodes;
x=1;
a= getdata("mode1","TE polarization fraction");
for(0; a<0.5; 0) 
{
    x=x+1;
    a = getdata("mode" + num2str(x), "TE polarization fraction");
}
b= getdata("mode" + num2str(x),"neff");

Let me know if that helps.

Thanks a lot. It really helped. But if I use asymmetric boundary conditions in the x directions, what should be the boundary condition in Y?

In the y direction you can use metal boundary conditions if you have a high-confinement waveguide (SOI for example), or PML boundary conditions for a low-confinement waveguide (see this KB page for more information). You could also use symmetric BCs, if the waveguide is symmetric in the y direction. Note that this will restrict the solver to only find modes with this symmetry as well.

I should correct my previous post: higher order TM modes can still be found with antisymmetric BCs in the x direction, but the fundamental TM mode will not be found. If you use antisymmetric BCs in the x direction the mode with the lowest effective index will almost always be the fundamental TE mode.