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;
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",
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";
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++)
750 #ifdef RANGE_CHECKING
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";
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()",
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;
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
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++)
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;
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++)
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;
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++)
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)
2624 for (
unsigned long i = 0;
i < this->
Nnz;
i++)
2633 for (
unsigned long i = 0;
i <= this->
M;
i++)
2656 #ifdef RANGE_CHECKING
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";
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;
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;
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;
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;
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;
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;
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++)
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;
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."
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++)
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";
3505 if (in_matrix_pt == 0)
3507 std::ostringstream err_msg;
3508 err_msg <<
"The in_matrix_pt is null.\n";
3514 if (!in_matrix_pt->
built())
3516 std::ostringstream err_msg;
3517 err_msg <<
"The in_matrix_pt is null.\n";
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,
int i
Definition: BiCGSTAB_step_by_step.cpp:9
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
Eigen::Triplet< double > T
Definition: EigenUnitTest.cpp:11
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Definition: PartialRedux_count.cpp:3
float * p
Definition: Tutorial_Map_using.cpp:9
Scalar * b
Definition: benchVecAdd.cpp:17
Matrix< RealScalar, Dynamic, Dynamic > M
Definition: bench_gemm.cpp:50
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
A class for compressed column matrices that store doubles.
Definition: matrices.h:2791
double operator()(const unsigned long &i, const unsigned long &j) const
Definition: matrices.h:2830
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.
Definition: matrices.cc:715
virtual void lubksub(DoubleVector &rhs)
LU back solve for given RHS.
Definition: matrices.cc:614
void matrix_reduction(const double &alpha, CCDoubleMatrix &reduced_matrix)
Definition: matrices.cc:1149
virtual ~CCDoubleMatrix()
Destructor: Kill the LU factors if they have been setup.
Definition: matrices.cc:597
CCDoubleMatrix(const CCDoubleMatrix &matrix)=delete
Broken copy constructor.
unsigned long ncol() const
Return the number of columns of the matrix.
Definition: matrices.h:2823
unsigned long nrow() const
Return the number of rows of the matrix.
Definition: matrices.h:2817
CCDoubleMatrix()
Default constructor.
Definition: matrices.cc:572
unsigned & matrix_matrix_multiply_method()
Definition: matrices.h:2886
virtual void ludecompose()
LU decomposition using SuperLU.
Definition: matrices.cc:606
void multiply(const DoubleVector &x, DoubleVector &soln) const
Multiply the matrix by the vector x: soln=Ax.
Definition: matrices.cc:622
unsigned Matrix_matrix_multiply_method
Flag to determine which matrix-matrix multiplication method is used.
Definition: matrices.h:2893
Definition: matrices.h:2585
CCMatrix()
Default constructor.
Definition: matrices.h:2588
void sparse_indexed_output_helper(std::ostream &outfile) const
Definition: matrices.h:2735
CCMatrix(const Vector< T > &value, const Vector< int > &row_index_, const Vector< int > &column_start_, const unsigned long &n, const unsigned long &m)
Definition: matrices.h:2600
void build_without_copy(T *value, int *row_index, int *column_start, const unsigned long &nnz, const unsigned long &n, const unsigned long &m)
Definition: matrices.h:3199
virtual ~CCMatrix()
Destructor, delete any allocated memory.
Definition: matrices.h:2644
int * Column_start
Start index for column.
Definition: matrices.h:2779
int * Row_index
Row index.
Definition: matrices.h:2776
CCMatrix(const CCMatrix &source_matrix)
Copy constructor.
Definition: matrices.h:2614
T & entry(const unsigned long &i, const unsigned long &j)
Definition: matrices.h:2671
int * column_start()
Access to C-style column_start array.
Definition: matrices.h:2692
const int * column_start() const
Access to C-style column_start array (const version)
Definition: matrices.h:2698
T get_entry(const unsigned long &i, const unsigned long &j) const
Definition: matrices.h:2654
void build(const Vector< T > &value, const Vector< int > &row_index, const Vector< int > &column_start, const unsigned long &n, const unsigned long &m)
Definition: matrices.h:3247
void operator=(const CCMatrix &)=delete
Broken assignment operator.
const int * row_index() const
Access to C-style row index array (const version)
Definition: matrices.h:2710
void output_bottom_right_zero_helper(std::ostream &outfile) const
Definition: matrices.h:2718
int * row_index()
Access to C-style row index array.
Definition: matrices.h:2704
void clean_up_memory()
Wipe matrix data and set all values to 0.
Definition: matrices.h:3169
Definition: matrices.h:888
void sort_entries()
Definition: matrices.cc:1449
int * column_index()
Access to C-style column index array.
Definition: matrices.h:1072
int * row_start()
Access to C-style row_start array.
Definition: matrices.h:1060
virtual ~CRDoubleMatrix()
Destructor.
Definition: matrices.cc:1343
const double * value() const
Access to C-style value array (const version)
Definition: matrices.h:1090
void sparse_indexed_output_with_offset(std::string filename)
Definition: matrices.h:1031
unsigned & distributed_matrix_matrix_multiply_method()
Definition: matrices.h:1191
struct oomph::CRDoubleMatrix::CRDoubleMatrixComparisonHelper Comparison_struct
void matrix_reduction(const double &alpha, CRDoubleMatrix &reduced_matrix)
Definition: matrices.cc:2365
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.
Definition: matrices.cc:1882
void sparse_indexed_output_helper(std::ostream &outfile) const
Definition: matrices.h:1023
unsigned Distributed_matrix_matrix_multiply_method
Definition: matrices.h:1246
virtual void ludecompose()
Do LU decomposition.
Definition: matrices.cc:1728
unsigned long ncol() const
Return the number of columns of the matrix.
Definition: matrices.h:1008
void multiply(const DoubleVector &x, DoubleVector &soln) const
Multiply the matrix by the vector x: soln=Ax.
Definition: matrices.cc:1782
void add(const CRDoubleMatrix &matrix_in, CRDoubleMatrix &result_matrix) const
element-wise addition of this matrix with matrix_in.
Definition: matrices.cc:3515
const unsigned & distributed_matrix_matrix_multiply_method() const
Definition: matrices.h:1202
bool Built
Definition: matrices.h:1253
Vector< int > Index_of_diagonal_entries
Definition: matrices.h:1238
double inf_norm() const
returns the inf-norm of this matrix
Definition: matrices.cc:3412
void clear()
clear
Definition: matrices.cc:1657
const Vector< int > get_index_of_diagonal_entries() const
Definition: matrices.h:920
void get_matrix_transpose(CRDoubleMatrix *result) const
Returns the transpose of this matrix.
Definition: matrices.cc:3271
const int * column_index() const
Access to C-style column index array (const version)
Definition: matrices.h:1078
unsigned long nnz() const
Return the number of nonzero entries (the local nnz)
Definition: matrices.h:1096
CRDoubleMatrix * global_matrix() const
Definition: matrices.cc:2431
void redistribute(const LinearAlgebraDistribution *const &dist_pt)
Definition: matrices.cc:2575
const int * row_start() const
Access to C-style row_start array (const version)
Definition: matrices.h:1066
bool built() const
Definition: matrices.h:1210
unsigned & serial_matrix_matrix_multiply_method()
Definition: matrices.h:1159
void build_without_copy(const unsigned &ncol, const unsigned &nnz, double *value, int *column_index, int *row_start)
method to rebuild the matrix, but not the distribution
Definition: matrices.cc:1710
void output_bottom_right_zero_helper(std::ostream &outfile) const
Definition: matrices.h:1016
double * value()
Access to C-style value array.
Definition: matrices.h:1084
unsigned long nrow() const
Return the number of rows of the matrix.
Definition: matrices.h:1002
unsigned Serial_matrix_matrix_multiply_method
Definition: matrices.h:1242
Vector< double > diagonal_entries() const
Definition: matrices.cc:3465
CRDoubleMatrix()
Default constructor.
Definition: matrices.cc:1214
bool entries_are_sorted(const bool &doc_unordered_entries=false) const
Definition: matrices.cc:1366
const unsigned & serial_matrix_matrix_multiply_method() const
Definition: matrices.h:1181
CRMatrix< double > CR_matrix
Storage for the Matrix in CR Format.
Definition: matrices.h:1249
virtual void lubksub(DoubleVector &rhs)
LU back solve for given RHS.
Definition: matrices.cc:1749
void build(const LinearAlgebraDistribution *distribution_pt, const unsigned &ncol, const Vector< double > &value, const Vector< int > &column_index, const Vector< int > &row_start)
Definition: matrices.cc:1672
double operator()(const unsigned long &i, const unsigned long &j) const
Definition: matrices.h:1053
Definition: matrices.h:682
CRMatrix()
Default constructor.
Definition: matrices.h:685
void clean_up_memory()
Wipe matrix data and set all values to 0.
Definition: matrices.h:3323
const int * column_index() const
Access to C-style column index array (const version)
Definition: matrices.h:803
CRMatrix(const CRMatrix &source_matrix)
Copy constructor.
Definition: matrices.h:710
const int * row_start() const
Access to C-style row_start array (const version)
Definition: matrices.h:791
T & entry(const unsigned long &i, const unsigned long &j)
The read-write access function is deliberately broken.
Definition: matrices.h:764
int * row_start()
Access to C-style row_start array.
Definition: matrices.h:785
int * Row_start
Start index for row.
Definition: matrices.h:873
int * Column_index
Column index.
Definition: matrices.h:870
void build(const Vector< T > &value, const Vector< int > &column_index, const Vector< int > &row_start, const unsigned long &n, const unsigned long &m)
Definition: matrices.h:3404
void operator=(const CRMatrix &)=delete
Broken assignment operator.
int * column_index()
Access to C-style column index array.
Definition: matrices.h:797
void output_bottom_right_zero_helper(std::ostream &outfile) const
Definition: matrices.h:811
virtual ~CRMatrix()
Destructor, delete any allocated memory.
Definition: matrices.h:738
void build_without_copy(T *value, int *column_index, int *row_start, const unsigned long &nnz, const unsigned long &n, const unsigned long &m)
Definition: matrices.h:3354
void sparse_indexed_output_helper(std::ostream &outfile) const
Definition: matrices.h:828
T get_entry(const unsigned long &i, const unsigned long &j) const
Definition: matrices.h:748
CRMatrix(const Vector< T > &value, const Vector< int > &column_index_, const Vector< int > &row_start_, const unsigned long &n, const unsigned long &m)
Definition: matrices.h:697
Definition: matrices.h:1271
DenseDoubleMatrix()
Constructor, set the default linear solver.
Definition: matrices.cc:139
DenseDoubleMatrix(const DenseDoubleMatrix &matrix)=delete
Broken copy constructor.
virtual void lubksub(DoubleVector &rhs)
LU backsubstitution.
Definition: matrices.cc:202
virtual ~DenseDoubleMatrix()
Destructor.
Definition: matrices.cc:182
void matrix_reduction(const double &alpha, DenseDoubleMatrix &reduced_matrix)
Definition: matrices.cc:481
double & operator()(const unsigned long &i, const unsigned long &j)
Definition: matrices.h:1316
virtual void ludecompose()
LU decomposition using DenseLU (default linea solver)
Definition: matrices.cc:192
void multiply_transpose(const DoubleVector &x, DoubleVector &soln) const
Multiply the transposed matrix by the vector x: soln=A^T x.
Definition: matrices.cc:385
void multiply(const DoubleVector &x, DoubleVector &soln) const
Multiply the matrix by the vector x: soln=Ax.
Definition: matrices.cc:294
unsigned long nrow() const
Return the number of rows of the matrix.
Definition: matrices.h:1295
double operator()(const unsigned long &i, const unsigned long &j) const
Definition: matrices.h:1308
unsigned long ncol() const
Return the number of columns of the matrix.
Definition: matrices.h:1301
void eigenvalues_by_jacobi(Vector< double > &eigen_val, DenseMatrix< double > &eigen_vect) const
Definition: matrices.cc:224
void operator=(const DenseDoubleMatrix &)=delete
Broken assignment operator.
Definition: linear_solver.h:334
Definition: matrices.h:386
DenseMatrix & operator=(const DenseMatrix &source_matrix)
Copy assignment.
Definition: matrices.h:420
T & entry(const unsigned long &i, const unsigned long &j)
Definition: matrices.h:447
void output(std::ostream &outfile) const
Output function to print a matrix row-by-row to the stream outfile.
Definition: matrices.h:3054
T get_entry(const unsigned long &i, const unsigned long &j) const
Definition: matrices.h:457
void resize(const unsigned long &n, const unsigned long &m)
Definition: matrices.h:2959
unsigned long nrow() const
Return the number of rows of the matrix.
Definition: matrices.h:485
DenseMatrix(const DenseMatrix &source_matrix)
Copy constructor: Deep copy!
Definition: matrices.h:402
DenseMatrix(const unsigned long &n)
Constructor to build a square n by n matrix.
Definition: matrices.h:2906
unsigned long N
Number of rows.
Definition: matrices.h:392
void indexed_output(std::ostream &outfile) const
Indexed output as i,j,a(i,j)
Definition: matrices.h:3089
void output(std::string filename) const
Output function to print a matrix row-by-row to a file. Specify filename.
Definition: matrices.h:3074
void indexed_output(std::string filename) const
Definition: matrices.h:3108
DenseMatrix(const unsigned long &n, const unsigned long &m)
Constructor to build a matrix with n rows and m columns.
Definition: matrices.h:2924
virtual ~DenseMatrix()
Destructor, clean up the matrix data.
Definition: matrices.h:478
void sparse_indexed_output_helper(std::ostream &outfile) const
Sparse indexed output as i,j,a(i,j) for a(i,j)!=0 only.
Definition: matrices.h:3143
DenseMatrix(const unsigned long &n, const unsigned long &m, const T &initial_val)
Definition: matrices.h:2941
T * Matrixdata
Internal representation of matrix as a pointer to data.
Definition: matrices.h:389
unsigned long ncol() const
Return the number of columns of the matrix.
Definition: matrices.h:491
void output_bottom_right_zero_helper(std::ostream &outfile) const
Definition: matrices.h:3124
unsigned long M
Number of columns.
Definition: matrices.h:395
void initialise(const T &val)
Initialize all values in the matrix to val.
Definition: matrices.h:514
void resize(const unsigned long &n)
Definition: matrices.h:498
void resize(const unsigned long &n, const unsigned long &m, const T &initial_value)
Definition: matrices.h:3008
DenseMatrix()
Empty constructor, simply assign the lengths N and M to 0.
Definition: matrices.h:399
Definition: linear_algebra_distribution.h:435
LinearAlgebraDistribution * distribution_pt() const
access to the LinearAlgebraDistribution
Definition: linear_algebra_distribution.h:457
unsigned nrow() const
access function to the number of global rows.
Definition: linear_algebra_distribution.h:463
unsigned nrow_local() const
access function for the num of local rows on this processor.
Definition: linear_algebra_distribution.h:469
unsigned first_row() const
access function for the first row on this processor
Definition: linear_algebra_distribution.h:481
Definition: matrices.h:261
LinearSolver *& linear_solver_pt()
Return a pointer to the linear solver object.
Definition: matrices.h:296
virtual double operator()(const unsigned long &i, const unsigned long &j) const =0
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)
Definition: matrices.cc:50
virtual double max_residual(const DoubleVector &x, const DoubleVector &rhs)
Definition: matrices.h:348
LinearSolver * Default_linear_solver_pt
Definition: matrices.h:267
virtual void multiply(const DoubleVector &x, DoubleVector &soln) const =0
Multiply the matrix by the vector x: soln=Ax.
virtual ~DoubleMatrixBase()
virtual (empty) destructor
Definition: matrices.h:286
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
Definition: matrices.h:264
virtual void residual(const DoubleVector &x, const DoubleVector &b, DoubleVector &residual_)
Find the residual, i.e. r=b-Ax the residual.
Definition: matrices.h:326
DoubleMatrixBase()
(Empty) constructor.
Definition: matrices.h:271
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)
Definition: matrices.h:302
Definition: double_vector.h:58
double * values_pt()
access function to the underlying values
Definition: double_vector.h:254
Definition: linear_algebra_distribution.h:64
unsigned first_row() const
Definition: linear_algebra_distribution.h:261
Definition: linear_solver.h:68
Definition: matrices.h:74
virtual void output_bottom_right_zero_helper(std::ostream &outfile) const =0
T & operator()(const unsigned long &i, const unsigned long &j)
Definition: matrices.h:140
T operator()(const unsigned long &i, const unsigned long &j) const
Definition: matrices.h:128
void range_check(const unsigned long &i, const unsigned long &j) const
Definition: matrices.h:78
virtual ~Matrix()
Virtual (empty) destructor.
Definition: matrices.h:114
void sparse_indexed_output(std::ostream &outfile, const unsigned &precision=0, const bool &output_bottom_right_zero=false) const
Definition: matrices.h:182
virtual void sparse_indexed_output_helper(std::ostream &outfile) const =0
void operator=(const Matrix &)=delete
Broken assignment operator.
Matrix()
(Empty) constructor
Definition: matrices.h:105
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
Definition: matrices.h:226
virtual void output(std::ostream &outfile) const
Definition: matrices.h:152
virtual unsigned long ncol() const =0
Return the number of columns of the matrix.
Definition: communicator.h:54
Definition: oomph_definitions.h:222
Definition: oomph_definitions.h:267
A Rank 5 Tensor class.
Definition: matrices.h:2113
unsigned R
5th Tensor dimension
Definition: matrices.h:2131
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)
Definition: matrices.h:2529
const T & raw_direct_access(const unsigned long &i) const
Definition: matrices.h:2555
RankFiveTensor(const RankFiveTensor &source_tensor)
Copy constructor: Deep copy.
Definition: matrices.h:2198
unsigned M
2nd Tensor dimension
Definition: matrices.h:2122
unsigned long nindex4() const
Return the range of index 4 of the tensor.
Definition: matrices.h:2504
RankFiveTensor(const unsigned long &n)
One parameter constructor produces a nxnxnxnxn tensor.
Definition: matrices.h:2272
RankFiveTensor()
Empty constructor.
Definition: matrices.h:2195
RankFiveTensor & operator=(const RankFiveTensor &source_tensor)
Copy assignement.
Definition: matrices.h:2231
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)
Definition: matrices.h:2516
unsigned Q
4th Tensor dimension
Definition: matrices.h:2128
unsigned long nindex3() const
Return the range of index 3 of the tensor.
Definition: matrices.h:2498
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.
Definition: matrices.h:2311
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.
Definition: matrices.h:2410
void resize(const unsigned long &n)
Resize to a square nxnxnxn tensor.
Definition: matrices.h:2338
void range_check(const unsigned long &i, const unsigned long &j, const unsigned long &k, const unsigned long &l, const unsigned long &m) const
Definition: matrices.h:2135
unsigned long nindex2() const
Return the range of index 2 of the tensor.
Definition: matrices.h:2492
T & raw_direct_access(const unsigned long &i)
Definition: matrices.h:2545
unsigned long nindex5() const
Return the range of index 5 of the tensor.
Definition: matrices.h:2510
unsigned P
3rd Tensor dimension
Definition: matrices.h:2125
unsigned offset(const unsigned long &i, const unsigned long &j, const unsigned long &k) const
Definition: matrices.h:2564
void initialise(const T &val)
Initialise all values in the tensor to val.
Definition: matrices.h:2477
unsigned long nindex1() const
Return the range of index 1 of the tensor.
Definition: matrices.h:2486
T * Tensordata
Private internal representation as pointer to data.
Definition: matrices.h:2116
virtual ~RankFiveTensor()
Destructor: delete the pointers.
Definition: matrices.h:2331
unsigned N
1st Tensor dimension
Definition: matrices.h:2119
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.
Definition: matrices.h:2289
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.
Definition: matrices.h:2344
A Rank 4 Tensor class.
Definition: matrices.h:1701
T & raw_direct_access(const unsigned long &i)
Definition: matrices.h:2078
unsigned M
2nd Tensor dimension
Definition: matrices.h:1710
unsigned N
1st Tensor dimension
Definition: matrices.h:1707
RankFourTensor()
Empty constructor.
Definition: matrices.h:1769
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.
Definition: matrices.h:1854
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.
Definition: matrices.h:1961
virtual ~RankFourTensor()
Destructor: delete the pointers.
Definition: matrices.h:1892
unsigned offset(const unsigned long &i, const unsigned long &j) const
Definition: matrices.h:2096
T * Tensordata
Private internal representation as pointer to data.
Definition: matrices.h:1704
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.
Definition: matrices.h:1905
unsigned long nindex4() const
Return the range of index 4 of the tensor.
Definition: matrices.h:2045
unsigned long nindex2() const
Return the range of index 2 of the tensor.
Definition: matrices.h:2033
const T & raw_direct_access(const unsigned long &i) const
Definition: matrices.h:2087
unsigned long nindex1() const
Return the range of index 1 of the tensor.
Definition: matrices.h:2027
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)
Definition: matrices.h:2051
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)
Definition: matrices.h:2063
unsigned long nindex3() const
Return the range of index 3 of the tensor.
Definition: matrices.h:2039
RankFourTensor(const unsigned long &n)
One parameter constructor produces a nxnxnxn tensor.
Definition: matrices.h:1838
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.
Definition: matrices.h:1874
unsigned P
3rd Tensor dimension
Definition: matrices.h:1713
void range_check(const unsigned long &i, const unsigned long &j, const unsigned long &k, const unsigned long &l) const
Definition: matrices.h:1720
RankFourTensor & operator=(const RankFourTensor &source_tensor)
Copy assignement.
Definition: matrices.h:1801
RankFourTensor(const RankFourTensor &source_tensor)
Copy constructor: Deep copy.
Definition: matrices.h:1772
unsigned Q
4th Tensor dimension
Definition: matrices.h:1716
void initialise(const T &val)
Initialise all values in the tensor to val.
Definition: matrices.h:2018
void resize(const unsigned long &n)
Resize to a square nxnxnxn tensor.
Definition: matrices.h:1899
A Rank 3 Tensor class.
Definition: matrices.h:1370
virtual ~RankThreeTensor()
Destructor: delete the pointers.
Definition: matrices.h:1532
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.
Definition: matrices.h:1593
unsigned N
1st Tensor dimension
Definition: matrices.h:1376
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.
Definition: matrices.h:1516
unsigned long nindex1() const
Return the range of index 1 of the tensor.
Definition: matrices.h:1651
unsigned long nindex2() const
Return the range of index 2 of the tensor.
Definition: matrices.h:1657
void range_check(const unsigned long &i, const unsigned long &j, const unsigned long &k) const
Definition: matrices.h:1386
RankThreeTensor(const RankThreeTensor &source_tensor)
Copy constructor: Deep copy.
Definition: matrices.h:1428
RankThreeTensor()
Empty constructor.
Definition: matrices.h:1425
unsigned M
2nd Tensor dimension
Definition: matrices.h:1379
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)
Definition: matrices.h:1680
void resize(const unsigned long &n)
Resize to a square nxnxn tensor.
Definition: matrices.h:1539
void resize(const unsigned long &n_index1, const unsigned long &n_index2, const unsigned long &n_index3)
Resize to a general tensor.
Definition: matrices.h:1545
unsigned long nindex3() const
Return the range of index 3 of the tensor.
Definition: matrices.h:1663
void initialise(const T &val)
Initialise all values in the tensor to val.
Definition: matrices.h:1642
RankThreeTensor & operator=(const RankThreeTensor &source_tensor)
Copy assignement.
Definition: matrices.h:1450
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)
Definition: matrices.h:1669
RankThreeTensor(const unsigned long &n_index1, const unsigned long &n_index2, const unsigned long &n_index3)
Three parameter constructor, general non-square tensor.
Definition: matrices.h:1498
unsigned P
3rd Tensor dimension
Definition: matrices.h:1382
T * Tensordata
Private internal representation as pointer to data.
Definition: matrices.h:1373
RankThreeTensor(const unsigned long &n)
One parameter constructor produces a cubic nxnxn tensor.
Definition: matrices.h:1483
Definition: matrices.h:562
unsigned long Nnz
Number of non-zero values (i.e. size of Value array)
Definition: matrices.h:574
unsigned long nrow() const
Return the number of rows of the matrix.
Definition: matrices.h:628
T * value()
Access to C-style value array.
Definition: matrices.h:616
virtual void output_bottom_right_zero_helper(std::ostream &outfile) const
Definition: matrices.h:648
const T * value() const
Access to C-style value array (const version)
Definition: matrices.h:622
unsigned long ncol() const
Return the number of columns of the matrix.
Definition: matrices.h:634
T * Value
Internal representation of the matrix values, a pointer.
Definition: matrices.h:565
static T Zero
Dummy zero.
Definition: matrices.h:577
virtual void sparse_indexed_output_helper(std::ostream &outfile) const
Definition: matrices.h:661
void operator=(const SparseMatrix &)=delete
Broken assignment operator.
unsigned long nnz() const
Return the number of nonzero entries.
Definition: matrices.h:640
unsigned long N
Number of rows.
Definition: matrices.h:568
SparseMatrix()
Default constructor.
Definition: matrices.h:581
SparseMatrix(const SparseMatrix &source_matrix)
Copy constructor.
Definition: matrices.h:584
virtual ~SparseMatrix()
Destructor, delete the memory associated with the values.
Definition: matrices.h:609
unsigned long M
Number of columns.
Definition: matrices.h:571
Definition: linear_solver.h:486
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor >, 0, Eigen::OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: common.h:85
@ N
Definition: constructor.cpp:22
#define min(a, b)
Definition: datatypes.h:22
RealScalar alpha
Definition: level1_cplx_impl.h:151
EIGEN_BLAS_FUNC() copy(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:32
int * m
Definition: level2_cplx_impl.h:294
char char char int int * k
Definition: level2_impl.h:374
EIGEN_DEVICE_FUNC const Scalar & q
Definition: SpecialFunctionsImpl.h:2019
squared absolute value
Definition: GlobalFunctions.h:87
string filename
Definition: MergeRestartFiles.py:39
val
Definition: calibrate.py:119
double gershgorin_eigenvalue_estimate(const DenseMatrix< CRDoubleMatrix * > &matrix_pt)
Definition: matrices.cc:4003
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.
Definition: matrices.h:3490
void concatenate_without_communication(const Vector< LinearAlgebraDistribution * > &row_distribution_pt, const Vector< LinearAlgebraDistribution * > &col_distribution_pt, const DenseMatrix< CRDoubleMatrix * > &matrix_pt, CRDoubleMatrix &result_matrix)
Definition: matrices.cc:5223
double inf_norm(const DenseMatrix< CRDoubleMatrix * > &matrix_pt)
Compute infinity (maximum) norm of sub blocks as if it was one matrix.
Definition: matrices.cc:3731
void concatenate(const DenseMatrix< CRDoubleMatrix * > &matrix_pt, CRDoubleMatrix &result_matrix)
Definition: matrices.cc:4349
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)
Definition: matrices.cc:3676
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).
Definition: AnisotropicHookean.h:10
void output(std::ostream &outfile)
Output with default number of plot points.
Definition: gen_axisym_advection_diffusion_elements.h:161
list x
Definition: plotDoE.py:28
GenericValue< UTF8<> > Value
Value with UTF8 encoding.
Definition: document.h:679
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86
Create a struct to provide a comparison function for std::sort.
Definition: matrices.h:942
bool operator()(const std::pair< int, double > &pair_1, const std::pair< int, double > &pair_2)
Definition: matrices.h:944
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2