libmesh解析
本工作只是尝试解析原libmesh的代码,供学习使用
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 
lumped_mass_matrix.C
浏览该文件的文档.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2023 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 
25 namespace libMesh
26 {
27 
28 template <typename T>
29 LumpedMassMatrix<T>::LumpedMassMatrix(const Parallel::Communicator & comm_in)
30  : DiagonalMatrix<T>(comm_in)
31 {
32 }
33 
34 template <typename T>
35 std::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  // Work around an issue on older compilers. We are able to simply
46  // "return mat_copy;" on newer compilers
47  return std::unique_ptr<SparseMatrix<T>>(mat_copy.release());
48 }
49 
50 template <typename T>
51 std::unique_ptr<SparseMatrix<T>>
53 {
54  // Make empty copy with matching comm
55  auto mat_copy = std::make_unique<LumpedMassMatrix<T>>(this->comm());
56 
57  // Make copy of our diagonal
58  auto diag_copy = this->_diagonal->clone();
59 
60  // Swap diag_copy with diagonal in mat_copy
61  *mat_copy = std::move(*diag_copy);
62 
63  // Work around an issue on older compilers. We are able to simply
64  // "return mat_copy;" on newer compilers
65  return std::unique_ptr<SparseMatrix<T>>(mat_copy.release());
66 }
67 
68 template <typename T>
69 void
71  const numeric_index_type libmesh_dbg_var(j),
72  const T value)
73 {
74  libmesh_assert_msg(i == j, "Set in a lumped mass matrix really only makes sense for i == j");
75  this->_diagonal->set(i, std::abs(value));
76 }
77 
78 template <typename T>
79 void
81 {
82  this->_diagonal->add(i, std::abs(value));
83 }
84 
85 template <typename T>
86 void
88 {
89  if (dynamic_cast<const LumpedMassMatrix<T> *>(&X))
90  {
91  auto x_diagonal = this->_diagonal->zero_clone();
92  X.get_diagonal(*x_diagonal);
93  this->_diagonal->add(a, *x_diagonal);
94  }
95  else
96  libmesh_error_msg("Unsupported matrix type passed to LumpedMassMatrix::add");
97 }
98 
99 template <typename T>
102 {
103  *this->_diagonal = vec;
104  return *this;
105 }
106 
107 template <typename T>
110 {
111  this->_diagonal->swap(vec);
112  return *this;
113 }
114 
115 template class LIBMESH_EXPORT LumpedMassMatrix<Number>;
116 
117 } // namespace libMesh
virtual void set(const numeric_index_type i, const numeric_index_type j, const T value) override
设置矩阵中指定位置 的值为 value。
LumpedMassMatrix(const Parallel::Communicator &comm)
构造函数;将矩阵初始化为空,没有任何结构,即矩阵完全无法使用。 因此,此构造函数仅适用于作为类的成员的矩阵。所有其他矩阵应在具有所有必要信息的数据流中创建。
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value) override
将值 value 添加到矩阵中的指定位置 。
提供了不同线性代数库的向量存储方案的统一接口。
Definition: dof_map.h:67
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
计算自动微分实数向量的绝对值。
Definition: type_vector.h:112
这是一个通用的稀疏矩阵类。该类包含了必须在派生类中覆盖的纯虚拟成员。 使用一个公共的基类允许从不同的求解器包中以不同的格式统一访问稀疏矩阵。
Definition: dof_map.h:66
dof_id_type numeric_index_type
Definition: id_types.h:99
virtual void get_diagonal(NumericVector< T > &dest) const =0
复制矩阵的对角线部分到 dest。
对角矩阵类,其底层存储是一个向量
virtual std::unique_ptr< SparseMatrix< T > > clone() const override
克隆当前矩阵的唯一指针。
LumpedMassMatrix & operator=(LumpedMassMatrix &&)=default
模板类用于构造集中质量矩阵。 可能还有用于计算与整体系统缩放相关的数量。每当在此类上调用 add 方法时,我们都会将提供的值的绝对值相加到行索引 i 中。
virtual std::unique_ptr< SparseMatrix< T > > zero_clone() const override
创建一个与当前矩阵相同的零矩阵的唯一指针。