34 #ifndef OOMPH_MATRICES_HEADER 35 #define OOMPH_MATRICES_HEADER 39 #include <oomph-lib-config.h> 57 #ifdef OOMPH_HAS_TRILINOS 65 #define OOMPH_INITIALISE_DENSE_MATRICES 66 #undef OOMPH_INITIALISE_DENSE_MATRICES 77 template<
class T,
class MATRIX_TYPE>
85 void range_check(
const unsigned long&
i,
const unsigned long& j)
const 89 std::ostringstream error_message;
90 error_message <<
"Range Error: i=" << i <<
" is not in the range (0," 91 <<
nrow()-1 <<
")." << std::endl;
94 OOMPH_CURRENT_FUNCTION,
95 OOMPH_EXCEPTION_LOCATION);
99 std::ostringstream error_message;
100 error_message <<
"Range Error: j=" << j <<
" is not in the range (0," 101 <<
ncol()-1 <<
")." << std::endl;
104 OOMPH_CURRENT_FUNCTION,
105 OOMPH_EXCEPTION_LOCATION);
131 virtual unsigned long nrow()
const=0;
134 virtual unsigned long ncol()
const=0;
143 const unsigned long &j)
const 145 return static_cast<MATRIX_TYPE
const *
>(
this)->get_entry(i,j);
156 const unsigned long &j)
158 return static_cast<MATRIX_TYPE*
>(
this)->entry(i,j);
168 virtual void output(std::ostream &outfile)
const 171 "Output function is not implemented for this matrix class",
172 OOMPH_CURRENT_FUNCTION,
173 OOMPH_EXCEPTION_LOCATION);
198 const unsigned &precision=0,
199 const bool& output_bottom_right_zero=
false)
const 209 unsigned old_precision = 0;
212 old_precision = outfile.precision();
213 outfile.precision(precision);
221 if(output_bottom_right_zero &&
ncol() > 0 &&
nrow() > 0)
231 outfile.precision(old_precision);
241 const unsigned &precision=0,
242 const bool& output_bottom_right_zero=
false)
const 249 std::ofstream some_file(filename.c_str());
303 virtual unsigned long nrow()
const=0;
306 virtual unsigned long ncol()
const=0;
315 const unsigned long &j)
const=0;
351 double* residual_pt = residual_.
values_pt();
352 for (
unsigned i = 0; i < nrow_local; i++)
354 residual_pt[
i] = -residual_pt[
i];
428 N=source_matrix.
nrow();
429 M=source_matrix.
ncol();
431 Matrixdata =
new T[N*M];
433 for(
unsigned long i=0;
i<
N;
i++)
435 for(
unsigned long j=0;j<M;j++)
437 Matrixdata[M*
i+j] = source_matrix(
i,j);
446 if (
this != & source_matrix)
449 unsigned long n=source_matrix.
nrow();
450 unsigned long m=source_matrix.
ncol();
451 if ( (N!=n) || (M!=m) )
456 for (
unsigned long i=0;
i<
N;
i++)
458 for (
unsigned long j=0;j<M;j++)
460 (*this)(
i,j) = source_matrix(i,j);
470 inline T&
entry(
const unsigned long &
i,
const unsigned long &j)
472 #ifdef RANGE_CHECKING 475 return Matrixdata[M*i+j];
481 const unsigned long &j)
const 483 #ifdef RANGE_CHECKING 486 return Matrixdata[M*i+j];
493 DenseMatrix(
const unsigned long &n,
const unsigned long &m);
497 DenseMatrix(
const unsigned long &n,
const unsigned long &m,
498 const T &initial_val);
504 inline unsigned long nrow()
const {
return N;}
507 inline unsigned long ncol()
const {
return M;}
515 void resize(
const unsigned long &n,
const unsigned long &m);
519 void resize(
const unsigned long &n,
const unsigned long &m,
520 const T& initial_value);
524 {
for(
unsigned long i=0;
i<(N*M);++
i) {Matrixdata[
i] = val;}}
527 void output(std::ostream &outfile)
const;
534 void indexed_output(std::ostream &outfile)
const;
564 template <
class T,
class MATRIX_TYPE>
593 Nnz=source_matrix.
nnz();
596 N=source_matrix.
nrow();
599 M=source_matrix.
ncol();
605 for (
unsigned long i=0;
i<Nnz;
i++) {Value[
i]=source_matrix.
value()[
i];}
624 inline unsigned long nrow()
const {
return N;}
627 inline unsigned long ncol()
const {
return M;}
630 inline unsigned long nnz()
const {
return Nnz;}
638 "SparseMatrix::output_bottom_right_zero_helper() is a virtual function.\n";
640 "It must be overloaded for specific sparse matrix storage formats\n";
643 OOMPH_CURRENT_FUNCTION,
644 OOMPH_EXCEPTION_LOCATION);
652 "SparseMatrix::sparse_indexed_output_helper() is a virtual function.\n";
654 "It must be overloaded for specific sparse matrix storage formats\n";
657 OOMPH_CURRENT_FUNCTION,
658 OOMPH_EXCEPTION_LOCATION);
696 const unsigned long &n,
697 const unsigned long &m) :
702 build(value,column_index_,row_start_,n,m);
712 Column_index =
new int[this->Nnz];
715 for (
unsigned long i=0;
i<this->Nnz;
i++)
721 Row_start =
new int[this->
N+1];
724 for (
unsigned long i=0;
i<=this->
N;
i++)
739 delete[] Column_index; Column_index = 0;
740 delete[] Row_start; Row_start = 0;
746 const unsigned long &j)
const 748 #ifdef RANGE_CHECKING 751 for (
long k=Row_start[i];k<Row_start[i+1];k++)
753 if (
unsigned(Column_index[k])==j)
755 return this->Value[k];
762 T&
entry(
const unsigned long &
i,
const unsigned long &j)
765 "Non-const access not provided for the CRMatrix<T> class\n";
766 error_string +=
"It is not possible to use round-bracket access: M(i,j)\n";
767 error_string +=
"if M is not declared as const.\n";
769 "The solution (albeit ugly) is to create const reference to the matrix\n";
770 error_string +=
" const CRMatrix<T>& read_M = M;\n";
771 error_string +=
"Then read_M(i,j) is permitted\n";
774 OOMPH_CURRENT_FUNCTION,
775 OOMPH_EXCEPTION_LOCATION);
799 int last_row_local = this->
N-1;
800 int last_col = this->M-1;
803 T last_value = this->
operator()(last_row_local, last_col);
805 if(last_value ==
T(0))
807 outfile << last_row_local <<
" " << last_col <<
" " <<
T(0)
816 for (
unsigned long i=0;
i<this->
N;
i++)
818 for (
long j=Row_start[
i];j<Row_start[
i+1];j++)
820 outfile <<
i <<
" " << Column_index[j] <<
" " << this->Value[j]
827 void clean_up_memory();
836 const unsigned long &n,
837 const unsigned long &m);
845 void build_without_copy(
T* value,
848 const unsigned long& nnz,
849 const unsigned long& n,
850 const unsigned long& m);
885 const unsigned&
ncol,
915 if (Index_of_diagonal_entries.size()==0)
918 std::string err_strng=
"The Index_of_diagonal_entries vector has not been ";
919 err_strng+=
"set up yet. Run sort_entries() to set this vector up.";
923 "CRDoubleMatrix::get_index_of_diagonal_entries()",
924 OOMPH_EXCEPTION_LOCATION);
928 return Index_of_diagonal_entries;
936 const std::pair<int,double>& pair_2)
940 return (pair_1.first < pair_2.first);
948 bool entries_are_sorted(
const bool& doc_unordered_entries=
false)
const;
958 const unsigned& ncol,
967 void build(
const unsigned& ncol,
974 void build_without_copy(
const unsigned& ncol,
992 inline unsigned long nrow()
const 998 inline unsigned long ncol()
const 1000 return CR_matrix.ncol();
1008 CR_matrix.output_bottom_right_zero_helper(outfile);
1015 CR_matrix.sparse_indexed_output_helper(outfile);
1025 unsigned first_row=distribution_pt()->
first_row();
1028 std::ofstream some_file;
1029 some_file.open(filename.c_str());
1030 unsigned n=nrow_local();
1031 for (
unsigned long i=0;
i<n;
i++)
1033 for (
long j=row_start()[
i];j<row_start()[
i+1];j++)
1035 some_file << first_row+
i <<
" " << column_index()[j] <<
" " 1046 const unsigned long &j)
const 1047 {
return CR_matrix.get_entry(i,j);}
1053 const int*
row_start()
const {
return CR_matrix.row_start();}
1062 double*
value() {
return CR_matrix.value();}
1065 const double*
value()
const {
return CR_matrix.value();}
1068 inline unsigned long nnz()
const {
return CR_matrix.nnz();}
1072 virtual void ludecompose();
1109 void matrix_reduction(
const double &alpha,
1129 return Serial_matrix_matrix_multiply_method;
1150 return Serial_matrix_matrix_multiply_method;
1160 return Distributed_matrix_matrix_multiply_method;
1171 return Distributed_matrix_matrix_multiply_method;
1252 const double &initial_val);
1277 const unsigned long &j)
1282 inline double&
operator()(
const unsigned long &
i,
const unsigned long &j)
1289 virtual void ludecompose();
1316 void matrix_reduction(
const double &alpha,
1357 const unsigned long& j,
1358 const unsigned long& k)
const 1362 std::ostringstream error_message;
1363 error_message <<
"Range Error: i=" << i <<
" is not in the range (0," 1364 << N-1 <<
")." << std::endl;
1367 OOMPH_CURRENT_FUNCTION,
1368 OOMPH_EXCEPTION_LOCATION);
1372 std::ostringstream error_message;
1373 error_message <<
"Range Error: j=" << j <<
" is not in the range (0," 1374 << M-1 <<
")." << std::endl;
1377 OOMPH_CURRENT_FUNCTION,
1378 OOMPH_EXCEPTION_LOCATION);
1382 std::ostringstream error_message;
1383 error_message <<
"Range Error: k=" << k <<
" is not in the range (0," 1384 << P-1 <<
")." << std::endl;
1387 OOMPH_CURRENT_FUNCTION,
1388 OOMPH_EXCEPTION_LOCATION);
1406 Tensordata =
new T[N*M*P];
1408 for(
unsigned i=0;
i<
N;
i++)
1410 for(
unsigned j=0;j<M;j++)
1412 for(
unsigned k=0;k<P;k++)
1414 Tensordata[P*(M*
i + j) +k] = source_tensor(
i,j,k);
1424 if (
this != & source_tensor)
1427 unsigned long n=source_tensor.
nindex1();
1428 unsigned long m=source_tensor.
nindex2();
1429 unsigned long p=source_tensor.
nindex3();
1431 if ( (N!=n) || (M!=m) || (P!=p) ) {resize(n,m,p);}
1434 for (
unsigned long i=0;
i<
N;
i++)
1436 for (
unsigned long j=0;j<M;j++)
1438 for(
unsigned long k=0;k<P;k++)
1440 (*this)(
i,j,k) = source_tensor(i,j,k);
1456 Tensordata =
new T[N*M*P];
1458 #ifdef OOMPH_INITIALISE_DENSE_MATRICES 1465 const unsigned long &n_index3)
1468 N=n_index1; M=n_index2; P=n_index3;
1470 Tensordata =
new T[N*M*P];
1472 #ifdef OOMPH_INITIALISE_DENSE_MATRICES 1480 const unsigned long &n_index3,
const T &initial_val)
1483 N=n_index1; M=n_index2; P=n_index3;
1485 Tensordata =
new T[N*M*P];
1487 initialise(initial_val);
1497 void resize(
const unsigned long &n_index1,
const unsigned long &n_index2,
1498 const unsigned long &n_index3)
1501 if((n_index1==N) && (n_index2==M) && (n_index3==P)) {
return;}
1503 unsigned long n_old=
N, m_old=M, p_old=P;
1505 N=n_index1; M=n_index2; P=n_index3;
1507 T* temp_tensor = Tensordata;
1509 Tensordata =
new T[N*M*P];
1510 #ifdef OOMPH_INITIALISE_DENSE_MATRICES 1514 unsigned long n_copy, m_copy, p_copy;
1515 n_copy = std::min(n_old,n_index1);
1516 m_copy = std::min(m_old,n_index2);
1517 p_copy = std::min(p_old,n_index3);
1520 for (
unsigned long i=0;
i<n_copy;
i++)
1523 for (
unsigned long j=0;j<m_copy;j++)
1526 for (
unsigned long k=0;k<p_copy;k++)
1529 Tensordata[M*P*
i + P*j + k] =
1530 temp_tensor[m_old*p_old*
i + p_old*j + k];
1535 delete[] temp_tensor;
1539 void resize(
const unsigned long &n_index1,
const unsigned long &n_index2,
1540 const unsigned long &n_index3,
const T &initial_value)
1543 if((n_index1==N) && (n_index2==M) && (n_index3==P)) {
return;}
1545 unsigned long n_old=
N, m_old=M, p_old=P;
1547 N=n_index1; M=n_index2; P=n_index3;
1549 T* temp_tensor = Tensordata;
1551 Tensordata =
new T[N*M*P];
1553 initialise(initial_value);
1556 unsigned long n_copy, m_copy, p_copy;
1557 n_copy = std::min(n_old,n_index1);
1558 m_copy = std::min(m_old,n_index2);
1559 p_copy = std::min(p_old,n_index3);
1562 for (
unsigned long i=0;
i<n_copy;
i++)
1565 for (
unsigned long j=0;j<m_copy;j++)
1568 for (
unsigned long k=0;k<p_copy;k++)
1571 Tensordata[M*P*
i + P*j + k] =
1572 temp_tensor[m_old*p_old*
i + p_old*j + k];
1577 delete[] temp_tensor;
1582 {
for(
unsigned long i=0;
i<(N*M*P);++
i) {Tensordata[
i] = val;}}
1595 const unsigned long &k)
1597 #ifdef RANGE_CHECKING 1600 return Tensordata[P*(M*i + j) + k];
1605 const unsigned long &k)
const 1607 #ifdef RANGE_CHECKING 1610 return Tensordata[P*(M*i + j) + k];
1648 const unsigned long& j,
1649 const unsigned long& k,
1650 const unsigned long& l)
const 1654 std::ostringstream error_message;
1655 error_message <<
"Range Error: i=" << i <<
" is not in the range (0," 1656 << N-1 <<
")." << std::endl;
1659 OOMPH_CURRENT_FUNCTION,
1660 OOMPH_EXCEPTION_LOCATION);
1664 std::ostringstream error_message;
1665 error_message <<
"Range Error: j=" << j <<
" is not in the range (0," 1666 << M-1 <<
")." << std::endl;
1669 OOMPH_CURRENT_FUNCTION,
1670 OOMPH_EXCEPTION_LOCATION);
1674 std::ostringstream error_message;
1675 error_message <<
"Range Error: k=" << k <<
" is not in the range (0," 1676 << P-1 <<
")." << std::endl;
1679 OOMPH_CURRENT_FUNCTION,
1680 OOMPH_EXCEPTION_LOCATION);
1684 std::ostringstream error_message;
1685 error_message <<
"Range Error: l=" << l <<
" is not in the range (0," 1686 << Q-1 <<
")." << std::endl;
1689 OOMPH_CURRENT_FUNCTION,
1690 OOMPH_EXCEPTION_LOCATION);
1708 Tensordata =
new T[N*M*P*
Q];
1711 for(
unsigned i=0;
i<
N;
i++)
1713 for(
unsigned j=0;j<M;j++)
1715 for(
unsigned k=0;k<P;k++)
1717 for(
unsigned l=0;l<
Q;l++)
1719 Tensordata[Q*(P*(M*
i + j) +k)+l] = source_tensor(
i,j,k,l);
1730 if (
this != & source_tensor)
1733 unsigned long n=source_tensor.
nindex1();
1734 unsigned long m=source_tensor.
nindex2();
1735 unsigned long p=source_tensor.
nindex3();
1736 unsigned long q=source_tensor.
nindex4();
1738 if ( (N!=n) || (M!=m) || (P!=p) || (Q!=q) ) {resize(n,m,p,q);}
1741 for (
unsigned long i=0;
i<
N;
i++)
1743 for (
unsigned long j=0;j<M;j++)
1745 for(
unsigned long k=0;k<P;k++)
1747 for(
unsigned long l=0;l<
Q;l++)
1749 (*this)(
i,j,k,l) = source_tensor(i,j,k,l);
1766 Tensordata =
new T[N*M*P*
Q];
1768 #ifdef OOMPH_INITIALISE_DENSE_MATRICES 1775 const unsigned long &n_index3,
const unsigned long &n_index4)
1778 N=n_index1; M=n_index2; P=n_index3; Q=n_index4;
1780 Tensordata =
new T[N*M*P*
Q];
1782 #ifdef OOMPH_INITIALISE_DENSE_MATRICES 1790 const unsigned long &n_index3,
const unsigned long &n_index4,
1791 const T &initial_val)
1794 N=n_index1; M=n_index2; P=n_index3; Q=n_index4;
1796 Tensordata =
new T[N*M*P*
Q];
1798 initialise(initial_val);
1808 void resize(
const unsigned long &n_index1,
const unsigned long &n_index2,
1809 const unsigned long &n_index3,
const unsigned long &n_index4)
1812 if((n_index1==N) && (n_index2==M) && (n_index3==P) && (n_index4==Q))
1815 unsigned long n_old=
N, m_old=M, p_old=P, q_old=
Q;
1817 N=n_index1; M=n_index2; P=n_index3; Q=n_index4;
1819 T* temp_tensor = Tensordata;
1821 Tensordata =
new T[N*M*P*
Q];
1822 #ifdef OOMPH_INITIALISE_DENSE_MATRICES 1826 unsigned long n_copy, m_copy, p_copy, q_copy;
1827 n_copy = std::min(n_old,n_index1);
1828 m_copy = std::min(m_old,n_index2);
1829 p_copy = std::min(p_old,n_index3);
1830 q_copy = std::min(q_old,n_index4);
1833 for (
unsigned long i=0;
i<n_copy;
i++)
1836 for (
unsigned long j=0;j<m_copy;j++)
1839 for (
unsigned long k=0;k<p_copy;k++)
1842 for (
unsigned long l=0;l<q_copy;l++)
1845 Tensordata[Q*(M*P*
i + P*j + k) +l] =
1846 temp_tensor[q_old*(m_old*p_old*
i + p_old*j + k)+ l];
1852 delete[] temp_tensor;
1856 void resize(
const unsigned long &n_index1,
const unsigned long &n_index2,
1857 const unsigned long &n_index3,
const unsigned long &n_index4,
1858 const T &initial_value)
1861 if((n_index1==N) && (n_index2==M) && (n_index3==P) && (n_index4==Q))
1864 unsigned long n_old=
N, m_old=M, p_old=P, q_old=
Q;
1866 N=n_index1; M=n_index2; P=n_index3; Q=n_index4;
1868 T* temp_tensor = Tensordata;
1870 Tensordata =
new T[N*M*P*
Q];
1872 initialise(initial_value);
1875 unsigned long n_copy, m_copy, p_copy, q_copy;
1876 n_copy = std::min(n_old,n_index1);
1877 m_copy = std::min(m_old,n_index2);
1878 p_copy = std::min(p_old,n_index3);
1879 q_copy = std::min(q_old,n_index4);
1882 for (
unsigned long i=0;
i<n_copy;
i++)
1885 for (
unsigned long j=0;j<m_copy;j++)
1888 for (
unsigned long k=0;k<p_copy;k++)
1891 for (
unsigned long l=0;l<q_copy;l++)
1894 Tensordata[Q*(M*P*
i + P*j + k) +l] =
1895 temp_tensor[q_old*(m_old*p_old*
i + p_old*j + k)+ l];
1901 delete[] temp_tensor;
1906 {
for(
unsigned long i=0;
i<(N*M*P*
Q);++
i) {Tensordata[
i] = val;}}
1922 const unsigned long &k,
const unsigned long &l)
1924 #ifdef RANGE_CHECKING 1927 return Tensordata[Q*(P*(M*i + j) + k)+l];
1932 const unsigned long &j,
1933 const unsigned long &k,
1934 const unsigned long &l)
const 1936 #ifdef RANGE_CHECKING 1939 return Tensordata[Q*(P*(M*i + j) + k)+l];
1947 {
return Tensordata[
i];}
1954 {
return Tensordata[
i];}
1961 const unsigned long &j)
const 1962 {
return (Q*(P*(M*i + j) + 0) + 0);}
2002 const unsigned long& j,
2003 const unsigned long& k,
2004 const unsigned long& l,
2005 const unsigned long& m)
const 2009 std::ostringstream error_message;
2010 error_message <<
"Range Error: i=" << i <<
" is not in the range (0," 2011 << N-1 <<
")." << std::endl;
2014 OOMPH_CURRENT_FUNCTION,
2015 OOMPH_EXCEPTION_LOCATION);
2019 std::ostringstream error_message;
2020 error_message <<
"Range Error: j=" << j <<
" is not in the range (0," 2021 << M-1 <<
")." << std::endl;
2024 OOMPH_CURRENT_FUNCTION,
2025 OOMPH_EXCEPTION_LOCATION);
2029 std::ostringstream error_message;
2030 error_message <<
"Range Error: k=" << k <<
" is not in the range (0," 2031 << P-1 <<
")." << std::endl;
2034 OOMPH_CURRENT_FUNCTION,
2035 OOMPH_EXCEPTION_LOCATION);
2039 std::ostringstream error_message;
2040 error_message <<
"Range Error: l=" << l <<
" is not in the range (0," 2041 << Q-1 <<
")." << std::endl;
2044 OOMPH_CURRENT_FUNCTION,
2045 OOMPH_EXCEPTION_LOCATION);
2049 std::ostringstream error_message;
2050 error_message <<
"Range Error: m=" << m <<
" is not in the range (0," 2051 << R-1 <<
")." << std::endl;
2054 OOMPH_CURRENT_FUNCTION,
2055 OOMPH_EXCEPTION_LOCATION);
2075 Tensordata =
new T[N*M*P*Q*
R];
2078 for(
unsigned i=0;
i<
N;
i++)
2080 for(
unsigned j=0;j<M;j++)
2082 for(
unsigned k=0;k<P;k++)
2084 for(
unsigned l=0;l<
Q;l++)
2086 for(
unsigned m=0;m<
R;m++)
2088 Tensordata[R*(Q*(P*(M*
i + j) +k)+l)+m] = source_tensor(
i,j,k,l,m);
2100 if (
this != & source_tensor)
2103 unsigned long n=source_tensor.
nindex1();
2104 unsigned long m=source_tensor.
nindex2();
2105 unsigned long p=source_tensor.
nindex3();
2106 unsigned long q=source_tensor.
nindex4();
2107 unsigned long r=source_tensor.
nindex5();
2109 if ( (N!=n) || (M!=m) || (P!=p) || (Q!=q)|| (R!=r) ) {resize(n,m,p,q,r);}
2112 for (
unsigned long i=0;
i<
N;
i++)
2114 for (
unsigned long j=0;j<M;j++)
2116 for(
unsigned long k=0;k<P;k++)
2118 for(
unsigned long l=0;l<
Q;l++)
2120 for(
unsigned long m=0;m<
R;m++)
2122 (*this)(
i,j,k,l,m) = source_tensor(i,j,k,l,m);
2138 N=n; M=n; P=n; Q=n; R=n;
2140 Tensordata =
new T[N*M*P*Q*
R];
2142 #ifdef OOMPH_INITIALISE_DENSE_MATRICES 2149 const unsigned long &n_index3,
const unsigned long &n_index4,
2150 const unsigned long &n_index5)
2153 N=n_index1; M=n_index2; P=n_index3; Q=n_index4; R=n_index5;
2155 Tensordata =
new T[N*M*P*Q*
R];
2157 #ifdef OOMPH_INITIALISE_DENSE_MATRICES 2165 const unsigned long &n_index3,
const unsigned long &n_index4,
2166 const unsigned long &n_index5,
const T &initial_val)
2169 N=n_index1; M=n_index2; P=n_index3; Q=n_index4; R=n_index5;
2171 Tensordata =
new T[N*M*P*Q*
R];
2173 initialise(initial_val);
2183 void resize(
const unsigned long &n_index1,
const unsigned long &n_index2,
2184 const unsigned long &n_index3,
const unsigned long &n_index4,
2185 const unsigned long &n_index5)
2188 if((n_index1==N) && (n_index2==M) && (n_index3==P) && (n_index4==Q) &&
2192 unsigned long n_old=
N, m_old=M, p_old=P, q_old=
Q, r_old=
R;
2194 N=n_index1; M=n_index2; P=n_index3; Q=n_index4; R=n_index5;
2196 T* temp_tensor = Tensordata;
2198 Tensordata =
new T[N*M*P*Q*
R];
2199 #ifdef OOMPH_INITIALISE_DENSE_MATRICES 2203 unsigned long n_copy, m_copy, p_copy, q_copy, r_copy;
2204 n_copy = std::min(n_old,n_index1);
2205 m_copy = std::min(m_old,n_index2);
2206 p_copy = std::min(p_old,n_index3);
2207 q_copy = std::min(q_old,n_index4);
2208 r_copy = std::min(r_old,n_index5);
2211 for (
unsigned long i=0;
i<n_copy;
i++)
2214 for (
unsigned long j=0;j<m_copy;j++)
2217 for (
unsigned long k=0;k<p_copy;k++)
2220 for (
unsigned long l=0;l<q_copy;l++)
2223 for (
unsigned long m=0;m<r_copy;m++)
2226 Tensordata[R*(Q*(M*P*
i + P*j + k) +l) +m] =
2227 temp_tensor[r_old*(q_old*(m_old*p_old*
i + p_old*j + k)+ l)+ m];
2234 delete[] temp_tensor;
2238 void resize(
const unsigned long &n_index1,
const unsigned long &n_index2,
2239 const unsigned long &n_index3,
const unsigned long &n_index4,
2240 const unsigned long &n_index5,
const T &initial_value)
2243 if((n_index1==N) && (n_index2==M) && (n_index3==P) && (n_index4==Q) &&
2247 unsigned long n_old=
N, m_old=M, p_old=P, q_old=
Q, r_old=
R;
2249 N=n_index1; M=n_index2; P=n_index3; Q=n_index4; R=n_index5;
2251 T* temp_tensor = Tensordata;
2253 Tensordata =
new T[N*M*P*Q*
R];
2255 initialise(initial_value);
2258 unsigned long n_copy, m_copy, p_copy, q_copy, r_copy;
2259 n_copy = std::min(n_old,n_index1);
2260 m_copy = std::min(m_old,n_index2);
2261 p_copy = std::min(p_old,n_index3);
2262 q_copy = std::min(q_old,n_index4);
2263 r_copy = std::min(r_old,n_index5);
2266 for (
unsigned long i=0;
i<n_copy;
i++)
2269 for (
unsigned long j=0;j<m_copy;j++)
2272 for (
unsigned long k=0;k<p_copy;k++)
2275 for (
unsigned long l=0;l<q_copy;l++)
2278 for (
unsigned long m=0;m<r_copy;m++)
2281 Tensordata[R*(Q*(M*P*
i + P*j + k) +l) + m] =
2282 temp_tensor[r_old*(q_old*(m_old*p_old*
i + p_old*j + k)+ l) +m];
2289 delete[] temp_tensor;
2294 {
for(
unsigned long i=0;
i<(N*M*P*Q*
R);++
i) {Tensordata[
i] = val;}}
2313 const unsigned long &k,
const unsigned long &l,
2314 const unsigned long &m)
2316 #ifdef RANGE_CHECKING 2319 return Tensordata[R*(Q*(P*(M*i + j) + k) +l) +m];
2324 const unsigned long &j,
2325 const unsigned long &k,
2326 const unsigned long &l,
2327 const unsigned long &m)
const 2329 #ifdef RANGE_CHECKING 2332 return Tensordata[R*(Q*(P*(M*i + j) + k) +l) +m];
2340 {
return Tensordata[
i];}
2348 {
return Tensordata[
i];}
2355 const unsigned long &j,
2356 const unsigned long &k)
const 2357 {
return (R*(Q*(P*(M*i + j) + k) + 0 ) + 0);}
2397 const unsigned long &n,
2402 build(value,row_index_,column_start_,n,m);
2414 Row_index =
new int[this->Nnz];
2417 for (
unsigned long i=0;
i<this->Nnz;
i++)
2423 Column_start =
new int[this->M+1];
2426 for (
unsigned long i=0;
i<=this->M;
i++)
2442 delete[] Row_index; Row_index = 0;
2443 delete[] Column_start; Column_start = 0;
2450 #ifdef RANGE_CHECKING 2453 for (
long k=Column_start[j];k<Column_start[j+1];k++)
2455 if (
unsigned(Row_index[k])==i)
2457 return this->Value[k];
2465 T&
entry(
const unsigned long &
i,
const unsigned long &j)
2468 "Non-const access not provided for the CCMatrix<T> class\n";
2469 error_string +=
"It is not possible to use round-bracket access: M(i,j)\n";
2470 error_string +=
"if M is not declared as const.\n";
2472 "The solution (albeit ugly) is to create const reference to the matrix\n";
2473 error_string +=
" const CCMatrix<T>& read_M = M;\n";
2474 error_string +=
"Then read_M(i,j) is permitted\n";
2477 OOMPH_CURRENT_FUNCTION,
2478 OOMPH_EXCEPTION_LOCATION);
2502 int last_row = this->
N-1;
2503 int last_col_local = this->M-1;
2506 T last_value = this->
operator()(last_row, last_col_local);
2508 if(last_value ==
T(0))
2510 outfile << last_row <<
" " << last_col_local <<
" " <<
T(0)
2519 for (
unsigned long j=0;j<this->
N;j++)
2521 for (
long k=Column_start[j];k<Column_start[j+1];k++)
2523 outfile << Row_index[k] <<
" " << j
2524 <<
" " << this->Value[k] << std::endl;
2530 void clean_up_memory();
2539 const unsigned long &n,
2540 const unsigned long &m);
2547 void build_without_copy(
T* value,
2550 const unsigned long &nnz,
2551 const unsigned long &n,
2552 const unsigned long &m);
2590 const unsigned long &n,
2591 const unsigned long &m);
2618 const unsigned long &j)
2622 virtual void ludecompose();
2656 void matrix_reduction(
const double &alpha,
2673 return Matrix_matrix_multiply_method;
2698 Matrixdata =
new T[n*n];
2700 #ifdef OOMPH_INITIALISE_DENSE_MATRICES 2711 const unsigned long &m)
2716 Matrixdata =
new T[n*m];
2717 #ifdef OOMPH_INITIALISE_DENSE_MATRICES 2728 const T &initial_val)
2733 Matrixdata =
new T[n*m];
2734 initialise(initial_val);
2744 const unsigned long &m)
2747 if((n==
N) && (m==M)) {
return;}
2749 unsigned long n_old=
N, m_old=M;
2753 T* temp_matrix = Matrixdata;
2756 Matrixdata =
new T[n*m];
2758 #ifdef OOMPH_INITIALISE_DENSE_MATRICES 2763 unsigned long n_copy, m_copy;
2764 n_copy = std::min(n_old,n); m_copy = std::min(m_old,m);
2768 for(
unsigned long i=0;
i<n_copy;
i++)
2771 for (
unsigned long j=0;j<m_copy;j++)
2774 Matrixdata[m*
i+j] = temp_matrix[m_old*
i+j];
2779 delete[] temp_matrix;
2790 const unsigned long &m,
2791 const T &initial_value)
2794 if((n==
N) && (m==M)) {
return;}
2796 unsigned long n_old=
N, m_old=M;
2800 T* temp_matrix = Matrixdata;
2802 Matrixdata =
new T[n*m];
2804 initialise(initial_value);
2807 unsigned long n_copy, m_copy;
2808 n_copy = std::min(n_old,n); m_copy = std::min(m_old,m);
2811 for (
unsigned long i=0;
i<n_copy;
i++)
2814 for (
unsigned long j=0;j<m_copy;j++)
2817 Matrixdata[m*
i+j] = temp_matrix[m_old*
i+j];
2822 delete[] temp_matrix;
2834 for(
unsigned i=0;
i<
N;
i++)
2837 for(
unsigned j=0;j<M;j++)
2839 outfile << (*this)(
i,j) <<
" ";
2842 outfile << std::endl;
2855 std::ofstream some_file;
2856 some_file.open(filename.c_str());
2871 for(
unsigned i=0;
i<
N;
i++)
2874 for(
unsigned j=0;j<M;j++)
2876 outfile <<
i <<
" " << j <<
" " << (*this)(
i,j) << std::endl;
2891 std::ofstream some_file;
2892 some_file.open(filename.c_str());
2893 indexed_output(some_file);
2906 int last_row = this->
N-1;
2907 int last_col = this->M-1;
2910 T last_value = this->
operator()(last_row, last_col);
2912 if(last_value ==
T(0))
2914 outfile << last_row <<
" " << last_col <<
" " <<
T(0)
2926 for(
unsigned i=0;
i<
N;
i++)
2929 for(
unsigned j=0;j<M;j++)
2931 if ((*
this)(
i,j)!=
T(0))
2933 outfile <<
i <<
" " << j <<
" " << (*this)(
i,j) << std::endl;
2955 delete[] this->Value;
2958 if (this->Row_index!=0)
2960 delete[] this->Row_index;
2963 if (this->Column_start!=0)
2965 delete[] this->Column_start;
2966 this->Column_start=0;
2984 const unsigned long& nnz,
2985 const unsigned long& n,
2986 const unsigned long& m)
2998 if(this->Value!=0) {
delete[] this->Value;}
2999 if(this->Row_index!=0) {
delete[] this->Row_index;}
3000 if(this->Column_start!=0) {
delete[] this->Column_start;}
3003 this->Value = value;
3006 this->Row_index = row_index;
3009 this->Column_start = column_start;
3024 const unsigned long &n,
3025 const unsigned long &m)
3029 if (value.size()!=row_index_.size())
3031 std::ostringstream error_message;
3033 <<
"length of value " << value.size()
3034 <<
" and row_index vectors " << row_index_.size() <<
" should match " 3038 OOMPH_CURRENT_FUNCTION,
3039 OOMPH_EXCEPTION_LOCATION);
3044 this->Nnz = value.size();
3053 if(this->Value!=0) {
delete[] this->Value;}
3054 if(this->Row_index!=0) {
delete[] this->Row_index;}
3055 if(this->Column_start!=0) {
delete[] this->Column_start;}
3058 this->Value =
new T[this->Nnz];
3061 this->Row_index =
new int[this->Nnz];
3064 for (
unsigned long i=0;
i<this->Nnz;
i++)
3066 this->Value[
i]=value[
i];
3067 this->Row_index[
i]=row_index_[
i];
3072 unsigned long n_column_start = column_start_.size();
3073 this->Column_start =
new int[n_column_start];
3076 for (
unsigned long i=0;
i<n_column_start;
i++)
3078 this->Column_start[
i]=column_start_[
i];
3097 delete[] this->Value;
3100 if (this->Column_index!=0)
3102 delete[] this->Column_index;
3103 this->Column_index=0;
3105 if (this->Row_start!=0)
3107 delete[] this->Row_start;
3127 const unsigned long& nnz,
3128 const unsigned long& n,
3129 const unsigned long& m)
3141 if(this->Value!=0) {
delete[] this->Value;}
3142 if(this->Column_index!=0) {
delete[] this->Column_index;}
3143 if(this->Row_start!=0) {
delete[] this->Row_start;}
3146 this->Value = value;
3149 this->Column_index = column_index_;
3152 this->Row_start = row_start_;
3169 const unsigned long &n,
3170 const unsigned long &m)
3173 if(value.size() != column_index_.size())
3175 std::ostringstream error_message;
3176 error_message <<
"Must have the same number of values and column indices," 3177 <<
"we have " << value.size() <<
" values and " 3178 << column_index_.size() <<
" column inidicies." 3181 OOMPH_CURRENT_FUNCTION,
3182 OOMPH_EXCEPTION_LOCATION);
3186 this->Nnz = value.size();
3195 if(this->Value!=0) {
delete[] this->Value;}
3196 if(this->Column_index!=0) {
delete[] this->Column_index;}
3197 if(this->Row_start!=0) {
delete[] this->Row_start;}
3200 this->Value =
new T[this->Nnz];
3203 this->Column_index =
new int[this->Nnz];
3206 for (
unsigned long i=0;
i<this->Nnz;
i++)
3208 this->Value[
i]=value[
i];
3209 this->Column_index[
i]=column_index_[
i];
3214 unsigned long n_row_start = row_start_.size();
3215 this->Row_start =
new int[n_row_start];
3218 for (
unsigned long i=0;
i<n_row_start;
i++)
3220 this->Row_start[
i]=row_start_[
i];
3228 template<
class T,
class MATRIX_TYPE>
3241 namespace CRDoubleMatrixHelpers
3249 if(out_matrix.
built())
3251 std::ostringstream err_msg;
3252 err_msg <<
"The result matrix has been built.\n" 3253 <<
"Please clear the matrix.\n";
3255 OOMPH_CURRENT_FUNCTION,
3256 OOMPH_EXCEPTION_LOCATION);
3260 if(in_matrix_pt == 0)
3262 std::ostringstream err_msg;
3263 err_msg <<
"The in_matrix_pt is null.\n";
3265 OOMPH_CURRENT_FUNCTION,
3266 OOMPH_EXCEPTION_LOCATION);
3270 if(!in_matrix_pt->
built())
3272 std::ostringstream err_msg;
3273 err_msg <<
"The in_matrix_pt is null.\n";
3275 OOMPH_CURRENT_FUNCTION,
3276 OOMPH_EXCEPTION_LOCATION);
3290 const unsigned in_nrow_local = in_matrix_pt->
nrow_local();
3291 const unsigned long in_nnz = in_matrix_pt->
nnz();
3294 double* out_values =
new double[in_nnz];
3295 int* out_column_indices =
new int[in_nnz];
3296 int* out_row_start =
new int[in_nrow_local + 1];
3299 const double*
const in_values = in_matrix_pt->
value();
3300 const int*
const in_column_indices = in_matrix_pt->
column_index();
3301 const int*
const in_row_start = in_matrix_pt->
row_start();
3304 std::copy(in_values,
3308 std::copy(in_column_indices,
3309 in_column_indices+in_nnz,
3310 out_column_indices);
3312 std::copy(in_row_start,
3313 in_row_start+(in_nrow_local + 1),
3337 const unsigned &
nrow,
const unsigned &
ncol,
virtual ~RankThreeTensor()
Destructor: delete the pointers.
unsigned long N
Number of rows.
int * column_index()
Access to C-style column index array.
void operator=(const CCDoubleMatrix &)
Broken assignment operator.
unsigned long nnz() const
Return the number of nonzero entries (the local nnz)
unsigned long nindex5() const
Return the range of index 5 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.
Class of matrices containing doubles, and stored as a DenseMatrix<double>, but with solving functiona...
unsigned long ncol() const
Return the number of columns of the matrix.
void resize(const unsigned long &n)
Resize to a square nxnxn tensor.
void broken_copy(const std::string &class_name)
Issue error message and terminate execution.
int * row_start()
Access to C-style row_start array.
unsigned long nrow() const
Return the number of rows of the matrix.
const unsigned & distributed_matrix_matrix_multiply_method() const
Read only access function (const version) to Distributed_matrix_matrix_multiply_method, the flag which determines the matrix matrix multiplication method used for distributed matrices. Method 1: Trilinos Epetra Matrix Matrix multiply. Method 2: Trilinos Epetra Matrix Matrix multiply (ML based).
void initialise(const T &val)
Initialize all values in the matrix to val.
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 ~DoubleMatrixBase()
virtual (empty) destructor
bool Built
Flag to indicate whether the matrix has been built - i.e. the distribution has been setup AND the mat...
unsigned Serial_matrix_matrix_multiply_method
Flag to determine which matrix-matrix multiplication method is used (for serial (or global) matrices)...
void clean_up_memory()
Wipe matrix data and set all values to 0.
int * Column_start
Start index for column.
T * Tensordata
Private internal representation as pointer to data.
const int * row_index() const
Access to C-style row index array (const version)
void initialise(const T &val)
Initialise all values in the tensor to val.
double inf_norm(const DenseMatrix< CRDoubleMatrix *> &matrix_pt)
Compute infinity (maximum) norm of sub blocks as if it was one matrix.
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)
void operator=(const SparseMatrix &)
Broken assignment operator.
unsigned long ncol() const
Return the number of columns of the matrix.
LinearSolver * Default_linear_solver_pt
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.
bool built() const
access function to the Built flag - indicates whether the matrix has been build - i...
unsigned & distributed_matrix_matrix_multiply_method()
Access function to Distributed_matrix_matrix_multiply_method, the flag which determines the matrix ma...
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...
unsigned long nrow() const
Return the number of rows of the matrix.
RankFiveTensor()
Empty constructor.
double * values_pt()
access function to the underlying values
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...
CRMatrix()
Default constructor.
const int * row_start() const
Access to C-style row_start array (const version)
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...
void initialise(const T &val)
Initialise all values in the tensor to val.
int * row_index()
Access to C-style row index array.
Matrix(const Matrix &matrix)
Broken copy 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...
DenseMatrix()
Empty constructor, simply assign the lengths N and M to 0.
unsigned P
3rd Tensor dimension
T * Tensordata
Private internal representation as pointer to data.
unsigned long N
Number of rows.
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. Specify filename. This uses acual global row numbers.
virtual ~CCMatrix()
Destructor, delete any allocated memory.
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.
const int * column_start() const
Access to C-style column_start array (const version)
void resize(const unsigned long &n)
Resize to a square nxnxnxn tensor.
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 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...
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 multiply(const CRDoubleMatrix *matrix, const DoubleVector &x, DoubleVector &soln)
Function to perform a matrix-vector multiplication on a oomph-lib matrix and vector using Trilinos fu...
double operator()(const unsigned long &i, const unsigned long &j) const
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 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...
unsigned first_row() const
access function for the first row on this processor. If not distributed then this is just zero...
void operator=(const DoubleMatrixBase &)
Broken assignment operator.
T * Tensordata
Private internal representation as pointer to data.
. SuperLU Project Solver class. This is a combined wrapper for both SuperLU and SuperLU Dist...
SparseMatrix(const SparseMatrix &source_matrix)
Copy 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...
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...
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)
unsigned long ncol() const
Return the number of columns of the matrix.
RankFourTensor(const RankFourTensor &source_tensor)
Copy constructor: Deep copy.
const int * column_index() const
Access to C-style column index array (const version)
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...
double * value()
Access to C-style value array.
LinearSolver * Linear_solver_pt
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...
unsigned long nnz() const
Return the number of nonzero entries.
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...
unsigned Distributed_matrix_matrix_multiply_method
Flag to determine which matrix-matrix multiplication method is used (for distributed matrices) ...
unsigned long nindex2() const
Return the range of index 2 of the tensor.
int * Row_index
Row index.
void concatenate_without_communication(const Vector< DoubleVector *> &in_vector_pt, DoubleVector &out_vector)
Concatenate DoubleVectors. Takes a Vector of DoubleVectors. If the out vector is built, we will not build a new distribution. Otherwise a new distribution will be built using LinearAlgebraDistribution::concatenate(...).
const unsigned & serial_matrix_matrix_multiply_method() const
Read only access function (const version) to Serial_matrix_matrix_multiply_method, the flag which determines the matrix matrix multiplication method used for serial matrices. Method 1: First runs through this matrix and matrix_in to find the storage requirements for result - arrays of the correct size are then allocated before performing the calculation. Minimises memory requirements but more costly. Method 2: Grows storage for values and column indices of result 'on the fly' using an array of maps. Faster but more memory intensive. Method 3: Grows storage for values and column indices of result 'on the fly' using a vector of vectors. Not particularly impressive on the platforms we tried... Method 4: Trilinos Epetra Matrix Matrix multiply. Method 5: Trilinos Epetra Matrix Matrix multiply (ML based).
unsigned N
1st Tensor dimension
unsigned long nindex2() const
Return the range of index 2 of the tensor.
unsigned Q
4th Tensor dimension
CCMatrix()
Default constructor.
unsigned long nindex3() const
Return the range of index 3 of the tensor.
unsigned long nindex3() const
Return the range of index 3 of the tensor.
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 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...
unsigned P
3rd Tensor dimension
int * Row_start
Start index for row.
CCDoubleMatrix(const CCDoubleMatrix &matrix)
Broken copy constructor.
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 operator=(const CRDoubleMatrix &)
Broken assignment operator.
T & raw_direct_access(const unsigned long &i)
Direct access to internal storage of data in flat-packed C-style column-major format. WARNING: Only for experienced users. Only use this if raw speed is of the essence, as in the solid mechanics problems.
virtual unsigned long nrow() const =0
Return the number of rows of the matrix.
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)
CRMatrix< double > CR_matrix
Storage for the Matrix in CR Format.
RankThreeTensor()
Empty constructor.
LinearSolver *& linear_solver_pt()
Return a pointer to the linear solver object.
Describes the distribution of a distributable linear algebra type object. Typically this is a contain...
virtual ~DenseMatrix()
Destructor, clean up the matrix data.
Dense LU decomposition-based solve of full assembled linear system. VERY inefficient but useful to il...
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...
double Zero
Static variable to hold the default value for the pseudo-solid's inertia parameter Lambda^2...
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.
Base class for any linear algebra object that is distributable. Just contains storage for the LinearA...
virtual ~RankFourTensor()
Destructor: delete the pointers.
RankThreeTensor(const unsigned long &n)
One parameter constructor produces a cubic nxnxn tensor.
virtual void residual(const DoubleVector &x, const DoubleVector &b, DoubleVector &residual_)
Find the residual, i.e. r=b-Ax the residual.
T & raw_direct_access(const unsigned long &i)
Direct access to internal storage of data in flat-packed C-style column-major format. WARNING: Only for experienced users. Only use this if raw speed is of the essence, as in the solid mechanics problems.
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 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...
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...
A class for compressed column matrices: a sparse matrix format The class is passed as the MATRIX_TYPE...
const int * row_start() const
Access to C-style row_start array (const version)
unsigned N
1st Tensor dimension
unsigned & matrix_matrix_multiply_method()
Access function to Matrix_matrix_multiply_method, the flag which determines the matrix matrix multipl...
void operator=(const Matrix &)
Broken assignment operator.
unsigned long nindex4() const
Return the range of index 4 of the tensor.
RankThreeTensor & operator=(const RankThreeTensor &source_tensor)
Copy assignement.
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...
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...
void resize(const unsigned long &n_index1, const unsigned long &n_index2, const unsigned long &n_index3, const unsigned long &n_index4, const unsigned long &n_index5)
Resize to a general tensor.
unsigned long M
Number of columns.
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...
RankFiveTensor(const RankFiveTensor &source_tensor)
Copy constructor: Deep copy.
unsigned N
1st Tensor dimension
RankFourTensor()
Empty constructor.
void output(std::ostream &outfile) const
Output function to print a matrix row-by-row to the stream outfile.
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...
CRMatrix(const CRMatrix &source_matrix)
Copy constructor.
unsigned long nindex2() const
Return the range of index 2 of the tensor.
unsigned M
2nd Tensor dimension
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 long nindex3() const
Return the range of index 3 of the tensor.
unsigned long nindex1() const
Return the range of index 1 of the tensor.
virtual ~CRMatrix()
Destructor, delete any allocated memory.
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...
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.
unsigned R
5th Tensor dimension
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. WARNING: Only for experienced users. Only use this if raw speed is of the essence, as in the solid mechanics problems.
Matrix()
(Empty) constructor
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 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.
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.
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...
unsigned long nindex1() const
Return the range of index 1 of the tensor.
RankFourTensor & operator=(const RankFourTensor &source_tensor)
Copy assignement.
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 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...
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...
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)
unsigned M
2nd Tensor dimension
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...
virtual ~SparseMatrix()
Destructor, delete the memory associated with the values.
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. WARNING: Only for experienced users. Only use this if raw speed is of the essence, as in the solid mechanics problems.
DoubleMatrixBase(const DoubleMatrixBase &matrix)
Broken copy constructor.
A class for compressed row matrices, a sparse storage format Once again the recursive template trick ...
int * column_index()
Access to C-style column index array.
A class for compressed column matrices that store doubles.
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...
virtual ~RankFiveTensor()
Destructor: delete the pointers.
void resize(const unsigned long &n)
Resize to a square nxnxnxn tensor.
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...
unsigned long nrow() const
Return the number of rows of the matrix.
SparseMatrix()
Default constructor.
const T * value() const
Access to C-style value array (const version)
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_index1, const unsigned long &n_index2, const unsigned long &n_index3, const unsigned long &n_index4)
Resize to a general tensor.
void broken_assign(const std::string &class_name)
Issue error message and terminate execution.
unsigned nrow() const
access function to the number of global rows.
unsigned Q
4th Tensor dimension
Abstract base class for matrices, templated by the type of object that is stored in them and the type...
T operator()(const unsigned long &i, const unsigned long &j, const unsigned long &k, const unsigned long &l) const
Overload a const version for read-only access as a(i,j,k,l)
void initialise(const T &val)
Initialise all values in the tensor to val.
virtual unsigned long ncol() const =0
Return the number of columns of the matrix.
DenseDoubleMatrix(const DenseDoubleMatrix &matrix)
Broken copy constructor.
RankThreeTensor(const RankThreeTensor &source_tensor)
Copy constructor: Deep copy.
void operator=(const CCMatrix &)
Broken assignment operator.
DoubleMatrixBase()
(Empty) constructor.
std::string string(const unsigned &i)
Return the i-th string or "" if the relevant string hasn't been defined.
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.
RankThreeTensor(const unsigned long &n_index1, const unsigned long &n_index2, const unsigned long &n_index3)
Three parameter constructor, general non-square tensor.
const double * value() const
Access to C-style value array (const version)
unsigned long ncol() const
Return the number of columns of the matrix.
unsigned long M
Number of columns.
T * Value
Internal representation of the matrix values, a pointer.
DenseMatrix & operator=(const DenseMatrix &source_matrix)
Copy assignment.
void operator=(const CRMatrix &)
Broken assignment operator.
unsigned nrow_local() const
access function for the num of local rows on this processor.
Class for dense matrices, storing all the values of the matrix as a pointer to a pointer with assorte...
void concatenate(const Vector< DoubleVector *> &in_vector_pt, DoubleVector &out_vector)
Concatenate DoubleVectors. Takes a Vector of DoubleVectors. If the out vector is built, we will not build a new distribution. Otherwise we build a uniform distribution.
void resize(const unsigned long &n_index1, const unsigned long &n_index2, const unsigned long &n_index3)
Resize to a general tensor.
int * column_start()
Access to C-style column_start array.
LinearSolver *const & linear_solver_pt() const
Return a pointer to the linear solver object (const version)
unsigned & serial_matrix_matrix_multiply_method()
Access function to Serial_matrix_matrix_multiply_method, the flag which determines the matrix matrix ...
A vector in the mathematical sense, initially developed for linear algebra type applications. If MPI then this vector can be distributed - its distribution is described by the LinearAlgebraDistribution object at Distribution_pt. Data is stored in a C-style pointer vector (double*)
unsigned long nrow() const
Return the number of rows of the matrix.
T * Matrixdata
Internal representation of matrix as a pointer to data.
T & entry(const unsigned long &i, const unsigned long &j)
void indexed_output(std::ostream &outfile) const
Indexed output function to print a matrix to the stream outfile as i,j,a(i,j)
int * row_start()
Access to C-style row_start array.
void operator=(const DenseDoubleMatrix &)
Broken assignment operator.
RankFiveTensor & operator=(const RankFiveTensor &source_tensor)
Copy assignement.
RankFiveTensor(const unsigned long &n)
One parameter constructor produces a nxnxnxnxn tensor.
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.
Abstract base class for matrices of doubles – adds abstract interfaces for solving, LU decomposition and multiplication by vectors.
void clean_up_memory()
Wipe matrix data and set all values to 0.
unsigned Matrix_matrix_multiply_method
Flag to determine which matrix-matrix multiplication method is used.
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 w...
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...
A class for compressed row matrices. This is a distributable object.
virtual ~Matrix()
Virtual (empty) destructor.
Create a struct to provide a comparison function for std::sort.
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 ...
LinearAlgebraDistribution * distribution_pt() const
access to the LinearAlgebraDistribution
CCMatrix(const CCMatrix &source_matrix)
Copy constructor.
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...
unsigned P
3rd Tensor dimension
int * Column_index
Column index.
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...
unsigned long nindex1() const
Return the range of index 1 of the tensor.
T * value()
Access to C-style value array.
RankFourTensor(const unsigned long &n)
One parameter constructor produces a nxnxnxn tensor.
unsigned long nrow() const
Return the number of rows of the matrix.
unsigned long Nnz
Number of non-zero values (i.e. size of Value array)
unsigned long nindex4() const
Return the range of index 4 of the tensor.
T & entry(const unsigned long &i, const unsigned long &j)
The read-write access function is deliberately broken.
unsigned M
2nd Tensor dimension
double max() const
returns the maximum coefficient
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 ...
const int * column_index() const
Access to C-style column index array (const version)
DenseMatrix(const DenseMatrix &source_matrix)
Copy constructor: Deep copy!
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...
An oomph-lib wrapper to the MPI_Comm communicator object. Just contains an MPI_Comm object (which is ...
void resize(const unsigned long &n)