$extrastylesheet
eigen_sparse_matrix.h
Go to the documentation of this file.
00001 // The libMesh Finite Element Library.
00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
00003 
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either
00007 // version 2.1 of the License, or (at your option) any later version.
00008 
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Lesser General Public License for more details.
00013 
00014 // You should have received a copy of the GNU Lesser General Public
00015 // License along with this library; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 
00019 
00020 #ifndef LIBMESH_EIGEN_SPARSE_MATRIX_H
00021 #define LIBMESH_EIGEN_SPARSE_MATRIX_H
00022 
00023 #include "libmesh/libmesh_config.h"
00024 
00025 #ifdef LIBMESH_HAVE_EIGEN
00026 
00027 // Local includes
00028 #include "libmesh/sparse_matrix.h"
00029 #include "libmesh/eigen_core_support.h"
00030 
00031 // Eigen includes
00032 
00033 // C++ includes
00034 #include <algorithm>
00035 #include <cstddef>
00036 
00037 namespace libMesh
00038 {
00039 
00040 
00041 
00042 // Forward declarations
00043 template <typename T> class DenseMatrix;
00044 template <typename T> class EigenSparseVector;
00045 template <typename T> class EigenSparseLinearSolver;
00046 
00047 
00048 
00056 template <typename T>
00057 class EigenSparseMatrix : public SparseMatrix<T>
00058 {
00059 
00060 public:
00076   EigenSparseMatrix (const Parallel::Communicator &comm
00077                      LIBMESH_CAN_DEFAULT_TO_COMMWORLD);
00078 
00084   ~EigenSparseMatrix ();
00085 
00089   typedef EigenSM DataType;
00090   typedef Eigen::Triplet<T,eigen_idx_type> TripletType;
00091 
00102   void init (const numeric_index_type m,
00103              const numeric_index_type n,
00104              const numeric_index_type m_l,
00105              const numeric_index_type n_l,
00106              const numeric_index_type nnz=30,
00107              const numeric_index_type noz=10,
00108              const numeric_index_type blocksize=1);
00109 
00113   void init ();
00114 
00121   void clear ();
00122 
00126   void zero ();
00127 
00133   void close () const { const_cast<EigenSparseMatrix<T>*>(this)->_closed = true; }
00134 
00139   numeric_index_type m () const;
00140 
00145   numeric_index_type n () const;
00146 
00151   numeric_index_type row_start () const;
00152 
00157   numeric_index_type row_stop () const;
00158 
00165   void set (const numeric_index_type i,
00166             const numeric_index_type j,
00167             const T value);
00168 
00177   void add (const numeric_index_type i,
00178             const numeric_index_type j,
00179             const T value);
00180 
00188   void add_matrix (const DenseMatrix<T> &dm,
00189                    const std::vector<numeric_index_type> &rows,
00190                    const std::vector<numeric_index_type> &cols);
00191 
00196   void add_matrix (const DenseMatrix<T> &dm,
00197                    const std::vector<numeric_index_type> &dof_indices);
00198 
00206   void add (const T a, SparseMatrix<T> &X);
00207 
00215   T operator () (const numeric_index_type i,
00216                  const numeric_index_type j) const;
00217 
00228   Real l1_norm () const { libmesh_not_implemented(); return 0.; }
00229 
00241   Real linfty_norm () const { libmesh_not_implemented(); return 0.; }
00242 
00247   bool closed() const { return _closed; }
00248 
00253   void print_personal(std::ostream& os=libMesh::out) const { this->print(os); }
00254 
00258   virtual void get_diagonal (NumericVector<T>& dest) const;
00259 
00264   virtual void get_transpose (SparseMatrix<T>& dest) const;
00265 
00266 private:
00267 
00271   DataType _mat;
00272 
00276   bool _closed;
00277 
00281   friend class EigenSparseVector<T>;
00282   friend class EigenSparseLinearSolver<T>;
00283 };
00284 
00285 } // namespace libMesh
00286 
00287 #endif // #ifdef LIBMESH_HAVE_EIGEN
00288 #endif // #ifdef LIBMESH_EIGEN_SPARSE_MATRIX_H