#ifndef SLAMARR_H #define SLAMARR_H /* * METRIC --- Mode expansion modeling in integrated optics / photonics * http://metric.computational-photonics.eu/ */ /* * slamarr.h * Arrays of Modes, mode interference evaluation */ class ModeArray { public: // number of modes included int num; // initialize ModeArray(); // destroy ~ModeArray(); // copy constructor ModeArray(const ModeArray& ma); // assignment ModeArray& operator=(const ModeArray& s); // free allocated memory void clear(); // input from FILE dat void read(FILE *dat); // input from file with default name void read(char ext0, char ext1); // output to FILE dat void write(FILE *dat); // output to file with default name void write(char ext0, char ext1); // subscripting inline Mode& operator() (int i) { return mvec[i]; } inline Mode operator() (int i) const { return mvec[i]; } // add a mode void add(Mode m); // delete a mode entry void remove(int i); // add an entire ModeArray nma, nma is cleared ! void merge(ModeArray& nma); // sort the array by squared propagation constants, highest first void sort(); // compare the present object to ma, return 1 if equal, 0 otherwise int equal(ModeArray& ma); // ----------------------------------------------------------- // mode interference evaluation, bidirectional mode superpositions, // all modes are assumed to belong to the same waveguide ! // // field and energy density at a point (x, z), // amplitudes of forward and backward propgating mode variants must // be supplied, the interpretation depends on whether a z-interval // is present as an optional argument: // argument list ends with x, z: // famp: complex amplitudes of the forward traveling modes at z=0, // bamp: complex amplitudes of the backward traveling modes at z=0, // (note that z can be negative); // argument list ends with x, z, z0, z1: // famp: complex amplitudes of the forward traveling modes at z=z0, // bamp: complex amplitudes of the backward traveling modes at z=z1. // the local field, // cp: one of EX, EY, EZ, HX, HY, HZ, SX, SY, or SZ Complex field(const Cvector& famp, const Cvector& bamp, Fcomp cp, double x, double z) const; Complex field(const Cvector& famp, const Cvector& bamp, Fcomp cp, double x, double z, double z0, double z1) const; // local field "strength", id: one of mE, mH, qE, qH, mW double lfs(const Cvector& famp, const Cvector& bamp, FSid id, double x, double z) const; double lfs(const Cvector& famp, const Cvector& bamp, FSid id, double x, double z, double z0, double z1) const; // local energy density double endens(const Cvector& famp, const Cvector& bamp, double x, double z) const; double endens(const Cvector& famp, const Cvector& bamp, double x, double z, double z0, double z1) const; // the six electric and magnetic components at x, z void emfield(const Cvector& famp, const Cvector& bamp, double x, double z, Complex& ex, Complex& ey, Complex& ez, Complex& hx, Complex& hy, Complex& hz) const; void emfield(const Cvector& famp, const Cvector& bamp, double x, double z, double z0, double z1, Complex& ex, Complex& ey, Complex& ez, Complex& hx, Complex& hy, Complex& hz) const; // field superposition at point (x, z), // amp: complex amplitudes of forward traveling modes at z=0, // amplitudes evolve according to // amp_j(z) = amp_j(0)*exp(-i cbet_j*z), // pert: propagation constant perturbations, with // cbet_j = this(j).cbeta(FORW)+pert(j) // cp: EX, EY, EZ, HX, HY, HZ, SX, SY, SZ Complex pfield(const Cvector& amp, const Cvector& pert, Fcomp cp, double x, double z) const; // ----------------------------------------------------------- // visualization: output to MATLAB .m files // evaluation of the mode interference pattern in the display window // xbeg <= x <= xend, zbeg <= z <=zend // amp_f: amplitudes of the forward propagating modes at z=0 // amp_b: amplitudes of the backward propagating modes at z=0 // npx, npz: number of points in output mesh // ext0, ext1: filename id characters for the .m file // assumption: uniform polarization and wavelength of all included modes // image plot corresponding to field component cp // cp: EX, EY, EZ, HX, HY, HZ, SX, SY, SZ // foa: MOD, SQR, REP, IMP void plot(const Cvector& amp_f, const Cvector& amp_b, Fcomp cp, Afo foa, double xbeg, double xend, double zbeg, double zend, int npx, int npz, char ext0, char ext1) const; // relative phase, image plot void phasemap(const Cvector& amp_f, const Cvector& amp_b, Fcomp cp, double xbeg, double xend, double zbeg, double zend, int npx, int npz, char ext0, char ext1) const; // electromagnetic energy density image void plot(const Cvector& amp_f, const Cvector& amp_b, double xbeg, double xend, double zbeg, double zend, int npx, int npz, char ext0, char ext1) const; // fancy style surface plot corresponding to field component cp // cp: EX, EY, EZ, HX, HY, HZ, SX, SY, SZ void fplot(const Cvector& amp_f, const Cvector& amp_b, Fcomp cp, double xbeg, double xend, double zbeg, double zend, int npx, int npz, char ext0, char ext1) const; // animation of the light propagation along the waveguide // the frames show images of EY (TE) resp. HY (TM), at // ntfr equidistant times over one time period void movie(const Cvector& amp_f, const Cvector& amp_b, double xbeg, double xend, double zbeg, double zend, int npx, int npz, int ntfr, char ext0, char ext1); // animation of the light propagation along the waveguide, fancy style // the frames show surfaces of EY (TE) resp. HY (TM), at // ntfr equidistant times over one time period void fmovie(const Cvector& amp_f, const Cvector& amp_b, double xbeg, double xend, double zbeg, double zend, int npx, int npz, int ntfr, char ext0, char ext1); // export full field data ("everything") into a viewer MATLAB file void viewer(const Cvector& amp_f, const Cvector& amp_b, double xbeg, double xend, double zbeg, double zend, int npx, int npz, char ext0, char ext1) const; // ----------------------------------------------------------- // for the QUEP implementation: // overlaps of perpendiculary propagating modes Cmatrix crossoverlap(Propdir hdir, const ModeArray& mv, Propdir vdir, double zpos, Interval i) const; void crossoverlap(const ModeArray& mv, double zpos, Interval i, Cmatrix& cff, Cmatrix& cfb, Cmatrix& cbf, Cmatrix& cbb) const; // assuming that all modes belong to the same mode spectrum: // check orthogonality & normalization double orthonormality(); // ----------------------------------------------------------- // related to the classification of FB modes: // remove all non propagating modes from the array void restrict2prop(); // ----------------------------------------------------------- // three segment coupler, power transfer evaluation // imode: input mode, excites the array's modes // with rel. power 1 at z=0 // omode: output mode, relative power is returned // pert: propagation constant perturbations, // cbet(j) = this(j).beta+pert(j) // --- this(j) are assumed to be normalized ! --- // weights for the power evaluation: // w = ( omode | this(m) ) ( this(m) | imode ) double pweight(const Mode& imode, int m, const Mode& omode); // single relative power level for device length l double iopower(const Mode& imode, const Mode& omode, const Cvector& pert, double l); // output power for numl devices of lengths between lmin and lmax Dvector iopower(const Mode& imode, const Mode& omode, const Cvector& pert, int numl, double lbeg, double lend); // ... write to file void writeiopower(const Mode& imode, const Mode& omode, const Cvector& pert, int numl, double lbeg, double lend, char ext0, char ext1); // ----------------------------------------------------------- // prepare vTE / vTM mode representation, for given ky, for all modes void vectorify(Complex ky); // ----------------------------------------------------------- private: Mode *mvec; }; #endif // SLAMARR_H