libMesh
diagonal_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 #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 
61  DiagonalMatrix(DiagonalMatrix &&) = default;
62  DiagonalMatrix & operator=(DiagonalMatrix &&) = default;
63 
68 
73 
74 
75  void init(const numeric_index_type m,
76  const numeric_index_type n,
77  const numeric_index_type m_l,
78  const numeric_index_type n_l,
79  const numeric_index_type nnz = 30,
80  const numeric_index_type noz = 10,
81  const numeric_index_type blocksize = 1) override;
82 
83  void init() override;
84 
89  virtual void init(const NumericVector<T> & other, const bool fast = false);
90 
96  virtual void init(const DiagonalMatrix<T> & other, const bool fast = false);
97 
98  void clear() override;
99 
100  void zero() override;
101 
102  void close() override;
103 
104  numeric_index_type m() const override;
105 
106  numeric_index_type n() const override;
107 
108  numeric_index_type row_start() const override;
109 
110  numeric_index_type row_stop() const override;
111 
112  void set(const numeric_index_type i, const numeric_index_type j, const T value) override;
113 
114  void add(const numeric_index_type i, const numeric_index_type j, const T value) override;
115 
116  void add_matrix(const DenseMatrix<T> & dm,
117  const std::vector<numeric_index_type> & rows,
118  const std::vector<numeric_index_type> & cols) override;
119 
120  void add_matrix(const DenseMatrix<T> & dm,
121  const std::vector<numeric_index_type> & dof_indices) override;
122 
123  void add(const T a, const SparseMatrix<T> & X) override;
124 
125  T operator()(const numeric_index_type i, const numeric_index_type j) const override;
126 
127  Real l1_norm() const override;
128 
129  Real linfty_norm() const override;
130 
131  bool closed() const override;
132 
133  void print_personal(std::ostream & os = libMesh::out) const override;
134 
135  void get_diagonal(NumericVector<T> & dest) const override;
136 
137  void get_transpose(SparseMatrix<T> & dest) const override;
138 
139  void zero_rows(std::vector<numeric_index_type> & rows, T val = 0) override;
140 
141  const NumericVector<T> & diagonal() const;
142 
143 protected:
145  std::unique_ptr<NumericVector<T>> _diagonal;
146 };
147 } // namespace libMesh
148 
149 #endif // LIBMESH_DIAGONAL_MATRIX_H
libMesh::DiagonalMatrix::DiagonalMatrix
DiagonalMatrix(const Parallel::Communicator &comm)
Constructor; initializes the matrix to be empty, without any structure, i.e.
Definition: diagonal_matrix.C:27
libMesh::DiagonalMatrix::zero_rows
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.
Definition: diagonal_matrix.C:248
libMesh::DiagonalMatrix::row_stop
numeric_index_type row_stop() const override
Definition: diagonal_matrix.C:132
libMesh::DiagonalMatrix::operator=
DiagonalMatrix & operator=(DiagonalMatrix &&)=default
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::DiagonalMatrix::diagonal
const NumericVector< T > & diagonal() const
Definition: diagonal_matrix.C:256
libMesh::DiagonalMatrix::m
numeric_index_type m() const override
Definition: diagonal_matrix.C:111
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::DiagonalMatrix::print_personal
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: diagonal_matrix.C:222
libMesh::SparseMatrix
Generic sparse matrix.
Definition: vector_fe_ex5.C:45
libMesh::DiagonalMatrix
Diagonal matrix class whose underlying storage is a vector.
Definition: diagonal_matrix.h:42
libMesh::DiagonalMatrix::set
void set(const numeric_index_type i, const numeric_index_type j, const T value) override
Set the element (i,j) to value.
Definition: diagonal_matrix.C:139
libMesh::NumericVector
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
Definition: vector_fe_ex5.C:43
libMesh::DiagonalMatrix::closed
bool closed() const override
Definition: diagonal_matrix.C:215
libMesh::DiagonalMatrix::get_transpose
void get_transpose(SparseMatrix< T > &dest) const override
Copies the transpose of the matrix into dest, which may be *this.
Definition: diagonal_matrix.C:236
libMesh::DiagonalMatrix::get_diagonal
void get_diagonal(NumericVector< T > &dest) const override
Copies the diagonal part of the matrix into dest.
Definition: diagonal_matrix.C:229
libMesh::DiagonalMatrix::l1_norm
Real l1_norm() const override
Definition: diagonal_matrix.C:201
libMesh::DiagonalMatrix::linfty_norm
Real linfty_norm() const override
Definition: diagonal_matrix.C:208
libMesh::DiagonalMatrix::n
numeric_index_type n() const override
Definition: diagonal_matrix.C:118
libMesh::numeric_index_type
dof_id_type numeric_index_type
Definition: id_types.h:99
libMesh::DiagonalMatrix::init
void init() override
Initialize this matrix using the sparsity structure computed by dof_map.
Definition: diagonal_matrix.C:67
libMesh::DiagonalMatrix::_diagonal
std::unique_ptr< NumericVector< T > > _diagonal
Underlying diagonal matrix storage.
Definition: diagonal_matrix.h:145
libMesh::DiagonalMatrix::zero
void zero() override
Set all entries to 0.
Definition: diagonal_matrix.C:97
libMesh::DiagonalMatrix::close
void close() override
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
Definition: diagonal_matrix.C:104
value
static const bool value
Definition: xdr_io.C:56
libMesh::DiagonalMatrix::add
void add(const numeric_index_type i, const numeric_index_type j, const T value) override
Add value to the element (i,j).
Definition: diagonal_matrix.C:147
libMesh::DiagonalMatrix::operator()
T operator()(const numeric_index_type i, const numeric_index_type j) const override
Definition: diagonal_matrix.C:191
libMesh::DiagonalMatrix::add_matrix
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: diagonal_matrix.C:155
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::DiagonalMatrix::row_start
numeric_index_type row_start() const override
Definition: diagonal_matrix.C:125
libMesh::DiagonalMatrix::clear
void clear() override
Restores the SparseMatrix<T> to a pristine state.
Definition: diagonal_matrix.C:90
libMesh::out
OStreamProxy out