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 final
 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 final
 
virtual T & el (const unsigned int i) override final
 
virtual unsigned int size () const override final
 
virtual bool empty () const override final
 
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.

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

164  :
165  _parent_vector(new_parent)
166 {
167  reposition (ioff, n);
168 }
void reposition(const unsigned int ioff, const unsigned int n)
Changes the location of the subvector in the parent vector.
DenseVector< T > & _parent_vector
The parent vector that contains this subvector.

◆ 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
inlinefinaloverridevirtual
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)
inlinefinaloverridevirtual
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
inlinefinaloverridevirtual
Returns
true iff size() is 0.

Reimplemented from libMesh::DenseVectorBase< T >.

Definition at line 93 of file dense_subvector.h.

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

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

94  { return (_n == 0); }
unsigned int _n
The length of this subvector.

◆ 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.

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

99 { return _i_off; }
unsigned int _i_off
The offset into the parent vector.

◆ 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.

References std::abs(), libMesh::index_range(), and libMesh::Real.

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 }
unsigned int i_off() const
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
Definition: type_vector.h:57
DenseVector< T > & _parent_vector
The parent vector that contains this subvector.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:111

◆ 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.

References libMesh::index_range(), libMesh::TensorTools::norm_sq(), libMesh::Real, and std::sqrt().

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 }
unsigned int i_off() const
ADRealEigenVector< T, D, asd > sqrt(const ADRealEigenVector< T, D, asd > &)
Definition: type_vector.h:53
DenseVector< T > & _parent_vector
The parent vector that contains this subvector.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
auto norm_sq(const T &a) -> decltype(std::norm(a))
Definition: tensor_tools.h:104
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:111

◆ 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.

References libMesh::make_range(), libMesh::TensorTools::norm_sq(), libMesh::Real, and std::sqrt().

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 : make_range(1u, 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 }
unsigned int i_off() const
virtual unsigned int size() const override final
ADRealEigenVector< T, D, asd > sqrt(const ADRealEigenVector< T, D, asd > &)
Definition: type_vector.h:53
DenseVector< T > & _parent_vector
The parent vector that contains this subvector.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
auto norm_sq(const T &a) -> decltype(std::norm(a))
Definition: tensor_tools.h:104
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:134

◆ 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.

References libMesh::libmesh_assert(), libMesh::libmesh_real(), libMesh::make_range(), and libMesh::Real.

237 {
238  libmesh_assert (this->size());
239  Real my_max = libmesh_real(_parent_vector (this->i_off()));
240 
241  for (auto i : make_range(1u, 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 }
T libmesh_real(T a)
unsigned int i_off() const
virtual unsigned int size() const override final
libmesh_assert(ctx)
DenseVector< T > & _parent_vector
The parent vector that contains this subvector.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:134

◆ 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.

References libMesh::libmesh_assert(), libMesh::libmesh_real(), libMesh::make_range(), and libMesh::Real.

220 {
221  libmesh_assert (this->size());
222  Real my_min = libmesh_real(_parent_vector (this->i_off()));
223 
224  for (auto i : make_range(1u, 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 }
T libmesh_real(T a)
unsigned int i_off() const
virtual unsigned int size() const override final
libmesh_assert(ctx)
DenseVector< T > & _parent_vector
The parent vector that contains this subvector.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:134

◆ operator()() [1/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 }
unsigned int i_off() const
virtual unsigned int size() const override final
DenseVector< T > & _parent_vector
The parent vector that contains this subvector.

◆ operator()() [2/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 }
unsigned int i_off() const
virtual unsigned int size() const override final
DenseVector< T > & _parent_vector
The parent vector that contains this subvector.

◆ 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.

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

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

69 { return _parent_vector; }
DenseVector< T > & _parent_vector
The parent vector that contains this subvector.

◆ 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.

References libMesh::make_range().

52 {
53  for (auto i : make_range(this->size()))
54  os << std::setw(8)
55  << this->el(i)
56  << std::endl;
57 }
virtual unsigned int size() const =0
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:134
virtual T el(const unsigned int i) const =0

◆ 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.

References libMesh::make_range().

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 : make_range(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 }
virtual unsigned int size() const =0
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:134
virtual T el(const unsigned int i) const =0

◆ 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.

Referenced by assemble_elasticity(), assemble_laplace(), assemble_shell(), assemble_stokes(), and libMesh::DenseSubVector< T >::DenseSubVector().

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 }
unsigned int i_off() const
virtual unsigned int size() const override final
unsigned int _n
The length of this subvector.
DenseVector< T > & _parent_vector
The parent vector that contains this subvector.
unsigned int _i_off
The offset into the parent vector.

◆ size()

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

Implements libMesh::DenseVectorBase< T >.

Definition at line 90 of file dense_subvector.h.

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

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

91  { return _n; }
unsigned int _n
The length of this subvector.

◆ zero()

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

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.

References libMesh::index_range().

189 {
190  for (auto i : index_range(*this))
191  _parent_vector (i + this->i_off()) = 0.;
192 }
unsigned int i_off() const
DenseVector< T > & _parent_vector
The parent vector that contains this subvector.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:111

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< T >::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< T >::empty(), and libMesh::DenseSubVector< T >::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< T >::parent().


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