libMesh
Public Member Functions | Private Attributes | List of all members
libMesh::DenseSubVector< T > Class Template Reference

Defines a dense subvector for use in finite element computations. More...

#include <dense_subvector.h>

Inheritance diagram for libMesh::DenseSubVector< T >:
[legend]

Public Member Functions

 DenseSubVector (DenseVector< T > &new_parent, const unsigned int ioff=0, const unsigned int n=0)
 Constructor. More...
 
 DenseSubVector (DenseSubVector &&)=default
 The 5 special functions can be defaulted for this class, as it does not manage any memory itself. More...
 
 DenseSubVector (const DenseSubVector &)=default
 
DenseSubVectoroperator= (const DenseSubVector &)=default
 
DenseSubVectoroperator= (DenseSubVector &&)=default
 
virtual ~DenseSubVector ()=default
 
DenseVector< T > & parent ()
 
virtual void zero () override
 Set every element in the vector to 0. More...
 
const T & operator() (const unsigned int i) const
 
T & operator() (const unsigned int i)
 
virtual T el (const unsigned int i) const override
 
virtual T & el (const unsigned int i) override
 
virtual unsigned int size () const override
 
virtual bool empty () const override
 
unsigned int i_off () const
 
void reposition (const unsigned int ioff, const unsigned int n)
 Changes the location of the subvector in the parent vector. More...
 
Real min () const
 
Real max () const
 
Real l1_norm () const
 
Real l2_norm () const
 
Real linfty_norm () const
 
void print (std::ostream &os) const
 Pretty-print the vector to stdout. More...
 
void print_scientific (std::ostream &os, unsigned precision=8) const
 Prints the entries of the vector with additional decimal places in scientific notation. More...
 

Private Attributes

DenseVector< T > & _parent_vector
 The parent vector that contains this subvector. More...
 
unsigned int _n
 The length of this subvector. More...
 
unsigned int _i_off
 The offset into the parent vector. More...
 

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

Constructor & Destructor Documentation

◆ DenseSubVector() [1/3]

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

164  :
165  _parent_vector(new_parent)
166 {
167  reposition (ioff, n);
168 }

◆ DenseSubVector() [2/3]

template<typename T>
libMesh::DenseSubVector< T >::DenseSubVector ( DenseSubVector< T > &&  )
default

The 5 special functions can be defaulted for this class, as it does not manage any memory itself.

◆ DenseSubVector() [3/3]

template<typename T>
libMesh::DenseSubVector< T >::DenseSubVector ( const DenseSubVector< T > &  )
default

◆ ~DenseSubVector()

template<typename T>
virtual libMesh::DenseSubVector< T >::~DenseSubVector ( )
virtualdefault

Member Function Documentation

◆ el() [1/2]

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

Implements libMesh::DenseVectorBase< T >.

Definition at line 84 of file dense_subvector.h.

85  { return (*this)(i); }

◆ el() [2/2]

template<typename T>
virtual T& libMesh::DenseSubVector< T >::el ( const unsigned int  i)
inlineoverridevirtual
Returns
The (i) element of the vector as a writable reference.

Implements libMesh::DenseVectorBase< T >.

Definition at line 87 of file dense_subvector.h.

88  { return (*this)(i); }

◆ empty()

template<typename T>
virtual bool libMesh::DenseSubVector< T >::empty ( ) const
inlineoverridevirtual
Returns
true iff size() is 0.

Reimplemented from libMesh::DenseVectorBase< T >.

Definition at line 93 of file dense_subvector.h.

94  { return (_n == 0); }

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

◆ i_off()

template<typename T>
unsigned int libMesh::DenseSubVector< T >::i_off ( ) const
inline
Returns
The row offset into the parent vector.

Definition at line 99 of file dense_subvector.h.

99 { return _i_off; }

◆ l1_norm()

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

254 {
255  Real my_norm = 0.;
256  for (auto i : index_range(*this))
257  {
258  my_norm += std::abs(_parent_vector (i + this->i_off()));
259  }
260  return my_norm;
261 }

◆ l2_norm()

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

268 {
269  Real my_norm = 0.;
270  for (auto i : index_range(*this))
271  {
272  my_norm += TensorTools::norm_sq(_parent_vector (i + this->i_off()));
273  }
274  return sqrt(my_norm);
275 }

◆ linfty_norm()

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

282 {
283  if (!this->size())
284  return 0.;
285  Real my_norm = TensorTools::norm_sq(_parent_vector (this->i_off()));
286 
287  for (auto i : IntRange<unsigned int>(1, this->size()))
288  {
289  Real current = TensorTools::norm_sq(_parent_vector (i + this->i_off()));
290  my_norm = (my_norm > current? my_norm : current);
291  }
292  return sqrt(my_norm);
293 }

◆ max()

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

237 {
238  libmesh_assert (this->size());
239  Real my_max = libmesh_real(_parent_vector (this->i_off()));
240 
241  for (auto i : IntRange<unsigned int>(1, this->size()))
242  {
243  Real current = libmesh_real(_parent_vector (i + this->i_off()));
244  my_max = (my_max > current? my_max : current);
245  }
246  return my_max;
247 }

◆ min()

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

