oomph::CCDoubleMatrix Class Reference

A class for compressed column matrices that store doubles. More...

#include <matrices.h>

+ Inheritance diagram for oomph::CCDoubleMatrix:

Public Member Functions

 CCDoubleMatrix ()
 Default constructor. More...
 
 CCDoubleMatrix (const Vector< double > &value, const Vector< int > &row_index_, const Vector< int > &column_start_, const unsigned long &n, const unsigned long &m)
 
 CCDoubleMatrix (const CCDoubleMatrix &matrix)=delete
 Broken copy constructor. More...
 
void operator= (const CCDoubleMatrix &)=delete
 Broken assignment operator. More...
 
virtual ~CCDoubleMatrix ()
 Destructor: Kill the LU factors if they have been setup. More...
 
unsigned long nrow () const
 Return the number of rows of the matrix. More...
 
unsigned long ncol () const
 Return the number of columns of the matrix. More...
 
double operator() (const unsigned long &i, const unsigned long &j) const
 
virtual void ludecompose ()
 LU decomposition using SuperLU. More...
 
virtual void lubksub (DoubleVector &rhs)
 LU back solve for given RHS. More...
 
void multiply (const DoubleVector &x, DoubleVector &soln) const
 Multiply the matrix by the vector x: soln=Ax. More...
 
void multiply_transpose (const DoubleVector &x, DoubleVector &soln) const
 Multiply the transposed matrix by the vector x: soln=A^T x. More...
 
void multiply (const CCDoubleMatrix &matrix_in, CCDoubleMatrix &result)
 
void matrix_reduction (const double &alpha, CCDoubleMatrix &reduced_matrix)
 
unsignedmatrix_matrix_multiply_method ()
 
- Public Member Functions inherited from oomph::DoubleMatrixBase
 DoubleMatrixBase ()
 (Empty) constructor. More...
 
 DoubleMatrixBase (const DoubleMatrixBase &matrix)=delete
 Broken copy constructor. More...
 
void operator= (const DoubleMatrixBase &)=delete
 Broken assignment operator. More...
 
virtual ~DoubleMatrixBase ()
 virtual (empty) destructor More...
 
LinearSolver *& linear_solver_pt ()
 Return a pointer to the linear solver object. More...
 
LinearSolver *const & linear_solver_pt () const
 Return a pointer to the linear solver object (const version) More...
 
void solve (DoubleVector &rhs)
 
void solve (const DoubleVector &rhs, DoubleVector &soln)
 
void solve (Vector< double > &rhs)
 
void solve (const Vector< double > &rhs, Vector< double > &soln)
 
virtual void residual (const DoubleVector &x, const DoubleVector &b, DoubleVector &residual_)
 Find the residual, i.e. r=b-Ax the residual. More...
 
virtual double max_residual (const DoubleVector &x, const DoubleVector &rhs)
 
- Public Member Functions inherited from oomph::CCMatrix< double >
 CCMatrix ()
 Default constructor. More...
 
 CCMatrix (const Vector< double > &value, const Vector< int > &row_index_, const Vector< int > &column_start_, const unsigned long &n, const unsigned long &m)
 
 CCMatrix (const CCMatrix &source_matrix)
 Copy constructor. More...
 
void operator= (const CCMatrix &)=delete
 Broken assignment operator. More...
 
virtual ~CCMatrix ()
 Destructor, delete any allocated memory. More...
 
double get_entry (const unsigned long &i, const unsigned long &j) const
 
doubleentry (const unsigned long &i, const unsigned long &j)
 
intcolumn_start ()
 Access to C-style column_start array. More...
 
const intcolumn_start () const
 Access to C-style column_start array (const version) More...
 
introw_index ()
 Access to C-style row index array. More...
 
const introw_index () const
 Access to C-style row index array (const version) More...
 
void output_bottom_right_zero_helper (std::ostream &outfile) const
 
void sparse_indexed_output_helper (std::ostream &outfile) const
 
void clean_up_memory ()
 Wipe matrix data and set all values to 0. More...
 
void build (const Vector< double > &value, const Vector< int > &row_index, const Vector< int > &column_start, const unsigned long &n, const unsigned long &m)
 
void build_without_copy (double *value, int *row_index, int *column_start, const unsigned long &nnz, const unsigned long &n, const unsigned long &m)
 
