libMesh::PetscMatrix< T > Class Template Reference

SparseMatrix interface to PETSc Mat. More...

#include <petsc_linear_solver.h>

Inheritance diagram for libMesh::PetscMatrix< T >:

Public Member Functions

 PetscMatrix (const Parallel::Communicator &comm_in LIBMESH_CAN_DEFAULT_TO_COMMWORLD)
 
 PetscMatrix (Mat m, const Parallel::Communicator &comm_in LIBMESH_CAN_DEFAULT_TO_COMMWORLD)
 
 ~PetscMatrix ()
 
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) libmesh_override
 
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 std::vector< numeric_index_type > &n_nz, const std::vector< numeric_index_type > &n_oz, const numeric_index_type blocksize=1)
 
virtual void init () libmesh_override
 
void update_preallocation_and_zero ()
 
virtual void clear () libmesh_override
 
virtual void zero () libmesh_override
 
virtual void zero_rows (std::vector< numeric_index_type > &rows, T diag_value=0.0) libmesh_override
 
virtual void close () const libmesh_override
 
virtual numeric_index_type m () const libmesh_override
 
virtual numeric_index_type n () const libmesh_override
 
virtual numeric_index_type row_start () const libmesh_override
 
virtual numeric_index_type row_stop () const libmesh_override
 
virtual void set (const numeric_index_type i, const numeric_index_type j, const T value) libmesh_override
 
virtual void add (const numeric_index_type i, const numeric_index_type j, const T value) libmesh_override
 
virtual void add_matrix (const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols) libmesh_override
 
virtual void add_matrix (const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &dof_indices) libmesh_override
 
virtual void add_block_matrix (const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &brows, const std::vector< numeric_index_type > &bcols) libmesh_override
 
virtual void add_block_matrix (const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &dof_indices) libmesh_override
 
virtual void add (const T a, SparseMatrix< T > &X) libmesh_override
 
virtual T operator() (const numeric_index_type i, const numeric_index_type j) const libmesh_override
 
virtual Real l1_norm () const libmesh_override
 
virtual Real linfty_norm () const libmesh_override
 
virtual bool closed () const libmesh_override
 
virtual void print_personal (std::ostream &os=libMesh::out) const libmesh_override
 
virtual void print_matlab (const std::string &name="") const libmesh_override
 
virtual void get_diagonal (NumericVector< T > &dest) const libmesh_override
 
virtual void get_transpose (SparseMatrix< T > &dest) const libmesh_override
 
void swap (PetscMatrix< T > &)
 
Mat mat ()
 
virtual bool initialized () const
 
void attach_dof_map (const DofMap &dof_map)
 
virtual bool need_full_sparsity_pattern () const
 
virtual void update_sparsity_pattern (const SparsityPattern::Graph &)
 
void print (std::ostream &os=libMesh::out, const bool sparse=false) const
 
template<>
void print (std::ostream &os, const bool sparse) const
 
virtual void create_submatrix (SparseMatrix< T > &submatrix, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols) const
 
virtual void reinit_submatrix (SparseMatrix< T > &submatrix, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols) const
 
void vector_mult (NumericVector< T > &dest, const NumericVector< T > &arg) const
 
void vector_mult_add (NumericVector< T > &dest, const NumericVector< T > &arg) const
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static UniquePtr< SparseMatrix< T > > build (const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
 
static std::string get_info ()
 
static void print_info (std::ostream &out=libMesh::out)
 
static unsigned int n_objects ()
 
static void enable_print_counter_info ()
 
static void disable_print_counter_info ()
 

Protected Types

typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
 

Protected Member Functions

virtual void _get_submatrix (SparseMatrix< T > &submatrix, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols, const bool reuse_submatrix) const libmesh_override
 
void increment_constructor_count (const std::string &name)
 
void increment_destructor_count (const std::string &name)
 

Protected Attributes

DofMap const * _dof_map
 
bool _is_initialized
 
const Parallel::Communicator_communicator
 

Static Protected Attributes

static Counts _counts
 
static Threads::atomic< unsigned int > _n_objects
 
static Threads::spin_mutex _mutex
 
static bool _enable_print_counter = true
 

Private Attributes

Mat _mat
 
bool _destroy_mat_on_exit
 

Detailed Description

template<typename T>
class libMesh::PetscMatrix< T >

SparseMatrix interface to PETSc Mat.

Petsc matrix. Provides a nice interface to the Petsc C-based data structures for parallel, sparse matrices.

Author
Benjamin S. Kirk
Date
2002

Definition at line 71 of file petsc_linear_solver.h.

Member Typedef Documentation

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > libMesh::ReferenceCounter::Counts
protectedinherited

Data structure to log the information. The log is identified by the class name.

Definition at line 110 of file reference_counter.h.

Constructor & Destructor Documentation

template<typename T>
libMesh::PetscMatrix< T >::PetscMatrix ( const Parallel::Communicator &comm_in  LIBMESH_CAN_DEFAULT_TO_COMMWORLD)
explicit

Constructor; initializes the matrix to be empty, without any structure, i.e. the matrix is not usable at all. This constructor is therefore only useful for matrices which are members of a class. All other matrices should be created at a point in the data flow where all necessary information is available.

You have to initialize the matrix before usage with init(...).

template<typename T>
libMesh::PetscMatrix< T >::PetscMatrix ( Mat  m,
const Parallel::Communicator &comm_in  LIBMESH_CAN_DEFAULT_TO_COMMWORLD 
)
explicit

Constructor. Creates a PetscMatrix assuming you already have a valid Mat object. In this case, m is NOT destroyed by the PetscMatrix destructor when this object goes out of scope. This allows ownership of m to remain with the original creator, and to simply provide additional functionality with the PetscMatrix.

template<typename T >
libMesh::PetscMatrix< T >::~PetscMatrix ( )

Destructor. Free all memory, but do not release the memory of the sparsity structure.

Definition at line 113 of file petsc_matrix.C.

114 {
115  this->clear();
116 }
virtual void clear() libmesh_override
Definition: petsc_matrix.C:466

Member Function Documentation

template<typename T >
void libMesh::PetscMatrix< T >::_get_submatrix ( SparseMatrix< T > &  submatrix,
const std::vector< numeric_index_type > &  rows,
const std::vector< numeric_index_type > &  cols,
const bool  reuse_submatrix 
) const
protectedvirtual

This function either creates or re-initializes a matrix called "submatrix" which is defined by the row and column indices given in the "rows" and "cols" entries. This function is implemented in terms of the MatGetSubMatrix() routine of PETSc. The boolean reuse_submatrix parameter determines whether or not PETSc will treat "submatrix" as one which has already been used (had memory allocated) or as a new matrix.

Reimplemented from libMesh::SparseMatrix< T >.

Definition at line 778 of file petsc_matrix.C.

References libMesh::SparseMatrix< T >::_is_initialized, libMesh::PetscMatrix< T >::_mat, libMesh::SparseMatrix< T >::clear(), libMesh::PetscMatrix< T >::close(), ierr, libMesh::SparseMatrix< T >::initialized(), libMesh::numeric_petsc_cast(), and PETSC_USE_POINTER.

Referenced by libMesh::PetscMatrix< T >::mat().

782 {
783  // Can only extract submatrices from closed matrices
784  this->close();
785 
786  // Make sure the SparseMatrix passed in is really a PetscMatrix
787  PetscMatrix<T> * petsc_submatrix = cast_ptr<PetscMatrix<T> *>(&submatrix);
788 
789  // If we're not reusing submatrix and submatrix is already initialized
790  // then we need to clear it, otherwise we get a memory leak.
791  if( !reuse_submatrix && submatrix.initialized() )
792  submatrix.clear();
793 
794  // Construct row and column index sets.
795  PetscErrorCode ierr=0;
796  IS isrow, iscol;
797 
798  ierr = ISCreateLibMesh(this->comm().get(),
799  rows.size(),
800  numeric_petsc_cast(&rows[0]),
802  &isrow); LIBMESH_CHKERR(ierr);
803 
804  ierr = ISCreateLibMesh(this->comm().get(),
805  cols.size(),
806  numeric_petsc_cast(&cols[0]),
808  &iscol); LIBMESH_CHKERR(ierr);
809 
810  // Extract submatrix
811  ierr = MatGetSubMatrix(_mat,
812  isrow,
813  iscol,
814 #if PETSC_RELEASE_LESS_THAN(3,0,1)
815  PETSC_DECIDE,
816 #endif
817  (reuse_submatrix ? MAT_REUSE_MATRIX : MAT_INITIAL_MATRIX),
818  &(petsc_submatrix->_mat)); LIBMESH_CHKERR(ierr);
819 
820  // Specify that the new submatrix is initialized and close it.
821  petsc_submatrix->_is_initialized = true;
822  petsc_submatrix->close();
823 
824  // Clean up PETSc data structures
825  ierr = LibMeshISDestroy(&isrow); LIBMESH_CHKERR(ierr);
826  ierr = LibMeshISDestroy(&iscol); LIBMESH_CHKERR(ierr);
827 }
unsigned int size() const
Definition: parallel.h:679
virtual void close() const libmesh_override
Definition: petsc_matrix.C:881
virtual void clear()=0
PetscInt * numeric_petsc_cast(const numeric_index_type *p)
virtual bool initialized() const
PetscErrorCode ierr
const Parallel::Communicator & comm() const
SparseMatrix interface to PETSc Mat.
template<typename T >
void libMesh::PetscMatrix< T >::add ( const numeric_index_type  i,
const numeric_index_type  j,
const T  value 
)
virtual

Add value to the element (i,j). Throws an error if the entry does not exist. Still, it is allowed to store zero values in non-existent fields.

Implements libMesh::SparseMatrix< T >.

Definition at line 985 of file petsc_matrix.C.

References ierr, libMesh::initialized(), and libMesh::libmesh_assert().

Referenced by libMesh::PetscMatrix< T >::add_block_matrix().

988 {
989  libmesh_assert (this->initialized());
990 
991  PetscErrorCode ierr=0;
992  PetscInt i_val=i, j_val=j;
993 
994  PetscScalar petsc_value = static_cast<PetscScalar>(value);
995  ierr = MatSetValues(_mat, 1, &i_val, 1, &j_val,
996  &petsc_value, ADD_VALUES);
997  LIBMESH_CHKERR(ierr);
998 }
libmesh_assert(j)
virtual bool initialized() const
PetscErrorCode ierr
template<typename T >
void libMesh::PetscMatrix< T >::add ( const T  a,
SparseMatrix< T > &  X 
)
virtual

Add a Sparse matrix X, scaled with a, to this, stores the result in this: $\texttt{this} = a*X + \texttt{this} $. Use this with caution, the sparse matrices need to have the same nonzero pattern, otherwise PETSc will crash! It is advisable to not only allocate appropriate memory with init() , but also explicitly zero the terms of this whenever you add a non-zero value to X. Note: X will be closed, if not already done, before performing any work.

Implements libMesh::SparseMatrix< T >.

Definition at line 1016 of file petsc_matrix.C.

References libMesh::PetscMatrix< T >::_mat, libMesh::PetscMatrix< T >::closed(), ierr, libMesh::initialized(), libMesh::libmesh_assert(), libMesh::SparseMatrix< T >::m(), and libMesh::SparseMatrix< T >::n().

1017 {
1018  libmesh_assert (this->initialized());
1019 
1020  // sanity check. but this cannot avoid
1021  // crash due to incompatible sparsity structure...
1022  libmesh_assert_equal_to (this->m(), X_in.m());
1023  libmesh_assert_equal_to (this->n(), X_in.n());
1024 
1025  PetscScalar a = static_cast<PetscScalar> (a_in);
1026  PetscMatrix<T> * X = cast_ptr<PetscMatrix<T> *> (&X_in);
1027 
1028  libmesh_assert (X);
1029 
1030  PetscErrorCode ierr=0;
1031 
1032  // the matrix from which we copy the values has to be assembled/closed
1033  libmesh_assert(X->closed());
1034 
1035  semiparallel_only();
1036 
1037  ierr = MatAXPY(_mat, a, X->_mat, DIFFERENT_NONZERO_PATTERN);
1038  LIBMESH_CHKERR(ierr);
1039 }
virtual numeric_index_type m() const libmesh_override
Definition: petsc_matrix.C:903
virtual bool closed() const libmesh_override
libmesh_assert(j)
virtual bool initialized() const
virtual numeric_index_type n() const libmesh_override
Definition: petsc_matrix.C:919
PetscErrorCode ierr
SparseMatrix interface to PETSc Mat.
template<typename T >
void libMesh::PetscMatrix< T >::add_block_matrix ( const DenseMatrix< T > &  dm,
const std::vector< numeric_index_type > &  brows,
const std::vector< numeric_index_type > &  bcols 
)
virtual

Add the full matrix dm to the Sparse matrix. This is useful for adding an element matrix at assembly time. The matrix is assumed blocked, and brow, bcol correspond to the block row, columm indices.

Reimplemented from libMesh::SparseMatrix< T >.

Definition at line 734 of file petsc_matrix.C.

References libMesh::DenseMatrix< T >::get_values(), ierr, libMesh::initialized(), libMesh::libmesh_assert(), libMesh::DenseMatrixBase< T >::m(), libMesh::DenseMatrixBase< T >::n(), and libMesh::numeric_petsc_cast().

Referenced by libMesh::PetscMatrix< T >::add_block_matrix().

737 {
738  libmesh_assert (this->initialized());
739 
740  const numeric_index_type n_brows =
741  cast_int<numeric_index_type>(brows.size());
742  const numeric_index_type n_bcols =
743  cast_int<numeric_index_type>(bcols.size());
744 
745  PetscErrorCode ierr=0;
746 
747 #ifndef NDEBUG
748  const numeric_index_type n_rows =
749  cast_int<numeric_index_type>(dm.m());
750  const numeric_index_type n_cols =
751  cast_int<numeric_index_type>(dm.n());
752  const numeric_index_type blocksize = n_rows / n_brows;
753 
754  libmesh_assert_equal_to (n_cols / n_bcols, blocksize);
755  libmesh_assert_equal_to (blocksize*n_brows, n_rows);
756  libmesh_assert_equal_to (blocksize*n_bcols, n_cols);
757 
758  PetscInt petsc_blocksize;
759  ierr = MatGetBlockSize(_mat, &petsc_blocksize);
760  LIBMESH_CHKERR(ierr);
761  libmesh_assert_equal_to (blocksize, static_cast<numeric_index_type>(petsc_blocksize));
762 #endif
763 
764  // These casts are required for PETSc <= 2.1.5
765  ierr = MatSetValuesBlocked(_mat,
766  n_brows, numeric_petsc_cast(&brows[0]),
767  n_bcols, numeric_petsc_cast(&bcols[0]),
768  const_cast<PetscScalar *>(&dm.get_values()[0]),
769  ADD_VALUES);
770  LIBMESH_CHKERR(ierr);
771 }
unsigned int n() const
libmesh_assert(j)
PetscInt * numeric_petsc_cast(const numeric_index_type *p)
virtual bool initialized() const
dof_id_type numeric_index_type
Definition: id_types.h:92
unsigned int m() const
std::vector< T > & get_values()
Definition: dense_matrix.h:338
PetscErrorCode ierr
template<typename T>
virtual void libMesh::PetscMatrix< T >::add_block_matrix ( const DenseMatrix< T > &  dm,
const std::vector< numeric_index_type > &  dof_indices 
)
inlinevirtual

Same as add_block_matrix , but assumes the row and column maps are the same. Thus the matrix dm must be square.

Reimplemented from libMesh::SparseMatrix< T >.

Definition at line 267 of file petsc_matrix.h.

References libMesh::PetscMatrix< T >::add(), libMesh::PetscMatrix< T >::add_block_matrix(), libMesh::PetscMatrix< T >::closed(), libMesh::PetscMatrix< T >::get_diagonal(), libMesh::PetscMatrix< T >::get_transpose(), libMesh::PetscMatrix< T >::l1_norm(), libMesh::PetscMatrix< T >::linfty_norm(), libMesh::Quality::name(), libMesh::PetscMatrix< T >::operator()(), libMesh::out, libMesh::PetscMatrix< T >::print_matlab(), libMesh::PetscMatrix< T >::print_personal(), libMesh::Real, and libMesh::PetscMatrix< T >::swap().

269  { this->add_block_matrix (dm, dof_indices, dof_indices); }
virtual void add_block_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &brows, const std::vector< numeric_index_type > &bcols) libmesh_override
Definition: petsc_matrix.C:734
template<typename T >
void libMesh::PetscMatrix< T >::add_matrix ( const DenseMatrix< T > &  dm,
const std::vector< numeric_index_type > &  rows,
const std::vector< numeric_index_type > &  cols 
)
virtual

