oomph::VectorMatrix< VALUE_TYPE > Class Template Reference

#include <vector_matrix.h>

Public Member Functions

 VectorMatrix ()
 Default constructor - constructs an empty matrix. More...
 
 VectorMatrix (const unsigned &n, const unsigned &m, const VALUE_TYPE &val)
 Constructor - constructs an n by m matrix with value val. More...
 
 VectorMatrix (const unsigned &n, const unsigned &m)
 
virtual ~VectorMatrix ()
 Default virtual destructor. More...
 
const unsigned nrow () const
 returns the number of rows. This is the outer Vector size. More...
 
const unsigned ncol () const
 
Vector< VALUE_TYPE > & operator[] (const size_t i)
 [] access function to the i-th inner vector. More...
 
const Vector< VALUE_TYPE > & operator[] (const size_t i) const
 [] access function to the i-th inner vector const version More...
 
void clear ()
 
void resize (const size_t &n, const size_t &m, VALUE_TYPE val=VALUE_TYPE())
 
void assign (const size_t &n, const size_t &m, const VALUE_TYPE &val)
 

Protected Member Functions

void build_vectors (const unsigned &n, const unsigned &m)
 Builds an n by m VectorMatrix with default VALUE_TYPE. More...
 
void build_vectors_and_value (const unsigned &n, const unsigned &m, const VALUE_TYPE &val)
 Build an m by n VectorMatrix with VALUE_TYPE val. More...
 

Protected Attributes

Vector< Vector< VALUE_TYPE > > Vector_matrix
 

Detailed Description

template<class VALUE_TYPE>
class oomph::VectorMatrix< VALUE_TYPE >

VectorMatrix is a generalised, STL-map-based, matrix based on a Vector of Vectors.

Example of usage:

// Assume we have a Vector of pointers to objects:
VectorMatrix<int> vector_matrix(4,5,-1);
// This is a 4 by 5 matrix with all entries set to -1.
std::cout << vector_matrix[3][3] << " "
// << vector_matrix.nrow() << " "
// << vector_matrix.col() << std::endl;
// Output:
// -1 4 5
vector_matrix[3][3] = 42;
std::cout << vector_matrix[3][3] << " "
<< vector_matrix.nrow() << " "
<< vector_matrix.col() << std::endl;
// Output:
// 42 4 5

Constructor & Destructor Documentation

◆ VectorMatrix() [1/3]

template<class VALUE_TYPE >
oomph::VectorMatrix< VALUE_TYPE >::VectorMatrix ( )
inline

Default constructor - constructs an empty matrix.

83  {
84  Vector_matrix.resize(0);
85  }
Vector< Vector< VALUE_TYPE > > Vector_matrix
Definition: vector_matrix.h:249

References oomph::VectorMatrix< VALUE_TYPE >::Vector_matrix.

◆ VectorMatrix() [2/3]

template<class VALUE_TYPE >
oomph::VectorMatrix< VALUE_TYPE >::VectorMatrix ( const unsigned n,
const unsigned m,
const VALUE_TYPE &  val 
)
inline

Constructor - constructs an n by m matrix with value val.

89  {
90  this->build_vectors_and_value(n, m, val);
91  }
void build_vectors_and_value(const unsigned &n, const unsigned &m, const VALUE_TYPE &val)
Build an m by n VectorMatrix with VALUE_TYPE val.
Definition: vector_matrix.h:240
int * m
Definition: level2_cplx_impl.h:294
val
Definition: calibrate.py:119

References oomph::VectorMatrix< VALUE_TYPE >::build_vectors_and_value(), m, and calibrate::val.

◆ VectorMatrix() [3/3]

template<class VALUE_TYPE >
oomph::VectorMatrix< VALUE_TYPE >::VectorMatrix ( const unsigned n,
const unsigned m 
)
inline

Constructor - constructs an n by m matrix, the value is defined by the default initialisation of VALUE_TYPE.

