#include <laspack_matrix.h>
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 AutoPtr< SparseMatrix< T > > build (const SolverPackage solver_package=libMesh::default_solver_package())
static std::string get_info ()
static void print_info ()
static unsigned int n_objects ()
typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
virtual void _get_submatrix (SparseMatrix< T > &, 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)
DofMap const * _dof_map
bool _is_initialized
static Counts _counts
static Threads::atomic< unsigned int > _n_objects
static Threads::spin_mutex _mutex
unsigned int pos (const unsigned int i, const unsigned int j) const
QMatrix _QMat
std::vector< unsigned int > _csr
std::vector< std::vector< unsigned int >::const_iterator > _row_start
bool _closed
class LaspackVector< T >
class LaspackLinearSolver< T >
template<typename U > std::ostream & operator<< (std::ostream &os, const SparseMatrix< U > &m)
Author:
Definition at line 63 of file laspack_matrix.h.
Definition at line 105 of file reference_counter.h.
You have to initialize the matrix before usage with init(...).
Definition at line 329 of file laspack_matrix.h.
:
_closed (false)
{
}
Definition at line 338 of file laspack_matrix.h.
References LaspackLinearSolver< T >::clear().
{
this->clear ();
}
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();
}
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);
}
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);
}
}
}
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));
}
Implements SparseMatrix< T >.
Definition at line 475 of file laspack_matrix.h.
{
this->add_matrix (dm, dof_indices, dof_indices);
}
Definition at line 100 of file sparse_matrix.h.
Referenced by DofMap::attach_matrix().
{ _dof_map = &dof_map; }
Definition at line 40 of file sparse_matrix.C.
References LASPACK_SOLVERS, libMeshEnums::PETSC_SOLVERS, and TRILINOS_SOLVERS.
{
// Build the appropriate vector
switch (solver_package)
{
#ifdef LIBMESH_HAVE_LASPACK
case LASPACK_SOLVERS:
{
AutoPtr<SparseMatrix<T> > ap(new LaspackMatrix<T>);
return ap;
}
#endif
#ifdef LIBMESH_HAVE_PETSC
case PETSC_SOLVERS:
{
AutoPtr<SparseMatrix<T> > ap(new PetscMatrix<T>);
return ap;
}
#endif
#ifdef LIBMESH_HAVE_TRILINOS
case TRILINOS_SOLVERS:
{
AutoPtr<SparseMatrix<T> > ap(new EpetraMatrix<T>);
return ap;
}
#endif
default:
std::cerr << 'ERROR: Unrecognized solver package: '
<< solver_package
<< std::endl;
libmesh_error();
}
AutoPtr<SparseMatrix<T> > ap(NULL);
return ap;
}
Implements SparseMatrix< T >.
Definition at line 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;
}
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; }
Implements SparseMatrix< T >.
Definition at line 267 of file laspack_matrix.h.
References LaspackMatrix< T >::_closed.
{ return _closed; }
Definition at line 325 of file sparse_matrix.h.
{
this->_get_submatrix(submatrix,
rows,
cols,
false); // false means DO NOT REUSE submatrix
}
Implements SparseMatrix< T >.
Definition at line 199 of file laspack_matrix.C.
{
libmesh_not_implemented();
}
Definition at line 45 of file reference_counter.C.
References ReferenceCounter::_counts, and Quality::name().
Referenced by ReferenceCounter::print_info().
{
#if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
std::ostringstream out;
out << '
<< ' ----------------------------------------------------------------------------
<< '| Reference count information |
<< ' ---------------------------------------------------------------------------- ;
for (Counts::iterator it = _counts.begin();
it != _counts.end(); ++it)
{
const std::string name(it->first);
const unsigned int creations = it->second.first;
const unsigned int destructions = it->second.second;
out << '| ' << name << ' reference count information:
<< '| Creations: ' << creations << '
<< '| Destructions: ' << destructions << ';
}
out << ' ---------------------------------------------------------------------------- ;
return out.str();
#else
return '';
#endif
}
Implements SparseMatrix< T >.
Definition at line 207 of file laspack_matrix.C.
{
libmesh_not_implemented();
}
Definition at line 149 of file reference_counter.h.
References ReferenceCounter::_counts, Quality::name(), and Threads::spin_mtx.
Referenced by ReferenceCountedObject< Value >::ReferenceCountedObject().
{
Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
std::pair<unsigned int, unsigned int>& p = _counts[name];
p.first++;
}
Definition at line 167 of file reference_counter.h.
References ReferenceCounter::_counts, Quality::name(), and Threads::spin_mtx.
Referenced by ReferenceCountedObject< Value >::~ReferenceCountedObject().
{
Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
std::pair<unsigned int, unsigned int>& p = _counts[name];
p.second++;
}
Implements SparseMatrix< T >.
Definition at line 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;
}
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());
}
Definition at line 95 of file sparse_matrix.h.
Referenced by PetscMatrix< T >::_get_submatrix(), ImplicitSystem::assemble(), and ImplicitSystem::init_matrices().
{ return _is_initialized; }
Definition at line 248 of file laspack_matrix.h.
{ libmesh_error(); return 0.; }
Definition at line 261 of file laspack_matrix.h.
{ libmesh_error(); return 0.; }
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)));
}
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)));
}
Definition at line 76 of file reference_counter.h.
References ReferenceCounter::_n_objects.
Referenced by System::read_serialized_blocked_dof_objects(), and System::write_serialized_blocked_dof_objects().
{ return _n_objects; }
Reimplemented from SparseMatrix< T >.
Definition at line 94 of file laspack_matrix.h.
{ return true; }
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);
}
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);
}
Definition at line 118 of file sparse_matrix.C.
References libMesh::initialized(), libMesh::n_processors(), and libMesh::processor_id().
Referenced by LaspackMatrix< T >::print_personal().
{
parallel_only();
libmesh_assert (this->initialized());
// We'll print the matrix from processor 0 to make sure
// it's serialized properly
if (libMesh::processor_id() == 0)
{
libmesh_assert(this->_dof_map->first_dof() == 0);
for (unsigned int i=this->_dof_map->first_dof();
i!=this->_dof_map->end_dof(); ++i)
{
for (unsigned int j=0; j<this->n(); j++)
os << (*this)(i,j) << ' ';
os << std::endl;
}
std::vector<unsigned int> ibuf, jbuf;
std::vector<T> cbuf;
unsigned int currenti = this->_dof_map->end_dof();
for (unsigned int p=1; p < libMesh::n_processors(); ++p)
{
Parallel::receive(p, ibuf);
Parallel::receive(p, jbuf);
Parallel::receive(p, cbuf);
libmesh_assert(ibuf.size() == jbuf.size());
libmesh_assert(ibuf.size() == cbuf.size());
if (ibuf.empty())
continue;
libmesh_assert(ibuf.front() >= currenti);
libmesh_assert(ibuf.back() >= ibuf.front());
unsigned int currentb = 0;
for (;currenti <= ibuf.back(); ++currenti)
{
for (unsigned int j=0; j<this->n(); j++)
{
if (currentb < ibuf.size() &&
ibuf[currentb] == currenti &&
jbuf[currentb] == j)
{
os << cbuf[currentb] << ' ';
currentb++;
}
else
os << static_cast<T>(0.0) << ' ';
}
os << std::endl;
}
}
for (; currenti != this->m(); ++currenti)
{
for (unsigned int j=0; j<this->n(); j++)
os << static_cast<T>(0.0) << ' ';
os << std::endl;
}
}
else
{
std::vector<unsigned int> ibuf, jbuf;
std::vector<T> cbuf;
// We'll assume each processor has access to entire
// matrix rows, so (*this)(i,j) is valid if i is a local index.
for (unsigned int i=this->_dof_map->first_dof();
i!=this->_dof_map->end_dof(); ++i)
{
for (unsigned int j=0; j<this->n(); j++)
{
T c = (*this)(i,j);
if (c != static_cast<T>(0.0))
{
ibuf.push_back(i);
jbuf.push_back(j);
cbuf.push_back(c);
}
}
}
Parallel::send(0,ibuf);
Parallel::send(0,jbuf);
Parallel::send(0,cbuf);
}
}
Definition at line 429 of file sparse_matrix.h.
{
// std::complex<>::operator<<() is defined, but use this form
std::cout << 'Real part:' << std::endl;
for (unsigned int i=0; i<this->m(); i++)
{
for (unsigned int j=0; j<this->n(); j++)
os << std::setw(8) << (*this)(i,j).real() << ' ';
os << std::endl;
}
os << std::endl << 'Imaginary part:' << std::endl;
for (unsigned int i=0; i<this->m(); i++)
{
for (unsigned int j=0; j<this->n(); j++)
os << std::setw(8) << (*this)(i,j).imag() << ' ';
os << std::endl;
}
}
Definition at line 83 of file reference_counter.C.
References ReferenceCounter::get_info().
{
#if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
std::cout << ReferenceCounter::get_info();
#endif
}
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();
}
Implements SparseMatrix< T >.
Definition at line 273 of file laspack_matrix.h.
References SparseMatrix< T >::print().
{ this->print(os); }
Definition at line 341 of file sparse_matrix.h.
{
this->_get_submatrix(submatrix,
rows,
cols,
true); // true means REUSE submatrix
}
Implements SparseMatrix< T >.
Definition at line 416 of file laspack_matrix.h.
{
return 0;
}
Implements SparseMatrix< T >.
Definition at line 425 of file laspack_matrix.h.
{
return this->m();
}
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);
}
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();
}
Definition at line 87 of file sparse_matrix.C.
References NumericVector< T >::zero().
{
dest.zero();
this->vector_mult_add(dest,arg);
}
Definition at line 97 of file sparse_matrix.C.
References NumericVector< T >::add_vector().
{
/* This functionality is actually implemented in the
NumericVector class. */
dest.add_vector(arg,*this);
}
Implements SparseMatrix< T >.
Definition at line 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.);
}
}
}
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();
}
Definition at line 320 of file laspack_matrix.h.
Definition at line 319 of file laspack_matrix.h.
Definition at line 314 of file laspack_matrix.h.
Referenced by LaspackMatrix< T >::close(), and LaspackMatrix< T >::closed().
Definition at line 110 of file reference_counter.h.
Referenced by ReferenceCounter::get_info(), ReferenceCounter::increment_constructor_count(), and ReferenceCounter::increment_destructor_count().
Definition at line 303 of file laspack_matrix.h.
Definition at line 395 of file sparse_matrix.h.
Referenced by SparseMatrix< Number >::attach_dof_map().
Definition at line 401 of file sparse_matrix.h.
Referenced by PetscMatrix< T >::_get_submatrix(), PetscMatrix< T >::get_transpose(), SparseMatrix< Number >::initialized(), and PetscMatrix< T >::PetscMatrix().
Definition at line 123 of file reference_counter.h.
Definition at line 118 of file reference_counter.h.
Referenced by ReferenceCounter::n_objects(), ReferenceCounter::ReferenceCounter(), and ReferenceCounter::~ReferenceCounter().
Definition at line 298 of file laspack_matrix.h.
Referenced by LaspackLinearSolver< T >::solve().
Definition at line 309 of file laspack_matrix.h.
Generated automatically by Doxygen for libMesh from the source code.