OpenLB 1.8.1
Loading...
Searching...
No Matches
olb::opti::OptiCaseFDQ< S, C > Class Template Reference

Gradient computation with forward difference quotients. More...

#include <optiCase.h>

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

Public Member Functions

template<typename F >
 OptiCaseFDQ (F function, std::function< void(void)> postEvaluation=[](){})
 
template<typename F >
 OptiCaseFDQ (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::OptiCaseFDQ< S, C >

Gradient computation with forward difference quotients.

Definition at line 155 of file optiCase.h.

Constructor & Destructor Documentation

◆ OptiCaseFDQ() [1/2]

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

Definition at line 161 of file optiCase.h.

162 {})
164 { }
OptiCaseDQ(std::function< S(const C &, unsigned)> function, std::function< void(void)> postEvaluation)
Definition optiCase.h:124
OptiCaseFDQ(F function, std::function< void(void)> postEvaluation=[](){})
Definition optiCase.h:161
std::string function(const std::string &body, const std::string &arg)
Print as functions.

◆ OptiCaseFDQ() [2/2]

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

Definition at line 167 of file optiCase.h.

168 {})
170 { }

Member Function Documentation

◆ computeDerivatives()

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

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

Definition at line 172 of file optiCase.h.

174 {
175 assert((control.size() == derivatives.size()));
176
177 if (!(this->_objectiveComputed)) {
178 this->evaluateObjective(control, optiStep);
179 }
180 const S objective(this->_objective);
181
182 for (std::size_t it = 0; it < control.size(); ++it)
183 {
184 C shiftedControl(control);
185 shiftedControl[it] += this->_stepWidth;
186 S shiftedObjective = this->evaluateObjective(shiftedControl, optiStep);
187 derivatives[it] = (shiftedObjective - objective) / this->_stepWidth;
188 }
189 this->_objectiveComputed = false;
190 }
S evaluateObjective(const C &control, unsigned optiStep=0) override
Definition optiCase.h:144

References olb::opti::OptiCaseDQ< S, C >::_objectiveComputed, 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: