OGS
LisVector.h
Go to the documentation of this file.
1
15#pragma once
16
17#include <lis.h>
18
19#include <cassert>
20#include <string>
21#include <vector>
22
23namespace MathLib
24{
29{
30public:
31 using IndexType = LIS_INT;
32
33public:
38 explicit LisVector(std::size_t length);
39
45 LisVector(std::size_t length, double* data);
46
48 LisVector(LisVector const& src);
49
52 virtual ~LisVector();
53
55 std::size_t size() const;
56
58 std::size_t getRangeBegin() const { return 0; }
60 std::size_t getRangeEnd() const { return this->size(); }
61
62 // TODO preliminary
63 void setZero() { lis_vector_set_all(0.0, vec_); }
64
66 double operator[](IndexType rowId) const { return get(rowId); }
68 double get(IndexType rowId) const
69 {
70 double v = .0;
71 lis_vector_get_value(vec_, rowId, &v);
72 return v;
73 }
74
76 void set(IndexType rowId, double v)
77 {
78 lis_vector_set_value(LIS_INS_VALUE, rowId, v, vec_);
79 }
80
82 void add(IndexType rowId, double v)
83 {
84 lis_vector_set_value(LIS_ADD_VALUE, rowId, v, vec_);
85 }
86
88 void write(const std::string& filename) const;
89
91 LIS_VECTOR& getRawVector() { return vec_; }
92
94 template <class T_SUBVEC>
95 void set(const std::vector<IndexType>& pos, const T_SUBVEC& sub_vec)
96 {
97 for (std::size_t i = 0; i < pos.size(); ++i)
98 {
99 set(pos[i], sub_vec[i]);
100 }
101 }
102
104 template <class T_SUBVEC>
105 void add(const std::vector<IndexType>& pos, const T_SUBVEC& sub_vec)
106 {
107 for (std::size_t i = 0; i < pos.size(); ++i)
108 {
109 add(pos[i], sub_vec[i]);
110 }
111 }
112
116 void copyValues(std::vector<double>& u) const
117 {
118 u.resize(size());
119 lis_vector_get_values(vec_, 0, size(), u.data());
120 }
121
122private:
123 LIS_VECTOR vec_;
124};
125
126} // namespace MathLib
Lis vector wrapper class.
Definition LisVector.h:29
void add(IndexType rowId, double v)
add entry
Definition LisVector.h:82
LisVector(std::size_t length)
Definition LisVector.cpp:21
void add(const std::vector< IndexType > &pos, const T_SUBVEC &sub_vec)
add entries
Definition LisVector.h:105
void copyValues(std::vector< double > &u) const
Definition LisVector.h:116
std::size_t getRangeEnd() const
return an end index of the active data range
Definition LisVector.h:60
void write(const std::string &filename) const
printout this equation for debugging
Definition LisVector.cpp:56
void set(const std::vector< IndexType > &pos, const T_SUBVEC &sub_vec)
set entries
Definition LisVector.h:95
void set(IndexType rowId, double v)
set entry
Definition LisVector.h:76
virtual ~LisVector()
Definition LisVector.cpp:41
LIS_VECTOR & getRawVector()
return a raw Lis vector object
Definition LisVector.h:91
std::size_t size() const
return a vector length
Definition LisVector.cpp:46
double get(IndexType rowId) const
get entry
Definition LisVector.h:68
double operator[](IndexType rowId) const
access entry
Definition LisVector.h:66
LIS_VECTOR vec_
Definition LisVector.h:123
std::size_t getRangeBegin() const
return a start index of the active data range
Definition LisVector.h:58
static const double u
static const double v