Poster of Linux kernelThe best gift for a Linux geek
LaspackMatrix

LaspackMatrix

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

NAME

LaspackMatrix -  

SYNOPSIS


#include <laspack_matrix.h>

Inherits SparseMatrix< T >.  

Public Member Functions


LaspackMatrix ()

~LaspackMatrix ()

bool need_full_sparsity_pattern () const

void update_sparsity_pattern (const SparsityPattern::Graph &)

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

virtual void get_diagonal (NumericVector< T > &dest) const

virtual void get_transpose (SparseMatrix< T > &dest) const

virtual bool initialized () const

void attach_dof_map (const DofMap &dof_map)

virtual void zero_rows (std::vector< int > &rows, T diag_value=0.0)

void print (std::ostream &os=std::cout) const

template<> void print (std::ostream &os) const

virtual void print_matlab (const std::string name='NULL') 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 > &, const std::vector< unsigned int > &, const std::vector< unsigned int > &, const bool) 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 Member Functions


unsigned int pos (const unsigned int i, const unsigned int j) const
 

Private Attributes


QMatrix _QMat

std::vector< unsigned int > _csr

std::vector< std::vector< unsigned int >::const_iterator > _row_start

bool _closed
 

Friends


class LaspackVector< T >

class LaspackLinearSolver< T >

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

Detailed Description

 

template<typename T> class LaspackMatrix< T >

Generic laspack matrix. This class contains pure virtual members that must be overloaded in derived classes. Using a derived class allows for uniform access to laspack matrices from various different solver packages in different formats. Currently Laspack only supports real datatypes, so this class is a full specialization of SparseMatrix<> with T = Real

Author:

Benjamin S. Kirk, 2003

