#include <petsc_matrix.h>
PetscMatrix ()
PetscMatrix (Mat m)
~PetscMatrix ()
void init (const unsigned int m, const unsigned int n, const unsigned int m_l, const unsigned int n_l, const unsigned int nnz=30, const unsigned int noz=10)
void init ()
void clear ()
void zero ()
void zero_rows (std::vector< int > &rows, T diag_value=0.0)
void close () const
unsigned int m () const
unsigned int n () const
unsigned int row_start () const
unsigned int row_stop () const
void set (const unsigned int i, const unsigned int j, const T value)
void add (const unsigned int i, const unsigned int j, const T value)
void add_matrix (const DenseMatrix< T > &dm, const std::vector< unsigned int > &rows, const std::vector< unsigned int > &cols)
void add_matrix (const DenseMatrix< T > &dm, const std::vector< unsigned int > &dof_indices)
void add (const T a, SparseMatrix< T > &X)
T operator() (const unsigned int i, const unsigned int j) const
Real l1_norm () const
Real linfty_norm () const
bool closed () const
void print_personal (std::ostream &os=std::cout) const
void print_matlab (const std::string name='NULL') const
virtual void get_diagonal (NumericVector< T > &dest) const
virtual void get_transpose (SparseMatrix< T > &dest) const
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=std::cout) const
template<> void print (std::ostream &os) const
virtual void create_submatrix (SparseMatrix< T > &submatrix, const std::vector< unsigned int > &rows, const std::vector< unsigned int > &cols) const
virtual void reinit_submatrix (SparseMatrix< T > &submatrix, const std::vector< unsigned int > &rows, const std::vector< unsigned int > &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
static AutoPtr< SparseMatrix< T > > build (const SolverPackage solver_package=libMesh::default_solver_package())
static std::string get_info ()
static void print_info ()
static unsigned int n_objects ()
typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
virtual void _get_submatrix (SparseMatrix< T > &submatrix, const std::vector< unsigned int > &rows, const std::vector< unsigned int > &cols, const bool reuse_submatrix) const
void increment_constructor_count (const std::string &name)
void increment_destructor_count (const std::string &name)
DofMap const * _dof_map
bool _is_initialized
static Counts _counts
static Threads::atomic< unsigned int > _n_objects
static Threads::spin_mutex _mutex
Mat _mat
bool _destroy_mat_on_exit
template<typename U > std::ostream & operator<< (std::ostream &os, const SparseMatrix< U > &m)
Author:
Definition at line 76 of file petsc_matrix.h.
Definition at line 105 of file reference_counter.h.
You have to initialize the matrix before usage with init(...).
Definition at line 366 of file petsc_matrix.h.
: _destroy_mat_on_exit(true)
{}
Definition at line 375 of file petsc_matrix.h.
References SparseMatrix< T >::_is_initialized, PetscMatrix< T >::_mat, and PetscMatrix< T >::m().
: _destroy_mat_on_exit(false)
{
this->_mat = m;
this->_is_initialized = true;
}
Definition at line 387 of file petsc_matrix.h.
{
this->clear();
}
Reimplemented from SparseMatrix< T >.
Definition at line 362 of file petsc_matrix.C.
References SparseMatrix< T >::_is_initialized, PetscMatrix< T >::_mat, SparseMatrix< T >::clear(), PetscMatrix< T >::close(), libMesh::close(), libMesh::COMM_WORLD, and SparseMatrix< T >::initialized().
{
// Can only extract submatrices from closed matrices
this->close();
// Make sure the SparseMatrix passed in is really a PetscMatrix
PetscMatrix<T>* petsc_submatrix = libmesh_cast_ptr<PetscMatrix<T>*>(&submatrix);
// If we're not reusing submatrix and submatrix is already initialized
// then we need to clear it, otherwise we get a memory leak.
if( !reuse_submatrix && submatrix.initialized() )
submatrix.clear();
// Construct row and column index sets.
int ierr=0;
IS isrow, iscol;
ierr = ISCreateGeneral(libMesh::COMM_WORLD,
rows.size(),
(int*) &rows[0],
&isrow); CHKERRABORT(libMesh::COMM_WORLD,ierr);
ierr = ISCreateGeneral(libMesh::COMM_WORLD,
cols.size(),
(int*) &cols[0],
&iscol); CHKERRABORT(libMesh::COMM_WORLD,ierr);
// Extract submatrix
#if !PETSC_VERSION_LESS_THAN(3,0,1) || !PETSC_VERSION_RELEASE
ierr = MatGetSubMatrix(_mat,
isrow,
iscol,
(reuse_submatrix ? MAT_REUSE_MATRIX : MAT_INITIAL_MATRIX),
&(petsc_submatrix->_mat)); CHKERRABORT(libMesh::COMM_WORLD,ierr);
#else
ierr = MatGetSubMatrix(_mat,
isrow,
iscol,
PETSC_DECIDE,
(reuse_submatrix ? MAT_REUSE_MATRIX : MAT_INITIAL_MATRIX),
&(petsc_submatrix->_mat)); CHKERRABORT(libMesh::COMM_WORLD,ierr);
#endif
// Specify that the new submatrix is initialized and close it.
petsc_submatrix->_is_initialized = true;
petsc_submatrix->close();
// Clean up PETSc data structures
ierr = ISDestroy(isrow); CHKERRABORT(libMesh::COMM_WORLD,ierr);
ierr = ISDestroy(iscol); CHKERRABORT(libMesh::COMM_WORLD,ierr);
}
Implements SparseMatrix< T >.
Definition at line 499 of file petsc_matrix.h.
References libMesh::COMM_WORLD, and libMesh::initialized().
{
libmesh_assert (this->initialized());
int ierr=0, i_val=i, j_val=j;
PetscScalar petsc_value = static_cast<PetscScalar>(value);
ierr = MatSetValues(_mat, 1, &i_val, 1, &j_val,
&petsc_value, ADD_VALUES);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
}
Implements SparseMatrix< T >.
Definition at line 531 of file petsc_matrix.h.
References PetscMatrix< T >::_mat, PetscMatrix< T >::closed(), libMesh::COMM_WORLD, libMesh::initialized(), SparseMatrix< T >::m(), and SparseMatrix< T >::n().
{
libmesh_assert (this->initialized());
// sanity check. but this cannot avoid
// crash due to incompatible sparsity structure...
libmesh_assert (this->m() == X_in.m());
libmesh_assert (this->n() == X_in.n());
PetscScalar a = static_cast<PetscScalar> (a_in);
PetscMatrix<T>* X = dynamic_cast<PetscMatrix<T>*> (&X_in);
libmesh_assert (X != NULL);
int ierr=0;
// the matrix from which we copy the values has to be assembled/closed
// X->close ();
libmesh_assert(X->closed());
semiparallel_only();
// 2.2.x & earlier style
#if PETSC_VERSION_LESS_THAN(2,3,0)
ierr = MatAXPY(&a, X->_mat, _mat, SAME_NONZERO_PATTERN);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
// 2.3.x & newer
#else
ierr = MatAXPY(_mat, a, X->_mat, DIFFERENT_NONZERO_PATTERN);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
#endif
}
Implements SparseMatrix< T >.
Definition at line 334 of file petsc_matrix.C.
References libMesh::COMM_WORLD, DenseMatrix< T >::get_values(), libMesh::initialized(), DenseMatrixBase< T >::m(), and DenseMatrixBase< T >::n().
{
libmesh_assert (this->initialized());
const unsigned int m = dm.m();
const unsigned int n = dm.n();
libmesh_assert (rows.size() == m);
libmesh_assert (cols.size() == n);
int ierr=0;
// These casts are required for PETSc <= 2.1.5
ierr = MatSetValues(_mat,
m, (int*) &rows[0],
n, (int*) &cols[0],
(PetscScalar*) &dm.get_values()[0],
ADD_VALUES);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
}
Implements SparseMatrix< T >.
Definition at line 517 of file petsc_matrix.h.
{
this->add_matrix (dm, dof_indices, dof_indices);
}
Definition at line 100 of file sparse_matrix.h.
Referenced by DofMap::attach_matrix().
{ _dof_map = &dof_map; }
Definition at line 40 of file sparse_matrix.C.
References LASPACK_SOLVERS, libMeshEnums::PETSC_SOLVERS, and TRILINOS_SOLVERS.
{
// Build the appropriate vector
switch (solver_package)
{
#ifdef LIBMESH_HAVE_LASPACK
case LASPACK_SOLVERS:
{
AutoPtr<SparseMatrix<T> > ap(new LaspackMatrix<T>);
return ap;
}
#endif
#ifdef LIBMESH_HAVE_PETSC
case PETSC_SOLVERS:
{
AutoPtr<SparseMatrix<T> > ap(new PetscMatrix<T>);
return ap;
}
#endif
#ifdef LIBMESH_HAVE_TRILINOS
case TRILINOS_SOLVERS:
{
AutoPtr<SparseMatrix<T> > ap(new EpetraMatrix<T>);
return ap;
}
#endif
default:
std::cerr << 'ERROR: Unrecognized solver package: '
<< solver_package
<< std::endl;
libmesh_error();
}
AutoPtr<SparseMatrix<T> > ap(NULL);
return ap;
}
Implements SparseMatrix< T >.
Definition at line 209 of file petsc_matrix.C.
References libMesh::libMeshPrivateData::_is_initialized, libMesh::COMM_WORLD, and libMesh::initialized().
{
int ierr=0;
if ((this->initialized()) && (this->_destroy_mat_on_exit))
{
semiparallel_only();
ierr = MatDestroy (_mat);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
this->_is_initialized = false;
}
}
Implements SparseMatrix< T >.
Definition at line 396 of file petsc_matrix.h.
References libMesh::COMM_WORLD.
Referenced by __libmesh_petsc_diff_solver_jacobian(), __libmesh_petsc_snes_jacobian(), PetscMatrix< T >::_get_submatrix(), PetscVector< T >::add_vector(), PetscMatrix< T >::get_transpose(), PetscLinearSolver< T >::solve(), PetscDiffSolver::solve(), SlepcEigenSolver< T >::solve_generalized(), and SlepcEigenSolver< T >::solve_standard().
{
parallel_only();
// BSK - 1/19/2004
// strictly this check should be OK, but it seems to
// fail on matrix-free matrices. Do they falsely
// state they are assembled? Check with the developers...
// if (this->closed())
// return;
int ierr=0;
ierr = MatAssemblyBegin (_mat, MAT_FINAL_ASSEMBLY);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
ierr = MatAssemblyEnd (_mat, MAT_FINAL_ASSEMBLY);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
}
Implements SparseMatrix< T >.
Definition at line 643 of file petsc_matrix.h.
References libMesh::COMM_WORLD, and libMesh::initialized().
Referenced by PetscMatrix< T >::add().
{
libmesh_assert (this->initialized());
int ierr=0;
PetscTruth assembled;
ierr = MatAssembled(_mat, &assembled);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
return (assembled == PETSC_TRUE);
}
Definition at line 325 of file sparse_matrix.h.
{
this->_get_submatrix(submatrix,
rows,
cols,
false); // false means DO NOT REUSE submatrix
}
Implements SparseMatrix< T >.
Definition at line 420 of file petsc_matrix.C.
References libMesh::COMM_WORLD, and PetscVector< T >::vec().
{
// Make sure the NumericVector passed in is really a PetscVector
PetscVector<T>& petsc_dest = libmesh_cast_ref<PetscVector<T>&>(dest);
// Call PETSc function.
#if PETSC_VERSION_LESS_THAN(2,3,1)
std::cout << 'This method has been developed with PETSc 2.3.1. '
<< 'No one has made it backwards compatible with older '
<< 'versions of PETSc so far; however, it might work '
<< 'without any change with some older version.' << std::endl;
libmesh_error();
#else
// Needs a const_cast since PETSc does not work with const.
int ierr =
MatGetDiagonal(const_cast<PetscMatrix<T>*>(this)->mat(),petsc_dest.vec()); CHKERRABORT(libMesh::COMM_WORLD,ierr);
#endif
}
Definition at line 45 of file reference_counter.C.
References ReferenceCounter::_counts, and Quality::name().
Referenced by ReferenceCounter::print_info().
{
#if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
std::ostringstream out;
out << '
<< ' ----------------------------------------------------------------------------
<< '| Reference count information |
<< ' ---------------------------------------------------------------------------- ;
for (Counts::iterator it = _counts.begin();
it != _counts.end(); ++it)
{
const std::string name(it->first);
const unsigned int creations = it->second.first;
const unsigned int destructions = it->second.second;
out << '| ' << name << ' reference count information:
<< '| Creations: ' << creations << '
<< '| Destructions: ' << destructions << ';
}
out << ' ---------------------------------------------------------------------------- ;
return out.str();
#else
return '';
#endif
}
Implements SparseMatrix< T >.
Definition at line 448 of file petsc_matrix.C.
References SparseMatrix< T >::_is_initialized, PetscMatrix< T >::_mat, SparseMatrix< T >::clear(), PetscMatrix< T >::close(), and libMesh::COMM_WORLD.
{
// Make sure the SparseMatrix passed in is really a PetscMatrix
PetscMatrix<T>& petsc_dest = libmesh_cast_ref<PetscMatrix<T>&>(dest);
// If we aren't reusing the matrix then need to clear dest,
// otherwise we get a memory leak
if(&petsc_dest != this)
dest.clear();
int ierr;
#if PETSC_VERSION_LESS_THAN(3,0,0)
if (&petsc_dest == this)
ierr = MatTranspose(_mat,PETSC_NULL);
else
ierr = MatTranspose(_mat,&petsc_dest._mat);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
#else
// FIXME - we can probably use MAT_REUSE_MATRIX in more situations
if (&petsc_dest == this)
ierr = MatTranspose(_mat,MAT_REUSE_MATRIX,&petsc_dest._mat);
else
ierr = MatTranspose(_mat,MAT_INITIAL_MATRIX,&petsc_dest._mat);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
#endif
// Specify that the transposed matrix is initialized and close it.
petsc_dest._is_initialized = true;
petsc_dest.close();
}
Definition at line 149 of file reference_counter.h.
References ReferenceCounter::_counts, Quality::name(), and Threads::spin_mtx.
Referenced by ReferenceCountedObject< Value >::ReferenceCountedObject().
{
Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
std::pair<unsigned int, unsigned int>& p = _counts[name];
p.first++;
}
Definition at line 167 of file reference_counter.h.
References ReferenceCounter::_counts, Quality::name(), and Threads::spin_mtx.
Referenced by ReferenceCountedObject< Value >::~ReferenceCountedObject().
{
Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
std::pair<unsigned int, unsigned int>& p = _counts[name];
p.second++;
}
Implements SparseMatrix< T >.
Definition at line 96 of file petsc_matrix.C.
References libMesh::libMeshPrivateData::_is_initialized, libMesh::COMM_WORLD, libMesh::initialized(), libMesh::n_processors(), and libMesh::zero.
{
libmesh_assert (this->_dof_map != NULL);
// Clear initialized matrices
if (this->initialized())
this->clear();
this->_is_initialized = true;
int proc_id = 0;
MPI_Comm_rank (libMesh::COMM_WORLD, &proc_id);
const unsigned int m = this->_dof_map->n_dofs();
const unsigned int n = m;
const unsigned int n_l = this->_dof_map->n_dofs_on_processor(proc_id);
const unsigned int m_l = n_l;
const std::vector<unsigned int>& n_nz = this->_dof_map->get_n_nz();
const std::vector<unsigned int>& n_oz = this->_dof_map->get_n_oz();
// Make sure the sparsity pattern isn't empty unless the matrix is 0x0
libmesh_assert (n_nz.size() == n_l);
libmesh_assert (n_oz.size() == n_l);
// We allow 0x0 matrices now
//if (m==0)
// return;
int ierr = 0;
int m_global = static_cast<int>(m);
int n_global = static_cast<int>(n);
int m_local = static_cast<int>(m_l);
int n_local = static_cast<int>(n_l);
// create a sequential matrix on one processor
if (libMesh::n_processors() == 1)
{
libmesh_assert ((m_l == m) && (n_l == n));
if (n_nz.empty())
ierr = MatCreateSeqAIJ (libMesh::COMM_WORLD, n_global, n_global,
PETSC_NULL, (int*) PETSC_NULL, &_mat);
else
ierr = MatCreateSeqAIJ (libMesh::COMM_WORLD, n_global, n_global,
PETSC_NULL, (int*) &n_nz[0], &_mat);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
ierr = MatSetFromOptions (_mat);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
}
else
{
parallel_only();
if (n_nz.empty())
ierr = MatCreateMPIAIJ (libMesh::COMM_WORLD,
m_local, n_local,
m_global, n_global,
PETSC_NULL, (int*) PETSC_NULL,
PETSC_NULL, (int*) PETSC_NULL, &_mat);
else
ierr = MatCreateMPIAIJ (libMesh::COMM_WORLD,
m_local, n_local,
m_global, n_global,
PETSC_NULL, (int*) &n_nz[0],
PETSC_NULL, (int*) &n_oz[0], &_mat);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
ierr = MatSetFromOptions (_mat);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
}
this->zero();
}
Implements SparseMatrix< T >.
Definition at line 37 of file petsc_matrix.C.
References libMesh::libMeshPrivateData::_is_initialized, libMesh::COMM_WORLD, libMesh::initialized(), libMesh::n_processors(), and libMesh::zero.
{
// We allow 0x0 matrices now
//if ((m==0) || (n==0))
// return;
// Clear initialized matrices
if (this->initialized())
this->clear();
this->_is_initialized = true;
int ierr = 0;
int m_global = static_cast<int>(m);
int n_global = static_cast<int>(n);
int m_local = static_cast<int>(m_l);
int n_local = static_cast<int>(n_l);
int n_nz = static_cast<int>(nnz);
int n_oz = static_cast<int>(noz);
// create a sequential matrix on one processor
if (libMesh::n_processors() == 1)
{
libmesh_assert ((m_l == m) && (n_l == n));
// Create matrix. Revisit later to do preallocation and make more efficient
ierr = MatCreateSeqAIJ (libMesh::COMM_WORLD, n_global, n_global,
n_nz, PETSC_NULL, &_mat);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
ierr = MatSetFromOptions (_mat);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
}
else
{
parallel_only();
ierr = MatCreateMPIAIJ (libMesh::COMM_WORLD, m_local, n_local, m_global, n_global,
n_nz, PETSC_NULL, n_oz, PETSC_NULL, &_mat);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
ierr = MatSetFromOptions (_mat);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
}
this->zero ();
}
Definition at line 95 of file sparse_matrix.h.
Referenced by PetscMatrix< T >::_get_submatrix(), ImplicitSystem::assemble(), and ImplicitSystem::init_matrices().
{ return _is_initialized; }
Implements SparseMatrix< T >.
Definition at line 227 of file petsc_matrix.C.
References libMesh::closed(), libMesh::COMM_WORLD, and libMesh::initialized().
{
libmesh_assert (this->initialized());
semiparallel_only();
int ierr=0;
PetscReal petsc_value;
Real value;
libmesh_assert (this->closed());
ierr = MatNorm(_mat, NORM_1, &petsc_value);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
value = static_cast<Real>(petsc_value);
return value;
}
Implements SparseMatrix< T >.
Definition at line 250 of file petsc_matrix.C.
References libMesh::closed(), libMesh::COMM_WORLD, and libMesh::initialized().
{
libmesh_assert (this->initialized());
semiparallel_only();
int ierr=0;
PetscReal petsc_value;
Real value;
libmesh_assert (this->closed());
ierr = MatNorm(_mat, NORM_INFINITY, &petsc_value);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
value = static_cast<Real>(petsc_value);
return value;
}
Implements SparseMatrix< T >.
Definition at line 419 of file petsc_matrix.h.
References libMesh::initialized().
Referenced by PetscMatrix< T >::PetscMatrix().
{
libmesh_assert (this->initialized());
int petsc_m=0, petsc_n=0, ierr=0;
ierr = MatGetSize (_mat, &petsc_m, &petsc_n);
return static_cast<unsigned int>(petsc_m);
}
Definition at line 327 of file petsc_matrix.h.
References PetscMatrix< T >::_mat.
Referenced by PetscPreconditioner< T >::init(), PetscLinearSolver< T >::init(), PetscNonlinearSolver< T >::solve(), PetscLinearSolver< T >::solve(), PetscDiffSolver::solve(), SlepcEigenSolver< T >::solve_generalized(), and SlepcEigenSolver< T >::solve_standard().
{ libmesh_assert (_mat != NULL); return _mat; }
Implements SparseMatrix< T >.
Definition at line 434 of file petsc_matrix.h.
References libMesh::initialized().
{
libmesh_assert (this->initialized());
int petsc_m=0, petsc_n=0, ierr=0;
ierr = MatGetSize (_mat, &petsc_m, &petsc_n);
return static_cast<unsigned int>(petsc_n);
}
Definition at line 76 of file reference_counter.h.
References ReferenceCounter::_n_objects.
Referenced by System::read_serialized_blocked_dof_objects(), and System::write_serialized_blocked_dof_objects().
{ return _n_objects; }
Reimplemented in LaspackMatrix< T >, and EpetraMatrix< T >.
Definition at line 110 of file sparse_matrix.h.
{ return false; }
In case you want a function that returns zero instead (for entries that are not in the sparsity pattern of the matrix), use the el function.
Implements SparseMatrix< T >.
Definition at line 573 of file petsc_matrix.h.
References libMesh::closed(), libMesh::COMM_WORLD, and libMesh::initialized().
{
libmesh_assert (this->initialized());
#if PETSC_VERSION_LESS_THAN(2,2,1)
// PETSc 2.2.0 & older
PetscScalar *petsc_row;
int* petsc_cols;
#else
// PETSc 2.2.1 & newer
const PetscScalar *petsc_row;
const PetscInt *petsc_cols;
#endif
// If the entry is not in the sparse matrix, it is 0.
T value=0.;
int
ierr=0,
ncols=0,
i_val=static_cast<int>(i),
j_val=static_cast<int>(j);
// the matrix needs to be closed for this to work
// this->close();
// but closing it is a semiparallel operation; we want operator()
// to run on one processor.
libmesh_assert(this->closed());
ierr = MatGetRow(_mat, i_val, &ncols, &petsc_cols, &petsc_row);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
// Perform a binary search to find the contiguous index in
// petsc_cols (resp. petsc_row) corresponding to global index j_val
std::pair<const int*, const int*> p =
std::equal_range (&petsc_cols[0], &petsc_cols[0] + ncols, j_val);
// Found an entry for j_val
if (p.first != p.second)
{
// The entry in the contiguous row corresponding
// to the j_val column of interest
const int j = std::distance (const_cast<int*>(&petsc_cols[0]),
const_cast<int*>(p.first));
libmesh_assert (j < ncols);
libmesh_assert (petsc_cols[j] == j_val);
value = static_cast<T> (petsc_row[j]);
}
ierr = MatRestoreRow(_mat, i_val,
&ncols, &petsc_cols, &petsc_row);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
return value;
}
Definition at line 118 of file sparse_matrix.C.
References libMesh::initialized(), libMesh::n_processors(), and libMesh::processor_id().
Referenced by LaspackMatrix< T >::print_personal().
{
parallel_only();
libmesh_assert (this->initialized());
// We'll print the matrix from processor 0 to make sure
// it's serialized properly
if (libMesh::processor_id() == 0)
{
libmesh_assert(this->_dof_map->first_dof() == 0);
for (unsigned int i=this->_dof_map->first_dof();
i!=this->_dof_map->end_dof(); ++i)
{
for (unsigned int j=0; j<this->n(); j++)
os << (*this)(i,j) << ' ';
os << std::endl;
}
std::vector<unsigned int> ibuf, jbuf;
std::vector<T> cbuf;
unsigned int currenti = this->_dof_map->end_dof();
for (unsigned int p=1; p < libMesh::n_processors(); ++p)
{
Parallel::receive(p, ibuf);
Parallel::receive(p, jbuf);
Parallel::receive(p, cbuf);
libmesh_assert(ibuf.size() == jbuf.size());
libmesh_assert(ibuf.size() == cbuf.size());
if (ibuf.empty())
continue;
libmesh_assert(ibuf.front() >= currenti);
libmesh_assert(ibuf.back() >= ibuf.front());
unsigned int currentb = 0;
for (;currenti <= ibuf.back(); ++currenti)
{
for (unsigned int j=0; j<this->n(); j++)
{
if (currentb < ibuf.size() &&
ibuf[currentb] == currenti &&
jbuf[currentb] == j)
{
os << cbuf[currentb] << ' ';
currentb++;
}
else
os << static_cast<T>(0.0) << ' ';
}
os << std::endl;
}
}
for (; currenti != this->m(); ++currenti)
{
for (unsigned int j=0; j<this->n(); j++)
os << static_cast<T>(0.0) << ' ';
os << std::endl;
}
}
else
{
std::vector<unsigned int> ibuf, jbuf;
std::vector<T> cbuf;
// We'll assume each processor has access to entire
// matrix rows, so (*this)(i,j) is valid if i is a local index.
for (unsigned int i=this->_dof_map->first_dof();
i!=this->_dof_map->end_dof(); ++i)
{
for (unsigned int j=0; j<this->n(); j++)
{
T c = (*this)(i,j);
if (c != static_cast<T>(0.0))
{
ibuf.push_back(i);
jbuf.push_back(j);
cbuf.push_back(c);
}
}
}
Parallel::send(0,ibuf);
Parallel::send(0,jbuf);
Parallel::send(0,cbuf);
}
}
Definition at line 429 of file sparse_matrix.h.
{
// std::complex<>::operator<<() is defined, but use this form
std::cout << 'Real part:' << std::endl;
for (unsigned int i=0; i<this->m(); i++)
{
for (unsigned int j=0; j<this->n(); j++)
os << std::setw(8) << (*this)(i,j).real() << ' ';
os << std::endl;
}
os << std::endl << 'Imaginary part:' << std::endl;
for (unsigned int i=0; i<this->m(); i++)
{
for (unsigned int j=0; j<this->n(); j++)
os << std::setw(8) << (*this)(i,j).imag() << ' ';
os << std::endl;
}
}
Definition at line 83 of file reference_counter.C.
References ReferenceCounter::get_info().
{
#if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
std::cout << ReferenceCounter::get_info();
#endif
}
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 SparseMatrix< T >.
Definition at line 273 of file petsc_matrix.C.
References libMesh::close(), libMesh::COMM_WORLD, and libMesh::initialized().
{
libmesh_assert (this->initialized());
semiparallel_only();
// libmesh_assert (this->closed());
this->close();
int ierr=0;
PetscViewer petsc_viewer;
ierr = PetscViewerCreate (libMesh::COMM_WORLD,
&petsc_viewer);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
if (name != 'NULL')
{
ierr = PetscViewerASCIIOpen( libMesh::COMM_WORLD,
name.c_str(),
&petsc_viewer);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
ierr = PetscViewerSetFormat (petsc_viewer,
PETSC_VIEWER_ASCII_MATLAB);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
ierr = MatView (_mat, petsc_viewer);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
}
else
{
ierr = PetscViewerSetFormat (PETSC_VIEWER_STDOUT_WORLD,
PETSC_VIEWER_ASCII_MATLAB);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
ierr = MatView (_mat, PETSC_VIEWER_STDOUT_WORLD);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
}
ierr = PetscViewerDestroy (petsc_viewer);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
}
Implements SparseMatrix< T >.
Definition at line 671 of file petsc_matrix.h.
References libMesh::COMM_WORLD, and libMesh::initialized().
{
libmesh_assert (this->initialized());
#ifndef NDEBUG
if (os != std::cout)
std::cerr << 'Warning! PETSc can only print to std::cout!' << std::endl;
#endif
int ierr=0;
ierr = MatView(_mat, PETSC_VIEWER_STDOUT_SELF);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
}
Definition at line 341 of file sparse_matrix.h.
{
this->_get_submatrix(submatrix,
rows,
cols,
true); // true means REUSE submatrix
}
Implements SparseMatrix< T >.
Definition at line 449 of file petsc_matrix.h.
References libMesh::COMM_WORLD, and libMesh::initialized().
{
libmesh_assert (this->initialized());
int start=0, stop=0, ierr=0;
ierr = MatGetOwnershipRange(_mat, &start, &stop);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
return static_cast<unsigned int>(start);
}
Implements SparseMatrix< T >.
Definition at line 465 of file petsc_matrix.h.
References libMesh::COMM_WORLD, and libMesh::initialized().
{
libmesh_assert (this->initialized());
int start=0, stop=0, ierr=0;
ierr = MatGetOwnershipRange(_mat, &start, &stop);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
return static_cast<unsigned int>(stop);
}
Implements SparseMatrix< T >.
Definition at line 481 of file petsc_matrix.h.
References libMesh::COMM_WORLD, and libMesh::initialized().
{
libmesh_assert (this->initialized());
int ierr=0, i_val=i, j_val=j;
PetscScalar petsc_value = static_cast<PetscScalar>(value);
ierr = MatSetValues(_mat, 1, &i_val, 1, &j_val,
&petsc_value, INSERT_VALUES);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
}
Definition at line 659 of file petsc_matrix.h.
References PetscMatrix< T >::_destroy_mat_on_exit, and PetscMatrix< T >::_mat.
Referenced by __libmesh_petsc_diff_solver_jacobian(), and __libmesh_petsc_snes_jacobian().
{
std::swap(_mat, m._mat);
std::swap(_destroy_mat_on_exit, m._destroy_mat_on_exit);
}
Reimplemented in LaspackMatrix< T >, and EpetraMatrix< T >.
Definition at line 118 of file sparse_matrix.h.
{}
Definition at line 87 of file sparse_matrix.C.
References NumericVector< T >::zero().
{
dest.zero();
this->vector_mult_add(dest,arg);
}
Definition at line 97 of file sparse_matrix.C.
References NumericVector< T >::add_vector().
{
/* This functionality is actually implemented in the
NumericVector class. */
dest.add_vector(arg,*this);
}
Implements SparseMatrix< T >.
Definition at line 179 of file petsc_matrix.C.
References libMesh::COMM_WORLD, and libMesh::initialized().
Referenced by __libmesh_petsc_snes_jacobian().
{
libmesh_assert (this->initialized());
semiparallel_only();
int ierr=0;
ierr = MatZeroEntries(_mat);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
}
Reimplemented from SparseMatrix< T >.
Definition at line 192 of file petsc_matrix.C.
References libMesh::COMM_WORLD, and libMesh::initialized().
{
libmesh_assert (this->initialized());
semiparallel_only();
int ierr=0;
if(!rows.empty())
ierr = MatZeroRows(_mat, rows.size(), &rows[0], diag_value);
else
ierr = MatZeroRows(_mat, 0, PETSC_NULL, diag_value);
CHKERRABORT(libMesh::COMM_WORLD,ierr);
}
Definition at line 110 of file reference_counter.h.
Referenced by ReferenceCounter::get_info(), ReferenceCounter::increment_constructor_count(), and ReferenceCounter::increment_destructor_count().
Definition at line 356 of file petsc_matrix.h.
Referenced by PetscMatrix< T >::swap().
Definition at line 395 of file sparse_matrix.h.
Referenced by SparseMatrix< Number >::attach_dof_map().
Definition at line 401 of file sparse_matrix.h.
Referenced by PetscMatrix< T >::_get_submatrix(), PetscMatrix< T >::get_transpose(), SparseMatrix< Number >::initialized(), and PetscMatrix< T >::PetscMatrix().
Definition at line 350 of file petsc_matrix.h.
Referenced by PetscMatrix< T >::_get_submatrix(), PetscMatrix< T >::add(), PetscMatrix< T >::get_transpose(), PetscMatrix< T >::mat(), PetscMatrix< T >::PetscMatrix(), and PetscMatrix< T >::swap().
Definition at line 123 of file reference_counter.h.
Definition at line 118 of file reference_counter.h.
Referenced by ReferenceCounter::n_objects(), ReferenceCounter::ReferenceCounter(), and ReferenceCounter::~ReferenceCounter().
Generated automatically by Doxygen for libMesh from the source code.