DOFVector.hpp 2.29 KB
Newer Older
1
2
3
4
#pragma once

#include <dune/istl/bvector.hh>

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

namespace AMDiS
{
10
11
12
13
14
15
16
17
18
19
20
21
  template <class T, class = void>
  struct BlockVectorType
  {
    using type = Dune::FieldVector<T,1>;
  };

  template <class T>
  struct BlockVectorType<T, typename T::field_type>
  {
    using type = T;
  };

22
23
	template <class ValueType>
	class IstlVector
24
25
26
27
	{
	public:
    /// The type of the elements of the DOFVector
	  using value_type = typename BlockVectorType<ValueType>::type;
28

29
30
    /// The vector type of the underlying base vector
	  using BaseVector = Dune::BlockVector<value_type>;
31

32
    /// The index/size - type
33
	  using size_type  = typename BaseVector::size_type;
34

35
  public:
36
    /// Constructor. Constructs new BaseVector.
37
    IstlVector() = default;
38

39
40
41
    /// Return the data-vector \ref vector
    BaseVector const& vector() const
    {
42
      return vector_;
43
    }
44

45
46
47
    /// Return the data-vector \ref vector
    BaseVector& vector()
    {
48
      return vector_;
49
    }
50
51


52
53
    /// Return the current size of the \ref vector_
    size_type size() const
54
    {
55
      return vector_.size();
56
57
    }

58
59
    /// Resize the \ref vector_ to the size \p s
    void resize(size_type s)
60
    {
61
      vector_.resize(s);
62
    }
63
64


65
    /// Access the entry \p i of the \ref vector with read-access.
66
    value_type const& operator[](size_type i) const
67
    {
68
      test_exit_dbg(i < vector_.size(),
69
        "Index {} out of range [0,{})", i, vector_.size());
70
      return vector_[i];
71
72
73
    }

    /// Access the entry \p i of the \ref vector with write-access.
74
    value_type& operator[](size_type i)
75
    {
76
      test_exit_dbg(i < vector_.size(),
77
        "Index {} out of range [0,{})", i, vector_.size());
78
      return vector_[i];
79
    }
80

81
	private:
82
    BaseVector vector_;
83
	};
84

Praetorius, Simon's avatar
Praetorius, Simon committed
85

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

Praetorius, Simon's avatar
Praetorius, Simon committed
96
97
98
99
100
101
102
103
104

  /// Constructor a dofvector from given basis and name
  template <class ValueType = double, class Basis>
  DOFVector<Basis, ValueType>
  makeDOFVector(Basis const& basis)
  {
    return {basis};
  }

105
} // end namespace AMDiS