23 #include "libmesh/libmesh_config.h"
25 #ifdef LIBMESH_HAVE_LASPACK
27 #include "libmesh/laspack_matrix.h"
28 #include "libmesh/dense_matrix.h"
29 #include "libmesh/dof_map.h"
30 #include "libmesh/sparsity_pattern.h"
55 size += sparsity_pattern[row].size();
58 _row_start.reserve(n_rows + 1);
64 std::vector<numeric_index_type>::iterator position = _csr.begin();
66 _row_start.push_back (position);
71 for (
const auto & col : sparsity_pattern[row])
78 _row_start.push_back (position);
89 libmesh_assert_equal_to (n_rows, this->m());
95 auto rs = _row_start[i];
99 Q_SetLen (&_QMat, i+1, length);
113 libmesh_assert_equal_to (this->pos(i,j), l);
114 Q_SetEntry (&_QMat, i+1, l, j+1, 0.);
124 template <
typename T>
134 libmesh_assert_equal_to (m_in, m_l);
135 libmesh_assert_equal_to (n_in, n_l);
136 libmesh_assert_equal_to (m_in, n_in);
137 libmesh_assert_greater (nnz, 0);
139 libmesh_error_msg(
"ERROR: Only the init() member that uses the DofMap is implemented for Laspack matrices!");
146 template <
typename T>
170 libmesh_assert_equal_to (n_rows, n_cols);
171 libmesh_assert_equal_to (m_l, n_rows);
172 libmesh_assert_equal_to (n_l, n_cols);
177 const std::vector<numeric_index_type> & n_nz = this->_dof_map->get_n_nz();
178 const std::vector<numeric_index_type> & n_oz = this->_dof_map->get_n_oz();
182 libmesh_assert_equal_to (n_nz.size(), n_l);
183 libmesh_assert_equal_to (n_oz.size(), n_l);
188 Q_Constr(&_QMat, const_cast<char *>(
"Mat"), n_rows, _LPFalse, Rowws, Normal, _LPTrue);
192 libmesh_assert_equal_to (n_rows, this->m());
197 template <
typename T>
199 const std::vector<numeric_index_type> & rows,
200 const std::vector<numeric_index_type> & cols)
204 unsigned int n_rows = cast_int<unsigned int>(rows.size());
205 unsigned int n_cols = cast_int<unsigned int>(cols.size());
206 libmesh_assert_equal_to (dm.
m(), n_rows);
207 libmesh_assert_equal_to (dm.
n(), n_cols);
210 for (
unsigned int i=0; i<n_rows; i++)
211 for (
unsigned int j=0; j<n_cols; j++)
212 this->add(rows[i],cols[j],dm(i,j));
217 template <
typename T>
220 libmesh_not_implemented();
225 template <
typename T>
228 libmesh_not_implemented();
233 template <
typename T>
242 template <
typename T>
250 template <
typename T>
266 template <
typename T>
273 auto r_start = _row_start[row];
278 libmesh_assert_equal_to (len, Q_GetLen(&_QMat, row+1));
285 libmesh_assert_equal_to ((j+1), Q_GetPos (&_QMat, row+1, l));
287 Q_SetEntry (&_QMat, row+1, l, j+1, 0.);
296 template <
typename T>
301 return static_cast<numeric_index_type>(Q_GetDim(const_cast<QMatrix*>(&_QMat)));
306 template <
typename T>
311 return static_cast<numeric_index_type>(Q_GetDim(const_cast<QMatrix*>(&_QMat)));
316 template <
typename T>
324 template <
typename T>
332 template <
typename T>
338 libmesh_assert_less (i, this->m());
339 libmesh_assert_less (j, this->n());
344 libmesh_assert_equal_to (*(_row_start[i]+position), j);
345 libmesh_assert_equal_to ((j+1), Q_GetPos (&_QMat, i+1, position));
347 Q_SetEntry (&_QMat, i+1, position, j+1,
value);
352 template <
typename T>
358 libmesh_assert_less (i, this->m());
359 libmesh_assert_less (j, this->n());
364 libmesh_assert_equal_to (*(_row_start[i]+position), j);
366 Q_AddVal (&_QMat, i+1, position,
value);
371 template <
typename T>
373 const std::vector<numeric_index_type> & dof_indices)
375 this->add_matrix (dm, dof_indices, dof_indices);
380 template <
typename T>
384 libmesh_assert_equal_to (this->m(), X_in.
m());
385 libmesh_assert_equal_to (this->n(), X_in.
n());
388 cast_ptr<const LaspackMatrix<T> *> (&X_in);
390 _LPNumber a = static_cast<_LPNumber> (a_in);
400 auto r_start = _row_start[row];
405 libmesh_assert_equal_to (len, Q_GetLen(&_QMat, row+1));
407 libmesh_assert_equal_to (len, Q_GetLen(&(X->_QMat), row+1));
415 libmesh_assert_equal_to ((j+1), Q_GetPos (&_QMat, row+1, l));
417 const _LPNumber
value = a * Q_GetEl(const_cast<QMatrix*>(&(X->_QMat)), row+1, j+1);
418 Q_AddVal (&_QMat, row+1, l,
value);
426 template <
typename T>
431 libmesh_assert_less (i, this->m());
432 libmesh_assert_less (j, this->n());
434 return Q_GetEl (const_cast<QMatrix*>(&_QMat), i+1, j+1);
439 template <
typename T>
443 libmesh_assert_less (i, this->m());
444 libmesh_assert_less (j, this->n());
445 libmesh_assert_less (i+1, _row_start.size());
449 auto p = std::equal_range (_row_start[i], _row_start[i+1], j);
463 template <
typename T>
468 this->_closed =
true;
472 *_QMat.DiagElAlloc = _LPFalse;
473 *_QMat.ElSorted = _LPFalse;
474 if (*_QMat.ILUExists)
476 *_QMat.ILUExists = _LPFalse;
490 #endif // #ifdef LIBMESH_HAVE_LASPACK