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

#include <dune/istl/bvector.hh>

5
#include <amdis/Output.hpp>
6
#include <amdis/linearalgebra/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
88
89
90
91
    void set(field_type value)
    {
      vector_ = value;
    }

92
	private:
93
    BaseVector vector_;
94
	};
95

Praetorius, Simon's avatar
Praetorius, Simon committed
96

97
98
  template <class GlobalBasis, class ValueType>
  class DOFVector : public DOFVectorBase<GlobalBasis, IstlVector<ValueType>>
99
  {
100
    using Super = DOFVectorBase<GlobalBasis, IstlVector<ValueType>>;
101
102

  public:
103
104
105
106
107
    DOFVector(std::shared_ptr<GlobalBasis> basis, DataTransferOperation op = DataTransferOperation::INTERPOLATE)
      : Super(std::move(basis), op)
    {}

    DOFVector(GlobalBasis& basis, DataTransferOperation op = DataTransferOperation::INTERPOLATE)
108
      : Super(basis, op)
109
    {}
110

111
112
113
114
    DOFVector(GlobalBasis&& basis, DataTransferOperation op = DataTransferOperation::INTERPOLATE)
      : Super(std::move(basis), op)
    {}

115
    using Super::operator=;
116
117
  };

118
} // end namespace AMDiS