00001 #pragma once
00002 
00003 #ifndef GRATING_H
00004 #define GRATING_H
00005 
00006 
00007 #include "GratingLayer1D.h"
00008 #include <vector>
00009 
00010 #include "tbci/f_bandmatrix.h"
00011 #include "tbci/cscmatrix.h"
00012 
00013 using std::complex;
00014 using std::string;
00015 using std::vector;
00016 using TBCI::F_Matrix;
00017 using TBCI::F_BandMatrix;
00018 using TBCI::Vector;
00019 using TBCI::CSCMatrix;
00020 
00021 
00023 class Grating1D{
00024 
00025 private:
00027         double theta;
00029         double lambda;
00031         double period;
00033         double gratingSize; 
00035         double padding;
00037         Vector< complex<double> > r;
00039         Vector< complex<double> > t;
00041         Vector< complex<double> > refl;
00043         Vector< complex<double> > tran, transS;
00045         Vector <double> rEFF;
00047         Vector <double> tEFF;
00049         complex <double> n0;
00051         complex <double> n3;
00053         complex <double> nPad;
00054         
00055         F_BandMatrix< complex<double> > precond;
00056         F_Matrix< complex<double> >invA;
00058         F_BandMatrix< complex<double> > lhsMatBand;
00060         Vector < complex<double> > rhsVec;
00062         Vector < complex<double> > solVec;
00064         Vector < complex<double> > incid;
00065         Vector < complex<double> > gamma;  
00067         complex <double> I;
00068         complex <double> za, zb;
00070         int nLayers;
00072         int nOrds
00074         int minOrd
00076         int maxOrd;
00078         int nUnknowns;
00080         int nPermSegs, nPadSegs, gratingSegs;
00082         string polMode;
00083         string initMode;
00085         F_Matrix<int> material, MCoeffs;
00087         int nMat;
00089         int matPad;
00091         F_Matrix < complex<double> > indices;
00093         Vector< complex<double> > refIndMat;
00095         F_Matrix <double> transpt;
00097         Vector<double> slabThick;
00099         F_Matrix<double> fieldAmplitude;
00101         int dimX;
00103         int dimY;
00104         
00105         double embedding, embPeriod, propAfter;
00106         int nOrdsEmb;
00107         Vector < complex<double> > TransEmb, tEmb, gammaEmb;
00108         double plotSize;
00109         
00110         F_Matrix< complex<double> > Q1, Q2, G, tau, R, T, R_tilde, T_tilde, F;
00111         Vector < complex<double> > expTerm;
00112         double incidPowFactor;
00113 public:
00114         
00116         vector<GratingLayer> layer;
00117         
00118         
00124 
00125         Grating(int truncation, int layers, int nSegments);
00127         ~Grating();
00129         void setParameters(double,double,double,complex<double>,complex<double>,complex<double>,double,Vector< complex<double> >,string);
00131         void initLayers(string,string,string);
00133         void initLayers(F_Matrix<int>,Vector<double>,string);
00135         void initLayers(F_Matrix< complex<double> >,Vector<double>);
00137         void solve(string);
00139         void calcIntField(int,int);
00141         void calcExtField(int,int,double,double,double);
00143         void calcEmbField(int,int,double,double,double);
00145         complex<double> getIntField(double,double);
00147         complex<double> getExtField(double,double);
00149         complex<double> getEmbExtField(double,double);
00151         void writeField(string);
00153         void calcTransEmb(double embSize, int embOrd);
00155         double getEfficiencyR(int);
00157         double getEfficiencyT(int);
00159         complex<double> getTrans(int);
00161         complex<double> getRef(int);
00162         
00164         void calcIncid(Vector < complex <double> >,int);
00165         
00166         
00168         void changeRefInd(int,int,complex<double>);
00170         void changeMaterial(int slab, int segment, int mat);
00172         void addFrame(complex<double>,double);
00174         void writeParameters(string);
00177 
00178 
00179 
00185 
00186         void setTheta(double);
00188         double getTheta();
00190         void setLambda(double); 
00192         double getLambda();
00194         void setPeriod(double); 
00196         double getPeriod(void);
00198         double getGratingSize(void);
00200         void setnPermSegs(int); 
00202         int getnPermSegs(void);
00204         void setPolMode(string);
00206         string getPolMode();
00208         void setN0(complex<double>);
00210         complex<double> getN0();
00212         void setN3(complex<double>);
00214         complex<double> getN3();
00216         void setNPad(complex<double>);
00218         complex<double> getNPad();
00220         void setIncid(Vector< complex<double> >);
00222         complex<double>getIncid(int);
00224         void setMatPad(int);
00226         void setPadding(double);        
00228         double getPadding(void);
00230         int getnOrds();
00232         int getnLayers(void);
00234         double getEmbSize();
00236         complex<double> getLhsMat(int,int);
00238         complex<double>getRhsVec(int);
00240         complex<double> getA(int,int);
00242         complex<double> getAdash(int,int);
00244         complex<double>getGamma(int);   
00245         
00246         
00248 
00253 
00254         void setEquations(void);
00256         void setLhsMatTE(void);
00258         void setLhsMatTM(void);
00260         void  solveEquations(void);
00262         void setSMatrix(void);
00264         void findEfficiency(string);
00265         void findEfficiencyT(void);
00266         void findEfficiencyS(void);
00268         void calcSTR(void);
00270         void importMaterials(string);
00272         void calcGamma(void);
00274         void setLhsMatBand(int,int,complex<double>);
00275         
00276         
00277         int nLines(string);
00278         
00279         double delta(int,int);
00280 
00281         inline F_Matrix < complex<double> > unit(int i)
00282         {
00283                 F_Matrix< complex<double> > m(i);
00284                 m.setunit();
00285                 return m;
00286         }
00287 
00289 };
00290 
00291 #endif