libMesh::DenseSubVector< T > Class Template Reference

#include <dense_subvector.h>

Inheritance diagram for libMesh::DenseSubVector< T >:

Public Member Functions

 DenseSubVector (DenseVector< T > &new_parent, const unsigned int ioff=0, const unsigned int n=0)
 
virtual ~DenseSubVector ()
 
DenseVector< T > & parent ()
 
virtual void zero () libmesh_override
 
const T & operator() (const unsigned int i) const
 
T & operator() (const unsigned int i)
 
virtual T el (const unsigned int i) const libmesh_override
 
virtual T & el (const unsigned int i) libmesh_override
 
virtual unsigned int size () const libmesh_override
 
virtual bool empty () const libmesh_override
 
unsigned int i_off () const
 
void reposition (const unsigned int ioff, const unsigned int n)
 
Real min () const
 
Real max () const
 
Real l1_norm () const
 
Real l2_norm () const
 
Real linfty_norm () const
 
void print (std::ostream &os) const
 
void print_scientific (std::ostream &os, unsigned precision=8) const
 

Private Attributes

DenseVector< T > & _parent_vector
 
unsigned int _n
 
unsigned int _i_off
 

Detailed Description

template<typename T>
class libMesh::DenseSubVector< T >

Defines a dense subvector for use in finite element computations. Useful for storing element load vectors before summation into a global vector, particularly when you have systems of equations. All overridden virtual functions are documented in dense_vector_base.h.

Author
Benjamin S. Kirk
Date
2003

Definition at line 42 of file dense_subvector.h.

Constructor & Destructor Documentation

template<typename T >
libMesh::DenseSubVector< T >::DenseSubVector ( DenseVector< T > &  new_parent,
const unsigned int  ioff = 0,
const unsigned int  n = 0 
)
inline

Constructor. Creates a dense subvector of the vector parent. The subvector has dimensions $(m \times n)$, and the $(0,0)$ entry of the subvector is located at the $(ioff,joff)$ location in the parent vector.

Definition at line 156 of file dense_subvector.h.

References libMesh::DenseSubVector< T >::reposition().

158  :
159  _parent_vector(new_parent)
160 {
161  reposition (ioff, n);
162 }
void reposition(const unsigned int ioff, const unsigned int n)
DenseVector< T > & _parent_vector
template<typename T>
virtual libMesh::DenseSubVector< T >::~DenseSubVector ( )
inlinevirtual

Destructor. Does nothing.

Definition at line 58 of file dense_subvector.h.

58 {}

Member Function Documentation

template<typename T>
virtual T libMesh::DenseSubVector< T >::el ( const unsigned int  i) const
inlinevirtual
Returns
The (i) element of the vector.

Implements libMesh::DenseVectorBase< T >.

Definition at line 78 of file dense_subvector.h.

79  { return (*this)(i); }
template<typename T>
virtual T& libMesh::DenseSubVector< T >::el ( const unsigned int  i)
inlinevirtual
Returns
The (i) element of the vector as a writable reference.

Implements libMesh::DenseVectorBase< T >.

Definition at line 81 of file dense_subvector.h.

82  { return (*this)(i); }
template<typename T>
virtual bool libMesh::DenseSubVector< T >::empty ( ) const
inlinevirtual
Returns
true iff size() is 0.

Reimplemented from libMesh::DenseVectorBase< T >.

Definition at line 87 of file dense_subvector.h.

References libMesh::DenseSubVector< T >::_n.

Referenced by libMesh::NumericVector< T >::insert().

88  { return (_n == 0); }
template<typename T >
Real libMesh::DenseSubVector< T >::l1_norm ( ) const
inline
Returns
The $l_1$-norm of the vector, i.e. the sum of the absolute values of the entries.

Definition at line 247 of file dense_subvector.h.

References libMesh::DenseSubVector< T >::_parent_vector, std::abs(), libMesh::DenseSubVector< T >::i_off(), libMesh::Real, and libMesh::DenseSubVector< T >::size().

Referenced by libMesh::DenseSubVector< T >::i_off().

248 {
249  Real my_norm = 0.;
250  for (unsigned int i=0; i!=this->size(); i++)
251  {
252  my_norm += std::abs(_parent_vector (i + this->i_off()));
253  }
254  return my_norm;
255 }
double abs(double a)
unsigned int i_off() const
DenseVector< T > & _parent_vector
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual unsigned int size() const libmesh_override
template<typename T >
Real libMesh::DenseSubVector< T >::l2_norm ( ) const
inline
Returns
The $l_2$-norm of the vector, i.e. the square root of the sum of the squares of the entries.

Definition at line 261 of file dense_subvector.h.

