OGS
MathLib::EigenVector Class Referencefinal

Detailed Description

Global vector based on Eigen vector.

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

◆ RawVectorType

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

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

33: vec_(length) {}
RawVectorType vec_

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

86 {
87 auto const length = pos.size();
88 for (std::size_t i = 0; i < length; ++i)
89 {
90 add(pos[i], sub_vec[i]);
91 }
92 }
void add(IndexType rowId, double v)
add entry
Definition EigenVector.h:70

References add().

◆ add() [2/2]

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

add entry

Definition at line 70 of file EigenVector.h.

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

References MathLib::v, and vec_.

Referenced by add(), ProcessLib::ReleaseNodalForce::applyNaturalBC(), 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 23 of file EigenVector.cpp.

24{
25 if (u.size() != static_cast<std::size_t>(vec_.size()))
26 {
28 "EigenVector copy values; size mismatch. Trying to copy a vector "
29 "of size {:d} to a span of size {:d}.",
30 size(), u.size());
31 }
32 ranges::copy(vec_, u.begin());
33}
#define OGS_FATAL(...)
Definition Error.h:19
IndexType size() const
return a vector length
Definition EigenVector.h:36
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 17 of file EigenVector.cpp.

18{
19 u.resize(size());
20 toVector(u) = vec_;
21}
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 55 of file EigenVector.h.

56 {
57 std::vector<double> local_x;
58 local_x.reserve(indices.size());
59
60 transform(cbegin(indices), cend(indices), back_inserter(local_x),
61 [&](auto const i) { return vec_[i]; });
62
63 return local_x;
64 }

References vec_.

◆ getRangeBegin()

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

return a start index of the active data range

Definition at line 39 of file EigenVector.h.

39{ return 0; }

Referenced by getIndexForComponentInSolutionVector().

◆ getRangeEnd()

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

return an end index of the active data range

Definition at line 42 of file EigenVector.h.

42{ return size(); }

References size().

Referenced by getIndexForComponentInSolutionVector().

◆ getRawVector() [1/2]

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

return a raw Eigen vector object

Definition at line 110 of file EigenVector.h.

110{ 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 113 of file EigenVector.h.

113{ return vec_; }

References vec_.

◆ operator[]() [1/2]

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

Definition at line 49 of file EigenVector.h.

49{ return vec_[rowId]; }

References vec_.

◆ operator[]() [2/2]

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

access entry

Definition at line 48 of file EigenVector.h.

48{ 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 74 of file EigenVector.h.

75 {
76 auto const length = pos.size();
77 for (std::size_t i = 0; i < length; ++i)
78 {
79 set(pos[i], sub_vec[i]);
80 }
81 }
void set(IndexType rowId, double v)
set entry
Definition EigenVector.h:67

References set().

◆ set() [2/2]

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

◆ setZero()

void MathLib::EigenVector::setZero ( )
inline

◆ size()

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

return a vector length

Definition at line 36 of file EigenVector.h.

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

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

37{
38 std::ofstream os(filename);
39 os << vec_;
40}

References vec_.

Member Data Documentation

◆ vec_

RawVectorType MathLib::EigenVector::vec_
private

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