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

#include <string>
#include <memory>

#include <dune/functions/functionspacebases/interpolate.hh>
#include <dune/istl/bvector.hh>

9
#include "ClonablePtr.hpp"
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "Log.hpp"

namespace AMDiS
{
    template <class FeSpaceType, class ValueType = Dune::FieldVector<double,1>>
    class DOFVector
    {
    public:
	using FeSpace    = FeSpaceType;
	using BaseVector = Dune::BlockVector<ValueType>;
	
	using size_type  = typename FeSpace::size_type;
	using field_type = typename ValueType::field_type;
	
	using value_type = ValueType;
	
26
	/// Constructor. Constructs new BaseVector.
27
28
29
	DOFVector(FeSpace const& feSpace, std::string name)
	  : feSpace(feSpace)
	  , name(name)
30
	  , vector(ClonablePtr<BaseVector>::make())
31
32
33
34
35
36
	{
	    compress();
	}
	
	/// Constructor. Takes pointer of data-vector.
	DOFVector(FeSpace const& feSpace, std::string name, 
37
		  BaseVector& vector_ref)
38
39
	  : feSpace(feSpace)
	  , name(name)
40
	  , vector(vector_ref)
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
	{}
	
	/// Return the basis \ref feSpace of the vector
	FeSpace const& getFeSpace() const
	{
	    return feSpace;
	}
	
	/// Return the data-vector \ref vector
	BaseVector const& getVector() const
	{
	    return *vector;
	}
	
	/// Return the data-vector \ref vector
	BaseVector& getVector()
	{
	    return *vector;
	}
	
	/// Return the size of the \ref feSpace
	size_type getSize() const
	{
	    return feSpace.size();
	}
	
	/// Return the \ref name of this vector
	std::string getName() const
	{
	    return name;
	}
	
	/// Resize the \ref vector to the size of the \ref feSpace.
	void compress()
	{
76
	    vector->resize(getSize() / value_type::dimension);
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
	}
	
	
	/// Access the entry \p i of the \ref vector with read-access.
	value_type const& operator[](size_type i) const
	{
	    AMDIS_TEST_EXIT_DBG( i < vector->size() , 
		"index " << i << " out of range [" << 0 << "," << vector->size() << ")" );
	    return (*vector)[i];
	}
	
	/// Access the entry \p i of the \ref vector with write-access.
	value_type& operator[](size_type i)
	{
	    AMDIS_TEST_EXIT_DBG( i < vector->size() , 
		"index " << i << " out of range [" << 0 << "," << vector->size() << ")" );
	    return (*vector)[i];
	}
	
	/// 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);
	}
	
    private:
	FeSpace const&	feSpace;
	std::string	name;
	
108
	ClonablePtr<BaseVector> vector;
109
110
111
112
113
114
115
	
    // friend class declarations
    template <class, class>
    friend class SystemVector;
    };

} // end namespace AMDiS