Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <array> 7 : #include <cstddef> 8 : #include <deque> 9 : 10 : namespace fd { 11 : /*! 12 : * \ingroup FiniteDifferenceGroup 13 : * \brief Returns the weights for a 1D non-uniform finite difference stencil. 14 : * 15 : * These weights are for the Lagrange interpolation polynomial and its 16 : * derivatives evaluated at `times[0]`. If the number of times is not the same 17 : * as `StencilSize`, then an error will occur. 18 : * 19 : * The reason that `times` was chosen to be monotonically decreasing is because 20 : * the intended use of this function is with data that is stored in a 21 : * `std::deque` where the zeroth element is the "most recent" in time and then 22 : * later elements are further in the "past". 23 : * 24 : * \param times A monotonically *decreasing* sequence of times 25 : * \return A 2D array of all finite difference weights that correspond to the 26 : * input times. The outer dimension is the Nth derivative, and the inner 27 : * dimension loops over the weights for each of the times. 28 : * 29 : * \note Only stencil sizes 2, 3, and 4 are implemented right now. If you need 30 : * more, you'll either need to add it yourself or generalize the algorithm. 31 : */ 32 : template <size_t StencilSize> 33 1 : std::array<std::array<double, StencilSize>, StencilSize> non_uniform_1d_weights( 34 : const std::deque<double>& times); 35 : } // namespace fd