libMesh
Loading...
Searching...
No Matches
lumped_mass_matrix.C
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#include "libmesh/lumped_mass_matrix.h"
19#include "libmesh/numeric_vector.h"
20
21// C++ Includes
22#include <cmath>
23#include <memory>
24
25namespace libMesh
26{
27
28template <typename T>
33
34template <typename T>
35std::unique_ptr<SparseMatrix<T>>
37{
38 // Make empty copy with matching comm
39 auto mat_copy = std::make_unique<LumpedMassMatrix<T>>(this->comm());
40
41 // Initialize copy with our same nonzero structure, and explicitly
42 // zero values using fast == false.
43 mat_copy->init(*this, /*fast=*/false);
44
45 return mat_copy;
46}
47
48template <typename T>
49std::unique_ptr<SparseMatrix<T>>
51{
52 // Make empty copy with matching comm
53 auto mat_copy = std::make_unique<LumpedMassMatrix<T>>(this->comm());
54
55 // Make copy of our diagonal
56 auto diag_copy = this->_diagonal->clone();
57
58 // Swap diag_copy with diagonal in mat_copy
59 *mat_copy = std::move(*diag_copy);
60
61 return mat_copy;
62}
63
64template <typename T>
65void
67 const numeric_index_type libmesh_dbg_var(j),
68 const T value)
69{
70 libmesh_assert_msg(i == j, "Set in a lumped mass matrix really only makes sense for i == j");
71 this->_diagonal->set(i, std::abs(value));
72}
73
74template <typename T>
75void
77{
78 this->_diagonal->add(i, std::abs(value));
79}
80
81template <typename T>
82void
84{
85 if (dynamic_cast<const LumpedMassMatrix<T> *>(&X))
86 {
87 auto x_diagonal = this->_diagonal->zero_clone();
88 X.get_diagonal(*x_diagonal);
89 this->_diagonal->add(a, *x_diagonal);
90 }
91 else
92 libmesh_error_msg("Unsupported matrix type passed to LumpedMassMatrix::add");
93}
94
95template <typename T>
98{
99 *this->_diagonal = vec;
100 return *this;
101}
102
103template <typename T>
106{
107 this->_diagonal->swap(vec);
108 return *this;
109}
110
111template class LIBMESH_EXPORT LumpedMassMatrix<Number>;
112
113} // namespace libMesh
Diagonal matrix class whose underlying storage is a vector.
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.
Template class used to construct a lumped mass matrix.
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
virtual void set(const numeric_index_type i, const numeric_index_type j, const T value) override
Set the element (i,j) to value.
LumpedMassMatrix(const Parallel::Communicator &comm)
Constructor; initializes the matrix to be empty, without any structure, i.e.
virtual std::unique_ptr< SparseMatrix< T > > clone() const override
LumpedMassMatrix & operator=(LumpedMassMatrix &&)=default
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
Generic sparse matrix.
virtual void get_diagonal(NumericVector< T > &dest) const =0
Copies the diagonal part of the matrix into dest.
The libMesh namespace provides an interface to certain functionality in the library.
dof_id_type numeric_index_type
Definition id_types.h:99
static const bool value
Definition xdr_io.C:55