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-type computations. Useful for storing element load vectors before summation into a global vector, particularly when you have systems of equations.

Author
Benjamin S. Kirk
Date
2003

Definition at line 41 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 175 of file dense_subvector.h.

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

177  :
178  _parent_vector(new_parent)
179 {
180  reposition (ioff, n);
181 }
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 57 of file dense_subvector.h.

57 {}

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 84 of file dense_subvector.h.

85  { 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 writeable reference.

Implements libMesh::DenseVectorBase< T >.

Definition at line 90 of file dense_subvector.h.

91  { 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 102 of file dense_subvector.h.

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

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

103  { 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.

Definition at line 266 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().

267 {
268  Real my_norm = 0.;
269  for (unsigned int i=0; i!=this->size(); i++)
270  {
271  my_norm += std::abs(_parent_vector (i + this->i_off()));
272  }
273  return my_norm;
274 }
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 elements.

Definition at line 280 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().

281 {
282  Real my_norm = 0.;
283  for (unsigned int i=0; i!=this->size(); i++)
284  {
285  my_norm += TensorTools::norm_sq(_parent_vector (i + this->i_off()));
286  }
287  return sqrt(my_norm);
288 }
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 maximum absolute value of the elements of this vector, which is the $l_\infty$-norm of a vector.

Definition at line 294 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().

295 {
296  if (!this->size())
297  return 0.;
298  Real my_norm = TensorTools::norm_sq(_parent_vector (this->i_off()));
299 
300  for (unsigned int i=1; i!=this->size(); i++)
301  {
302  Real current = TensorTools::norm_sq(_parent_vector (i + this->i_off()));
303  my_norm = (my_norm > current? my_norm : current);
304  }
305  return sqrt(my_norm);
306 }
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. In case of complex numbers, this returns the maximum Real part.

Definition at line 249 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().

250 {
251  libmesh_assert (this->size());
252  Real my_max = libmesh_real(_parent_vector (this->i_off()));
253 
254  for (unsigned int i=1; i!=this->size(); i++)
255  {
256  Real current = libmesh_real(_parent_vector (i + this->i_off()));
257  my_max = (my_max > current? my_max : current);
258  }
259  return my_max;
260 }
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. In case of complex numbers, this returns the minimum Real part.

Definition at line 232 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().

233 {
234  libmesh_assert (this->size());
235  Real my_min = libmesh_real(_parent_vector (this->i_off()));
236 
237  for (unsigned int i=1; i!=this->size(); i++)
238  {
239  Real current = libmesh_real(_parent_vector (i + this->i_off()));
240  my_min = (my_min < current? my_min : current);
241  }
242  return my_min;
243 }
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 211 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().

212 {
213  libmesh_assert_less (i, this->size());
214  libmesh_assert_less (i + this->i_off(), _parent_vector.size());
215 
216  return _parent_vector (i + this->i_off());
217 }
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 writeable reference.

Definition at line 222 of file dense_subvector.h.

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

223 {
224  libmesh_assert_less (i, this->size());
225  libmesh_assert_less (i + this->i_off(), _parent_vector.size());
226 
227  return _parent_vector (i + this->i_off());
228 }
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 187 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().

189 {
190  _i_off = ioff;
191  _n = n;
192 
193  // Make sure we still fit in the parent vector.
194  libmesh_assert_less_equal ((this->i_off() + this->size()), _parent_vector.size());
195 }
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 subvector to 0.

Implements libMesh::DenseVectorBase< T >.

Definition at line 201 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().

202 {
203  for (unsigned int i=0; i<this->size(); i++)
204  _parent_vector (i + this->i_off()) = 0.;
205 }
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 166 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: