OperatorTermBase.hpp 2.13 KB
Newer Older
1
2
3
4
5
6
7
8
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
#pragma once

#include "Traits.hpp"

namespace AMDiS {


template <class K, int SIZE>
K sum(Dune::FieldVector<K, SIZE> const& vector)
{
    K result = 0;
    for (int i = 0; i < SIZE; ++i)
	result += vector[i];
    return result;
}
    
    

class OperatorEvaluation
{
    using Scalar = Dune::FieldVector<double, 1>;
    
protected:
    template <class... Args>
    auto evalZotImpl(Args...) const { return 0; }
	
    template <class ValueType>
    auto evalZotImpl(_scalar, _none, ValueType const& v, 
		     Scalar const& test, Scalar const& trial) const
    {
	return v * test * trial;
    }
    
    template <class... Args>
    auto evalFotImpl(Args...) const { return 0; }
	
    template <size_t I, class ValueType, class Gradient>
    auto evalFotImpl(_scalar, VectorComponent<I>, ValueType const& v, 
		     Gradient const& grad_test, Scalar const& trial) const
    {
	return v * grad_test[I] * trial;
    }
	
    template <class ValueType, class Gradient>
    auto evalFotImpl(_vector, _none, ValueType const& v, 
		     Gradient const& grad_test, Scalar const& trial) const
    {
	return (v * grad_test) * trial;
    }
	
    template <class ValueType, class Gradient>
    auto evalFotImpl(_scalar, _none, ValueType const& v, 
		     Gradient const& grad_test, Scalar const& trial) const
    {
	return v * sum(grad_test) * trial;
    }
    
    
    template <class... Args>
    auto evalSotImpl(Args...) const { return 0; }
	
    template <size_t R, size_t C, class ValueType, class Gradient>
    auto evalSotImpl(_scalar, MatrixComponent<R, C>, ValueType const& v, 
		     Gradient const& grad_test, Gradient const& grad_trial) const
    {
	return v * (grad_test[R] * grad_trial[C]);
    }
	
    template <class ValueType, class Gradient>
    auto evalSotImpl(_matrix, _none, ValueType const& v, 
		     Gradient const& grad_test, Gradient const& grad_trial) const
    {
	return grad_test * (v * grad_trial);
    }
	
    template <class ValueType, class Gradient>
    auto evalSotImpl(_scalar, _none, ValueType const& v, 
		     Gradient const& grad_test, Gradient const& grad_trial) const
    {
	return v * (grad_test * grad_trial);
    }
};
  

} // end namespace AMDiS