Poster of Linux kernelThe best gift for a Linux geek
PetscMatrix

PetscMatrix

Section: C Library Functions (3) Updated: Thu Apr 7 2011
Local index Up
 

NAME

PetscMatrix -  

SYNOPSIS


#include <petsc_matrix.h>

Inherits SparseMatrix< T >.  

Public Member Functions


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 Public Member Functions


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 ()
 

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< 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)
 

Protected Attributes


DofMap const * _dof_map

bool _is_initialized
 

Static Protected Attributes


static Counts _counts

static Threads::atomic< unsigned int > _n_objects

static Threads::spin_mutex _mutex
 

Private Attributes


Mat _mat

bool _destroy_mat_on_exit
 

Friends


template<typename U > std::ostream & operator<< (std::ostream &os, const SparseMatrix< U > &m)
 

Detailed Description

 

template<typename T> class PetscMatrix< T >

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

Author:

Benjamin S. Kirk, 2002

Definition at line 76 of file petsc_matrix.h.  

Member Typedef Documentation

 

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > ReferenceCounter::Counts [protected, inherited]Data structure to log the information. The log is identified by the class name.

Definition at line 105 of file reference_counter.h.  

Constructor & Destructor Documentation

 

template<typename T > PetscMatrix< T >::PetscMatrix () [inline]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(...).

Definition at line 366 of file petsc_matrix.h.

  : _destroy_mat_on_exit(true)
{}
 

template<typename T > PetscMatrix< T >::PetscMatrix (Matm) [inline]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.

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;
}
 

template<typename T > PetscMatrix< T >::~PetscMatrix () [inline]Destructor. Free all memory, but do not release the memory of the sparsity structure.

Definition at line 387 of file petsc_matrix.h.

{
  this->clear();
}
 

Member Function Documentation

 

template<typename T > void PetscMatrix< T >::_get_submatrix (SparseMatrix< T > &submatrix, const std::vector< unsigned int > &rows, const std::vector< unsigned int > &cols, const boolreuse_submatrix) const [protected, virtual]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 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);
}
 

template<typename T > void PetscMatrix< T >::add (const unsigned inti, const unsigned intj, const Tvalue) [inline, 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 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);
}
 

template<typename T > void PetscMatrix< T >::add (const Ta, SparseMatrix< T > &X) [inline, virtual]Add a Sparse matrix X, scaled with a, to this, stores the result in this: $ exttt{this} = a*X + exttt{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 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
}
 

template<typename T > void PetscMatrix< T >::add_matrix (const DenseMatrix< T > &dm, const std::vector< unsigned int > &rows, const std::vector< unsigned int > &cols) [virtual]Add the full matrix to the Petsc matrix. This is useful for adding an element matrix at assembly time

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);
}
 

template<typename T > void PetscMatrix< T >::add_matrix (const DenseMatrix< T > &dm, const std::vector< unsigned int > &dof_indices) [inline, virtual]Same, but assumes the row and column maps are the same. Thus the matrix dm must be square.

Implements SparseMatrix< T >.

Definition at line 517 of file petsc_matrix.h.

{
  this->add_matrix (dm, dof_indices, dof_indices);
}
 

template<typename T> void SparseMatrix< T >::attach_dof_map (const DofMap &dof_map) [inline, inherited]Get a pointer to the DofMap to use.

Definition at line 100 of file sparse_matrix.h.

Referenced by DofMap::attach_matrix().

  { _dof_map = &dof_map; }
 

template<typename T > AutoPtr< SparseMatrix< T > > SparseMatrix< T >::build (const SolverPackagesolver_package = libMesh::default_solver_package()) [static, inherited]Builds a SparseMatrix<T> using the linear solver package specified by solver_package

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;    
}
 

template<typename T > void PetscMatrix< T >::clear () [virtual]Release all memory and return to a state just like after having called the default constructor.

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;
    }
}
 

template<typename T > void PetscMatrix< T >::close () const [inline, virtual]Call the Petsc assemble routines. sends necessary messages to other processors

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);
}
 

template<typename T > bool PetscMatrix< T >::closed () const [inline, virtual]see if Petsc matrix has been closed and fully assembled yet

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);
}
 