220 {
221  libmesh_assert (this->size());
222  Real my_min = libmesh_real(_parent_vector (this->i_off()));
223 
224  for (auto i : IntRange<unsigned int>(1, this->size()))
225  {
226  Real current = libmesh_real(_parent_vector (i + this->i_off()));
227  my_min = (my_min < current? my_min : current);
228  }
229  return my_min;
230 }

◆ operator()() [1/2]

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

210 {
211  libmesh_assert_less (i, this->size());
212  libmesh_assert_less (i + this->i_off(), _parent_vector.size());
213 
214  return _parent_vector (i + this->i_off());
215 }

◆ operator()() [2/2]

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

199 {
200  libmesh_assert_less (i, this->size());
201  libmesh_assert_less (i + this->i_off(), _parent_vector.size());
202 
203  return _parent_vector (i + this->i_off());
204 }

◆ operator=() [1/2]

template<typename T>
DenseSubVector& libMesh::DenseSubVector< T >::operator= ( const DenseSubVector< T > &  )
default

◆ operator=() [2/2]

template<typename T>
DenseSubVector& libMesh::DenseSubVector< T >::operator= ( DenseSubVector< T > &&  )
default

◆ parent()

template<typename T>
DenseVector<T>& libMesh::DenseSubVector< T >::parent ( )
inline
Returns
A reference to the parent vector.

Definition at line 69 of file dense_subvector.h.

69 { return _parent_vector; }

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

◆ print()

template<typename T >
void libMesh::DenseVectorBase< T >::print ( std::ostream &  os) const
inherited

Pretty-print the vector to stdout.

Definition at line 51 of file dense_vector_base.C.

52 {
53  for (auto i : IntRange<int>(0, this->size()))
54  os << std::setw(8)
55  << this->el(i)
56  << std::endl;
57 }

◆ print_scientific()

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 31 of file dense_vector_base.C.

32 {
33  // save the initial format flags
34  std::ios_base::fmtflags os_flags = os.flags();
35 
36  // Print the vector entries.
37  for (auto i : IntRange<int>(0, this->size()))
38  os << std::setw(10)
39  << std::scientific
40  << std::setprecision(precision)
41  << this->el(i)
42  << std::endl;
43 
44  // reset the original format flags
45  os.flags(os_flags);
46 }

◆ reposition()

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

176 {
177  _i_off = ioff;
178  _n = n;
179 
180  // Make sure we still fit in the parent vector.
181  libmesh_assert_less_equal ((this->i_off() + this->size()), _parent_vector.size());
182 }

Referenced by assemble_elasticity(), assemble_laplace(), assemble_shell(), and assemble_stokes().

◆ size()

template<typename T>
virtual unsigned int libMesh::DenseSubVector< T >::size ( ) const
inlineoverridevirtual
Returns
The size of the vector.

Implements libMesh::DenseVectorBase< T >.

Definition at line 90 of file dense_subvector.h.

91  { return _n; }

Referenced by libMesh::index_range(), and libMesh::NumericVector< Number >::insert().

◆ zero()

template<typename T >
void libMesh::DenseSubVector< T >::zero ( )
inlineoverridevirtual

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

189 {
190  for (auto i : index_range(*this))
191  _parent_vector (i + this->i_off()) = 0.;
192 }

Member Data Documentation

◆ _i_off

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

The offset into the parent vector.

Definition at line 153 of file dense_subvector.h.

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

◆ _n

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

The length of this subvector.

Definition at line 148 of file dense_subvector.h.

Referenced by libMesh::DenseSubVector< Number >::empty(), and libMesh::DenseSubVector< Number >::size().

◆ _parent_vector

template<typename T>
DenseVector<T>& libMesh::DenseSubVector< T >::_parent_vector
private

The parent vector that contains this subvector.

Definition at line 143 of file dense_subvector.h.

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


The documentation for this class was generated from the following file:
libMesh::DenseSubVector::_parent_vector
DenseVector< T > & _parent_vector
The parent vector that contains this subvector.
Definition: dense_subvector.h:143
libMesh::libmesh_real
T libmesh_real(T a)
Definition: libmesh_common.h:166
libMesh::DenseSubVector::i_off
unsigned int i_off() const
Definition: dense_subvector.h:99
libMesh::index_range
IntRange< std::size_t > index_range(const std::vector< T > &vec)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:106
std::sqrt
MetaPhysicL::DualNumber< T, D > sqrt(const MetaPhysicL::DualNumber< T, D > &in)
libMesh::DenseVectorBase::el
virtual T el(const unsigned int i) const =0
libMesh::libmesh_assert
libmesh_assert(ctx)
std::abs
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
libMesh::DenseSubVector::size
virtual unsigned int size() const override
Definition: dense_subvector.h:90
libMesh::DenseVectorBase::size
virtual unsigned int size() const =0
libMesh::TensorTools::norm_sq
T norm_sq(std::complex< T > a)
Definition: tensor_tools.h:85
libMesh::DenseSubVector::reposition
void reposition(const unsigned int ioff, const unsigned int n)
Changes the location of the subvector in the parent vector.
Definition: dense_subvector.h:174
libMesh::DenseSubVector::_n
unsigned int _n
The length of this subvector.
Definition: dense_subvector.h:148
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::DenseSubVector::_i_off
unsigned int _i_off
The offset into the parent vector.
Definition: dense_subvector.h:153