DOFVector.hpp 2.64 KB
Newer Older
1
2
3
4
5
6
7
#pragma once

#include <Eigen/Dense>

#include <dune/common/ftraits.hh>

#include <amdis/Output.hpp>
8
#include <amdis/linearalgebra/DOFVectorBase.hpp>
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

namespace AMDiS
{
  /// The basic container that stores a base vector and a corresponding basis
  template <class ValueType>
  class EigenVector
  {
  public:
    /// 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;

    /// The type of the base vector
    using BaseVector = Eigen::Matrix<ValueType, Eigen::Dynamic, 1>;

    /// The index/size - type
    using size_type  = typename BaseVector::Index;

  public:
    /// Constructor. Constructs new BaseVector.
    EigenVector() = default;

    /// Return the data-vector \ref vector_
    BaseVector const& vector() const
    {
      return vector_;
    }

    /// Return the data-vector \ref vector_
    BaseVector& vector()
    {
      return vector_;
    }

    /// Return the current size of the \ref vector_
    size_type size() const
    {
      return vector_.size();
    }

    /// Resize the \ref vector_ to the size \p s
    void resize(size_type s)
    {
      vector_.resize(s);
    }


    /// Access the entry \p i of the \ref vector with read-access.
    value_type const& operator[](size_type i) const
    {
      test_exit_dbg(i < size(),
        "Index {} out of range [0,{})", i, size());
      return vector_.coeff(i);
    }

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

    void set(field_type value)
    {
      vector_.setConstant(value);
    }

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


88
89
  template <class GlobalBasis, class ValueType>
  class DOFVector : public DOFVectorBase<GlobalBasis, EigenVector<ValueType>>
90
  {
91
    using Super = DOFVectorBase<GlobalBasis, EigenVector<ValueType>>;
92
93

  public:
94
95
96
97
98
    DOFVector(std::shared_ptr<GlobalBasis> basis, DataTransferOperation op = DataTransferOperation::INTERPOLATE)
      : Super(std::move(basis), op)
    {}

    DOFVector(GlobalBasis& basis, DataTransferOperation op = DataTransferOperation::INTERPOLATE)
99
      : Super(basis, op)
100
    {}
101

102
103
104
105
    DOFVector(GlobalBasis&& basis, DataTransferOperation op = DataTransferOperation::INTERPOLATE)
      : Super(std::move(basis), op)
    {}

106
    using Super::operator=;
107
108
109
  };

} // end namespace AMDiS