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>
78 void range_check(
const unsigned long&
i,
const unsigned long& j)
const
82 std::ostringstream error_message;
83 error_message <<
"Range Error: i=" <<
i <<
" is not in the range (0,"
84 <<
nrow() - 1 <<
")." << std::endl;
87 OOMPH_CURRENT_FUNCTION,
88 OOMPH_EXCEPTION_LOCATION);
92 std::ostringstream error_message;
93 error_message <<
"Range Error: j=" << j <<
" is not in the range (0,"
94 <<
ncol() - 1 <<
")." << std::endl;
97 OOMPH_CURRENT_FUNCTION,
98 OOMPH_EXCEPTION_LOCATION);
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
130 return static_cast<MATRIX_TYPE const*
>(
this)->get_entry(
i, j);
142 return static_cast<MATRIX_TYPE*
>(
this)->entry(
i, j);
152 virtual void output(std::ostream& outfile)
const
155 "Output function is not implemented for this matrix class",
156 OOMPH_CURRENT_FUNCTION,
157 OOMPH_EXCEPTION_LOCATION);
169 std::ostream& outfile)
const = 0;
183 std::ostream& outfile,
184 const unsigned& precision = 0,
185 const bool& output_bottom_right_zero =
false)
const
195 unsigned old_precision = 0;
198 old_precision = outfile.precision();
199 outfile.precision(precision);
207 if (output_bottom_right_zero &&
ncol() > 0 &&
nrow() > 0)
217 outfile.precision(old_precision);
228 const unsigned& precision = 0,
229 const bool& output_bottom_right_zero =
false)
const
236 std::ofstream some_file(filename.c_str());
280 virtual unsigned long nrow()
const = 0;
283 virtual unsigned long ncol()
const = 0;
292 const unsigned long& j)
const = 0;
335 double* residual_pt = residual_.
values_pt();
336 for (
unsigned i = 0;
i < nrow_local;
i++)
338 residual_pt[
i] = -residual_pt[
i];
405 N = source_matrix.
nrow();
406 M = source_matrix.
ncol();
410 for (
unsigned long i = 0;
i <
N;
i++)
412 for (
unsigned long j = 0; j <
M; j++)
423 if (
this != &source_matrix)
426 unsigned long n = source_matrix.
nrow();
427 unsigned long m = source_matrix.
ncol();
428 if ((
N != n) || (
M != m))
433 for (
unsigned long i = 0;
i <
N;
i++)
435 for (
unsigned long j = 0; j <
M; j++)
437 (*this)(
i, j) = source_matrix(
i, j);
447 inline T&
entry(
const unsigned long&
i,
const unsigned long& j)
449 #ifdef RANGE_CHECKING
457 inline T get_entry(
const unsigned long&
i,
const unsigned long& j)
const
459 #ifdef RANGE_CHECKING
474 const unsigned long& m,
475 const T& initial_val);
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,
511 const T& initial_value);
516 for (
unsigned long i = 0;
i < (
N *
M); ++
i)
523 void output(std::ostream& outfile)
const;
560 template<
class T,
class MATRIX_TYPE>
587 Nnz = source_matrix.
nnz();
590 N = source_matrix.
nrow();
593 M = source_matrix.
ncol();
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";
656 error_message, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
664 "SparseMatrix::sparse_indexed_output_helper() is a virtual function.\n";
666 "It must be overloaded for specific sparse matrix storage formats\n";
669 error_message, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
700 const unsigned long& n,
701 const unsigned long& m)
706 build(
value, column_index_, row_start_, n, m);
719 for (
unsigned long i = 0;
i < this->
Nnz;
i++)
728 for (
unsigned long i = 0;
i <= this->
N;
i++)
750 #ifdef RANGE_CHECKING
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";
770 error_string +=
"if M is not declared as const.\n";
771 error_string +=
"The solution (albeit ugly) is to create const reference "
773 error_string +=
" const CRMatrix<T>& read_M = M;\n";
774 error_string +=
"Then read_M(i,j) is permitted\n";
777 error_string, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
813 int last_row_local = this->
N - 1;
814 int last_col = this->
M - 1;
817 T last_value = this->
operator()(last_row_local, last_col);
819 if (last_value ==
T(0))
821 outfile << last_row_local <<
" " << last_col <<
" " <<
T(0)
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()",
933 OOMPH_EXCEPTION_LOCATION);
945 const std::pair<int, double>& pair_2)
949 return (pair_1.first < pair_2.first);
967 const unsigned&
ncol,
1037 std::ofstream some_file;
1038 some_file.open(filename.c_str());
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,
1286 const double& initial_val);
1309 const unsigned long& j)
const
1316 inline double&
operator()(
const unsigned long&
i,
const unsigned long& j)
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;
1397 OOMPH_CURRENT_FUNCTION,
1398 OOMPH_EXCEPTION_LOCATION);
1402 std::ostringstream error_message;
1403 error_message <<
"Range Error: j=" << j <<
" is not in the range (0,"
1404 <<
M - 1 <<
")." << std::endl;
1407 OOMPH_CURRENT_FUNCTION,
1408 OOMPH_EXCEPTION_LOCATION);
1412 std::ostringstream error_message;
1413 error_message <<
"Range Error: k=" << k <<
" is not in the range (0,"
1414 <<
P - 1 <<
")." << std::endl;
1417 OOMPH_CURRENT_FUNCTION,
1418 OOMPH_EXCEPTION_LOCATION);
1437 for (
unsigned i = 0;
i <
N;
i++)
1439 for (
unsigned j = 0; j <
M; j++)
1441 for (
unsigned k = 0; k <
P; k++)
1453 if (
this != &source_tensor)
1456 unsigned long n = source_tensor.
nindex1();
1457 unsigned long m = source_tensor.
nindex2();
1458 unsigned long p = source_tensor.
nindex3();
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++)
1472 (*this)(
i, j, k) = source_tensor(
i, j, k);
1492 #ifdef OOMPH_INITIALISE_DENSE_MATRICES
1499 const unsigned long& n_index2,
1500 const unsigned long& n_index3)
1509 #ifdef OOMPH_INITIALISE_DENSE_MATRICES
1517 const unsigned long& n_index2,
1518 const unsigned long& n_index3,
1519 const T& initial_val)
1546 const unsigned long& n_index2,
1547 const unsigned long& n_index3)
1550 if ((n_index1 ==
N) && (n_index2 ==
M) && (n_index3 ==
P))
1555 unsigned long n_old =
N, m_old =
M, p_old =
P;
1564 #ifdef OOMPH_INITIALISE_DENSE_MATRICES
1568 unsigned long n_copy, m_copy, p_copy;
1569 n_copy = std::min(n_old, n_index1);
1570 m_copy = std::min(m_old, n_index2);
1571 p_copy = std::min(p_old, n_index3);
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++)
1584 temp_tensor[m_old * p_old *
i + p_old * j + k];
1589 delete[] temp_tensor;
1594 const unsigned long& n_index2,
1595 const unsigned long& n_index3,
1596 const T& initial_value)
1599 if ((n_index1 ==
N) && (n_index2 ==
M) && (n_index3 ==
P))
1604 unsigned long n_old =
N, m_old =
M, p_old =
P;
1617 unsigned long n_copy, m_copy, p_copy;
1618 n_copy = std::min(n_old, n_index1);
1619 m_copy = std::min(m_old, n_index2);
1620 p_copy = std::min(p_old, n_index3);
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++)
1633 temp_tensor[m_old * p_old *
i + p_old * j + k];
1638 delete[] temp_tensor;
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;
1732 OOMPH_CURRENT_FUNCTION,
1733 OOMPH_EXCEPTION_LOCATION);
1737 std::ostringstream error_message;
1738 error_message <<
"Range Error: j=" << j <<
" is not in the range (0,"
1739 <<
M - 1 <<
")." << std::endl;
1742 OOMPH_CURRENT_FUNCTION,
1743 OOMPH_EXCEPTION_LOCATION);
1747 std::ostringstream error_message;
1748 error_message <<
"Range Error: k=" << k <<
" is not in the range (0,"
1749 <<
P - 1 <<
")." << std::endl;
1752 OOMPH_CURRENT_FUNCTION,
1753 OOMPH_EXCEPTION_LOCATION);
1757 std::ostringstream error_message;
1758 error_message <<
"Range Error: l=" << l <<
" is not in the range (0,"
1759 <<
Q - 1 <<
")." << std::endl;
1762 OOMPH_CURRENT_FUNCTION,
1763 OOMPH_EXCEPTION_LOCATION);
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++)
1793 source_tensor(
i, j, k, l);
1804 if (
this != &source_tensor)
1807 unsigned long n = source_tensor.
nindex1();
1808 unsigned long m = source_tensor.
nindex2();
1809 unsigned long p = source_tensor.
nindex3();
1810 unsigned long q = source_tensor.
nindex4();
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++)
1826 (*this)(
i, j, k, l) = source_tensor(
i, j, k, l);
1848 #ifdef OOMPH_INITIALISE_DENSE_MATRICES
1855 const unsigned long& n_index2,
1856 const unsigned long& n_index3,
1857 const unsigned long& n_index4)
1867 #ifdef OOMPH_INITIALISE_DENSE_MATRICES
1875 const unsigned long& n_index2,
1876 const unsigned long& n_index3,
1877 const unsigned long& n_index4,
1878 const T& initial_val)
1906 const unsigned long& n_index2,
1907 const unsigned long& n_index3,
1908 const unsigned long& n_index4)
1911 if ((n_index1 ==
N) && (n_index2 ==
M) && (n_index3 ==
P) &&
1917 unsigned long n_old =
N, m_old =
M, p_old =
P, q_old =
Q;
1927 #ifdef OOMPH_INITIALISE_DENSE_MATRICES
1931 unsigned long n_copy, m_copy, p_copy, q_copy;
1932 n_copy = std::min(n_old, n_index1);
1933 m_copy = std::min(m_old, n_index2);
1934 p_copy = std::min(p_old, n_index3);
1935 q_copy = std::min(q_old, n_index4);
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++)
1951 temp_tensor[q_old * (m_old * p_old *
i + p_old * j + k) + l];
1957 delete[] temp_tensor;
1962 const unsigned long& n_index2,
1963 const unsigned long& n_index3,
1964 const unsigned long& n_index4,
1965 const T& initial_value)
1968 if ((n_index1 ==
N) && (n_index2 ==
M) && (n_index3 ==
P) &&
1974 unsigned long n_old =
N, m_old =
M, p_old =
P, q_old =
Q;
1988 unsigned long n_copy, m_copy, p_copy, q_copy;
1989 n_copy = std::min(n_old, n_index1);
1990 m_copy = std::min(m_old, n_index2);
1991 p_copy = std::min(p_old, n_index3);
1992 q_copy = std::min(q_old, n_index4);
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++)
2008 temp_tensor[q_old * (m_old * p_old *
i + p_old * j + k) + l];
2014 delete[] temp_tensor;
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;
2148 OOMPH_CURRENT_FUNCTION,
2149 OOMPH_EXCEPTION_LOCATION);
2153 std::ostringstream error_message;
2154 error_message <<
"Range Error: j=" << j <<
" is not in the range (0,"
2155 <<
M - 1 <<
")." << std::endl;
2158 OOMPH_CURRENT_FUNCTION,
2159 OOMPH_EXCEPTION_LOCATION);
2163 std::ostringstream error_message;
2164 error_message <<
"Range Error: k=" << k <<
" is not in the range (0,"
2165 <<
P - 1 <<
")." << std::endl;
2168 OOMPH_CURRENT_FUNCTION,
2169 OOMPH_EXCEPTION_LOCATION);
2173 std::ostringstream error_message;
2174 error_message <<
"Range Error: l=" << l <<
" is not in the range (0,"
2175 <<
Q - 1 <<
")." << std::endl;
2178 OOMPH_CURRENT_FUNCTION,
2179 OOMPH_EXCEPTION_LOCATION);
2183 std::ostringstream error_message;
2184 error_message <<
"Range Error: m=" << m <<
" is not in the range (0,"
2185 <<
R - 1 <<
")." << std::endl;
2188 OOMPH_CURRENT_FUNCTION,
2189 OOMPH_EXCEPTION_LOCATION);
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++)
2222 source_tensor(
i, j, k, l, m);
2234 if (
this != &source_tensor)
2237 unsigned long n = source_tensor.
nindex1();
2238 unsigned long m = source_tensor.
nindex2();
2239 unsigned long p = source_tensor.
nindex3();
2240 unsigned long q = source_tensor.
nindex4();
2241 unsigned long r = source_tensor.
nindex5();
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++)
2259 (*this)(
i, j, k, l, m) = source_tensor(
i, j, k, l, m);
2283 #ifdef OOMPH_INITIALISE_DENSE_MATRICES
2290 const unsigned long& n_index2,
2291 const unsigned long& n_index3,
2292 const unsigned long& n_index4,
2293 const unsigned long& n_index5)
2304 #ifdef OOMPH_INITIALISE_DENSE_MATRICES
2312 const unsigned long& n_index2,
2313 const unsigned long& n_index3,
2314 const unsigned long& n_index4,
2315 const unsigned long& n_index5,
2316 const T& initial_val)
2345 const unsigned long& n_index2,
2346 const unsigned long& n_index3,
2347 const unsigned long& n_index4,
2348 const unsigned long& n_index5)
2351 if ((n_index1 ==
N) && (n_index2 ==
M) && (n_index3 ==
P) &&
2352 (n_index4 ==
Q) && (n_index5 ==
R))
2357 unsigned long n_old =
N, m_old =
M, p_old =
P, q_old =
Q, r_old =
R;
2368 #ifdef OOMPH_INITIALISE_DENSE_MATRICES
2372 unsigned long n_copy, m_copy, p_copy, q_copy, r_copy;
2373 n_copy = std::min(n_old, n_index1);
2374 m_copy = std::min(m_old, n_index2);
2375 p_copy = std::min(p_old, n_index3);
2376 q_copy = std::min(q_old, n_index4);
2377 r_copy = std::min(r_old, n_index5);
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++)
2397 (q_old * (m_old * p_old *
i + p_old * j + k) +
2406 delete[] temp_tensor;
2411 const unsigned long& n_index2,
2412 const unsigned long& n_index3,
2413 const unsigned long& n_index4,
2414 const unsigned long& n_index5,
2415 const T& initial_value)
2418 if ((n_index1 ==
N) && (n_index2 ==
M) && (n_index3 ==
P) &&
2419 (n_index4 ==
Q) && (n_index5 ==
R))
2424 unsigned long n_old =
N, m_old =
M, p_old =
P, q_old =
Q, r_old =
R;
2439 unsigned long n_copy, m_copy, p_copy, q_copy, r_copy;
2440 n_copy = std::min(n_old, n_index1);
2441 m_copy = std::min(m_old, n_index2);
2442 p_copy = std::min(p_old, n_index3);
2443 q_copy = std::min(q_old, n_index4);
2444 r_copy = std::min(r_old, n_index5);
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++)
2464 (q_old * (m_old * p_old *
i + p_old * j + k) +
2473 delete[] temp_tensor;
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)
2609 build(
value, row_index_, column_start_, n, 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";
2677 error_string +=
"if M is not declared as const.\n";
2678 error_string +=
"The solution (albeit ugly) is to create const reference "
2680 error_string +=
" const CCMatrix<T>& read_M = M;\n";
2681 error_string +=
"Then read_M(i,j) is permitted\n";
2684 error_string, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
2720 int last_row = this->
N - 1;
2721 int last_col_local = this->
M - 1;
2724 T last_value = this->
operator()(last_row, last_col_local);
2726 if (last_value ==
T(0))
2728 outfile << last_row <<
" " << last_col_local <<
" " <<
T(0)
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,
2943 const T& initial_val)
2949 Matrixdata =
new T[n * m];
2950 initialise(initial_val);
2962 if ((n ==
N) && (m == M))
2967 unsigned long n_old =
N, m_old = M;
2972 T* temp_matrix = Matrixdata;
2975 Matrixdata =
new T[n * m];
2977 #ifdef OOMPH_INITIALISE_DENSE_MATRICES
2982 unsigned long n_copy, m_copy;
2983 n_copy = std::min(n_old, n);
2984 m_copy = std::min(m_old, m);
2988 for (
unsigned long i = 0;
i < n_copy;
i++)
2991 for (
unsigned long j = 0; j < m_copy; j++)
2994 Matrixdata[m *
i + j] = temp_matrix[m_old *
i + j];
2999 delete[] temp_matrix;
3009 const unsigned long& m,
3010 const T& initial_value)
3013 if ((n ==
N) && (m == M))
3018 unsigned long n_old =
N, m_old = M;
3023 T* temp_matrix = Matrixdata;
3025 Matrixdata =
new T[n * m];
3027 initialise(initial_value);
3030 unsigned long n_copy, m_copy;
3031 n_copy = std::min(n_old, n);
3032 m_copy = std::min(m_old, m);
3035 for (
unsigned long i = 0;
i < n_copy;
i++)
3038 for (
unsigned long j = 0; j < m_copy; j++)
3041 Matrixdata[m *
i + j] = temp_matrix[m_old *
i + j];
3046 delete[] temp_matrix;
3057 for (
unsigned i = 0;
i <
N;
i++)
3060 for (
unsigned j = 0; j < M; j++)
3062 outfile << (*this)(
i, j) <<
" ";
3065 outfile << std::endl;
3077 std::ofstream some_file;
3078 some_file.open(filename.c_str());
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;
3111 std::ofstream some_file;
3112 some_file.open(filename.c_str());
3113 indexed_output(some_file);
3125 std::ostream& outfile)
const
3127 int last_row = this->
N - 1;
3128 int last_col = this->M - 1;
3131 T last_value = this->operator()(last_row, last_col);
3133 if (last_value ==
T(0))
3135 outfile << last_row <<
" " << last_col <<
" " <<
T(0) << 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)
3254 if (value.size() != row_index_.size())
3256 std::ostringstream error_message;
3257 error_message <<
"length of value " << value.size()
3258 <<
" and row_index vectors " << row_index_.size()
3259 <<
" should match " << std::endl;
3262 error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
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];
3299 this->Row_index[
i] = row_index_[
i];
3304 unsigned long n_column_start = column_start_.size();
3305 this->Column_start =
new int[n_column_start];
3308 for (
unsigned long i = 0;
i < n_column_start;
i++)
3310 this->Column_start[
i] = column_start_[
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;
3388 this->Column_index = column_index_;
3391 this->Row_start = row_start_;
3407 const unsigned long& n,
3408 const unsigned long& m)
3411 if (value.size() != column_index_.size())
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 "
3416 << column_index_.size() <<
" column inidicies."
3419 error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
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];
3455 this->Column_index[
i] = column_index_[
i];
3460 unsigned long n_row_start = row_start_.size();
3461 this->Row_start =
new int[n_row_start];
3464 for (
unsigned long i = 0;
i < n_row_start;
i++)
3466 this->Row_start[
i] = row_start_[
i];
3474 template<
class T,
class MATRIX_TYPE>
3487 namespace CRDoubleMatrixHelpers
3495 if (out_matrix.
built())
3497 std::ostringstream err_msg;
3498 err_msg <<
"The result matrix has been built.\n"
3499 <<
"Please clear the matrix.\n";
3501 err_msg.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
3505 if (in_matrix_pt == 0)
3507 std::ostringstream err_msg;
3508 err_msg <<
"The in_matrix_pt is null.\n";
3510 err_msg.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
3514 if (!in_matrix_pt->
built())
3516 std::ostringstream err_msg;
3517 err_msg <<
"The in_matrix_pt is null.\n";
3519 err_msg.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
3533 const unsigned in_nrow_local = in_matrix_pt->
nrow_local();
3534 const unsigned long in_nnz = in_matrix_pt->
nnz();
3537 double* out_values =
new double[in_nnz];
3538 int* out_column_indices =
new int[in_nnz];
3539 int* out_row_start =
new int[in_nrow_local + 1];
3542 const double*
const in_values = in_matrix_pt->
value();
3543 const int*
const in_column_indices = in_matrix_pt->
column_index();
3544 const int*
const in_row_start = in_matrix_pt->
row_start();
3547 std::copy(in_values, in_values + in_nnz, out_values);
3550 in_column_indices, in_column_indices + in_nnz, out_column_indices);
3553 in_row_start, in_row_start + (in_nrow_local + 1), out_row_start);
3576 const unsigned& nrow,
3577 const unsigned& ncol,
//////////////////////////////////////////////////////////////// ////////////////////////////////////...
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...
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.
unsigned & matrix_matrix_multiply_method()
Access function to Matrix_matrix_multiply_method, the flag which determines the matrix matrix multipl...
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.
/////////////////////////////////////////////////////////////// /////////////////////////////////////...
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,...
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 & entry(const unsigned long &i, const unsigned long &j)
Read-write access is not permitted for these matrices and is deliberately broken.
int * column_start()
Access to C-style column_start array.
const int * column_start() const
Access to C-style column_start 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)
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.
const int * row_index() const
Access to C-style row index array (const version)
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...
int * row_index()
Access to C-style row index array.
void clean_up_memory()
Wipe matrix data and set all values to 0.
A class for compressed row matrices. This is a distributable object.
void sort_entries()
Sorts the entries associated with each row of the matrix in the column index vector and the value vec...
int * column_index()
Access to C-style column index array.
int * row_start()
Access to C-style row_start array.
virtual ~CRDoubleMatrix()
Destructor.
const double * value() const
Access to C-style value array (const version)
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....
unsigned & distributed_matrix_matrix_multiply_method()
Access function to Distributed_matrix_matrix_multiply_method, the flag which determines the matrix ma...
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,...
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.
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.
const unsigned & distributed_matrix_matrix_multiply_method() const
Read only access function (const version) to Distributed_matrix_matrix_multiply_method,...
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
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 get_matrix_transpose(CRDoubleMatrix *result) const
Returns the transpose of this matrix.
const int * column_index() const
Access to C-style column index array (const version)
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...
const int * row_start() const
Access to C-style row_start array (const version)
bool built() const
access function to the Built flag - indicates whether the matrix has been build - i....
unsigned & serial_matrix_matrix_multiply_method()
Access function to Serial_matrix_matrix_multiply_method, the flag which determines the matrix matrix ...
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
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...
double * value()
Access to C-style value array.
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 unsigned & serial_matrix_matrix_multiply_method() const
Read only access function (const version) to Serial_matrix_matrix_multiply_method,...
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.
const int * column_index() const
Access to C-style column index array (const version)
CRMatrix(const CRMatrix &source_matrix)
Copy constructor.
const int * row_start() const
Access to C-style row_start array (const version)
T & entry(const unsigned long &i, const unsigned long &j)
The read-write access function is deliberately broken.
int * row_start()
Access to C-style row_start 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,...
void operator=(const CRMatrix &)=delete
Broken assignment operator.
int * column_index()
Access to C-style column index 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...
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,...
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...
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...
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.
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...
//////////////////////////////////////////////////////////////////////////// ////////////////////////...
DenseMatrix & operator=(const DenseMatrix &source_matrix)
Copy assignment.
T & entry(const unsigned long &i, const unsigned long &j)
The access function that will be called by the read-write round-bracket operator.
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,...
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...
LinearAlgebraDistribution * distribution_pt() const
access to the LinearAlgebraDistribution
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
Abstract base class for matrices of doubles – adds abstract interfaces for solving,...
LinearSolver *& linear_solver_pt()
Return a pointer to the linear solver object.
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.
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.
void operator=(const DoubleMatrixBase &)=delete
Broken assignment operator.
virtual unsigned long nrow() const =0
Return the number of rows of the matrix.
LinearSolver *const & linear_solver_pt() const
Return a pointer to the linear solver object (const version)
A vector in the mathematical sense, initially developed for linear algebra type applications....
double max() const
returns the maximum coefficient
double * values_pt()
access function to the underlying values
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...
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)
Round brackets to give access as a(i,j) for read-write access. The function uses the MATRIX_TYPE temp...
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)
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....
RankFiveTensor(const RankFiveTensor &source_tensor)
Copy constructor: Deep copy.
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.
RankFiveTensor & operator=(const RankFiveTensor &source_tensor)
Copy assignement.
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 Q
4th Tensor dimension
unsigned long nindex3() const
Return the range of index 3 of the tensor.
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.
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 & raw_direct_access(const unsigned long &i)
Direct access to internal storage of data in flat-packed C-style column-major format....
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.
////////////////////////////////////////////////////////////////// //////////////////////////////////...
T & raw_direct_access(const unsigned long &i)
Direct access to internal storage of data in flat-packed C-style column-major format....
unsigned M
2nd Tensor dimension
unsigned N
1st Tensor dimension
RankFourTensor()
Empty constructor.
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.
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)
Overload the round brackets to give access as a(i,j,k,l)
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...
RankFourTensor & operator=(const RankFourTensor &source_tensor)
Copy assignement.
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.
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) 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 & operator=(const RankThreeTensor &source_tensor)
Copy assignement.
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)
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.
//////////////////////////////////////////////////////////////// ////////////////////////////////////...
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.
T * value()
Access to C-style value array.
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...
const T * value() const
Access to C-style value array (const version)
unsigned long ncol() const
Return the number of columns of the matrix.
T * Value
Internal representation of the matrix values, a pointer.
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.
//////////////////////////////////////////////////////////////////////////// ////////////////////////...
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 ...
void output()
Doc the command line arguments.
std::string string(const unsigned &i)
Return the i-th string or "" if the relevant string hasn't been defined.
//////////////////////////////////////////////////////////////////// ////////////////////////////////...
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)