Skip to content
Snippets Groups Projects
Select Git revision
  • d15023eef5e2bbc163cbaeddb24b6b80c4ca3b9a
  • develop default protected
  • feature/advection
  • feature/composite-scheme-other-fluxes
  • origin/stage/bouguettaia
  • save_clemence
  • feature/local-dt-fsi
  • feature/variational-hydro
  • feature/gmsh-reader
  • feature/reconstruction
  • feature/kinetic-schemes
  • feature/composite-scheme-sources
  • feature/serraille
  • feature/composite-scheme
  • hyperplastic
  • feature/polynomials
  • feature/gks
  • feature/implicit-solver-o2
  • feature/coupling_module
  • feature/implicit-solver
  • feature/merge-local-dt-fsi
  • v0.5.0 protected
  • v0.4.1 protected
  • v0.4.0 protected
  • v0.3.0 protected
  • v0.2.0 protected
  • v0.1.0 protected
  • Kidder
  • v0.0.4 protected
  • v0.0.3 protected
  • v0.0.2 protected
  • v0 protected
  • v0.0.1 protected
33 results

EigenvalueSolver.hpp

Blame
  • EigenvalueSolver.hpp 3.96 KiB
    #ifndef EIGENVALUE_SOLVER_HPP
    #define EIGENVALUE_SOLVER_HPP
    
    #include <algebra/PETScUtils.hpp>
    
    #include <algebra/SmallMatrix.hpp>
    #include <algebra/SmallVector.hpp>
    #include <analysis/Polynomial.hpp>
    #include <utils/Exceptions.hpp>
    #include <utils/SmallArray.hpp>
    
    class EigenvalueSolver
    {
     private:
      struct Internals;
      TinyMatrix<3> eigenvectors0{1, 0, 0, 0, 1, 0, 0, 0, 1};
      TinyVector<3> eigenvalues0{0, 0, 0};
    
    #ifdef PUGS_HAS_SLEPC
      void computeForSymmetricMatrix(const PETScAijMatrixEmbedder& A, SmallArray<double>& eigenvalues);
    
      void computeForSymmetricMatrix(const PETScAijMatrixEmbedder& A,
                                     SmallArray<double>& eigenvalues,
                                     std::vector<SmallVector<double>>& eigenvectors);
    
      void computeForSymmetricMatrix(const PETScAijMatrixEmbedder& A,
                                     SmallArray<double>& eigenvalues,
                                     SmallMatrix<double>& P);
      void computeExpForSymmetricMatrix(const PETScAijMatrixEmbedder& A, SmallMatrix<double>& expA);
    #endif   // PUGS_HAS_SLEPC
    
     public:
      template <typename MatrixType>
      void
      computeForSymmetricMatrix([[maybe_unused]] const MatrixType& A, [[maybe_unused]] SmallArray<double>& eigenvalues)
      {
    #ifdef PUGS_HAS_SLEPC
        this->computeForSymmetricMatrix(PETScAijMatrixEmbedder{A}, eigenvalues);
    #else    // PUGS_HAS_SLEPC
        throw NotImplementedError("SLEPc is required to solve eigenvalue problems");
    #endif   // PUGS_HAS_SLEPC
      }
    
      template <typename MatrixType>
      void
      computeForSymmetricMatrix([[maybe_unused]] const MatrixType& A,
                                [[maybe_unused]] SmallArray<double>& eigenvalues,
                                [[maybe_unused]] std::vector<SmallVector<double>>& eigenvectors)
      {
    #ifdef PUGS_HAS_SLEPC
        this->computeForSymmetricMatrix(PETScAijMatrixEmbedder{A}, eigenvalues, eigenvectors);
    #else    // PUGS_HAS_SLEPC
        throw NotImplementedError("SLEPc is required to solve eigenvalue problems");
    #endif   // PUGS_HAS_SLEPC
      }
    
      template <typename MatrixType>
      void
      computeForSymmetricMatrix([[maybe_unused]] const MatrixType& A,
                                [[maybe_unused]] SmallArray<double>& eigenvalues,
                                [[maybe_unused]] SmallMatrix<double>& P)
      {
    #ifdef PUGS_HAS_SLEPC
        this->computeForSymmetricMatrix(PETScAijMatrixEmbedder{A}, eigenvalues, P);
    #else    // PUGS_HAS_SLEPC
        throw NotImplementedError("SLEPc is required to solve eigenvalue problems");
    #endif   // PUGS_HAS_SLEPC
      }
    
      template <typename MatrixType>
      void
      computeExpForSymmetricMatrix([[maybe_unused]] const MatrixType& A, [[maybe_unused]] SmallMatrix<double>& expA)
      {
    #ifdef PUGS_HAS_SLEPC
        this->computeExpForSymmetricMatrix(PETScAijMatrixEmbedder{A}, expA);
    #else    // PUGS_HAS_SLEPC
        throw NotImplementedError("SLEPc is required to solve eigenvalue problems");
    #endif   // PUGS_HAS_SLEPC
      }
    
      template <typename T>
      PUGS_INLINE TinyMatrix<3, 3, T> swap(TinyMatrix<3, 3, T>& matrix, size_t i, size_t j) const;
    
      template <typename T>
      PUGS_INLINE constexpr TinyMatrix<3, 3, T> rowReduce(const TinyMatrix<3, 3, T>& matrix, const double epsilon) const;
    
      TinyMatrix<3, 3> findEigenvector(const TinyMatrix<3, 3>& A,
                                       const double eigenvalue,
                                       const size_t space_size,
                                       const double epsilon) const;
    
      bool isDiagonal(const TinyMatrix<3, 3>& A, const double epsilon);
    
      TinyMatrix<3, 3> findEigenvectors(const TinyMatrix<3, 3>& A, TinyVector<3> eigenvalues, const double epsilon) const;
    
      std::tuple<TinyVector<3>, TinyMatrix<3>> findEigen(const TinyMatrix<3> A);
      TinyVector<3> _findEigenValues(const TinyMatrix<3>& A, const double epsilon) const;
    
      double _findFirstRoot(Polynomial<3> P) const;
    
      TinyVector<2> _findLastRoots(Polynomial<2> P, const double epsilon) const;
    
      TinyMatrix<3> computeExpForTinyMatrix(const TinyMatrix<3>& A);
    
      EigenvalueSolver();
      ~EigenvalueSolver() = default;
    };
    
    #endif   // EIGENVALUE_SOLVER_HPP