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
73 template<
class T,
class MATRIX_TYPE>
83 std::ostringstream error_message;
84 error_message <<
"Range Error: i=" <<
i <<
" is not in the range (0,"
85 <<
nrow() - 1 <<
")." << std::endl;
93 std::ostringstream error_message;
94 error_message <<
"Range Error: j=" <<
j <<
" is not in the range (0,"
95 <<
ncol() - 1 <<
")." << std::endl;
118 virtual unsigned long nrow()
const = 0;
121 virtual unsigned long ncol()
const = 0;
129 inline T
operator()(
const unsigned long&
i,
const unsigned long&
j)
const
156 "Output function is not implemented for this matrix class",
170 std::ostream&
outfile)
const = 0;
176 std::ostream&
outfile,
const double&
cutoff = 0.0)
const = 0;
188 const double&
cutoff = 0.0)
const
234 const double&
cutoff = 0.0)
const
255 const double&
cutoff = 0.0)
const
267 const double&
cutoff = 0.0)
const
310 virtual unsigned long nrow()
const = 0;
313 virtual unsigned long ncol()
const = 0;
322 const unsigned long&
j)
const = 0;
364 unsigned nrow_local =
residual_.nrow_local();
366 for (
unsigned i = 0;
i < nrow_local;
i++)
440 for (
unsigned long i = 0;
i <
N;
i++)
442 for (
unsigned long j = 0;
j <
M;
j++)
458 if ((
N !=
n) || (
M !=
m))
463 for (
unsigned long i = 0;
i <
N;
i++)
465 for (
unsigned long j = 0;
j <
M;
j++)
477 inline T&
entry(
const unsigned long&
i,
const unsigned long&
j)
487 inline T
get_entry(
const unsigned long&
i,
const unsigned long&
j)
const
504 const unsigned long&
m,
515 inline unsigned long nrow()
const
521 inline unsigned long ncol()
const
535 void resize(
const unsigned long&
n,
const unsigned long&
m);
540 const unsigned long&
m,
546 for (
unsigned long i = 0;
i < (
N *
M); ++
i)
576 const double&
cutoff = 0.0)
const;
592 template<
class T,
class MATRIX_TYPE>
631 for (
unsigned long i = 0;
i <
Nnz;
i++)
660 inline unsigned long nrow()
const
666 inline unsigned long ncol()
const
672 inline unsigned long nnz()
const
682 std::string error_message =
"SparseMatrix::output_bottom_right_zero_"
683 "helper() is a virtual function.\n";
685 "It must be overloaded for specific sparse matrix storage formats\n";
695 const double&
cutoff = 0.0)
const
697 std::string error_message =
698 "SparseMatrix::sparse_indexed_output_helper() is a virtual function.\n";
700 "It must be overloaded for specific sparse matrix storage formats\n";
734 const unsigned long&
n,
735 const unsigned long&
m)
753 for (
unsigned long i = 0;
i < this->
Nnz;
i++)
762 for (
unsigned long i = 0;
i <= this->
N;
i++)
791 return this->
Value[k];
798 T&
entry(
const unsigned long&
i,
const unsigned long&
j)
801 "Non-const access not provided for the CRMatrix<T> class\n";
803 "It is not possible to use round-bracket access: M(i,j)\n";
805 error_string +=
"The solution (albeit ugly) is to create const reference "
864 const double&
cutoff = 0.0)
const
866 for (
unsigned long i = 0;
i < this->
N;
i++)
890 const unsigned long&
n,
891 const unsigned long&
m);
902 const unsigned long&
nnz,
903 const unsigned long&
n,
904 const unsigned long&
m);
935 const unsigned&
ncol,
966 "The Index_of_diagonal_entries vector has not been ";
967 err_strng +=
"set up yet. Run sort_entries() to set this vector up.";
971 "CRDoubleMatrix::get_index_of_diagonal_entries()",
984 const std::pair<int, double>&
pair_2)
1006 const unsigned&
ncol,
1024 const unsigned&
nnz,
1064 const double&
cutoff = 0.0)
const
1081 for (
unsigned long i = 0;
i <
n;
i++)
1086 <<
value()[
j] << std::endl;
1095 const unsigned long&
j)
const
1137 inline unsigned long nnz()
const
1326 const unsigned long&
m,
1350 const unsigned long&
j)
const
1428 const unsigned long&
j,
1429 const unsigned long&
k)
const
1433 std::ostringstream error_message;
1434 error_message <<
"Range Error: i=" <<
i <<
" is not in the range (0,"
1435 <<
N - 1 <<
")." << std::endl;
1443 std::ostringstream error_message;
1444 error_message <<
"Range Error: j=" <<
j <<
" is not in the range (0,"
1445 <<
M - 1 <<
")." << std::endl;
1453 std::ostringstream error_message;
1454 error_message <<
"Range Error: k=" <<
k <<
" is not in the range (0,"
1455 <<
P - 1 <<
")." << std::endl;
1478 for (
unsigned i = 0;
i <
N;
i++)
1480 for (
unsigned j = 0;
j <
M;
j++)
1482 for (
unsigned k = 0;
k <
P;
k++)
1501 if ((
N !=
n) || (
M !=
m) || (
P !=
p))
1507 for (
unsigned long i = 0;
i <
N;
i++)
1509 for (
unsigned long j = 0;
j <
M;
j++)
1511 for (
unsigned long k = 0;
k <
P;
k++)
1533#ifdef OOMPH_INITIALISE_DENSE_MATRICES
1550#ifdef OOMPH_INITIALISE_DENSE_MATRICES
1605#ifdef OOMPH_INITIALISE_DENSE_MATRICES
1615 for (
unsigned long i = 0;
i <
n_copy;
i++)
1618 for (
unsigned long j = 0;
j <
m_copy;
j++)
1621 for (
unsigned long k = 0;
k <
p_copy;
k++)
1664 for (
unsigned long i = 0;
i <
n_copy;
i++)
1667 for (
unsigned long j = 0;
j <
m_copy;
j++)
1670 for (
unsigned long k = 0;
k <
p_copy;
k++)
1685 for (
unsigned long i = 0;
i < (
N *
M *
P); ++
i)
1711 const unsigned long&
j,
1712 const unsigned long&
k)
1714#ifdef RANGE_CHECKING
1722 const unsigned long&
j,
1723 const unsigned long&
k)
const
1725#ifdef RANGE_CHECKING
1765 const unsigned long&
j,
1766 const unsigned long&
k,
1767 const unsigned long&
l)
const
1771 std::ostringstream error_message;
1772 error_message <<
"Range Error: i=" <<
i <<
" is not in the range (0,"
1773 <<
N - 1 <<
")." << std::endl;
1781 std::ostringstream error_message;
1782 error_message <<
"Range Error: j=" <<
j <<
" is not in the range (0,"
1783 <<
M - 1 <<
")." << std::endl;
1791 std::ostringstream error_message;
1792 error_message <<
"Range Error: k=" <<
k <<
" is not in the range (0,"
1793 <<
P - 1 <<
")." << std::endl;
1801 std::ostringstream error_message;
1802 error_message <<
"Range Error: l=" <<
l <<
" is not in the range (0,"
1803 <<
Q - 1 <<
")." << std::endl;
1832 for (
unsigned i = 0;
i <
N;
i++)
1834 for (
unsigned j = 0;
j <
M;
j++)
1836 for (
unsigned k = 0;
k <
P;
k++)
1838 for (
unsigned l = 0;
l <
Q;
l++)
1860 if ((
N !=
n) || (
M !=
m) || (
P !=
p) || (
Q != q))
1866 for (
unsigned long i = 0;
i <
N;
i++)
1868 for (
unsigned long j = 0;
j <
M;
j++)
1870 for (
unsigned long k = 0;
k <
P;
k++)
1872 for (
unsigned long l = 0;
l <
Q;
l++)
1915#ifdef OOMPH_INITIALISE_DENSE_MATRICES
1935#ifdef OOMPH_INITIALISE_DENSE_MATRICES
1999#ifdef OOMPH_INITIALISE_DENSE_MATRICES
2010 for (
unsigned long i = 0;
i <
n_copy;
i++)
2013 for (
unsigned long j = 0;
j <
m_copy;
j++)
2016 for (
unsigned long k = 0;
k <
p_copy;
k++)
2019 for (
unsigned long l = 0;
l <
q_copy;
l++)
2074 for (
unsigned long i = 0;
i <
n_copy;
i++)
2077 for (
unsigned long j = 0;
j <
m_copy;
j++)
2080 for (
unsigned long k = 0;
k <
p_copy;
k++)
2083 for (
unsigned long l = 0;
l <
q_copy;
l++)
2106 for (
unsigned long i = 0;
i < (
N *
M *
P *
Q); ++
i)
2138 const unsigned long&
j,
2139 const unsigned long&
k,
2140 const unsigned long&
l)
2142#ifdef RANGE_CHECKING
2151 const unsigned long&
j,
2152 const unsigned long&
k,
2153 const unsigned long&
l)
const
2155#ifdef RANGE_CHECKING
2183 unsigned offset(
const unsigned long&
i,
const unsigned long&
j)
const
2185 return (
Q * (
P * (
M *
i +
j) + 0) + 0);
2223 const unsigned long&
j,
2224 const unsigned long&
k,
2225 const unsigned long&
l,
2226 const unsigned long&
m)
const
2230 std::ostringstream error_message;
2231 error_message <<
"Range Error: i=" <<
i <<
" is not in the range (0,"
2232 <<
N - 1 <<
")." << std::endl;
2240 std::ostringstream error_message;
2241 error_message <<
"Range Error: j=" <<
j <<
" is not in the range (0,"
2242 <<
M - 1 <<
")." << std::endl;
2250 std::ostringstream error_message;
2251 error_message <<
"Range Error: k=" <<
k <<
" is not in the range (0,"
2252 <<
P - 1 <<
")." << std::endl;
2260 std::ostringstream error_message;
2261 error_message <<
"Range Error: l=" <<
l <<
" is not in the range (0,"
2262 <<
Q - 1 <<
")." << std::endl;
2270 std::ostringstream error_message;
2271 error_message <<
"Range Error: m=" <<
m <<
" is not in the range (0,"
2272 <<
R - 1 <<
")." << std::endl;
2298 for (
unsigned i = 0;
i <
N;
i++)
2300 for (
unsigned j = 0;
j <
M;
j++)
2302 for (
unsigned k = 0;
k <
P;
k++)
2304 for (
unsigned l = 0;
l <
Q;
l++)
2306 for (
unsigned m = 0;
m <
R;
m++)
2330 if ((
N !=
n) || (
M !=
m) || (
P !=
p) || (
Q != q) || (
R !=
r))
2336 for (
unsigned long i = 0;
i <
N;
i++)
2338 for (
unsigned long j = 0;
j <
M;
j++)
2340 for (
unsigned long k = 0;
k <
P;
k++)
2342 for (
unsigned long l = 0;
l <
Q;
l++)
2344 for (
unsigned long m = 0;
m <
R;
m++)
2370#ifdef OOMPH_INITIALISE_DENSE_MATRICES
2391#ifdef OOMPH_INITIALISE_DENSE_MATRICES
2455#ifdef OOMPH_INITIALISE_DENSE_MATRICES
2467 for (
unsigned long i = 0;
i <
n_copy;
i++)
2470 for (
unsigned long j = 0;
j <
m_copy;
j++)
2473 for (
unsigned long k = 0;
k <
p_copy;
k++)
2476 for (
unsigned long l = 0;
l <
q_copy;
l++)
2479 for (
unsigned long m = 0;
m <
r_copy;
m++)
2534 for (
unsigned long i = 0;
i <
n_copy;
i++)
2537 for (
unsigned long j = 0;
j <
m_copy;
j++)
2540 for (
unsigned long k = 0;
k <
p_copy;
k++)
2543 for (
unsigned long l = 0;
l <
q_copy;
l++)
2546 for (
unsigned long m = 0;
m <
r_copy;
m++)
2566 for (
unsigned long i = 0;
i < (
N *
M *
P *
Q *
R); ++
i)
2604 const unsigned long&
j,
2605 const unsigned long&
k,
2606 const unsigned long&
l,
2607 const unsigned long&
m)
2609#ifdef RANGE_CHECKING
2617 const unsigned long&
j,
2618 const unsigned long&
k,
2619 const unsigned long&
l,
2620 const unsigned long&
m)
const
2622#ifdef RANGE_CHECKING
2652 const unsigned long&
j,
2653 const unsigned long&
k)
const
2655 return (
R * (
Q * (
P * (
M *
i +
j) +
k) + 0) + 0);
2690 const unsigned long&
n,
2691 const unsigned long&
m)
2711 for (
unsigned long i = 0;
i < this->
Nnz;
i++)
2720 for (
unsigned long i = 0;
i <= this->
M;
i++)
2743#ifdef RANGE_CHECKING
2750 return this->
Value[k];
2758 T&
entry(
const unsigned long&
i,
const unsigned long&
j)
2761 "Non-const access not provided for the CCMatrix<T> class\n";
2763 "It is not possible to use round-bracket access: M(i,j)\n";
2765 error_string +=
"The solution (albeit ugly) is to create const reference "
2824 const double&
cutoff)
const
2826 for (
unsigned long j = 0;
j < this->
N;
j++)
2850 const unsigned long&
n,
2851 const unsigned long&
m);
2861 const unsigned long&
nnz,
2862 const unsigned long&
n,
2863 const unsigned long&
m);
2896 const unsigned long&
n,
2897 const unsigned long&
m);
2923 const unsigned long&
j)
const
3004 Matrixdata =
new T[
n *
n];
3006#ifdef OOMPH_INITIALISE_DENSE_MATRICES
3022 Matrixdata =
new T[
n *
m];
3023#ifdef OOMPH_INITIALISE_DENSE_MATRICES
3034 const unsigned long&
m,
3041 Matrixdata =
new T[
n *
m];
3054 if ((
n == N) && (
m == M))
3067 Matrixdata =
new T[
n *
m];
3069#ifdef OOMPH_INITIALISE_DENSE_MATRICES
3080 for (
unsigned long i = 0;
i <
n_copy;
i++)
3083 for (
unsigned long j = 0;
j <
m_copy;
j++)
3101 const unsigned long&
m,
3105 if ((
n == N) && (
m == M))
3117 Matrixdata =
new T[
n *
m];
3127 for (
unsigned long i = 0;
i <
n_copy;
i++)
3130 for (
unsigned long j = 0;
j <
m_copy;
j++)
3149 for (
unsigned i = 0;
i < N;
i++)
3152 for (
unsigned j = 0;
j < M;
j++)
3184 for (
unsigned i = 0;
i < N;
i++)
3187 for (
unsigned j = 0;
j < M;
j++)
3189 outfile <<
i <<
" " <<
j <<
" " << (*this)(
i,
j) << std::endl;
3237 const double&
cutoff)
const
3240 for (
unsigned i = 0;
i < N;
i++)
3243 for (
unsigned j = 0;
j < M;
j++)
3245 if ((*
this)(
i,
j) != T(0))
3252 if (std::abs((*
this)(
i,
j)) >
cutoff)
3254 outfile <<
i <<
" " <<
j <<
" " << (*this)(
i,
j) << std::endl;
3260 outfile <<
i <<
" " <<
j <<
" " << (*this)(
i,
j) << std::endl;
3280 if (this->Value != 0)
3282 delete[] this->Value;
3285 if (this->Row_index != 0)
3287 delete[] this->Row_index;
3288 this->Row_index = 0;
3290 if (this->Column_start != 0)
3292 delete[] this->Column_start;
3293 this->Column_start = 0;
3310 const unsigned long& nnz,
3311 const unsigned long&
n,
3312 const unsigned long&
m)
3324 if (this->Value != 0)
3326 delete[] this->Value;
3328 if (this->Row_index != 0)
3330 delete[] this->Row_index;
3332 if (this->Column_start != 0)
3334 delete[] this->Column_start;
3338 this->Value = value;
3341 this->Row_index = row_index;
3344 this->Column_start = column_start;
3358 const unsigned long&
n,
3359 const unsigned long&
m)
3364 std::ostringstream error_message;
3365 error_message <<
"length of value " << value.
size()
3367 <<
" should match " << std::endl;
3375 this->Nnz = value.
size();
3384 if (this->Value != 0)
3386 delete[] this->Value;
3388 if (this->Row_index != 0)
3390 delete[] this->Row_index;
3392 if (this->Column_start != 0)
3394 delete[] this->Column_start;
3398 this->Value =
new T[this->Nnz];
3401 this->Row_index =
new int[this->Nnz];
3404 for (
unsigned long i = 0;
i < this->Nnz;
i++)
3406 this->Value[
i] = value[
i];
3434 if (this->Value != 0)
3436 delete[] this->Value;
3439 if (this->Column_index != 0)
3441 delete[] this->Column_index;
3442 this->Column_index = 0;
3444 if (this->Row_start != 0)
3446 delete[] this->Row_start;
3447 this->Row_start = 0;
3465 const unsigned long& nnz,
3466 const unsigned long&
n,
3467 const unsigned long&
m)
3479 if (this->Value != 0)
3481 delete[] this->Value;
3483 if (this->Column_index != 0)
3485 delete[] this->Column_index;
3487 if (this->Row_start != 0)
3489 delete[] this->Row_start;
3493 this->Value = value;
3515 const unsigned long&
n,
3516 const unsigned long&
m)
3521 std::ostringstream error_message;
3522 error_message <<
"Must have the same number of values and column indices,"
3523 <<
"we have " << value.
size() <<
" values and "
3531 this->Nnz = value.
size();
3540 if (this->Value != 0)
3542 delete[] this->Value;
3544 if (this->Column_index != 0)
3546 delete[] this->Column_index;
3548 if (this->Row_start != 0)
3550 delete[] this->Row_start;
3554 this->Value =
new T[this->Nnz];
3557 this->Column_index =
new int[this->Nnz];
3560 for (
unsigned long i = 0;
i < this->Nnz;
i++)
3562 this->Value[
i] = value[
i];
3582 template<
class T,
class MATRIX_TYPE>
3588 extern std::string
RayStr;
3595 namespace CRDoubleMatrixHelpers
3606 err_msg <<
"The result matrix has been built.\n"
3607 <<
"Please clear the matrix.\n";
3616 err_msg <<
"The in_matrix_pt is null.\n";
3625 err_msg <<
"The in_matrix_pt is null.\n";
3633 out_matrix.serial_matrix_matrix_multiply_method() =
3636 out_matrix.distributed_matrix_matrix_multiply_method() =
3637 in_matrix_pt->distributed_matrix_matrix_multiply_method();
3684 const unsigned& nrow,
3685 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.
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.
void sparse_indexed_output_helper(std::ostream &outfile, const double &cutoff) const
Indexed output function to print a matrix to the stream outfile as i,j,a(i,j) for a(i,...
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.
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...
void sparse_indexed_output_helper(std::ostream &outfile, const double &cutoff=0.0) 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)
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.
void sparse_indexed_output_helper(std::ostream &outfile, const double &cutoff=0.0) const
Indexed output function to print a matrix to the stream outfile as i,j,a(i,j) for a(i,...
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...
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.
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 sparse_indexed_output_helper(std::ostream &outfile, const double &cutoff=0.0) const
Indexed output function to print a matrix to the stream outfile as i,j,a(i,j) for a(i,...
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...
void sparse_indexed_output_with_cutoff(std::ostream &outfile, const double &cutoff=0.0) const
Indexed output function to print a matrix to the stream outfile as i,j,a(i,j) for a(i,...
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...
void sparse_indexed_output_with_cutoff(std::string filename, const double &cutoff=0.0) const
Indexed output function to print a matrix to the stream outfile as i,j,a(i,j) for a(i,...
virtual ~Matrix()
Virtual (empty) destructor.
virtual void sparse_indexed_output_helper(std::ostream &outfile, const double &cutoff=0.0) const =0
Indexed output function to print a matrix to the stream outfile as i,j,a(i,j) for a(i,...
void sparse_indexed_output(std::ostream &outfile, const unsigned &precision=0, const bool &output_bottom_right_zero=false, const double &cutoff=0.0) const
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.
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.
void sparse_indexed_output(std::string filename, const unsigned &precision=0, const bool &output_bottom_right_zero=false, const double &cutoff=0.0) const
Indexed output function to print a matrix to the file named filename as i,j,a(i,j) for a(i,...
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.
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.
virtual void sparse_indexed_output_helper(std::ostream &outfile, const double &cutoff=0.0) const
Indexed output function to print a matrix to the stream outfile as i,j,a(i,j) for a(i,...
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)
Compile-time test to determine if a type T has a notion of "magnitude", i.e. if std::abs(T) is a vali...