DOFVector.hpp 2.63 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/linearalgebra/DOFVectorBase.hpp>
9 10 11

namespace AMDiS
{
12
  /// The basic container that stores a base vector data
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 78 79 80 81
    void set(field_type value)
    {
      vector_ = value;
    }

82
  private:
83
    /// The data-vector (can hold a new BaseVector or a pointer to external data
84
    BaseVector vector_;
85
  };
86

87

88
  template <class BasisType, class ValueType = double>
89
  class DOFVector : public DOFVectorBase<BasisType, MtlVector<ValueType>>
90
  {
91
    using Super = DOFVectorBase<BasisType, MtlVector<ValueType>>;
92 93 94 95

  public:
    DOFVector(BasisType const& basis, DataTransferOperation op = NO_OPERATION)
      : Super(basis, op)
96
    {}
97 98

    using Super::operator=;
99
  };
100 101


102
  /// Constructor a dofvector from given basis and name
Praetorius, Simon's avatar
Praetorius, Simon committed
103
  template <class ValueType = double, class Basis>
104
  DOFVector<Basis, ValueType>
105
  makeDOFVector(Basis const& basis, DataTransferOperation op = NO_OPERATION)
106
  {
107
    return {basis, op};
108
  }
109 110

} // end namespace AMDiS