Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)

app-pkauf/PHC4.hh
Go to the documentation of this file.
00001 #ifndef CONV_PHC4_HH_
00002 #define CONV_PHC4_HH_
00003 
00004 #include <fstream>
00005 #include <memory>
00006 #include <vector>
00007 #include <complex>
00008 #include "basics/outputMatlab.hh"
00009 #include "basics/exceptions.hh"
00010 #include "hp2D/spacePreBuilder.hh"
00011 #include "geometry/meshImport2Dgeneral.hh"
00012 #include "graphics/matlab.hh"
00013 #include "basics/outputMatlab.hh"
00014 #include "basics/exceptions.hh"
00015 #include "hp2D/hpAdaptiveSpaceH1.hh"
00016 #include "hp2D/bilinearForm.hh"
00017 #include "operator/sparseMatrix.hh"
00018 #include "operator/denseMatrix.hh"
00019 #include "operator/superLU.hh"
00020 #include "eigensolver/ARPACK.hh"
00021 #include "space/formula.hh"
00022 #include "toolbox/resourceMonitor.hh"
00023 #include "Brillouin.hh"
00024 #include "hp2D/aprioriRef2D.hh"
00025 #include "toolbox/inputOutput.hh"
00026 
00027 using concepts::Real;
00028 using concepts::Cmplx;
00029 
00030 namespace phc {
00031 
00032   // ****************************************************************** PHC4 **
00033   
00039   class PHC4 {
00040     public:
00041     /* Constructor: Imports the spaces, constructs the k-values (uint i)
00042        and the bilinearforms with dielectricity constants epsilon 
00043        (std::vector<Real> epsilon) on attributes 
00044        (std::vector<uint> attributes) and default epsilon (Real dflt).
00045        @param spc vector containing the adresses of the four spaces.
00046        @param i number of points on the boundary of the irreducible 
00047        Brillouin zone used in the computation.
00048        @param epsilon Must have the same length as attributes. Contains the 
00049        epsilon values belonging to the same index of the attribute vector.
00050        @param attributes see epsilon
00051        @param dflt The default value for the dielectric constant.*/
00052     PHC4(std::vector<hp2D::hpAdaptiveSpaceH1*> spc, Brillouin_Base& B, 
00053    uint i, std::vector<Real> epsilon, std::vector<uint> attributes,
00054    Real dflt = 1.0);
00055     PHC4(std::vector<hp2D::hpAdaptiveSpaceH1*> spc, Brillouin_Base& B, 
00056    concepts::Array<concepts::Real2d*> k_val, std::vector<Real> epsilon, 
00057    std::vector<uint> attributes, Real dflt = 1.0);
00058     ~PHC4();
00059     // rebuilding:
00060     void rebuild();
00061     hp2D::hpAdaptiveSpaceH1 get_spc(uint i);
00062     
00063     concepts::Array<concepts::Real2d*> get_k() { return k_; }
00064     // Constructing the bilinear forms with dielectric constants:
00065     void bilinearforms(std::vector<Real> epsilon, 
00066            std::vector<uint> attributes,
00067            Real dflt = 1.0);
00068     // Assembling the basic matrices:
00069     void assemble();
00070     
00071     /*get_16_matrices_k1_k2() saves the assembled matrices corresponding to
00072       the combinations of the 4 spaces as matlab files m_1, ... , m_16. 
00073       The k-vector array corresponding to the Brillouin zone iteration is saved
00074       to the file Brill_factors.m. Use the matlab routine Bandstructure.m to 
00075       compute the Bandstructure.*/
00076     
00077     void get_16_matrices_k1_k2_(std::string path = std::string(".")); 
00078     void get_16_matrices_k1_k2_TE(std::string path = std::string("."));
00079     void get_16_matrices_k1_k2_TM(std::string path = std::string("."));
00080     
00081     // Getting the multiplication factors out of k_x, k_y:
00082     void factor(Real k_x, Real k_y, concepts::Array<Real> v1,
00083     concepts::Array<Real> v2);
00084 
00085     /* The routine handling the Brillouin iterations:
00086        @param kmax Number of eigenvalues to compute (should not be too small)
00087        @param maxiter maximal number of Arnoldi iterations to be performed
00088        @param eps tolerance up to which Arnoldi should converge
00089        @param n saving the eigenfunctions to the nth eigenvalue (counted from 
00090        below) if EF_graph == true.
00091        @EF_graph if true the eigenfunctions are plotted
00092        The output of this routine are matlab files containing an eigenvalue 
00093        matrix (Brillouin Point x Eigenvalue), Eigenvalue in increasing order 
00094        at first Brillouin point. If EF_graph == true you get another set of 
00095        matlab files containing the basis functions, indexed with the 
00096        Brillouin point index..
00097     */
00098     void compute(uint kmax, uint maxiter, Real eps, uint n,
00099      bool EF_graph);
00100     /* If you want to compute the generalized eigenvalues with matlab, use 
00101        this routine. 
00102        Specify the Brillouin Point at which you want to look and indicate 
00103        the refinement step for the name of the output matrices. With the 
00104        boolian TE you can choose whether you want TE modes (TE_TM = 0) or 
00105        TM modes (TE_TM = 1).
00106        The output m-files with the matrices will be called 
00107        'Laplace_T*_"Brillouin_Point"_"Ref_Step"_.m' and
00108        'Identity_T*_"Brillouin_Point"_"Ref_Step"_.m', with * being 'E' or 'M'
00109        corresponding to TE_TM. Also a file with the times needed to assemble
00110        the matrices is written.
00111     */ 
00112     void give_matrices(uint Brillouin_Point, uint Ref_Step,  
00113                        std::string tag);
00114     void rcount() { refine_++; }
00115     /* If you want to compute the eigenvalues of a refined problem 
00116        use this routine:
00117        Same output as compute, but with additional parameter in the
00118        matlab file for number
00119        of recomputation step (this parameter is zero in compute(...).
00120     */
00121     void recompute(uint kmax, uint maxiter, Real eps, uint n, bool EF_graph);
00122     uint nDoF() { return nDoF_; }
00123     // returns pointer to  the eigenvalue matrix for TE / TM modes:
00124     concepts::SparseMatrix<Real>* get_ev_TE() { return ev_TE_matrix_; }
00125     concepts::SparseMatrix<Real>* get_ev_TM() { return ev_TM_matrix_; }
00126     void set_tag(std::string tag){ tag_ = tag; set_tag_ = true; }
00127     double get_time(){ return t_; }
00128     
00129   private:
00130     // The four spaces:
00131     hp2D::hpAdaptiveSpaceH1& spc1_;
00132     hp2D::hpAdaptiveSpaceH1& spc2_;
00133     hp2D::hpAdaptiveSpaceH1& spc3_;
00134     hp2D::hpAdaptiveSpaceH1& spc4_;
00135     std::vector<hp2D::hpAdaptiveSpaceH1*> spc_;
00136     hp2D::hpFull& prebuild_;
00137     uint refine_;
00138     uint nDoF_;
00139     Brillouin_Base& B_;
00140     concepts::Array<concepts::Real2d*> k_;
00141     // Bilinearforms for TE and TM modes:
00142     hp2D::Laplace<> *la_TE_, *la_TM_;
00143     hp2D::Identity<> *id_TE_, *id_TM_;
00144     // for the assembly routine:
00145     bool assembled_;
00146     bool rebuilt_;
00147     bool computed_;
00148     bool EF_graph_;
00149     // The different matrices without factors:
00150     std::vector<concepts::SparseMatrix<Real>* > mat_la_TE_;
00151     std::vector<concepts::SparseMatrix<Real>* > mat_la_TM_;
00152     std::vector<concepts::SparseMatrix<Real>* > mat_id_TE_;
00153     std::vector<concepts::SparseMatrix<Real>* > mat_id_TM_;
00154     // The array of multiplication factors:
00155     concepts::Array<Cmplx> factor_;
00156     // The single space factors:
00157     concepts::Array<Cmplx> single_factor_;
00158     // matrices of eigenvalues:
00159     concepts::SparseMatrix<Real>* ev_TE_matrix_;
00160     concepts::SparseMatrix<Real>* ev_TM_matrix_;
00161     // The residual starting vectors:
00162     concepts::Array<Cmplx>* resid_TE_;
00163     concepts::Array<Cmplx>* resid_TM_;
00164     // intermediate eigenvalue arrays:
00165     concepts::Array<concepts::Array<Cmplx>*>* ev_TE_;
00166     concepts::Array<concepts::Array<Cmplx>*>* ev_TM_;
00167     concepts::Vector<Cmplx>* EF_TE_;
00168     concepts::Vector<Cmplx>* EF_TM_;
00169     // a tag that is appended to e.g. ev_TE_"tag"_1.m
00170     std::string tag_;
00171     bool set_tag_;
00172     double t_;
00173 
00174     // Sorting the eigenvalues / eigenvectors:
00175     concepts::Array<uint> sort_(concepts::Array<Cmplx>* unsorted);
00176 
00183     void brillouinIteration_(uint kmax, uint maxiter, Real eps, uint n, 
00184            uint j, concepts::LiCoI<Real>* Id_OP);
00185   };
00186 
00187 } // namespace phc
00188 
00189 #endif /*CONV_PHC4_HH_*/

Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)