libMesh
laspack_matrix.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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_LASPACK_MATRIX_H
21 #define LIBMESH_LASPACK_MATRIX_H
22 
23 #include "libmesh/libmesh_config.h"
24 
25 #ifdef LIBMESH_HAVE_LASPACK
26 
27 // Local includes
28 #include "libmesh/sparse_matrix.h"
29 
30 // Laspack includes
31 #include <qmatrix.h>
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 LaspackVector;
43 template <typename T> class LaspackLinearSolver;
44 
55 template <typename T>
56 class LaspackMatrix final : public SparseMatrix<T>
57 {
58 
59 public:
70  LaspackMatrix (const Parallel::Communicator & comm);
71 
77  LaspackMatrix (LaspackMatrix &&) = delete;
78  LaspackMatrix (const LaspackMatrix &) = delete;
79  LaspackMatrix & operator= (const LaspackMatrix &) = delete;
80  LaspackMatrix & operator= (LaspackMatrix &&) = delete;
81  virtual ~LaspackMatrix ();
82 
86  virtual bool need_full_sparsity_pattern() const override
87  { return true; }
88 
94  virtual void update_sparsity_pattern (const SparsityPattern::Graph &) override;
95 
96  virtual void init (const numeric_index_type m,
97  const numeric_index_type n,
98  const numeric_index_type m_l,
99  const numeric_index_type n_l,
100  const numeric_index_type nnz=30,
101  const numeric_index_type noz=10,
102  const numeric_index_type blocksize=1) override;
103 
104  virtual void init () override;
105 
106  virtual void clear () override;
107 
108  virtual void zero () override;
109 
110  virtual void close () override;
111 
112  virtual numeric_index_type m () const override;
113 
114  virtual numeric_index_type n () const override;
115 
116  virtual numeric_index_type row_start () const override;
117 
118  virtual numeric_index_type row_stop () const override;
119 
120  virtual void set (const numeric_index_type i,
121  const numeric_index_type j,
122  const T value) override;
123 
124  virtual void add (const numeric_index_type i,
125  const numeric_index_type j,
126  const T value) override;
127 
128  virtual void add_matrix (const DenseMatrix<T> & dm,
129  const std::vector<numeric_index_type> & rows,
130  const std::vector<numeric_index_type> & cols) override;
131 
132  virtual void add_matrix (const DenseMatrix<T> & dm,
133  const std::vector<numeric_index_type> & dof_indices) override;
134 
142  virtual void add (const T a, const SparseMatrix<T> & X) override;
143 
144  virtual T operator () (const numeric_index_type i,
145  const numeric_index_type j) const override;
146 
147  virtual Real l1_norm () const override { libmesh_not_implemented(); return 0.; }
148 
149  virtual Real linfty_norm () const override { libmesh_not_implemented(); return 0.; }
150 
151  virtual bool closed() const override { return _closed; }
152 
153  virtual void print_personal(std::ostream & os=libMesh::out) const override { this->print(os); }
154 
155  virtual void get_diagonal (NumericVector<T> & dest) const override;
156 
157  virtual void get_transpose (SparseMatrix<T> & dest) const override;
158 
159 private:
160 
166  const numeric_index_type j) const;
167 
171  QMatrix _QMat;
172 
176  std::vector<numeric_index_type> _csr;
177 
182  std::vector<std::vector<numeric_index_type>::const_iterator> _row_start;
183 
187  bool _closed;
188 
192  friend class LaspackVector<T>;
193  friend class LaspackLinearSolver<T>;
194 };
195 
196 } // namespace libMesh
197 
198 #endif // #ifdef LIBMESH_HAVE_LASPACK
199 #endif // #ifdef LIBMESH_LASPACK_MATRIX_H
libMesh::LaspackMatrix::LaspackMatrix
LaspackMatrix(const Parallel::Communicator &comm)
Constructor; initializes the matrix to be empty, without any structure, i.e.
Definition: laspack_matrix.C:234
libMesh::LaspackMatrix::operator=
LaspackMatrix & operator=(const LaspackMatrix &)=delete
libMesh::LaspackMatrix::~LaspackMatrix
virtual ~LaspackMatrix()
Definition: laspack_matrix.C:243
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::LaspackMatrix::_row_start
std::vector< std::vector< numeric_index_type >::const_iterator > _row_start
The start of each row in the compressed row index data structure.
Definition: laspack_matrix.h:182
libMesh::ParallelObject::comm
const Parallel::Communicator & comm() const
Definition: parallel_object.h:94
libMesh::DenseMatrix
Defines a dense matrix for use in Finite Element-type computations.
Definition: dof_map.h:73
libMesh::SparseMatrix
Generic sparse matrix.
Definition: vector_fe_ex5.C:45
libMesh::LaspackMatrix::set
virtual void set(const numeric_index_type i, const numeric_index_type j, const T value) override
Set the element (i,j) to value.
Definition: laspack_matrix.C:333
libMesh::LaspackMatrix::update_sparsity_pattern
virtual void update_sparsity_pattern(const SparsityPattern::Graph &) override
Updates the matrix sparsity pattern.
Definition: laspack_matrix.C:39
libMesh::NumericVector
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
Definition: vector_fe_ex5.C:43
libMesh::LaspackMatrix::clear
virtual void clear() override
Restores the SparseMatrix<T> to a pristine state.
Definition: laspack_matrix.C:251
libMesh::LaspackMatrix::print_personal
virtual void print_personal(std::ostream &os=libMesh::out) const override
Print the contents of the matrix to the screen in a package-personalized style, if available.
Definition: laspack_matrix.h:153
libMesh::LaspackMatrix::pos
numeric_index_type pos(const numeric_index_type i, const numeric_index_type j) const
Definition: laspack_matrix.C:440
libMesh::LaspackVector
This class provides a nice interface to the Laspack C-based data structures for serial vectors.
Definition: laspack_matrix.h:42
libMesh::LaspackMatrix::operator()
virtual T operator()(const numeric_index_type i, const numeric_index_type j) const override
Definition: laspack_matrix.C:427
libMesh::LaspackMatrix::get_transpose
virtual void get_transpose(SparseMatrix< T > &dest) const override
Copies the transpose of the matrix into dest, which may be *this.
Definition: laspack_matrix.C:226
libMesh::LaspackMatrix::add
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value) override
Add value to the element (i,j).
Definition: laspack_matrix.C:353
libMesh::LaspackMatrix::close
virtual void close() override
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
Definition: laspack_matrix.C:464
libMesh::LaspackMatrix
The LaspackMatrix class wraps a QMatrix object from the Laspack library.
Definition: laspack_matrix.h:56
libMesh::LaspackMatrix::zero
virtual void zero() override
Set all entries to 0.
Definition: laspack_matrix.C:267
libMesh::numeric_index_type
dof_id_type numeric_index_type
Definition: id_types.h:99
libMesh::LaspackMatrix::linfty_norm
virtual Real linfty_norm() const override
Definition: laspack_matrix.h:149
libMesh::LaspackMatrix::closed
virtual bool closed() const override
Definition: laspack_matrix.h:151
libMesh::LaspackMatrix::row_start
virtual numeric_index_type row_start() const override
Definition: laspack_matrix.C:317
libMesh::LaspackMatrix::get_diagonal
virtual void get_diagonal(NumericVector< T > &dest) const override
Copies the diagonal part of the matrix into dest.
Definition: laspack_matrix.C:218
libMesh::LaspackMatrix::l1_norm
virtual Real l1_norm() const override
Definition: laspack_matrix.h:147
libMesh::LaspackMatrix::init
virtual void init() override
Initialize this matrix using the sparsity structure computed by dof_map.
Definition: laspack_matrix.C:147
value
static const bool value
Definition: xdr_io.C:56
libMesh::LaspackMatrix::_QMat
QMatrix _QMat
The Laspack sparse matrix pointer.
Definition: laspack_matrix.h:171
libMesh::LaspackLinearSolver
This class provides an interface to Laspack iterative solvers that is compatible with the libMesh Lin...
Definition: laspack_matrix.h:43
libMesh::LaspackMatrix::m
virtual numeric_index_type m() const override
Definition: laspack_matrix.C:297
libMesh::LaspackMatrix::_csr
std::vector< numeric_index_type > _csr
The compressed row indices.
Definition: laspack_matrix.h:176
libMesh::LaspackMatrix::add_matrix
virtual void add_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols) override
Add the full matrix dm to the SparseMatrix.
Definition: laspack_matrix.C:198
libMesh::LaspackMatrix::_closed
bool _closed
Flag indicating if the matrix has been closed yet.
Definition: laspack_matrix.h:187
libMesh::LaspackMatrix::row_stop
virtual numeric_index_type row_stop() const override
Definition: laspack_matrix.C:325
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::SparseMatrix::print
void print(std::ostream &os=libMesh::out, const bool sparse=false) const
Print the contents of the matrix to the screen in a uniform style, regardless of matrix/solver packag...
Definition: sparse_matrix.C:200
libMesh::out
OStreamProxy out
libMesh::SparsityPattern::Graph
Definition: sparsity_pattern.h:52
libMesh::LaspackMatrix::n
virtual numeric_index_type n() const override
Definition: laspack_matrix.C:307
libMesh::LaspackMatrix::need_full_sparsity_pattern
virtual bool need_full_sparsity_pattern() const override
The LaspackMatrix needs the full sparsity pattern.
Definition: laspack_matrix.h:86