AMDiS 2.11-git
The Adaptive Multi-Dimensional Simulation Toolbox
 
Loading...
Searching...
No Matches
VectorBackend.hpp
1#pragma once
2
3#include <boost/numeric/mtl/vector/dense_vector.hpp>
4
5#include <dune/common/ftraits.hh>
6
7#include <amdis/Output.hpp>
8#include <amdis/common/FakeContainer.hpp>
9#include <amdis/linearalgebra/VectorBase.hpp>
10#include <amdis/typetree/MultiIndex.hpp>
11
12namespace AMDiS
13{
14 class DefaultIndexDistribution;
15
17 template <class T>
19 : public VectorBase<MTLVector<T>>
20 {
21 using Self = MTLVector;
22
23 public:
25 using BaseVector = mtl::dense_vector<T>;
26
28 using value_type = typename BaseVector::value_type;
29
31 using size_type = typename BaseVector::size_type;
32
33 private:
35 using block_type = value_type;
36
38 using field_type = typename Dune::FieldTraits<value_type>::field_type;
39
40 public:
43
45 BaseVector const& vector() const
46 {
47 return vector_;
48 }
49
52 {
53 return vector_;
54 }
55
57 std::size_t size() const
58 {
59 return mtl::vec::size(vector_);
60 }
61
62
64 template <class Basis>
65 void init(Basis const& basis, bool clear)
66 {
67 vector_.change_dim(basis.dimension());
68 if (clear)
69 set_to_zero(vector_);
70 }
71
73 template <class MultiIndex>
74 value_type& at(MultiIndex const& idx)
75 {
76 const size_type i = flatMultiIndex(idx);
77 test_exit_dbg(i < size(),"Index {} out of range [0,{})", i, size());
78 return vector_[i];
79 }
80
82 template <class MultiIndex>
83 value_type const& at(MultiIndex const& idx) const
84 {
85 const size_type i = flatMultiIndex(idx);
86 test_exit_dbg(i < size(), "Index {} out of range [0,{})", i, size());
87 return vector_[i];
88 }
89
92
94 Self& axpy (const value_type& alpha, const Self& x)
95 {
96 vector_ += alpha * x.vector_;
97 return *this;
98 }
99
101 Self& aypx (const value_type& alpha, const Self& x)
102 {
103 vector_ = alpha * vector_ + x.vector_;
104 return *this;
105 }
106
108 void set (const value_type& alpha)
109 {
110 vector_ = alpha;
111 }
112
114 void scale (const value_type& alpha)
115 {
116 vector_ *= alpha;
117 }
118
120
121 private:
123 BaseVector vector_;
124 };
125
126
127 namespace Recursive
128 {
129 template <class T>
130 struct ForEach<MTLVector<T>> : ForEach<VectorBase<MTLVector<T>>> {};
131
132 template <class T>
133 struct Transform<MTLVector<T>> : Transform<VectorBase<MTLVector<T>>> {};
134
135 template <class T>
136 struct InnerProduct<MTLVector<T>> : InnerProduct<VectorBase<MTLVector<T>>> {};
137
138 } // end namespace Recursive
139} // end namespace AMDiS
Dummy implementation for sequential index "distribution".
Definition IndexDistribution.hpp:7
The basic container that stores a base vector data.
Definition VectorBackend.hpp:20
value_type & at(MultiIndex const &idx)
Access the entry i of the vector with read-access.
Definition VectorBackend.hpp:74
value_type const & at(MultiIndex const &idx) const
Access the entry i of the vector with read-access.
Definition VectorBackend.hpp:83
typename BaseVector::value_type value_type
The type of the elements of the DOFVector.
Definition VectorBackend.hpp:28
Self & axpy(const value_type &alpha, const Self &x)
Implements *this = *this + alpha * x.
Definition VectorBackend.hpp:94
void scale(const value_type &alpha)
scale all entries by the factor alpha
Definition VectorBackend.hpp:114
typename BaseVector::size_type size_type
The index/size - type.
Definition VectorBackend.hpp:31
Self & aypx(const value_type &alpha, const Self &x)
Implements *this = alpha * (*this) + x.
Definition VectorBackend.hpp:101
void init(Basis const &basis, bool clear)
Resize the vector_ to the size s.
Definition VectorBackend.hpp:65
BaseVector & vector()
Return the data-vector vector_.
Definition VectorBackend.hpp:51
MTLVector(DefaultIndexDistribution const &)
Constructor. Constructs new BaseVector.
Definition VectorBackend.hpp:42
BaseVector const & vector() const
Return the data-vector vector_.
Definition VectorBackend.hpp:45
void set(const value_type &alpha)
Set all entries to alpha.
Definition VectorBackend.hpp:108
std::size_t size() const
Return the current size of the vector_.
Definition VectorBackend.hpp:57
mtl::dense_vector< T > BaseVector
The type of the base vector.
Definition VectorBackend.hpp:25
CRTP base class for flat vector backends.
Definition VectorBase.hpp:19