DOFVector.hpp 2.49 KB
Newer Older
1
2
#pragma once

3
#include <boost/numeric/mtl/vector/dense_vector.hpp>
4

5
6
#include <dune/common/ftraits.hh>

7
#include <amdis/Output.hpp>
8
#include <amdis/linear_algebra/DOFVectorBase.hpp>
9
10
11

namespace AMDiS
{
12
  /// The basic container that stores a base vector and a corresponding basis
13
14
  template <class ValueType>
  class MtlVector
15
16
  {
  public:
17
18
19
20
21
22
23
24
25
    /// The type of the elements of the DOFVector
    using value_type = ValueType;

    /// The type of the elements of the DOFVector
    using block_type = ValueType;

    /// The underlying field type
    using field_type = typename Dune::FieldTraits<ValueType>::field_type;

26
    /// The type of the base vector
27
    using BaseVector = mtl::vec::dense_vector<ValueType>;
28

29
    /// The index/size - type
30
    using size_type  = typename BaseVector::size_type;
31

32
  public:
33
    /// Constructor. Constructs new BaseVector.
34
    MtlVector() = default;
35

36
    /// Return the data-vector \ref vector_
37
    BaseVector const& vector() const
38
    {
39
      return vector_;
40
    }
41

42
    /// Return the data-vector \ref vector_
43
    BaseVector& vector()
44
    {
45
      return vector_;
46
    }
47

48
49
    /// Return the current size of the \ref vector_
    size_type size() const
50
    {
51
      return mtl::vec::size(vector_);
52
    }
53

54
55
    /// Resize the \ref vector_ to the size \p s
    void resize(size_type s)
56
    {
57
      vector_.change_dim(s);
58
    }
59

60

61
    /// Access the entry \p i of the \ref vector with read-access.
62
    value_type const& operator[](size_type i) const
63
    {
64
      test_exit_dbg(i < mtl::vec::size(vector_),
65
        "Index {} out of range [0,{})", i, mtl::vec::size(vector_));
66
      return vector_[i];
67
68
    }

69
    /// Access the entry \p i of the \ref vector with write-access.
70
    value_type& operator[](size_type i)
71
    {
72
      test_exit_dbg(i < mtl::vec::size(vector_),
73
        "Index {} out of range [0,{})", i, mtl::vec::size(vector_));
74
      return vector_[i];
75
    }
76

77
  private:
78
    /// The data-vector (can hold a new BaseVector or a pointer to external data
79
    BaseVector vector_;
80
  };
81

82

83
84
  template <class BasisType, class ValueType = double>
  struct DOFVector : public DOFVectorBase<BasisType, MtlVector<ValueType>>
85
  {
86
    using Super = DOFVectorBase<BasisType, MtlVector<ValueType>>;
87
    using Super::operator=;
88
89
90
    DOFVector(BasisType const& basis)
      : Super(basis)
    {}
91
  };
92
93


94
  /// Constructor a dofvector from given basis and name
Praetorius, Simon's avatar
Praetorius, Simon committed
95
  template <class ValueType = double, class Basis>
96
97
  DOFVector<Basis, ValueType>
  makeDOFVector(Basis const& basis)
98
  {
99
    return {basis};
100
  }
101
102

} // end namespace AMDiS