OGS
NumLib::detail::DefaultPerturbationStrategy Struct Reference

Detailed Description

Perturbs values according to a relative epsilon. The perturbation should not be less than a certain minimum.

Definition at line 125 of file NumericalDifferentiation.h.

#include <NumericalDifferentiation.h>

Public Member Functions

 DefaultPerturbationStrategy (RelativeEpsilon const &rel_eps, MinimumPerturbation const &min_pert)
 
double getPerturbation (double const value) const
 
double perturbIf (std::true_type, double value, double const plus_or_minus, Eigen::Index) const
 
template<int N>
Eigen::Vector< double, NperturbIf (std::true_type, Eigen::Matrix< double, N, 1, Eigen::ColMajor, N, 1 > const &vec, double const plus_or_minus, Eigen::Index comp) const
 

Static Public Member Functions

template<typename T >
static T const & perturbIf (std::false_type, T const &value, double const, Eigen::Index)
 

Private Attributes

double rel_eps_
 
double min_pert_
 

Constructor & Destructor Documentation

◆ DefaultPerturbationStrategy()

NumLib::detail::DefaultPerturbationStrategy::DefaultPerturbationStrategy ( RelativeEpsilon const & rel_eps,
MinimumPerturbation const & min_pert )
inline

Member Function Documentation

◆ getPerturbation()

double NumLib::detail::DefaultPerturbationStrategy::getPerturbation ( double const value) const
inline

Definition at line 133 of file NumericalDifferentiation.h.

134 {
135 auto const pert = std::abs(value) * rel_eps_;
136
137 if (std::abs(pert) >= std::abs(min_pert_))
138 {
139 return pert;
140 }
141
142 return min_pert_;
143 }

References min_pert_, and rel_eps_.

Referenced by perturbIf(), and perturbIf().

◆ perturbIf() [1/3]

template<typename T >
static T const & NumLib::detail::DefaultPerturbationStrategy::perturbIf ( std::false_type ,
T const & value,
double const ,
Eigen::Index  )
inlinestatic

Definition at line 146 of file NumericalDifferentiation.h.

149 {
150 return value;
151 }

◆ perturbIf() [2/3]

double NumLib::detail::DefaultPerturbationStrategy::perturbIf ( std::true_type ,
double value,
double const plus_or_minus,
Eigen::Index  ) const
inline

Definition at line 153 of file NumericalDifferentiation.h.

155 {
156 return value + plus_or_minus * getPerturbation(value);
157 }

References getPerturbation().

◆ perturbIf() [3/3]

template<int N>
Eigen::Vector< double, N > NumLib::detail::DefaultPerturbationStrategy::perturbIf ( std::true_type ,
Eigen::Matrix< double, N, 1, Eigen::ColMajor, N, 1 > const & vec,
double const plus_or_minus,
Eigen::Index comp ) const
inline

Definition at line 160 of file NumericalDifferentiation.h.

165 {
166 Eigen::Vector<double, N> vec_pert = vec;
167 vec_pert[comp] += plus_or_minus * getPerturbation(vec[comp]);
168 return vec_pert;
169 }

References getPerturbation().

Member Data Documentation

◆ min_pert_

double NumLib::detail::DefaultPerturbationStrategy::min_pert_
private

Definition at line 173 of file NumericalDifferentiation.h.

Referenced by getPerturbation().

◆ rel_eps_

double NumLib::detail::DefaultPerturbationStrategy::rel_eps_
private

Definition at line 172 of file NumericalDifferentiation.h.

Referenced by getPerturbation().


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