- Public Member Functions inherited from oomph::SparseMatrix< T, MATRIX_TYPE >
 SparseMatrix ()
 Default constructor. More...
 
 SparseMatrix (const SparseMatrix &source_matrix)
 Copy constructor. More...
 
void operator= (const SparseMatrix &)=delete
 Broken assignment operator. More...
 
virtual ~SparseMatrix ()
 Destructor, delete the memory associated with the values. More...
 
Tvalue ()
 Access to C-style value array. More...
 
const Tvalue () const
 Access to C-style value array (const version) More...
 
unsigned long nnz () const
 Return the number of nonzero entries. More...
 
- Public Member Functions inherited from oomph::Matrix< T, MATRIX_TYPE >
 Matrix ()
 (Empty) constructor More...
 
 Matrix (const Matrix &matrix)=delete
 Broken copy constructor. More...
 
void operator= (const Matrix &)=delete
 Broken assignment operator. More...
 
virtual ~Matrix ()
 Virtual (empty) destructor. More...
 
T operator() (const unsigned long &i, const unsigned long &j) const
 
Toperator() (const unsigned long &i, const unsigned long &j)
 
virtual void output (std::ostream &outfile) const
 
void sparse_indexed_output (std::ostream &outfile, const unsigned &precision=0, const bool &output_bottom_right_zero=false) const
 
void sparse_indexed_output (std::string filename, const unsigned &precision=0, const bool &output_bottom_right_zero=false) const
 

Private Attributes

unsigned Matrix_matrix_multiply_method
 Flag to determine which matrix-matrix multiplication method is used. More...
 

Additional Inherited Members

- Protected Member Functions inherited from oomph::Matrix< T, MATRIX_TYPE >
void range_check (const unsigned long &i, const unsigned long &j) const
 
- Protected Attributes inherited from oomph::DoubleMatrixBase
LinearSolverLinear_solver_pt
 
LinearSolverDefault_linear_solver_pt
 
- Protected Attributes inherited from oomph::CCMatrix< double >
intRow_index
 Row index. More...
 
intColumn_start
 Start index for column. More...
 
- Protected Attributes inherited from oomph::SparseMatrix< T, MATRIX_TYPE >
TValue
 Internal representation of the matrix values, a pointer. More...
 
unsigned long N
 Number of rows. More...
 
unsigned long M
 Number of columns. More...
 
unsigned long Nnz
 Number of non-zero values (i.e. size of Value array) More...
 
- Static Protected Attributes inherited from oomph::SparseMatrix< T, MATRIX_TYPE >
static T Zero = T(0)
 Dummy zero. More...
 

Detailed Description

A class for compressed column matrices that store doubles.

//////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////

Constructor & Destructor Documentation

◆ CCDoubleMatrix() [1/3]

oomph::CCDoubleMatrix::CCDoubleMatrix ( )

Default constructor.

//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// Default constructor, set the default linear solver and matrix-matrix multiplication method.

572  : CCMatrix<double>()
573  {
574  Linear_solver_pt = Default_linear_solver_pt = new SuperLUSolver;
576  }
unsigned Matrix_matrix_multiply_method
Flag to determine which matrix-matrix multiplication method is used.
Definition: matrices.h:2893
LinearSolver * Default_linear_solver_pt
Definition: matrices.h:267
LinearSolver * Linear_solver_pt
Definition: matrices.h:264

References oomph::DoubleMatrixBase::Default_linear_solver_pt, oomph::DoubleMatrixBase::Linear_solver_pt, and Matrix_matrix_multiply_method.

◆ CCDoubleMatrix() [2/3]

