OGS
MathLib::EigenVector Class Referencefinal

Detailed Description

Global vector based on Eigen vector.

Definition at line 24 of file EigenVector.h.

#include <EigenVector.h>

Public Types

using RawVectorType = Eigen::VectorXd
 
using IndexType = Eigen::SparseMatrix<double>::Index
 

Public Member Functions

 EigenVector ()=default
 
 EigenVector (IndexType length)
 
IndexType size () const
 return a vector length
 
IndexType getRangeEnd () const
 return an end index of the active data range
 
void setZero ()
 
double constoperator[] (IndexType rowId) const
 access entry
 
doubleoperator[] (IndexType rowId)
 
double get (IndexType rowId) const
 get entry
 
std::vector< doubleget (std::vector< IndexType > const &indices) const
 get entries
 
void set (IndexType rowId, double v)
 set entry
 
void add (IndexType rowId, double v)
 add entry
 
template<class T_SUBVEC >
void set (const std::vector< IndexType > &pos, const T_SUBVEC &sub_vec)
 set entries
 
template<class T_SUBVEC >
void add (const std::vector< IndexType > &pos, const T_SUBVEC &sub_vec)
 add entries
 
void copyValues (std::vector< double > &u) const
 
void write (const std::string &filename) const
 write this vector to a file for debugging
 
RawVectorTypegetRawVector ()
 return a raw Eigen vector object
 
const RawVectorTypegetRawVector () const
 return a raw Eigen vector object
 

Static Public Member Functions

static constexpr IndexType getRangeBegin ()
 return a start index of the active data range
 

Private Attributes

RawVectorType vec_
 

Member Typedef Documentation

◆ IndexType

using MathLib::EigenVector::IndexType = Eigen::SparseMatrix<double>::Index

Definition at line 32 of file EigenVector.h.

◆ RawVectorType

Definition at line 27 of file EigenVector.h.

Constructor & Destructor Documentation

◆ EigenVector() [1/2]

MathLib::EigenVector::EigenVector ( )
default

◆ EigenVector() [2/2]

MathLib::EigenVector::EigenVector ( IndexType length)
inlineexplicit

Constructor for initialization of the number of rows

Parameters
lengthnumber of rows

Definition at line 39 of file EigenVector.h.

39: vec_(length) {}
RawVectorType vec_

Member Function Documentation

◆ add() [1/2]

template<class T_SUBVEC >
void MathLib::EigenVector::add ( const std::vector< IndexType > & pos,
const T_SUBVEC & sub_vec )
inline

add entries

Definition at line 91 of file EigenVector.h.

92 {
93 auto const length = pos.size();
94 for (std::size_t i = 0; i < length; ++i)
95 {
96 add(pos[i], sub_vec[i]);
97 }
98 }
void add(IndexType rowId, double v)
add entry
Definition EigenVector.h:76
void set(IndexType rowId, double v)
set entry
Definition EigenVector.h:73

References add(), and set().

◆ add() [2/2]

◆ copyValues()

void MathLib::EigenVector::copyValues ( std::vector< double > & u) const

Copy local entries to a vector.

Parameters
ua vector for the values of local entries. It will be resized to hold the current vector data.

Definition at line 21 of file EigenVector.cpp.

22{
23 u.resize(size());
24 toVector(u) = vec_;
25}
IndexType size() const
return a vector length
Definition EigenVector.h:42
Eigen::Map< const Vector > toVector(std::vector< double > const &data, Eigen::VectorXd::Index size)
Creates an Eigen mapped vector from the given data vector.
static const double u

References size(), MathLib::toVector(), MathLib::u, and vec_.

Referenced by ProcessLib::PhaseField::PhaseFieldProcess< DisplacementDim >::assembleWithJacobianConcreteProcess(), ProcessLib::SmallDeformationNonlocal::SmallDeformationNonlocalProcess< DisplacementDim >::assembleWithJacobianConcreteProcess(), and copySolutionVector().

◆ get() [1/2]

◆ get() [2/2]

std::vector< double > MathLib::EigenVector::get ( std::vector< IndexType > const & indices) const
inline

get entries

Definition at line 61 of file EigenVector.h.

62 {
63 std::vector<double> local_x;
64 local_x.reserve(indices.size());
65
66 transform(cbegin(indices), cend(indices), back_inserter(local_x),
67 [&](auto const i) { return vec_[i]; });
68
69 return local_x;
70 }

References set(), and vec_.

◆ getRangeBegin()

static constexpr IndexType MathLib::EigenVector::getRangeBegin ( )
inlinestaticconstexpr

return a start index of the active data range

Definition at line 45 of file EigenVector.h.

45{ return 0; }

Referenced by getIndexForComponentInSolutionVector().

◆ getRangeEnd()

IndexType MathLib::EigenVector::getRangeEnd ( ) const
inline

return an end index of the active data range

Definition at line 48 of file EigenVector.h.

48{ return size(); }

References size().

Referenced by getIndexForComponentInSolutionVector().

◆ getRawVector() [1/2]

RawVectorType & MathLib::EigenVector::getRawVector ( )
inline

return a raw Eigen vector object

Definition at line 111 of file EigenVector.h.

111{ return vec_; }

References vec_.

Referenced by MathLib::applyKnownSolution(), MathLib::EigenLisLinearSolver::solve(), MathLib::EigenLinearSolver::solve(), and MathLib::EigenLinearSolver::solve().

◆ getRawVector() [2/2]

const RawVectorType & MathLib::EigenVector::getRawVector ( ) const
inline

return a raw Eigen vector object

Definition at line 114 of file EigenVector.h.

114{ return vec_; }

References vec_.

◆ operator[]() [1/2]

Definition at line 55 of file EigenVector.h.

55{ return vec_[rowId]; }

References set(), and vec_.

◆ operator[]() [2/2]

access entry

Definition at line 54 of file EigenVector.h.

54{ return vec_[rowId]; }

References set(), and vec_.

◆ set() [1/2]

template<class T_SUBVEC >
void MathLib::EigenVector::set ( const std::vector< IndexType > & pos,
const T_SUBVEC & sub_vec )
inline

set entries

Definition at line 80 of file EigenVector.h.

81 {
82 auto const length = pos.size();
83 for (std::size_t i = 0; i < length; ++i)
84 {
85 set(pos[i], sub_vec[i]);
86 }
87 }

References set().

◆ set() [2/2]

void MathLib::EigenVector::set ( IndexType rowId,
double v )
inline

◆ setZero()

◆ size()

IndexType MathLib::EigenVector::size ( ) const
inline

return a vector length

Definition at line 42 of file EigenVector.h.

42{ return static_cast<IndexType>(vec_.size()); }
Eigen::SparseMatrix< double >::Index IndexType
Definition EigenVector.h:32

References vec_.

Referenced by copyValues(), and getRangeEnd().

◆ write()

void MathLib::EigenVector::write ( const std::string & filename) const

write this vector to a file for debugging

Definition at line 28 of file EigenVector.cpp.

29{
30 std::ofstream os(filename);
31 os << vec_;
32}

References set(), and vec_.

Member Data Documentation

◆ vec_

RawVectorType MathLib::EigenVector::vec_
private

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