libMesh
diagonal_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 #ifndef LIBMESH_DIAGONAL_MATRIX_H
19 #define LIBMESH_DIAGONAL_MATRIX_H
20 
21 #include "libmesh/id_types.h"
22 #include "libmesh/sparse_matrix.h"
23 
24 #include <memory>
25 
26 namespace libMesh
27 {
28 template <typename>
29 class NumericVector;
30 namespace Parallel
31 {
32 class Communicator;
33 }
34 
41 template <typename T>
42 class DiagonalMatrix : public SparseMatrix<T>
43 {
44 public:
56  explicit DiagonalMatrix(const Parallel::Communicator & comm);
57 
62  virtual ~DiagonalMatrix() = default;
63 
64  virtual SolverPackage solver_package() override
65  {
66  return DIAGONAL_MATRIX;
67  }
68 
72  DiagonalMatrix(DiagonalMatrix &&) = default;
73  DiagonalMatrix & operator=(DiagonalMatrix &&) = default;
74  DiagonalMatrix & operator=(const DiagonalMatrix &) = delete;
75  virtual SparseMatrix<T> & operator=(const SparseMatrix<T> &) override
76  {
77  libmesh_not_implemented();
78  return *this;
79  }
80 
85 
90 
91 
92  virtual
93  void init(const numeric_index_type m,
94  const numeric_index_type n,
95  const numeric_index_type m_l,
96  const numeric_index_type n_l,
97  const numeric_index_type nnz = 30,
98  const numeric_index_type noz = 10,
99  const numeric_index_type blocksize = 1) override;
100 
101  virtual void init(ParallelType type = PARALLEL) override;
102 
109  virtual void init(const NumericVector<T> & other, const bool fast = false);
110 
118  virtual void init(const DiagonalMatrix<T> & other, const bool fast = false);
119 
120  virtual void clear() override;
121 
122  virtual void zero() override;
123 
124  virtual std::unique_ptr<SparseMatrix<T>> zero_clone () const override;
125 
126  virtual std::unique_ptr<SparseMatrix<T>> clone () const override;
127 
128  virtual void close() override;
129 
130  virtual numeric_index_type m() const override;
131 
132  virtual numeric_index_type n() const override;
133 
134  virtual numeric_index_type row_start() const override;
135 
136  virtual numeric_index_type row_stop() const override;
137 
138  virtual numeric_index_type col_start() const override;
139 
140  virtual numeric_index_type col_stop() const override;
141 
142  virtual void set(const numeric_index_type i, const numeric_index_type j, const T value) override;
143 
144  virtual void add(const numeric_index_type i, const numeric_index_type j, const T value) override;
145 
146  virtual
147  void add_matrix(const DenseMatrix<T> & dm,
148  const std::vector<numeric_index_type> & rows,
149  const std::vector<numeric_index_type> & cols) override;
150 
151  virtual
152  void add_matrix(const DenseMatrix<T> & dm,
153  const std::vector<numeric_index_type> & dof_indices) override;
154 
155  virtual void add(const T a, const SparseMatrix<T> & X) override;
156 
157  virtual T operator()(const numeric_index_type i, const numeric_index_type j) const override;
158 
159  virtual Real l1_norm() const override;
160 
161  virtual Real linfty_norm() const override;
162 
163  virtual bool closed() const override;
164 
165  virtual void print_personal(std::ostream & os = libMesh::out) const override;
166 
167  virtual void get_diagonal(NumericVector<T> & dest) const override;
168 
169  virtual void get_transpose(SparseMatrix<T> & dest) const override;
170 
171  virtual void get_row(numeric_index_type i,
172  std::vector<numeric_index_type> & indices,
173  std::vector<T> & values) const override;
174 
175  virtual void zero_rows(std::vector<numeric_index_type> & rows, T val = 0) override;
176 
177  const NumericVector<T> & diagonal() const;
178 
179  virtual void restore_original_nonzero_pattern() override;
180 
181 protected:
183  std::unique_ptr<NumericVector<T>> _diagonal;
184 };
185 } // namespace libMesh
186 
187 #endif // LIBMESH_DIAGONAL_MATRIX_H
virtual SparseMatrix< T > & operator=(const SparseMatrix< T > &) override
This looks like a copy assignment operator, but note that, unlike normal copy assignment operators...
virtual numeric_index_type col_stop() const override
virtual void get_transpose(SparseMatrix< T > &dest) const override
Copies the transpose of the matrix into dest, which may be *this.
virtual SolverPackage solver_package() override
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.
const NumericVector< T > & diagonal() const
virtual numeric_index_type col_start() const override
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: vector_fe_ex5.C:44
const Parallel::Communicator & comm() const
virtual Real l1_norm() 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.
The libMesh namespace provides an interface to certain functionality in the library.
virtual void restore_original_nonzero_pattern() override
Reset the memory storage of the matrix.
virtual void zero() override
Set all entries to 0.
virtual bool closed() const override
virtual numeric_index_type n() const override
Generic sparse matrix.
Definition: vector_fe_ex5.C:46
virtual numeric_index_type m() const override
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 numeric_index_type row_stop() const override
virtual ~DiagonalMatrix()=default
This class does not manually manage any memory, so the destructor can be safely defaulted.
virtual void clear() override
Restores the SparseMatrix<T> to a pristine state.
DiagonalMatrix(const Parallel::Communicator &comm)
Constructor; initializes the matrix to be empty, without any structure, i.e.
virtual T operator()(const numeric_index_type i, const numeric_index_type j) const override
Diagonal matrix class whose underlying storage is a vector.
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 zero_rows(std::vector< numeric_index_type > &rows, T val=0) override
Sets all row entries to 0 then puts diag_value in the diagonal entry.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void get_diagonal(NumericVector< T > &dest) const override
Copies the diagonal part of the matrix into dest.
OStreamProxy out
virtual Real linfty_norm() const override
static const bool value
Definition: xdr_io.C:54
DiagonalMatrix & operator=(DiagonalMatrix &&)=default
virtual std::unique_ptr< SparseMatrix< T > > clone() const override
virtual numeric_index_type row_start() const override
std::unique_ptr< NumericVector< T > > _diagonal
Underlying diagonal matrix storage.
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.
SolverPackage
Defines an enum for various linear solver packages.
Defines a dense matrix for use in Finite Element-type computations.
Definition: dof_map.h:75
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value) override
Add value to the element (i,j).
virtual std::unique_ptr< SparseMatrix< T > > zero_clone() const override
ParallelType
Defines an enum for parallel data structure types.