References libMesh::DenseSubVector< T >::_parent_vector, libMesh::DenseSubVector< T >::i_off(), libMesh::TensorTools::norm_sq(), libMesh::Real, and libMesh::DenseSubVector< T >::size().

Referenced by libMesh::DenseSubVector< T >::i_off().

262 {
263  Real my_norm = 0.;
264  for (unsigned int i=0; i!=this->size(); i++)
265  {
266  my_norm += TensorTools::norm_sq(_parent_vector (i + this->i_off()));
267  }
268  return sqrt(my_norm);
269 }
unsigned int i_off() const
DenseVector< T > & _parent_vector
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual unsigned int size() const libmesh_override
template<typename T >
Real libMesh::DenseSubVector< T >::linfty_norm ( ) const
inline
Returns
The $l_\infty$-norm of the vector, i.e. the maximum absolute value of the entries.

Definition at line 275 of file dense_subvector.h.

References libMesh::DenseSubVector< T >::_parent_vector, libMesh::DenseSubVector< T >::i_off(), libMesh::TensorTools::norm_sq(), libMesh::Real, and libMesh::DenseSubVector< T >::size().

Referenced by libMesh::DenseSubVector< T >::i_off().

276 {
277  if (!this->size())
278  return 0.;
279  Real my_norm = TensorTools::norm_sq(_parent_vector (this->i_off()));
280 
281  for (unsigned int i=1; i!=this->size(); i++)
282  {
283  Real current = TensorTools::norm_sq(_parent_vector (i + this->i_off()));
284  my_norm = (my_norm > current? my_norm : current);
285  }
286  return sqrt(my_norm);
287 }
unsigned int i_off() const
DenseVector< T > & _parent_vector
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual unsigned int size() const libmesh_override
template<typename T >
Real libMesh::DenseSubVector< T >::max ( ) const
inline
Returns
The maximum element in the vector, or the maximum real part in the case of complex numbers.

Definition at line 230 of file dense_subvector.h.

References libMesh::DenseSubVector< T >::_parent_vector, libMesh::DenseSubVector< T >::i_off(), libMesh::libmesh_assert(), libMesh::libmesh_real(), libMesh::Real, and libMesh::DenseSubVector< T >::size().

Referenced by libMesh::DenseSubVector< T >::i_off().

231 {
232  libmesh_assert (this->size());
233  Real my_max = libmesh_real(_parent_vector (this->i_off()));
234 
235  for (unsigned int i=1; i!=this->size(); i++)
236  {
237  Real current = libmesh_real(_parent_vector (i + this->i_off()));
238  my_max = (my_max > current? my_max : current);
239  }
240  return my_max;
241 }
T libmesh_real(T a)
libmesh_assert(j)
unsigned int i_off() const
DenseVector< T > & _parent_vector
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual unsigned int size() const libmesh_override
template<typename T >
Real libMesh::DenseSubVector< T >::min ( ) const
inline
Returns
The minimum element in the vector, or the minimum real part in the case of complex numbers.

Definition at line 213 of file dense_subvector.h.

References libMesh::DenseSubVector< T >::_parent_vector, libMesh::DenseSubVector< T >::i_off(), libMesh::libmesh_assert(), libMesh::libmesh_real(), libMesh::Real, and libMesh::DenseSubVector< T >::size().

Referenced by libMesh::DenseSubVector< T >::i_off().

214 {
215  libmesh_assert (this->size());
216  Real my_min = libmesh_real(_parent_vector (this->i_off()));
217 
218  for (unsigned int i=1; i!=this->size(); i++)
219  {
220  Real current = libmesh_real(_parent_vector (i + this->i_off()));
221  my_min = (my_min < current? my_min : current);
222  }
223  return my_min;
224 }
T libmesh_real(T a)
libmesh_assert(j)
unsigned int i_off() const
DenseVector< T > & _parent_vector
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual unsigned int size() const libmesh_override
template<typename T >
const T & libMesh::DenseSubVector< T >::operator() ( const unsigned int  i) const
inline
Returns
The (i,j) element of the subvector as a const reference.

Definition at line 192 of file dense_subvector.h.

References libMesh::DenseSubVector< T >::_parent_vector, libMesh::DenseSubVector< T >::i_off(), and libMesh::DenseSubVector< T >::size().

Referenced by libMesh::DenseSubVector< T >::parent().

193 {
194  libmesh_assert_less (i, this->size());
195  libmesh_assert_less (i + this->i_off(), _parent_vector.size());
196 
197  return _parent_vector (i + this->i_off());
198 }
unsigned int i_off() const
DenseVector< T > & _parent_vector
virtual unsigned int size() const libmesh_override
template<typename T >
T & libMesh::DenseSubVector< T >::operator() ( const unsigned int  i)
inline
Returns
The (i,j) element of the subvector as a writable reference.