template<typename T> virtual void SparseMatrix< T >::create_submatrix (SparseMatrix< T > &submatrix, const std::vector< unsigned int > &rows, const std::vector< unsigned int > &cols) const [inline, virtual, inherited]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 325 of file sparse_matrix.h.

  {
    this->_get_submatrix(submatrix,
                         rows,
                         cols,
                         false); // false means DO NOT REUSE submatrix
  }
 

template<typename T > void PetscMatrix< T >::get_diagonal (NumericVector< T > &dest) const [virtual]Copies the diagonal part of the matrix into dest.

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

}
 

std::string ReferenceCounter::get_info () [static, inherited]Gets a string containing the reference information.

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
}
 

template<typename T > void PetscMatrix< T >::get_transpose (SparseMatrix< T > &dest) const [virtual]Copies the transpose of the matrix into dest, which may be *this.

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();
}
 

void ReferenceCounter::increment_constructor_count (const std::string &name) [inline, protected, inherited]Increments the construction counter. Should be called in the constructor of any derived class that will be reference counted.

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++;
}
 

void ReferenceCounter::increment_destructor_count (const std::string &name) [inline, protected, inherited]Increments the destruction counter. Should be called in the destructor of any derived class that will be reference counted.

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++;
}
 

template<typename T > void PetscMatrix< T >::init () [virtual]Initialize using sparsity structure computed by dof_map.

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();
}
 

template<typename T > void PetscMatrix< T >::init (const unsigned intm, const unsigned intn, const unsigned intm_l, const unsigned intn_l, const unsigned intnnz = 30, const unsigned intnoz = 10) [virtual]Initialize a Petsc matrix that is of global dimension $ m imes n $ with local dimensions $ m_l imes 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).

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 ();
}
 

template<typename T> virtual bool SparseMatrix< T >::initialized () const [inline, virtual, inherited]Returns:

true if the matrix has been initialized, false otherwise.

Definition at line 95 of file sparse_matrix.h.

Referenced by PetscMatrix< T >::_get_submatrix(), ImplicitSystem::assemble(), and ImplicitSystem::init_matrices().

{ return _is_initialized; }
 

template<typename T > Real PetscMatrix< T >::l1_norm () const [virtual]Return the l1-norm of the matrix, that is $|M|_1=max_{all columns j}um_{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
mmerlin-Hoffmann : Numerische Mathematik)

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;
}
 

template<typename T > Real PetscMatrix< T >::linfty_norm () const [virtual]Return the linfty-norm of the matrix, that is $|M|_infty=max_{all rows i}um_{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
mmerlin-Hoffmann : Numerische Mathematik)

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;
}
 

template<typename T > unsigned int PetscMatrix< T >::m () const [inline, virtual]Returns:

m, the row-dimension of the matrix where the marix is $ M imes N $.

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);
}
 

template<typename T> Mat PetscMatrix< T >::mat () [inline]Returns the raw PETSc matrix context pointer. Note this is generally not required in user-level code. Just don't do anything crazy like calling MatDestroy()!

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; }
 

template<typename T > unsigned int PetscMatrix< T >::n () const [inline, virtual]Returns:

n, the column-dimension of the matrix where the marix is $ M imes N $.

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);
}
 

static unsigned int ReferenceCounter::n_objects () [inline, static, inherited]Prints the number of outstanding (created, but not yet destroyed) objects.

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; }
 

template<typename T> virtual bool SparseMatrix< T >::need_full_sparsity_pattern () const [inline, virtual, inherited]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 LaspackMatrix< T >, and EpetraMatrix< T >.

Definition at line 110 of file sparse_matrix.h.

  { return false; }  
 

template<typename T > T PetscMatrix< T >::operator() (const unsigned inti, const unsigned intj) const [inline, virtual]Return the value of the entry (i,j). This may be an expensive operation and you should always take care where to call this function. In order to avoid abuse, this function throws an exception if the required element does not exist in the matrix.

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;
}
 

template<typename T > void SparseMatrix< T >::print (std::ostream &os = std::cout) const [inline, inherited]Print the contents of the matrix to the screen in a uniform style, regardless of matrix/solver package being used.

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);
    }
}
 

template<> void SparseMatrix< Complex >::print (std::ostream &os) const [inline, inherited]

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;
    }
}
 

void ReferenceCounter::print_info () [static, inherited]Prints the reference information to std::cout.

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
}
 

