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
1721 const unsigned long&
j,
1722 const unsigned long&
k,
1723 const unsigned long&
l)
const
1727 std::ostringstream error_message;
1728 error_message <<
"Range Error: i=" <<
i <<
" is not in the range (0,"
1729 <<
N - 1 <<
")." << std::endl;
1737 std::ostringstream error_message;
1738 error_message <<
"Range Error: j=" <<
j <<
" is not in the range (0,"
1739 <<
M - 1 <<
")." << std::endl;
1747 std::ostringstream error_message;
1748 error_message <<
"Range Error: k=" <<
k <<
" is not in the range (0,"
1749 <<
P - 1 <<
")." << std::endl;
1757 std::ostringstream error_message;
1758 error_message <<
"Range Error: l=" <<
l <<
" is not in the range (0,"
1759 <<
Q - 1 <<
")." << std::endl;
1784 for (
unsigned i = 0;
i <
N;
i++)
1786 for (
unsigned j = 0;
j <
M;
j++)
1788 for (
unsigned k = 0;
k <
P;
k++)
1790 for (
unsigned l = 0;
l <
Q;
l++)
1812 if ((
N !=
n) || (
M !=
m) || (
P !=
p) || (
Q != q))
1818 for (
unsigned long i = 0;
i <
N;
i++)
1820 for (
unsigned long j = 0;
j <
M;
j++)
1822 for (
unsigned long k = 0;
k <
P;
k++)
1824 for (
unsigned long l = 0;
l <
Q;
l++)
1848#ifdef OOMPH_INITIALISE_DENSE_MATRICES
1867#ifdef OOMPH_INITIALISE_DENSE_MATRICES
1927#ifdef OOMPH_INITIALISE_DENSE_MATRICES
1938 for (
unsigned long i = 0;
i <
n_copy;
i++)
1941 for (
unsigned long j = 0;
j <
m_copy;
j++)
1944 for (
unsigned long k = 0;
k <
p_copy;
k++)
1947 for (
unsigned long l = 0;
l <
q_copy;
l++)
1995 for (
unsigned long i = 0;
i <
n_copy;
i++)
1998 for (
unsigned long j = 0;
j <
m_copy;
j++)
2001 for (
unsigned long k = 0;
k <
p_copy;
k++)
2004 for (
unsigned long l = 0;
l <
q_copy;
l++)
2020 for (
unsigned long i = 0;
i < (
N *
M *
P *
Q); ++
i)
2052 const unsigned long&
j,
2053 const unsigned long&
k,
2054 const unsigned long&
l)
2056#ifdef RANGE_CHECKING
2064 const unsigned long&
j,
2065 const unsigned long&
k,
2066 const unsigned long&
l)
const
2068#ifdef RANGE_CHECKING
2096 unsigned offset(
const unsigned long&
i,
const unsigned long&
j)
const
2098 return (
Q * (
P * (
M *
i +
j) + 0) + 0);
2136 const unsigned long&
j,
2137 const unsigned long&
k,
2138 const unsigned long&
l,
2139 const unsigned long&
m)
const
2143 std::ostringstream error_message;
2144 error_message <<
"Range Error: i=" <<
i <<
" is not in the range (0,"
2145 <<
N - 1 <<
")." << std::endl;
2153 std::ostringstream error_message;
2154 error_message <<
"Range Error: j=" <<
j <<
" is not in the range (0,"
2155 <<
M - 1 <<
")." << std::endl;
2163 std::ostringstream error_message;
2164 error_message <<
"Range Error: k=" <<
k <<
" is not in the range (0,"
2165 <<
P - 1 <<
")." << std::endl;
2173 std::ostringstream error_message;
2174 error_message <<
"Range Error: l=" <<
l <<
" is not in the range (0,"
2175 <<
Q - 1 <<
")." << std::endl;
2183 std::ostringstream error_message;
2184 error_message <<
"Range Error: m=" <<
m <<
" is not in the range (0,"
2185 <<
R - 1 <<
")." << std::endl;
2211 for (
unsigned i = 0;
i <
N;
i++)
2213 for (
unsigned j = 0;
j <
M;
j++)
2215 for (
unsigned k = 0;
k <
P;
k++)
2217 for (
unsigned l = 0;
l <
Q;
l++)
2219 for (
unsigned m = 0;
m <
R;
m++)
2243 if ((
N !=
n) || (
M !=
m) || (
P !=
p) || (
Q != q) || (
R !=
r))
2249 for (
unsigned long i = 0;
i <
N;
i++)
2251 for (
unsigned long j = 0;
j <
M;
j++)
2253 for (
unsigned long k = 0;
k <
P;
k++)
2255 for (
unsigned long l = 0;
l <
Q;
l++)
2257 for (
unsigned long m = 0;
m <
R;
m++)
2283#ifdef OOMPH_INITIALISE_DENSE_MATRICES
2304#ifdef OOMPH_INITIALISE_DENSE_MATRICES
2368#ifdef OOMPH_INITIALISE_DENSE_MATRICES
2380 for (
unsigned long i = 0;
i <
n_copy;
i++)
2383 for (
unsigned long j = 0;
j <
m_copy;
j++)
2386 for (
unsigned long k = 0;
k <
p_copy;
k++)
2389 for (
unsigned long l = 0;
l <
q_copy;
l++)
2392 for (
unsigned long m = 0;
m <
r_copy;
m++)
2447 for (
unsigned long i = 0;
i <
n_copy;
i++)
2450 for (
unsigned long j = 0;
j <
m_copy;
j++)
2453 for (
unsigned long k = 0;
k <
p_copy;
k++)
2456 for (
unsigned long l = 0;
l <
q_copy;
l++)
2459 for (
unsigned long m = 0;
m <
r_copy;
m++)
2479 for (
unsigned long i = 0;
i < (
N *
M *
P *
Q *
R); ++
i)
2517 const unsigned long&
j,
2518 const unsigned long&
k,
2519 const unsigned long&
l,
2520 const unsigned long&
m)
2522#ifdef RANGE_CHECKING
2530 const unsigned long&
j,
2531 const unsigned long&
k,
2532 const unsigned long&
l,
2533 const unsigned long&
m)
const
2535#ifdef RANGE_CHECKING
2565 const unsigned long&
j,
2566 const unsigned long&
k)
const
2568 return (
R * (
Q * (
P * (
M *
i +
j) +
k) + 0) + 0);
2603 const unsigned long&
n,
2604 const unsigned long&
m)
2624 for (
unsigned long i = 0;
i < this->
Nnz;
i++)
2633 for (
unsigned long i = 0;
i <= this->
M;
i++)
2656#ifdef RANGE_CHECKING
2663 return this->
Value[k];
2671 T&
entry(
const unsigned long&
i,
const unsigned long&
j)
2674 "Non-const access not provided for the CCMatrix<T> class\n";
2676 "It is not possible to use round-bracket access: M(i,j)\n";
2678 error_string +=
"The solution (albeit ugly) is to create const reference "
2737 for (
unsigned long j = 0;
j < this->
N;
j++)
2758 const unsigned long&
n,
2759 const unsigned long&
m);
2769 const unsigned long&
nnz,
2770 const unsigned long&
n,
2771 const unsigned long&
m);
2804 const unsigned long&
n,
2805 const unsigned long&
m);
2831 const unsigned long&
j)
const
2912 Matrixdata =
new T[
n *
n];
2914#ifdef OOMPH_INITIALISE_DENSE_MATRICES
2930 Matrixdata =
new T[
n *
m];
2931#ifdef OOMPH_INITIALISE_DENSE_MATRICES
2942 const unsigned long&
m,
2949 Matrixdata =
new T[
n *
m];
2962 if ((
n == N) && (
m == M))
2975 Matrixdata =
new T[
n *
m];
2977#ifdef OOMPH_INITIALISE_DENSE_MATRICES
2988 for (
unsigned long i = 0;
i <
n_copy;
i++)
2991 for (
unsigned long j = 0;
j <
m_copy;
j++)
3009 const unsigned long&
m,
3013 if ((
n == N) && (
m == M))
3025 Matrixdata =
new T[
n *
m];
3035 for (
unsigned long i = 0;
i <
n_copy;
i++)
3038 for (
unsigned long j = 0;
j <
m_copy;
j++)
3057 for (
unsigned i = 0;
i < N;
i++)
3060 for (
unsigned j = 0;
j < M;
j++)
3092 for (
unsigned i = 0;
i < N;
i++)
3095 for (
unsigned j = 0;
j < M;
j++)
3097 outfile <<
i <<
" " <<
j <<
" " << (*this)(
i,
j) << std::endl;
3146 for (
unsigned i = 0;
i < N;
i++)
3149 for (
unsigned j = 0;
j < M;
j++)
3151 if ((*
this)(
i,
j) != T(0))
3153 outfile <<
i <<
" " <<
j <<
" " << (*this)(
i,
j) << std::endl;
3172 if (this->Value != 0)
3174 delete[] this->Value;
3177 if (this->Row_index != 0)
3179 delete[] this->Row_index;
3180 this->Row_index = 0;
3182 if (this->Column_start != 0)
3184 delete[] this->Column_start;
3185 this->Column_start = 0;
3202 const unsigned long& nnz,
3203 const unsigned long&
n,
3204 const unsigned long&
m)
3216 if (this->Value != 0)
3218 delete[] this->Value;
3220 if (this->Row_index != 0)
3222 delete[] this->Row_index;
3224 if (this->Column_start != 0)
3226 delete[] this->Column_start;
3230 this->Value = value;
3233 this->Row_index = row_index;
3236 this->Column_start = column_start;
3250 const unsigned long&
n,
3251 const unsigned long&
m)
3256 std::ostringstream error_message;
3257 error_message <<
"length of value " << value.
size()
3259 <<
" should match " << std::endl;
3267 this->Nnz = value.
size();
3276 if (this->Value != 0)
3278 delete[] this->Value;
3280 if (this->Row_index != 0)
3282 delete[] this->Row_index;
3284 if (this->Column_start != 0)
3286 delete[] this->Column_start;
3290 this->Value =
new T[this->Nnz];
3293 this->Row_index =
new int[this->Nnz];
3296 for (
unsigned long i = 0;
i < this->Nnz;
i++)
3298 this->Value[
i] = value[
i];
3326 if (this->Value != 0)
3328 delete[] this->Value;
3331 if (this->Column_index != 0)
3333 delete[] this->Column_index;
3334 this->Column_index = 0;
3336 if (this->Row_start != 0)
3338 delete[] this->Row_start;
3339 this->Row_start = 0;
3357 const unsigned long& nnz,
3358 const unsigned long&
n,
3359 const unsigned long&
m)
3371 if (this->Value != 0)
3373 delete[] this->Value;
3375 if (this->Column_index != 0)
3377 delete[] this->Column_index;
3379 if (this->Row_start != 0)
3381 delete[] this->Row_start;
3385 this->Value = value;
3407 const unsigned long&
n,
3408 const unsigned long&
m)
3413 std::ostringstream error_message;
3414 error_message <<
"Must have the same number of values and column indices,"
3415 <<
"we have " << value.
size() <<
" values and "
3423 this->Nnz = value.
size();
3432 if (this->Value != 0)
3434 delete[] this->Value;
3436 if (this->Column_index != 0)
3438 delete[] this->Column_index;
3440 if (this->Row_start != 0)
3442 delete[] this->Row_start;
3446 this->Value =
new T[this->Nnz];
3449 this->Column_index =
new int[this->Nnz];
3452 for (
unsigned long i = 0;
i < this->Nnz;
i++)
3454 this->Value[
i] = value[
i];
3474 template<
class T,
class MATRIX_TYPE>
3480 extern std::string
RayStr;
3487 namespace CRDoubleMatrixHelpers
3498 err_msg <<
"The result matrix has been built.\n"
3499 <<
"Please clear the matrix.\n";
3508 err_msg <<
"The in_matrix_pt is null.\n";
3517 err_msg <<
"The in_matrix_pt is null.\n";
3525 out_matrix.serial_matrix_matrix_multiply_method() =
3528 out_matrix.distributed_matrix_matrix_multiply_method() =
3529 in_matrix_pt->distributed_matrix_matrix_multiply_method();
3576 const unsigned& nrow,
3577 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.
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.
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)