19#if defined(PETSC_D) || defined(PETSC_Z)
25 template <
typename _SystemType>
26 class SparseLinearSystem;
30 template <
typename _Type>
32 typedef typename std::map< std::size_t, _Type >::const_iterator citer;
33 typedef typename std::map< std::size_t, _Type >::iterator iter;
40 SparseMatrix(
const std::size_t& rows,
const std::size_t& cols);
62 m_matrix.reserve(m_nr);
64 for(std::size_t i = 0; i < m_nr; ++i) {
65 m_matrix.push_back(sparse_row);
70 const _Type&
operator()(
const std::size_t& row,
const std::size_t& col)
const;
73 _Type&
operator()(
const std::size_t& row,
const std::size_t& col);
75 const _Type&
get(
const std::size_t& row,
const std::size_t& col)
const;
77 _Type&
set(
const std::size_t& row,
const std::size_t& col);
91 m_matrix[row] = row_vector;
96 std::size_t
nrows()
const;
100 std::size_t
ncols()
const;
104 std::size_t
nelts()
const;
108 void scale(
const _Type& mult);
137 void dump(std::string filename,
int precision = 10)
const {
139 dump.open(filename.c_str());
140 dump.precision(precision);
141 dump.setf(std::ios::showpoint);
142 dump.setf(std::ios::showpos);
143 dump.setf(std::ios::scientific);
144 for(std::size_t row = 0; row < m_nr; ++row) {
145 for(citer pos = m_matrix[row].begin(); pos != m_matrix[row].end(); ++pos) {
146 dump << row <<
" " << pos -> first <<
" " << pos -> second <<
"\n";
168#if defined (PETSC_D) || defined (PETSC_Z)
179 void get_row_petsc(PetscInt row_number, PetscScalar* storage, PetscInt* cols);
185 void nelts_all_rows(PetscInt* row_nnz) {
186 for(std::size_t i = 0; i < m_nr; ++i) {
187 row_nnz[i] = m_matrix[i].nelts();
195 return m_matrix[row].nelts();
202 std::size_t
max_in_col(
const std::size_t& col,
const std::size_t& row_min,
203 const std::size_t& row_max)
const;
208 void row_swap(
const std::size_t& row1,
const std::size_t& row2);
213 std::vector< SparseVector<_Type> > m_matrix;
219 template <
typename _SystemType>
228 template <
typename _Type>
230 return m_matrix[ row ].get(col);
233 template <
typename _Type>
235 return m_matrix[ row ][ col ];
238 template <
typename _Type>
240 return this -> operator()(row, col);
243 template <
typename _Type>
245 return this -> operator()(row, col);
248 template <
typename _Type>
251 if((row > m_nr) || (row < 0)) {
252 std::string problem(
"The SparseMatrix.get_row has a range error.\n");
256 return m_matrix[ row ];
260 template <
typename _Type>
263 if((row > m_nr) || (row < 0)) {
264 std::string problem(
"The SparseMatrix.get_row has a range error.\n");
268 return m_matrix[ row ];
271 template <
typename _Type>
276 template <
typename _Type>
281 template <
typename _Type>
285 m_matrix[ row1 ].swap(m_matrix[ row2 ]);
Specification for a templated DenseVector class – a dense, dynamic, vector object.
The collection of CppNoddy exceptions.
A base matrix class to ensure a consistent interface between the inheriting dense/banded matrix class...
A templated SparseVector class – a sparse, variable size, vector object.
An DenseVector class – a dense vector object.
An exception to indicate that a CppNoddy container has been accessed with index/indices outside the m...
A base matrix class for sequential matrices.
A linear system class for vector right-hand sides.
A matrix class that constructs a SPARSE matrix as a row major std::vector of SparseVectors.
void row_swap(const std::size_t &row1, const std::size_t &row2)
Swap two rows in the matrix – used in the native solver.
std::size_t nelts_in_row(int row)
The number of non-zero elements in a specified row.
void blank()
Blank the contents of this matrix.
void dump() const
Output the contents of the matrix to std::cout.
~SparseMatrix()
Default d-tor.
void dump(std::string filename, int precision=10) const
A simple method for dumping the matrix to a file.
_Type & set(const std::size_t &row, const std::size_t &col)
Access operator.
void set_row(const std::size_t &row, const SparseVector< _Type > &row_vector)
Set a row of the matrix.
DenseVector< _Type > multiply(const DenseVector< _Type > &X) const
Right-multiply by a DENSE vector.
SparseVector< _Type > get_row(const std::size_t &row) const
Get a row of the matrix.
const _Type & get(const std::size_t &row, const std::size_t &col) const
Access operator.
const _Type & operator()(const std::size_t &row, const std::size_t &col) const
Access operator.
SparseMatrix & operator=(const SparseMatrix &source)
Assignment operator.
void scale(const _Type &mult)
Scale the matrix by a scalar.
double one_norm() const
Transpose the matrix in place.
std::size_t nelts() const
Get the number of (non-zero) elements in the matrix.
SparseVector< _Type > & operator[](const std::size_t &row)
Operator overloading for ROW access.
std::size_t ncols() const
Get the number of columns in the matrix.
std::size_t max_in_col(const std::size_t &col, const std::size_t &row_min, const std::size_t &row_max) const
Find the maximum entry in a column – used in the native solver.
std::size_t nrows() const
Get the number of rows in the matrix.
An SparseVector class – a sparse vector object.
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...