template<typename T > void PetscMatrix< T >::print_matlab (const std::stringname = 'NULL') 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 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);
}
 

template<typename T > void PetscMatrix< T >::print_personal (std::ostream &os = std::cout) const [inline, 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 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);
}
 

template<typename T> virtual void SparseMatrix< T >::reinit_submatrix (SparseMatrix< T > &submatrix, const std::vector< unsigned int > &rows, const std::vector< unsigned int > &cols) const [inline, virtual, inherited]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 341 of file sparse_matrix.h.

  {
    this->_get_submatrix(submatrix,
                         rows,
                         cols,
                         true); // true means REUSE submatrix
  }
 

template<typename T > unsigned int PetscMatrix< T >::row_start () const [inline, virtual]return row_start, the index of the first matrix row stored on this processor

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);
}
 

template<typename T > unsigned int PetscMatrix< T >::row_stop () const [inline, virtual]return row_stop, the index of the last matrix row (+1) stored on this processor

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);
}
 

template<typename T > void PetscMatrix< T >::set (const unsigned inti, const unsigned intj, const Tvalue) [inline, 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 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);
}
 

template<typename T > void PetscMatrix< T >::swap (PetscMatrix< T > &m) [inline]Swaps the raw PETSc matrix context pointers.

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);
}
 

template<typename T> virtual void SparseMatrix< T >::update_sparsity_pattern (const SparsityPattern::Graph &) [inline, virtual, inherited]Updates the matrix sparsity pattern. When your SparseMatrix<T> implementation does not need this data simply do not overload this method.

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

Definition at line 118 of file sparse_matrix.h.

{}
 

template<typename T> void 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 87 of file sparse_matrix.C.

References NumericVector< T >::zero().

{
  dest.zero();
  this->vector_mult_add(dest,arg);
}
 

template<typename T> void 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 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); }
 

template<typename T > void PetscMatrix< T >::zero () [virtual]Set all entries to 0. This method retains sparsity structure.

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);
}
 

template<typename T > void PetscMatrix< T >::zero_rows (std::vector< int > &rows, Tdiag_value = 0.0) [virtual]Set all row entries to 0 then puts diag_value in the diagonal entry

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);
}
 

Friends And Related Function Documentation

 

template<typename T> template<typename U > std::ostream& operator<< (std::ostream &os, const SparseMatrix< U > &m) [friend, inherited]Same as the print method above, but allows you to print to a stream in the standard syntax.

 

Member Data Documentation

 

ReferenceCounter::Counts ReferenceCounter::_counts [static, protected, inherited]Actually holds the data.

Definition at line 110 of file reference_counter.h.

Referenced by ReferenceCounter::get_info(), ReferenceCounter::increment_constructor_count(), and ReferenceCounter::increment_destructor_count().  

template<typename T> bool 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 356 of file petsc_matrix.h.

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

template<typename T> DofMap const* SparseMatrix< T >::_dof_map [protected, inherited]The DofMap object associated with this object.

Definition at line 395 of file sparse_matrix.h.

Referenced by SparseMatrix< Number >::attach_dof_map().  

template<typename T> bool SparseMatrix< T >::_is_initialized [protected, inherited]Flag indicating whether or not the matrix has been initialized.

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().  

template<typename T> Mat PetscMatrix< T >::_mat [private]Petsc matrix datatype to store values

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().  

Threads::spin_mutex ReferenceCounter::_mutex [static, protected, inherited]Mutual exclusion object to enable thread-safe reference counting.

Definition at line 123 of file reference_counter.h.  

Threads::atomic< unsigned int > ReferenceCounter::_n_objects [static, protected, inherited]The number of objects. Print the reference count information when the number returns to 0.

Definition at line 118 of file reference_counter.h.

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

 

Author

Generated automatically by Doxygen for libMesh from the source code.


 

Index

