libMesh
laspack_matrix.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 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:
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  virtual SparseMatrix<T> & operator=(const SparseMatrix<T> &) override
83  {
84  libmesh_not_implemented();
85  return *this;
86  }
87 
88  virtual SolverPackage solver_package() override
89  {
90  return LASPACK_SOLVERS;
91  }
92 
96  virtual bool need_full_sparsity_pattern() const override
97  { return true; }
98 
104  virtual void update_sparsity_pattern (const SparsityPattern::Graph &) override;
105 
106  virtual void init (const numeric_index_type m,
107  const numeric_index_type n,
108  const numeric_index_type m_l,
109  const numeric_index_type n_l,
110  const numeric_index_type nnz=30,
111  const numeric_index_type noz=10,
112  const numeric_index_type blocksize=1) override;
113 
114  virtual void init (ParallelType = PARALLEL) override;
115 
116  virtual void clear () override;
117 
118  virtual void zero () override;
119 
120  virtual std::unique_ptr<SparseMatrix<T>> zero_clone () const override;
121 
122  virtual std::unique_ptr<SparseMatrix<T>> clone () const override;
123 
124  virtual void close () override;
125 
126  virtual numeric_index_type m () const override;
127 
128  virtual numeric_index_type n () const override;
129 
130  virtual numeric_index_type row_start () const override;
131 
132  virtual numeric_index_type row_stop () const override;
133 
134  virtual numeric_index_type col_start () const override;
135 
136  virtual numeric_index_type col_stop () const override;
137 
138  virtual void set (const numeric_index_type i,
139  const numeric_index_type j,
140  const T value) override;
141 
142  virtual void add (const numeric_index_type i,
143  const numeric_index_type j,
144  const T value) override;
145 
146  virtual void add_matrix (const DenseMatrix<T> & dm,
147  const std::vector<numeric_index_type> & rows,
148  const std::vector<numeric_index_type> & cols) override;
149 
150  virtual void add_matrix (const DenseMatrix<T> & dm,
151  const std::vector<numeric_index_type> & dof_indices) override;
152 
160  virtual void add (const T a, const SparseMatrix<T> & X) override;
161 
162  virtual T operator () (const numeric_index_type i,
163  const numeric_index_type j) const override;
164 
165  virtual Real l1_norm () const override;
166 
167  virtual Real linfty_norm () const override { libmesh_not_implemented(); return 0.; }
168 
169  virtual bool closed() const override { return _closed; }
170 
171  virtual void print_personal(std::ostream & os=libMesh::out) const override { this->print(os); }
172 
173  virtual void get_diagonal (NumericVector<T> & dest) const override;
174 
175  virtual void get_transpose (SparseMatrix<T> & dest) const override;
176 
177  virtual void get_row(numeric_index_type i,
178  std::vector<numeric_index_type> & indices,
179  std::vector<T> & values) const override;
180 
181 private:
182 
188  const numeric_index_type j) const;
189 
193  QMatrix _QMat;
194 
198  std::vector<numeric_index_type> _csr;
199 
204  std::vector<std::vector<numeric_index_type>::const_iterator> _row_start;
205 
209  bool _closed;
210 
214  friend class LaspackVector<T>;
215  friend class LaspackLinearSolver<T>;
216 };
217 
218 } // namespace libMesh
219 
220 #endif // #ifdef LIBMESH_HAVE_LASPACK
221 #endif // #ifdef LIBMESH_LASPACK_MATRIX_H
virtual void init(const numeric_index_type m, const numeric_index_type n, const numeric_index_type m_l, const numeric_index_type n_l, const numeric_index_type nnz=30, const numeric_index_type noz=10, const numeric_index_type blocksize=1) override
Initialize SparseMatrix with the specified sizes.
virtual std::unique_ptr< SparseMatrix< T > > zero_clone() const override
virtual void get_diagonal(NumericVector< T > &dest) const override
Copies the diagonal part of the matrix into dest.
virtual numeric_index_type col_start() const override
virtual Real linfty_norm() const override
std::vector< numeric_index_type > _csr
The compressed row indices.
virtual bool need_full_sparsity_pattern() const override
The LaspackMatrix needs the full sparsity pattern.
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: vector_fe_ex5.C:44
const Parallel::Communicator & comm() const
QMatrix _QMat
The Laspack sparse matrix pointer.
The libMesh namespace provides an interface to certain functionality in the library.
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...
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value) override
Add value to the element (i,j).
Generic sparse matrix.
Definition: vector_fe_ex5.C:46
virtual std::unique_ptr< SparseMatrix< T > > clone() const override
This class provides an interface to Laspack iterative solvers that is compatible with the libMesh Lin...
virtual SparseMatrix< T > & operator=(const SparseMatrix< T > &) override
This looks like a copy assignment operator, but note that, unlike normal copy assignment operators...
numeric_index_type pos(const numeric_index_type i, const numeric_index_type j) const
virtual void get_transpose(SparseMatrix< T > &dest) const override
Copies the transpose of the matrix into dest, which may be *this.
virtual void close() override
Calls the SparseMatrix&#39;s internal assembly routines, ensuring that the values are consistent across p...
dof_id_type numeric_index_type
Definition: id_types.h:99
virtual Real l1_norm() const override
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 zero() override
Set all entries to 0.
virtual bool closed() const override
virtual void clear() override
Restores the SparseMatrix<T> to a pristine state.
This class provides a nice interface to the Laspack C-based data structures for serial vectors...
std::vector< std::vector< numeric_index_type >::const_iterator > _row_start
The start of each row in the compressed row index data structure.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual numeric_index_type m() const override
OStreamProxy out
virtual numeric_index_type n() const override
static const bool value
Definition: xdr_io.C:54
bool _closed
Flag indicating if the matrix has been closed yet.
virtual void update_sparsity_pattern(const SparsityPattern::Graph &) override
Updates the matrix sparsity pattern.
virtual numeric_index_type row_stop() const override
SolverPackage
Defines an enum for various linear solver packages.
virtual SolverPackage solver_package() override
The LaspackMatrix class wraps a QMatrix object from the Laspack library.
Defines a dense matrix for use in Finite Element-type computations.
Definition: dof_map.h:75
LaspackMatrix & operator=(const LaspackMatrix &)=delete
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...
virtual void get_row(numeric_index_type i, std::vector< numeric_index_type > &indices, std::vector< T > &values) const override
Get a row from the matrix.
virtual numeric_index_type col_stop() const override
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.
LaspackMatrix(const Parallel::Communicator &comm)
Constructor; initializes the matrix to be empty, without any structure, i.e.
ParallelType
Defines an enum for parallel data structure types.