OGS
NumLib::NumericalDerivative< DerivativeStrategy > Struct Template Reference

Detailed Description

template<typename DerivativeStrategy>
struct NumLib::NumericalDerivative< DerivativeStrategy >

Computes numerical derivatives of almost arbitrary function (objects) with respect to scalar or vectorial (Eigen vectors) variables.

Template Parameters
DerivativeStrategycompute central or forward differences

Definition at line 208 of file NumericalDifferentiation.h.

#include <NumericalDifferentiation.h>

Collaboration diagram for NumLib::NumericalDerivative< DerivativeStrategy >:
[legend]

Public Member Functions

 NumericalDerivative (RelativeEpsilon const &rel_eps, MinimumPerturbation const &min_pert)
 
template<typename Function , typename... Args>
auto operator() (Function const &f, Args const &... args) const
 

Private Member Functions

template<typename Function , typename TupleOfArgs , typename DByDScalar , std::size_t... AllArgIdcs>
auto differentiate (Function const &f, TupleOfArgs const &args, DByDScalar const &d_by_dScalar, std::index_sequence< AllArgIdcs... > all_arg_idcs) const
 
template<typename Function , typename TupleOfArgs , typename DByDScalar , std::size_t... AllArgIdcs, std::size_t PerturbedArgIdx>
auto differentiateWrtScalarOrVectorialArgument (std::true_type, Function const &f, TupleOfArgs const &args, DByDScalar const &d_by_dScalar, std::integral_constant< std::size_t, PerturbedArgIdx > perturbed_arg_idx, std::index_sequence< AllArgIdcs... > all_arg_idcs) const
 
template<typename Function , typename TupleOfArgs , typename DByDScalar , std::size_t... AllArgIdcs, std::size_t PerturbedArgIdx>
auto differentiateWrtScalarOrVectorialArgument (std::false_type, Function const &f, TupleOfArgs const &args, DByDScalar const &d_by_dScalar, std::integral_constant< std::size_t, PerturbedArgIdx > perturbed_arg_idx, std::index_sequence< AllArgIdcs... > all_arg_idcs) const
 
template<typename Function , typename TupleOfArgs , typename DByDScalar , Eigen::Index... PerturbedArgComponents, std::size_t... AllArgIdcs, std::size_t PerturbedArgIdx>
auto differentiateWrtAllVectorComponents (Function const &f, TupleOfArgs const &args, DByDScalar const &d_by_dScalar, std::integer_sequence< Eigen::Index, PerturbedArgComponents... >, std::integral_constant< std::size_t, PerturbedArgIdx > perturbed_arg_idx, std::index_sequence< AllArgIdcs... > all_arg_idcs) const
 

Private Attributes

detail::DefaultPerturbationStrategy pert_strat_
 

Constructor & Destructor Documentation

◆ NumericalDerivative()

template<typename DerivativeStrategy >
NumLib::NumericalDerivative< DerivativeStrategy >::NumericalDerivative ( RelativeEpsilon const & rel_eps,
MinimumPerturbation const & min_pert )
inline

Definition at line 210 of file NumericalDifferentiation.h.

212 : pert_strat_{rel_eps, min_pert}
213 {
214 }
detail::DefaultPerturbationStrategy pert_strat_

Member Function Documentation

◆ differentiate()

template<typename DerivativeStrategy >
template<typename Function , typename TupleOfArgs , typename DByDScalar , std::size_t... AllArgIdcs>
auto NumLib::NumericalDerivative< DerivativeStrategy >::differentiate ( Function const & f,
TupleOfArgs const & args,
DByDScalar const & d_by_dScalar,
std::index_sequence< AllArgIdcs... > all_arg_idcs ) const
inlineprivate

Definition at line 232 of file NumericalDifferentiation.h.

235 {
237 detail::IsScalar<std::remove_cvref_t<
238 std::tuple_element_t<AllArgIdcs, TupleOfArgs>>>{},
239 f, args, d_by_dScalar,
240 std::integral_constant<std::size_t, AllArgIdcs>{},
241 all_arg_idcs)... /* "for each function argument" */};
242 }
auto differentiateWrtScalarOrVectorialArgument(std::true_type, Function const &f, TupleOfArgs const &args, DByDScalar const &d_by_dScalar, std::integral_constant< std::size_t, PerturbedArgIdx > perturbed_arg_idx, std::index_sequence< AllArgIdcs... > all_arg_idcs) const

References NumLib::NumericalDerivative< DerivativeStrategy >::differentiateWrtScalarOrVectorialArgument().

Referenced by NumLib::NumericalDerivative< DerivativeStrategy >::operator()().

◆ differentiateWrtAllVectorComponents()