96  {
97  this->build_vectors(n, m);
98  }
void build_vectors(const unsigned &n, const unsigned &m)
Builds an n by m VectorMatrix with default VALUE_TYPE.
Definition: vector_matrix.h:234

References oomph::VectorMatrix< VALUE_TYPE >::build_vectors(), and m.

◆ ~VectorMatrix()

template<class VALUE_TYPE >
virtual oomph::VectorMatrix< VALUE_TYPE >::~VectorMatrix ( )
inlinevirtual

Default virtual destructor.

102  {
103  this->clear();
104  }
void clear()
Definition: vector_matrix.h:201

References oomph::VectorMatrix< VALUE_TYPE >::clear().

Member Function Documentation

◆ assign()

template<class VALUE_TYPE >
void oomph::VectorMatrix< VALUE_TYPE >::assign ( const size_t &  n,
const size_t &  m,
const VALUE_TYPE &  val 
)
inline

Any elements held in the container before the call are destroyed and replaced by newly constructed elements (no assignments of elements take place). This causes an automatic reallocation of the allocated storage space if -and only if- the new vector size surpasses the current vector capacity. This invokes std::assign on both the outer vector and the inner vectors.

227  {
228  Vector_matrix.assign(n, Vector<VALUE_TYPE>(m, val));
229  }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11

References m, n, calibrate::val, and oomph::VectorMatrix< VALUE_TYPE >::Vector_matrix.

Referenced by main().

◆ build_vectors()

template<class VALUE_TYPE >
void oomph::VectorMatrix< VALUE_TYPE >::build_vectors ( const unsigned n,
const unsigned m 
)
inlineprotected

Builds an n by m VectorMatrix with default VALUE_TYPE.

235  {
236  Vector_matrix.resize(n, Vector<VALUE_TYPE>(m));
237  }

References m, n, and oomph::VectorMatrix< VALUE_TYPE >::Vector_matrix.

Referenced by oomph::VectorMatrix< VALUE_TYPE >::VectorMatrix().

◆ build_vectors_and_value()

template<class VALUE_TYPE >
void oomph::VectorMatrix< VALUE_TYPE >::build_vectors_and_value ( const unsigned n,
const unsigned m,
const VALUE_TYPE &  val 
)
inlineprotected

Build an m by n VectorMatrix with VALUE_TYPE val.

243  {
244  Vector_matrix.resize(n, Vector<VALUE_TYPE>(m, val));
245  }

References m, n, calibrate::val, and oomph::VectorMatrix< VALUE_TYPE >::Vector_matrix.

Referenced by oomph::VectorMatrix< VALUE_TYPE >::VectorMatrix().

◆ clear()

template<class VALUE_TYPE >
void oomph::VectorMatrix< VALUE_TYPE >::clear ( )
inline

Clears the outer vector. Calling Vector::clear() will invoke the destructor of all the inner Vectors.

202  {
203  Vector_matrix.clear();
204  }

References oomph::VectorMatrix< VALUE_TYPE >::Vector_matrix.

Referenced by main(), and oomph::VectorMatrix< VALUE_TYPE >::~VectorMatrix().

◆ ncol()

template<class VALUE_TYPE >
const unsigned oomph::VectorMatrix< VALUE_TYPE >::ncol ( ) const
inline

return the number of columns. This is the size of the first inner vectors, or returns 0 if the outer vector is of size 0 (this->nrow() is 0).

