Code covered by the BSD License  

Highlights from
Interactive Simulation Toolbox for Optics

image thumbnail

Interactive Simulation Toolbox for Optics

by

 

30 Jan 2013 (Updated )

2-dimensional FDTD-Toolbox (Yee Grid,Matrix based,current like sources,PML boundaries, GUI based)

checkepsmu
function checkepsmu
%This function is for changing the refractive index profile in the
%Simulation - You can change and delete the according Refractive index
%parts
%(the function is called by
%clicking - 'Change Refractive iIndex Profile')

global check x y dx X Y backgroundeps backgroundmu epsilon mu ZS Anz epsilon0 mu0 userepsmu
if check==1
    errordlg('There is an unconfirmed Structure')
    return
end
a=size(userepsmu);
laufs=1;
for runstructures = 1:a(1)
    
    answer=userepsmu{laufs,1};
    pc=answer{4};
    Strukturalt=answer{5};
    posold=userepsmu{laufs,2};
    if answer{4}~='1'
        switch Strukturalt
            case '1'
                h=imrect(gca,posold);
                indexalt=find(X>posold(1) & X<posold(1)+posold(3) & Y>posold(2) & Y<posold(2)+posold(4) );
            case '2'
                h=imellipse(gca,posold);
                indexalt=find((X-posold(1)-posold(3)/2).^2/(posold(3)/2).^2+(Y-posold(2)-posold(4)/2).^2/(posold(4)/2).^2<1 );
            case '3'
                h=impoly(gca,posold);
                IN = inpolygon(X,Y,posold(:,1),posold(:,2));
                indexalt=find(IN==1);
        end
    end
    answer{4}='0';
    
    prompt={'\epsilon - Structure',...
        '\mu - Structure',...
        'Softened Structures',...
        'Delete Structure'};
    name='Structure';
    numlines=1;
    defaultanswer=answer;
    options.Resize='on';
    options.WindowStyle='normal';
    options.Interpreter='tex';
    options.fonsize=20;
    answer=inputdlg(prompt,name,numlines,defaultanswer,options);
    try
        delete(h)
    end
    if isempty(answer)
        return
    end
 
    
    if str2num( answer{4})==0
        if pc~='1'
            switch Strukturalt
                case '1'
                    h=imrect(gca,posold);
                    confirmwait
                    pos = getPosition(h);
                    pos2=pos;
                    delete(h);
                    index=find(X>pos(1) & X<pos(1)+pos(3) & Y>pos(2) & Y<pos(2)+pos(4) );
                    
                case '2'
                    h=imellipse(gca,posold);
                    confirmwait
                    pos = getPosition(h);
                    pos2=pos;
                    delete(h);
                    index=find((X-pos(1)-pos(3)/2).^2/(pos(3)/2).^2+(Y-pos(2)-pos(4)/2).^2/(pos(4)/2).^2<1 );
                    
                case '3'
                    h=impoly(gca,posold);
                    confirmwait
                    pos = getPosition(h);
                    IN = inpolygon(X,Y,pos(:,1),pos(:,2));
                    index=find(IN==1);
                    pos2(1)=min(pos(:,1));
                    pos2(2)=min(pos(:,2));
                    pos2(3)=max(pos(:,1))-min(pos(:,1));
                    pos2(4)=max(pos(:,2))-min(pos(:,2));
                    
            end
            
        else
           answer{3}='0'; 
            answer2={num2str(posold(1)),num2str(posold(2)),num2str(posold(3)),num2str(posold(4)),num2str(posold(5))};
            prompt={'Periodic Cell Size x-Dimension [\mum]',...
                'Periodic Cell Size y-Dimension [\mum]',...
                'Structure Size x-Dimension [\mum]',...
                'Structure Size y-Dimension [\mum]',...
                'Structure -1 for Square - 2 for Circular'};
            
            name='periodic Definition';
            numlines=1;
            defaultanswer=answer2;
            options.Resize='on';
            options.WindowStyle='normal';
            options.Interpreter='tex';
            options.fonsize=20;
            answer2=inputdlg(prompt,name,numlines,defaultanswer,options);
            if isempty(answer2)
                try
                    delete(h)
                end
                return
            end
            
            
            
            
            a=0*X;
            gro2=size(a);
            width=str2num(answer2{1});
            height=str2num(answer2{2});
            lx=str2num(answer2{3});
            ly=str2num(answer2{4});
            dx=X(1,2)-X(1,1);
            xp=[0:dx:width];
            yp=[0:dx:height];
            
            [Xp,Yp]=meshgrid(xp,yp);
            
            switch str2num(answer2{5})
                case 1
                    index=find(Xp>(width-lx)/2 & Xp<(width+lx)/2 & Yp>(height-ly)/2 & Yp<(height+ly)/2 );
                    
                case 2
                    index=find((Xp-width/2).^2/(lx/2).^2+(Yp-height/2).^2/(ly/2).^2<1 );
            end
            b=0*Xp;
            b(index)=1;
            gro=size(b);
            
            c2=b;
            for li=1:ceil(gro2(1)/gro(1))-1
                c2=[c2;b];
            end
            d=c2;
            for        lk=1:ceil(gro2(2)/gro(2))-1
                c2=[c2 d];
            end
            a=c2;
            a=a(1:gro2(1),1:gro2(2));
            index=find(a~=0);
            pos=[width height lx ly str2num(answer2{5})];
            indexalt=userepsmu{runstructures,3};
        pos2=0;
        end
        
        
        switch answer{3}
            case '1'
                mux=pos2(1)+pos2(3)/2;
                muy=pos2(2)+pos2(4)/2;
                sigmax=0.4*pos2(3);
                sigmay=0.4*pos2(4);
                alpha=epsilon0.*str2num(answer{1})-backgroundeps;
                beta=mu0*str2num(answer{2})-backgroundmu;
                
                gauss=exp(-0.5*((X-mux)./sigmax).^8).*exp(-0.5*((Y-muy)./sigmay).^8);
                
                
                epsilon(indexalt) =backgroundeps;
                mu(indexalt) = backgroundmu;
                
                epsilon(index) =alpha*gauss(index)+backgroundeps;
                mu(index) = beta*gauss(index)+backgroundmu;
                
            case '0'
                
                epsilon(indexalt) =backgroundeps;
                mu(indexalt) = backgroundmu;
                
                epsilon(index) =epsilon0.*str2num(answer{1});
                mu(index) = mu0*str2num(answer{2});
                
        end
        answer{5}=Strukturalt;
        answer{4}=pc;
        
        userepsmu{laufs,1}=answer;
        userepsmu{laufs,2}=pos;
        userepsmu{laufs,3}=index;
        userepsmu{laufs,4}=pos2;

        laufs=laufs+1;
    else
        epsilon(userepsmu{laufs,3}) =backgroundeps;
        mu(userepsmu{laufs,3}) = backgroundmu;
        userepsmu(laufs,:)=[];
    end
    
    refreshstructure
end



Contact us