Add the full matrix to the Petsc matrix. This is useful for adding an element matrix at assembly time

Implements libMesh::SparseMatrix< T >.

Definition at line 705 of file petsc_matrix.C.

References libMesh::DenseMatrix< T >::get_values(), ierr, libMesh::initialized(), libMesh::libmesh_assert(), libMesh::DenseMatrixBase< T >::m(), libMesh::DenseMatrixBase< T >::n(), and libMesh::numeric_petsc_cast().

708 {
709  libmesh_assert (this->initialized());
710 
711  const numeric_index_type n_rows = dm.m();
712  const numeric_index_type n_cols = dm.n();
713 
714  libmesh_assert_equal_to (rows.size(), n_rows);
715  libmesh_assert_equal_to (cols.size(), n_cols);
716 
717  PetscErrorCode ierr=0;
718 
719  // These casts are required for PETSc <= 2.1.5
720  ierr = MatSetValues(_mat,
721  n_rows, numeric_petsc_cast(&rows[0]),
722  n_cols, numeric_petsc_cast(&cols[0]),
723  const_cast<PetscScalar *>(&dm.get_values()[0]),
724  ADD_VALUES);
725  LIBMESH_CHKERR(ierr);
726 }
unsigned int n() const
libmesh_assert(j)
PetscInt * numeric_petsc_cast(const numeric_index_type *p)
virtual bool initialized() const
dof_id_type numeric_index_type
Definition: id_types.h:92
unsigned int m() const
std::vector< T > & get_values()
Definition: dense_matrix.h:338
PetscErrorCode ierr
template<typename T >
void libMesh::PetscMatrix< T >::add_matrix ( const DenseMatrix< T > &  dm,
const std::vector< numeric_index_type > &  dof_indices 
)
virtual

Same as add_matrix, but assumes the row and column maps are the same. Thus the matrix dm must be square.

Implements libMesh::SparseMatrix< T >.

Definition at line 1003 of file petsc_matrix.C.

1005 {
1006  this->add_matrix (dm, dof_indices, dof_indices);
1007 }
virtual void add_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols) libmesh_override
Definition: petsc_matrix.C:705
template<typename T>
void libMesh::SparseMatrix< T >::attach_dof_map ( const DofMap dof_map)
inlineinherited

Get a pointer to the DofMap to use.

Definition at line 112 of file sparse_matrix.h.

Referenced by libMesh::__libmesh_tao_hessian(), and libMesh::DofMap::attach_matrix().

113  { _dof_map = &dof_map; }
DofMap const * _dof_map
template<typename T >
UniquePtr< SparseMatrix< T > > libMesh::SparseMatrix< T >::build ( const Parallel::Communicator comm,
const SolverPackage  solver_package = libMesh::default_solver_package() 
)
staticinherited

Builds a SparseMatrix<T> using the linear solver package specified by solver_package

Definition at line 135 of file sparse_matrix.C.

References libMesh::ParallelObject::comm(), libMesh::EIGEN_SOLVERS, libMesh::LASPACK_SOLVERS, libMesh::PETSC_SOLVERS, and libMesh::TRILINOS_SOLVERS.

Referenced by libMesh::ImplicitSystem::add_matrix().

137 {
138  // Build the appropriate vector
139  switch (solver_package)
140  {
141 
142 #ifdef LIBMESH_HAVE_LASPACK
143  case LASPACK_SOLVERS:
144  return UniquePtr<SparseMatrix<T> >(new LaspackMatrix<T>(comm));
145 #endif
146 
147 
148 #ifdef LIBMESH_HAVE_PETSC
149  case PETSC_SOLVERS:
150  return UniquePtr<SparseMatrix<T> >(new PetscMatrix<T>(comm));
151 #endif
152 
153 
154 #ifdef LIBMESH_TRILINOS_HAVE_EPETRA
155  case TRILINOS_SOLVERS:
156  return UniquePtr<SparseMatrix<T> >(new EpetraMatrix<T>(comm));
157 #endif
158 
159 
160 #ifdef LIBMESH_HAVE_EIGEN
161  case EIGEN_SOLVERS:
162  return UniquePtr<SparseMatrix<T> >(new EigenSparseMatrix<T>(comm));
163 #endif
164 
165  default:
166  libmesh_error_msg("ERROR: Unrecognized solver package: " << solver_package);
167  }
168 
169  libmesh_error_msg("We'll never get here!");
170  return UniquePtr<SparseMatrix<T> >();
171 }
EIGEN_SOLVERS
Definition: libmesh.C:260
TRILINOS_SOLVERS
Definition: libmesh.C:258
LASPACK_SOLVERS
Definition: libmesh.C:262
const Parallel::Communicator & comm() const
template<typename T >
void libMesh::PetscMatrix< T >::clear ( )
virtual

Release all memory and return to a state just like after having called the default constructor.

Implements libMesh::SparseMatrix< T >.

Definition at line 466 of file petsc_matrix.C.

References libMesh::libMeshPrivateData::_is_initialized, ierr, and libMesh::initialized().

467 {
468  PetscErrorCode ierr=0;
469 
470  if ((this->initialized()) && (this->_destroy_mat_on_exit))
471  {
472  semiparallel_only();
473 
474  ierr = LibMeshMatDestroy (&_mat);
475  LIBMESH_CHKERR(ierr);
476 
477  this->_is_initialized = false;
478  }
479 }
virtual bool initialized() const
PetscErrorCode ierr
template<typename T >
void libMesh::PetscMatrix< T >::close ( ) const
virtual

Call the Petsc assemble routines. sends necessary messages to other processors

Implements libMesh::SparseMatrix< T >.

Definition at line 881 of file petsc_matrix.C.

References ierr.

Referenced by libMesh::PetscMatrix< T >::_get_submatrix(), libMesh::PetscLinearSolver< T >::adjoint_solve(), libMesh::PetscMatrix< T >::get_transpose(), libMesh::PetscLinearSolver< T >::solve(), libMesh::SlepcEigenSolver< T >::solve_generalized(), and libMesh::SlepcEigenSolver< T >::solve_standard().

882 {
883  semiparallel_only();
884 
885  // BSK - 1/19/2004
886  // strictly this check should be OK, but it seems to
887  // fail on matrix-free matrices. Do they falsely
888  // state they are assembled? Check with the developers...
889  // if (this->closed())
890  // return;
891 
892  PetscErrorCode ierr=0;
893 
894  ierr = MatAssemblyBegin (_mat, MAT_FINAL_ASSEMBLY);
895  LIBMESH_CHKERR(ierr);
896  ierr = MatAssemblyEnd (_mat, MAT_FINAL_ASSEMBLY);
897  LIBMESH_CHKERR(ierr);
898 }
PetscErrorCode ierr
template<typename T >
bool libMesh::PetscMatrix< T >::closed ( ) const
virtual

