OperatorTermBase.hpp 2.25 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
#pragma once

#include "Traits.hpp"

namespace AMDiS {


template <class K, int SIZE>
K sum(Dune::FieldVector<K, SIZE> const& vector)
{
11
12
13
14
  K result = 0;
  for (int i = 0; i < SIZE; ++i)
    result += vector[i];
  return result;
15
16
17
18
19
20
}
    
    

class OperatorEvaluation
{
21
  using Scalar = Dune::FieldVector<double, 1>;
22
23
    
protected:
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
  template <class... Args>
  auto evalZotImpl(Args...) const { assert( false ); 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 { assert( false ); 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 { assert( false ); 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& M, 
                    Gradient const& grad_test, Gradient const& grad_trial) const
  {
    return grad_test * (M * 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);
  }
82
83
84
85
};
  

} // end namespace AMDiS