21 #include "libmesh/libmesh_config.h"
23 #ifdef LIBMESH_HAVE_LASPACK
25 #include "libmesh/laspack_matrix.h"
26 #include "libmesh/dense_matrix.h"
27 #include "libmesh/dof_map.h"
28 #include "libmesh/sparsity_pattern.h"
48 libmesh_assert(this->_dof_map);
58 size += sparsity_pattern[row].size();
61 _row_start.reserve(n_rows + 1);
67 std::vector<numeric_index_type>::iterator position = _csr.begin();
69 _row_start.push_back (position);
74 for (
const auto & col : sparsity_pattern[row])
76 libmesh_assert (position != _csr.end());
81 _row_start.push_back (position);
92 libmesh_assert_equal_to (n_rows, this->m());
98 auto rs = _row_start[i];
102 Q_SetLen (&_QMat, i+1, length);
116 libmesh_assert_equal_to (this->pos(i,j), l);
117 Q_SetEntry (&_QMat, i+1, l, j+1, 0.);
127 template <
typename T>
137 libmesh_assert_equal_to (m_in, m_l);
138 libmesh_assert_equal_to (n_in, n_l);
139 libmesh_assert_equal_to (m_in, n_in);
140 libmesh_assert_greater (nnz, 0);
142 libmesh_error_msg(
"ERROR: Only the init() member that uses the DofMap is implemented for Laspack matrices!");
149 template <
typename T>
157 libmesh_assert(this->_dof_map);
173 libmesh_assert_equal_to (n_rows, n_cols);
174 libmesh_assert_equal_to (m_l, n_rows);
175 libmesh_assert_equal_to (n_l, n_cols);
180 const std::vector<numeric_index_type> & n_nz = this->_sp->get_n_nz();
181 const std::vector<numeric_index_type> & n_oz = this->_sp->get_n_oz();
185 libmesh_assert_equal_to (n_nz.size(), n_l);
186 libmesh_assert_equal_to (n_oz.size(), n_l);
191 Q_Constr(&_QMat, const_cast<char *>(
"Mat"), n_rows, _LPFalse, Rowws, Normal, _LPTrue);
195 libmesh_assert_equal_to (n_rows, this->m());
200 template <
typename T>
202 const std::vector<numeric_index_type> & rows,
203 const std::vector<numeric_index_type> & cols)
207 unsigned int n_rows = cast_int<unsigned int>(rows.size());
208 unsigned int n_cols = cast_int<unsigned int>(cols.size());
209 libmesh_assert_equal_to (dm.
m(), n_rows);
210 libmesh_assert_equal_to (dm.
n(), n_cols);
213 for (
unsigned int i=0; i<n_rows; i++)
214 for (
unsigned int j=0; j<n_cols; j++)
215 this->add(rows[i],cols[j],dm(i,j));
220 template <
typename T>
223 libmesh_not_implemented();
228 template <
typename T>
231 libmesh_not_implemented();
236 template <
typename T>
245 template <
typename T>
253 template <
typename T>
269 template <
typename T>
276 auto r_start = _row_start[row];
281 libmesh_assert_equal_to (len, Q_GetLen(&_QMat, row+1));
288 libmesh_assert_equal_to ((j+1), Q_GetPos (&_QMat, row+1, l));
290 Q_SetEntry (&_QMat, row+1, l, j+1, 0.);
299 template <
typename T>
304 libmesh_not_implemented();
307 auto mat_copy = std::make_unique<LaspackMatrix<T>>(this->comm());
313 return std::unique_ptr<SparseMatrix<T>>(mat_copy.release());
318 template <
typename T>
323 auto mat_copy = this->zero_clone();
324 mat_copy->add(1., *
this);
328 return std::unique_ptr<SparseMatrix<T>>(mat_copy.release());
331 template <
typename T>
341 template <
typename T>
351 template <
typename T>
359 template <
typename T>
367 template <
typename T>
373 libmesh_assert_less (i, this->m());
374 libmesh_assert_less (j, this->n());
379 libmesh_assert_equal_to (*(_row_start[i]+position), j);
380 libmesh_assert_equal_to ((j+1), Q_GetPos (&_QMat, i+1, position));
382 Q_SetEntry (&_QMat, i+1, position, j+1, value);
387 template <
typename T>
393 libmesh_assert_less (i, this->m());
394 libmesh_assert_less (j, this->n());
399 libmesh_assert_equal_to (*(_row_start[i]+position), j);
401 Q_AddVal (&_QMat, i+1, position, value);
406 template <
typename T>
408 const std::vector<numeric_index_type> & dof_indices)
410 this->add_matrix (dm, dof_indices, dof_indices);
415 template <
typename T>
419 libmesh_assert_equal_to (this->m(), X_in.
m());
420 libmesh_assert_equal_to (this->n(), X_in.
n());
423 cast_ptr<const LaspackMatrix<T> *> (&X_in);
425 _LPNumber a =
static_cast<_LPNumber
> (a_in);
435 auto r_start = _row_start[row];
440 libmesh_assert_equal_to (len, Q_GetLen(&_QMat, row+1));
442 libmesh_assert_equal_to (len, Q_GetLen(&(X->_QMat), row+1));
450 libmesh_assert_equal_to ((j+1), Q_GetPos (&_QMat, row+1, l));
452 const _LPNumber value = a * Q_GetEl(const_cast<QMatrix*>(&(X->_QMat)), row+1, j+1);
453 Q_AddVal (&_QMat, row+1, l, value);
461 template <
typename T>
466 libmesh_assert_less (i, this->m());
467 libmesh_assert_less (j, this->n());
469 return Q_GetEl (const_cast<QMatrix*>(&_QMat), i+1, j+1);
474 template <
typename T>
478 libmesh_assert_less (i, this->m());
479 libmesh_assert_less (j, this->n());
480 libmesh_assert_less (i+1, _row_start.size());
481 libmesh_assert (_row_start.back() == _csr.end());
484 auto p = std::equal_range (_row_start[i], _row_start[i+1], j);
487 libmesh_assert (p.first != p.second);
490 libmesh_assert (*p.first == j);
493 return std::distance (_row_start[i], p.first);
498 template <
typename T>
503 this->_closed =
true;
507 *_QMat.DiagElAlloc = _LPFalse;
508 *_QMat.ElSorted = _LPFalse;
509 if (*_QMat.ILUExists)
511 *_QMat.ILUExists = _LPFalse;
525 #endif // #ifdef LIBMESH_HAVE_LASPACK
virtual std::unique_ptr< SparseMatrix< T > > zero_clone() const override
创建一个与LaspackMatrix对象具有相同属性但所有元素为零的新矩阵。 这个函数用于创建一个与原矩阵具有相同大小和属性的全零矩阵。
virtual void get_diagonal(NumericVector< T > &dest) const override
获取矩阵的对角线元素,并存储到指定的NumericVector对象中。 这个函数用于获取矩阵的对角线元素。
unsigned int n() const
返回矩阵的列维度。
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value) override
将 处的值增加 value。
这是一个通用的稀疏矩阵类。该类包含了必须在派生类中覆盖的纯虚拟成员。 使用一个公共的基类允许从不同的求解器包中以不同的格式统一访问稀疏矩阵。
virtual std::unique_ptr< SparseMatrix< T > > clone() const override
克隆LaspackMatrix对象,创建一个具有相同属性和数据的新矩阵。 这个函数用于创建一个与原矩阵具有相同大小、属性和数据的新矩阵。
virtual void get_transpose(SparseMatrix< T > &dest) const override
获取矩阵的转置,并存储到指定的SparseMatrix对象中。 这个函数用于获取矩阵的转置矩阵。
virtual void close() override
关闭LaspackMatrix对象,标记矩阵已经完成构建,不再修改其结构。 这个函数用于标记矩阵的状态为已完成构建,之后不再修改其结构。
dof_id_type numeric_index_type
bool _is_initialized
Flag that tells if init() has been called.
unsigned int m() const
返回矩阵的行维度。
virtual numeric_index_type m() const =0
virtual T operator()(const numeric_index_type i, const numeric_index_type j) const override
获取LaspackMatrix对象的指定位置 处的值。 这个函数用于获取矩阵的特定元素的值。
virtual numeric_index_type row_start() const override
返回LaspackMatrix对象的行起始位置。 这个函数用于获取矩阵的行起始位置,通常用于稀疏矩阵的索引操作。
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
初始化LaspackMatrix对象的属性,包括矩阵的行数、列数、非零元素的预估数量等。这些参数将影响矩阵的内存分配和性能。
virtual void zero() override
将LaspackMatrix对象的所有元素置零。 这个函数用于将矩阵中的所有元素设置为零。
virtual void clear() override
清空LaspackMatrix对象,释放分配的内存和资源。 这个函数用于清除矩阵的数据和状态。
virtual numeric_index_type m() const override
返回LaspackMatrix对象的行数。 这个函数用于获取矩阵的行数。
virtual numeric_index_type n() const override
返回LaspackMatrix对象的列数。 这个函数用于获取矩阵的列数。
bool initialized()
Checks that library initialization has been done.
virtual void update_sparsity_pattern(const SparsityPattern::Graph &) override
更新矩阵的稀疏性模式。这将告诉底层矩阵存储方案如何映射 元素。
virtual numeric_index_type row_stop() const override
返回LaspackMatrix对象的行结束位置。 这个函数用于获取矩阵的行结束位置,通常用于稀疏矩阵的索引操作。
LaspackMatrix类封装了Laspack库中的QMatrix对象。 目前,Laspack仅支持实数数据类型,因此这个类是对 SparseMatrix<T> 的全特化,其中 T = Real。 所...
virtual void set(const numeric_index_type i, const numeric_index_type j, const T value) override
设置LaspackMatrix对象的指定位置 处的值为 value。
定义用于有限元类型计算的密集矩阵。 用于在求和成全局矩阵之前存储单元刚度矩阵。所有被覆盖的虚函数都记录在dense_matrix_base.h中。
numeric_index_type pos(const numeric_index_type i, const numeric_index_type j) const
virtual numeric_index_type n() const =0
virtual void add_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols) override
将一个DenseMatrix对象的元素加到LaspackMatrix对象的指定行和列。
LaspackMatrix(const Parallel::Communicator &comm)
构造函数;将矩阵初始化为空,没有任何结构,即矩阵无法使用。因此,此构造函数仅适用于类的成员矩阵。 所有其他矩阵应在所有必要信息都可用的数据流的某一点创建。