AMDiS 2.11-git
The Adaptive Multi-Dimensional Simulation Toolbox
 
Loading...
Searching...
No Matches
VectorBackend.hpp
1#pragma once
2
3#include <dune/istl/bvector.hh>
4#include <dune/functions/backends/istlvectorbackend.hh>
5
6#include <amdis/Output.hpp>
7#include <amdis/common/FakeContainer.hpp>
8#include <amdis/linearalgebra/VectorBase.hpp>
9#include <amdis/typetree/MultiIndex.hpp>
10
11namespace AMDiS
12{
13 template <class T, class = void>
15 {
16 using type = Dune::FieldVector<T,1>;
17 };
18
19 template <class T>
20 struct BlockVectorType<T, typename T::field_type>
21 {
22 using type = T;
23 };
24
25 template <class T>
27 : public VectorBase<ISTLBlockVector<T>>
28 {
29 using Self = ISTLBlockVector;
30
31 public:
33 using BaseVector = Dune::BlockVector<typename BlockVectorType<T>::type>;
34
36 using block_type = typename BaseVector::block_type;
37
39 using value_type = T;
40
42 using field_type = typename block_type::field_type;
43
45 using size_type = typename BaseVector::size_type;
46
47 public:
49 template <class Comm,
50 Dune::disableCopyMove<ISTLBlockVector,Comm> = 0>
51 explicit ISTLBlockVector(Comm const&) {}
52
53 ISTLBlockVector() = default;
54
56 BaseVector const& vector() const
57 {
58 return vector_;
59 }
60
63 {
64 return vector_;
65 }
66
68 std::size_t size() const
69 {
70 return vector_.size();
71 }
72
74 // NOTE: this resize works recursively on the hierarchy of the vector
75 template <class Basis>
76 void init(Basis const& basis, bool clear)
77 {
78 Dune::Functions::istlVectorBackend(vector_).resize(basis);
79 if (clear)
80 vector_ = 0;
81 }
82
84 template <class MultiIndex>
85 value_type& at(MultiIndex const& idx)
86 {
87 return Dune::Functions::istlVectorBackend(vector_)[idx];
88 }
89
91 template <class MultiIndex>
92 value_type const& at(MultiIndex const& idx) const
93 {
94 return Dune::Functions::istlVectorBackend(vector_)[idx];
95 }
96
99
101 Self& axpy (const value_type& alpha, const Self& x)
102 {
103 vector_.axpy(alpha, x.vector_);
104 return *this;
105 }
106
108 Self& aypx (const value_type& alpha, const Self& x)
109 {
110 vector_ *= alpha;
111 vector_ += x.vector_;
112 return *this;
113 }
114
116 void set (const value_type& alpha)
117 {
118 vector_ = alpha;
119 }
120
122 void scale (const value_type& alpha)
123 {
124 vector_ *= alpha;
125 }
126
128
129 private:
130 BaseVector vector_;
131 };
132
133
134 namespace Recursive
135 {
136 template <class T>
137 struct ForEach<ISTLBlockVector<T>> : ForEach<VectorBase<ISTLBlockVector<T>>> {};
138
139 template <class T>
140 struct Transform<ISTLBlockVector<T>> : Transform<VectorBase<ISTLBlockVector<T>>> {};
141
142 template <class T>
143 struct InnerProduct<ISTLBlockVector<T>> : InnerProduct<VectorBase<ISTLBlockVector<T>>> {};
144
145 } // end namespace Recursive
146} // end namespace AMDiS
Definition VectorBackend.hpp:28
value_type & at(MultiIndex const &idx)
Access the entry idx of the vector_ with write-access.
Definition VectorBackend.hpp:85
ISTLBlockVector(Comm const &)
Constructor. Constructs new BaseVector.
Definition VectorBackend.hpp:51
value_type const & at(MultiIndex const &idx) const
Access the entry idx of the vector_ with read-access.
Definition VectorBackend.hpp:92
Self & axpy(const value_type &alpha, const Self &x)
Implements *this = *this + alpha * x.
Definition VectorBackend.hpp:101
void scale(const value_type &alpha)
scale all entries by the factor alpha
Definition VectorBackend.hpp:122
typename BaseVector::size_type size_type
The index/size - type.
Definition VectorBackend.hpp:45
typename block_type::field_type field_type
The underlying field type.
Definition VectorBackend.hpp:42
Self & aypx(const value_type &alpha, const Self &x)
Implements *this = alpha * (*this) + x.
Definition VectorBackend.hpp:108
Dune::BlockVector< typename BlockVectorType< T >::type > BaseVector
The vector type of the underlying base vector.
Definition VectorBackend.hpp:33
void init(Basis const &basis, bool clear)
Resize the vector_ to the size given by the sizeProvider.
Definition VectorBackend.hpp:76
BaseVector & vector()
Return the data-vector vector.
Definition VectorBackend.hpp:62
BaseVector const & vector() const
Return the data-vector vector.
Definition VectorBackend.hpp:56
void set(const value_type &alpha)
Set all entries to alpha.
Definition VectorBackend.hpp:116
std::size_t size() const
Return the current size of the vector_.
Definition VectorBackend.hpp:68
typename BaseVector::block_type block_type
The type of the elements of the DOFVector.
Definition VectorBackend.hpp:36
T value_type
The type of the elements of the DOFVector.
Definition VectorBackend.hpp:39
CRTP base class for flat vector backends.
Definition VectorBase.hpp:19
Definition VectorBackend.hpp:15