oomph::CCDoubleMatrix::CCDoubleMatrix ( const Vector< double > &  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 (can be suppressed for square matrices). Number of nonzero entries is read off from value, so make sure the vector has been shrunk to its correct length.

590  : CCMatrix<double>(value, row_index, column_start, n, m)
591  {
592  Linear_solver_pt = Default_linear_solver_pt = new SuperLUSolver;
594  }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
int * column_start()
Access to C-style column_start array.
Definition: matrices.h:2692
int * row_index()
Access to C-style row index array.
Definition: matrices.h:2704
T * value()
Access to C-style value array.
Definition: matrices.h:616
int * m
Definition: level2_cplx_impl.h:294

References oomph::DoubleMatrixBase::Default_linear_solver_pt, oomph::DoubleMatrixBase::Linear_solver_pt, and Matrix_matrix_multiply_method.

◆ CCDoubleMatrix() [3/3]

oomph::CCDoubleMatrix::CCDoubleMatrix ( const CCDoubleMatrix matrix)
delete

Broken copy constructor.

◆ ~CCDoubleMatrix()

oomph::CCDoubleMatrix::~CCDoubleMatrix ( )
virtual

Destructor: Kill the LU factors if they have been setup.

Destructor: delete the default linear solver.

598  {
600  }

References oomph::DoubleMatrixBase::Default_linear_solver_pt.

Member Function Documentation

◆ lubksub()

void oomph::CCDoubleMatrix::lubksub ( DoubleVector rhs)
virtual

LU back solve for given RHS.

Do the backsubstitution.

615  {
616  static_cast<SuperLUSolver*>(Default_linear_solver_pt)->backsub(rhs, rhs);
617  }

References oomph::DoubleMatrixBase::Default_linear_solver_pt.

◆ ludecompose()

void oomph::CCDoubleMatrix::ludecompose ( )
virtual

LU decomposition using SuperLU.

Perform LU decomposition. Return the sign of the determinant.

607  {
608  static_cast<SuperLUSolver*>(Default_linear_solver_pt)->factorise(this);
609  }

References oomph::DoubleMatrixBase::Default_linear_solver_pt.

◆ matrix_matrix_multiply_method()

unsigned& oomph::CCDoubleMatrix::matrix_matrix_multiply_method ( )
inline

Access function to Matrix_matrix_multiply_method, the flag which determines the matrix matrix multiplication method used. 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...

2887  {
2889  }

References Matrix_matrix_multiply_method.

Referenced by main().

◆ matrix_reduction()

void oomph::CCDoubleMatrix::matrix_reduction ( const double alpha,
CCDoubleMatrix reduced_matrix 
)

For every row, find the maximum absolute value of the entries in this row. Set all values that are less than alpha times this maximum to zero and return the resulting matrix in reduced_matrix. Note: Diagonal entries are retained regardless of their size.

1151  {
1152  // number of columns in matrix
1153  long n_coln = ncol();
1154 
1155  Vector<double> max_row(nrow(), 0.0);
1156 
1157  // Here's the packed format for the new matrix
1158  Vector<int> B_row_start(1);
1159  Vector<int> B_column_index;
1160  Vector<double> B_value;
1161 
1162 
1163  // k is counter for the number of entries in the reduced matrix
1164  unsigned k = 0;
1165 
1166  // Initialise row start
1167  B_row_start[0] = 0;
1168 
1169  // Loop over columns
1170  for (long i = 0; i < n_coln; i++)
1171  {
1172  // Loop over entries in columns
1173  for (long j = Column_start[i]; j < Column_start[i + 1]; j++)
1174  {
1175  // Find max. value in row
1176  if (std::fabs(Value[j]) > max_row[Row_index[j]])
1177  {
1178  max_row[Row_index[j]] = std::fabs(Value[j]);
1179  }
1180  }
1181 
1182  // Decide if we need to retain the entries in the row
1183  for (long j = Column_start[i]; j < Column_start[i + 1]; j++)
1184  {
1185  // If we're on the diagonal or the value is sufficiently large: retain
1186  // i.e. copy across.
1187  if (i == Row_index[j] ||
1188  std::fabs(Value[j]) > alpha * max_row[Row_index[j]])
1189  {
1190  B_value.push_back(Value[j]);
1191  B_column_index.push_back(Row_index[j]);
1192  k++;
1193  }
1194  }
1195  // This writes the row start for the next row -- equal to
1196  // to the number of entries written so far (C++ zero-based indexing!)
1197  B_row_start.push_back(k);
1198  }
1199 
1200 
1201  // Build the matrix from the compressed format
1202  dynamic_cast<CCDoubleMatrix&>(reduced_matrix)
1203  .build(B_value, B_column_index, B_row_start, nrow(), ncol());
1204  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
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
int * Column_start
Start index for column.
Definition: matrices.h:2779
int * Row_index
Row index.
Definition: matrices.h:2776
void build(const Vector< double > &value, const Vector< int > &row_index, const Vector< int > &column_start, const unsigned long &n, const unsigned long &m)
Definition: matrices.h:3247
T * Value
Internal representation of the matrix values, a pointer.
Definition: matrices.h:565
RealScalar alpha
Definition: level1_cplx_impl.h:151
char char char int int * k
Definition: level2_impl.h:374
Real fabs(const Real &a)
Definition: boostmultiprec.cpp:117
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References alpha, oomph::CCMatrix< double >::build(), oomph::CCMatrix< double >::Column_start, boost::multiprecision::fabs(), i, j, k, ncol(), nrow(), oomph::CCMatrix< double >::Row_index, and oomph::SparseMatrix< T, MATRIX_TYPE >::Value.

◆ multiply() [1/2]

void oomph::CCDoubleMatrix::multiply ( const CCDoubleMatrix matrix_in,
CCDoubleMatrix result 
)

Function to multiply this matrix by the CCDoubleMatrix matrix_in The multiplication method used can be selected using the flag Matrix_matrix_multiply_method. By default Method 2 is used. 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...

823  {
824 #ifdef PARANOID
825  // check matrix dimensions are compatible
826  if (this->ncol() != matrix_in.nrow())
827  {
828  std::ostringstream error_message;
829  error_message
830  << "Matrix dimensions incompatable for matrix-matrix multiplication"
831  << "ncol() for first matrix:" << this->ncol()
832  << "nrow() for second matrix: " << matrix_in.nrow();
833 
834  throw OomphLibError(
835  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
836  }
837 #endif
838 
839  // NB N is number of rows!
840  unsigned long N = this->nrow();
841  unsigned long M = matrix_in.ncol();
842  unsigned long Nnz = 0;
843 
844  // pointers to arrays which store result
845  int* Column_start;
846  double* Value;
847  int* Row_index;
848 
849  // get pointers to matrix_in
850  const int* matrix_in_col_start = matrix_in.column_start();
851  const int* matrix_in_row_index = matrix_in.row_index();
852  const double* matrix_in_value = matrix_in.value();
853 
854  // get pointers to this matrix
855  const double* this_value = this->value();
856  const int* this_col_start = this->column_start();
857  const int* this_row_index = this->row_index();
858 
859  // set method
860  unsigned method = Matrix_matrix_multiply_method;
861 
862  // clock_t clock1 = clock();
863 
864  // METHOD 1
865  // --------
866  if (method == 1)
867  {
868  // allocate storage for column starts
869  Column_start = new int[M + 1];
870  Column_start[0] = 0;
871 
872  // a set to store number of non-zero rows in each column of result
873  std::set<unsigned> rows;
874 
875  // run through columns of this matrix and matrix_in to find number of
876  // non-zero entries in each column of result
877  for (unsigned long this_col = 0; this_col < M; this_col++)
878  {
879  // run through non-zeros in this_col of this matrix
880  for (int this_ptr = this_col_start[this_col];
881  this_ptr < this_col_start[this_col + 1];
882  this_ptr++)
883  {
884  // find row index for non-zero
885  unsigned matrix_in_col = this_row_index[this_ptr];
886 
887  // run through corresponding column in matrix_in
888  for (int matrix_in_ptr = matrix_in_col_start[matrix_in_col];
889  matrix_in_ptr < matrix_in_col_start[matrix_in_col + 1];
890  matrix_in_ptr++)
891  {
892  // find row index for non-zero in matrix_in and store in rows
893  rows.insert(matrix_in_row_index[matrix_in_ptr]);
894  }
895  }
896  // update Column_start
897  Column_start[this_col + 1] = Column_start[this_col] + rows.size();
898 
899  // wipe values in rows
900  rows.clear();
901  }
902 
903  // set Nnz
904  Nnz = Column_start[M];
905 
906  // allocate arrays for result
907  Value = new double[Nnz];
908  Row_index = new int[Nnz];
909 
910  // set all values of Row_index to -1
911  for (unsigned long i = 0; i < Nnz; i++) Row_index[i] = -1;
912 
913  // Calculate values for result - first run through columns of this matrix
914  for (unsigned long this_col = 0; this_col < M; this_col++)
915  {
916  // run through non-zeros in this_column
917  for (int this_ptr = this_col_start[this_col];
918  this_ptr < this_col_start[this_col + 1];
919  this_ptr++)
920  {
921  // find value of non-zero
922  double this_val = this_value[this_ptr];
923 
924  // find row associated with non-zero
925  unsigned matrix_in_col = this_row_index[this_ptr];
926 
927  // run through corresponding column in matrix_in
928  for (int matrix_in_ptr = matrix_in_col_start[matrix_in_col];
929  matrix_in_ptr < matrix_in_col_start[matrix_in_col + 1];
930  matrix_in_ptr++)
931  {
932  // find row index for non-zero in matrix_in
933  int row = matrix_in_row_index[matrix_in_ptr];
934 
935  // find position in result to insert value
936  for (int ptr = Column_start[this_col];
937  ptr <= Column_start[this_col + 1];
938  ptr++)
939  {
940  if (ptr == Column_start[this_col + 1])
941  {
942  // error - have passed end of column without finding
943  // correct row index
944  std::ostringstream error_message;
945  error_message << "Error inserting value in result";
946 
947  throw OomphLibError(error_message.str(),
950  }
951  else if (Row_index[ptr] == -1)
952  {
953  // first entry for this row index
954  Row_index[ptr] = row;
955  Value[ptr] = this_val * matrix_in_value[matrix_in_ptr];
956  break;
957  }
958  else if (Row_index[ptr] == row)
959  {
960  // row index already exists - add value
961  Value[ptr] += this_val * matrix_in_value[matrix_in_ptr];
962  break;
963  }
964  }
965  }
966  }
967  }
968  }
969 
970  // METHOD 2
971  // --------
972  else if (method == 2)
973  {
974  // generate array of maps to store values for result
975  std::map<int, double>* result_maps = new std::map<int, double>[M];
976 
977  // run through columns of this matrix
978  for (unsigned long this_col = 0; this_col < M; this_col++)
979  {
980  // run through non-zeros in this_col
981  for (int this_ptr = this_col_start[this_col];
982  this_ptr < this_col_start[this_col + 1];
983  this_ptr++)
984  {
985  // find value of non-zero
986  double this_val = this_value[this_ptr];
987 
988  // find row index associated with non-zero
989  unsigned matrix_in_col = this_row_index[this_ptr];
990 
991  // run through corresponding column in matrix_in
992  for (int matrix_in_ptr = matrix_in_col_start[matrix_in_col];
993  matrix_in_ptr < matrix_in_col_start[matrix_in_col + 1];
994  matrix_in_ptr++)
995  {
996  // find row index for non-zero in matrix_in
997  int row = matrix_in_row_index[matrix_in_ptr];
998 
999  // insert value
1000  result_maps[this_col][row] +=
1001  this_val * matrix_in_value[matrix_in_ptr];
1002  }
1003  }
1004  }
1005 
1006  // allocate Column_start
1007  Column_start = new int[M + 1];
1008 
1009  // copy across column starts
1010  Column_start[0] = 0;
1011  for (unsigned long col = 0; col < M; col++)
1012  {
1013  int size = result_maps[col].size();
1014  Column_start[col + 1] = Column_start[col] + size;
1015  }
1016 
1017  // set Nnz
1018  Nnz = Column_start[M];
1019 
1020  // allocate other arrays
1021  Value = new double[Nnz];
1022  Row_index = new int[Nnz];
1023 
1024  // copy values and row indices
1025  for (unsigned long col = 0; col < M; col++)
1026  {
1027  unsigned ptr = Column_start[col];
1028  for (std::map<int, double>::iterator i = result_maps[col].begin();
1029  i != result_maps[col].end();
1030  i++)
1031  {
1032  Row_index[ptr] = i->first;
1033  Value[ptr] = i->second;
1034  ptr++;
1035  }
1036  }
1037 
1038  // tidy up memory
1039  delete[] result_maps;
1040  }
1041 
1042  // METHOD 3
1043  // --------
1044  else if (method == 3)
1045  {
1046  // vectors of vectors to store results
1047  std::vector<std::vector<int>> result_rows(N);
1048  std::vector<std::vector<double>> result_vals(N);
1049 
1050  // run through the columns of this matrix
1051  for (unsigned long this_col = 0; this_col < M; this_col++)
1052  {
1053  // run through non-zeros in this_col
1054  for (int this_ptr = this_col_start[this_col];
1055  this_ptr < this_col_start[this_col + 1];
1056  this_ptr++)
1057  {
1058  // find value of non-zero
1059  double this_val = this_value[this_ptr];
1060 
1061  // find row index associated with non-zero
1062  unsigned matrix_in_col = this_row_index[this_ptr];
1063 
1064  // run through corresponding column in matrix_in
1065  for (int matrix_in_ptr = matrix_in_col_start[matrix_in_col];
1066  matrix_in_ptr < matrix_in_col_start[matrix_in_col + 1];
1067  matrix_in_ptr++)
1068  {
1069  // find row index for non-zero in matrix_in
1070  int row = matrix_in_row_index[matrix_in_ptr];
1071 
1072  // insert value
1073  int size = result_rows[this_col].size();
1074  for (int i = 0; i <= size; i++)
1075  {
1076  if (i == size)
1077  {
1078  // first entry for this row index
1079  result_rows[this_col].push_back(row);
1080  result_vals[this_col].push_back(this_val *
1081  matrix_in_value[matrix_in_ptr]);
1082  }
1083  else if (row == result_rows[this_col][i])
1084  {
1085  // row index already exists
1086  result_vals[this_col][i] +=
1087  this_val * matrix_in_value[matrix_in_ptr];
1088  break;
1089  }
1090  }
1091  }
1092  }
1093  }
1094 
1095  // allocate Column_start
1096  Column_start = new int[M + 1];
1097 
1098  // copy across column starts
1099  Column_start[0] = 0;
1100  for (unsigned long col = 0; col < M; col++)
1101  {
1102  int size = result_rows[col].size();
1103  Column_start[col + 1] = Column_start[col] + size;
1104  }
1105 
1106  // set Nnz
1107  Nnz = Column_start[M];
1108 
1109  // allocate other arrays
1110  Value = new double[Nnz];
1111  Row_index = new int[Nnz];
1112 
1113  // copy across values and row indices
1114  for (unsigned long col = 0; col < N; col++)
1115  {
1116  unsigned ptr = Column_start[col];
1117  unsigned n_rows = result_rows[col].size();
1118  for (unsigned i = 0; i < n_rows; i++)
1119  {
1120  Row_index[ptr] = result_rows[col][i];
1121  Value[ptr] = result_vals[col][i];
1122  ptr++;
1123  }
1124  }
1125  }
1126 
1127  // INCORRECT VALUE FOR METHOD
1128  else
1129  {
1130  std::ostringstream error_message;
1131  error_message << "Incorrect method set in matrix-matrix multiply"
1132  << "method=" << method << " not allowed";
1133 
1134  throw OomphLibError(
1135  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
1136  }
1137 
1138  result.build_without_copy(Value, Row_index, Column_start, Nnz, N, M);
1139  }
m col(1)
m row(1)
int rows
Definition: Tutorial_commainit_02.cpp:1
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
unsigned long Nnz
Number of non-zero values (i.e. size of Value array)
Definition: matrices.h:574
unsigned long N
Number of rows.
Definition: matrices.h:568
unsigned long M
Number of columns.
Definition: matrices.h:571
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References oomph::CCMatrix< T >::build_without_copy(), col(), oomph::CCMatrix< double >::column_start(), oomph::CCMatrix< T >::column_start(), oomph::CCMatrix< double >::Column_start, i, oomph::SparseMatrix< T, MATRIX_TYPE >::M, Matrix_matrix_multiply_method, oomph::SparseMatrix< T, MATRIX_TYPE >::N, ncol(), oomph::SparseMatrix< T, MATRIX_TYPE >::Nnz, nrow(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, row(), oomph::CCMatrix< T >::row_index(), oomph::CCMatrix< double >::row_index(), oomph::CCMatrix< double >::Row_index, rows, size, oomph::SparseMatrix< T, MATRIX_TYPE >::Value, and oomph::SparseMatrix< T, MATRIX_TYPE >::value().

◆ multiply() [2/2]

void oomph::CCDoubleMatrix::multiply ( const DoubleVector x,
DoubleVector soln 
) const
virtual

Multiply the matrix by the vector x: soln=Ax.

Multiply the matrix by the vector x.

Implements oomph::DoubleMatrixBase.

623  {
624 #ifdef PARANOID
625  // Check to see if x.size() = ncol().
626  if (x.nrow() != this->ncol())
627  {
628  std::ostringstream error_message_stream;
629  error_message_stream << "The x vector is not the right size. It is "
630  << x.nrow() << ", it should be " << this->ncol()
631  << std::endl;
632  throw OomphLibError(error_message_stream.str(),
635  }
636  // check that x is not distributed
637  if (x.distributed())
638  {
639  std::ostringstream error_message_stream;
640  error_message_stream
641  << "The x vector cannot be distributed for CCDoubleMatrix "
642  << "matrix-vector multiply" << std::endl;
643  throw OomphLibError(error_message_stream.str(),
646  }
647  // if soln is setup...
648  if (soln.built())
649  {
650  // check that soln is not distributed
651  if (soln.distributed())
652  {
653  std::ostringstream error_message_stream;
654  error_message_stream
655  << "The x vector cannot be distributed for CCDoubleMatrix "
656  << "matrix-vector multiply" << std::endl;
657  throw OomphLibError(error_message_stream.str(),
660  }
661  if (soln.nrow() != this->nrow())
662  {
663  std::ostringstream error_message_stream;
664  error_message_stream
665  << "The soln vector is setup and therefore must have the same "
666  << "number of rows as the matrix";
667  throw OomphLibError(error_message_stream.str(),
670  }
671  if (*soln.distribution_pt()->communicator_pt() !=
672  *x.distribution_pt()->communicator_pt())
673  {
674  std::ostringstream error_message_stream;
675  error_message_stream
676  << "The soln vector and the x vector must have the same communicator"
677  << std::endl;
678  throw OomphLibError(error_message_stream.str(),
681  }
682  }
683 #endif
684 
685  // if soln is not setup then setup the distribution
686  if (!soln.built())
687  {
688  LinearAlgebraDistribution* dist_pt = new LinearAlgebraDistribution(
689  x.distribution_pt()->communicator_pt(), this->nrow(), false);
690  soln.build(dist_pt, 0.0);
691  delete dist_pt;
692  }
693 
694  // zero
695  soln.initialise(0.0);
696 
697  // multiply
698  double* soln_pt = soln.values_pt();
699  const double* x_pt = x.values_pt();
700  for (unsigned long j = 0; j < N; j++)
701  {
702  for (long k = Column_start[j]; k < Column_start[j + 1]; k++)
703  {
704  unsigned long i = Row_index[k];
705  double a_ij = Value[k];
706  soln_pt[i] += a_ij * x_pt[j];
707  }
708  }
709  }
list x
Definition: plotDoE.py:28

References oomph::DoubleVector::build(), oomph::DoubleVector::built(), oomph::CCMatrix< double >::Column_start, oomph::LinearAlgebraDistribution::communicator_pt(), oomph::DistributableLinearAlgebraObject::distributed(), oomph::DistributableLinearAlgebraObject::distribution_pt(), i, oomph::DoubleVector::initialise(), j, k, oomph::SparseMatrix< T, MATRIX_TYPE >::N, ncol(), oomph::DistributableLinearAlgebraObject::nrow(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, oomph::CCMatrix< double >::Row_index, oomph::SparseMatrix< T, MATRIX_TYPE >::Value, oomph::DoubleVector::values_pt(), and plotDoE::x.

Referenced by main().

◆ multiply_transpose()

void oomph::CCDoubleMatrix::multiply_transpose ( const DoubleVector x,
DoubleVector soln 
) const
virtual

Multiply the transposed matrix by the vector x: soln=A^T x.

Implements oomph::DoubleMatrixBase.

717  {
718 #ifdef PARANOID
719  // Check to see if x.size() = ncol().
720  if (x.nrow() != this->nrow())
721  {
722  std::ostringstream error_message_stream;
723  error_message_stream << "The x vector is not the right size. It is "
724  << x.nrow() << ", it should be " << this->nrow()
725  << std::endl;
726  throw OomphLibError(error_message_stream.str(),
729  }
730  // check that x is not distributed
731  if (x.distributed())
732  {
733  std::ostringstream error_message_stream;
734  error_message_stream
735  << "The x vector cannot be distributed for CCDoubleMatrix "
736  << "matrix-vector multiply" << std::endl;
737  throw OomphLibError(error_message_stream.str(),
740  }
741  // if soln is setup...
742  if (soln.built())
743  {
744  // check that soln is not distributed
745  if (soln.distributed())
746  {
747  std::ostringstream error_message_stream;
748  error_message_stream
749  << "The x vector cannot be distributed for CCDoubleMatrix "
750  << "matrix-vector multiply" << std::endl;
751  throw OomphLibError(error_message_stream.str(),
754  }
755  if (soln.nrow() != this->ncol())
756  {
757  std::ostringstream error_message_stream;
758  error_message_stream
759  << "The soln vector is setup and therefore must have the same "
760  << "number of columns as the matrix";
761  throw OomphLibError(error_message_stream.str(),
764  }
765  if (*soln.distribution_pt()->communicator_pt() !=
766  *x.distribution_pt()->communicator_pt())
767  {
768  std::ostringstream error_message_stream;
769  error_message_stream
770  << "The soln vector and the x vector must have the same communicator"
771  << std::endl;
772  throw OomphLibError(error_message_stream.str(),
775  }
776  }
777 #endif
778 
779  // if soln is not setup then setup the distribution
780  if (!soln.built())
781  {
782  LinearAlgebraDistribution* dist_pt = new LinearAlgebraDistribution(
783  x.distribution_pt()->communicator_pt(), this->ncol(), false);
784  soln.build(dist_pt, 0.0);
785  delete dist_pt;
786  }
787 
788  // zero
789  soln.initialise(0.0);
790 
791  // Matrix vector product
792  double* soln_pt = soln.values_pt();
793  const double* x_pt = x.values_pt();
794  for (unsigned long i = 0; i < N; i++)
795  {
796  for (long k = Column_start[i]; k < Column_start[i + 1]; k++)
797  {
798  unsigned long j = Row_index[k];
799  double a_ij = Value[k];
800  soln_pt[j] += a_ij * x_pt[i];
801  }
802  }
803  }

References oomph::DoubleVector::build(), oomph::DoubleVector::built(), oomph::CCMatrix< double >::Column_start, oomph::LinearAlgebraDistribution::communicator_pt(), oomph::DistributableLinearAlgebraObject::distributed(), oomph::DistributableLinearAlgebraObject::distribution_pt(), i, oomph::DoubleVector::initialise(), j, k, oomph::SparseMatrix< T, MATRIX_TYPE >::N, oomph::DistributableLinearAlgebraObject::nrow(), nrow(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, oomph::CCMatrix< double >::Row_index, oomph::SparseMatrix< T, MATRIX_TYPE >::Value, oomph::DoubleVector::values_pt(), and plotDoE::x.

Referenced by oomph::SuperLUSolver::solve(), and oomph::SuperLUSolver::solve_transpose().

◆ ncol()

unsigned long oomph::CCDoubleMatrix::ncol ( ) const
inlinevirtual

Return the number of columns of the matrix.

Implements oomph::DoubleMatrixBase.

2824  {
2825  return CCMatrix<double>::ncol();
2826  }
unsigned long ncol() const
Return the number of columns of the matrix.
Definition: matrices.h:634

References oomph::SparseMatrix< T, CCMatrix< T > >::ncol().

Referenced by matrix_reduction(), and multiply().

◆ nrow()

unsigned long oomph::CCDoubleMatrix::nrow ( ) const
inlinevirtual

Return the number of rows of the matrix.

Implements oomph::DoubleMatrixBase.

2818  {
2819  return CCMatrix<double>::nrow();
2820  }
unsigned long nrow() const
Return the number of rows of the matrix.
Definition: matrices.h:628

References oomph::SparseMatrix< T, CCMatrix< T > >::nrow().

Referenced by matrix_reduction(), multiply(), multiply_transpose(), and oomph::ILUZeroPreconditioner< CCDoubleMatrix >::setup().

◆ operator()()

double oomph::CCDoubleMatrix::operator() ( const unsigned long &  i,
const unsigned long &  j 
) const
inlinevirtual

Overload the round-bracket access operator to provide read-only (const) access to the data

Implements oomph::DoubleMatrixBase.

2832  {
2833  return CCMatrix<double>::get_entry(i, j);
2834  }
T get_entry(const unsigned long &i, const unsigned long &j) const
Definition: matrices.h:2654

References oomph::CCMatrix< T >::get_entry(), i, and j.

◆ operator=()

void oomph::CCDoubleMatrix::operator= ( const CCDoubleMatrix )
delete

Broken assignment operator.

Member Data Documentation

◆ Matrix_matrix_multiply_method

unsigned oomph::CCDoubleMatrix::Matrix_matrix_multiply_method
private

Flag to determine which matrix-matrix multiplication method is used.

Referenced by CCDoubleMatrix(), matrix_matrix_multiply_method(), and multiply().


The documentation for this class was generated from the following files: