AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
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/common/FakeContainer.hpp>
9 #include <amdis/linearalgebra/VectorBase.hpp>
10 #include <amdis/typetree/MultiIndex.hpp>
11 
12 namespace AMDiS
13 {
15  template <class T>
17  : public VectorBase<EigenVector<T>>
18  {
19  public:
21  using BaseVector = Eigen::Matrix<T, Eigen::Dynamic, 1>;
22 
24  using value_type = typename BaseVector::Scalar;
25 
27  using size_type = typename BaseVector::Index;
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 EigenVector(Basis const&) {}
40 
42  BaseVector const& vector() const
43  {
44  return vector_;
45  }
46 
49  {
50  return vector_;
51  }
52 
54  size_type size() const
55  {
56  return vector_.size();
57  }
58 
59 
61  template <class SizeInfo>
62  void init(SizeInfo const& size, bool clear)
63  {
64  vector_.resize(size_type(size));
65  if (clear)
66  vector_.setZero();
67  }
68 
69 
71  template <class MultiIndex>
72  value_type& at(MultiIndex const& idx)
73  {
74  const size_type i = flatMultiIndex(idx);
75  test_exit_dbg(i < size(), "Index {} out of range [0,{})", i, size());
76  return vector_.coeffRef(i);
77  }
78 
80  template <class MultiIndex>
81  value_type const& at(MultiIndex const& idx) const
82  {
83  const size_type i = flatMultiIndex(idx);
84  test_exit_dbg(i < size(), "Index {} out of range [0,{})", i, size());
85  return vector_.coeff(i);
86  }
87 
88  private:
90  BaseVector vector_;
91  };
92 
93 } // end namespace AMDiS
value_type const & at(MultiIndex const &idx) const
Access the entry i of the vector with read-access.
Definition: VectorBackend.hpp:81
constexpr bool MultiIndex
A multi-index type.
Definition: Concepts.hpp:150
typename BaseVector::Scalar value_type
The type of the elements of the DOFVector.
Definition: VectorBackend.hpp:24
BaseVector & vector()
Return the data-vector vector_.
Definition: VectorBackend.hpp:48
void test_exit_dbg(bool condition, Args &&... args)
call assert_msg, in debug mode only
Definition: Output.hpp:205
Eigen::Matrix< T, Eigen::Dynamic, 1 > BaseVector
The type of the base vector.
Definition: VectorBackend.hpp:21
value_type & at(MultiIndex const &idx)
Access the entry i of the vector with write-access.
Definition: VectorBackend.hpp:72
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
EigenVector(Basis const &)
Constructor. Constructs new BaseVector.
Definition: VectorBackend.hpp:39
The basic container that stores a base vector and a corresponding basis.
Definition: VectorBackend.hpp:16
typename BaseVector::Index size_type
The index/size - type.
Definition: VectorBackend.hpp:27
void init(SizeInfo const &size, bool clear)
Resize the vector_ to the size s.
Definition: VectorBackend.hpp:62
CRTP base class for flat vector backends.
Definition: VectorBase.hpp:15
BaseVector const & vector() const
Return the data-vector vector_.
Definition: VectorBackend.hpp:42
size_type size() const
Return the current size of the vector_.
Definition: VectorBackend.hpp:54