9#ifndef DRYCHEM_COMMON_UTILITIES_INCLUDE_COMMON_UTILS_MATH_CALCULUS_DIFFERENTIATION_NPOINTSTENCIL_HPP
10#define DRYCHEM_COMMON_UTILITIES_INCLUDE_COMMON_UTILS_MATH_CALCULUS_DIFFERENTIATION_NPOINTSTENCIL_HPP
42 template<std::size_t N,
typename ContainerX,
typename ContainerY = ContainerX,
43 typename = std::enable_if_t<std::conjunction_v<std::is_default_constructible<typename ContainerX::value_type>,
44 std::is_default_constructible<typename ContainerY::value_type>>>>
47 using Ty_x =
decltype(y.at(0) / x.at(0));
49 if (x.size() != y.size())
52 std::vector<Ty_x> dy_dx(x.size());
56 for (std::size_t i {2}; i < x.size() - 2; ++i)
58 dy_dx[i] = (y[i - 2] - (8 * y[i + 1]) + (8 * y[i - 1]) - y[i + 2])
59 / (12 * (x[i + 1] - x[i]));
62 else if constexpr(N == 7)
64 for (std::size_t i {3}; i < x.size() - 3; ++i)
66 dy_dx[i] = ((-1 * y[i - 3]) + (9 * y[i - 2]) - (45 * y[i + 1]) + (45 * y[i - 1]) - (9 * y[i + 2]) + y[i + 3])
67 / (60 * (x[i + 1] - x[i]));
70 else if constexpr(N == 9)
72 for (std::size_t i {4}; i < x.size() - 4; ++i)
74 dy_dx[i] = ((3 * y[i - 4]) - (32 * y[i - 3]) + (168 * y[i - 2]) - (672 * y[i + 1]) + (672 * y[i - 1]) - (168 * y[i + 2]) + (32 * y[i + 3]) - (3 * y[i + 4]))
75 / (840 * (x[i + 1] - x[i]));
86 template<
typename ContainerX,
typename ContainerY = ContainerX,
87 typename = std::enable_if_t<std::conjunction_v<std::is_default_constructible<typename ContainerX::value_type>,
88 std::is_default_constructible<typename ContainerY::value_type>>>>
94 template<
typename ContainerX,
typename ContainerY = ContainerX,
95 typename = std::enable_if_t<std::conjunction_v<std::is_default_constructible<typename ContainerX::value_type>,
96 std::is_default_constructible<typename ContainerY::value_type>>>>
102 template<
typename ContainerX,
typename ContainerY = ContainerX,
103 typename = std::enable_if_t<std::conjunction_v<std::is_default_constructible<typename ContainerX::value_type>,
104 std::is_default_constructible<typename ContainerY::value_type>>>>
Definition nPointStencil.hpp:25
constexpr auto nPointStencilMethod(const ContainerX &x, const ContainerY &y)
Definition nPointStencil.hpp:45
Definition backwardsDifferenceMethod.hpp:20
constexpr auto fivePointStencilMethod(const ContainerX &x, const ContainerY &y)
Definition nPointStencil.hpp:89
constexpr auto ninePointStencilMethod(const ContainerX &x, const ContainerY &y)
Definition nPointStencil.hpp:105
constexpr auto sevenPointStencilMethod(const ContainerX &x, const ContainerY &y)
Definition nPointStencil.hpp:97