00001
00002
00003
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00016
00017 #include "GratingLayer2D.h"
00018 #include <iostream>
00019 #include <iomanip>
00020 #include <fstream>
00021 #include <string>
00022 #include "tools.h"
00023 using std::endl;
00024 using std::ofstream;
00025 using std::fstream;
00026 using std::cout;
00027
00028 extern "C" void zgeev_(char *, char *, int *, cmplx*, int *, cmplx*, cmplx*, int*, cmplx*, int*, cmplx*, int*, double*, int*);
00029
00030
00031 GratingLayer2D::GratingLayer2D(void)
00032 {
00033 mu=1.;
00034 memorysave=true;
00035 }
00036
00037 GratingLayer2D::~GratingLayer2D(){}
00038
00039 void GratingLayer2D::minimiseMemory()
00040 {
00041 epsilon.resize(0);
00042 invEpsilon.resize(0);
00043 invEpsilonMatrix.resize(0);
00044 invEpsilonMatrix_inv.resize(0);
00045 eps.resize(0);
00046 invEps.resize(0);
00047 tInvEps.resize(0);
00048 bInvEps.resize(0);
00049 btEps.resize(0);
00050 tbEps.resize(0);
00051 invEps_TbEps.resize(0);
00052 invEps_BtEps.resize(0);
00053 eigVal.resize(0);
00054 gamma.resize(0);
00055 eigMatE.resize(0);
00056 F.resize(0);
00057 G.resize(0);
00058 FG.resize(0);
00059 eigVecE.resize(0);
00060 eigVecH.resize(0);
00061 invEigVecE.resize(0);
00062 invEigVecH.resize(0);
00063 }
00064
00065
00066 void GratingLayer2D::setParameters(int ords, double pX, double pY, double thick, double lam, double angleZ, double angleX, complex<double> ref0)
00067 {
00068 setnOrds(ords);
00069 periodX=pX;
00070 periodY=pY;
00071 lambda=lam;
00072 theta=M_PI/180.*angleZ;
00073 phi=M_PI/180.*angleX;
00074 n1=ref0;
00075 k0=2.*M_PI*real(n1)/lambda;
00076 thickness = thick;
00077 calcAlphaBeta();
00078 }
00079
00080 double GratingLayer2D::getSizeX(void){return periodX;}
00081 void GratingLayer2D::setSizeX(double d){periodX=d;}
00082 double GratingLayer2D::getSizeY(void){return periodY;}
00083 void GratingLayer2D::setSizeY(double d){periodY=d;}
00084 double GratingLayer2D::getThickness(void){return thickness;}
00085 void GratingLayer2D::setThickness(double d){thickness=d;}
00086 double GratingLayer2D::getLambda(void){return lambda;}
00087
00092 void GratingLayer2D::setLambda(double wavelength)
00093 {
00094 lambda=wavelength;
00095 k0=2.*M_PI*real(n1)/lambda;
00096 }
00097 double GratingLayer2D::getTheta(void){return theta*180./M_PI;}
00098 void GratingLayer2D::setTheta(double angle)
00099 {
00100 theta=M_PI/180.*angle;
00101 }
00102 double GratingLayer2D::getPhi(void){return phi*180./M_PI;}
00103 void GratingLayer2D::setPhi(double angle)
00104 {
00105 phi=M_PI/180.*angle;
00106 }
00107 complex<double>GratingLayer2D::getN1(void){return n1;}
00112 void GratingLayer2D::setN1(complex<double>index)
00113 {
00114 n1=index;
00115 k0=2.*M_PI*real(n1)/lambda;
00116 }
00117
00118 complex<double>GratingLayer2D::getRefInd(int i, int j){return refInd(i,j);}
00119 Matrix< complex<double> > GratingLayer2D::getRefInd(void){return refInd;}
00120 void GratingLayer2D::setRefInd(Matrix < complex<double> >ref)
00121 {
00122 nPixelsX=ref.columns();
00123 nPixelsY=ref.rows();
00124 refInd.resize(ref.rows(),ref.columns());
00125 refInd=ref;
00126 }
00127
00128
00134 void GratingLayer2D::setTransPt(Vector<double> tX, Vector<double> tY)
00135 {
00136
00137 nPixelsX=tX.size();
00138 nPixelsY=tY.size();
00139 transPtX.resize(0.,tX.size()+1);
00140 transPtY.resize(0.,tY.size()+1);
00141 for (unsigned int i=0;i<transPtX.size()-1;i++) transPtX[i+1]=tX[i];
00142 for (unsigned int i=0;i<transPtY.size()-1;i++) transPtY[i+1]=tY[i];
00143 }
00144
00148 Vector<double> GratingLayer2D::getTransPtX(void){return transPtX.slice(1,transPtX.size());}
00152 Vector<double> GratingLayer2D::getTransPtY(void){return transPtY.slice(1,transPtY.size());}
00156 double GratingLayer2D::getTransPtX(int n){return transPtX[n+1];}
00160 double GratingLayer2D::getTransPtY(int n){return transPtY[n+1];}
00161
00162 void GratingLayer2D::reset(Vector<double> pX, Vector<double> pY, Matrix< complex<double> > N)
00163 {
00164 nPixelsX=pX.size();
00165 nPixelsY=pY.size();
00166 setTransPt(pX,pY);
00167 setRefInd(N);
00168 }
00169
00170
00171
00172 int GratingLayer2D::getnPixelsX(void) {return nPixelsX;}
00173 int GratingLayer2D::getnPixelsY(void) {return nPixelsY;}
00174 int GratingLayer2D::getnOrds(void) {return nOrds;}
00175 void GratingLayer2D::setnOrds(int ords)
00176 {
00177 nOrds=ords;
00178 nOrdsSq=nOrds*nOrds;
00179 nPermCoeffs=2*nOrds-1;
00180 maxPermCoeff=(nPermCoeffs-1)/2;
00181 }
00182
00183 complex<double> GratingLayer2D::getEigMatE(int a, int b){return eigMatE(a,b);}
00184 complex<double> GratingLayer2D::getEigVecE(int a, int b){return eigVecE(a,b);}
00185 complex<double> GratingLayer2D::getEigVecH(int a, int b){return eigVecH(a,b);}
00186 complex<double> GratingLayer2D::getInvEigVecE(int a, int b){return invEigVecE(a,b);}
00187 complex<double> GratingLayer2D::getInvEigVecH(int a, int b){return invEigVecH(a,b);}
00188 complex<double> GratingLayer2D::getG(int a, int b){return G(a,b);}
00189 complex<double> GratingLayer2D::getEigVal(int a){return eigVal[a];}
00190 complex<double> GratingLayer2D::getAlpha(int a){return alpha[a];}
00191 complex<double> GratingLayer2D::getBeta(int a){return beta[a];}
00192 complex<double> GratingLayer2D::getGamma(int a){return gamma[a];}
00193
00194
00195 const GratingLayer2D &GratingLayer2D::operator=(GratingLayer2D &in)
00196 {
00197
00198 setnOrds(in.getnOrds());
00199 setN1(in.getN1());
00200 setLambda(in.getLambda());
00201 setPhi(in.getPhi());
00202 setTheta(in.getTheta());
00203 setSizeX(in.getSizeX());
00204 setSizeY(in.getSizeY());
00205 setThickness(in.getThickness());
00206 nPixelsX=in.getnPixelsX();
00207 nPixelsY=in.getnPixelsY();
00208 k0=in.k0;
00209 mu=in.mu;
00210
00211
00212 refInd.resize(in.refInd);
00213 transPtX.resize(in.transPtX);
00214 transPtY.resize(in.transPtY);
00215
00216 alpha.resize(in.alpha);
00217 beta.resize(in.beta);
00218 epsilon.resize(in.epsilon);
00219 invEpsilon.resize(in.invEpsilon);
00220 invEpsilonMatrix.resize(in.invEpsilonMatrix);
00221 invEpsilonMatrix_inv.resize(in.invEpsilonMatrix_inv);
00222 eps.resize(in.eps);
00223 invEps.resize(in.invEps);
00224 tInvEps.resize(in.invEps);
00225 bInvEps.resize(in.bInvEps);
00226 btEps.resize(in.btEps);
00227 tbEps.resize(in.tbEps);
00228 invEps_TbEps.resize(in.invEps_TbEps);
00229 invEps_BtEps.resize(in.invEps_BtEps);
00230 eigVal.resize(in.eigVal);
00231 gamma.resize(in.gamma);
00232 eigMatE.resize(in.eigMatE);
00233 F.resize(in.F);
00234 G.resize(in.G);
00235 FG.resize(in.FG);
00236 eigVecE.resize(in.eigVecE);
00237 eigVecH.resize(in.eigVecH);
00238 invEigVecE.resize(in.invEigVecE);
00239 invEigVecH.resize(in.invEigVecH);
00240
00241 return *this;
00242 }
00243
00244
00245
00246 void GratingLayer2D::calcAlphaBeta(void)
00247 {
00248 if ((signed int)alpha.size()!=nOrds) alpha.resize(nOrds);
00249 if ((signed int)beta.size()!=nOrds) beta.resize(nOrds);
00250 for (int i=0;i<nOrds;i++)
00251 {
00252 alpha[i]=n1*2.*M_PI/lambda*sin(theta)*cos(phi)+2*M_PI*(i-(nOrds-1)/2)/periodX;
00253 beta[i]=n1*2.*M_PI/lambda*sin(theta)*sin(phi)+2*M_PI*(i-(nOrds-1)/2)/periodY;
00254 }
00255 }
00256
00257
00258
00259 void GratingLayer2D::calcPermCoeffs(void)
00260 {
00261 calcEpsilon();
00262 calcBTEpsilon();
00263 calcTBEpsilon();
00264 }
00265
00266 void GratingLayer2D::calcEpsilon(void)
00267 {
00268 if ((signed int)epsilon.size()!=nPermCoeffs*nPermCoeffs) epsilon.resize(nPermCoeffs, nPermCoeffs);
00269 if ((signed int)eps.size()!=pow(nOrds,4)) eps.resize(nOrds*nOrds, nOrds*nOrds);
00270 if ((signed int)invEps.size()!=pow(nOrds,4)) invEps.resize(nOrds*nOrds, nOrds*nOrds);
00271 double k2, k1;
00272 complex<double> cx,cy, c;
00273 k1=2.*M_PI/periodX;
00274 k2=2.*M_PI/periodY;
00275
00276
00277 for (int i=0;i<nPermCoeffs;i++)
00278 {
00279 for (int j=0;j<nPermCoeffs;j++)
00280 {
00281 epsilon(i,j)=0.;
00282 for (int p=0;p<nPixelsX;p++)
00283 {
00284 for (int q=0;q<nPixelsY;q++)
00285 {
00286
00287
00288 cx = ((i-maxPermCoeff==0) ? (transPtX[p+1]-transPtX[p]) : (exp(-I*k1*(1.*i-maxPermCoeff)*transPtX[p+1])-exp(-I*k1*(1.*i-maxPermCoeff)*(transPtX[p])))*I*(periodX/((i-maxPermCoeff)*k1)));
00289
00290
00291 cy = ((j-maxPermCoeff==0) ? (transPtY[q+1]-transPtY[q]) : (exp(-I*k2*(1.*j-maxPermCoeff)*transPtY[q+1])-exp(-I*k2*(1.*j-maxPermCoeff)*(transPtY[q])))*I*(periodY/((j-maxPermCoeff)*k2)));
00292
00293 epsilon(i,j)+=cx*cy*pow(refInd(q,p),2.);
00294 }
00295 }
00296 epsilon(i,j)/=(periodX*periodY);
00297 }
00298 }
00299
00300
00301
00302 for (int m=0;m<nOrds;m++)
00303 {
00304 for (int n=0;n<nOrds;n++)
00305 {
00306 for (int j=0;j<nOrds;j++)
00307 {
00308 for (int l=0;l<nOrds;l++)
00309 {
00310 eps(m*nOrds+n,j*nOrds+l)=epsilon(nOrds-1+m-j,nOrds-1+n-l);
00311 }
00312 }
00313 }
00314 }
00315 invEps=invert(eps);
00316
00317
00318 if (memorysave)
00319 {
00320 epsilon.resize(0);
00321 eps.resize(0);
00322 }
00323 }
00324
00325
00326 void GratingLayer2D::calcTBEpsilon(void)
00327 {
00328 if ((signed int)bInvEps.size()!=nPixelsX*nPermCoeffs) bInvEps.resize(nPixelsX, nPermCoeffs);
00329 if ((signed int)tbEps.size()!=pow(nOrds,4)) tbEps.resize(0.,nOrds*nOrds, nOrds*nOrds);
00330 Matrix< complex<double> > M1(nOrds);
00331 double k2, k1;
00332 k1=2.*M_PI/periodX;
00333 k2=2.*M_PI/periodY;
00334
00335 for (int i=0;i<nPixelsX;i++)
00336 {
00337 for(int j=0;j<nPermCoeffs;j++)
00338 {
00339 bInvEps(i,j)=0.;
00340 for (int k=0;k<nPixelsY;k++)
00341 {
00342 if (j-maxPermCoeff!=0)
00343 {
00344 bInvEps(i,j)+=pow(1./refInd(k,i),2.)/(2.*M_PI*(j-maxPermCoeff))*I*(exp(-I*k2*(1.*j-maxPermCoeff)*transPtY[k+1])-exp(-I*k2*(1.*j-maxPermCoeff)*transPtY[k]));
00345 }
00346 else bInvEps(i,j)+=pow(1./refInd(k,i),2.)/periodY*(transPtY[k+1]-transPtY[k]);
00347 }
00348 }
00349 }
00350
00351
00352
00353
00354
00355 for (int x=0;x<nPixelsX;x++)
00356 {
00357 for (int i=0;i<nOrds;i++)
00358 {
00359 for (int j=0;j<nOrds;j++)
00360 {
00361 M1(i,j) = bInvEps(x,nOrds-1+i-j);
00362 }
00363 }
00364
00365 M1=invert(M1);
00366
00367
00368 for (int m=0;m<nOrds;m++)
00369 {
00370 for (int n=0;n<nOrds;n++)
00371 {
00372 for (int j=0;j<nOrds;j++)
00373 {
00374 for (int l=0;l<nOrds;l++)
00375 {
00376 if (m-j!=0)
00377 {
00378 tbEps(m*nOrds+n,j*nOrds+l)+= M1(n,l)*I/((1.*m-j)*2.*M_PI)*(exp(-I*k1*(1.*m-j)*transPtX[x+1])-exp(-I*k1*(1.*m-j)*transPtX[x]));
00379 }
00380 else tbEps(m*nOrds+n,j*nOrds+l)+=M1(n,l)/periodX*(transPtX[x+1]-transPtX[x]);
00381 }
00382 }
00383 }
00384 }
00385 }
00386 if (memorysave)
00387 {
00388 bInvEps.resize(0);
00389 }
00390 }
00391
00392 void GratingLayer2D::calcBTEpsilon(void)
00393 {
00394 if ((signed int)tInvEps.size()!=nPixelsY*nPermCoeffs) tInvEps.resize(nPixelsY, nPermCoeffs);
00395 if ((signed int)btEps.size()!=pow(nOrds,4)) btEps.resize(0.,nOrds*nOrds, nOrds*nOrds);
00396 Matrix< complex<double> > M1(nOrds);
00397 double k2, k1;
00398 k1=2.*M_PI/periodX;
00399 k2=2.*M_PI/periodY;
00400
00401
00402 for (int i=0;i<nPixelsY;i++)
00403 {
00404 for(int j=0;j<nPermCoeffs;j++)
00405 {
00406 tInvEps(i,j)=0.;
00407 for (int k=0;k<nPixelsX;k++)
00408 {
00409 if (j-maxPermCoeff!=0)
00410 {
00411 tInvEps(i,j)+=pow(1./refInd(i,k),2.)/(2.*M_PI*(j-maxPermCoeff))*I*(exp(-I*k1*(1.*j-maxPermCoeff)*transPtX[k+1])-exp(-I*k1*(1.*j-maxPermCoeff)*(transPtX[k])));
00412 }
00413 else tInvEps(i,j)+=pow(1./refInd(i,k),2.)*(transPtX[k+1]-transPtX[k])/periodX;
00414 }
00415 }
00416 }
00417
00418
00419
00420
00421 for (int y=0;y<nPixelsY;y++)
00422 {
00423 for (int i=0;i<nOrds;i++)
00424 {
00425 for (int j=0;j<nOrds;j++)
00426 {
00427 M1(i,j) = tInvEps(y,nOrds-1+i-j);
00428 }
00429 }
00430
00431
00432 M1=invert(M1);
00433
00434 for (int m=0;m<nOrds;m++)
00435 {
00436 for (int n=0;n<nOrds;n++)
00437 {
00438 for (int j=0;j<nOrds;j++)
00439 {
00440 for (int l=0;l<nOrds;l++)
00441 {
00442 if (n-l!=0)
00443 {
00444 btEps(m*nOrds+n,j*nOrds+l) +=M1(m,j)*I/((1.*n-l)*2.*M_PI)*(exp(-I*k2*(1.*n-l)*transPtY[y+1])-exp(-I*k2*(1.*n-l)*(transPtY[y])));
00445 }
00446 else btEps(m*nOrds+n,j*nOrds+l) +=M1(m,j)*(transPtY[y+1]-transPtY[y])/periodY;
00447 }
00448 }
00449 }
00450 }
00451 }
00452 if (memorysave)
00453 {
00454 tInvEps.resize(0);
00455 }
00456 }
00457
00458
00459
00460 void GratingLayer2D::solve(void)
00461 {
00462 int hom=0;
00463 for (int i=0;i<nPixelsX;i++) for (int j=0;j<nPixelsY;j++)
00464 {
00465 if (refInd(j,i)!=refInd(0,0)) hom++;
00466 }
00467 if (hom==0) solveHomogeneous();
00468 else
00469 {
00470 calcPermCoeffs();
00471 setEigMat();
00472 solveEigMat();
00473 }
00474 }
00475
00476 void GratingLayer2D::solveHomogeneous()
00477 {
00478 if ((signed) eigVal.size()!=2*nOrdsSq) {eigVal.resize(2*nOrdsSq); }
00479 if ((signed) invEigVecE.size()!=pow(2*nOrdsSq,2)) {invEigVecE.resize(2*nOrdsSq,2*nOrdsSq); }
00480 if ((signed) invEigVecH.size()!=pow(2*nOrdsSq,2)) invEigVecH.resize(2*nOrdsSq,2*nOrdsSq);
00481 if ((signed int) eigVecE.size()!=pow(2*nOrdsSq,2)) eigVecE.resize(0.,2*nOrdsSq, 2*nOrdsSq);
00482 if ((signed int) eigVecH.size()!=pow(2*nOrdsSq,2)) eigVecH.resize(0.,2*nOrdsSq, 2*nOrdsSq);
00483 if ((signed)gamma.size()!=2*nOrdsSq) gamma.resize(2*nOrdsSq);
00484
00485 for (int i=0;i<2*nOrdsSq;i++)
00486 {
00487 eigVal[i]=sqrt(-alpha[(i%nOrdsSq)/nOrds]*alpha[(i%nOrdsSq)/nOrds]-beta[i%nOrds]*beta[i%nOrds]+(refInd(0,0)*refInd(0,0)*mu*k0*k0));
00488 }
00489
00490 for(int i=0;i<2*nOrdsSq;i++){
00491 gamma(i) = sqrt(eigVal(i));
00492 if(real(gamma(i))+imag(gamma(i))<0) gamma(i)*=-1.;
00493 }
00494 for (int i=0;i<nOrdsSq;i++)
00495 {
00496 eigVecE(i,i)=1.;
00497 eigVecE(i+nOrdsSq,i+nOrdsSq)=1.;
00498 invEigVecE(i,i)=1.;
00499 invEigVecE(i+nOrdsSq,i+nOrdsSq)=1.;
00500 eigVecH(i,i)=-alpha[i/nOrds]*beta[i%nOrds]/(mu*k0*eigVal[i]);
00501 eigVecH(i+nOrdsSq,i+nOrdsSq)=(alpha[i/nOrds]*beta[i%nOrds])/(mu*k0*eigVal[i]);
00502 eigVecH(i,i+nOrdsSq)=(alpha[i/nOrds]*alpha[i/nOrds]-mu*k0*k0*refInd(0,0)*refInd(0,0))/(mu*k0*eigVal[i]);
00503 eigVecH(i+nOrdsSq,i)=(mu*k0*k0*refInd(0,0)*refInd(0,0)-beta[i%nOrds]*beta[i%nOrds])/(mu*k0*eigVal[i]);
00504 }
00505 invEigVecH=invert(eigVecH);
00506 }
00507
00508 void GratingLayer2D::setEigMat(void)
00509 {
00510 if (G.size()!=pow(2*nOrdsSq,2)) G.resize(2*nOrdsSq,2*nOrdsSq);
00511 if (eigMatE.size()!=pow(2*nOrdsSq,2)) eigMatE.resize(2*nOrds*nOrds, 2*nOrds*nOrds);
00512 complex<double> c;
00513
00514
00515
00516 for (int i=0;i<2*nOrdsSq;i++)
00517 {
00518 for (int j=0;j<2*nOrdsSq;j++)
00519 {
00520 eigMatE(i,j)=0.;
00521
00522 if ((i<nOrdsSq) && (j<nOrdsSq))
00523 {
00524 eigMatE(i,j) += mu*k0*k0*btEps(i,j);
00525 if (i==j) eigMatE(i,j) -= beta[i%nOrds]*beta[i%nOrds];
00526
00527 c=0.;
00528 for (int k=0;k<nOrdsSq;k++)
00529 {
00530 c+=alpha[i/nOrds]*invEps(i,k)*alpha[k/nOrds]*btEps(k,j);
00531 }
00532 eigMatE(i,j) -= c;
00533 }
00534
00535 if ((i<nOrdsSq) && (j>=nOrdsSq))
00536 {
00537
00538 c=0.;
00539 for (int k=0;k<nOrdsSq;k++)
00540 {
00541 c+=alpha[i/nOrds]*invEps(i,k)*beta[k%nOrds]*tbEps(k,j-nOrdsSq);
00542 }
00543 eigMatE(i,j) = ((i==j-nOrdsSq?alpha[i/nOrds]*beta[i%nOrds]:0.)-c);
00544 }
00545
00546
00547 if ((i>=nOrdsSq) && (j<nOrdsSq))
00548 {
00549
00550 c=0.;
00551 for (int k=0;k<nOrdsSq;k++)
00552 {
00553 c+=beta[i%nOrds]*invEps(i-nOrdsSq,k)*alpha[k/nOrds]*btEps(k,j);
00554 }
00555 eigMatE(i,j) += -c+(i==j+nOrdsSq?alpha[(i%nOrdsSq)/nOrds]*beta[i%nOrds]:0.);
00556 }
00557
00558 if ((i>=nOrdsSq) && (j>=nOrdsSq))
00559 {
00560 eigMatE(i,j) += mu*k0*k0*tbEps(i-nOrdsSq,j-nOrdsSq);
00561 if (i==j) eigMatE(i,j) -= alpha[(i%nOrdsSq)/nOrds]*alpha[(i%nOrdsSq)/nOrds];
00562
00563 c=0.;
00564 for (int k=0;k<nOrdsSq;k++)
00565 {
00566 c+=beta[i%nOrds]*invEps(i-nOrdsSq,k)*beta[k%nOrds]*tbEps(k,j-nOrdsSq);
00567 }
00568 eigMatE(i,j) -= c;
00569 }
00570
00571
00572
00573
00574
00575 if ((i<nOrdsSq) && (j<nOrdsSq))
00576 {
00577 G(i,j)=(i==j ? -alpha[i/nOrds]*beta[j%nOrds] : 0.);
00578 }
00579
00580 if ((i<nOrdsSq) && (j>=nOrdsSq))
00581 {
00582 G(i,j)= (i==j-nOrdsSq ? alpha[i/nOrds]*alpha[i/nOrds] : 0.) - mu*k0*k0*tbEps(i,j-nOrdsSq);
00583 }
00584
00585 if ((i>=nOrdsSq) && (j<nOrdsSq))
00586 {
00587 G(i,j)=mu*k0*k0*btEps(i-nOrdsSq,j) - (i-nOrdsSq==j ? beta[i%nOrds]*beta[i%nOrds] : 0.);
00588 }
00589
00590 if ((i>=nOrdsSq) && (j>=nOrdsSq))
00591 {
00592 G(i,j) = (i==j ? alpha[(i%nOrdsSq)/nOrds]*beta[j%nOrds] : 0.);
00593 }
00594 }
00595 }
00596
00597 if (memorysave)
00598 {
00599 invEps.resize(0);
00600 btEps.resize(0);
00601 tbEps.resize(0);
00602 }
00603 }
00604
00605
00606
00607 void GratingLayer2D::solveEigMat(void)
00608 {
00609
00610 if ((signed int) eigVecE.size()!=pow(2*nOrdsSq,2)) eigVecE.resize(0.,2*nOrdsSq, 2*nOrdsSq);
00611 if ((signed int) eigVecH.size()!=pow(2*nOrdsSq,2)) eigVecH.resize(0.,2*nOrdsSq, 2*nOrdsSq);
00612 if ((signed int) eigVal.size()!=2*nOrdsSq) eigVal.resize(0.,2*nOrdsSq);
00613 if ((signed int) gamma.size()!=2*nOrdsSq) gamma.resize(2*nOrdsSq);
00614 F_Matrix< complex<double> >eigVecE_F(eigVecE.rows(), eigVecE.columns());
00615
00616
00617 TBCI::eig(F_Matrix< complex<double> >(eigMatE),eigVal,eigVecE_F);
00618 eigVecE=Matrix< complex<double> >(eigVecE_F);
00619
00620
00621
00622 for(int i=0;i<2*nOrdsSq;i++){
00623 gamma(i) = sqrt(eigVal(i));
00624 if(real(gamma(i))+imag(gamma(i))<0) gamma(i)*=-1.;
00625 }
00626
00627 eigVecH=G*eigVecE;
00628 for (int i=0;i<2*nOrdsSq;i++)
00629 {
00630 for (int j=0;j<2*nOrdsSq;j++)
00631 eigVecH(i,j)/=(mu*k0*gamma[j]);
00632 }
00633
00634 if ((signed int) invEigVecE.size()!=pow(2*nOrdsSq,2)) {invEigVecE.resize(2*nOrdsSq,2*nOrdsSq); }
00635 if ((signed int) invEigVecH.size()!=pow(2*nOrdsSq,2)) invEigVecH.resize(2*nOrdsSq,2*nOrdsSq);
00636 invEigVecH=invert(eigVecH);
00637 invEigVecE=invert(eigVecE);
00638
00639 if (memorysave)
00640 {
00641 eigMatE.resize(0);
00642 G.resize(0);
00643 }
00644 }
00645
00646 void GratingLayer2D::calcEig(void)
00647 {
00648
00649 }