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

Gradient computation with central difference quotients. More...

#include <optiCase.h>

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

Public Member Functions

template<typename F >
 OptiCaseCDQ (F function, std::function< void(void)> postEvaluation=[](){})
 
template<typename F >
 OptiCaseCDQ (F function, S stepWidth, std::function< void(void)> postEvaluation=[](){})
 
void computeDerivatives (const C &control, C &derivatives, unsigned optiStep=0) override
 
- Public Member Functions inherited from olb::opti::OptiCaseDQ< S, C >
 OptiCaseDQ (std::function< S(const C &, unsigned)> function, std::function< void(void)> postEvaluation)
 
 OptiCaseDQ (std::function< S(const C &)> function, std::function< void(void)> postEvaluation)
 
template<typename F >
 OptiCaseDQ (F function, S stepWidth, std::function< void(void)> postEvaluation)
 
evaluateObjective (const C &control, unsigned optiStep=0) override
 
- Public Member Functions inherited from olb::opti::OptiCase< S, C >
 OptiCase ()=default
 
 OptiCase (std::function< void(void)> postEvaluation)
 
void postEvaluation ()
 

Additional Inherited Members

- Protected Attributes inherited from olb::opti::OptiCaseDQ< S, C >
std::function< S(const C &) _functionHelp ) { [](const C&){ return S{}; } }
 
std::function< S(const C &, unsigned) _function )
 
_stepWidth {1.e-8}
 
bool _objectiveComputed {false}
 
_objective
 
- Protected Attributes inherited from olb::opti::OptiCase< S, C >
std::function< void(void)> _postEvaluation { [](){} }
 

Detailed Description

template<typename S, typename C>
class olb::opti::OptiCaseCDQ< S, C >

Gradient computation with central difference quotients.

Definition at line 216 of file optiCase.h.

Constructor & Destructor Documentation

◆ OptiCaseCDQ() [1/2]

template<typename S , typename C >
template<typename F >
olb::opti::OptiCaseCDQ< S, C >::OptiCaseCDQ ( F function,
std::function< void(void)> postEvaluation = [](){} )
inlineexplicit

Definition at line 222 of file optiCase.h.

223 {})
225 { }
OptiCaseCDQ(F function, std::function< void(void)> postEvaluation=[](){})
Definition optiCase.h:222
OptiCaseDQ(std::function< S(const C &, unsigned)> function, std::function< void(void)> postEvaluation)
Definition optiCase.h:113
void postEvaluation()
Definition optiCase.h:56

◆ OptiCaseCDQ() [2/2]

template<typename S , typename C >
template<typename F >
olb::opti::OptiCaseCDQ< S, C >::OptiCaseCDQ ( F function,
S stepWidth,
std::function< void(void)> postEvaluation = [](){} )
inline

Definition at line 228 of file optiCase.h.

229 {})
230 : OptiCaseCDQ::OptiCaseDQ(function, stepWidth, postEvaluation)
231 { }

Member Function Documentation

◆ computeDerivatives()

template<typename S , typename C >
void olb::opti::OptiCaseCDQ< S, C >::computeDerivatives ( const C & control,
C & derivatives,
unsigned optiStep = 0 )
inlineoverridevirtual

Implements olb::opti::OptiCase< S, C >.

Definition at line 233 of file optiCase.h.

235 {
236 assert((control.size() == derivatives.size()));
237
238 for (std::size_t it = 0; it < control.size(); ++it)
239 {
240 C shiftedControl(control);
241 shiftedControl[it] += this->_stepWidth;
242 S shiftedObjective_plus = this->evaluateObjective(shiftedControl, optiStep);
243
244 shiftedControl[it] = control[it] - this->_stepWidth;
245 S shiftedObjective_minus = this->evaluateObjective(shiftedControl, optiStep);
246
247 derivatives[it] = 0.5 * (shiftedObjective_plus - shiftedObjective_minus) / this->_stepWidth;
248 }
249 }
S evaluateObjective(const C &control, unsigned optiStep=0) override
Definition optiCase.h:133

References olb::opti::OptiCaseDQ< S, C >::_stepWidth, olb::opti::control, and olb::opti::OptiCaseDQ< S, C >::evaluateObjective().

+ Here is the call graph for this function:

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