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 
23 namespace MathLib
24 {
28 class LisVector
29 {
30 public:
31  using IndexType = LIS_INT;
32 public:
37  explicit LisVector(std::size_t length);
38 
44  LisVector(std::size_t length, double* data);
45 
47  LisVector(LisVector const& src);
48 
51  virtual ~LisVector();
52 
54  std::size_t size() const;
55 
57  std::size_t getRangeBegin() const { return 0; }
59  std::size_t getRangeEnd() const { return this->size(); }
60 
61  // TODO preliminary
62  void setZero() { lis_vector_set_all(0.0, vec_); }
63 
65  double operator[](IndexType rowId) const { return get(rowId); }
67  double get(IndexType rowId) const
68  {
69  double v = .0;
70  lis_vector_get_value(vec_, rowId, &v);
71  return v;
72  }
73 
75  void set(IndexType rowId, double v)
76  {
77  lis_vector_set_value(LIS_INS_VALUE, rowId, v, vec_);
78  }
79 
81  void add(IndexType rowId, double v)
82  {
83  lis_vector_set_value(LIS_ADD_VALUE, rowId, v, vec_);
84  }
85 
87  void write(const std::string& filename) const;
88 
90  LIS_VECTOR& getRawVector() { return vec_; }
91 
93  template <class T_SUBVEC>
94  void add(const std::vector<IndexType>& pos, const T_SUBVEC& sub_vec)
95  {
96  for (std::size_t i = 0; i < pos.size(); ++i)
97  {
98  this->add(pos[i], sub_vec[i]);
99  }
100  }
101 
103  void copyValues(std::vector<double>& u) const
104  {
105  assert(u.size() == size());
106  lis_vector_get_values(vec_, 0, size(), u.data());
107  }
108 
109 private:
110  LIS_VECTOR vec_;
111 };
112 
113 } // MathLib
Lis vector wrapper class.
Definition: LisVector.h:29
void add(IndexType rowId, double v)
add entry
Definition: LisVector.h:81
LisVector(std::size_t length)
Definition: LisVector.cpp:21
void add(const std::vector< IndexType > &pos, const T_SUBVEC &sub_vec)
Definition: LisVector.h:94
void copyValues(std::vector< double > &u) const
Copy vector values.
Definition: LisVector.h:103
std::size_t getRangeEnd() const
return an end index of the active data range
Definition: LisVector.h:59
void write(const std::string &filename) const
printout this equation for debugging
Definition: LisVector.cpp:56
void set(IndexType rowId, double v)
set entry
Definition: LisVector.h:75
virtual ~LisVector()
Definition: LisVector.cpp:41
std::size_t size() const
return a vector length
Definition: LisVector.cpp:46
double get(IndexType rowId) const
get entry
Definition: LisVector.h:67
double operator[](IndexType rowId) const
access entry
Definition: LisVector.h:65
LIS_VECTOR & getRawVector()
return a raw Lis vector object
Definition: LisVector.h:90
LIS_VECTOR vec_
Definition: LisVector.h:110
std::size_t getRangeBegin() const
return a start index of the active data range
Definition: LisVector.h:57
LIS_INT IndexType
Definition: LisVector.h:31