see if Petsc matrix has been closed and fully assembled yet

Implements libMesh::SparseMatrix< T >.

Definition at line 1105 of file petsc_matrix.C.

References ierr, libMesh::initialized(), and libMesh::libmesh_assert().

Referenced by libMesh::PetscMatrix< T >::add(), and libMesh::PetscMatrix< T >::add_block_matrix().

1106 {
1107  libmesh_assert (this->initialized());
1108 
1109  PetscErrorCode ierr=0;
1110  PetscBool assembled;
1111 
1112  ierr = MatAssembled(_mat, &assembled);
1113  LIBMESH_CHKERR(ierr);
1114 
1115  return (assembled == PETSC_TRUE);
1116 }
libmesh_assert(j)
virtual bool initialized() const
PetscTruth PetscBool
Definition: petsc_macro.h:64
PetscErrorCode ierr
const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inlineinherited
Returns
a reference to the Parallel::Communicator object used by this mesh.

Definition at line 87 of file parallel_object.h.

References libMesh::ParallelObject::_communicator.

Referenced by libMesh::__libmesh_petsc_diff_solver_monitor(), libMesh::__libmesh_petsc_diff_solver_residual(), libMesh::__libmesh_petsc_snes_jacobian(), libMesh::__libmesh_petsc_snes_postcheck(), libMesh::__libmesh_petsc_snes_residual(), libMesh::__libmesh_tao_equality_constraints(), libMesh::__libmesh_tao_equality_constraints_jacobian(), libMesh::__libmesh_tao_gradient(), libMesh::__libmesh_tao_hessian(), libMesh::__libmesh_tao_inequality_constraints(), libMesh::__libmesh_tao_inequality_constraints_jacobian(), libMesh::__libmesh_tao_objective(), libMesh::MeshRefinement::_coarsen_elements(), libMesh::ExactSolution::_compute_error(), libMesh::ParmetisPartitioner::_do_repartition(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult_add(), libMesh::EquationSystems::_read_impl(), libMesh::MeshRefinement::_refine_elements(), libMesh::MeshRefinement::_smooth_flags(), libMesh::ImplicitSystem::add_matrix(), libMesh::System::add_vector(), libMesh::EigenSparseLinearSolver< T >::adjoint_solve(), libMesh::UnstructuredMesh::all_second_order(), libMesh::MeshTools::Modification::all_tri(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assemble_qoi(), libMesh::MeshCommunication::assign_global_indices(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::DofMap::attach_matrix(), libMesh::Parallel::BinSorter< KeyType, IdxType >::binsort(), libMesh::Parallel::Sort< KeyType, IdxType >::binsort(), libMesh::MeshTools::bounding_box(), libMesh::MeshCommunication::broadcast(), libMesh::SparseMatrix< T >::build(), libMesh::MeshTools::Generation::build_extrusion(), libMesh::Parallel::Histogram< KeyType, IdxType >::build_histogram(), libMesh::PetscNonlinearSolver< T >::build_mat_null_space(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::MeshBase::cache_elem_dims(), libMesh::System::calculate_norm(), libMesh::DofMap::check_dirichlet_bcid_consistency(), libMesh::DistributedVector< T >::clone(), libMesh::EigenSparseVector< T >::clone(), libMesh::LaspackVector< T >::clone(), libMesh::EpetraVector< T >::clone(), libMesh::PetscVector< T >::clone(), libMesh::EpetraVector< T >::close(), libMesh::Parallel::Sort< KeyType, IdxType >::communicate_bins(), libMesh::Nemesis_IO_Helper::compute_num_global_elem_blocks(), libMesh::Nemesis_IO_Helper::compute_num_global_nodesets(), libMesh::Nemesis_IO_Helper::compute_num_global_sidesets(), libMesh::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::MeshRefinement::create_parent_error_vector(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), DMlibMeshFunction(), DMlibMeshJacobian(), DMlibMeshSetSystem_libMesh(), DMVariableBounds_libMesh(), libMesh::MeshRefinement::eliminate_unrefined_patches(), libMesh::EpetraVector< T >::EpetraVector(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::MeshRefinement::flag_elements_by_elem_fraction(), libMesh::MeshRefinement::flag_elements_by_error_fraction(), libMesh::MeshRefinement::flag_elements_by_nelem_target(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::DofMap::get_info(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::EquationSystems::get_solution(), libMesh::LocationMap< T >::init(), libMesh::PetscDiffSolver::init(), libMesh::TimeSolver::init(), libMesh::TopologyMap::init(), libMesh::TaoOptimizationSolver< T >::init(), libMesh::PetscNonlinearSolver< T >::init(), libMesh::DistributedVector< T >::init(), libMesh::EpetraVector< T >::init(), libMesh::PetscVector< T >::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::EigenSystem::init_data(), libMesh::EigenSystem::init_matrices(), libMesh::ParmetisPartitioner::initialize(), libMesh::OptimizationSystem::initialize_equality_constraints_storage(), libMesh::OptimizationSystem::initialize_inequality_constraints_storage(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_topology_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_boundary_ids(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_flags(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_p_levels(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::MeshTools::libmesh_assert_valid_unique_ids(), libMesh::MeshRefinement::limit_level_mismatch_at_edge(), libMesh::MeshRefinement::limit_level_mismatch_at_node(), libMesh::MeshRefinement::limit_overrefined_boundary(), libMesh::MeshRefinement::limit_underrefined_boundary(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshCommunication::make_elems_parallel_consistent(), libMesh::MeshRefinement::make_flags_parallel_consistent(), libMesh::MeshCommunication::make_new_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_new_nodes_parallel_consistent(), libMesh::MeshCommunication::make_node_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_unique_ids_parallel_consistent(), libMesh::MeshCommunication::make_nodes_parallel_consistent(), libMesh::MeshCommunication::make_p_levels_parallel_consistent(), libMesh::MeshRefinement::make_refinement_compatible(), libMesh::DistributedVector< T >::max(), libMesh::FEMSystem::mesh_position_set(), libMesh::MeshSerializer::MeshSerializer(), libMesh::DistributedVector< T >::min(), libMesh::DistributedMesh::n_active_elem(), libMesh::MeshTools::n_active_levels(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::CondensedEigenSystem::n_global_non_condensed_dofs(), libMesh::MeshTools::n_levels(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::MeshTools::n_p_levels(), libMesh::BoundaryInfo::n_shellface_conds(), libMesh::DistributedMesh::parallel_max_elem_id(), libMesh::DistributedMesh::parallel_max_node_id(), libMesh::ReplicatedMesh::parallel_max_unique_id(), libMesh::DistributedMesh::parallel_max_unique_id(), libMesh::DistributedMesh::parallel_n_elem(), libMesh::DistributedMesh::parallel_n_nodes(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::MeshTools::paranoid_n_levels(), libMesh::Partitioner::partition(), libMesh::MetisPartitioner::partition_range(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::petsc_auto_fieldsplit(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::MeshBase::prepare_for_use(), libMesh::SparseMatrix< T >::print(), libMesh::MeshTools::processor_bounding_box(), libMesh::Nemesis_IO::read(), libMesh::XdrIO::read(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::MeshBase::recalculate_n_partitions(), libMesh::MeshCommunication::redistribute(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::Partitioner::set_parent_processor_ids(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::Parallel::Sort< KeyType, IdxType >::sort(), libMesh::MeshTools::subdomain_bounding_box(), libMesh::MeshBase::subdomain_ids(), libMesh::BoundaryInfo::sync(), libMesh::Parallel::sync_element_data_by_parent_id(), libMesh::Parallel::sync_node_data_by_element_id(), libMesh::MeshRefinement::test_level_one(), libMesh::MeshRefinement::test_unflagged(), libMesh::MeshTools::total_weight(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::DistributedVector< T >::zero_clone(), libMesh::LaspackVector< T >::zero_clone(), libMesh::EigenSparseVector< T >::zero_clone(), libMesh::EpetraVector< T >::zero_clone(), and libMesh::PetscVector< T >::zero_clone().

88  { return _communicator; }
const Parallel::Communicator & _communicator
template<typename T>
virtual void libMesh::SparseMatrix< T >::create_submatrix ( SparseMatrix< T > &  submatrix,
const std::vector< numeric_index_type > &  rows,
const std::vector< numeric_index_type > &  cols 
) const
inlinevirtualinherited

This function creates a matrix called "submatrix" which is defined by the row and column indices given in the "rows" and "cols" entries. Currently this operation is only defined for the PetscMatrix type.

Definition at line 368 of file sparse_matrix.h.

371  {
372  this->_get_submatrix(submatrix,
373  rows,
374  cols,
375  false); // false means DO NOT REUSE submatrix
376  }
virtual void _get_submatrix(SparseMatrix< T > &, const std::vector< numeric_index_type > &, const std::vector< numeric_index_type > &, const bool) const
void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited
void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

Methods to enable/disable the reference counter output from print_info()

Definition at line 100 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

Referenced by libMesh::ReferenceCounter::n_objects().

101 {
102  _enable_print_counter = true;
103  return;
104 }
template<typename T >
void libMesh::PetscMatrix< T >::get_diagonal ( NumericVector< T > &  dest) const
virtual

Copies the diagonal part of the matrix into dest.

Implements libMesh::SparseMatrix< T >.

Definition at line 832 of file petsc_matrix.C.

References ierr, and libMesh::PetscVector< T >::vec().

Referenced by libMesh::PetscMatrix< T >::add_block_matrix().

833 {
834  // Make sure the NumericVector passed in is really a PetscVector
835  PetscVector<T> & petsc_dest = cast_ref<PetscVector<T> &>(dest);
836 
837  // Needs a const_cast since PETSc does not work with const.
838  PetscErrorCode ierr =
839  MatGetDiagonal(const_cast<PetscMatrix<T> *>(this)->mat(),petsc_dest.vec()); LIBMESH_CHKERR(ierr);
840 }
NumericVector interface to PETSc Vec.
Definition: petsc_vector.h:64
PetscErrorCode ierr
SparseMatrix interface to PETSc Mat.
std::string libMesh::ReferenceCounter::get_info ( )
staticinherited

Gets a string containing the reference information.

Definition at line 47 of file reference_counter.C.

References libMesh::ReferenceCounter::_counts, and libMesh::Quality::name().

Referenced by libMesh::ReferenceCounter::print_info().

48 {
49 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
50 
51  std::ostringstream oss;
52 
53  oss << '\n'
54  << " ---------------------------------------------------------------------------- \n"
55  << "| Reference count information |\n"
56  << " ---------------------------------------------------------------------------- \n";
57 
58  for (Counts::iterator it = _counts.begin();
59  it != _counts.end(); ++it)
60  {
61  const std::string name(it->first);
62  const unsigned int creations = it->second.first;
63  const unsigned int destructions = it->second.second;
64 
65  oss << "| " << name << " reference count information:\n"
66  << "| Creations: " << creations << '\n'
67  << "| Destructions: " << destructions << '\n';
68  }
69 
70  oss << " ---------------------------------------------------------------------------- \n";
71 
72  return oss.str();
73 
74 #else
75 
76  return "";
77 
78 #endif
79 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
template<typename T >
void libMesh::PetscMatrix< T >::get_transpose ( SparseMatrix< T > &  dest) const
virtual

Copies the transpose of the matrix into dest, which may be *this.

Implements libMesh::SparseMatrix< T >.

Definition at line 845 of file petsc_matrix.C.

References libMesh::SparseMatrix< T >::_is_initialized, libMesh::PetscMatrix< T >::_mat, libMesh::SparseMatrix< T >::clear(), libMesh::PetscMatrix< T >::close(), and ierr.

Referenced by libMesh::PetscMatrix< T >::add_block_matrix().

846 {
847  // Make sure the SparseMatrix passed in is really a PetscMatrix
848  PetscMatrix<T> & petsc_dest = cast_ref<PetscMatrix<T> &>(dest);
849 
850  // If we aren't reusing the matrix then need to clear dest,
851  // otherwise we get a memory leak
852  if(&petsc_dest != this)
853  dest.clear();
854 
855  PetscErrorCode ierr;
856 #if PETSC_VERSION_LESS_THAN(3,0,0)
857  if (&petsc_dest == this)
858  ierr = MatTranspose(_mat,PETSC_NULL);
859  else
860  ierr = MatTranspose(_mat,&petsc_dest._mat);
861  LIBMESH_CHKERR(ierr);
862 #else
863  // FIXME - we can probably use MAT_REUSE_MATRIX in more situations
864  if (&petsc_dest == this)
865  ierr = MatTranspose(_mat,MAT_REUSE_MATRIX,&petsc_dest._mat);
866  else
867  ierr = MatTranspose(_mat,MAT_INITIAL_MATRIX,&petsc_dest._mat);
868  LIBMESH_CHKERR(ierr);
869 #endif
870 
871  // Specify that the transposed matrix is initialized and close it.
872  petsc_dest._is_initialized = true;
873  petsc_dest.close();
874 }
virtual void close() const libmesh_override
Definition: petsc_matrix.C:881
virtual void clear()=0
PetscErrorCode ierr
SparseMatrix interface to PETSc Mat.
void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name)
inlineprotectedinherited

Increments the construction counter. Should be called in the constructor of any derived class that will be reference counted.

Definition at line 160 of file reference_counter.h.

References libMesh::ReferenceCounter::_counts, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCounter::n_objects(), and libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

161 {
162  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
163  std::pair<unsigned int, unsigned int> & p = _counts[name];
164 
165  p.first++;
166 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
spin_mutex spin_mtx
Definition: threads.C:29
void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name)
inlineprotectedinherited

Increments the destruction counter. Should be called in the destructor of any derived class that will be reference counted.

Definition at line 173 of file reference_counter.h.

References libMesh::ReferenceCounter::_counts, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCounter::n_objects(), and libMesh::ReferenceCountedObject< RBParametrized >::~ReferenceCountedObject().

174 {
175  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
176  std::pair<unsigned int, unsigned int> & p = _counts[name];
177 
178  p.second++;
179 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
spin_mutex spin_mtx
Definition: threads.C:29
template<typename T >
void libMesh::PetscMatrix< T >::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 
)
virtual

Initialize a Petsc matrix that is of global dimension $ m \times n $ with local dimensions $ m_l \times n_l $. nnz is the number of on-processor nonzeros per row (defaults to 30). noz is the number of on-processor nonzeros per row (defaults to 30). Optionally supports a block size, which indicates dense coupled blocks for systems with multiple variables all of the same type.

Implements libMesh::SparseMatrix< T >.

Definition at line 120 of file petsc_matrix.C.

References libMesh::libMeshPrivateData::_is_initialized, ierr, libMesh::initialized(), libMesh::libmesh_ignore(), and libMesh::zero.

127 {
128  // So compilers don't warn when !LIBMESH_ENABLE_BLOCKED_STORAGE
129  libmesh_ignore(blocksize_in);
130 
131  // Clear initialized matrices
132  if (this->initialized())
133  this->clear();
134 
135  this->_is_initialized = true;
136 
137 
138  PetscErrorCode ierr = 0;
139  PetscInt m_global = static_cast<PetscInt>(m_in);
140  PetscInt n_global = static_cast<PetscInt>(n_in);
141  PetscInt m_local = static_cast<PetscInt>(m_l);
142  PetscInt n_local = static_cast<PetscInt>(n_l);
143  PetscInt n_nz = static_cast<PetscInt>(nnz);
144  PetscInt n_oz = static_cast<PetscInt>(noz);
145 
146  ierr = MatCreate(this->comm().get(), &_mat);
147  LIBMESH_CHKERR(ierr);
148  ierr = MatSetSizes(_mat, m_local, n_local, m_global, n_global);
149  LIBMESH_CHKERR(ierr);
150 
151 #ifdef LIBMESH_ENABLE_BLOCKED_STORAGE
152  PetscInt blocksize = static_cast<PetscInt>(blocksize_in);
153  if (blocksize > 1)
154  {
155  // specified blocksize, bs>1.
156  // double check sizes.
157  libmesh_assert_equal_to (m_local % blocksize, 0);
158  libmesh_assert_equal_to (n_local % blocksize, 0);
159  libmesh_assert_equal_to (m_global % blocksize, 0);
160  libmesh_assert_equal_to (n_global % blocksize, 0);
161  libmesh_assert_equal_to (n_nz % blocksize, 0);
162  libmesh_assert_equal_to (n_oz % blocksize, 0);
163 
164  ierr = MatSetType(_mat, MATBAIJ); // Automatically chooses seqbaij or mpibaij
165  LIBMESH_CHKERR(ierr);
166  ierr = MatSetBlockSize(_mat, blocksize);
167  LIBMESH_CHKERR(ierr);
168  ierr = MatSeqBAIJSetPreallocation(_mat, blocksize, n_nz/blocksize, PETSC_NULL);
169  LIBMESH_CHKERR(ierr);
170  ierr = MatMPIBAIJSetPreallocation(_mat, blocksize,
171  n_nz/blocksize, PETSC_NULL,
172  n_oz/blocksize, PETSC_NULL);
173  LIBMESH_CHKERR(ierr);
174  }
175  else
176 #endif
177  {
178  ierr = MatSetType(_mat, MATAIJ); // Automatically chooses seqaij or mpiaij
179  LIBMESH_CHKERR(ierr);
180  ierr = MatSeqAIJSetPreallocation(_mat, n_nz, PETSC_NULL);
181  LIBMESH_CHKERR(ierr);
182  ierr = MatMPIAIJSetPreallocation(_mat, n_nz, PETSC_NULL, n_oz, PETSC_NULL);
183  LIBMESH_CHKERR(ierr);
184  }
185 
186  // Make it an error for PETSc to allocate new nonzero entries during assembly
187 #if PETSC_VERSION_LESS_THAN(3,0,0)
188  ierr = MatSetOption(_mat, MAT_NEW_NONZERO_ALLOCATION_ERR);
189 #else
190  ierr = MatSetOption(_mat, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_TRUE);
191 #endif
192  LIBMESH_CHKERR(ierr);
193 
194  // Is prefix information available somewhere? Perhaps pass in the system name?
195  ierr = MatSetOptionsPrefix(_mat, "");
196  LIBMESH_CHKERR(ierr);
197  ierr = MatSetFromOptions(_mat);
198  LIBMESH_CHKERR(ierr);
199 
200  this->zero ();
201 }
virtual bool initialized() const
virtual void clear() libmesh_override
Definition: petsc_matrix.C:466
void libmesh_ignore(const T &)
PetscErrorCode ierr
const Parallel::Communicator & comm() const
virtual void zero() libmesh_override
Definition: petsc_matrix.C:413
template<typename T >
void libMesh::PetscMatrix< T >::init ( const numeric_index_type  m,
const numeric_index_type  n,
const numeric_index_type  m_l,
const numeric_index_type  n_l,
const std::vector< numeric_index_type > &  n_nz,
const std::vector< numeric_index_type > &  n_oz,
const numeric_index_type  blocksize = 1 
)

Initialize a Petsc matrix that is of global dimension $ m \times n $ with local dimensions $ m_l \times n_l $. nnz is the number of on-processor nonzeros per row. noz is the number of off-processor nonzeros per row. Optionally supports a block size, which indicates dense coupled blocks for systems with multiple variables all of the same type.

Definition at line 205 of file petsc_matrix.C.

References libMesh::libMeshPrivateData::_is_initialized, ierr, libMesh::initialized(), libMesh::libmesh_ignore(), libmesh_nullptr, libMesh::numeric_petsc_cast(), and libMesh::zero.

212 {
213  // So compilers don't warn when !LIBMESH_ENABLE_BLOCKED_STORAGE
214  libmesh_ignore(blocksize_in);
215 
216  // Clear initialized matrices
217  if (this->initialized())
218  this->clear();
219 
220  this->_is_initialized = true;
221 
222  // Make sure the sparsity pattern isn't empty unless the matrix is 0x0
223  libmesh_assert_equal_to (n_nz.size(), m_l);
224  libmesh_assert_equal_to (n_oz.size(), m_l);
225 
226  PetscErrorCode ierr = 0;
227  PetscInt m_global = static_cast<PetscInt>(m_in);
228  PetscInt n_global = static_cast<PetscInt>(n_in);
229  PetscInt m_local = static_cast<PetscInt>(m_l);
230  PetscInt n_local = static_cast<PetscInt>(n_l);
231 
232  ierr = MatCreate(this->comm().get(), &_mat);
233  LIBMESH_CHKERR(ierr);
234  ierr = MatSetSizes(_mat, m_local, n_local, m_global, n_global);
235  LIBMESH_CHKERR(ierr);
236 
237 #ifdef LIBMESH_ENABLE_BLOCKED_STORAGE
238  PetscInt blocksize = static_cast<PetscInt>(blocksize_in);
239  if (blocksize > 1)
240  {
241  // specified blocksize, bs>1.
242  // double check sizes.
243  libmesh_assert_equal_to (m_local % blocksize, 0);
244  libmesh_assert_equal_to (n_local % blocksize, 0);
245  libmesh_assert_equal_to (m_global % blocksize, 0);
246  libmesh_assert_equal_to (n_global % blocksize, 0);
247 
248  ierr = MatSetType(_mat, MATBAIJ); // Automatically chooses seqbaij or mpibaij
249  LIBMESH_CHKERR(ierr);
250  ierr = MatSetBlockSize(_mat, blocksize);
251  LIBMESH_CHKERR(ierr);
252 
253  // transform the per-entry n_nz and n_oz arrays into their block counterparts.
254  std::vector<numeric_index_type> b_n_nz, b_n_oz;
255 
256  transform_preallocation_arrays (blocksize,
257  n_nz, n_oz,
258  b_n_nz, b_n_oz);
259 
260  ierr = MatSeqBAIJSetPreallocation (_mat,
261  blocksize,
262  0,
263  numeric_petsc_cast(b_n_nz.empty() ? libmesh_nullptr : &b_n_nz[0]));
264  LIBMESH_CHKERR(ierr);
265 
266  ierr = MatMPIBAIJSetPreallocation (_mat,
267  blocksize,
268  0,
269  numeric_petsc_cast(b_n_nz.empty() ? libmesh_nullptr : &b_n_nz[0]),
270  0,
271  numeric_petsc_cast(b_n_oz.empty() ? libmesh_nullptr : &b_n_oz[0]));
272  LIBMESH_CHKERR(ierr);
273  }
274  else
275 #endif
276  {
277 
278  ierr = MatSetType(_mat, MATAIJ); // Automatically chooses seqaij or mpiaij
279  LIBMESH_CHKERR(ierr);
280  ierr = MatSeqAIJSetPreallocation (_mat,
281  0,
282  numeric_petsc_cast(n_nz.empty() ? libmesh_nullptr : &n_nz[0]));
283  LIBMESH_CHKERR(ierr);
284  ierr = MatMPIAIJSetPreallocation (_mat,
285  0,
286  numeric_petsc_cast(n_nz.empty() ? libmesh_nullptr : &n_nz[0]),
287  0,
288  numeric_petsc_cast(n_oz.empty() ? libmesh_nullptr : &n_oz[0]));
289  LIBMESH_CHKERR(ierr);
290  }
291 
292  // Is prefix information available somewhere? Perhaps pass in the system name?
293  ierr = MatSetOptionsPrefix(_mat, "");
294  LIBMESH_CHKERR(ierr);
295  ierr = MatSetFromOptions(_mat);
296  LIBMESH_CHKERR(ierr);
297 
298 
299  this->zero();
300 }
const class libmesh_nullptr_t libmesh_nullptr
PetscInt * numeric_petsc_cast(const numeric_index_type *p)
virtual bool initialized() const
virtual void clear() libmesh_override
Definition: petsc_matrix.C:466
void libmesh_ignore(const T &)
PetscErrorCode ierr
const Parallel::Communicator & comm() const
virtual void zero() libmesh_override
Definition: petsc_matrix.C:413
template<typename T >
void libMesh::PetscMatrix< T >::init ( )
virtual

Initialize using sparsity structure computed by dof_map.

Implements libMesh::SparseMatrix< T >.

Definition at line 304 of file petsc_matrix.C.

References libMesh::libMeshPrivateData::_is_initialized, ierr, libMesh::initialized(), libMesh::libmesh_assert(), libmesh_nullptr, libMesh::numeric_petsc_cast(), libMesh::processor_id(), and libMesh::zero.

305 {
306  libmesh_assert(this->_dof_map);
307 
308  // Clear initialized matrices
309  if (this->initialized())
310  this->clear();
311 
312  this->_is_initialized = true;
313 
314 
315  const numeric_index_type my_m = this->_dof_map->n_dofs();
316  const numeric_index_type my_n = my_m;
317  const numeric_index_type n_l = this->_dof_map->n_dofs_on_processor(this->processor_id());
318  const numeric_index_type m_l = n_l;
319 
320 
321  const std::vector<numeric_index_type> & n_nz = this->_dof_map->get_n_nz();
322  const std::vector<numeric_index_type> & n_oz = this->_dof_map->get_n_oz();
323 
324  // Make sure the sparsity pattern isn't empty unless the matrix is 0x0
325  libmesh_assert_equal_to (n_nz.size(), m_l);
326  libmesh_assert_equal_to (n_oz.size(), m_l);
327 
328  PetscErrorCode ierr = 0;
329  PetscInt m_global = static_cast<PetscInt>(my_m);
330  PetscInt n_global = static_cast<PetscInt>(my_n);
331  PetscInt m_local = static_cast<PetscInt>(m_l);
332  PetscInt n_local = static_cast<PetscInt>(n_l);
333 
334  ierr = MatCreate(this->comm().get(), &_mat);
335  LIBMESH_CHKERR(ierr);
336  ierr = MatSetSizes(_mat, m_local, n_local, m_global, n_global);
337  LIBMESH_CHKERR(ierr);
338 
339 #ifdef LIBMESH_ENABLE_BLOCKED_STORAGE
340  PetscInt blocksize = static_cast<PetscInt>(this->_dof_map->block_size());
341  if (blocksize > 1)
342  {
343  // specified blocksize, bs>1.
344  // double check sizes.
345  libmesh_assert_equal_to (m_local % blocksize, 0);
346  libmesh_assert_equal_to (n_local % blocksize, 0);
347  libmesh_assert_equal_to (m_global % blocksize, 0);
348  libmesh_assert_equal_to (n_global % blocksize, 0);
349 
350  ierr = MatSetType(_mat, MATBAIJ); // Automatically chooses seqbaij or mpibaij
351  LIBMESH_CHKERR(ierr);
352  ierr = MatSetBlockSize(_mat, blocksize);
353  LIBMESH_CHKERR(ierr);
354 
355  // transform the per-entry n_nz and n_oz arrays into their block counterparts.
356  std::vector<numeric_index_type> b_n_nz, b_n_oz;
357 
358  transform_preallocation_arrays (blocksize,
359  n_nz, n_oz,
360  b_n_nz, b_n_oz);
361 
362  ierr = MatSeqBAIJSetPreallocation (_mat,
363  blocksize,
364  0,
365  numeric_petsc_cast(b_n_nz.empty() ? libmesh_nullptr : &b_n_nz[0]));
366  LIBMESH_CHKERR(ierr);
367 
368  ierr = MatMPIBAIJSetPreallocation (_mat,
369  blocksize,
370  0,
371  numeric_petsc_cast(b_n_nz.empty() ? libmesh_nullptr : &b_n_nz[0]),
372  0,
373  numeric_petsc_cast(b_n_oz.empty() ? libmesh_nullptr : &b_n_oz[0]));
374  LIBMESH_CHKERR(ierr);
375  }
376  else
377 #endif
378  {
379  // no block storage case
380  ierr = MatSetType(_mat, MATAIJ); // Automatically chooses seqaij or mpiaij
381  LIBMESH_CHKERR(ierr);
382 
383  ierr = MatSeqAIJSetPreallocation (_mat,
384  0,
385  numeric_petsc_cast(n_nz.empty() ? libmesh_nullptr : &n_nz[0]));
386  LIBMESH_CHKERR(ierr);
387  ierr = MatMPIAIJSetPreallocation (_mat,
388  0,
389  numeric_petsc_cast(n_nz.empty() ? libmesh_nullptr : &n_nz[0]),
390  0,
391  numeric_petsc_cast(n_oz.empty() ? libmesh_nullptr : &n_oz[0]));
392  LIBMESH_CHKERR(ierr);
393  }
394 
395  // Is prefix information available somewhere? Perhaps pass in the system name?
396  ierr = MatSetOptionsPrefix(_mat, "");
397  LIBMESH_CHKERR(ierr);
398  ierr = MatSetFromOptions(_mat);
399  LIBMESH_CHKERR(ierr);
400 
401  this->zero();
402 }
const class libmesh_nullptr_t libmesh_nullptr
unsigned int block_size() const
Definition: dof_map.h:494
dof_id_type n_dofs() const
Definition: dof_map.h:506
dof_id_type n_dofs_on_processor(const processor_id_type proc) const
Definition: dof_map.h:522
libmesh_assert(j)
PetscInt * numeric_petsc_cast(const numeric_index_type *p)
virtual bool initialized() const
dof_id_type numeric_index_type
Definition: id_types.h:92
virtual void clear() libmesh_override
Definition: petsc_matrix.C:466
const std::vector< dof_id_type > & get_n_oz() const
Definition: dof_map.h:412
DofMap const * _dof_map
PetscErrorCode ierr
const Parallel::Communicator & comm() const
virtual void zero() libmesh_override
Definition: petsc_matrix.C:413
const std::vector< dof_id_type > & get_n_nz() const
Definition: dof_map.h:400
processor_id_type processor_id() const
template<typename T >
Real libMesh::PetscMatrix< T >::l1_norm ( ) const
virtual

Return the l1-norm of the matrix, that is $|M|_1=max_{all columns j}\sum_{all rows i} |M_ij|$, (max. sum of columns). This is the natural matrix norm that is compatible to the l1-norm for vectors, i.e. $|Mv|_1\leq |M|_1 |v|_1$. (cf. Haemmerlin-Hoffmann : Numerische Mathematik)

Implements libMesh::SparseMatrix< T >.

Definition at line 484 of file petsc_matrix.C.

References libMesh::closed(), ierr, libMesh::initialized(), libMesh::libmesh_assert(), and libMesh::Real.

Referenced by libMesh::PetscMatrix< T >::add_block_matrix().

485 {
486  libmesh_assert (this->initialized());
487 
488  semiparallel_only();
489 
490  PetscErrorCode ierr=0;
491  PetscReal petsc_value;
492  Real value;
493 
494  libmesh_assert (this->closed());
495 
496  ierr = MatNorm(_mat, NORM_1, &petsc_value);
497  LIBMESH_CHKERR(ierr);
498 
499  value = static_cast<Real>(petsc_value);
500 
501  return value;
502 }
virtual bool closed() const libmesh_override
libmesh_assert(j)
virtual bool initialized() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
PetscErrorCode ierr
template<typename T >
Real libMesh::PetscMatrix< T >::linfty_norm ( ) const
virtual

Return the linfty-norm of the matrix, that is $|M|_infty=max_{all rows i}\sum_{all columns j} |M_ij|$, (max. sum of rows). This is the natural matrix norm that is compatible to the linfty-norm of vectors, i.e. $|Mv|_infty \leq |M|_infty |v|_infty$. (cf. Haemmerlin-Hoffmann : Numerische Mathematik)

Implements libMesh::SparseMatrix< T >.

Definition at line 507 of file petsc_matrix.C.

References libMesh::closed(), ierr, libMesh::initialized(), libMesh::libmesh_assert(), and libMesh::Real.

Referenced by libMesh::PetscMatrix< T >::add_block_matrix().

508 {
509  libmesh_assert (this->initialized());
510 
511  semiparallel_only();
512 
513  PetscErrorCode ierr=0;
514  PetscReal petsc_value;
515  Real value;
516 
517  libmesh_assert (this->closed());
518 
519  ierr = MatNorm(_mat, NORM_INFINITY, &petsc_value);
520  LIBMESH_CHKERR(ierr);
521 
522  value = static_cast<Real>(petsc_value);
523 
524  return value;
525 }
virtual bool closed() const libmesh_override
libmesh_assert(j)
virtual bool initialized() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
PetscErrorCode ierr
template<typename T >
numeric_index_type libMesh::PetscMatrix< T >::m ( ) const
virtual
Returns
m, the row-dimension of the matrix where the marix is $ M \times N $.

Implements libMesh::SparseMatrix< T >.

Definition at line 903 of file petsc_matrix.C.

References ierr, libMesh::initialized(), and libMesh::libmesh_assert().

904 {
905  libmesh_assert (this->initialized());
906 
907  PetscInt petsc_m=0, petsc_n=0;
908  PetscErrorCode ierr=0;
909 
910  ierr = MatGetSize (_mat, &petsc_m, &petsc_n);
911  LIBMESH_CHKERR(ierr);
912 
913  return static_cast<numeric_index_type>(petsc_m);
914 }
libmesh_assert(j)
virtual bool initialized() const
dof_id_type numeric_index_type
Definition: id_types.h:92
PetscErrorCode ierr
template<typename T >
numeric_index_type libMesh::PetscMatrix< T >::n ( ) const
virtual
Returns
n, the column-dimension of the matrix where the marix is $ M \times N $.

Implements libMesh::SparseMatrix< T >.

Definition at line 919 of file petsc_matrix.C.

References ierr, libMesh::initialized(), and libMesh::libmesh_assert().

920 {
921  libmesh_assert (this->initialized());
922 
923  PetscInt petsc_m=0, petsc_n=0;
924  PetscErrorCode ierr=0;
925 
926  ierr = MatGetSize (_mat, &petsc_m, &petsc_n);
927  LIBMESH_CHKERR(ierr);
928 
929  return static_cast<numeric_index_type>(petsc_n);
930 }
libmesh_assert(j)
virtual bool initialized() const
dof_id_type numeric_index_type
Definition: id_types.h:92
PetscErrorCode ierr
static unsigned int libMesh::ReferenceCounter::n_objects ( )
inlinestaticinherited
processor_id_type libMesh::ParallelObject::n_processors ( ) const
inlineinherited
Returns
the number of processors in the group.

Definition at line 93 of file parallel_object.h.

References libMesh::ParallelObject::_communicator, and libMesh::Parallel::Communicator::size().

Referenced by libMesh::ParmetisPartitioner::_do_repartition(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::DistributedMesh::add_elem(), libMesh::DistributedMesh::add_node(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assembly(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::AztecLinearSolver< T >::AztecLinearSolver(), libMesh::MeshCommunication::broadcast(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::DistributedMesh::clear(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::UnstructuredMesh::create_pid_mesh(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::DistributedMesh::DistributedMesh(), libMesh::EnsightIO::EnsightIO(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::MeshBase::get_info(), libMesh::EquationSystems::get_solution(), libMesh::DistributedVector< T >::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::ParmetisPartitioner::initialize(), libMesh::Nemesis_IO_Helper::initialize(), libMesh::DistributedMesh::insert_elem(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_topology_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_boundary_ids(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::DofMap::local_variable_indices(), libMesh::MeshBase::n_active_elem_on_proc(), libMesh::MeshBase::n_elem_on_proc(), libMesh::MeshBase::n_nodes_on_proc(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::Partitioner::partition(), libMesh::MeshBase::partition(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::PetscLinearSolver< T >::PetscLinearSolver(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::SparseMatrix< T >::print(), libMesh::MeshTools::processor_bounding_box(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::XdrIO::read(), libMesh::MeshCommunication::redistribute(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::Partitioner::repartition(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::Parallel::Sort< KeyType, IdxType >::sort(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), and libMesh::XdrIO::write_serialized_nodesets().

94  { return cast_int<processor_id_type>(_communicator.size()); }
unsigned int size() const
Definition: parallel.h:679
const Parallel::Communicator & _communicator
template<typename T>
virtual bool libMesh::SparseMatrix< T >::need_full_sparsity_pattern ( ) const
inlinevirtualinherited

returns true if this sparse matrix format needs to be fed the graph of the sparse matrix. This is true in the case of the LaspackMatrix, but not for the PetscMatrix. In the case where the full graph is not required we can efficiently approximate it to provide a good estimate of the required size of the sparse matrix.

Reimplemented in libMesh::EpetraMatrix< T >, and libMesh::LaspackMatrix< T >.

Definition at line 122 of file sparse_matrix.h.

Referenced by libMesh::DofMap::attach_matrix().

123  { return false; }
template<typename T >
T libMesh::PetscMatrix< T >::operator() ( const numeric_index_type  i,
const numeric_index_type  j 
) const
virtual

Return the value of the entry (i,j). This may be an expensive operation, and you should always be careful where you call this function.

Implements libMesh::SparseMatrix< T >.

Definition at line 1045 of file petsc_matrix.C.

References libMesh::closed(), ierr, libMesh::initialized(), and libMesh::libmesh_assert().

Referenced by libMesh::PetscMatrix< T >::add_block_matrix().

1047 {
1048  libmesh_assert (this->initialized());
1049 
1050  // PETSc 2.2.1 & newer
1051  const PetscScalar * petsc_row;
1052  const PetscInt * petsc_cols;
1053 
1054  // If the entry is not in the sparse matrix, it is 0.
1055  T value=0.;
1056 
1057  PetscErrorCode
1058  ierr=0;
1059  PetscInt
1060  ncols=0,
1061  i_val=static_cast<PetscInt>(i_in),
1062  j_val=static_cast<PetscInt>(j_in);
1063 
1064 
1065  // the matrix needs to be closed for this to work
1066  // this->close();
1067  // but closing it is a semiparallel operation; we want operator()
1068  // to run on one processor.
1069  libmesh_assert(this->closed());
1070 
1071  ierr = MatGetRow(_mat, i_val, &ncols, &petsc_cols, &petsc_row);
1072  LIBMESH_CHKERR(ierr);
1073 
1074  // Perform a binary search to find the contiguous index in
1075  // petsc_cols (resp. petsc_row) corresponding to global index j_val
1076  std::pair<const PetscInt *, const PetscInt *> p =
1077  std::equal_range (&petsc_cols[0], &petsc_cols[0] + ncols, j_val);
1078 
1079  // Found an entry for j_val
1080  if (p.first != p.second)
1081  {
1082  // The entry in the contiguous row corresponding
1083  // to the j_val column of interest
1084  const std::size_t j =
1085  std::distance (const_cast<PetscInt *>(&petsc_cols[0]),
1086  const_cast<PetscInt *>(p.first));
1087 
1088  libmesh_assert_less (static_cast<PetscInt>(j), ncols);
1089  libmesh_assert_equal_to (petsc_cols[j], j_val);
1090 
1091  value = static_cast<T> (petsc_row[j]);
1092  }
1093 
1094  ierr = MatRestoreRow(_mat, i_val,
1095  &ncols, &petsc_cols, &petsc_row);
1096  LIBMESH_CHKERR(ierr);
1097 
1098  return value;
1099 }
virtual bool closed() const libmesh_override
libmesh_assert(j)
virtual bool initialized() const
PetscErrorCode ierr
template<>
void libMesh::SparseMatrix< Complex >::print ( std::ostream &  os,
const bool  sparse 
) const
inherited

Definition at line 101 of file sparse_matrix.C.

References libMesh::SparseMatrix< T >::m(), and libMesh::SparseMatrix< T >::n().

102 {
103  // std::complex<>::operator<<() is defined, but use this form
104 
105  if(sparse)
106  {
107  libmesh_not_implemented();
108  }
109 
110  os << "Real part:" << std::endl;
111  for (numeric_index_type i=0; i<this->m(); i++)
112  {
113  for (numeric_index_type j=0; j<this->n(); j++)
114  os << std::setw(8) << (*this)(i,j).real() << " ";
115  os << std::endl;
116  }
117 
118  os << std::endl << "Imaginary part:" << std::endl;
119  for (numeric_index_type i=0; i<this->m(); i++)
120  {
121  for (numeric_index_type j=0; j<this->n(); j++)
122  os << std::setw(8) << (*this)(i,j).imag() << " ";
123  os << std::endl;
124  }
125 }
virtual numeric_index_type n() const =0
virtual numeric_index_type m() const =0
dof_id_type numeric_index_type
Definition: id_types.h:92
template<typename T >
void libMesh::SparseMatrix< T >::print ( std::ostream &  os = libMesh::out,
const bool  sparse = false 
) const
inherited

Print the contents of the matrix to the screen in a uniform style, regardless of matrix/solver package being used.

Definition at line 205 of file sparse_matrix.C.

References libMesh::SparseMatrix< T >::_dof_map, libMesh::ParallelObject::comm(), libMesh::DofMap::end_dof(), libMesh::DofMap::first_dof(), libMesh::SparseMatrix< T >::initialized(), libMesh::libmesh_assert(), libMesh::SparseMatrix< T >::m(), libMesh::SparseMatrix< T >::n(), libMesh::ParallelObject::n_processors(), libMesh::ParallelObject::processor_id(), libMesh::Parallel::Communicator::receive(), and libMesh::Parallel::Communicator::send().

Referenced by libMesh::EigenSparseMatrix< T >::print_personal(), and libMesh::LaspackMatrix< T >::print_personal().

206 {
207  parallel_object_only();
208 
209  libmesh_assert (this->initialized());
210 
211  if(!this->_dof_map)
212  libmesh_error_msg("Error! Trying to print a matrix with no dof_map set!");
213 
214  // We'll print the matrix from processor 0 to make sure
215  // it's serialized properly
216  if (this->processor_id() == 0)
217  {
218  libmesh_assert_equal_to (this->_dof_map->first_dof(), 0);
219  for (numeric_index_type i=this->_dof_map->first_dof();
220  i!=this->_dof_map->end_dof(); ++i)
221  {
222  if(sparse)
223  {
224  for (numeric_index_type j=0; j<this->n(); j++)
225  {
226  T c = (*this)(i,j);
227  if (c != static_cast<T>(0.0))
228  {
229  os << i << " " << j << " " << c << std::endl;
230  }
231  }
232  }
233  else
234  {
235  for (numeric_index_type j=0; j<this->n(); j++)
236  os << (*this)(i,j) << " ";
237  os << std::endl;
238  }
239  }
240 
241  std::vector<numeric_index_type> ibuf, jbuf;
242  std::vector<T> cbuf;
243  numeric_index_type currenti = this->_dof_map->end_dof();
244  for (processor_id_type p=1; p < this->n_processors(); ++p)
245  {
246  this->comm().receive(p, ibuf);
247  this->comm().receive(p, jbuf);
248  this->comm().receive(p, cbuf);
249  libmesh_assert_equal_to (ibuf.size(), jbuf.size());
250  libmesh_assert_equal_to (ibuf.size(), cbuf.size());
251 
252  if (ibuf.empty())
253  continue;
254  libmesh_assert_greater_equal (ibuf.front(), currenti);
255  libmesh_assert_greater_equal (ibuf.back(), ibuf.front());
256 
257  std::size_t currentb = 0;
258  for (;currenti <= ibuf.back(); ++currenti)
259  {
260  if(sparse)
261  {
262  for (numeric_index_type j=0; j<this->n(); j++)
263  {
264  if (currentb < ibuf.size() &&
265  ibuf[currentb] == currenti &&
266  jbuf[currentb] == j)
267  {
268  os << currenti << " " << j << " " << cbuf[currentb] << std::endl;
269  currentb++;
270  }
271  }
272  }
273  else
274  {
275  for (numeric_index_type j=0; j<this->n(); j++)
276  {
277  if (currentb < ibuf.size() &&
278  ibuf[currentb] == currenti &&
279  jbuf[currentb] == j)
280  {
281  os << cbuf[currentb] << " ";
282  currentb++;
283  }
284  else
285  os << static_cast<T>(0.0) << " ";
286  }
287  os << std::endl;
288  }
289  }
290  }
291  if(!sparse)
292  {
293  for (; currenti != this->m(); ++currenti)
294  {
295  for (numeric_index_type j=0; j<this->n(); j++)
296  os << static_cast<T>(0.0) << " ";
297  os << std::endl;
298  }
299  }
300  }
301  else
302  {
303  std::vector<numeric_index_type> ibuf, jbuf;
304  std::vector<T> cbuf;
305 
306  // We'll assume each processor has access to entire
307  // matrix rows, so (*this)(i,j) is valid if i is a local index.
308  for (numeric_index_type i=this->_dof_map->first_dof();
309  i!=this->_dof_map->end_dof(); ++i)
310  {
311  for (numeric_index_type j=0; j<this->n(); j++)
312  {
313  T c = (*this)(i,j);
314  if (c != static_cast<T>(0.0))
315  {
316  ibuf.push_back(i);
317  jbuf.push_back(j);
318  cbuf.push_back(c);
319  }
320  }
321  }
322  this->comm().send(0,ibuf);
323  this->comm().send(0,jbuf);
324  this->comm().send(0,cbuf);
325  }
326 }
virtual numeric_index_type n() const =0
virtual numeric_index_type m() const =0
processor_id_type n_processors() const
uint8_t processor_id_type
Definition: id_types.h:99
libmesh_assert(j)
virtual bool initialized() const
dof_id_type first_dof(const processor_id_type proc) const
Definition: dof_map.h:531
dof_id_type end_dof(const processor_id_type proc) const
Definition: dof_map.h:569
dof_id_type numeric_index_type
Definition: id_types.h:92
void send(const unsigned int dest_processor_id, const T &buf, const MessageTag &tag=no_tag) const
DofMap const * _dof_map
const Parallel::Communicator & comm() const
Status receive(const unsigned int dest_processor_id, T &buf, const MessageTag &tag=any_tag) const
processor_id_type processor_id() const
void libMesh::ReferenceCounter::print_info ( std::ostream &  out = libMesh::out)
staticinherited

Prints the reference information, by default to libMesh::out.

Definition at line 88 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter, and libMesh::ReferenceCounter::get_info().

Referenced by libMesh::LibMeshInit::LibMeshInit().

89 {
91 }
static std::string get_info()
template<typename T >
void libMesh::PetscMatrix< T >::print_matlab ( const std::string &  name = "") const
virtual

Print the contents of the matrix in Matlab's sparse matrix format. Optionally prints the matrix to the file named name. If name is not specified it is dumped to the screen.

Create an ASCII file containing the matrix if a filename was provided.

Otherwise the matrix will be dumped to the screen.

Destroy the viewer.

Reimplemented from libMesh::SparseMatrix< T >.

Definition at line 530 of file petsc_matrix.C.

References ierr, libMesh::initialized(), and libMesh::libmesh_assert().

Referenced by libMesh::PetscMatrix< T >::add_block_matrix().

531 {
532  libmesh_assert (this->initialized());
533 
534  semiparallel_only();
535 
536  // libmesh_assert (this->closed());
537  this->close();
538 
539  PetscErrorCode ierr=0;
540  PetscViewer petsc_viewer;
541 
542 
543  ierr = PetscViewerCreate (this->comm().get(),
544  &petsc_viewer);
545  LIBMESH_CHKERR(ierr);
546 
551  if (name != "")
552  {
553  ierr = PetscViewerASCIIOpen( this->comm().get(),
554  name.c_str(),
555  &petsc_viewer);
556  LIBMESH_CHKERR(ierr);
557 
558 #if PETSC_VERSION_LESS_THAN(3,7,0)
559  ierr = PetscViewerSetFormat (petsc_viewer,
560  PETSC_VIEWER_ASCII_MATLAB);
561 #else
562  ierr = PetscViewerPushFormat (petsc_viewer,
563  PETSC_VIEWER_ASCII_MATLAB);
564 #endif
565 
566  LIBMESH_CHKERR(ierr);
567 
568  ierr = MatView (_mat, petsc_viewer);
569  LIBMESH_CHKERR(ierr);
570  }
571 
575  else
576  {
577 #if PETSC_VERSION_LESS_THAN(3,7,0)
578  ierr = PetscViewerSetFormat (PETSC_VIEWER_STDOUT_WORLD,
579  PETSC_VIEWER_ASCII_MATLAB);
580 #else
581  ierr = PetscViewerPushFormat (PETSC_VIEWER_STDOUT_WORLD,
582  PETSC_VIEWER_ASCII_MATLAB);
583 #endif
584 
585  LIBMESH_CHKERR(ierr);
586 
587  ierr = MatView (_mat, PETSC_VIEWER_STDOUT_WORLD);
588  LIBMESH_CHKERR(ierr);
589  }
590 
591 
595  ierr = LibMeshPetscViewerDestroy (&petsc_viewer);
596  LIBMESH_CHKERR(ierr);
597 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
virtual void close() const libmesh_override
Definition: petsc_matrix.C:881
libmesh_assert(j)
virtual bool initialized() const
PetscErrorCode ierr
const Parallel::Communicator & comm() const
template<typename T >
void libMesh::PetscMatrix< T >::print_personal ( std::ostream &  os = libMesh::out) const
virtual

Print the contents of the matrix to the screen with the PETSc viewer. This function only allows printing to standard out, this is because we have limited ourselves to one PETSc implementation for writing.

Implements libMesh::SparseMatrix< T >.

Definition at line 604 of file petsc_matrix.C.

References ierr, libMesh::initialized(), libMesh::libmesh_assert(), and libMesh::processor_id().

Referenced by libMesh::PetscMatrix< T >::add_block_matrix().

605 {
606  libmesh_assert (this->initialized());
607 
608  // Routine must be called in parallel on parallel matrices
609  // and serial on serial matrices.
610  semiparallel_only();
611 
612  // #ifndef NDEBUG
613  // if (os != std::cout)
614  // libMesh::err << "Warning! PETSc can only print to std::cout!" << std::endl;
615  // #endif
616 
617  // Matrix must be in an assembled state to be printed
618  this->close();
619 
620  PetscErrorCode ierr=0;
621 
622  // Print to screen if ostream is stdout
623  if (os.rdbuf() == std::cout.rdbuf())
624  {
625  ierr = MatView(_mat, PETSC_VIEWER_STDOUT_SELF);
626  LIBMESH_CHKERR(ierr);
627  }
628 
629  // Otherwise, print to the requested file, in a roundabout way...
630  else
631  {
632  // We will create a temporary filename, and file, for PETSc to
633  // write to.
634  std::string temp_filename;
635 
636  {
637  // Template for temporary filename
638  char c[] = "temp_petsc_matrix.XXXXXX";
639 
640  // Generate temporary, unique filename only on processor 0. We will
641  // use this filename for PetscViewerASCIIOpen, before copying it into
642  // the user's stream
643  if (this->processor_id() == 0)
644  {
645  int fd = mkstemp(c);
646 
647  // Check to see that mkstemp did not fail.
648  if (fd == -1)
649  libmesh_error_msg("mkstemp failed in PetscMatrix::print_personal()");
650 
651  // mkstemp returns a file descriptor for an open file,
652  // so let's close it before we hand it to PETSc!
653  ::close (fd);
654  }
655 
656  // Store temporary filename as string, makes it easier to broadcast
657  temp_filename = c;
658  }
659 
660  // Now broadcast the filename from processor 0 to all processors.
661  this->comm().broadcast(temp_filename);
662 
663  // PetscViewer object for passing to MatView
664  PetscViewer petsc_viewer;
665 
666  // This PETSc function only takes a string and handles the opening/closing
667  // of the file internally. Since print_personal() takes a reference to
668  // an ostream, we have to do an extra step... print_personal() should probably
669  // have a version that takes a string to get rid of this problem.
670  ierr = PetscViewerASCIIOpen( this->comm().get(),
671  temp_filename.c_str(),
672  &petsc_viewer);
673  LIBMESH_CHKERR(ierr);
674 
675  // Probably don't need to set the format if it's default...
676  // ierr = PetscViewerSetFormat (petsc_viewer,
677  // PETSC_VIEWER_DEFAULT);
678  // LIBMESH_CHKERR(ierr);
679 
680  // Finally print the matrix using the viewer
681  ierr = MatView (_mat, petsc_viewer);
682  LIBMESH_CHKERR(ierr);
683 
684  if (this->processor_id() == 0)
685  {
686  // Now the inefficient bit: open temp_filename as an ostream and copy the contents
687  // into the user's desired ostream. We can't just do a direct file copy, we don't even have the filename!
688  std::ifstream input_stream(temp_filename.c_str());
689  os << input_stream.rdbuf(); // The "most elegant" way to copy one stream into another.
690  // os.close(); // close not defined in ostream
691 
692  // Now remove the temporary file
693  input_stream.close();
694  std::remove(temp_filename.c_str());
695  }
696  }
697 }
virtual void close() const libmesh_override
Definition: petsc_matrix.C:881
libmesh_assert(j)
virtual bool initialized() const
void broadcast(T &data, const unsigned int root_id=0) const
PetscErrorCode ierr
const Parallel::Communicator & comm() const
processor_id_type processor_id() const
processor_id_type libMesh::ParallelObject::processor_id ( ) const
inlineinherited
Returns
the rank of this processor in the group.

Definition at line 99 of file parallel_object.h.

References libMesh::ParallelObject::_communicator, and libMesh::Parallel::Communicator::rank().

Referenced by libMesh::BoundaryInfo::_find_id_maps(), libMesh::EquationSystems::_read_impl(), libMesh::DistributedMesh::add_elem(), libMesh::BoundaryInfo::add_elements(), libMesh::DofMap::add_neighbors_to_send_list(), libMesh::DistributedMesh::add_node(), libMesh::MeshRefinement::add_node(), libMesh::MeshTools::Modification::all_tri(), libMesh::FEMSystem::assembly(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::MeshCommunication::broadcast(), libMesh::EquationSystems::build_discontinuous_solution_vector(), libMesh::Nemesis_IO_Helper::build_element_and_node_maps(), libMesh::ParmetisPartitioner::build_graph(), libMesh::InfElemBuilder::build_inf_elem(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::DofMap::build_sparsity(), libMesh::DistributedMesh::clear(), libMesh::ExodusII_IO_Helper::close(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::compute_communication_map_parameters(), libMesh::Nemesis_IO_Helper::compute_internal_and_border_elems_and_internal_nodes(), libMesh::Nemesis_IO_Helper::compute_node_communication_maps(), libMesh::Nemesis_IO_Helper::compute_num_global_elem_blocks(), libMesh::Nemesis_IO_Helper::compute_num_global_nodesets(), libMesh::Nemesis_IO_Helper::compute_num_global_sidesets(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::ExodusII_IO_Helper::create(), libMesh::DistributedMesh::delete_elem(), libMesh::DistributedMesh::delete_node(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::DistributedMesh::DistributedMesh(), libMesh::EnsightIO::EnsightIO(), libMesh::MeshFunction::find_element(), libMesh::MeshFunction::find_elements(), libMesh::UnstructuredMesh::find_neighbors(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::Nemesis_IO_Helper::get_cmap_params(), libMesh::Nemesis_IO_Helper::get_eb_info_global(), libMesh::Nemesis_IO_Helper::get_elem_cmap(), libMesh::Nemesis_IO_Helper::get_elem_map(), libMesh::MeshBase::get_info(), libMesh::DofMap::get_info(), libMesh::Nemesis_IO_Helper::get_init_global(), libMesh::Nemesis_IO_Helper::get_init_info(), libMesh::Nemesis_IO_Helper::get_loadbal_param(), libMesh::Nemesis_IO_Helper::get_node_cmap(), libMesh::Nemesis_IO_Helper::get_node_map(), libMesh::Nemesis_IO_Helper::get_ns_param_global(), libMesh::EquationSystems::get_solution(), libMesh::Nemesis_IO_Helper::get_ss_param_global(), libMesh::SparsityPattern::Build::handle_vi_vj(), libMesh::DistributedVector< T >::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::ParmetisPartitioner::initialize(), libMesh::ExodusII_IO_Helper::initialize(), libMesh::ExodusII_IO_Helper::initialize_element_variables(), libMesh::ExodusII_IO_Helper::initialize_global_variables(), libMesh::ExodusII_IO_Helper::initialize_nodal_variables(), libMesh::DistributedMesh::insert_elem(), libMesh::DofMap::is_evaluable(), libMesh::SparsityPattern::Build::join(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DofMap::local_variable_indices(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshBase::n_active_local_elem(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::System::n_local_dofs(), libMesh::MeshBase::n_local_elem(), libMesh::MeshBase::n_local_nodes(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::BoundaryInfo::n_shellface_conds(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SparsityPattern::Build::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::MetisPartitioner::partition_range(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::SparseMatrix< T >::print(), libMesh::NumericVector< T >::print_global(), libMesh::Nemesis_IO_Helper::put_cmap_params(), libMesh::Nemesis_IO_Helper::put_elem_cmap(), libMesh::Nemesis_IO_Helper::put_elem_map(), libMesh::Nemesis_IO_Helper::put_loadbal_param(), libMesh::Nemesis_IO_Helper::put_node_cmap(), libMesh::Nemesis_IO_Helper::put_node_map(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::XdrIO::read(), libMesh::ExodusII_IO_Helper::read_elem_num_map(), libMesh::ExodusII_IO_Helper::read_node_num_map(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::MeshCommunication::redistribute(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::MeshTools::total_weight(), libMesh::Parallel::Packing< Node * >::unpack(), libMesh::Parallel::Packing< Elem * >::unpack(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::MeshTools::weight(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), libMesh::EquationSystems::write(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::ExodusII_IO::write_element_data(), libMesh::ExodusII_IO_Helper::write_element_values(), libMesh::ExodusII_IO_Helper::write_elements(), libMesh::ExodusII_IO::write_global_data(), libMesh::ExodusII_IO_Helper::write_global_values(), libMesh::ExodusII_IO::write_information_records(), libMesh::ExodusII_IO_Helper::write_information_records(), libMesh::ExodusII_IO_Helper::write_nodal_coordinates(), libMesh::UCDIO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data_discontinuous(), libMesh::ExodusII_IO_Helper::write_nodal_values(), libMesh::Nemesis_IO_Helper::write_nodesets(), libMesh::ExodusII_IO_Helper::write_nodesets(), libMesh::XdrIO::write_serialized_bc_names(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::Nemesis_IO_Helper::write_sidesets(), libMesh::ExodusII_IO_Helper::write_sidesets(), libMesh::ExodusII_IO::write_timestep(), and libMesh::ExodusII_IO_Helper::write_timestep().

100  { return cast_int<processor_id_type>(_communicator.rank()); }
const Parallel::Communicator & _communicator
unsigned int rank() const
Definition: parallel.h:677
template<typename T>
virtual void libMesh::SparseMatrix< T >::reinit_submatrix ( SparseMatrix< T > &  submatrix,
const std::vector< numeric_index_type > &  rows,
const std::vector< numeric_index_type > &  cols 
) const
inlinevirtualinherited

This function is similar to the one above, but it allows you to reuse the existing sparsity pattern of "submatrix" instead of reallocating it again. This should hopefully be more efficient if you are frequently extracting submatrices of the same size.

Definition at line 384 of file sparse_matrix.h.

387  {
388  this->_get_submatrix(submatrix,
389  rows,
390  cols,
391  true); // true means REUSE submatrix
392  }
virtual void _get_submatrix(SparseMatrix< T > &, const std::vector< numeric_index_type > &, const std::vector< numeric_index_type > &, const bool) const
template<typename T >
numeric_index_type libMesh::PetscMatrix< T >::row_start ( ) const
virtual

return row_start, the index of the first matrix row stored on this processor

Implements libMesh::SparseMatrix< T >.

Definition at line 935 of file petsc_matrix.C.

References ierr, libMesh::initialized(), libMesh::libmesh_assert(), and libMesh::MacroFunctions::stop().

936 {
937  libmesh_assert (this->initialized());
938 
939  PetscInt start=0, stop=0;
940  PetscErrorCode ierr=0;
941 
942  ierr = MatGetOwnershipRange(_mat, &start, &stop);
943  LIBMESH_CHKERR(ierr);
944 
945  return static_cast<numeric_index_type>(start);
946 }
libmesh_assert(j)
virtual bool initialized() const
dof_id_type numeric_index_type
Definition: id_types.h:92
void stop(const char *file, int line, const char *date, const char *time)
PetscErrorCode ierr
template<typename T >
numeric_index_type libMesh::PetscMatrix< T >::row_stop ( ) const
virtual

return row_stop, the index of the last matrix row (+1) stored on this processor

Implements libMesh::SparseMatrix< T >.

Definition at line 951 of file petsc_matrix.C.

References ierr, libMesh::initialized(), libMesh::libmesh_assert(), and libMesh::MacroFunctions::stop().

952 {
953  libmesh_assert (this->initialized());
954 
955  PetscInt start=0, stop=0;
956  PetscErrorCode ierr=0;
957 
958  ierr = MatGetOwnershipRange(_mat, &start, &stop);
959  LIBMESH_CHKERR(ierr);
960 
961  return static_cast<numeric_index_type>(stop);
962 }
libmesh_assert(j)
virtual bool initialized() const
dof_id_type numeric_index_type
Definition: id_types.h:92
void stop(const char *file, int line, const char *date, const char *time)
PetscErrorCode ierr
template<typename T >
void libMesh::PetscMatrix< T >::set ( const numeric_index_type  i,
const numeric_index_type  j,
const T  value 
)
virtual

Set the element (i,j) to value. Throws an error if the entry does not exist. Still, it is allowed to store zero values in non-existent fields.

Implements libMesh::SparseMatrix< T >.

Definition at line 967 of file petsc_matrix.C.

References ierr, libMesh::initialized(), and libMesh::libmesh_assert().

970 {
971  libmesh_assert (this->initialized());
972 
973  PetscErrorCode ierr=0;
974  PetscInt i_val=i, j_val=j;
975 
976  PetscScalar petsc_value = static_cast<PetscScalar>(value);
977  ierr = MatSetValues(_mat, 1, &i_val, 1, &j_val,
978  &petsc_value, INSERT_VALUES);
979  LIBMESH_CHKERR(ierr);
980 }
libmesh_assert(j)
virtual bool initialized() const
PetscErrorCode ierr
template<typename T >
void libMesh::PetscMatrix< T >::swap ( PetscMatrix< T > &  m_in)

Swaps the raw PETSc matrix context pointers.

Definition at line 1121 of file petsc_matrix.C.

References libMesh::PetscMatrix< T >::_destroy_mat_on_exit, libMesh::PetscMatrix< T >::_mat, and swap().

Referenced by libMesh::PetscMatrix< T >::add_block_matrix().

1122 {
1123  std::swap(_mat, m_in._mat);
1125 }
void swap(Iterator &lhs, Iterator &rhs)
template<typename T >
void libMesh::PetscMatrix< T >::update_preallocation_and_zero ( )

Update the sparsity pattern based on dof_map, and set the matrix to zero. This is useful in cases where the sparsity pattern changes during a computation.

Definition at line 406 of file petsc_matrix.C.

407 {
408  libmesh_not_implemented();
409 }
template<typename T>
virtual void libMesh::SparseMatrix< T >::update_sparsity_pattern ( const SparsityPattern::Graph )
inlinevirtualinherited

Updates the matrix sparsity pattern. When your SparseMatrix<T> implementation does not need this data simply do not overload this method.

Reimplemented in libMesh::EpetraMatrix< T >, and libMesh::LaspackMatrix< T >.

Definition at line 130 of file sparse_matrix.h.

Referenced by libMesh::DofMap::attach_matrix().

130 {}
template<typename T>
void libMesh::SparseMatrix< T >::vector_mult ( NumericVector< T > &  dest,
const NumericVector< T > &  arg 
) const
inherited

Multiplies the matrix with arg and stores the result in dest.

Definition at line 175 of file sparse_matrix.C.

References libMesh::SparseMatrix< T >::vector_mult_add(), and libMesh::NumericVector< T >::zero().

Referenced by libMesh::ImplicitSystem::qoi_parameter_hessian(), and libMesh::ImplicitSystem::qoi_parameter_hessian_vector_product().

177 {
178  dest.zero();
179  this->vector_mult_add(dest,arg);
180 }
void vector_mult_add(NumericVector< T > &dest, const NumericVector< T > &arg) const
template<typename T>
void libMesh::SparseMatrix< T >::vector_mult_add ( NumericVector< T > &  dest,
const NumericVector< T > &  arg 
) const
inherited

Multiplies the matrix with arg and adds the result to dest.

Definition at line 185 of file sparse_matrix.C.

References libMesh::NumericVector< T >::add_vector().

Referenced by libMesh::SparseMatrix< T >::vector_mult(), and libMesh::ImplicitSystem::weighted_sensitivity_adjoint_solve().

187 {
188  /* This functionality is actually implemented in the \p
189  NumericVector class. */
190  dest.add_vector(arg,*this);
191 }
template<typename T >
void libMesh::PetscMatrix< T >::zero ( )
virtual

Set all entries to 0. This method retains sparsity structure.

Implements libMesh::SparseMatrix< T >.

Definition at line 413 of file petsc_matrix.C.

References ierr, libMesh::initialized(), and libMesh::libmesh_assert().

414 {
415  libmesh_assert (this->initialized());
416 
417  semiparallel_only();
418 
419  PetscErrorCode ierr=0;
420 
421  PetscInt m_l, n_l;
422 
423  ierr = MatGetLocalSize(_mat,&m_l,&n_l);
424  LIBMESH_CHKERR(ierr);
425 
426  if (n_l)
427  {
428  ierr = MatZeroEntries(_mat);
429  LIBMESH_CHKERR(ierr);
430  }
431 }
libmesh_assert(j)
virtual bool initialized() const
PetscErrorCode ierr
template<typename T >
void libMesh::PetscMatrix< T >::zero_rows ( std::vector< numeric_index_type > &  rows,
diag_value = 0.0 
)
virtual

Set all row entries to 0 then puts diag_value in the diagonal entry

Reimplemented from libMesh::SparseMatrix< T >.

Definition at line 434 of file petsc_matrix.C.

References ierr, libMesh::initialized(), libMesh::libmesh_assert(), and libMesh::numeric_petsc_cast().

435 {
436  libmesh_assert (this->initialized());
437 
438  semiparallel_only();
439 
440  PetscErrorCode ierr=0;
441 
442 #if PETSC_RELEASE_LESS_THAN(3,1,1)
443  if(!rows.empty())
444  ierr = MatZeroRows(_mat, rows.size(),
445  numeric_petsc_cast(&rows[0]), diag_value);
446  else
447  ierr = MatZeroRows(_mat, 0, PETSC_NULL, diag_value);
448 #else
449  // As of petsc-dev at the time of 3.1.0, MatZeroRows now takes two additional
450  // optional arguments. The optional arguments (x,b) can be used to specify the
451  // solutions for the zeroed rows (x) and right hand side (b) to update.
452  // Could be useful for setting boundary conditions...
453  if(!rows.empty())
454  ierr = MatZeroRows(_mat, cast_int<PetscInt>(rows.size()),
455  numeric_petsc_cast(&rows[0]), diag_value,
456  PETSC_NULL, PETSC_NULL);
457  else
458  ierr = MatZeroRows(_mat, 0, PETSC_NULL, diag_value, PETSC_NULL,
459  PETSC_NULL);
460 #endif
461 
462  LIBMESH_CHKERR(ierr);
463 }
libmesh_assert(j)
PetscInt * numeric_petsc_cast(const numeric_index_type *p)
virtual bool initialized() const
PetscErrorCode ierr

Member Data Documentation

ReferenceCounter::Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited
template<typename T>
bool libMesh::PetscMatrix< T >::_destroy_mat_on_exit
private

This boolean value should only be set to false for the constructor which takes a PETSc Mat object.

Definition at line 394 of file petsc_matrix.h.

Referenced by libMesh::PetscMatrix< T >::swap().

template<typename T>
DofMap const* libMesh::SparseMatrix< T >::_dof_map
protectedinherited

The DofMap object associated with this object.

Definition at line 436 of file sparse_matrix.h.

Referenced by libMesh::SparseMatrix< T >::print().

bool libMesh::ReferenceCounter::_enable_print_counter = true
staticprotectedinherited

Flag to control whether reference count information is printed when print_info is called.

Definition at line 134 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::disable_print_counter_info(), libMesh::ReferenceCounter::enable_print_counter_info(), and libMesh::ReferenceCounter::print_info().

template<typename T>
bool libMesh::SparseMatrix< T >::_is_initialized
protectedinherited

Flag indicating whether or not the matrix has been initialized.

Definition at line 442 of file sparse_matrix.h.

Referenced by libMesh::PetscMatrix< T >::_get_submatrix(), libMesh::EigenSparseMatrix< T >::clear(), libMesh::LaspackMatrix< T >::clear(), and libMesh::PetscMatrix< T >::get_transpose().

Threads::spin_mutex libMesh::ReferenceCounter::_mutex
staticprotectedinherited

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 128 of file reference_counter.h.

Threads::atomic< unsigned int > libMesh::ReferenceCounter::_n_objects
staticprotectedinherited

The number of objects. Print the reference count information when the number returns to 0.

Definition at line 123 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::n_objects(), libMesh::ReferenceCounter::ReferenceCounter(), and libMesh::ReferenceCounter::~ReferenceCounter().


The documentation for this class was generated from the following files: