Loading [MathJax]/extensions/tex2jax.js
OGS
MathLib::EigenVector Class Referencefinal

Detailed Description

Global vector based on Eigen vector.

Definition at line 25 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 const & operator[] (IndexType rowId) const
 access entry
 
double & operator[] (IndexType rowId)
 
double get (IndexType rowId) const
 get entry
 
std::vector< double > get (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 copyValues (std::span< 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 33 of file EigenVector.h.

◆ RawVectorType

using MathLib::EigenVector::RawVectorType = Eigen::VectorXd

Definition at line 28 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 40 of file EigenVector.h.

40: 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 92 of file EigenVector.h.

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

References add().

◆ add() [2/2]

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

add entry

Definition at line 77 of file EigenVector.h.

77{ vec_[rowId] += v; }
static const double v

References MathLib::v, and vec_.

Referenced by add(), ProcessLib::BoundaryConditionAndSourceTerm::Python::BcAndStLocalAssemblerImpl< BcOrStData, ShapeFunction, LowerOrderShapeFunction, GlobalDim >::assemble(), ProcessLib::HCNonAdvectiveFreeComponentFlowBoundaryConditionLocalAssembler< ShapeFunction, GlobalDim >::assemble(), ProcessLib::NeumannBoundaryConditionLocalAssembler< ShapeFunction, GlobalDim >::assemble(), ProcessLib::NormalTractionBoundaryCondition::NormalTractionBoundaryConditionLocalAssembler< ShapeFunctionDisplacement, GlobalDim >::assemble(), ProcessLib::RobinBoundaryConditionLocalAssembler< ShapeFunction, GlobalDim >::assemble(), ProcessLib::VariableDependentNeumannBoundaryConditionLocalAssembler< ShapeFunction, GlobalDim >::assemble(), ProcessLib::VectorMatrixAssembler::assemble(), ProcessLib::WellboreCompensateNeumannBoundaryConditionLocalAssembler< ShapeFunction, GlobalDim >::assemble(), ProcessLib::ComponentTransport::ComponentTransportLocalAssemblerInterface::assembleReactionEquation(), ProcessLib::VectorMatrixAssembler::assembleWithJacobian(), NumLib::detail::calculateFluxCorrectedTransportPETSc(), NumLib::LocalLinearLeastSquaresExtrapolator::extrapolateElement(), ProcessLib::AnchorTerm< GlobalDim >::integrate(), ProcessLib::EmbeddedAnchor< GlobalDim >::integrate(), ProcessLib::NodalSourceTerm::integrate(), ProcessLib::VolumetricSourceTermLocalAssembler< ShapeFunction, GlobalDim >::integrate(), and ProcessLib::SmallDeformation::writeMaterialForces().

◆ copyValues() [1/2]

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

Copy local entries to a span.

Parameters
ua span for the values of local entries of correct size. If the sizes mismatch, exception will be thrown.

Definition at line 30 of file EigenVector.cpp.

31{
32 if (u.size() != static_cast<std::size_t>(vec_.size()))
33 {
35 "EigenVector copy values; size mismatch. Trying to copy a vector "
36 "of size {:d} to a span of size {:d}.",
37 size(), u.size());
38 }
39 ranges::copy(vec_, u.begin());
40}
#define OGS_FATAL(...)
Definition Error.h:26
IndexType size() const
return a vector length
Definition EigenVector.h:43
static const double u

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

◆ copyValues() [2/2]

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 24 of file EigenVector.cpp.

25{
26 u.resize(size());
27 toVector(u) = vec_;
28}
Eigen::Map< const Vector > toVector(std::vector< double > const &data, Eigen::VectorXd::Index size)
Creates an Eigen mapped vector from the given data vector.

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

Referenced by ProcessLib::HMPhaseField::HMPhaseFieldProcess< DisplacementDim >::assembleWithJacobianConcreteProcess(), ProcessLib::PhaseField::PhaseFieldProcess< 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 62 of file EigenVector.h.

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

References vec_.

◆ getRangeBegin()

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

return a start index of the active data range

Definition at line 46 of file EigenVector.h.

46{ return 0; }

Referenced by getIndexForComponentInSolutionVector().

◆ getRangeEnd()

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

return an end index of the active data range

Definition at line 49 of file EigenVector.h.

49{ return size(); }

References size().

Referenced by getIndexForComponentInSolutionVector().

◆ getRawVector() [1/2]

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

return a raw Eigen vector object

Definition at line 117 of file EigenVector.h.

117{ return vec_; }

References vec_.

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

◆ getRawVector() [2/2]

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

return a raw Eigen vector object

Definition at line 120 of file EigenVector.h.

120{ return vec_; }

References vec_.

◆ operator[]() [1/2]

double & MathLib::EigenVector::operator[] ( IndexType rowId)
inline

Definition at line 56 of file EigenVector.h.

56{ return vec_[rowId]; }

References vec_.

◆ operator[]() [2/2]

double const & MathLib::EigenVector::operator[] ( IndexType rowId) const
inline

access entry

Definition at line 55 of file EigenVector.h.

55{ return vec_[rowId]; }

References 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 81 of file EigenVector.h.

82 {
83 auto const length = pos.size();
84 for (std::size_t i = 0; i < length; ++i)
85 {
86 set(pos[i], sub_vec[i]);
87 }
88 }
void set(IndexType rowId, double v)
set entry
Definition EigenVector.h:74

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

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

References vec_.

Referenced by copyValues(), copyValues(), and getRangeEnd().

◆ write()

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

write this vector to a file for debugging

Definition at line 43 of file EigenVector.cpp.

44{
45 std::ofstream os(filename);
46 os << vec_;
47}

References vec_.

Member Data Documentation

◆ vec_

RawVectorType MathLib::EigenVector::vec_
private

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