libMesh
eigen_sparse_matrix.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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"
29 #include "libmesh/eigen_core_support.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>
55 {
56 
57 public:
69  LIBMESH_CAN_DEFAULT_TO_COMMWORLD);
70 
76 
80  typedef EigenSM DataType;
81  typedef Eigen::Triplet<T,eigen_idx_type> TripletType;
82 
83  virtual void init (const numeric_index_type m,
84  const numeric_index_type n,
85  const numeric_index_type m_l,
86  const numeric_index_type n_l,
87  const numeric_index_type nnz=30,
88  const numeric_index_type noz=10,
89  const numeric_index_type blocksize=1) libmesh_override;
90 
91  virtual void init () libmesh_override;
92 
93  virtual void clear () libmesh_override;
94 
95  virtual void zero () libmesh_override;
96 
97  virtual void close () libmesh_override { this->_closed = true; }
98 
99  virtual numeric_index_type m () const libmesh_override;
100 
101  virtual numeric_index_type n () const libmesh_override;
102 
103  virtual numeric_index_type row_start () const libmesh_override;
104 
105  virtual numeric_index_type row_stop () const libmesh_override;
106 
107  virtual void set (const numeric_index_type i,
108  const numeric_index_type j,
109  const T value) libmesh_override;
110 
111  virtual void add (const numeric_index_type i,
112  const numeric_index_type j,
113  const T value) libmesh_override;
114 
115  virtual void add_matrix (const DenseMatrix<T> & dm,
116  const std::vector<numeric_index_type> & rows,
117  const std::vector<numeric_index_type> & cols) libmesh_override;
118 
119  virtual void add_matrix (const DenseMatrix<T> & dm,
120  const std::vector<numeric_index_type> & dof_indices) libmesh_override;
121 
122  virtual void add (const T a, SparseMatrix<T> & X) libmesh_override;
123 
124  virtual T operator () (const numeric_index_type i,
125  const numeric_index_type j) const libmesh_override;
126 
127  virtual Real l1_norm () const libmesh_override;
128 
129  virtual Real linfty_norm () const libmesh_override;
130 
131  virtual bool closed() const libmesh_override { return _closed; }
132 
133  virtual void print_personal(std::ostream & os=libMesh::out) const libmesh_override { this->print(os); }
134 
135  virtual void get_diagonal (NumericVector<T> & dest) const libmesh_override;
136 
137  virtual void get_transpose (SparseMatrix<T> & dest) const libmesh_override;
138 
139 private:
140 
144  DataType _mat;
145 
149  bool _closed;
150 
154  friend class EigenSparseVector<T>;
155  friend class EigenSparseLinearSolver<T>;
156 };
157 
158 } // namespace libMesh
159 
160 #endif // #ifdef LIBMESH_HAVE_EIGEN
161 #endif // #ifdef LIBMESH_EIGEN_SPARSE_MATRIX_H
Encapsulates the MPI_Comm object.
Definition: parallel.h:657
The Hex20 is an element in 3D composed of 20 nodes.
Definition: cell_hex20.h:66
virtual void print_personal(std::ostream &os=libMesh::out) const libmesh_override
Print the contents of the matrix to the screen in a package-personalized style, if available...
EigenSM DataType
Convenient typedefs.
This class provides an interface to Eigen iterative solvers that is compatible with the libMesh Linea...
Numeric vector.
Definition: dof_map.h:66
The libMesh namespace provides an interface to certain functionality in the library.
const Number zero
.
Definition: libmesh.h:178
virtual bool closed() const libmesh_override
Generic sparse matrix.
Definition: dof_map.h:65
dof_id_type numeric_index_type
Definition: id_types.h:92
void init(triangulateio &t)
Initializes the fields of t to NULL/0 as necessary.
Eigen::SparseMatrix< Number, Eigen::RowMajor, eigen_idx_type > EigenSM
bool _closed
Flag indicating if the matrix has been closed yet.
DataType _mat
Actual Eigen::SparseMatrix<> we are wrapping.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
OStreamProxy out
Eigen::Triplet< T, eigen_idx_type > TripletType
static const bool value
Definition: xdr_io.C:108
Defines a dense matrix for use in Finite Element-type computations.
Definition: dof_map.h:64