OGS
MathLib::LisVector Class Reference

Detailed Description

Lis vector wrapper class.

Definition at line 19 of file LisVector.h.

#include <LisVector.h>

Public Types

using IndexType = LIS_INT

Public Member Functions

 LisVector (std::size_t length)
 LisVector (std::size_t length, double *data)
 LisVector (LisVector const &src)
 copy constructor
virtual ~LisVector ()
std::size_t size () const
 return a vector length
std::size_t getRangeBegin () const
 return a start index of the active data range
std::size_t getRangeEnd () const
 return an end index of the active data range
void setZero ()
double operator[] (IndexType rowId) const
 access entry
double get (IndexType rowId) const
 get entry
void set (IndexType rowId, double v)
 set entry
void add (IndexType rowId, double v)
 add entry
void write (const std::string &filename) const
 printout this equation for debugging
LIS_VECTOR & getRawVector ()
 return a raw Lis vector object
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

Private Attributes

LIS_VECTOR vec_

Member Typedef Documentation

◆ IndexType

Definition at line 22 of file LisVector.h.

Constructor & Destructor Documentation

◆ LisVector() [1/3]

MathLib::LisVector::LisVector ( std::size_t length)
explicit

Constructor for initialization of the number of rows

Parameters
lengthnumber of rows

Definition at line 10 of file LisVector.cpp.

11{
12 lis_vector_create(0, &vec_);
13 lis_vector_set_size(vec_, 0, length);
14}
LIS_VECTOR vec_
Definition LisVector.h:130

References vec_.

Referenced by LisVector().

◆ LisVector() [2/3]

MathLib::LisVector::LisVector ( std::size_t length,
double * data )

Constructor using the given raw data

Parameters
lengththe length of the vector
datathe raw data

Definition at line 16 of file LisVector.cpp.

17{
18 lis_vector_create(0, &vec_);
19 lis_vector_set_size(vec_, 0, length);
20 for (std::size_t i = 0; i < length; i++)
21 lis_vector_set_value(LIS_INS_VALUE, i, data[i], vec_);
22}

References vec_.

◆ LisVector() [3/3]

MathLib::LisVector::LisVector ( LisVector const & src)

copy constructor

Definition at line 24 of file LisVector.cpp.

25{
26 lis_vector_duplicate(src.vec_, &vec_);
27 lis_vector_copy(src.vec_, vec_);
28}

References LisVector(), and vec_.

◆ ~LisVector()

MathLib::LisVector::~LisVector ( )
virtual

Definition at line 30 of file LisVector.cpp.

31{
32 lis_vector_destroy(vec_);
33}

References vec_.

Member Function Documentation

◆ add() [1/2]

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

add entries

Definition at line 96 of file LisVector.h.

97 {
98 for (std::size_t i = 0; i < pos.size(); ++i)
99 {
100 add(pos[i], sub_vec[i]);
101 }
102 }
void add(IndexType rowId, double v)
add entry
Definition LisVector.h:73

References add().

◆ add() [2/2]

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

add entry

Definition at line 73 of file LisVector.h.

74 {
75 lis_vector_set_value(LIS_ADD_VALUE, rowId, v, vec_);
76 }
static const double v

References MathLib::v, and vec_.

Referenced by add().

◆ copyValues() [1/2]

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

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 116 of file LisVector.h.

117 {
118 if (u.size() != size())
119 {
120 OGS_FATAL(
121 "LisVector::copyValues() size mismatch. Trying to copy a "
122 "vector "
123 "of size {:d} to a span of size {:d}.",
124 size(), u.size());
125 }
126 lis_vector_get_values(vec_, 0, size(), u.data());
127 }
#define OGS_FATAL(...)
Definition Error.h:19
std::size_t size() const
return a vector length
Definition LisVector.cpp:35
static const double u

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

◆ copyValues() [2/2]

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

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 107 of file LisVector.h.

108 {
109 u.resize(size());
110 lis_vector_get_values(vec_, 0, size(), u.data());
111 }

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

◆ get()

double MathLib::LisVector::get ( IndexType rowId) const
inline

get entry

Definition at line 59 of file LisVector.h.

60 {
61 double v = .0;
62 lis_vector_get_value(vec_, rowId, &v);
63 return v;
64 }

References MathLib::v, and vec_.

Referenced by operator[]().

◆ getRangeBegin()

std::size_t MathLib::LisVector::getRangeBegin ( ) const
inline

return a start index of the active data range

Definition at line 49 of file LisVector.h.

49{ return 0; }

◆ getRangeEnd()

std::size_t MathLib::LisVector::getRangeEnd ( ) const
inline

return an end index of the active data range

Definition at line 51 of file LisVector.h.

51{ return this->size(); }

References size().

◆ getRawVector()

LIS_VECTOR & MathLib::LisVector::getRawVector ( )
inline

return a raw Lis vector object

Definition at line 82 of file LisVector.h.

82{ return vec_; }

References vec_.

Referenced by MathLib::EigenLisLinearSolver::solve().

◆ operator[]()

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

access entry

Definition at line 57 of file LisVector.h.

57{ return get(rowId); }
double get(IndexType rowId) const
get entry
Definition LisVector.h:59

References get().

◆ set() [1/2]

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

set entries

Definition at line 86 of file LisVector.h.

87 {
88 for (std::size_t i = 0; i < pos.size(); ++i)
89 {
90 set(pos[i], sub_vec[i]);
91 }
92 }
void set(IndexType rowId, double v)
set entry
Definition LisVector.h:67

References set().

◆ set() [2/2]

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

set entry

Definition at line 67 of file LisVector.h.

68 {
69 lis_vector_set_value(LIS_INS_VALUE, rowId, v, vec_);
70 }

References MathLib::v, and vec_.

Referenced by set().

◆ setZero()

void MathLib::LisVector::setZero ( )
inline

Definition at line 54 of file LisVector.h.

54{ lis_vector_set_all(0.0, vec_); }

References vec_.

◆ size()

std::size_t MathLib::LisVector::size ( ) const

return a vector length

Definition at line 35 of file LisVector.cpp.

36{
37 IndexType dummy;
39 int const ierr = lis_vector_get_size(vec_, &dummy, &size);
40 checkLisError(ierr);
41 assert(size >= 0); // For safe implicit conversion to std::size_t.
42 return size;
43}
bool checkLisError(int err)
Definition LisCheck.h:20

References MathLib::checkLisError(), size(), and vec_.

Referenced by copyValues(), copyValues(), getRangeEnd(), size(), and MathLib::EigenLisLinearSolver::solve().

◆ write()

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

printout this equation for debugging

Definition at line 45 of file LisVector.cpp.

46{
47 lis_output_vector(vec_, LIS_FMT_PLAIN, const_cast<char*>(filename.c_str()));
48}

References vec_.

Member Data Documentation

◆ vec_

LIS_VECTOR MathLib::LisVector::vec_
private

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