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

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

5
#include <amdis/Output.hpp>
6
#include <amdis/linear_algebra/DOFVectorBase.hpp>
7
8
9

namespace AMDiS
{
10
  /// The basic container that stores a base vector and a corresponding basis
11
12
  template <class ValueType>
  class MtlVector
13
14
  {
  public:
15
    /// The type of the base vector
16
    using BaseVector = mtl::vec::dense_vector<ValueType>;
17

18
    /// The index/size - type
19
    using size_type  = typename BaseVector::size_type;
20

21
    /// The type of the elements of the DOFVector
22
    using value_type = ValueType;
23

24
  public:
25
    /// Constructor. Constructs new BaseVector.
26
    MtlVector() = default;
27

28
    /// Return the data-vector \ref vector_
29
    BaseVector const& vector() const
30
    {
31
      return vector_;
32
    }
33

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

40
41
    /// Return the current size of the \ref vector_
    size_type size() const
42
    {
43
      return mtl::vec::size(vector_);
44
    }
45

46
47
    /// Resize the \ref vector_ to the size \p s
    void resize(size_type s)
48
    {
49
      vector_.change_dim(s);
50
    }
51

52

53
    /// Access the entry \p i of the \ref vector with read-access.
54
    value_type const& operator[](size_type i) const
55
    {
56
      test_exit_dbg(i < mtl::vec::size(vector_),
57
        "Index {} out of range [0,{})", i, mtl::vec::size(vector_));
58
      return vector_[i];
59
60
    }

61
    /// Access the entry \p i of the \ref vector with write-access.
62
    value_type& operator[](size_type i)
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
  private:
70
    /// The data-vector (can hold a new BaseVector or a pointer to external data
71
    BaseVector vector_;
72
  };
73

74
75

  template <class BasisType, class VectorType = double>
76
77
78
79
80
81
  struct DOFVector : public DOFVectorBase<BasisType, MtlVector<VectorType>>
  {
    using Super = DOFVectorBase<BasisType, MtlVector<VectorType>>;
    using Super::DOFVectorBase;
    using Super::operator=;
  };
82
83


84
  /// Constructor a dofvector from given basis and name
Praetorius, Simon's avatar
Praetorius, Simon committed
85
  template <class ValueType = double, class Basis>
86
87
  DOFVector<Basis, ValueType>
  makeDOFVector(Basis const& basis)
88
  {
89
    return {basis};
90
  }
91
92

} // end namespace AMDiS