20#include "libmesh/libmesh_config.h"
22#ifdef LIBMESH_HAVE_PETSC
25#include "libmesh/petsc_matrix_base.h"
26#include "libmesh/petsc_matrix_shell_matrix.h"
27#include "libmesh/petsc_matrix.h"
42 _destroy_mat_on_exit(true)
52 const bool destroy_on_exit) :
54 _destroy_mat_on_exit(destroy_on_exit)
76 if ((this->
initialized()) && (this->_destroy_mat_on_exit))
78 exceptionless_semiparallel_only();
82 PetscErrorCode ierr = MatDestroy (&_mat);
84 libmesh_warning(
"Warning: MatDestroy returned a non-zero error code which we ignored.");
86 this->_is_initialized =
false;
93 this->_destroy_mat_on_exit = destroy;
100 std::swap(_mat, m_in.
_mat);
108 PetscContainer container;
109 LibmeshPetscCall(PetscContainerCreate(this->comm().get(), &container));
110 LibmeshPetscCall(PetscContainerSetPointer(container,
this));
111 LibmeshPetscCall(PetscObjectCompose((PetscObject)(Mat)this->_mat,
"PetscMatrixCtx", (PetscObject)container));
112 LibmeshPetscCall(PetscContainerDestroy(&container));
119 PetscContainer container;
120 LibmeshPetscCall2(comm, PetscObjectQuery((PetscObject)mat,
"PetscMatrixCtx", (PetscObject *)&container));
124 LibmeshPetscCall2(comm, PetscContainerGetPointer(container, &
ctx));
134 PetscInt petsc_m=0, petsc_n=0;
136 LibmeshPetscCall(MatGetSize (this->_mat, &petsc_m, &petsc_n));
148 LibmeshPetscCall(MatGetLocalSize (this->_mat, &m, NULL));
158 PetscInt petsc_m=0, petsc_n=0;
160 LibmeshPetscCall(MatGetSize (this->_mat, &petsc_m, &petsc_n));
172 LibmeshPetscCall(MatGetLocalSize (this->_mat, NULL, &n));
182 PetscInt start=0, stop=0;
184 LibmeshPetscCall(MatGetOwnershipRange(this->_mat, &start, &stop));
194 PetscInt start=0, stop=0;
196 LibmeshPetscCall(MatGetOwnershipRange(this->_mat, &start, &stop));
206 PetscInt start=0, stop=0;
208 LibmeshPetscCall(MatGetOwnershipRangeColumn(this->_mat, &start, &stop));
218 PetscInt start=0, stop=0;
220 LibmeshPetscCall(MatGetOwnershipRangeColumn(this->_mat, &start, &stop));
237 MatAssemblyBeginEnd(this->comm(), this->_mat, MAT_FINAL_ASSEMBLY);
247 LibmeshPetscCall(MatAssembled(this->_mat, &assembled));
249 return (assembled == PETSC_TRUE);
This class provides a nice interface to the PETSc C-based data structures for parallel,...
void swap(PetscMatrixBase< T > &)
Swaps the internal data pointers of two PetscMatrices, no actual values are swapped.
virtual numeric_index_type n() const override
static PetscMatrixBase< T > * get_context(Mat mat, const TIMPI::Communicator &comm)
virtual numeric_index_type local_m() const final
Get the number of rows owned by this process.
bool _destroy_mat_on_exit
This boolean value should only be set to false for the constructor which takes a PETSc Mat object.
virtual numeric_index_type col_start() const override
void set_context()
Set the context (ourself) for _mat.
virtual void close() override
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
virtual ~PetscMatrixBase()
virtual numeric_index_type m() const override
PetscMatrixBase(const Parallel::Communicator &comm_in)
virtual bool closed() const override
virtual numeric_index_type local_n() const final
Get the number of columns owned by this process.
virtual numeric_index_type col_stop() const override
virtual numeric_index_type row_start() const override
Mat _mat
PETSc matrix datatype to store values.
virtual void clear() noexcept override
clear() is called from the destructor, so it should not throw.
virtual numeric_index_type row_stop() const override
void set_destroy_mat_on_exit(bool destroy=true)
If set to false, we don't delete the Mat on destruction and allow instead for PETSc to manage it.
bool _is_initialized
Flag indicating whether or not the matrix has been initialized.
The libMesh namespace provides an interface to certain functionality in the library.
dof_id_type numeric_index_type
bool initialized()
Checks that library initialization has been done.