147  {
148 #ifdef PARANOID
149  // Inner vector size consistency check: All inner vectors must be the same
150  // size.
151 
152  const unsigned para_nrow = this->nrow();
153  if (para_nrow > 0)
154  {
155  // There is at least one inner vector
156  unsigned inner_vector0_size = Vector_matrix[0].size();
157 
158  for (unsigned row_i = 0; row_i < para_nrow; row_i++)
159  {
160  unsigned current_inner_vector_size = Vector_matrix[row_i].size();
161  if (current_inner_vector_size != inner_vector0_size)
162  {
163  std::ostringstream err_msg;
164  err_msg << "The size of the inner vectors are not consistent.\n"
165  << "Vector_matrix[0].size() is " << inner_vector0_size
166  << "\n"
167  << "Vector_matrix[" << row_i << "] is "
168  << current_inner_vector_size << "\n";
169  throw OomphLibError(
171  }
172  }
173  }
174 #endif
175 
176  if (this->nrow() == 0)
177  {
178  return 0;
179  }
180  else
181  {
182  return Vector_matrix[0].size();
183  }
184  }
const unsigned nrow() const
returns the number of rows. This is the outer Vector size.
Definition: vector_matrix.h:107
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References oomph::VectorMatrix< VALUE_TYPE >::nrow(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and oomph::VectorMatrix< VALUE_TYPE >::Vector_matrix.

Referenced by oomph::BlockPreconditioner< MATRIX >::get_concatenated_block(), and main().

◆ nrow()

template<class VALUE_TYPE >
const unsigned oomph::VectorMatrix< VALUE_TYPE >::nrow ( ) const
inline

returns the number of rows. This is the outer Vector size.

108  {
109 #ifdef PARANOID
110  // Inner vector size consistency check: All inner vectors must be the same
111  // size. Although the size of the inner vectors are not directly used to
112  // calculate the nrow(), we perform this check here in case the user has
113  // done something dodgy.
114 
115  const unsigned para_nrow = Vector_matrix.size();
116 
117  if (para_nrow > 0)
118  {
119  // There is at least one inner vector
120  unsigned inner_vector0_size = Vector_matrix[0].size();
121 
122  for (unsigned row_i = 0; row_i < para_nrow; row_i++)
123  {
124  unsigned current_inner_vector_size = Vector_matrix[row_i].size();
125  if (current_inner_vector_size != inner_vector0_size)
126  {
127  std::ostringstream err_msg;
128  err_msg << "The size of the inner vectors are not consistent.\n"
129  << "Vector_matrix[0].size() is " << inner_vector0_size
130  << "\n"
131  << "Vector_matrix[" << row_i << "] is "
132  << current_inner_vector_size << "\n";
133  throw OomphLibError(
135  }
136  }
137  }
138 #endif
139 
140  return Vector_matrix.size();
141  }

References OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and oomph::VectorMatrix< VALUE_TYPE >::Vector_matrix.

Referenced by oomph::BlockPreconditioner< MATRIX >::get_concatenated_block(), main(), and oomph::VectorMatrix< VALUE_TYPE >::ncol().

◆ operator[]() [1/2]

template<class VALUE_TYPE >
Vector<VALUE_TYPE>& oomph::VectorMatrix< VALUE_TYPE >::operator[] ( const size_t  i)
inline

[] access function to the i-th inner vector.

188  {
189  return Vector_matrix[i];
190  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9

References i, and oomph::VectorMatrix< VALUE_TYPE >::Vector_matrix.

◆ operator[]() [2/2]

template<class VALUE_TYPE >
const Vector<VALUE_TYPE>& oomph::VectorMatrix< VALUE_TYPE >::operator[] ( const size_t  i) const
inline

[] access function to the i-th inner vector const version

194  {
195  return Vector_matrix[i];
196  }

References i, and oomph::VectorMatrix< VALUE_TYPE >::Vector_matrix.

◆ resize()

template<class VALUE_TYPE >
void oomph::VectorMatrix< VALUE_TYPE >::resize ( const size_t &  n,
const size_t &  m,
VALUE_TYPE  val = VALUE_TYPE() 
)
inline

Resize the existing VectorMatrix. WARNING: This invokes the resize function in std::vector, as such, only new values are assigned, old values as kept. e.g. if vec = [2,2,2], then vec.resize(5,3) gives vec = [2, 2, 2, 3, 3].

212  {
213  Vector_matrix.resize(n);
214  for (unsigned i = 0; i < n; i++)
215  {
216  Vector_matrix[i].resize(m, val);
217  }
218  }

References i, m, n, calibrate::val, and oomph::VectorMatrix< VALUE_TYPE >::Vector_matrix.

Referenced by main().

Member Data Documentation

◆ Vector_matrix


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