AMDiS 2.11-git
The Adaptive Multi-Dimensional Simulation Toolbox
 
Loading...
Searching...
No Matches
VectorBackend.hpp
1#pragma once
2
3#include <Eigen/Dense>
4
5#include <dune/common/ftraits.hh>
6
7#include <amdis/Output.hpp>
8#include <amdis/algorithm/ForEach.hpp>
9#include <amdis/algorithm/Transform.hpp>
10#include <amdis/common/FakeContainer.hpp>
11#include <amdis/linearalgebra/VectorBase.hpp>
12#include <amdis/typetree/MultiIndex.hpp>
13
14namespace AMDiS
15{
16 class DefaultIndexDistribution;
17
19 template <class T>
21 : public VectorBase<EigenVector<T>>
22 {
23 using Self = EigenVector;
24
25 public:
27 using BaseVector = Eigen::Matrix<T, Eigen::Dynamic, 1>;
28
30 using value_type = typename BaseVector::Scalar;
31
33 using size_type = typename BaseVector::Index;
34
35 private:
37 using block_type = value_type;
38
40 using field_type = typename Dune::FieldTraits<value_type>::field_type;
41
42 public:
45
47 BaseVector const& vector() const
48 {
49 return vector_;
50 }
51
54 {
55 return vector_;
56 }
57
60 {
61 return vector_.size();
62 }
63
64
66 template <class Basis>
67 void init(Basis const& basis, bool clear)
68 {
69 vector_.resize(basis.dimension());
70 if (clear)
71 vector_.setZero();
72 }
73
74
76 template <class MultiIndex>
77 value_type& at(MultiIndex const& idx)
78 {
79 const size_type i = flatMultiIndex(idx);
80 test_exit_dbg(i < size(), "Index {} out of range [0,{})", i, size());
81 return vector_.coeffRef(i);
82 }
83
85 template <class MultiIndex>
86 value_type const& at(MultiIndex const& idx) const
87 {
88 const size_type i = flatMultiIndex(idx);
89 test_exit_dbg(i < size(), "Index {} out of range [0,{})", i, size());
90 return vector_.coeff(i);
91 }
92
93
96
98 Self& axpy (const value_type& alpha, const Self& x)
99 {
100 vector_ += alpha * x.vector_;
101 return *this;
102 }
103
105 Self& aypx (const value_type& alpha, const Self& x)
106 {
107 vector_ = alpha * vector_ + x.vector_;
108 return *this;
109 }
110
112 void set (const value_type& alpha)
113 {
114 vector_.setConstant(alpha);
115 }
116
118 void scale (const value_type& alpha)
119 {
120 vector_ *= alpha;
121 }
122
124
125 private:
127 BaseVector vector_;
128 };
129
130
131 namespace Recursive
132 {
133 template <class T>
134 struct ForEach<EigenVector<T>> : ForEach<VectorBase<EigenVector<T>>> {};
135
136 template <class T>
137 struct Transform<EigenVector<T>> : Transform<VectorBase<EigenVector<T>>> {};
138
139 template <class T>
140 struct InnerProduct<EigenVector<T>> : InnerProduct<VectorBase<EigenVector<T>>> {};
141
142 } // end namespace Recursive
143} // end namespace AMDiS
Dummy implementation for sequential index "distribution".
Definition IndexDistribution.hpp:7
The basic container that stores a base vector and a corresponding basis.
Definition VectorBackend.hpp:22
value_type & at(MultiIndex const &idx)
Access the entry i of the vector with write-access.
Definition VectorBackend.hpp:77
value_type const & at(MultiIndex const &idx) const
Access the entry i of the vector with read-access.
Definition VectorBackend.hpp:86
typename BaseVector::Index size_type
The index/size - type.
Definition VectorBackend.hpp:33
typename BaseVector::Scalar value_type
The type of the elements of the DOFVector.
Definition VectorBackend.hpp:30
Self & axpy(const value_type &alpha, const Self &x)
Implements *this = *this + alpha * x.
Definition VectorBackend.hpp:98
void scale(const value_type &alpha)
scale all entries by the factor alpha
Definition VectorBackend.hpp:118
size_type size() const
Return the current size of the vector_.
Definition VectorBackend.hpp:59
EigenVector(DefaultIndexDistribution const &)
Constructor. Constructs new BaseVector.
Definition VectorBackend.hpp:44
Self & aypx(const value_type &alpha, const Self &x)
Implements *this = alpha * (*this) + x.
Definition VectorBackend.hpp:105
void init(Basis const &basis, bool clear)
Resize the vector_ to the size s.
Definition VectorBackend.hpp:67
Eigen::Matrix< T, Eigen::Dynamic, 1 > BaseVector
The type of the base vector.
Definition VectorBackend.hpp:27
BaseVector & vector()
Return the data-vector vector_.
Definition VectorBackend.hpp:53
BaseVector const & vector() const
Return the data-vector vector_.
Definition VectorBackend.hpp:47
void set(const value_type &alpha)
Set all entries to alpha.
Definition VectorBackend.hpp:112
CRTP base class for flat vector backends.
Definition VectorBase.hpp:19