libMesh
Loading...
Searching...
No Matches
diagonal_matrix.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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
26namespace libMesh
27{
28template <typename>
29class NumericVector;
30namespace Parallel
31{
32class Communicator;
33}
34
41template <typename T>
43{
44public:
57
62 virtual ~DiagonalMatrix() = default;
63
64 virtual SolverPackage solver_package() override
65 {
66 return DIAGONAL_MATRIX;
67 }
68
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,
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
181protected:
183 std::unique_ptr<NumericVector<T>> _diagonal;
184};
185} // namespace libMesh
186
187#endif // LIBMESH_DIAGONAL_MATRIX_H
Defines a dense matrix for use in Finite Element-type computations.
Diagonal matrix class whose underlying storage is a vector.
virtual bool closed() const override
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 numeric_index_type m() const override
virtual void clear() override
Restores the SparseMatrix<T> to a pristine state.
DiagonalMatrix(DiagonalMatrix &&)=default
unique pointers can be moved but not copied
virtual numeric_index_type col_start() const 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.
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.
virtual numeric_index_type row_start() const override
virtual numeric_index_type col_stop() const override
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 numeric_index_type n() const override
virtual std::unique_ptr< SparseMatrix< T > > clone() const override
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.
virtual void set(const numeric_index_type i, const numeric_index_type j, const T value) override
Set the element (i,j) to value.
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 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's internal assembly routines, ensuring that the values are consistent across p...
virtual numeric_index_type row_stop() const override
virtual void get_diagonal(NumericVector< T > &dest) const override
Copies the diagonal part of the matrix into dest.
virtual std::unique_ptr< SparseMatrix< T > > zero_clone() const override
virtual Real linfty_norm() const override
virtual ~DiagonalMatrix()=default
This class does not manually manage any memory, so the destructor can be safely defaulted.
virtual T operator()(const numeric_index_type i, const numeric_index_type j) const override
std::unique_ptr< NumericVector< T > > _diagonal
Underlying diagonal matrix storage.
const NumericVector< T > & diagonal() const
virtual SolverPackage solver_package() override
DiagonalMatrix & operator=(DiagonalMatrix &&)=default
virtual SparseMatrix< T > & operator=(const SparseMatrix< T > &) override
This looks like a copy assignment operator, but note that, unlike normal copy assignment operators,...
virtual void zero() override
Set all entries to 0.
DiagonalMatrix & operator=(const DiagonalMatrix &)=delete
virtual void restore_original_nonzero_pattern() override
Reset the memory storage of the matrix.
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
const Parallel::Communicator & comm() const
Generic sparse matrix.
The libMesh namespace provides an interface to certain functionality in the library.
ParallelType
Defines an enum for parallel data structure types.
OStreamProxy out
dof_id_type numeric_index_type
Definition id_types.h:99
SolverPackage
Defines an enum for various linear solver packages.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const bool value
Definition xdr_io.C:55