vector_matrix.h
Go to the documentation of this file.
1 // LIC// ====================================================================
2 // LIC// This file forms part of oomph-lib, the object-oriented,
3 // LIC// multi-physics finite-element library, available
4 // LIC// at http://www.oomph-lib.org.
5 // LIC//
6 // LIC// Copyright (C) 2006-2022 Matthias Heil and Andrew Hazel
7 // LIC//
8 // LIC// This library is free software; you can redistribute it and/or
9 // LIC// modify it under the terms of the GNU Lesser General Public
10 // LIC// License as published by the Free Software Foundation; either
11 // LIC// version 2.1 of the License, or (at your option) any later version.
12 // LIC//
13 // LIC// This library is distributed in the hope that it will be useful,
14 // LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // LIC// Lesser General Public License for more details.
17 // LIC//
18 // LIC// You should have received a copy of the GNU Lesser General Public
19 // LIC// License along with this library; if not, write to the Free Software
20 // LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 // LIC// 02110-1301 USA.
22 // LIC//
23 // LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
24 // LIC//
25 // LIC//====================================================================
26 #ifndef OOMPH_VECTOR_MATRIX_HEADER
27 #define OOMPH_VECTOR_MATRIX_HEADER
28 
29 
30 // Config header generated by autoconfig
31 #ifdef HAVE_CONFIG_H
32 #include <oomph-lib-config.h>
33 #endif
34 
35 
36 #ifdef OOMPH_HAS_MPI
37 #include "mpi.h"
38 #endif
39 
40 // oomph-lib headers
41 #include "Vector.h"
42 #include "oomph_utilities.h"
43 
44 namespace oomph
45 {
46  //================================================================
59  // << vector_matrix.nrow() << " "
60  // << vector_matrix.col() << std::endl;
76  //================================================================
77  template<class VALUE_TYPE>
79  {
80  public:
83  {
84  Vector_matrix.resize(0);
85  }
86 
88  VectorMatrix(const unsigned& n, const unsigned& m, const VALUE_TYPE& val)
89  {
90  this->build_vectors_and_value(n, m, val);
91  }
92 
95  VectorMatrix(const unsigned& n, const unsigned& m)
96  {
97  this->build_vectors(n, m);
98  }
99 
101  virtual ~VectorMatrix()
102  {
103  this->clear();
104  }
105 
107  const unsigned nrow() const
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  }
142 
146  const unsigned ncol() const
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  }
185 
188  {
189  return Vector_matrix[i];
190  }
191 
193  const Vector<VALUE_TYPE>& operator[](const size_t i) const
194  {
195  return Vector_matrix[i];
196  }
197 
198 
201  void clear()
202  {
203  Vector_matrix.clear();
204  }
205 
211  void resize(const size_t& n, const size_t& m, VALUE_TYPE val = VALUE_TYPE())
212  {
213  Vector_matrix.resize(n);
214  for (unsigned i = 0; i < n; i++)
215  {
216  Vector_matrix[i].resize(m, val);
217  }
218  }
219 
226  void assign(const size_t& n, const size_t& m, const VALUE_TYPE& val)
227  {
229  }
230 
231 
232  protected:
234  void build_vectors(const unsigned& n, const unsigned& m)
235  {
237  }
238 
240  void build_vectors_and_value(const unsigned& n,
241  const unsigned& m,
242  const VALUE_TYPE& val)
243  {
245  }
246 
250  };
251 
252 } // namespace oomph
253 
254 #endif
int i
Definition: BiCGSTAB_step_by_step.cpp:9
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
Definition: oomph_definitions.h:222
Definition: vector_matrix.h:79
void build_vectors(const unsigned &n, const unsigned &m)
Builds an n by m VectorMatrix with default VALUE_TYPE.
Definition: vector_matrix.h:234
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
Vector< Vector< VALUE_TYPE > > Vector_matrix
Definition: vector_matrix.h:249
void assign(const size_t &n, const size_t &m, const VALUE_TYPE &val)
Definition: vector_matrix.h:226
virtual ~VectorMatrix()
Default virtual destructor.
Definition: vector_matrix.h:101
const unsigned ncol() const
Definition: vector_matrix.h:146
void resize(const size_t &n, const size_t &m, VALUE_TYPE val=VALUE_TYPE())
Definition: vector_matrix.h:211
const Vector< VALUE_TYPE > & operator[](const size_t i) const
[] access function to the i-th inner vector const version
Definition: vector_matrix.h:193
const unsigned nrow() const
returns the number of rows. This is the outer Vector size.
Definition: vector_matrix.h:107
VectorMatrix(const unsigned &n, const unsigned &m, const VALUE_TYPE &val)
Constructor - constructs an n by m matrix with value val.
Definition: vector_matrix.h:88
void clear()
Definition: vector_matrix.h:201
VectorMatrix()
Default constructor - constructs an empty matrix.
Definition: vector_matrix.h:82
Vector< VALUE_TYPE > & operator[](const size_t i)
[] access function to the i-th inner vector.
Definition: vector_matrix.h:187
VectorMatrix(const unsigned &n, const unsigned &m)
Definition: vector_matrix.h:95
Definition: oomph-lib/src/generic/Vector.h:58
int * m
Definition: level2_cplx_impl.h:294
val
Definition: calibrate.py:119
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).
Definition: AnisotropicHookean.h:10
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86