diff --git a/src/amdis/operations/CMakeLists.txt b/src/amdis/operations/CMakeLists.txt index 9bb68ae2cb321dc3090b9137ee6737f675a10f5f..23e3876ae079ed1ab3d0eec5aca772eab01d4717 100644 --- a/src/amdis/operations/CMakeLists.txt +++ b/src/amdis/operations/CMakeLists.txt @@ -5,6 +5,7 @@ install(FILES Basic.hpp CMath.hpp Composer.hpp + Composer.impl.hpp FieldMatVec.hpp MaxMin.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/amdis/operations) diff --git a/src/amdis/operations/Composer.impl.hpp b/src/amdis/operations/Composer.impl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5a53683448fdc54076dcac02237d73a7de06e8a1 --- /dev/null +++ b/src/amdis/operations/Composer.impl.hpp @@ -0,0 +1,34 @@ +#pragma once + +#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) + { + auto index_seq = MakeSeq_t<sizeof...(Gs)>{}; + + // 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