18 #include "libmesh/diagonal_matrix.h" 19 #include "libmesh/numeric_vector.h" 20 #include "libmesh/dense_matrix.h" 21 #include "libmesh/dof_map.h" 22 #include "libmesh/libmesh_common.h" 68 _diagonal->init(m, m_l);
77 _diagonal->init(this->_dof_map->n_dofs(),
78 this->_dof_map->n_local_dofs(),
87 _diagonal->init(other, fast);
104 template <
typename T>
111 template <
typename T>
115 auto mat_copy = std::make_unique<DiagonalMatrix<T>>(this->comm());
119 mat_copy->init(*
this,
false);
126 template <
typename T>
130 auto mat_copy = std::make_unique<DiagonalMatrix<T>>(this->comm());
133 auto diag_copy = _diagonal->clone();
136 *mat_copy = std::move(*diag_copy);
141 template <
typename T>
148 template <
typename T>
152 return _diagonal->size();
155 template <
typename T>
159 return _diagonal->size();
162 template <
typename T>
166 return _diagonal->first_local_index();
169 template <
typename T>
173 return _diagonal->last_local_index();
176 template <
typename T>
180 return _diagonal->first_local_index();
183 template <
typename T>
187 return _diagonal->last_local_index();
190 template <
typename T>
195 _diagonal->set(i,
value);
198 template <
typename T>
203 _diagonal->add(i,
value);
206 template <
typename T>
209 const std::vector<numeric_index_type> & rows,
210 const std::vector<numeric_index_type> & cols)
215 for (decltype(m) i = 0; i < m; ++i)
216 for (decltype(n) j = 0; j < n; ++j)
218 auto global_i = rows[i];
219 auto global_j = cols[j];
220 if (global_i == global_j)
221 _diagonal->add(global_i, dm(i, j));
225 template <
typename T>
228 const std::vector<numeric_index_type> & dof_indices)
230 _diagonal->add_vector(dm.
diagonal(), dof_indices);
233 template <
typename T>
237 auto x_diagonal = _diagonal->zero_clone();
239 _diagonal->add(a, *x_diagonal);
242 template <
typename T>
247 return (*_diagonal)(i);
252 template <
typename T>
256 return _diagonal->l1_norm();
259 template <
typename T>
263 return _diagonal->linfty_norm();
266 template <
typename T>
270 return _diagonal->closed();
273 template <
typename T>
277 _diagonal->print(os);
282 template <
typename T>
291 template <
typename T>
297 *diagonal_dest = *_diagonal;
299 libmesh_error_msg(
"DenseMatrix<T>::get_transpose currently only accepts another DenseMatrix<T> " 305 template <
typename T>
308 std::vector<numeric_index_type> & indices,
309 std::vector<T> & values)
const 312 indices.push_back(i);
314 values.push_back((*_diagonal)(i));
319 template <
typename T>
323 for (
auto row : rows)
324 _diagonal->set(row, val);
327 template <
typename T>
334 template <
typename T>
virtual numeric_index_type col_stop() const override
virtual void get_transpose(SparseMatrix< T > &dest) const override
Copies the transpose of the matrix into dest, which may be *this.
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.
const NumericVector< T > & diagonal() const
DenseVector< T > diagonal() const
Return the matrix diagonal.
virtual numeric_index_type col_start() const override
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
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.
The libMesh namespace provides an interface to certain functionality in the library.
virtual void restore_original_nonzero_pattern() override
Reset the memory storage of the matrix.
virtual void zero() override
Set all entries to 0.
virtual bool closed() const override
virtual numeric_index_type n() const override
virtual numeric_index_type m() const override
virtual void close() override
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
dof_id_type numeric_index_type
virtual numeric_index_type row_stop() const override
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
virtual void clear() override
Restores the SparseMatrix<T> to a pristine state.
virtual void get_diagonal(NumericVector< T > &dest) const =0
Copies the diagonal part of the matrix into dest.
DiagonalMatrix(const Parallel::Communicator &comm)
Constructor; initializes the matrix to be empty, without any structure, i.e.
virtual T operator()(const numeric_index_type i, const numeric_index_type j) const override
Diagonal matrix class whose underlying storage is a vector.
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 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.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void get_diagonal(NumericVector< T > &dest) const override
Copies the diagonal part of the matrix into dest.
virtual Real linfty_norm() const override
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, SolverPackage solver_package=libMesh::default_solver_package(), ParallelType parallel_type=AUTOMATIC)
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
DiagonalMatrix & operator=(DiagonalMatrix &&)=default
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 std::unique_ptr< SparseMatrix< T > > clone() const override
virtual numeric_index_type row_start() const override
std::unique_ptr< NumericVector< T > > _diagonal
Underlying diagonal matrix storage.
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.
Defines a dense matrix for use in Finite Element-type computations.
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
ParallelType
Defines an enum for parallel data structure types.