Definition at line 63 of file laspack_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 > LaspackMatrix< T >::LaspackMatrix () [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 329 of file laspack_matrix.h.

                                 :
  _closed (false)
{
}
 

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

Definition at line 338 of file laspack_matrix.h.

References LaspackLinearSolver< T >::clear().

{
  this->clear ();
}
 

Member Function Documentation

 

template<typename T> virtual void SparseMatrix< T >::_get_submatrix (SparseMatrix< T > &, const std::vector< unsigned int > &, const std::vector< unsigned int > &, const bool) const [inline, protected, virtual, inherited]Protected implementation of the create_submatrix and reinit_submatrix routines. Note that this function must be redefined in derived classes for it to work properly!

Reimplemented in PetscMatrix< T >.

Definition at line 382 of file sparse_matrix.h.

Referenced by SparseMatrix< Number >::create_submatrix(), and SparseMatrix< Number >::reinit_submatrix().

  {
    std::cerr << 'Error! This function is not yet implemented in the base class!'
              << std::endl;
    libmesh_error();
  }
 

template<typename T > void LaspackMatrix< 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 455 of file laspack_matrix.h.

References libMesh::initialized().

{
  libmesh_assert (this->initialized());
  libmesh_assert (i < this->m());
  libmesh_assert (j < this->n());
  
  const unsigned int position = this->pos(i,j);

  // Sanity check
  libmesh_assert (*(_row_start[i]+position) == j);

  Q_AddVal (&_QMat, i+1, position, value);
}
 

template<typename T > void LaspackMatrix< T >::add (const Ta, SparseMatrix< T > &X) [virtual]Add a Sparse matrix X, scaled with a, to this, stores the result in this: $ exttt{this} += a*X $. LASPACK does not provide a true axpy for matrices, so a hand-coded version with hopefully acceptable performance is provided.

Implements SparseMatrix< T >.

Definition at line 503 of file laspack_matrix.h.

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

{
  libmesh_assert (this->initialized());
  libmesh_assert (this->m() == X_in.m());
  libmesh_assert (this->n() == X_in.n());

  LaspackMatrix<T>* X = dynamic_cast<LaspackMatrix<T>*> (&X_in);
  _LPNumber         a = static_cast<_LPNumber>          (a_in);
  
  libmesh_assert(X != NULL);
  
  // loops taken from LaspackMatrix<T>::zero ()

  const unsigned int n_rows = this->m();

  for (unsigned int row=0; row<n_rows; row++)
    {
      const std::vector<unsigned int>::const_iterator
        r_start = _row_start[row];
      
      const unsigned int len = (_row_start[row+1] - _row_start[row]);

      // Make sure we agree on the row length
      libmesh_assert (len == Q_GetLen(&_QMat, row+1));
      // compare matrix sparsity structures
      libmesh_assert (len == Q_GetLen(&(X->_QMat), row+1));
        
      
      for (unsigned int l=0; l<len; l++)
        {
          const unsigned int j = *(r_start + l);

          // Make sure the data structures are working
          libmesh_assert ((j+1) == Q_GetPos (&_QMat, row+1, l));

          const _LPNumber value = a * Q_GetEl(const_cast<QMatrix*>(&(X->_QMat)), row+1, j+1);
          Q_AddVal   (&_QMat, row+1, l, value);
        }
    }    
}
 

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

Implements SparseMatrix< T >.

Definition at line 485 of file laspack_matrix.h.

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

{
  libmesh_assert (this->initialized());
  libmesh_assert (dm.m() == rows.size());
  libmesh_assert (dm.n() == cols.size());

  
  for (unsigned int i=0; i<rows.size(); i++)
    for (unsigned int j=0; j<cols.size(); j++)
      this->add(rows[i],cols[j],dm(i,j));
}
 

template<typename T > void LaspackMatrix< 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 475 of file laspack_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 LaspackMatrix< T >::clear () [inline, virtual]Release all memory and return to a state just like after having called the default constructor.

Implements SparseMatrix< T >.

Definition at line 347 of file laspack_matrix.h.

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

{
  if (this->initialized())
    {
      Q_Destr(&_QMat);
    }
  
  _csr.clear();
  _row_start.clear();
  _closed = false;
  this->_is_initialized = false;
}
 

template<typename T> void LaspackMatrix< T >::close () const [inline, virtual]Close the matrix. Dummy routine. After calling this method closed() is true and the matrix can be used in computations.

Implements SparseMatrix< T >.

Definition at line 142 of file laspack_matrix.h.

References LaspackMatrix< T >::_closed.

Referenced by LaspackLinearSolver< T >::solve().

{ const_cast<LaspackMatrix<T>*>(this)->_closed = true; }
 

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

Implements SparseMatrix< T >.

Definition at line 267 of file laspack_matrix.h.

References LaspackMatrix< T >::_closed.

{ return _closed; }
 

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 LaspackMatrix< T >::get_diagonal (NumericVector< T > &dest) const [virtual]Copies the diagonal part of the matrix into dest.

Implements SparseMatrix< T >.

Definition at line 199 of file laspack_matrix.C.

{
  libmesh_not_implemented();
}
 

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 LaspackMatrix< 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 207 of file laspack_matrix.C.

{
  libmesh_not_implemented();
}
 

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 LaspackMatrix< 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 Laspack 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 124 of file laspack_matrix.C.

References libMesh::libMeshPrivateData::_is_initialized.

{
  // noz ignored...  only used for multiple processors!
  libmesh_assert (m == m_l);
  libmesh_assert (n == n_l);
  libmesh_assert (m == n);
  libmesh_assert (nnz > 0);


  std::cerr << 'ERROR: Only the init() member that uses the' << std::endl
            << 'DofMap is implemented for Laspack matrices!' << std::endl;
  libmesh_error();

  this->_is_initialized = true;
}
 

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

Implements SparseMatrix< T >.

Definition at line 148 of file laspack_matrix.C.

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

{
  // Ignore calls on initialized objects
  if (this->initialized())
    return;
  
  // We need the DofMap for this!
  libmesh_assert (this->_dof_map != NULL);

  // Clear intialized matrices
  if (this->initialized())
    this->clear();

  const unsigned int m   = this->_dof_map->n_dofs();
#ifndef NDEBUG
  // The following variables are only used for assertions,
  // so avoid declaring them when asserts are inactive.
  const unsigned int n   = m;
  const unsigned int n_l = this->_dof_map->n_dofs_on_processor(0); 
  const unsigned int m_l = n_l;
#endif
  
  // Laspack Matrices only work for uniprocessor cases
  libmesh_assert (m   == n);
  libmesh_assert (m_l == m);
  libmesh_assert (n_l == n);

#ifndef NDEBUG
  // The following variables are only used for assertions,
  // so avoid declaring them when asserts are inactive.
  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();
#endif
  
  // Make sure the sparsity pattern isn't empty
  libmesh_assert (n_nz.size() == n_l);
  libmesh_assert (n_oz.size() == n_l);
  
  if (m==0)
    return;

  Q_Constr(&_QMat, const_cast<char*>('Mat'), m, _LPFalse, Rowws, Normal, _LPTrue);

  this->_is_initialized = true;
  
  libmesh_assert (m == this->m());
}
 

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 LaspackMatrix< T >::l1_norm () const [inline, 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
ments SparseMatrix< T >.

Definition at line 248 of file laspack_matrix.h.

{ libmesh_error(); return 0.; }
 

template<typename T> Real LaspackMatrix< T >::linfty_norm () const [inline, 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
ments SparseMatrix< T >.

Definition at line 261 of file laspack_matrix.h.

{ libmesh_error(); return 0.; }
 

template<typename T > unsigned int LaspackMatrix< 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 394 of file laspack_matrix.h.

References libMesh::initialized().

{
  libmesh_assert (this->initialized());

  return static_cast<unsigned int>(Q_GetDim(const_cast<QMatrix*>(&_QMat)));
}
 

template<typename T > unsigned int LaspackMatrix< 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 405 of file laspack_matrix.h.

References libMesh::initialized().

{
  libmesh_assert (this->initialized());
  
  return static_cast<unsigned int>(Q_GetDim(const_cast<QMatrix*>(&_QMat)));
}
 

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> bool LaspackMatrix< T >::need_full_sparsity_pattern () const [inline, virtual]The LaspackMatrix needs the full sparsity pattern.

Reimplemented from SparseMatrix< T >.

Definition at line 94 of file laspack_matrix.h.

  { return true; }
 

template<typename T > T LaspackMatrix< 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 549 of file laspack_matrix.h.

References libMesh::initialized().

{
  libmesh_assert (this->initialized());
  libmesh_assert (i < this->m());
  libmesh_assert (j < this->n());
  
  return Q_GetEl (const_cast<QMatrix*>(&_QMat), i+1, j+1);
}
 

template<typename T > unsigned int LaspackMatrix< T >::pos (const unsigned inti, const unsigned intj) const [inline, private]Returns:

the position in the compressed row storage scheme of the $ (i,j) $ element.

Definition at line 563 of file laspack_matrix.h.

{
  //std::cout << 'm()=' << m() << std::endl;
  libmesh_assert (i < this->m());
  libmesh_assert (j < this->n());
  libmesh_assert (i+1 < _row_start.size());
  libmesh_assert (_row_start.back() == _csr.end());

  // note this requires the _csr to be 
  std::pair<std::vector<unsigned int>::const_iterator,
            std::vector<unsigned int>::const_iterator> p =
    std::equal_range (_row_start[i],
                      _row_start[i+1],
                      j);

  // Make sure the row contains the element j
  libmesh_assert (p.first != p.second);

  // Make sure the values match
  libmesh_assert (*p.first == j);

  // Return the position in the compressed row
  return std::distance (_row_start[i], p.first);
}
 

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> virtual void SparseMatrix< T >::print_matlab (const std::stringname = 'NULL') const [inline, virtual, inherited]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. x

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

Definition at line 313 of file sparse_matrix.h.

  {
    std::cerr << 'ERROR: Not Implemented in base class yet!' << std::endl;
    std::cerr << 'ERROR writing MATLAB file ' << name << std::endl;
    libmesh_error();
  }
 

template<typename T> void LaspackMatrix< T >::print_personal (std::ostream &os = std::cout) const [inline, virtual]Print the contents of the matrix to the screen, currently identical to print().

Implements SparseMatrix< T >.

Definition at line 273 of file laspack_matrix.h.

References SparseMatrix< T >::print().

{ this->print(os); }
 

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 LaspackMatrix< 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 416 of file laspack_matrix.h.

{
  return 0;
}
 

template<typename T > unsigned int LaspackMatrix< 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 425 of file laspack_matrix.h.

{
  return this->m();
}
 

template<typename T > void LaspackMatrix< 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 434 of file laspack_matrix.h.

References libMesh::initialized().

{
  libmesh_assert (this->initialized());
  libmesh_assert (i < this->m());
  libmesh_assert (j < this->n());
  
  const unsigned int position = this->pos(i,j);

  // Sanity check
  libmesh_assert (*(_row_start[i]+position) == j);
  libmesh_assert ((j+1) == Q_GetPos (&_QMat, i+1, position));

  Q_SetEntry (&_QMat, i+1, position, j+1, value);
}
 

template<typename T > void LaspackMatrix< T >::update_sparsity_pattern (const SparsityPattern::Graph &sparsity_pattern) [virtual]Updates the matrix sparsity pattern. This will tell the underlying matrix storage scheme how to map the $ (i,j) $ elements.

Reimplemented from SparseMatrix< T >.

Definition at line 36 of file laspack_matrix.C.

References libMesh::init(), and libMesh::initialized().

{
  // clear data, start over
  this->clear ();    

  // big trouble if this fails!
  libmesh_assert (this->_dof_map != NULL);
  
  const unsigned int n_rows = sparsity_pattern.size();

  // Initialize the _row_start data structure,
  // allocate storage for the _csr array
  {
    unsigned int size = 0;
 
    for (unsigned int row=0; row<n_rows; row++)
      size += sparsity_pattern[row].size();
    
    _csr.resize       (size);
    _row_start.reserve(n_rows + 1);
  }


  // Initize the _csr data structure.
  {
    std::vector<unsigned int>::iterator pos = _csr.begin();
    
    _row_start.push_back (pos);
    
    for (unsigned int row=0; row<n_rows; row++)
      {
        // insert the row indices
        for (SparsityPattern::Row::const_iterator col = sparsity_pattern[row].begin();
             col != sparsity_pattern[row].end(); ++col)
          {
            libmesh_assert (pos != _csr.end());
            *pos = *col;
            ++pos;
          }
        
        _row_start.push_back (pos);
      }
  }


  // Initialize the matrix
  libmesh_assert (!this->initialized());
  this->init ();
  libmesh_assert (this->initialized());
  //std::cout << 'n_rows=' << n_rows << std::endl;
  //std::cout << 'm()=' << m() << std::endl;
  libmesh_assert (n_rows == this->m());

  // Tell the matrix about its structure.  Initialize it
  // to zero.
  for (unsigned int i=0; i<n_rows; i++)
    {
      const std::vector<unsigned int>::const_iterator
        rs = _row_start[i];
      
      const unsigned int length = _row_start[i+1] - rs;
      
      Q_SetLen (&_QMat, i+1, length);

      for (unsigned int l=0; l<length; l++)
        {
          const unsigned int j = *(rs+l);

          // sanity check
          //std::cout << 'm()=' << m() << std::endl;
          //std::cout << '(i,j,l) = (' << i
          //        << ',' << j
          //        << ',' << l
          //        << ')' << std::endl;
          //std::cout << 'pos(i,j)=' << pos(i,j)
          //          << std::endl;       
          libmesh_assert (this->pos(i,j) == l);
          Q_SetEntry (&_QMat, i+1, l, j+1, 0.);
        }
    }
  
  // That's it!
  //libmesh_here();
}
 

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 LaspackMatrix< T >::zero () [inline, virtual]Set all entries to 0.

Implements SparseMatrix< T >.

Definition at line 364 of file laspack_matrix.h.

{
  const unsigned int n_rows = this->m();

  for (unsigned int row=0; row<n_rows; row++)
    {
      const std::vector<unsigned int>::const_iterator
        r_start = _row_start[row];
      
      const unsigned int len = (_row_start[row+1] - _row_start[row]);
        
      // Make sure we agree on the row length
      libmesh_assert (len == Q_GetLen(&_QMat, row+1));
      
      for (unsigned int l=0; l<len; l++)
        {
          const unsigned int j = *(r_start + l);

          // Make sure the data structures are working
          libmesh_assert ((j+1) == Q_GetPos (&_QMat, row+1, l));
          
          Q_SetEntry (&_QMat, row+1, l, j+1, 0.);
        }
    }    
}
 

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

Reimplemented in PetscMatrix< T >.

Definition at line 108 of file sparse_matrix.C.

{
  /* This functionality isn't implemented or stubbed in every subclass yet */
  libmesh_not_implemented();
}
 

Friends And Related Function Documentation

 

template<typename T> friend class LaspackLinearSolver< T > [friend]

Definition at line 320 of file laspack_matrix.h.  

template<typename T> friend class LaspackVector< T > [friend]Make other Laspack datatypes friends

Definition at line 319 of file laspack_matrix.h.  

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

 

template<typename T> bool LaspackMatrix< T >::_closed [private]Flag indicating if the matrix has been closed yet.

Definition at line 314 of file laspack_matrix.h.

Referenced by LaspackMatrix< T >::close(), and LaspackMatrix< T >::closed().  

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> std::vector<unsigned int> LaspackMatrix< T >::_csr [private]The compressed row indices.

Definition at line 303 of file laspack_matrix.h.  

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

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

template<typename T> QMatrix LaspackMatrix< T >::_QMat [private]The Laspack sparse matrix pointer.

Definition at line 298 of file laspack_matrix.h.

Referenced by LaspackLinearSolver< T >::solve().  

template<typename T> std::vector<std::vector<unsigned int>::const_iterator> LaspackMatrix< T >::_row_start [private]The start of each row in the compressed row index data structure.

Definition at line 309 of file laspack_matrix.h.

 

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 Member Functions
Private Attributes
Friends
Detailed Description
template<typename T> class LaspackMatrix< 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 > LaspackMatrix< T >::LaspackMatrix () [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 > LaspackMatrix< T >::~LaspackMatrix () [inline]Destructor. Free all memory, but do not release the memory of the sparsity structure.
Member Function Documentation
template<typename T> virtual void SparseMatrix< T >::_get_submatrix (SparseMatrix< T > &, const std::vector< unsigned int > &, const std::vector< unsigned int > &, const bool) const [inline, protected, virtual, inherited]Protected implementation of the create_submatrix and reinit_submatrix routines. Note that this function must be redefined in derived classes for it to work properly!
template<typename T > void LaspackMatrix< 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 LaspackMatrix< T >::add (const Ta, SparseMatrix< T > &X) [virtual]Add a Sparse matrix X, scaled with a, to this, stores the result in this: $ exttt{this} += a*X $. LASPACK does not provide a true axpy for matrices, so a hand-coded version with hopefully acceptable performance is provided.
template<typename T > void LaspackMatrix< T >::add_matrix (const DenseMatrix< T > &dm, const std::vector< unsigned int > &rows, const std::vector< unsigned int > &cols) [inline, virtual]Add the full matrix to the Laspack matrix. This is useful for adding an element matrix at assembly time
template<typename T > void LaspackMatrix< 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 LaspackMatrix< T >::clear () [inline, virtual]Release all memory and return to a state just like after having called the default constructor.
template<typename T> void LaspackMatrix< T >::close () const [inline, virtual]Close the matrix. Dummy routine. After calling this method closed() is true and the matrix can be used in computations.
template<typename T> bool LaspackMatrix< T >::closed () const [inline, virtual]see if Laspack 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 LaspackMatrix< 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 LaspackMatrix< 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 LaspackMatrix< 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 Laspack 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 > void LaspackMatrix< T >::init () [virtual]Initialize using sparsity structure computed by dof_map.
template<typename T> virtual bool SparseMatrix< T >::initialized () const [inline, virtual, inherited]Returns:
template<typename T> Real LaspackMatrix< T >::l1_norm () const [inline, 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
ments SparseMatrix< T >.
template<typename T> Real LaspackMatrix< T >::linfty_norm () const [inline, 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
ments SparseMatrix< T >.
template<typename T > unsigned int LaspackMatrix< T >::m () const [inline, virtual]Returns:
template<typename T > unsigned int LaspackMatrix< 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> bool LaspackMatrix< T >::need_full_sparsity_pattern () const [inline, virtual]The LaspackMatrix needs the full sparsity pattern.
template<typename T > T LaspackMatrix< 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 > unsigned int LaspackMatrix< T >::pos (const unsigned inti, const unsigned intj) const [inline, private]Returns:
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> virtual void SparseMatrix< T >::print_matlab (const std::stringname = 'NULL') const [inline, virtual, inherited]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. x
template<typename T> void LaspackMatrix< T >::print_personal (std::ostream &os = std::cout) const [inline, virtual]Print the contents of the matrix to the screen, currently identical to print().
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 LaspackMatrix< 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 LaspackMatrix< 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 LaspackMatrix< 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 LaspackMatrix< T >::update_sparsity_pattern (const SparsityPattern::Graph &sparsity_pattern) [virtual]Updates the matrix sparsity pattern. This will tell the underlying matrix storage scheme how to map the $ (i,j) $ elements.
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 LaspackMatrix< T >::zero () [inline, virtual]Set all entries to 0.
template<typename T> void SparseMatrix< T >::zero_rows (std::vector< int > &rows, Tdiag_value = 0.0) [virtual, inherited]Set all row entries to 0 then puts diag_value in the diagonal entry
Friends And Related Function Documentation
template<typename T> friend class LaspackLinearSolver< T > [friend]
template<typename T> friend class LaspackVector< T > [friend]Make other Laspack datatypes friends
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
template<typename T> bool LaspackMatrix< T >::_closed [private]Flag indicating if the matrix has been closed yet.
ReferenceCounter::Counts ReferenceCounter::_counts [static, protected, inherited]Actually holds the data.
template<typename T> std::vector<unsigned int> LaspackMatrix< T >::_csr [private]The compressed row indices.
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.
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.
template<typename T> QMatrix LaspackMatrix< T >::_QMat [private]The Laspack sparse matrix pointer.
template<typename T> std::vector<std::vector<unsigned int>::const_iterator> LaspackMatrix< T >::_row_start [private]The start of each row in the compressed row index data structure.
Author

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