30#ifndef OOMPH_MATRICES_HEADER
31#define OOMPH_MATRICES_HEADER
35#include <oomph-lib-config.h>
53#ifdef OOMPH_HAS_TRILINOS
60#define OOMPH_INITIALISE_DENSE_MATRICES
61#undef OOMPH_INITIALISE_DENSE_MATRICES
72 template<
class T,
class MATRIX_TYPE>
82 std::ostringstream error_message;
83 error_message <<
"Range Error: i=" <<
i <<
" is not in the range (0,"
84 <<
nrow() - 1 <<
")." << std::endl;
92 std::ostringstream error_message;
93 error_message <<
"Range Error: j=" <<
j <<
" is not in the range (0,"
94 <<
ncol() - 1 <<
")." << std::endl;
117 virtual unsigned long nrow()
const = 0;
120 virtual unsigned long ncol()
const = 0;
128 inline T
operator()(
const unsigned long&
i,
const unsigned long&
j)
const
155 "Output function is not implemented for this matrix class",
169 std::ostream&
outfile)
const = 0;
280 virtual unsigned long nrow()
const = 0;
283 virtual unsigned long ncol()
const = 0;
292 const unsigned long&
j)
const = 0;
334 unsigned nrow_local =
residual_.nrow_local();
336 for (
unsigned i = 0;
i < nrow_local;
i++)
410 for (
unsigned long i = 0;
i <
N;
i++)
412 for (
unsigned long j = 0;
j <
M;
j++)
428 if ((
N !=
n) || (
M !=
m))
433 for (
unsigned long i = 0;
i <
N;
i++)
435 for (
unsigned long j = 0;
j <
M;
j++)
447 inline T&
entry(
const unsigned long&
i,
const unsigned long&
j)
457 inline T
get_entry(
const unsigned long&
i,
const unsigned long&
j)
const
474 const unsigned long&
m,
485 inline unsigned long nrow()
const
491 inline unsigned long ncol()
const
505 void resize(
const unsigned long&
n,
const unsigned long&
m);
510 const unsigned long&
m,
516 for (
unsigned long i = 0;
i < (
N *
M); ++
i)
560 template<
class T,
class MATRIX_TYPE>
599 for (
unsigned long i = 0;
i <
Nnz;
i++)
628 inline unsigned long nrow()
const
634 inline unsigned long ncol()
const
640 inline unsigned long nnz()
const
650 std::string error_message =
"SparseMatrix::output_bottom_right_zero_"
651 "helper() is a virtual function.\n";
653 "It must be overloaded for specific sparse matrix storage formats\n";
663 std::string error_message =
664 "SparseMatrix::sparse_indexed_output_helper() is a virtual function.\n";
666 "It must be overloaded for specific sparse matrix storage formats\n";
700 const unsigned long&
n,
701 const unsigned long&
m)
719 for (
unsigned long i = 0;
i < this->
Nnz;
i++)
728 for (
unsigned long i = 0;
i <= this->
N;
i++)
757 return this->
Value[k];
764 T&
entry(
const unsigned long&
i,
const unsigned long&
j)
767 "Non-const access not provided for the CRMatrix<T> class\n";
769 "It is not possible to use round-bracket access: M(i,j)\n";
771 error_string +=
"The solution (albeit ugly) is to create const reference "
830 for (
unsigned long i = 0;
i < this->
N;
i++)
851 const unsigned long&
n,
852 const unsigned long&
m);
863 const unsigned long&
nnz,
864 const unsigned long&
n,
865 const unsigned long&
m);
896 const unsigned&
ncol,
927 "The Index_of_diagonal_entries vector has not been ";
928 err_strng +=
"set up yet. Run sort_entries() to set this vector up.";
932 "CRDoubleMatrix::get_index_of_diagonal_entries()",
945 const std::pair<int, double>&
pair_2)
967 const unsigned&
ncol,
1040 for (
unsigned long i = 0;
i <
n;
i++)
1045 <<
value()[
j] << std::endl;
1054 const unsigned long&
j)
const
1096 inline unsigned long nnz()
const
1285 const unsigned long&
m,
1309 const unsigned long&
j)
const
1387 const unsigned long&
j,
1388 const unsigned long&
k)
const
1392 std::ostringstream error_message;
1393 error_message <<
"Range Error: i=" <<
i <<
" is not in the range (0,"
1394 <<
N - 1 <<
")." << std::endl;
1402 std::ostringstream error_message;
1403 error_message <<
"Range Error: j=" <<
j <<
" is not in the range (0,"
1404 <<
M - 1 <<
")." << std::endl;
1412 std::ostringstream error_message;
1413 error_message <<
"Range Error: k=" <<
k <<
" is not in the range (0,"
1414 <<
P - 1 <<
")." << std::endl;
1437 for (
unsigned i = 0;
i <
N;
i++)
1439 for (
unsigned j = 0;
j <
M;
j++)
1441 for (
unsigned k = 0;
k <
P;
k++)
1460 if ((
N !=
n) || (
M !=
m) || (
P !=
p))
1466 for (
unsigned long i = 0;
i <
N;
i++)
1468 for (
unsigned long j = 0;
j <
M;
j++)
1470 for (
unsigned long k = 0;
k <
P;
k++)
1492#ifdef OOMPH_INITIALISE_DENSE_MATRICES
1509#ifdef OOMPH_INITIALISE_DENSE_MATRICES
1564#ifdef OOMPH_INITIALISE_DENSE_MATRICES
1574 for (
unsigned long i = 0;
i <
n_copy;
i++)
1577 for (
unsigned long j = 0;
j <
m_copy;
j++)
1580 for (
unsigned long k = 0;
k <
p_copy;
k++)
1623 for (
unsigned long i = 0;
i <
n_copy;
i++)
1626 for (
unsigned long j = 0;
j <
m_copy;
j++)
1629 for (
unsigned long k = 0;
k <
p_copy;
k++)
1644 for (
unsigned long i = 0;
i < (
N *
M *
P); ++
i)
1670 const unsigned long&
j,
1671 const unsigned long&
k)
1673#ifdef RANGE_CHECKING
1681 const unsigned long&
j,
1682 const unsigned long&
k)
const
1684#ifdef RANGE_CHECKING
1724 const unsigned long&
j,
1725 const unsigned long&
k,
1726 const unsigned long&
l)
const
1730 std::ostringstream error_message;
1731 error_message <<
"Range Error: i=" <<
i <<
" is not in the range (0,"
1732 <<
N - 1 <<
")." << std::endl;
1740 std::ostringstream error_message;
1741 error_message <<
"Range Error: j=" <<
j <<
" is not in the range (0,"
1742 <<
M - 1 <<
")." << std::endl;
1750 std::ostringstream error_message;
1751 error_message <<
"Range Error: k=" <<
k <<
" is not in the range (0,"
1752 <<
P - 1 <<
")." << std::endl;
1760 std::ostringstream error_message;
1761 error_message <<
"Range Error: l=" <<
l <<
" is not in the range (0,"
1762 <<
Q - 1 <<
")." << std::endl;
1791 for (
unsigned i = 0;
i <
N;
i++)
1793 for (
unsigned j = 0;
j <
M;
j++)
1795 for (
unsigned k = 0;
k <
P;
k++)
1797 for (
unsigned l = 0;
l <
Q;
l++)
1819 if ((
N !=
n) || (
M !=
m) || (
P !=
p) || (
Q != q))
1825 for (
unsigned long i = 0;
i <
N;
i++)
1827 for (
unsigned long j = 0;
j <
M;
j++)
1829 for (
unsigned long k = 0;
k <
P;
k++)
1831 for (
unsigned long l = 0;
l <
Q;
l++)
1874#ifdef OOMPH_INITIALISE_DENSE_MATRICES
1894#ifdef OOMPH_INITIALISE_DENSE_MATRICES
1958#ifdef OOMPH_INITIALISE_DENSE_MATRICES
1969 for (
unsigned long i = 0;
i <
n_copy;
i++)
1972 for (
unsigned long j = 0;
j <
m_copy;
j++)
1975 for (
unsigned long k = 0;
k <
p_copy;
k++)
1978 for (
unsigned long l = 0;
l <
q_copy;
l++)
2033 for (
unsigned long i = 0;
i <
n_copy;
i++)
2036 for (
unsigned long j = 0;
j <
m_copy;
j++)
2039 for (
unsigned long k = 0;
k <
p_copy;
k++)
2042 for (
unsigned long l = 0;
l <
q_copy;
l++)
2065 for (
unsigned long i = 0;
i < (
N *
M *
P *
Q); ++
i)
2097 const unsigned long&
j,
2098 const unsigned long&
k,
2099 const unsigned long&
l)
2101#ifdef RANGE_CHECKING
2110 const unsigned long&
j,
2111 const unsigned long&
k,
2112 const unsigned long&
l)
const
2114#ifdef RANGE_CHECKING
2142 unsigned offset(
const unsigned long&
i,
const unsigned long&
j)
const
2144 return (
Q * (
P * (
M *
i +
j) + 0) + 0);
2182 const unsigned long&
j,
2183 const unsigned long&
k,
2184 const unsigned long&
l,
2185 const unsigned long&
m)
const
2189 std::ostringstream error_message;
2190 error_message <<
"Range Error: i=" <<
i <<
" is not in the range (0,"
2191 <<
N - 1 <<
")." << std::endl;
2199 std::ostringstream error_message;
2200 error_message <<
"Range Error: j=" <<
j <<
" is not in the range (0,"
2201 <<
M - 1 <<
")." << std::endl;
2209 std::ostringstream error_message;
2210 error_message <<
"Range Error: k=" <<
k <<
" is not in the range (0,"
2211 <<
P - 1 <<
")." << std::endl;
2219 std::ostringstream error_message;
2220 error_message <<
"Range Error: l=" <<
l <<
" is not in the range (0,"
2221 <<
Q - 1 <<
")." << std::endl;
2229 std::ostringstream error_message;
2230 error_message <<
"Range Error: m=" <<
m <<
" is not in the range (0,"
2231 <<
R - 1 <<
")." << std::endl;
2257 for (
unsigned i = 0;
i <
N;
i++)
2259 for (
unsigned j = 0;
j <
M;
j++)
2261 for (
unsigned k = 0;
k <
P;
k++)
2263 for (
unsigned l = 0;
l <
Q;
l++)
2265 for (
unsigned m = 0;
m <
R;
m++)
2289 if ((
N !=
n) || (
M !=
m) || (
P !=
p) || (
Q != q) || (
R !=
r))
2295 for (
unsigned long i = 0;
i <
N;
i++)
2297 for (
unsigned long j = 0;
j <
M;
j++)
2299 for (
unsigned long k = 0;
k <
P;
k++)
2301 for (
unsigned long l = 0;
l <
Q;
l++)
2303 for (
unsigned long m = 0;
m <
R;
m++)
2329#ifdef OOMPH_INITIALISE_DENSE_MATRICES
2350#ifdef OOMPH_INITIALISE_DENSE_MATRICES
2414#ifdef OOMPH_INITIALISE_DENSE_MATRICES
2426 for (
unsigned long i = 0;
i <
n_copy;
i++)
2429 for (
unsigned long j = 0;
j <
m_copy;
j++)
2432 for (
unsigned long k = 0;
k <
p_copy;
k++)
2435 for (
unsigned long l = 0;
l <
q_copy;
l++)
2438 for (
unsigned long m = 0;
m <
r_copy;
m++)
2493 for (
unsigned long i = 0;
i <
n_copy;
i++)
2496 for (
unsigned long j = 0;
j <
m_copy;
j++)
2499 for (
unsigned long k = 0;
k <
p_copy;
k++)
2502 for (
unsigned long l = 0;
l <
q_copy;
l++)
2505 for (
unsigned long m = 0;
m <
r_copy;
m++)
2525 for (
unsigned long i = 0;
i < (
N *
M *
P *
Q *
R); ++
i)
2563 const unsigned long&
j,
2564 const unsigned long&
k,
2565 const unsigned long&
l,
2566 const unsigned long&
m)
2568#ifdef RANGE_CHECKING
2576 const unsigned long&
j,
2577 const unsigned long&
k,
2578 const unsigned long&
l,
2579 const unsigned long&
m)
const
2581#ifdef RANGE_CHECKING
2611 const unsigned long&
j,
2612 const unsigned long&
k)
const
2614 return (
R * (
Q * (
P * (
M *
i +
j) +
k) + 0) + 0);
2649 const unsigned long&
n,
2650 const unsigned long&
m)
2670 for (
unsigned long i = 0;
i < this->
Nnz;
i++)
2679 for (
unsigned long i = 0;
i <= this->
M;
i++)
2702#ifdef RANGE_CHECKING
2709 return this->
Value[k];
2717 T&
entry(
const unsigned long&
i,
const unsigned long&
j)
2720 "Non-const access not provided for the CCMatrix<T> class\n";
2722 "It is not possible to use round-bracket access: M(i,j)\n";
2724 error_string +=
"The solution (albeit ugly) is to create const reference "
2783 for (
unsigned long j = 0;
j < this->
N;
j++)
2804 const unsigned long&
n,
2805 const unsigned long&
m);
2815 const unsigned long&
nnz,
2816 const unsigned long&
n,
2817 const unsigned long&
m);
2850 const unsigned long&
n,
2851 const unsigned long&
m);
2877 const unsigned long&
j)
const
2958 Matrixdata =
new T[
n *
n];
2960#ifdef OOMPH_INITIALISE_DENSE_MATRICES
2976 Matrixdata =
new T[
n *
m];
2977#ifdef OOMPH_INITIALISE_DENSE_MATRICES
2988 const unsigned long&
m,
2995 Matrixdata =
new T[
n *
m];
3008 if ((
n == N) && (
m == M))
3021 Matrixdata =
new T[
n *
m];
3023#ifdef OOMPH_INITIALISE_DENSE_MATRICES
3034 for (
unsigned long i = 0;
i <
n_copy;
i++)
3037 for (
unsigned long j = 0;
j <
m_copy;
j++)
3055 const unsigned long&
m,
3059 if ((
n == N) && (
m == M))
3071 Matrixdata =
new T[
n *
m];
3081 for (
unsigned long i = 0;
i <
n_copy;
i++)
3084 for (
unsigned long j = 0;
j <
m_copy;
j++)
3103 for (
unsigned i = 0;
i < N;
i++)
3106 for (
unsigned j = 0;
j < M;
j++)
3138 for (
unsigned i = 0;
i < N;
i++)
3141 for (
unsigned j = 0;
j < M;
j++)
3143 outfile <<
i <<
" " <<
j <<
" " << (*this)(
i,
j) << std::endl;
3192 for (
unsigned i = 0;
i < N;
i++)
3195 for (
unsigned j = 0;
j < M;
j++)
3197 if ((*
this)(
i,
j) != T(0))
3199 outfile <<
i <<
" " <<
j <<
" " << (*this)(
i,
j) << std::endl;
3218 if (this->Value != 0)
3220 delete[] this->Value;
3223 if (this->Row_index != 0)
3225 delete[] this->Row_index;
3226 this->Row_index = 0;
3228 if (this->Column_start != 0)
3230 delete[] this->Column_start;
3231 this->Column_start = 0;
3248 const unsigned long& nnz,
3249 const unsigned long&
n,
3250 const unsigned long&
m)
3262 if (this->Value != 0)
3264 delete[] this->Value;
3266 if (this->Row_index != 0)
3268 delete[] this->Row_index;
3270 if (this->Column_start != 0)
3272 delete[] this->Column_start;
3276 this->Value = value;
3279 this->Row_index = row_index;
3282 this->Column_start = column_start;
3296 const unsigned long&
n,
3297 const unsigned long&
m)
3302 std::ostringstream error_message;
3303 error_message <<
"length of value " << value.
size()
3305 <<
" should match " << std::endl;
3313 this->Nnz = value.
size();
3322 if (this->Value != 0)
3324 delete[] this->Value;
3326 if (this->Row_index != 0)
3328 delete[] this->Row_index;
3330 if (this->Column_start != 0)
3332 delete[] this->Column_start;
3336 this->Value =
new T[this->Nnz];
3339 this->Row_index =
new int[this->Nnz];
3342 for (
unsigned long i = 0;
i < this->Nnz;
i++)
3344 this->Value[
i] = value[
i];
3372 if (this->Value != 0)
3374 delete[] this->Value;
3377 if (this->Column_index != 0)
3379 delete[] this->Column_index;
3380 this->Column_index = 0;
3382 if (this->Row_start != 0)
3384 delete[] this->Row_start;
3385 this->Row_start = 0;
3403 const unsigned long& nnz,
3404 const unsigned long&
n,
3405 const unsigned long&
m)
3417 if (this->Value != 0)
3419 delete[] this->Value;
3421 if (this->Column_index != 0)
3423 delete[] this->Column_index;
3425 if (this->Row_start != 0)
3427 delete[] this->Row_start;
3431 this->Value = value;
3453 const unsigned long&
n,
3454 const unsigned long&
m)
3459 std::ostringstream error_message;
3460 error_message <<
"Must have the same number of values and column indices,"
3461 <<
"we have " << value.
size() <<
" values and "
3469 this->Nnz = value.
size();
3478 if (this->Value != 0)
3480 delete[] this->Value;
3482 if (this->Column_index != 0)
3484 delete[] this->Column_index;
3486 if (this->Row_start != 0)
3488 delete[] this->Row_start;
3492 this->Value =
new T[this->Nnz];
3495 this->Column_index =
new int[this->Nnz];
3498 for (
unsigned long i = 0;
i < this->Nnz;
i++)
3500 this->Value[
i] = value[
i];
3520 template<
class T,
class MATRIX_TYPE>
3526 extern std::string
RayStr;
3533 namespace CRDoubleMatrixHelpers
3544 err_msg <<
"The result matrix has been built.\n"
3545 <<
"Please clear the matrix.\n";
3554 err_msg <<
"The in_matrix_pt is null.\n";
3563 err_msg <<
"The in_matrix_pt is null.\n";
3571 out_matrix.serial_matrix_matrix_multiply_method() =
3574 out_matrix.distributed_matrix_matrix_multiply_method() =
3575 in_matrix_pt->distributed_matrix_matrix_multiply_method();
3622 const unsigned& nrow,
3623 const unsigned& ncol,
A class for compressed column matrices that store doubles.
double operator()(const unsigned long &i, const unsigned long &j) const
Overload the round-bracket access operator to provide read-only (const) access to the data.
void operator=(const CCDoubleMatrix &)=delete
Broken assignment operator.
void multiply_transpose(const DoubleVector &x, DoubleVector &soln) const
Multiply the transposed matrix by the vector x: soln=A^T x.
virtual void lubksub(DoubleVector &rhs)
LU back solve for given RHS.
void matrix_reduction(const double &alpha, CCDoubleMatrix &reduced_matrix)
For every row, find the maximum absolute value of the entries in this row. Set all values that are le...
unsigned & matrix_matrix_multiply_method()
Access function to Matrix_matrix_multiply_method, the flag which determines the matrix matrix multipl...
virtual ~CCDoubleMatrix()
Destructor: Kill the LU factors if they have been setup.
CCDoubleMatrix(const CCDoubleMatrix &matrix)=delete
Broken copy constructor.
unsigned long ncol() const
Return the number of columns of the matrix.
unsigned long nrow() const
Return the number of rows of the matrix.
CCDoubleMatrix()
Default constructor.
virtual void ludecompose()
LU decomposition using SuperLU.
void multiply(const DoubleVector &x, DoubleVector &soln) const
Multiply the matrix by the vector x: soln=Ax.
unsigned Matrix_matrix_multiply_method
Flag to determine which matrix-matrix multiplication method is used.
A class for compressed column matrices: a sparse matrix format The class is passed as the MATRIX_TYPE...
CCMatrix()
Default constructor.
void sparse_indexed_output_helper(std::ostream &outfile) const
Indexed output function to print a matrix to the stream outfile as i,j,a(i,j) for a(i,...
T & entry(const unsigned long &i, const unsigned long &j)
Read-write access is not permitted for these matrices and is deliberately broken.
CCMatrix(const Vector< T > &value, const Vector< int > &row_index_, const Vector< int > &column_start_, const unsigned long &n, const unsigned long &m)
Constructor: Pass vector of values, vector of row indices, vector of column starts and number of rows...
void build_without_copy(T *value, int *row_index, int *column_start, const unsigned long &nnz, const unsigned long &n, const unsigned long &m)
Function to build matrix from pointers to arrays which hold the column starts, row indices and non-ze...
virtual ~CCMatrix()
Destructor, delete any allocated memory.
int * Column_start
Start index for column.
int * Row_index
Row index.
CCMatrix(const CCMatrix &source_matrix)
Copy constructor.
T get_entry(const unsigned long &i, const unsigned long &j) const
Access function that will be called by the read-only round-bracket operator (const)
int * column_start()
Access to C-style column_start array.
void build(const Vector< T > &value, const Vector< int > &row_index, const Vector< int > &column_start, const unsigned long &n, const unsigned long &m)
Build matrix from compressed representation. Number of nonzero entries is read off from value,...
void operator=(const CCMatrix &)=delete
Broken assignment operator.
void output_bottom_right_zero_helper(std::ostream &outfile) const
Output the "bottom right" entry regardless of it being zero or not (this allows automatic detection o...
const int * row_index() const
Access to C-style row index array (const version)
int * row_index()
Access to C-style row index array.
const int * column_start() const
Access to C-style column_start array (const version)
void clean_up_memory()
Wipe matrix data and set all values to 0.
A class for compressed row matrices. This is a distributable object.
unsigned & serial_matrix_matrix_multiply_method()
Access function to Serial_matrix_matrix_multiply_method, the flag which determines the matrix matrix ...
void sort_entries()
Sorts the entries associated with each row of the matrix in the column index vector and the value vec...
virtual ~CRDoubleMatrix()
Destructor.
void sparse_indexed_output_with_offset(std::string filename)
Indexed output function to print a matrix to a file as i,j,a(i,j) for a(i,j)!=0 only....
int * row_start()
Access to C-style row_start array.
struct oomph::CRDoubleMatrix::CRDoubleMatrixComparisonHelper Comparison_struct
void matrix_reduction(const double &alpha, CRDoubleMatrix &reduced_matrix)
For every row, find the maximum absolute value of the entries in this row. Set all values that are le...
void operator=(const CRDoubleMatrix &)=delete
Broken assignment operator.
void multiply_transpose(const DoubleVector &x, DoubleVector &soln) const
Multiply the transposed matrix by the vector x: soln=A^T x.
void sparse_indexed_output_helper(std::ostream &outfile) const
Indexed output function to print a matrix to the stream outfile as i,j,a(i,j) for a(i,...
const double * value() const
Access to C-style value array (const version)
unsigned Distributed_matrix_matrix_multiply_method
Flag to determine which matrix-matrix multiplication method is used (for distributed matrices)
virtual void ludecompose()
LU decomposition using SuperLU if matrix is not distributed or distributed onto a single processor.
unsigned long ncol() const
Return the number of columns of the matrix.
const Vector< int > get_index_of_diagonal_entries() const
Access function: returns the vector Index_of_diagonal_entries. The i-th entry of the vector contains ...
void multiply(const DoubleVector &x, DoubleVector &soln) const
Multiply the matrix by the vector x: soln=Ax.
void add(const CRDoubleMatrix &matrix_in, CRDoubleMatrix &result_matrix) const
element-wise addition of this matrix with matrix_in.
unsigned & distributed_matrix_matrix_multiply_method()
Access function to Distributed_matrix_matrix_multiply_method, the flag which determines the matrix ma...
bool Built
Flag to indicate whether the matrix has been built - i.e. the distribution has been setup AND the mat...
Vector< int > Index_of_diagonal_entries
Vector whose i'th entry contains the index of the last entry below or on the diagonal of the i'th row...
double inf_norm() const
returns the inf-norm of this matrix
void get_matrix_transpose(CRDoubleMatrix *result) const
Returns the transpose of this matrix.
const unsigned & serial_matrix_matrix_multiply_method() const
Read only access function (const version) to Serial_matrix_matrix_multiply_method,...
int * column_index()
Access to C-style column index array.
unsigned long nnz() const
Return the number of nonzero entries (the local nnz)
CRDoubleMatrix * global_matrix() const
if this matrix is distributed then a the equivalent global matrix is built using new and returned....
void redistribute(const LinearAlgebraDistribution *const &dist_pt)
The contents of the matrix are redistributed to match the new distribution. In a non-MPI build this m...
bool built() const
access function to the Built flag - indicates whether the matrix has been build - i....
const unsigned & distributed_matrix_matrix_multiply_method() const
Read only access function (const version) to Distributed_matrix_matrix_multiply_method,...
void build_without_copy(const unsigned &ncol, const unsigned &nnz, double *value, int *column_index, int *row_start)
keeps the existing distribution and just matrix that is stored without copying the matrix data
double * value()
Access to C-style value array.
void output_bottom_right_zero_helper(std::ostream &outfile) const
Output the "bottom right" entry regardless of it being zero or not (this allows automatic detection o...
const int * row_start() const
Access to C-style row_start array (const version)
unsigned long nrow() const
Return the number of rows of the matrix.
unsigned Serial_matrix_matrix_multiply_method
Flag to determine which matrix-matrix multiplication method is used (for serial (or global) matrices)
Vector< double > diagonal_entries() const
returns a Vector of diagonal entries of this matrix. This only works with square matrices....
CRDoubleMatrix()
Default constructor.
bool entries_are_sorted(const bool &doc_unordered_entries=false) const
Runs through the column index vector and checks if the entries follow the regular lexicographical ord...
const int * column_index() const
Access to C-style column index array (const version)
CRMatrix< double > CR_matrix
Storage for the Matrix in CR Format.
virtual void lubksub(DoubleVector &rhs)
LU back solve for given RHS.
void build(const LinearAlgebraDistribution *distribution_pt, const unsigned &ncol, const Vector< double > &value, const Vector< int > &column_index, const Vector< int > &row_start)
build method: vector of values, vector of column indices, vector of row starts and number of rows and...
double operator()(const unsigned long &i, const unsigned long &j) const
Overload the round-bracket access operator for read-only access. In a distributed matrix i refers to ...
A class for compressed row matrices, a sparse storage format Once again the recursive template trick ...
CRMatrix()
Default constructor.
void clean_up_memory()
Wipe matrix data and set all values to 0.
CRMatrix(const CRMatrix &source_matrix)
Copy constructor.
T & entry(const unsigned long &i, const unsigned long &j)
The read-write access function is deliberately broken.
int * column_index()
Access to C-style column index array.
int * Row_start
Start index for row.
int * Column_index
Column index.
void build(const Vector< T > &value, const Vector< int > &column_index, const Vector< int > &row_start, const unsigned long &n, const unsigned long &m)
Build matrix from compressed representation. Number of nonzero entries is read off from value,...
int * row_start()
Access to C-style row_start array.
void operator=(const CRMatrix &)=delete
Broken assignment operator.
void output_bottom_right_zero_helper(std::ostream &outfile) const
Output the "bottom right" entry regardless of it being zero or not (this allows automatic detection o...
const int * row_start() const
Access to C-style row_start array (const version)
virtual ~CRMatrix()
Destructor, delete any allocated memory.
void build_without_copy(T *value, int *column_index, int *row_start, const unsigned long &nnz, const unsigned long &n, const unsigned long &m)
Function to build matrix from pointers to arrays which hold the row starts, column indices and non-ze...
void sparse_indexed_output_helper(std::ostream &outfile) const
Indexed output function to print a matrix to the stream outfile as i,j,a(i,j) for a(i,...
const int * column_index() const
Access to C-style column index array (const version)
T get_entry(const unsigned long &i, const unsigned long &j) const
Access function that will be called by the read-only round-bracket operator (const)
CRMatrix(const Vector< T > &value, const Vector< int > &column_index_, const Vector< int > &row_start_, const unsigned long &n, const unsigned long &m)
Constructor: Pass vector of values, vector of column indices, vector of row starts and number of rows...
Class of matrices containing doubles, and stored as a DenseMatrix<double>, but with solving functiona...
double & operator()(const unsigned long &i, const unsigned long &j)
Overload the non-const version of the round-bracket access operator for read-write access.
DenseDoubleMatrix()
Constructor, set the default linear solver.
DenseDoubleMatrix(const DenseDoubleMatrix &matrix)=delete
Broken copy constructor.
virtual void lubksub(DoubleVector &rhs)
LU backsubstitution.
virtual ~DenseDoubleMatrix()
Destructor.
void matrix_reduction(const double &alpha, DenseDoubleMatrix &reduced_matrix)
For every row, find the maximum absolute value of the entries in this row. Set all values that are le...
virtual void ludecompose()
LU decomposition using DenseLU (default linea solver)
void multiply_transpose(const DoubleVector &x, DoubleVector &soln) const
Multiply the transposed matrix by the vector x: soln=A^T x.
void multiply(const DoubleVector &x, DoubleVector &soln) const
Multiply the matrix by the vector x: soln=Ax.
unsigned long nrow() const
Return the number of rows of the matrix.
double operator()(const unsigned long &i, const unsigned long &j) const
Overload the const version of the round-bracket access operator for read-only access.
unsigned long ncol() const
Return the number of columns of the matrix.
void eigenvalues_by_jacobi(Vector< double > &eigen_val, DenseMatrix< double > &eigen_vect) const
Determine eigenvalues and eigenvectors, using Jacobi rotations. Only for symmetric matrices....
void operator=(const DenseDoubleMatrix &)=delete
Broken assignment operator.
Dense LU decomposition-based solve of full assembled linear system. VERY inefficient but useful to il...
Class for dense matrices, storing all the values of the matrix as a pointer to a pointer with assorte...
DenseMatrix & operator=(const DenseMatrix &source_matrix)
Copy assignment.
void output(std::ostream &outfile) const
Output function to print a matrix row-by-row to the stream outfile.
T get_entry(const unsigned long &i, const unsigned long &j) const
The access function the will be called by the read-only (const version) round-bracket operator.
void resize(const unsigned long &n, const unsigned long &m)
Resize to a non-square n x m matrix; any values already present will be transfered.
unsigned long nrow() const
Return the number of rows of the matrix.
DenseMatrix(const DenseMatrix &source_matrix)
Copy constructor: Deep copy!
DenseMatrix(const unsigned long &n)
Constructor to build a square n by n matrix.
unsigned long N
Number of rows.
void indexed_output(std::ostream &outfile) const
Indexed output function to print a matrix to the stream outfile as i,j,a(i,j)
void output(std::string filename) const
Output function to print a matrix row-by-row to a file. Specify filename.
void indexed_output(std::string filename) const
Indexed output function to print a matrix to a file as i,j,a(i,j). Specify filename.
DenseMatrix(const unsigned long &n, const unsigned long &m)
Constructor to build a matrix with n rows and m columns.
virtual ~DenseMatrix()
Destructor, clean up the matrix data.
void sparse_indexed_output_helper(std::ostream &outfile) const
Indexed output function to print a matrix to the stream outfile as i,j,a(i,j) for a(i,...
T & entry(const unsigned long &i, const unsigned long &j)
The access function that will be called by the read-write round-bracket operator.
DenseMatrix(const unsigned long &n, const unsigned long &m, const T &initial_val)
Constructor to build a matrix with n rows and m columns, with initial value initial_val.
T * Matrixdata
Internal representation of matrix as a pointer to data.
unsigned long ncol() const
Return the number of columns of the matrix.
void output_bottom_right_zero_helper(std::ostream &outfile) const
Output the "bottom right" entry regardless of it being zero or not (this allows automatic detection o...
unsigned long M
Number of columns.
void initialise(const T &val)
Initialize all values in the matrix to val.
void resize(const unsigned long &n)
Resize to a square nxn matrix; any values already present will be transfered.
void resize(const unsigned long &n, const unsigned long &m, const T &initial_value)
Resize to a non-square n x m matrix and initialize the new values to initial_value.
DenseMatrix()
Empty constructor, simply assign the lengths N and M to 0.
Base class for any linear algebra object that is distributable. Just contains storage for the LinearA...
unsigned nrow() const
access function to the number of global rows.
unsigned nrow_local() const
access function for the num of local rows on this processor.
unsigned first_row() const
access function for the first row on this processor
LinearAlgebraDistribution * distribution_pt() const
access to the LinearAlgebraDistribution
Abstract base class for matrices of doubles – adds abstract interfaces for solving,...
virtual double operator()(const unsigned long &i, const unsigned long &j) const =0
Round brackets to give access as a(i,j) for read only (we're not providing a general interface for co...
virtual unsigned long ncol() const =0
Return the number of columns of the matrix.
DoubleMatrixBase(const DoubleMatrixBase &matrix)=delete
Broken copy constructor.
LinearSolver *const & linear_solver_pt() const
Return a pointer to the linear solver object (const version)
void solve(DoubleVector &rhs)
Complete LU solve (replaces matrix by its LU decomposition and overwrites RHS with solution)....
virtual double max_residual(const DoubleVector &x, const DoubleVector &rhs)
Find the maximum residual r=b-Ax – generic version, can be overloaded for specific derived classes wh...
LinearSolver * Default_linear_solver_pt
virtual void multiply(const DoubleVector &x, DoubleVector &soln) const =0
Multiply the matrix by the vector x: soln=Ax.
virtual ~DoubleMatrixBase()
virtual (empty) destructor
virtual void multiply_transpose(const DoubleVector &x, DoubleVector &soln) const =0
Multiply the transposed matrix by the vector x: soln=A^T x.
LinearSolver * Linear_solver_pt
virtual void residual(const DoubleVector &x, const DoubleVector &b, DoubleVector &residual_)
Find the residual, i.e. r=b-Ax the residual.
DoubleMatrixBase()
(Empty) constructor.
LinearSolver *& linear_solver_pt()
Return a pointer to the linear solver object.
void operator=(const DoubleMatrixBase &)=delete
Broken assignment operator.
virtual unsigned long nrow() const =0
Return the number of rows of the matrix.
A vector in the mathematical sense, initially developed for linear algebra type applications....
double size() const
Calculate the size of the element (length, area, volume,...) in Eulerian computational coordinates....
Describes the distribution of a distributable linear algebra type object. Typically this is a contain...
unsigned first_row() const
access function for the first row on this processor. If not distributed then this is just zero.
Base class for all linear solvers. This merely defines standard interfaces for linear solvers,...
Abstract base class for matrices, templated by the type of object that is stored in them and the type...
T & operator()(const unsigned long &i, const unsigned long &j)
Round brackets to give access as a(i,j) for read-write access. The function uses the MATRIX_TYPE temp...
virtual void output_bottom_right_zero_helper(std::ostream &outfile) const =0
Output the "bottom right" entry regardless of it being zero or not (this allows automatic detection o...
T operator()(const unsigned long &i, const unsigned long &j) const
Round brackets to give access as a(i,j) for read only (we're not providing a general interface for co...
void range_check(const unsigned long &i, const unsigned long &j) const
Range check to catch when an index is out of bounds, if so, it issues a warning message and dies by t...
virtual ~Matrix()
Virtual (empty) destructor.
void sparse_indexed_output(std::ostream &outfile, const unsigned &precision=0, const bool &output_bottom_right_zero=false) const
Indexed output function to print a matrix to the stream outfile as i,j,a(i,j) for a(i,...
virtual void sparse_indexed_output_helper(std::ostream &outfile) const =0
Indexed output function to print a matrix to the stream outfile as i,j,a(i,j) for a(i,...
void operator=(const Matrix &)=delete
Broken assignment operator.
Matrix()
(Empty) constructor
virtual unsigned long nrow() const =0
Return the number of rows of the matrix.
Matrix(const Matrix &matrix)=delete
Broken copy constructor.
void sparse_indexed_output(std::string filename, const unsigned &precision=0, const bool &output_bottom_right_zero=false) const
Indexed output function to print a matrix to the file named filename as i,j,a(i,j) for a(i,...
virtual void output(std::ostream &outfile) const
Output function to print a matrix row-by-row, in the form a(0,0) a(0,1) ... a(1,0) a(1,...
virtual unsigned long ncol() const =0
Return the number of columns of the matrix.
An oomph-lib wrapper to the MPI_Comm communicator object. Just contains an MPI_Comm object (which is ...
An OomphLibError object which should be thrown when an run-time error is encountered....
An OomphLibWarning object which should be created as a temporary object to issue a warning....
unsigned R
5th Tensor dimension
T operator()(const unsigned long &i, const unsigned long &j, const unsigned long &k, const unsigned long &l, const unsigned long &m) const
Overload a const version for read-only access as a(i,j,k,l,m)
RankFiveTensor(const RankFiveTensor &source_tensor)
Copy constructor: Deep copy.
RankFiveTensor & operator=(const RankFiveTensor &source_tensor)
Copy assignement.
unsigned M
2nd Tensor dimension
unsigned long nindex4() const
Return the range of index 4 of the tensor.
RankFiveTensor(const unsigned long &n)
One parameter constructor produces a nxnxnxnxn tensor.
RankFiveTensor()
Empty constructor.
unsigned Q
4th Tensor dimension
unsigned long nindex3() const
Return the range of index 3 of the tensor.
T & raw_direct_access(const unsigned long &i)
Direct access to internal storage of data in flat-packed C-style column-major format....
RankFiveTensor(const unsigned long &n_index1, const unsigned long &n_index2, const unsigned long &n_index3, const unsigned long &n_index4, const unsigned long &n_index5, const T &initial_val)
Four parameter constructor, general non-square tensor.
const T & raw_direct_access(const unsigned long &i) const
Direct access to internal storage of data in flat-packed C-style column-major format....
void resize(const unsigned long &n_index1, const unsigned long &n_index2, const unsigned long &n_index3, const unsigned long &n_index4, const unsigned long &n_index5, const T &initial_value)
Resize to a general tensor.
void resize(const unsigned long &n)
Resize to a square nxnxnxn tensor.
void range_check(const unsigned long &i, const unsigned long &j, const unsigned long &k, const unsigned long &l, const unsigned long &m) const
Range check to catch when an index is out of bounds, if so, it issues a warning message and dies by t...
unsigned long nindex2() const
Return the range of index 2 of the tensor.
T & operator()(const unsigned long &i, const unsigned long &j, const unsigned long &k, const unsigned long &l, const unsigned long &m)
Overload the round brackets to give access as a(i,j,k,l,m)
unsigned long nindex5() const
Return the range of index 5 of the tensor.
unsigned P
3rd Tensor dimension
unsigned offset(const unsigned long &i, const unsigned long &j, const unsigned long &k) const
Caculate the offset in flat-packed Cy-style, column-major format, required for a given i,...
void initialise(const T &val)
Initialise all values in the tensor to val.
unsigned long nindex1() const
Return the range of index 1 of the tensor.
T * Tensordata
Private internal representation as pointer to data.
virtual ~RankFiveTensor()
Destructor: delete the pointers.
unsigned N
1st Tensor dimension
RankFiveTensor(const unsigned long &n_index1, const unsigned long &n_index2, const unsigned long &n_index3, const unsigned long &n_index4, const unsigned long &n_index5)
Four parameter constructor, general non-square tensor.
void resize(const unsigned long &n_index1, const unsigned long &n_index2, const unsigned long &n_index3, const unsigned long &n_index4, const unsigned long &n_index5)
Resize to a general tensor.
unsigned M
2nd Tensor dimension
unsigned N
1st Tensor dimension
RankFourTensor()
Empty constructor.
T & raw_direct_access(const unsigned long &i)
Direct access to internal storage of data in flat-packed C-style column-major format....
RankFourTensor(const unsigned long &n_index1, const unsigned long &n_index2, const unsigned long &n_index3, const unsigned long &n_index4)
Four parameter constructor, general non-square tensor.
void resize(const unsigned long &n_index1, const unsigned long &n_index2, const unsigned long &n_index3, const unsigned long &n_index4, const T &initial_value)
Resize to a general tensor.
virtual ~RankFourTensor()
Destructor: delete the pointers.
unsigned offset(const unsigned long &i, const unsigned long &j) const
Caculate the offset in flat-packed C-style, column-major format, required for a given i,...
T * Tensordata
Private internal representation as pointer to data.
void resize(const unsigned long &n_index1, const unsigned long &n_index2, const unsigned long &n_index3, const unsigned long &n_index4)
Resize to a general tensor.
unsigned long nindex4() const
Return the range of index 4 of the tensor.
RankFourTensor & operator=(const RankFourTensor &source_tensor)
Copy assignement.
void shallow_copy_from(const RankFourTensor &source_tensor)
Shallow copy of data from source_tensor.
unsigned long nindex2() const
Return the range of index 2 of the tensor.
const T & raw_direct_access(const unsigned long &i) const
Direct access to internal storage of data in flat-packed C-style column-major format....
unsigned long nindex1() const
Return the range of index 1 of the tensor.
bool Is_tensordata_a_copy
Boolean to indicate whether data is a copy.
T operator()(const unsigned long &i, const unsigned long &j, const unsigned long &k, const unsigned long &l) const
Overload a const version for read-only access as a(i,j,k,l)
unsigned long nindex3() const
Return the range of index 3 of the tensor.
RankFourTensor(const unsigned long &n)
One parameter constructor produces a nxnxnxn tensor.
RankFourTensor(const unsigned long &n_index1, const unsigned long &n_index2, const unsigned long &n_index3, const unsigned long &n_index4, const T &initial_val)
Four parameter constructor, general non-square tensor.
unsigned P
3rd Tensor dimension
void range_check(const unsigned long &i, const unsigned long &j, const unsigned long &k, const unsigned long &l) const
Range check to catch when an index is out of bounds, if so, it issues a warning message and dies by t...
T & operator()(const unsigned long &i, const unsigned long &j, const unsigned long &k, const unsigned long &l)
Overload the round brackets to give access as a(i,j,k,l)
RankFourTensor(const RankFourTensor &source_tensor)
Copy constructor: Deep copy.
unsigned Q
4th Tensor dimension
void initialise(const T &val)
Initialise all values in the tensor to val.
void resize(const unsigned long &n)
Resize to a square nxnxnxn tensor.
virtual ~RankThreeTensor()
Destructor: delete the pointers.
void resize(const unsigned long &n_index1, const unsigned long &n_index2, const unsigned long &n_index3, const T &initial_value)
Resize to a general tensor.
unsigned N
1st Tensor dimension
RankThreeTensor(const unsigned long &n_index1, const unsigned long &n_index2, const unsigned long &n_index3, const T &initial_val)
Three parameter constructor, general non-square tensor.
RankThreeTensor & operator=(const RankThreeTensor &source_tensor)
Copy assignement.
unsigned long nindex1() const
Return the range of index 1 of the tensor.
unsigned long nindex2() const
Return the range of index 2 of the tensor.
void range_check(const unsigned long &i, const unsigned long &j, const unsigned long &k) const
Range check to catch when an index is out of bounds, if so, it issues a warning message and dies by t...
RankThreeTensor(const RankThreeTensor &source_tensor)
Copy constructor: Deep copy.
RankThreeTensor()
Empty constructor.
unsigned M
2nd Tensor dimension
T & operator()(const unsigned long &i, const unsigned long &j, const unsigned long &k)
Overload the round brackets to give access as a(i,j,k)
T operator()(const unsigned long &i, const unsigned long &j, const unsigned long &k) const
Overload a const version for read-only access as a(i,j,k)
void resize(const unsigned long &n)
Resize to a square nxnxn tensor.
void resize(const unsigned long &n_index1, const unsigned long &n_index2, const unsigned long &n_index3)
Resize to a general tensor.
unsigned long nindex3() const
Return the range of index 3 of the tensor.
void initialise(const T &val)
Initialise all values in the tensor to val.
RankThreeTensor(const unsigned long &n_index1, const unsigned long &n_index2, const unsigned long &n_index3)
Three parameter constructor, general non-square tensor.
unsigned P
3rd Tensor dimension
T * Tensordata
Private internal representation as pointer to data.
RankThreeTensor(const unsigned long &n)
One parameter constructor produces a cubic nxnxn tensor.
Class for sparse matrices, that store only the non-zero values in a linear array in memory....
unsigned long Nnz
Number of non-zero values (i.e. size of Value array)
unsigned long nrow() const
Return the number of rows of the matrix.
virtual void output_bottom_right_zero_helper(std::ostream &outfile) const
Output the "bottom right" entry regardless of it being zero or not (this allows automatic detection o...
unsigned long ncol() const
Return the number of columns of the matrix.
T * Value
Internal representation of the matrix values, a pointer.
T * value()
Access to C-style value array.
virtual void sparse_indexed_output_helper(std::ostream &outfile) const
Indexed output function to print a matrix to the stream outfile as i,j,a(i,j) for a(i,...
void operator=(const SparseMatrix &)=delete
Broken assignment operator.
unsigned long nnz() const
Return the number of nonzero entries.
unsigned long N
Number of rows.
SparseMatrix()
Default constructor.
SparseMatrix(const SparseMatrix &source_matrix)
Copy constructor.
virtual ~SparseMatrix()
Destructor, delete the memory associated with the values.
unsigned long M
Number of columns.
const T * value() const
Access to C-style value array (const version)
SuperLU Project Solver class. This is a combined wrapper for both SuperLU and SuperLU Dist....
TAdvectionDiffusionReactionElement<NREAGENT,DIM,NNODE_1D> elements are isoparametric triangular DIM-d...
void output(std::ostream &outfile)
Output function: x,y,u or x,y,z,u.
TAdvectionDiffusionReactionElement()
Constructor: Call constructors for TElement and AdvectionDiffusionReaction equations.
double gershgorin_eigenvalue_estimate(const DenseMatrix< CRDoubleMatrix * > &matrix_pt)
Calculates the largest Gershgorin disc whilst preserving the sign. Let A be an n by n matrix,...
void deep_copy(const CRDoubleMatrix *const in_matrix_pt, CRDoubleMatrix &out_matrix)
Create a deep copy of the matrix pointed to by in_matrix_pt.
void concatenate_without_communication(const Vector< LinearAlgebraDistribution * > &row_distribution_pt, const Vector< LinearAlgebraDistribution * > &col_distribution_pt, const DenseMatrix< CRDoubleMatrix * > &matrix_pt, CRDoubleMatrix &result_matrix)
Concatenate CRDoubleMatrix matrices.
double inf_norm(const DenseMatrix< CRDoubleMatrix * > &matrix_pt)
Compute infinity (maximum) norm of sub blocks as if it was one matrix.
void concatenate(const DenseMatrix< CRDoubleMatrix * > &matrix_pt, CRDoubleMatrix &result_matrix)
Concatenate CRDoubleMatrix matrices. The in matrices are concatenated such that the block structure o...
void create_uniformly_distributed_matrix(const unsigned &nrow, const unsigned &ncol, const OomphCommunicator *const comm_pt, const Vector< double > &values, const Vector< int > &column_indices, const Vector< int > &row_start, CRDoubleMatrix &matrix_out)
Builds a uniformly distributed matrix. A locally replicated matrix is constructed then redistributed ...
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).
Create a struct to provide a comparison function for std::sort.
bool operator()(const std::pair< int, double > &pair_1, const std::pair< int, double > &pair_2)