Composer.impl.hpp 948 Bytes
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
#pragma once

3
#include <utility>
Praetorius, Simon's avatar
Praetorius, Simon committed
4
5
6
7
8
9
10
11
12
13
14
#include <amdis/operations/Composer.hpp>

#include <amdis/operations/Arithmetic.hpp>

namespace AMDiS { namespace Operation {

  /// Partial derivative of composed function:
  /// Implements: // sum_i [ d_i(f)[g...] * d_j(g_i) ]
  template <int J, class F, class... Gs>
  auto partial(Composer<F,Gs...> const& c, index_t<J> _j)
  {
15
    auto index_seq = std::make_index_sequence<sizeof...(Gs)>{};
Praetorius, Simon's avatar
Praetorius, Simon committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

    // d_i(f)[g...] * d_j(g_i)
    auto term_i = [&](auto const _i)
    {
      auto di_f = Dune::Std::apply([&](auto const&... gs) {
        return compose(partial(c.f_, _i), gs...);
      }, c.gs_);

      auto const& g_i = std::get<_i>(c.gs_);
      return compose(Multiplies{}, di_f, partial(g_i, _j));
    };

    // sum_i [ d_i(f)[g...] * d_j(g_i) ]
    return Dune::Std::apply([&](auto const... _i)
    {
      return compose(Plus{}, term_i(_i)...);
    }, index_seq);
  }

}} // end namespace AMDiS::Operation