14 template <
typename _Type>
16 : m_nr(rows), m_nc(cols) {
17 m_matrix.reserve(m_nr);
19 for(std::size_t i = 0; i < m_nr; ++i) {
20 m_matrix.push_back(sparse_row);
24 template <
typename _Type>
26 m_nr(source.nrows()), m_nc(source.ncols()) {
27 m_matrix.reserve(m_nr);
28 for(std::size_t i = 0; i < m_nr; ++i) {
29 m_matrix.push_back(source.get_row(source_rows[i]));
33 template <
typename _Type>
38 template <
typename _Type>
42 m_matrix = source.m_matrix;
48 template <
typename _Type>
50 std::size_t num_of_elts(0);
51 for(std::size_t row = 0; row < m_nr; ++row) {
52 num_of_elts += m_matrix[ row ].nelts();
57 template <
typename _Type>
59 const std::size_t& row_min,
const std::size_t& row_max)
const {
62 std::size_t index = nrows();
63 for(std::size_t row = row_min; row < row_max ; ++row) {
66 if(m_matrix[ row ].begin() -> first <= col) {
67 const double elt(std::abs(m_matrix[ row ].get(col)));
77 template <
typename _Type>
79 for(std::size_t row = 0; row < m_nr; ++row) {
80 m_matrix[ row ] *= mult;
84 template <
typename _Type>
87 for(std::size_t row = 0; row < m_nr; ++row) {
88 max = std::max(max, m_matrix[ row ].one_norm());
93 template <
typename _Type>
96 for(std::size_t row = 0; row < m_nr; ++row) {
97 max = std::max(max, m_matrix[ row ].two_norm());
102 template <
typename _Type>
105 for(std::size_t row = 0; row < m_nr; ++row) {
106 max = std::max(max, m_matrix[ row ].inf_norm());
111 template <
typename _Type>
114 for(std::size_t row = 0; row < m_nr; ++row) {
115 sum += m_matrix[ row ].two_norm();
124 PetscScalar* storage, PetscInt* cols) {
130 if(m_matrix[row].nelts() > 0) {
132 pos = m_matrix[ row ].begin();
136 elt = std::real(pos -> second) + PETSC_i * std::imag(pos -> second);
137 int col(pos -> first);
143 }
while(pos != m_matrix[ row ].end());
150 void SparseMatrix<std::complex<double> >::get_row_petsc(PetscInt row, PetscScalar* storage, PetscInt* cols) {
152 problem =
"The SparseMatrix::get_row_petsc method was called for a SparseMatrix<D_complex>\n";
153 problem +=
"even though PETSC_ARCH is currently pointing to a double version of the library.\n";
154 throw ExceptionExternal(problem);
161 void SparseMatrix<double >::get_row_petsc(PetscInt row, PetscScalar* storage, PetscInt* cols) {
167 if(m_matrix[row].nelts() > 0) {
169 pos = m_matrix[ row ].begin();
174 int col(pos -> first);
180 }
while(pos != m_matrix[ row ].end());
187 void SparseMatrix<double >::get_row_petsc(PetscInt row, PetscScalar* storage, PetscInt* cols) {
189 problem =
"The SparseMatrix::get_row_petsc method was called for a SparseMatrix<double>\n";
190 problem +=
"even though PETSC_ARCH is currently pointing to a complex version of the library.\n";
191 throw ExceptionExternal(problem);
196 template <
typename _Type>
198 std::cout <<
"SPARSE mtx size = " << m_nr <<
" x sparse \n";
199 std::cout <<
"- start matrix \n";
200 for(std::size_t row = 0; row < m_nr; ++row) {
201 std::cout <<
" row " << row <<
" : ";
202 m_matrix[ row ].dump();
205 std::cout <<
"- end matrix \n";
The collection of CppNoddy exceptions.
A matrix class that constructs a SPARSE matrix as an STL Vector of SparseVectors, inheriting from Mat...
A matrix class that constructs a SPARSE matrix as a row major std::vector of SparseVectors.
void dump() const
Output the contents of the matrix to std::cout.
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.
SparseMatrix(const std::size_t &rows, const std::size_t &cols)
Construct with a set number of rows.
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.
An SparseVector class – a sparse vector object.
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...