eigen_sparse_matrix.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_EIGEN_SPARSE_MATRIX_H
21 #define LIBMESH_EIGEN_SPARSE_MATRIX_H
22 
23 #include "libmesh/libmesh_config.h"
24 
25 #ifdef LIBMESH_HAVE_EIGEN
26 
27 // Local includes
28 #include "libmesh/sparse_matrix.h"
30 
31 // Eigen includes
32 
33 // C++ includes
34 #include <algorithm>
35 #include <cstddef>
36 
37 namespace libMesh
38 {
39 
40 // Forward declarations
41 template <typename T> class DenseMatrix;
42 template <typename T> class EigenSparseVector;
43 template <typename T> class EigenSparseLinearSolver;
44 
53 template <typename T>
54 class EigenSparseMatrix final : public SparseMatrix<T>
55 {
56 
57 public:
69 
74  EigenSparseMatrix (EigenSparseMatrix &&) = default;
75  EigenSparseMatrix (const EigenSparseMatrix &) = default;
76  EigenSparseMatrix & operator= (const EigenSparseMatrix &) = default;
78  virtual ~EigenSparseMatrix () = default;
79 
83  typedef EigenSM DataType;
84  typedef Eigen::Triplet<T,eigen_idx_type> TripletType;
85 
86  virtual void init (const numeric_index_type m,
87  const numeric_index_type n,
88  const numeric_index_type m_l,
89  const numeric_index_type n_l,
90  const numeric_index_type nnz=30,
91  const numeric_index_type noz=10,
92  const numeric_index_type blocksize=1) override;
93 
94  virtual void init () override;
95 
96  virtual void clear () override;
97 
98  virtual void zero () override;
99 
100  virtual void close () override { this->_closed = true; }
101 
102  virtual numeric_index_type m () const override;
103 
104  virtual numeric_index_type n () const override;
105 
106  virtual numeric_index_type row_start () const override;
107 
108  virtual numeric_index_type row_stop () const override;
109 
110  virtual void set (const numeric_index_type i,
111  const numeric_index_type j,
112  const T value) override;
113 
114  virtual void add (const numeric_index_type i,
115  const numeric_index_type j,
116  const T value) override;
117 
118  virtual void add_matrix (const DenseMatrix<T> & dm,
119  const std::vector<numeric_index_type> & rows,
120  const std::vector<numeric_index_type> & cols) override;
121 
122  virtual void add_matrix (const DenseMatrix<T> & dm,
123  const std::vector<numeric_index_type> & dof_indices) override;
124 
125  virtual void add (const T a, const SparseMatrix<T> & X) override;
126 
127  virtual T operator () (const numeric_index_type i,
128  const numeric_index_type j) const override;
129 
130  virtual Real l1_norm () const override;
131 
132  virtual Real linfty_norm () const override;
133 
134  virtual bool closed() const override { return _closed; }
135 
136  virtual void print_personal(std::ostream & os=libMesh::out) const override { this->print(os); }
137 
138  virtual void get_diagonal (NumericVector<T> & dest) const override;
139 
140  virtual void get_transpose (SparseMatrix<T> & dest) const override;
141 
142 private:
143 
148 
152  bool _closed;
153 
157  friend class EigenSparseVector<T>;
158  friend class EigenSparseLinearSolver<T>;
159 };
160 
161 } // namespace libMesh
162 
163 #endif // #ifdef LIBMESH_HAVE_EIGEN
164 #endif // #ifdef LIBMESH_EIGEN_SPARSE_MATRIX_H
virtual void init() override
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value) override
virtual numeric_index_type m() const override
virtual void close() override
Eigen::Triplet< T, eigen_idx_type > TripletType
virtual numeric_index_type row_stop() const override
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: diff_context.h:40
const Parallel::Communicator & comm() const
EigenSparseMatrix & operator=(const EigenSparseMatrix &)=default
virtual ~EigenSparseMatrix()=default
virtual void get_transpose(SparseMatrix< T > &dest) const override
virtual void zero() override
virtual numeric_index_type n() const override
virtual bool closed() const override
virtual void get_diagonal(NumericVector< T > &dest) const override
dof_id_type numeric_index_type
Definition: id_types.h:92
EigenSparseMatrix(const Parallel::Communicator &comm)
Eigen::SparseMatrix< Number, Eigen::RowMajor, eigen_idx_type > EigenSM
virtual T operator()(const numeric_index_type i, const numeric_index_type j) const override
virtual numeric_index_type row_start() const override
virtual void print_personal(std::ostream &os=libMesh::out) const override
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual Real linfty_norm() const override
virtual void clear() override
static const bool value
Definition: xdr_io.C:109
virtual Real l1_norm() const override
A matrix object used for finite element assembly and numerics.
Definition: dense_matrix.h:54
OStreamProxy out(std::cout)
void print(std::ostream &os=libMesh::out, const bool sparse=false) const
virtual void add_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols) override