NAME
SYNOPSIS
Public Member Functions
Static Public Member Functions
Protected Types
Protected Member Functions
Protected Attributes
Static Protected Attributes
Private Attributes
Friends
Detailed Description
template<typename T> class PetscMatrix< T >
Member Typedef Documentation
typedef std::map<std::string, std::pair<unsigned int, unsigned int> > ReferenceCounter::Counts [protected, inherited]Data structure to log the information. The log is identified by the class name.
Constructor & Destructor Documentation
template<typename T > PetscMatrix< T >::PetscMatrix () [inline]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.
template<typename T > PetscMatrix< T >::PetscMatrix (Matm) [inline]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 > PetscMatrix< T >::~PetscMatrix () [inline]Destructor. Free all memory, but do not release the memory of the sparsity structure.
Member Function Documentation
template<typename T > void PetscMatrix< T >::_get_submatrix (SparseMatrix< T > &submatrix, const std::vector< unsigned int > &rows, const std::vector< unsigned int > &cols, const boolreuse_submatrix) const [protected, virtual]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.
template<typename T > void PetscMatrix< T >::add (const unsigned inti, const unsigned intj, const Tvalue) [inline, 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.
template<typename T > void PetscMatrix< T >::add (const Ta, SparseMatrix< T > &X) [inline, virtual]Add a Sparse matrix X, scaled with a, to this, stores the result in this: $ exttt{this} = a*X + exttt{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.
template<typename T > void PetscMatrix< T >::add_matrix (const DenseMatrix< T > &dm, const std::vector< unsigned int > &rows, const std::vector< unsigned int > &cols) [virtual]Add the full matrix to the Petsc matrix. This is useful for adding an element matrix at assembly time
template<typename T > void PetscMatrix< T >::add_matrix (const DenseMatrix< T > &dm, const std::vector< unsigned int > &dof_indices) [inline, virtual]Same, but assumes the row and column maps are the same. Thus the matrix dm must be square.
template<typename T> void SparseMatrix< T >::attach_dof_map (const DofMap &dof_map) [inline, inherited]Get a pointer to the DofMap to use.
template<typename T > AutoPtr< SparseMatrix< T > > SparseMatrix< T >::build (const SolverPackagesolver_package = libMesh::default_solver_package()) [static, inherited]Builds a SparseMatrix<T> using the linear solver package specified by solver_package
template<typename T > void PetscMatrix< T >::clear () [virtual]Release all memory and return to a state just like after having called the default constructor.
template<typename T > void PetscMatrix< T >::close () const [inline, virtual]Call the Petsc assemble routines. sends necessary messages to other processors
template<typename T > bool PetscMatrix< T >::closed () const [inline, virtual]see if Petsc matrix has been closed and fully assembled yet
template<typename T> virtual void SparseMatrix< T >::create_submatrix (SparseMatrix< T > &submatrix, const std::vector< unsigned int > &rows, const std::vector< unsigned int > &cols) const [inline, virtual, inherited]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.
template<typename T > void PetscMatrix< T >::get_diagonal (NumericVector< T > &dest) const [virtual]Copies the diagonal part of the matrix into dest.
std::string ReferenceCounter::get_info () [static, inherited]Gets a string containing the reference information.
template<typename T > void PetscMatrix< T >::get_transpose (SparseMatrix< T > &dest) const [virtual]Copies the transpose of the matrix into dest, which may be *this.
void ReferenceCounter::increment_constructor_count (const std::string &name) [inline, protected, inherited]Increments the construction counter. Should be called in the constructor of any derived class that will be reference counted.
void ReferenceCounter::increment_destructor_count (const std::string &name) [inline, protected, inherited]Increments the destruction counter. Should be called in the destructor of any derived class that will be reference counted.
template<typename T > void PetscMatrix< T >::init () [virtual]Initialize using sparsity structure computed by dof_map.
template<typename T > void PetscMatrix< T >::init (const unsigned intm, const unsigned intn, const unsigned intm_l, const unsigned intn_l, const unsigned intnnz = 30, const unsigned intnoz = 10) [virtual]Initialize a Petsc matrix that is of global dimension $ m imes n $ with local dimensions $ m_l imes 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).
template<typename T> virtual bool SparseMatrix< T >::initialized () const [inline, virtual, inherited]Returns:
template<typename T > Real PetscMatrix< T >::l1_norm () const [virtual]Return the l1-norm of the matrix, that is $|M|_1=max_{all columns j}um_{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
mmerlin-Hoffmann : Numerische Mathematik)
template<typename T > Real PetscMatrix< T >::linfty_norm () const [virtual]Return the linfty-norm of the matrix, that is $|M|_infty=max_{all rows i}um_{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
mmerlin-Hoffmann : Numerische Mathematik)
template<typename T > unsigned int PetscMatrix< T >::m () const [inline, virtual]Returns:
template<typename T> Mat PetscMatrix< T >::mat () [inline]Returns the raw PETSc matrix context pointer. Note this is generally not required in user-level code. Just don't do anything crazy like calling MatDestroy()!
template<typename T > unsigned int PetscMatrix< T >::n () const [inline, virtual]Returns:
static unsigned int ReferenceCounter::n_objects () [inline, static, inherited]Prints the number of outstanding (created, but not yet destroyed) objects.
template<typename T> virtual bool SparseMatrix< T >::need_full_sparsity_pattern () const [inline, virtual, inherited]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.
template<typename T > T PetscMatrix< T >::operator() (const unsigned inti, const unsigned intj) const [inline, virtual]Return the value of the entry (i,j). This may be an expensive operation and you should always take care where to call this function. In order to avoid abuse, this function throws an exception if the required element does not exist in the matrix.
template<typename T > void SparseMatrix< T >::print (std::ostream &os = std::cout) const [inline, inherited]Print the contents of the matrix to the screen in a uniform style, regardless of matrix/solver package being used.
template<> void SparseMatrix< Complex >::print (std::ostream &os) const [inline, inherited]
void ReferenceCounter::print_info () [static, inherited]Prints the reference information to std::cout.
template<typename T > void PetscMatrix< T >::print_matlab (const std::stringname = 'NULL') 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.
template<typename T > void PetscMatrix< T >::print_personal (std::ostream &os = std::cout) const [inline, 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.
template<typename T> virtual void SparseMatrix< T >::reinit_submatrix (SparseMatrix< T > &submatrix, const std::vector< unsigned int > &rows, const std::vector< unsigned int > &cols) const [inline, virtual, inherited]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.
template<typename T > unsigned int PetscMatrix< T >::row_start () const [inline, virtual]return row_start, the index of the first matrix row stored on this processor
template<typename T > unsigned int PetscMatrix< T >::row_stop () const [inline, virtual]return row_stop, the index of the last matrix row (+1) stored on this processor
template<typename T > void PetscMatrix< T >::set (const unsigned inti, const unsigned intj, const Tvalue) [inline, 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.
template<typename T > void PetscMatrix< T >::swap (PetscMatrix< T > &m) [inline]Swaps the raw PETSc matrix context pointers.
template<typename T> virtual void SparseMatrix< T >::update_sparsity_pattern (const SparsityPattern::Graph &) [inline, virtual, inherited]Updates the matrix sparsity pattern. When your SparseMatrix<T> implementation does not need this data simply do not overload this method.
template<typename T> void SparseMatrix< T >::vector_mult (NumericVector< T > &dest, const NumericVector< T > &arg) const [inherited]Multiplies the matrix with arg and stores the result in dest.
template<typename T> void 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.
template<typename T > void PetscMatrix< T >::zero () [virtual]Set all entries to 0. This method retains sparsity structure.
template<typename T > void PetscMatrix< T >::zero_rows (std::vector< int > &rows, Tdiag_value = 0.0) [virtual]Set all row entries to 0 then puts diag_value in the diagonal entry
Friends And Related Function Documentation
template<typename T> template<typename U > std::ostream& operator<< (std::ostream &os, const SparseMatrix< U > &m) [friend, inherited]Same as the print method above, but allows you to print to a stream in the standard syntax.
Member Data Documentation
ReferenceCounter::Counts ReferenceCounter::_counts [static, protected, inherited]Actually holds the data.
template<typename T> bool 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.
template<typename T> DofMap const* SparseMatrix< T >::_dof_map [protected, inherited]The DofMap object associated with this object.
template<typename T> bool SparseMatrix< T >::_is_initialized [protected, inherited]Flag indicating whether or not the matrix has been initialized.
template<typename T> Mat PetscMatrix< T >::_mat [private]Petsc matrix datatype to store values
Threads::spin_mutex ReferenceCounter::_mutex [static, protected, inherited]Mutual exclusion object to enable thread-safe reference counting.
Threads::atomic< unsigned int > ReferenceCounter::_n_objects [static, protected, inherited]The number of objects. Print the reference count information when the number returns to 0.
Author

This document was created by man2html, using the manual pages.
Time: 21:52:24 GMT, April 16, 2011