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

#include <string>
#include <memory>

#include <dune/istl/bvector.hh>

8
9
#include <dune/functions/functionspacebases/interpolate.hh>

10
11
#include <amdis/Output.hpp>
#include <amdis/common/ClonablePtr.hpp>
12
13
14
15
16
17

namespace AMDiS
{
    template <class FeSpaceType, class ValueType = Dune::FieldVector<double,1>>
    class DOFVector
    {
18
        using Self = DOFVector;
19

20
21
22
    public:
	using FeSpace    = FeSpaceType;
	using BaseVector = Dune::BlockVector<ValueType>;
23

24
25
	using size_type  = typename FeSpace::size_type;
	using field_type = typename ValueType::field_type;
26

27
	using value_type = ValueType;
28

29
	/// Constructor. Constructs new BaseVector.
30
31
32
	DOFVector(FeSpace const& feSpace, std::string name)
	  : feSpace(feSpace)
	  , name(name)
33
	  , vector(ClonablePtr<BaseVector>::make())
34
35
36
	{
	    compress();
	}
37

38
	/// Constructor. Takes pointer of data-vector.
39
	DOFVector(FeSpace const& feSpace, std::string name,
40
		  BaseVector& vector_ref)
41
42
	  : feSpace(feSpace)
	  , name(name)
43
	  , vector(vector_ref)
44
	{}
45

46
47
48
49
50
	/// Return the basis \ref feSpace of the vector
	FeSpace const& getFeSpace() const
	{
	    return feSpace;
	}
51

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

58
	/// Return the data-vector \ref vector
59
	BaseVector& vector()
60
61
62
	{
	    return *vector;
	}
63

64
65
66
67
68
	/// Return the size of the \ref feSpace
	size_type getSize() const
	{
	    return feSpace.size();
	}
69

70
71
72
73
74
	/// Return the \ref name of this vector
	std::string getName() const
	{
	    return name;
	}
75

76
77
78
	/// Resize the \ref vector to the size of the \ref feSpace.
	void compress()
	{
79
	    vector->resize(getSize() / value_type::dimension);
80
	}
81
82


83
84
85
	/// Access the entry \p i of the \ref vector with read-access.
	value_type const& operator[](size_type i) const
	{
86
87
	    test_exit_dbg(i < vector->size() ,
                          "Index ", i, " out of range [0,", vector->size(), ")" );
88
89
	    return (*vector)[i];
	}
90

91
92
93
	/// Access the entry \p i of the \ref vector with write-access.
	value_type& operator[](size_type i)
	{
94
95
	    test_exit_dbg(i < vector->size() ,
                          "Index ", i, " out of range [0,", vector->size(), ")" );
96
97
	    return (*vector)[i];
	}
98

99
100
101
102
103
104
105
	/// interpolate a function \p f to the basis \ref feSpace and store the
	/// coefficients in \ref vector.
	template <class F>
	void interpol(F const& f)
	{
	    Dune::Functions::interpolate(feSpace, *vector, f);
	}
106

107
	/// Calls the copy assignment operator of the BaseVector \ref vector
108
109
	void copy(Self const& that)
	{
110
		*vector = that.vector();
111
	}
112

113
114
115
    private:
	FeSpace const&	feSpace;
	std::string	name;
116

117
	ClonablePtr<BaseVector> vector;
118

119
120
121
122
123
124
    // friend class declarations
    template <class, class>
    friend class SystemVector;
    };

} // end namespace AMDiS