DOFVector.hpp 2.46 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
	{
	public:
    /// The type of the elements of the DOFVector
27
28
29
30
31
32
33
	  using block_type = typename BlockVectorType<ValueType>::type;

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

    /// The underlying field type
    using field_type = typename block_type::field_type;
34

35
    /// The vector type of the underlying base vector
36
	  using BaseVector = Dune::BlockVector<block_type>;
37

38
    /// The index/size - type
39
	  using size_type  = typename BaseVector::size_type;
40

41
  public:
42
    /// Constructor. Constructs new BaseVector.
43
    IstlVector() = default;
44

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

51
52
53
    /// Return the data-vector \ref vector
    BaseVector& vector()
    {
54
      return vector_;
55
    }
56
57


58
59
    /// Return the current size of the \ref vector_
    size_type size() const
60
    {
61
      return vector_.size();
62
63
    }

64
65
    /// Resize the \ref vector_ to the size \p s
    void resize(size_type s)
66
    {
67
      vector_.resize(s);
68
    }
69
70


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

    /// Access the entry \p i of the \ref vector with write-access.
80
    block_type& operator[](size_type i)
81
    {
82
      test_exit_dbg(i < vector_.size(),
83
        "Index {} out of range [0,{})", i, vector_.size());
84
      return vector_[i];
85
    }
86

87
	private:
88
    BaseVector vector_;
89
	};
90

Praetorius, Simon's avatar
Praetorius, Simon committed
91

92
93
  template <class BasisType, class ValueType = double>
  struct DOFVector : public DOFVectorBase<BasisType, IstlVector<ValueType>>
94
  {
95
    using Super = DOFVectorBase<BasisType, IstlVector<ValueType>>;
96
    using Super::operator=;
97
98
99
    DOFVector(BasisType const& basis)
      : Super(basis)
    {}
100
101
  };

Praetorius, Simon's avatar
Praetorius, Simon committed
102
103
104
105
106
107
108
109
110

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

111
} // end namespace AMDiS