OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | Protected Types | Protected Attributes | List of all members
olb::opti::OptiCaseAD< S, n, C > Class Template Reference

Derivatives are computed with automatic differentiation. More...

#include <optiCaseAD.h>

+ Inheritance diagram for olb::opti::OptiCaseAD< S, n, C >:
+ Collaboration diagram for olb::opti::OptiCaseAD< S, n, C >:

Public Member Functions

 OptiCaseAD ()=default
 
 OptiCaseAD (std::function< S(const C< S > &, unsigned)> function, std::function< T(const C< T > &, unsigned)> adFunction, std::function< void(void)> postEvaluation=[](){})
 
 OptiCaseAD (std::function< S(const C< S > &)> function, std::function< T(const C< T > &)> adFunction, std::function< void(void)> postEvaluation=[](){})
 
evaluateObjective (const C< S > &control, unsigned optiStep=0) override
 
void computeDerivatives (const C< S > &control, C< S > &derivatives, unsigned optiStep=0) override
 
- Public Member Functions inherited from olb::opti::OptiCase< S, C >
 OptiCase ()=default
 
 OptiCase (std::function< void(void)> postEvaluation)
 
virtual S evaluateObjective (const C &control, unsigned optiStep=0)=0
 
virtual void computeDerivatives (const C &control, C &derivatives, unsigned optiStep=0)=0
 
void postEvaluation ()
 

Protected Types

using T = util::ADf<S,n>
 

Protected Attributes

std::function< S(const C< S > &) _functionHelp ) { [](const C<S>&){ return S{}; } }
 
std::function< T(const C< T > &) _adFunctionHelp ) { [](const C<T>&){ return T{}; } }
 
std::function< S(const C< S > &, unsigned) _function )
 
std::function< T(const C< T > &, unsigned) _adFunction )
 
- Protected Attributes inherited from olb::opti::OptiCase< S, C >
std::function< void(void)> _postEvaluation { [](){} }
 

Detailed Description

template<typename S, std::size_t n, template< typename > typename C = util::StdVector>
class olb::opti::OptiCaseAD< S, n, C >

Derivatives are computed with automatic differentiation.

Template Parameters
SFundamental (floating point) datatype
nNumber of optimized (control) parameters
CContainer type

Definition at line 51 of file optiCaseAD.h.

Member Typedef Documentation

◆ T

template<typename S , std::size_t n, template< typename > typename C = util::StdVector>
using olb::opti::OptiCaseAD< S, n, C >::T = util::ADf<S,n>
protected

Definition at line 54 of file optiCaseAD.h.

Constructor & Destructor Documentation

◆ OptiCaseAD() [1/3]

template<typename S , std::size_t n, template< typename > typename C = util::StdVector>
olb::opti::OptiCaseAD< S, n, C >::OptiCaseAD ( )
explicitdefault

◆ OptiCaseAD() [2/3]

template<typename S , std::size_t n, template< typename > typename C = util::StdVector>
olb::opti::OptiCaseAD< S, n, C >::OptiCaseAD ( std::function< S(const C< S > &, unsigned)> function,
std::function< T(const C< T > &, unsigned)> adFunction,
std::function< void(void)> postEvaluation = [](){} )
inline

Definition at line 63 of file optiCaseAD.h.

66 {})
67 : OptiCase<S,C<S>>(postEvaluation), _function(function), _adFunction(adFunction)
68 { }
std::function< S(const C< S > &, unsigned) _function)
Definition optiCaseAD.h:57
std::function< T(const C< T > &, unsigned) _adFunction)
Definition optiCaseAD.h:58
void postEvaluation()
Definition optiCase.h:56

◆ OptiCaseAD() [3/3]

template<typename S , std::size_t n, template< typename > typename C = util::StdVector>
olb::opti::OptiCaseAD< S, n, C >::OptiCaseAD ( std::function< S(const C< S > &)> function,
std::function< T(const C< T > &)> adFunction,
std::function< void(void)> postEvaluation = [](){} )
inline

Definition at line 71 of file optiCaseAD.h.

74 {})
75 : OptiCase<S,C<S>>(postEvaluation),
76 _functionHelp(function), _adFunctionHelp(adFunction), // store original functions for memory reasons
77 _function ([&](const C<S>& arg, unsigned){ return _functionHelp(arg); }),
78 _adFunction ([&](const C<T>& arg, unsigned){ return _adFunctionHelp(arg); })
79 { }
std::function< T(const C< T > &) _adFunctionHelp)
Definition optiCaseAD.h:56
std::function< S(const C< S > &) _functionHelp)
Definition optiCaseAD.h:55

Member Function Documentation

◆ computeDerivatives()

template<typename S , std::size_t n, template< typename > typename C = util::StdVector>
void olb::opti::OptiCaseAD< S, n, C >::computeDerivatives ( const C< S > & control,
C< S > & derivatives,
unsigned optiStep = 0 )
inlineoverride

Definition at line 87 of file optiCaseAD.h.

89 {
90 assert((control.size() == derivatives.size()));
91
92 auto adControl = util::iniAD<n,S,C>(control);
93
94 const T adResult = _adFunction(adControl, optiStep);
95
96 for(std::size_t it = 0; it < control.size(); ++it){
97 derivatives[it] = adResult.d(it);
98 }
99 }
util::ADf< S, n > T
Definition optiCaseAD.h:54

References olb::opti::OptiCaseAD< S, n, C >::_adFunction, olb::opti::control, and olb::util::ADf< T, DIM >::d().

+ Here is the call graph for this function:

◆ evaluateObjective()

template<typename S , std::size_t n, template< typename > typename C = util::StdVector>
S olb::opti::OptiCaseAD< S, n, C >::evaluateObjective ( const C< S > & control,
unsigned optiStep = 0 )
inlineoverride

Definition at line 81 of file optiCaseAD.h.

83 {
84 return _function(control, optiStep);
85 }

References olb::opti::OptiCaseAD< S, n, C >::_function, and olb::opti::control.

Member Data Documentation

◆ _adFunction

template<typename S , std::size_t n, template< typename > typename C = util::StdVector>
std::function<T (const C<T>&, unsigned) olb::opti::OptiCaseAD< S, n, C >::_adFunction)
protected

Definition at line 58 of file optiCaseAD.h.

◆ _adFunctionHelp

template<typename S , std::size_t n, template< typename > typename C = util::StdVector>
std::function<T (const C<T>&) olb::opti::OptiCaseAD< S, n, C >::_adFunctionHelp) { [](const C<T>&){ return T{}; } }
protected

Definition at line 56 of file optiCaseAD.h.

56{ [](const C<T>&){ return T{}; } };

◆ _function

template<typename S , std::size_t n, template< typename > typename C = util::StdVector>
std::function<S (const C<S>&, unsigned) olb::opti::OptiCaseAD< S, n, C >::_function)
protected

Definition at line 57 of file optiCaseAD.h.

◆ _functionHelp

template<typename S , std::size_t n, template< typename > typename C = util::StdVector>
std::function<S (const C<S>&) olb::opti::OptiCaseAD< S, n, C >::_functionHelp) { [](const C<S>&){ return S{}; } }
protected

Definition at line 55 of file optiCaseAD.h.

55{ [](const C<S>&){ return S{}; } };

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