DOFVector.hpp 2.1 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
57
58
      test_exit_dbg(i < mtl::vec::size(vector_),
        "Index ", i, " out of range [0,", mtl::vec::size(vector_), ")" );
      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
65
66
      test_exit_dbg(i < mtl::vec::size(vector_),
        "Index ", i, " out of range [0,", mtl::vec::size(vector_), ")" );
      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
76
77
78

  template <class BasisType, class VectorType = double>
  using DOFVector = DOFVectorBase<BasisType, MtlVector<VectorType>>;


79
  /// Constructor a dofvector from given basis and name
Praetorius, Simon's avatar
Praetorius, Simon committed
80
  template <class ValueType = double, class Basis>
81
82
  DOFVector<Basis, ValueType>
  makeDOFVector(Basis const& basis)
83
  {
84
    return {basis};
85
  }
86
87

} // end namespace AMDiS