AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
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 
12 namespace AMDiS
13 {
15  template <class T>
16  class MTLVector
17  : public VectorBase<MTLVector<T>>
18  {
19  public:
21  using BaseVector = mtl::dense_vector<T>;
22 
24  using value_type = typename BaseVector::value_type;
25 
27  using size_type = typename BaseVector::size_type;
28 
29  private:
31  using block_type = value_type;
32 
34  using field_type = typename Dune::FieldTraits<value_type>::field_type;
35 
36  public:
38  template <class Basis>
39  explicit MTLVector(Basis const&) {}
40 
42  BaseVector const& vector() const
43  {
44  return vector_;
45  }
46 
49  {
50  return vector_;
51  }
52 
54  std::size_t size() const
55  {
56  return mtl::vec::size(vector_);
57  }
58 
59 
61  template <class SizeInfo>
62  void init(SizeInfo const& sizeInfo, bool clear)
63  {
64  vector_.change_dim(sizeInfo({}));
65  if (clear)
66  set_to_zero(vector_);
67  }
68 
70  template <class MultiIndex>
71  value_type& at(MultiIndex const& idx)
72  {
73  const size_type i = flatMultiIndex(idx);
74  test_exit_dbg(i < size(),"Index {} out of range [0,{})", i, size());
75  return vector_[i];
76  }
77 
79  template <class MultiIndex>
80  value_type const& at(MultiIndex const& idx) const
81  {
82  const size_type i = flatMultiIndex(idx);
83  test_exit_dbg(i < size(), "Index {} out of range [0,{})", i, size());
84  return vector_[i];
85  }
86 
87  private:
89  BaseVector vector_;
90  };
91 
92 } // end namespace AMDiS
constexpr bool MultiIndex
A multi-index type.
Definition: Concepts.hpp:150
void init(SizeInfo const &sizeInfo, bool clear)
Resize the vector_ to the size s.
Definition: VectorBackend.hpp:62
void test_exit_dbg(bool condition, Args &&... args)
call assert_msg, in debug mode only
Definition: Output.hpp:205
typename BaseVector::value_type value_type
The type of the elements of the DOFVector.
Definition: VectorBackend.hpp:24
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
value_type & at(MultiIndex const &idx)
Access the entry i of the vector with read-access.
Definition: VectorBackend.hpp:71
mtl::dense_vector< T > BaseVector
The type of the base vector.
Definition: VectorBackend.hpp:21
std::size_t size() const
Return the current size of the vector_.
Definition: VectorBackend.hpp:54
CRTP base class for flat vector backends.
Definition: VectorBase.hpp:15
MTLVector(Basis const &)
Constructor. Constructs new BaseVector.
Definition: VectorBackend.hpp:39
The basic container that stores a base vector data.
Definition: VectorBackend.hpp:16
BaseVector & vector()
Return the data-vector vector_.
Definition: VectorBackend.hpp:48
value_type const & at(MultiIndex const &idx) const
Access the entry i of the vector with read-access.
Definition: VectorBackend.hpp:80
typename BaseVector::size_type size_type
The index/size - type.
Definition: VectorBackend.hpp:27
BaseVector const & vector() const
Return the data-vector vector_.
Definition: VectorBackend.hpp:42