oomph::CCMatrix< T > Class Template Reference

#include <matrices.h>

+ Inheritance diagram for oomph::CCMatrix< T >:

Public Member Functions

 CCMatrix ()
 Default constructor. More...
 
 CCMatrix (const Vector< T > &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...
 
T get_entry (const unsigned long &i, const unsigned long &j) const
 
Tentry (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< T > &value, const Vector< int > &row_index, const Vector< int > &column_start, const unsigned long &n, const unsigned long &m)
 
void build_without_copy (T *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, CCMatrix< T > >
 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 nrow () const
 Return the number of rows of the matrix. More...
 
unsigned long ncol () const
 Return the number of columns of the matrix. 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
 

Protected Attributes

intRow_index
 Row index. More...
 
intColumn_start
 Start index for column. More...
 
- Protected Attributes inherited from oomph::SparseMatrix< T, CCMatrix< T > >
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...
 

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
 
- Static Protected Attributes inherited from oomph::SparseMatrix< T, CCMatrix< T > >
static T Zero
 Dummy zero. More...
 

Detailed Description

template<class T>
class oomph::CCMatrix< T >

/////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// A class for compressed column matrices: a sparse matrix format The class is passed as the MATRIX_TYPE paramater so that the base class can use the specific access functions in the round-bracket operator.

Constructor & Destructor Documentation

◆ CCMatrix() [1/3]

template<class T >
oomph::CCMatrix< T >::CCMatrix ( )
inline

Default constructor.

2588  : SparseMatrix<T, CCMatrix<T>>()
2589  {
2590  Row_index = 0;
2591  Column_start = 0;
2592  }
int * Column_start
Start index for column.
Definition: matrices.h:2779
int * Row_index
Row index.
Definition: matrices.h:2776

References oomph::CCMatrix< T >::Column_start, and oomph::CCMatrix< T >::Row_index.

◆ CCMatrix() [2/3]

template<class T >
oomph::CCMatrix< T >::CCMatrix ( const Vector< T > &  value,
const Vector< int > &  row_index_,
const Vector< int > &  column_start_,
const unsigned long &  n,
const unsigned long &  m 
)
inline

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.

2605  : SparseMatrix<T, CCMatrix<T>>()
2606  {
2607  Row_index = 0;
2608  Column_start = 0;
2609  build(value, row_index_, column_start_, n, m);
2610  }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
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
T * value()
Access to C-style value array.
Definition: matrices.h:616
int * m
Definition: level2_cplx_impl.h:294

References oomph::CCMatrix< T >::build(), oomph::CCMatrix< T >::Column_start, m, n, oomph::CCMatrix< T >::Row_index, and oomph::SparseMatrix< T, CCMatrix< T > >::value().

◆ CCMatrix() [3/3]

template<class T >
oomph::CCMatrix< T >::CCMatrix ( const CCMatrix< T > &  source_matrix)
inline

Copy constructor.

2615  : SparseMatrix<T, CCMatrix<T>>(source_matrix)
2616  {
2617  // NNz, N and M are set the the copy constructor of the SparseMatrix
2618  // called above
2619 
2620  // Row indices stored in C-style array
2621  Row_index = new int[this->Nnz];
2622 
2623  // Assign:
2624  for (unsigned long i = 0; i < this->Nnz; i++)
2625  {
2626  Row_index[i] = source_matrix.row_index()[i];
2627  }
2628 
2629  // Column start:
2630  Column_start = new int[this->M + 1];
2631 
2632  // Assign:
2633  for (unsigned long i = 0; i <= this->M; i++)
2634  {
2635  Column_start[i] = source_matrix.column_start()[i];
2636  }
2637  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
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 M
Number of columns.
Definition: matrices.h:571

References oomph::CCMatrix< T >::column_start(), oomph::CCMatrix< T >::Column_start, i, oomph::SparseMatrix< T, CCMatrix< T > >::M, oomph::SparseMatrix< T, CCMatrix< T > >::Nnz, oomph::CCMatrix< T >::row_index(), and oomph::CCMatrix< T >::Row_index.

◆ ~CCMatrix()

template<class T >
virtual oomph::CCMatrix< T >::~CCMatrix ( )
inlinevirtual

Destructor, delete any allocated memory.

2645  {
2646  delete[] Row_index;
2647  Row_index = 0;
2648  delete[] Column_start;
2649  Column_start = 0;
2650  }

References oomph::CCMatrix< T >::Column_start, and oomph::CCMatrix< T >::Row_index.

Member Function Documentation

◆ build()

template<class T >
void oomph::CCMatrix< T >::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, so make sure the vector has been shrunk to its correct length.

3252  {
3253 #ifdef PARANOID
3254  if (value.size() != row_index_.size())
3255  {
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;
3260 
3261  throw OomphLibError(
3262  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
3263  }
3264 #endif
3265 
3266  // Number of nonzero entries
3267  this->Nnz = value.size();
3268 
3269  // Number of rows
3270  this->N = n;
3271 
3272  // Number of columns
3273  this->M = m;
3274 
3275  // We need to delete any previously allocated storage
3276  if (this->Value != 0)
3277  {
3278  delete[] this->Value;
3279  }
3280  if (this->Row_index != 0)
3281  {
3282  delete[] this->Row_index;
3283  }
3284  if (this->Column_start != 0)
3285  {
3286  delete[] this->Column_start;
3287  }
3288 
3289  // Values stored in C-style array
3290  this->Value = new T[this->Nnz];
3291 
3292  // Row indices stored in C-style array
3293  this->Row_index = new int[this->Nnz];
3294 
3295  // Assign:
3296  for (unsigned long i = 0; i < this->Nnz; i++)
3297  {
3298  this->Value[i] = value[i];
3299  this->Row_index[i] = row_index_[i];
3300  }
3301 
3302  // Column start:
3303  // Find the size and aollcate
3304  unsigned long n_column_start = column_start_.size();
3305  this->Column_start = new int[n_column_start];
3306 
3307  // Assign:
3308  for (unsigned long i = 0; i < n_column_start; i++)
3309  {
3310  this->Column_start[i] = column_start_[i];
3311  }
3312  }
T * Value
Internal representation of the matrix values, a pointer.
Definition: matrices.h:565
unsigned long N
Number of rows.
Definition: matrices.h:568
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References i, m, n, N, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and Eigen::value.

Referenced by oomph::CCMatrix< T >::CCMatrix().

◆ build_without_copy()

template<class T >
void oomph::CCMatrix< T >::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-zero values. The final parameters specifies the number of rows and columns. Note that, as the name suggests, this function does not make a copy of the data pointed to by the first three arguments!

Build matrix from compressed representation. Note that, as the name suggests, this function does not make a copy of the data pointed to by the first three arguments!

3205  {
3206  // Number of nonzero entries
3207  this->Nnz = nnz;
3208 
3209  // Number of rows
3210  this->N = n;
3211 
3212  // Number of columns
3213  this->M = m;
3214 
3215  // delete any previously allocated storage
3216  if (this->Value != 0)
3217  {
3218  delete[] this->Value;
3219  }
3220  if (this->Row_index != 0)
3221  {
3222  delete[] this->Row_index;
3223  }
3224  if (this->Column_start != 0)
3225  {
3226  delete[] this->Column_start;
3227  }
3228 
3229  // set Value
3230  this->Value = value;
3231 
3232  // set Row_index
3233  this->Row_index = row_index;
3234 
3235  // set Column_start
3236  this->Column_start = column_start;
3237  }
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
unsigned long nnz() const
Return the number of nonzero entries.
Definition: matrices.h:640

References m, n, N, and Eigen::value.

Referenced by oomph::Problem::get_jacobian(), and oomph::CCDoubleMatrix::multiply().

◆ clean_up_memory()

template<class T >
void oomph::CCMatrix< T >::clean_up_memory

Wipe matrix data and set all values to 0.

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

3170  {
3171  // delete any previously allocated storage
3172  if (this->Value != 0)
3173  {
3174  delete[] this->Value;
3175  this->Value = 0;
3176  }
3177  if (this->Row_index != 0)
3178  {
3179  delete[] this->Row_index;
3180  this->Row_index = 0;
3181  }
3182  if (this->Column_start != 0)
3183  {
3184  delete[] this->Column_start;
3185  this->Column_start = 0;
3186  }
3187  this->Nnz = 0;
3188  this->N = 0;
3189  this->M = 0;
3190  }

References N.

◆ column_start() [1/2]

template<class T >
int* oomph::CCMatrix< T >::column_start ( )
inline

◆ column_start() [2/2]

template<class T >
const int* oomph::CCMatrix< T >::column_start ( ) const
inline

Access to C-style column_start array (const version)

2699  {
2700  return Column_start;
2701  }

References oomph::CCMatrix< T >::Column_start.

◆ entry()

template<class T >
T& oomph::CCMatrix< T >::entry ( const unsigned long &  i,
const unsigned long &  j 
)
inline

Read-write access is not permitted for these matrices and is deliberately broken.

2672  {
2673  std::string error_string =
2674  "Non-const access not provided for the CCMatrix<T> class\n";
2675  error_string +=
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 "
2679  "to the matrix\n";
2680  error_string += " const CCMatrix<T>& read_M = M;\n";
2681  error_string += "Then read_M(i,j) is permitted\n";
2682 
2683  throw OomphLibError(
2685 
2686  // Dummy return
2687  T dummy;
2688  return dummy;
2689  }
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286

References OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and oomph::Global_string_for_annotation::string().

◆ get_entry()

template<class T >
T oomph::CCMatrix< T >::get_entry ( const unsigned long &  i,
const unsigned long &  j 
) const
inline

Access function that will be called by the read-only round-bracket operator (const)

2655  {
2656 #ifdef RANGE_CHECKING
2657  this->range_check(i, j);
2658 #endif
2659  for (long k = Column_start[j]; k < Column_start[j + 1]; k++)
2660  {
2661  if (unsigned(Row_index[k]) == i)
2662  {
2663  return this->Value[k];
2664  }
2665  }
2666  return this->Zero;
2667  }
void range_check(const unsigned long &i, const unsigned long &j) const
Definition: matrices.h:78
static T Zero
Dummy zero.
Definition: matrices.h:577
char char char int int * k
Definition: level2_impl.h:374
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References oomph::CCMatrix< T >::Column_start, i, j, k, oomph::Matrix< T, MATRIX_TYPE >::range_check(), oomph::CCMatrix< T >::Row_index, oomph::SparseMatrix< T, CCMatrix< T > >::Value, and oomph::SparseMatrix< T, CCMatrix< T > >::Zero.

Referenced by oomph::CCDoubleMatrix::operator()().

◆ operator=()

template<class T >
void oomph::CCMatrix< T >::operator= ( const CCMatrix< T > &  )
delete

Broken assignment operator.

◆ output_bottom_right_zero_helper()

template<class T >
void oomph::CCMatrix< T >::output_bottom_right_zero_helper ( std::ostream &  outfile) const
inlinevirtual

Output the "bottom right" entry regardless of it being zero or not (this allows automatic detection of matrix size in e.g. matlab, python).

Reimplemented from oomph::SparseMatrix< T, CCMatrix< T > >.

2719  {
2720  int last_row = this->N - 1;
2721  int last_col_local = this->M - 1;
2722 
2723  // Use this strange thingy because of the CRTP discussed above.
2724  T last_value = this->operator()(last_row, last_col_local);
2725 
2726  if (last_value == T(0))
2727  {
2728  outfile << last_row << " " << last_col_local << " " << T(0)
2729  << std::endl;
2730  }
2731  }
Eigen::Triplet< double > T
Definition: EigenUnitTest.cpp:11
T operator()(const unsigned long &i, const unsigned long &j) const
Definition: matrices.h:128

References oomph::SparseMatrix< T, CCMatrix< T > >::N, and oomph::Matrix< T, MATRIX_TYPE >::operator()().

◆ row_index() [1/2]

◆ row_index() [2/2]

template<class T >
const int* oomph::CCMatrix< T >::row_index ( ) const
inline

Access to C-style row index array (const version)

2711  {
2712  return Row_index;
2713  }

References oomph::CCMatrix< T >::Row_index.

◆ sparse_indexed_output_helper()

template<class T >
void oomph::CCMatrix< T >::sparse_indexed_output_helper ( std::ostream &  outfile) const
inlinevirtual

Indexed output function to print a matrix to the stream outfile as i,j,a(i,j) for a(i,j)!=0 only.

Reimplemented from oomph::SparseMatrix< T, CCMatrix< T > >.

2736  {
2737  for (unsigned long j = 0; j < this->N; j++)
2738  {
2739  for (long k = Column_start[j]; k < Column_start[j + 1]; k++)
2740  {
2741  outfile << Row_index[k] << " " << j << " " << this->Value[k]
2742  << std::endl;
2743  }
2744  }
2745  }

References oomph::CCMatrix< T >::Column_start, j, k, oomph::SparseMatrix< T, CCMatrix< T > >::N, oomph::CCMatrix< T >::Row_index, and oomph::SparseMatrix< T, CCMatrix< T > >::Value.

Member Data Documentation

◆ Column_start

◆ Row_index


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