42 template<
typename Scalar>
47 template<
typename Scalar>
53 template<
typename Scalar>
56 for (
unsigned int i = 0; i < this->size; i++)
62 template<
typename Scalar>
65 if (!vector_out_initialized)
66 vector_out = malloc_with_check<Scalar>(this->size);
67 for (
unsigned int i = 0; i < this->size; i++)
69 vector_out[i] = Scalar(0.);
70 for (
unsigned int j = 0; j < this->size; j++)
71 vector_out[i] += this->
get(i, j) * vector_in[j];
75 template<
typename Scalar>
81 template<
typename Scalar>
88 void Matrix<double>::add(
unsigned int m,
unsigned int n,
double *mat,
int *rows,
int *cols,
const int size)
90 for (
unsigned int i = 0; i < m; i++)
92 for (
unsigned int j = 0; j < n; j++)
94 double entry = mat[i * size + j];
97 if (rows[i] >= 0 && cols[j] >= 0)
98 add(rows[i], cols[j], entry);
105 void Matrix<std::complex<double> >::add(
unsigned int m,
unsigned int n, std::complex<double>* mat,
int *rows,
int *cols,
const int size)
107 for (
unsigned int i = 0; i < m; i++)
109 for (
unsigned int j = 0; j < n; j++)
111 std::complex<double> entry = mat[i * size + j];
114 if (rows[i] >= 0 && cols[j] >= 0)
115 add(rows[i], cols[j], mat[i * size + j]);
121 template<
typename Scalar>
125 next_pages =
nullptr;
128 template<
typename Scalar>
133 next_pages =
nullptr;
136 template<
typename Scalar>
142 template<
typename Scalar>
147 free_with_check(pages);
152 for (
unsigned int i = 0; i < this->size; i++)
153 delete next_pages[i];
154 free_with_check(next_pages);
158 template<
typename Scalar>
163 template<
typename Scalar>
169 template<
typename Scalar>
171 unsigned int &n_entries,
double *vals,
172 unsigned int *idxs)
const
176 template<
typename Scalar>
182 template<
typename Scalar>
184 unsigned int &n_entries,
double *vals,
185 unsigned int *idxs)
const
189 template<
typename Scalar>
192 add_as_block(0, 0, mat);
195 template<
typename Scalar>
199 if (this->get_size() != (
unsigned int)num_stages * ndof)
202 for (
int i = 0; i < num_stages; i++)
203 this->add_as_block(ndof*i, ndof*i, mat);
206 template<
typename Scalar>
209 if ((this->get_size() < offset_i + mat->
get_size()) || (this->get_size() < offset_j + mat->
get_size()))
211 unsigned int block_size = mat->
get_size();
212 for (
unsigned int r = 0; r < block_size; r++)
214 for (
unsigned int c = 0; c < block_size; c++)
216 this->add(offset_i + r, offset_j + c, mat->
get(r, c));
221 template<
typename Scalar>
227 template<
typename Scalar>
234 template<
typename Scalar>
238 pages = malloc_with_check<SparseMatrix<Scalar>,
Page>(n,
this);
241 template<
typename Scalar>
244 if (pages[col].count >= PAGE_SIZE)
246 Page* final_page = &(pages[col]);
247 while (final_page->
next !=
nullptr && final_page->
count >= PAGE_SIZE)
248 final_page = final_page->
next;
250 if (final_page->
next ==
nullptr && final_page->
count >= PAGE_SIZE)
253 final_page = final_page->
next;
255 final_page->
idx[final_page->
count++] = row;
258 pages[col].idx[pages[col].count++] = row;
261 template<
typename Scalar>
266 while (page !=
nullptr)
268 memcpy(end, page->
idx,
sizeof(
int)* page->
count);
277 qsort_int(buffer, end - buffer);
279 for (
int *p = buffer, last = -1; p < end; p++)
286 template<
typename Scalar>
290 for (
unsigned int i = 0; i < this->size; i++)
291 for (
Page *page = &pages[i]; page !=
nullptr; page = page->
next)
292 total += page->count;
302 case Hermes::SOLVER_EXTERNAL:
307 case Hermes::SOLVER_AMESOS:
309 #if defined HAVE_AMESOS && defined HAVE_EPETRA
316 case Hermes::SOLVER_AZTECOO:
318 if (use_direct_solver)
320 #if defined HAVE_AZTECOO && defined HAVE_EPETRA
327 case Hermes::SOLVER_MUMPS:
336 case Hermes::SOLVER_PETSC:
338 if (use_direct_solver)
341 return new PetscMatrix < double > ;
347 case Hermes::SOLVER_UMFPACK:
356 case Hermes::SOLVER_PARALUTION_ITERATIVE:
357 case Hermes::SOLVER_PARALUTION_AMG:
359 if (use_direct_solver)
361 #ifdef WITH_PARALUTION
368 case Hermes::SOLVER_SUPERLU:
388 case Hermes::SOLVER_EXTERNAL:
392 case Hermes::SOLVER_AMESOS:
394 #if defined HAVE_AMESOS && defined HAVE_EPETRA
401 case Hermes::SOLVER_AZTECOO:
403 if (use_direct_solver)
405 #if defined HAVE_AZTECOO && defined HAVE_EPETRA
412 case Hermes::SOLVER_MUMPS:
421 case Hermes::SOLVER_PETSC:
423 if (use_direct_solver)
426 return new PetscMatrix < std::complex<double> > ;
432 case Hermes::SOLVER_UMFPACK:
441 case Hermes::SOLVER_PARALUTION_ITERATIVE:
442 case Hermes::SOLVER_PARALUTION_AMG:
444 if (use_direct_solver)
446 #ifdef WITH_PARALUTION
453 case Hermes::SOLVER_SUPERLU:
General (abstract) matrix representation in Hermes.
virtual unsigned int get_size() const
virtual void add_to_diagonal(Scalar v)
Add a number to each diagonal entry.
AmesosSolver class as an interface to Amesos.
General namespace for the Hermes library.
bool dyn_stored
this page is stored in the dynamically allocated part.
Linear matrix solver functionality.
virtual void extract_col_copy(unsigned int col, unsigned int len, unsigned int &n_entries, double *vals, unsigned int *idxs) const
Exception interface Basically a std::exception, but with a constructor with string and with print_msg...
PARALUTION solver interface.
HERMES_API SparseMatrix< Scalar > * create_matrix(bool use_direct_solver=false)
Function returning a matrix according to the users's choice.
File containing common definitions, and basic global enums etc. for HermesCommon. ...
virtual void multiply_with_Scalar(Scalar value)
Multiply with a Scalar.
General (abstract) sparse matrix representation in Hermes.
virtual void set_row_zero(unsigned int n)
AztecOOSolver class as an interface to AztecOO.
General CSC Matrix class. (can be used in umfpack, in that case use the CSCMatrix subclass...
HERMES_COMMON_API Hermes::Api HermesCommonApi
Global instance used inside Hermes which is also accessible to users.
virtual unsigned int get_nnz() const
virtual void add_sparse_to_diagonal_blocks(int num_stages, SparseMatrix< Scalar > *mat)
int idx[PAGE_SIZE]
buffer for storing indices
General Paralution matrix.
int sort_and_store_indices(Page *page, int *buffer, int *max)
Matrix used with MUMPS solver.
virtual void add_sparse_matrix(SparseMatrix< Scalar > *mat)
File containing functionality for investigating call stack.
virtual int get_num_row_entries(unsigned int row) const
Basic matrix classes and operations.
UMFPACK solver interface.
unsigned char count
number of indices stored
virtual void multiply_with_vector(Scalar *vector_in, Scalar *&vector_out, bool vector_out_initialized=false) const
Multiply with a vector.
virtual void prealloc(unsigned int n)
Structure for storing indices in sparse matrix.
The QuickSort routine from glibc-2.5 modified for sorting int arrays.
virtual SparseMatrix< Scalar > * duplicate() const
Duplicate sparse matrix (including allocation).
virtual Scalar get(unsigned int m, unsigned int n) const =0
virtual void free()
free the memory associated with stiffness matrix
Method is not overriden and should be.
Matrix(unsigned int size=0)
File containing common definitions, and basic global enums etc. for HermesCommon. ...
virtual void pre_add_ij(unsigned int row, unsigned int col)
SuperLU solver interface.
virtual void extract_row_copy(unsigned int row, unsigned int len, unsigned int &n_entries, double *vals, unsigned int *idxs) const
virtual void add_as_block(unsigned int i, unsigned int j, SparseMatrix< Scalar > *mat)
virtual int get_num_col_entries(unsigned int col) const
Page * next
pointer to next page
virtual void add(unsigned int m, unsigned int n, Scalar v)=0
virtual void finish()
Finish manipulation with matrix (called before solving)