template<typename DerivativeStrategy >
template<typename Function , typename TupleOfArgs , typename DByDScalar , Eigen::Index... PerturbedArgComponents, std::size_t... AllArgIdcs, std::size_t PerturbedArgIdx>
auto NumLib::NumericalDerivative< DerivativeStrategy >::differentiateWrtAllVectorComponents ( Function const & f,
TupleOfArgs const & args,
DByDScalar const & d_by_dScalar,
std::integer_sequence< Eigen::Index, PerturbedArgComponents... > ,
std::integral_constant< std::size_t, PerturbedArgIdx > perturbed_arg_idx,
std::index_sequence< AllArgIdcs... > all_arg_idcs ) const
inlineprivate

Definition at line 287 of file NumericalDifferentiation.h.

293 {
294 return std::array{
295 d_by_dScalar(f, args, pert_strat_, perturbed_arg_idx,
296 PerturbedArgComponents, all_arg_idcs)...
297 /* "for each component of the vectorial function argument being
298 perturbed" */
299 };
300 }

References NumLib::NumericalDerivative< DerivativeStrategy >::pert_strat_.

Referenced by NumLib::NumericalDerivative< DerivativeStrategy >::differentiateWrtScalarOrVectorialArgument().

◆ differentiateWrtScalarOrVectorialArgument() [1/2]

template<typename DerivativeStrategy >
template<typename Function , typename TupleOfArgs , typename DByDScalar , std::size_t... AllArgIdcs, std::size_t PerturbedArgIdx>
auto NumLib::NumericalDerivative< DerivativeStrategy >::differentiateWrtScalarOrVectorialArgument ( std::false_type ,
Function const & f,
TupleOfArgs const & args,
DByDScalar const & d_by_dScalar,
std::integral_constant< std::size_t, PerturbedArgIdx > perturbed_arg_idx,
std::index_sequence< AllArgIdcs... > all_arg_idcs ) const
inlineprivate

Definition at line 262 of file NumericalDifferentiation.h.

267 {
268 using VectorialArg = std::remove_cvref_t<
269 std::tuple_element_t<PerturbedArgIdx, TupleOfArgs>>;
270 constexpr int N = VectorialArg::RowsAtCompileTime;
271
272 static_assert(N != Eigen::Dynamic);
273 static_assert(VectorialArg::ColsAtCompileTime == 1,
274 "Row vectors are not supported, yet. If you implement "
275 "support for them, make sure to test your implementation "
276 "thoroughly.");
277
279 f, args, d_by_dScalar,
280 std::make_integer_sequence<Eigen::Index, N>{}, perturbed_arg_idx,
281 all_arg_idcs);
282 }
auto differentiateWrtAllVectorComponents(Function const &f, TupleOfArgs const &args, DByDScalar const &d_by_dScalar, std::integer_sequence< Eigen::Index, PerturbedArgComponents... >, std::integral_constant< std::size_t, PerturbedArgIdx > perturbed_arg_idx, std::index_sequence< AllArgIdcs... > all_arg_idcs) const

References NumLib::NumericalDerivative< DerivativeStrategy >::differentiateWrtAllVectorComponents(), and NumLib::N.

◆ differentiateWrtScalarOrVectorialArgument() [2/2]

template<typename DerivativeStrategy >
template<typename Function , typename TupleOfArgs , typename DByDScalar , std::size_t... AllArgIdcs, std::size_t PerturbedArgIdx>
auto NumLib::NumericalDerivative< DerivativeStrategy >::differentiateWrtScalarOrVectorialArgument ( std::true_type ,
Function const & f,
TupleOfArgs const & args,
DByDScalar const & d_by_dScalar,
std::integral_constant< std::size_t, PerturbedArgIdx > perturbed_arg_idx,
std::index_sequence< AllArgIdcs... > all_arg_idcs ) const
inlineprivate

Definition at line 247 of file NumericalDifferentiation.h.

252 {
253 constexpr Eigen::Index component_does_not_matter = -1;
254
255 return d_by_dScalar(f, args, pert_strat_, perturbed_arg_idx,
256 component_does_not_matter, all_arg_idcs);
257 }

References NumLib::NumericalDerivative< DerivativeStrategy >::pert_strat_.

Referenced by NumLib::NumericalDerivative< DerivativeStrategy >::differentiate().

◆ operator()()

template<typename DerivativeStrategy >
template<typename Function , typename... Args>
auto NumLib::NumericalDerivative< DerivativeStrategy >::operator() ( Function const & f,
Args const &... args ) const
inline

Definition at line 217 of file NumericalDifferentiation.h.

218 {
219 auto const d_by_dScalar =
220 DerivativeStrategy::createDByDScalar(f, args...);
221
222 // TODO also return value from the function, not only the derivatives?
223 return differentiate(f,
224 std::forward_as_tuple(args...),
225 d_by_dScalar,
226 std::make_index_sequence<sizeof...(Args)>{});
227 }
auto differentiate(Function const &f, TupleOfArgs const &args, DByDScalar const &d_by_dScalar, std::index_sequence< AllArgIdcs... > all_arg_idcs) const

References NumLib::NumericalDerivative< DerivativeStrategy >::differentiate().

Member Data Documentation

◆ pert_strat_


The documentation for this struct was generated from the following file: