20#include "libmesh/libmesh_config.h"
22#ifdef LIBMESH_TRILINOS_HAVE_EPETRA
25#include "libmesh/trilinos_epetra_matrix.h"
26#include "libmesh/trilinos_epetra_vector.h"
27#include "libmesh/dof_map.h"
28#include "libmesh/dense_matrix.h"
29#include "libmesh/parallel.h"
30#include "libmesh/sparsity_pattern.h"
31#include "libmesh/int_range.h"
51 (sparsity_pattern.size());
61 libmesh_assert_equal_to (n, m);
62 libmesh_assert_equal_to (n_l, m_l);
68 this->comm().sum (summed_m_l);
69 this->comm().sum (summed_n_l);
71 libmesh_assert_equal_to (m, summed_m_l);
72 libmesh_assert_equal_to (n, summed_n_l);
77 _map =
new Epetra_Map (
static_cast<int>(m),
80 Epetra_MpiComm (this->comm().get()));
85 const std::vector<numeric_index_type> & n_nz = this->_sp->get_n_nz();
86 const std::vector<numeric_index_type> & n_oz = this->_sp->get_n_oz();
89 libmesh_assert_equal_to (n_nz.size(), n_l);
90 libmesh_assert_equal_to (n_oz.size(), n_l);
93 std::vector<int> n_nz_tot; n_nz_tot.reserve(n_nz.size());
96 n_nz_tot.push_back(std::min(n_nz[i] + n_oz[i], n));
101 _graph =
new Epetra_CrsGraph(Copy, *_map, n_nz_tot.data());
106 _graph->InsertGlobalIndices(_graph->GRID(i),
107 cast_int<numeric_index_type>(sparsity_pattern[i].size()),
108 const_cast<int *
>(
reinterpret_cast<const int *
>(sparsity_pattern[i].data())));
110 _graph->FillComplete();
129 if ((m==0) || (n==0))
140 this->_is_initialized =
true;
146 libmesh_assert_equal_to (n, m);
147 libmesh_assert_equal_to (n_l, m_l);
153 this->comm().sum (summed_m_l);
154 this->comm().sum (summed_n_l);
156 libmesh_assert_equal_to (m, summed_m_l);
157 libmesh_assert_equal_to (n, summed_n_l);
162 _map =
new Epetra_Map (
static_cast<int>(m),
165 Epetra_MpiComm (this->comm().
get()));
167 libmesh_assert_equal_to (
static_cast<numeric_index_type>(_map->NumGlobalPoints()), m);
170 _mat =
new Epetra_FECrsMatrix (Copy, *_map, nnz + noz);
186 this->_is_initialized =
true;
190 _mat =
new Epetra_FECrsMatrix (Copy, *_graph);
210 libmesh_not_implemented();
213 auto mat_copy = std::make_unique<EpetraMatrix<T>>(this->comm());
227 auto mat_copy = this->zero_clone();
228 mat_copy->add(1., *
this);
243 this->_is_initialized =
false;
255 return static_cast<Real>(_mat->NormOne());
268 return static_cast<Real>(_mat->NormInf());
275 const std::vector<numeric_index_type> & rows,
276 const std::vector<numeric_index_type> & cols)
283 libmesh_assert_equal_to (rows.size(), m);
284 libmesh_assert_equal_to (cols.size(), n);
303 _mat->ExtractDiagonalCopy(*(epetra_dest->
vec()));
318 if (&epetra_dest !=
this)
319 libmesh_not_implemented();
329 std::vector<numeric_index_type> & indices,
330 std::vector<T> & values)
const
335 libmesh_assert_greater_equal (i, this->row_start());
336 libmesh_assert_less (i, this->row_stop());
342 _mat->ExtractMyRowView (i-this->row_start(),
347 indices.resize(row_length);
348 values.resize(row_length);
352 indices[i] = row_indices[i];
353 values[i] = row_values[i];
362 _destroy_mat_on_exit(true),
363 _use_transpose(false)
373 _destroy_mat_on_exit(false),
374 _use_transpose(false)
396 _mat->GlobalAssemble();
473 epetra_i =
static_cast<int>(i),
474 epetra_j =
static_cast<int>(j);
476 T epetra_value =
value;
479 _mat->ReplaceGlobalValues (epetra_i, 1, &epetra_value, &epetra_j);
481 _mat->InsertGlobalValues (epetra_i, 1, &epetra_value, &epetra_j);
494 epetra_i =
static_cast<int>(i),
495 epetra_j =
static_cast<int>(j);
497 T epetra_value =
value;
499 _mat->SumIntoGlobalValues (epetra_i, 1, &epetra_value, &epetra_j);
506 const std::vector<numeric_index_type> & dof_indices)
508 this->add_matrix (dm, dof_indices, dof_indices);
516#ifdef LIBMESH_TRILINOS_HAVE_EPETRAEXT
521 libmesh_assert_equal_to (this->m(), X_in.
m());
522 libmesh_assert_equal_to (this->n(), X_in.
n());
525 cast_ptr<const EpetraMatrix<T> *> (&X_in);
527 EpetraExt::MatrixMatrix::Add (*X->
_mat,
false, a_in, *_mat, 1.);
529 libmesh_error_msg(
"ERROR: EpetraExt is required for EpetraMatrix::add()!");
543 libmesh_assert_greater_equal (i, this->row_start());
544 libmesh_assert_less (i, this->row_stop());
551 _mat->ExtractMyRowView (i-this->row_start(),
558 int * index = std::lower_bound (row_indices, row_indices+row_length, j);
560 libmesh_assert_less (*index, row_length);
565 return values[*index];
577 return this->_mat->Filled();
584 std::swap(_mat, m.
_mat);
Defines a dense matrix for use in Finite Element-type computations.
std::vector< T > & get_values()
This class provides a nice interface to the Epetra data structures for parallel, sparse matrices.
virtual void close() override
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
virtual void update_sparsity_pattern(const SparsityPattern::Graph &) override
Updates the matrix sparsity pattern.
virtual numeric_index_type col_stop() const override
void swap(EpetraMatrix< T > &)
Swaps the internal data pointers, no actual values are swapped.
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 > > zero_clone() const override
virtual T operator()(const numeric_index_type i, const numeric_index_type j) const override
virtual Real linfty_norm() const override
bool _use_transpose
Epetra has no GetUseTranspose so we need to keep track of whether we're transposed manually.
virtual numeric_index_type m() 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 zero() override
Set all entries to 0.
virtual bool closed() const override
Epetra_FECrsMatrix * _mat
Actual Epetra datatype to hold matrix entries.
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 add(const numeric_index_type i, const numeric_index_type j, const T value) override
Add value to the element (i,j).
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.
virtual numeric_index_type row_start() const override
virtual void get_diagonal(NumericVector< T > &dest) const override
Copies the diagonal part of the matrix into dest.
virtual Real l1_norm() const override
virtual numeric_index_type col_start() const override
virtual numeric_index_type row_stop() const override
virtual numeric_index_type n() 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.
virtual std::unique_ptr< SparseMatrix< T > > clone() const override
EpetraMatrix(const Parallel::Communicator &comm)
Constructor; initializes the matrix to be empty, without any structure, i.e.
virtual void clear() noexcept override
clear() is called from the destructor, so it should not throw.
bool _destroy_mat_on_exit
This boolean value should only be set to false for the constructor which takes an Epetra_FECrsMatrix ...
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.
This class provides a nice interface to the Trilinos Epetra_Vector object.
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
virtual numeric_index_type n() const =0
virtual numeric_index_type m() const =0
bool _is_initialized
Flag indicating whether or not the matrix has been initialized.
const Elem & get(const ElemType type_in)
The libMesh namespace provides an interface to certain functionality in the library.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
ParallelType
Defines an enum for parallel data structure types.
dof_id_type numeric_index_type
bool initialized()
Checks that library initialization has been done.
int * numeric_trilinos_cast(const numeric_index_type *p)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...