libMesh
trilinos_epetra_matrix.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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 
19 
20 #ifndef LIBMESH_TRILINOS_EPETRA_MATRIX_H
21 #define LIBMESH_TRILINOS_EPETRA_MATRIX_H
22 
23 #include "libmesh/libmesh_common.h"
24 
25 #ifdef LIBMESH_TRILINOS_HAVE_EPETRA
26 
27 // Trilinos includes
28 #include "libmesh/ignore_warnings.h"
29 #include <Epetra_FECrsMatrix.h>
30 #include <Epetra_Map.h>
31 #include <Epetra_MpiComm.h>
32 
33 // The EpetraExt interface is only needed for EpetraMatrix::add()
34 #ifdef LIBMESH_TRILINOS_HAVE_EPETRAEXT
35 # include <EpetraExt_MatrixMatrix.h>
36 #endif
37 #include "libmesh/restore_warnings.h"
38 
39 // Local includes
40 #include "libmesh/sparse_matrix.h"
41 
42 // C++ includes
43 #include <algorithm>
44 #include <cstddef>
45 
46 namespace libMesh
47 {
48 
49 // Forward Declarations
50 template <typename T> class DenseMatrix;
51 
52 
53 
62 template <typename T>
63 class EpetraMatrix final : public SparseMatrix<T>
64 {
65 public:
76  EpetraMatrix (const Parallel::Communicator & comm);
77 
86  EpetraMatrix (Epetra_FECrsMatrix * m,
87  const Parallel::Communicator & comm);
88 
94  EpetraMatrix (EpetraMatrix &&) = delete;
95  EpetraMatrix (const EpetraMatrix &) = delete;
96  EpetraMatrix & operator= (const EpetraMatrix &) = delete;
97  EpetraMatrix & operator= (EpetraMatrix &&) = delete;
98  virtual ~EpetraMatrix ();
99 
103  virtual bool need_full_sparsity_pattern () const override
104  { return true; }
105 
111  virtual void update_sparsity_pattern (const SparsityPattern::Graph &) override;
112 
113  virtual void init (const numeric_index_type m,
114  const numeric_index_type n,
115  const numeric_index_type m_l,
116  const numeric_index_type n_l,
117  const numeric_index_type nnz=30,
118  const numeric_index_type noz=10,
119  const numeric_index_type blocksize=1) override;
120 
121  virtual void init () override;
122 
123  virtual void clear () override;
124 
125  virtual void zero () override;
126 
127  virtual void close () override;
128 
129  virtual numeric_index_type m () const override;
130 
131  virtual numeric_index_type n () const override;
132 
133  virtual numeric_index_type row_start () const override;
134 
135  virtual numeric_index_type row_stop () const override;
136 
137  virtual void set (const numeric_index_type i,
138  const numeric_index_type j,
139  const T value) override;
140 
141  virtual void add (const numeric_index_type i,
142  const numeric_index_type j,
143  const T value) override;
144 
145  virtual void add_matrix (const DenseMatrix<T> & dm,
146  const std::vector<numeric_index_type> & rows,
147  const std::vector<numeric_index_type> & cols) override;
148 
149  virtual void add_matrix (const DenseMatrix<T> & dm,
150  const std::vector<numeric_index_type> & dof_indices) override;
151 
162  virtual void add (const T a, const SparseMatrix<T> & X) override;
163 
164  virtual T operator () (const numeric_index_type i,
165  const numeric_index_type j) const override;
166 
167  virtual Real l1_norm () const override;
168 
169  virtual Real linfty_norm () const override;
170 
171  virtual bool closed() const override;
172 
173  virtual void print_personal(std::ostream & os=libMesh::out) const override;
174 
175  virtual void get_diagonal (NumericVector<T> & dest) const override;
176 
177  virtual void get_transpose (SparseMatrix<T> & dest) const override;
178 
182  void swap (EpetraMatrix<T> &);
183 
192  Epetra_FECrsMatrix * mat () { libmesh_assert(_mat); return _mat; }
193 
194  const Epetra_FECrsMatrix * mat () const { libmesh_assert(_mat); return _mat; }
195 
196 
197 private:
198 
202  Epetra_FECrsMatrix * _mat;
203 
207  Epetra_Map * _map;
208 
212  Epetra_CrsGraph * _graph;
213 
219 
225 };
226 
227 } // namespace libMesh
228 
229 #endif // LIBMESH_TRILINOS_HAVE_EPETRA
230 #endif // LIBMESH_TRILINOS_EPETRA_MATRIX_H
libMesh::EpetraMatrix::init
virtual void init() override
Initialize this matrix using the sparsity structure computed by dof_map.
Definition: trilinos_epetra_matrix.C:177
libMesh::EpetraMatrix::_mat
Epetra_FECrsMatrix * _mat
Actual Epetra datatype to hold matrix entries.
Definition: trilinos_epetra_matrix.h:202
libMesh::EpetraMatrix::mat
const Epetra_FECrsMatrix * mat() const
Definition: trilinos_epetra_matrix.h:194
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::EpetraMatrix::set
virtual void set(const numeric_index_type i, const numeric_index_type j, const T value) override
Set the element (i,j) to value.
Definition: trilinos_epetra_matrix.C:382
libMesh::ParallelObject::comm
const Parallel::Communicator & comm() const
Definition: parallel_object.h:94
libMesh::DenseMatrix
Defines a dense matrix for use in Finite Element-type computations.
Definition: dof_map.h:73
libMesh::EpetraMatrix::~EpetraMatrix
virtual ~EpetraMatrix()
Definition: trilinos_epetra_matrix.C:322
libMesh::EpetraMatrix::row_stop
virtual numeric_index_type row_stop() const override
Definition: trilinos_epetra_matrix.C:371
libMesh::EpetraMatrix::linfty_norm
virtual Real linfty_norm() const override
Definition: trilinos_epetra_matrix.C:231
libMesh::EpetraMatrix::get_transpose
virtual void get_transpose(SparseMatrix< T > &dest) const override
Copies the transpose of the matrix into dest, which may be *this.
Definition: trilinos_epetra_matrix.C:279
libMesh::SparseMatrix
Generic sparse matrix.
Definition: vector_fe_ex5.C:45
libMesh::NumericVector
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
Definition: vector_fe_ex5.C:43
libMesh::EpetraMatrix::_map
Epetra_Map * _map
Holds the distributed Map.
Definition: trilinos_epetra_matrix.h:207
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::EpetraMatrix::close
virtual void close() override
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
Definition: trilinos_epetra_matrix.C:330
libMesh::EpetraMatrix::EpetraMatrix
EpetraMatrix(const Parallel::Communicator &comm)
Constructor; initializes the matrix to be empty, without any structure, i.e.
Definition: trilinos_epetra_matrix.C:298
libMesh::EpetraMatrix
This class provides a nice interface to the Epetra data structures for parallel, sparse matrices.
Definition: trilinos_epetra_matrix.h:63
libMesh::EpetraMatrix::_use_transpose
bool _use_transpose
Epetra has no GetUseTranspose so we need to keep track of whether we're transposed manually.
Definition: trilinos_epetra_matrix.h:224
libMesh::EpetraMatrix::row_start
virtual numeric_index_type row_start() const override
Definition: trilinos_epetra_matrix.C:360
libMesh::EpetraMatrix::m
virtual numeric_index_type m() const override
Definition: trilinos_epetra_matrix.C:340
libMesh::EpetraMatrix::closed
virtual bool closed() const override
Definition: trilinos_epetra_matrix.C:488
libMesh::EpetraMatrix::mat
Epetra_FECrsMatrix * mat()
Definition: trilinos_epetra_matrix.h:192
libMesh::numeric_index_type
dof_id_type numeric_index_type
Definition: id_types.h:99
libMesh::EpetraMatrix::zero
virtual void zero() override
Set all entries to 0.
Definition: trilinos_epetra_matrix.C:196
libMesh::EpetraMatrix::update_sparsity_pattern
virtual void update_sparsity_pattern(const SparsityPattern::Graph &) override
Updates the matrix sparsity pattern.
Definition: trilinos_epetra_matrix.C:42
libMesh::EpetraMatrix::_graph
Epetra_CrsGraph * _graph
Holds the sparsity pattern.
Definition: trilinos_epetra_matrix.h:212
value
static const bool value
Definition: xdr_io.C:56
libMesh::EpetraMatrix::n
virtual numeric_index_type n() const override
Definition: trilinos_epetra_matrix.C:350
libMesh::EpetraMatrix::need_full_sparsity_pattern
virtual bool need_full_sparsity_pattern() const override
The EpetraMatrix needs the full sparsity pattern.
Definition: trilinos_epetra_matrix.h:103
libMesh::EpetraMatrix::add
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value) override
Add value to the element (i,j).
Definition: trilinos_epetra_matrix.C:403
libMesh::EpetraMatrix::clear
virtual void clear() override
Restores the SparseMatrix<T> to a pristine state.
Definition: trilinos_epetra_matrix.C:206
libMesh::EpetraMatrix::add_matrix
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.
Definition: trilinos_epetra_matrix.C:244
libMesh::EpetraMatrix::get_diagonal
virtual void get_diagonal(NumericVector< T > &dest) const override
Copies the diagonal part of the matrix into dest.
Definition: trilinos_epetra_matrix.C:267
libMesh::EpetraMatrix::swap
void swap(EpetraMatrix< T > &)
Swaps the internal data pointers, no actual values are swapped.
Definition: trilinos_epetra_matrix.C:498
libMesh::EpetraMatrix::operator=
EpetraMatrix & operator=(const EpetraMatrix &)=delete
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::EpetraMatrix::print_personal
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.
Definition: trilinos_epetra_matrix.C:509
libMesh::EpetraMatrix::l1_norm
virtual Real l1_norm() const override
Definition: trilinos_epetra_matrix.C:219
libMesh::out
OStreamProxy out
libMesh::SparsityPattern::Graph
Definition: sparsity_pattern.h:52
libMesh::EpetraMatrix::_destroy_mat_on_exit
bool _destroy_mat_on_exit
This boolean value should only be set to false for the constructor which takes an Epetra_FECrsMatrix ...
Definition: trilinos_epetra_matrix.h:218
libMesh::EpetraMatrix::operator()
virtual T operator()(const numeric_index_type i, const numeric_index_type j) const override
Definition: trilinos_epetra_matrix.C:453