Definition at line 203 of file dense_subvector.h.

References libMesh::DenseSubVector< T >::_parent_vector, libMesh::DenseSubVector< T >::i_off(), and libMesh::DenseSubVector< T >::size().

204 {
205  libmesh_assert_less (i, this->size());
206  libmesh_assert_less (i + this->i_off(), _parent_vector.size());
207 
208  return _parent_vector (i + this->i_off());
209 }
unsigned int i_off() const
DenseVector< T > & _parent_vector
virtual unsigned int size() const libmesh_override
template<typename T>
DenseVector<T>& libMesh::DenseSubVector< T >::parent ( )
inline
Returns
A reference to the parent vector.

Definition at line 63 of file dense_subvector.h.

References libMesh::DenseSubVector< T >::_parent_vector, libMesh::DenseSubVector< T >::operator()(), and libMesh::DenseSubVector< T >::zero().

Referenced by libMesh::DenseSubMatrix< T >::condense().

63 { return _parent_vector; }
DenseVector< T > & _parent_vector
template<typename T >
void libMesh::DenseVectorBase< T >::print ( std::ostream &  os) const
inherited

Pretty-print the vector to stdout.

Definition at line 62 of file dense_vector_base.C.

Referenced by libMesh::DenseVectorBase< T >::empty().

63 {
64  for (unsigned int i=0; i<this->size(); i++)
65  os << std::setw(8)
66  << this->el(i)
67  << std::endl;
68 }
virtual T el(const unsigned int i) const =0
virtual unsigned int size() const =0
template<typename T >
void libMesh::DenseVectorBase< T >::print_scientific ( std::ostream &  os,
unsigned  precision = 8 
) const
inherited

Prints the entries of the vector with additional decimal places in scientific notation.

Definition at line 30 of file dense_vector_base.C.

31 {
32 #ifndef LIBMESH_BROKEN_IOSTREAM
33 
34  // save the initial format flags
35  std::ios_base::fmtflags os_flags = os.flags();
36 
37  // Print the vector entries.
38  for (unsigned int i=0; i<this->size(); i++)
39  os << std::setw(10)
40  << std::scientific
41  << std::setprecision(precision)
42  << this->el(i)
43  << std::endl;
44 
45  // reset the original format flags
46  os.flags(os_flags);
47 
48 #else
49 
50  // Print the matrix entries.
51  for (unsigned int i=0; i<this->size(); i++)
52  os << std::setprecision(precision)
53  << this->el(i)
54  << std::endl;
55 
56 #endif
57 }
virtual T el(const unsigned int i) const =0
virtual unsigned int size() const =0
template<typename T >
void libMesh::DenseSubVector< T >::reposition ( const unsigned int  ioff,
const unsigned int  n 
)
inline

Changes the location of the subvector in the parent vector.

Definition at line 168 of file dense_subvector.h.

References libMesh::DenseSubVector< T >::_i_off, libMesh::DenseSubVector< T >::_n, libMesh::DenseSubVector< T >::_parent_vector, libMesh::DenseSubVector< T >::i_off(), and libMesh::DenseSubVector< T >::size().

Referenced by libMesh::DenseSubVector< T >::DenseSubVector(), and libMesh::DenseSubVector< T >::i_off().

170 {
171  _i_off = ioff;
172  _n = n;
173 
174  // Make sure we still fit in the parent vector.
175  libmesh_assert_less_equal ((this->i_off() + this->size()), _parent_vector.size());
176 }
unsigned int i_off() const
DenseVector< T > & _parent_vector
virtual unsigned int size() const libmesh_override
template<typename T >
void libMesh::DenseSubVector< T >::zero ( )
inlinevirtual

Set every element in the vector to 0. Needs to be pure virtual since the storage method may be different in derived classes.

Implements libMesh::DenseVectorBase< T >.

Definition at line 182 of file dense_subvector.h.

References libMesh::DenseSubVector< T >::_parent_vector, libMesh::DenseSubVector< T >::i_off(), and libMesh::DenseSubVector< T >::size().

Referenced by libMesh::DenseSubVector< T >::parent().

183 {
184  for (unsigned int i=0; i<this->size(); i++)
185  _parent_vector (i + this->i_off()) = 0.;
186 }
unsigned int i_off() const
DenseVector< T > & _parent_vector
virtual unsigned int size() const libmesh_override

Member Data Documentation

template<typename T>
unsigned int libMesh::DenseSubVector< T >::_i_off
private

The offset into the parent vector.

Definition at line 147 of file dense_subvector.h.

Referenced by libMesh::DenseSubVector< T >::i_off(), and libMesh::DenseSubVector< T >::reposition().

template<typename T>
unsigned int libMesh::DenseSubVector< T >::_n
private

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