OpenLB 1.7
Loading...
Searching...
No Matches
optimizerSteepestDecent.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2012-2016 Mathias J. Krause, Benjamin Förster
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
29#ifndef OPTIMIZER_STEEPEST_DECENT_H
30#define OPTIMIZER_STEEPEST_DECENT_H
31
32#include "optimizerLineSearch.h"
33
34
35
36// All OpenLB code is contained in this namespace.
37namespace olb {
38
40namespace opti {
41
43
52template<typename S, typename C>
54
55private:
56 mutable OstreamManager clout;
57
58
59public:
61 int dimCtrl, S eps, int maxIt, S lambda, int maxStepAttempts,
62 std::string stepCondition, bool verboseOn=true, const std::string fname="",
63 const std::string logFileName="", bool withUpperBound=false, S upperBound=S(),
64 bool withLowerBound=false, S lowerBound=S(),
65 bool vectorBounds=false, S controlEps=S(std::numeric_limits<double>::epsilon() ),
66 std::vector<OptimizerLogType> gplotAnalysis = {})
68 dimCtrl, eps, maxIt, lambda, maxStepAttempts, stepCondition, verboseOn, fname, logFileName,
69 withUpperBound, upperBound, withLowerBound, lowerBound, vectorBounds, controlEps, true,gplotAnalysis),
70 clout(std::cout,"OptimizerSteepestDescent") {};
71
72 virtual void computeDirection()
73 {
74 // Update _derivative
75 // computeDerivative only if not already done by wolfeCondition()
76 if (!this->_nextDerivFlag) {
77 this->computeDerivatives(this->_control, this->_derivative);
78 }
79 else for (int iDim=0; iDim<this->_dimCtrl; iDim++) {
80 this->_derivative[iDim] = this->_nextDerivative[iDim];
81 }
82
83 // S normDerivative = util::euklidN(this->_derivative.data(), this->_dimCtrl);
84 for (int iDim=0; iDim<this->_dimCtrl; iDim++) {
85 this->_direction[iDim] = this->_derivative[iDim] ; // /normDerivative;
86 }
87 };
88};
89
90
92template<typename S, typename C = std::vector<S>>
94{
95 OstreamManager clout(std::cout,"createOptimizerSteepestDescent");
96
97 // create variables with default values
98 int maxIt = 100;
99
100 //S controlEps = S(std::numeric_limits<double>::epsilon() );
101 S controlEps = S(0);
102 S eps = S(1.e-10);
103
104 S lambda = 1.;
105 int maxStepAttempts = 100;
106 std::string stepCondition = "Armijo";
107
108 bool vectorBounds = false;
109 bool verboseOn=true;
110 std::string fname = "control.dat";
111 std::string logFileName = "log.txt";
112
113 bool withUpperBound = false;
114 S upperBound = S();
115 bool withLowerBound = false;
116 S lowerBound = S();
117
118 std::vector<OptimizerLogType> gplotAnalysis = {};
119 std::string gplotAnalysisString = "";
120
121 // Read Values from XML File from area "Optimization"
122 params.readOrWarn<int>("Optimization", "MaxIter", "", maxIt);
123
124 params.readOrWarn<S>("Optimization", "Tolerance", "", eps);
125 params.readOrWarn<S>("Optimization", "ControlTolerance", "", controlEps);
126 params.readOrWarn<S>("Optimization", "Lambda", "", lambda);
127 params.readOrWarn<int>("Optimization", "MaxStepAttempts", "", maxStepAttempts);
128 params.readOrWarn<std::string>("Optimization", "StepCondition", "", stepCondition);
129
130 params.readOrWarn<bool>("Optimization", "Verbose", "", verboseOn);
131 params.readOrWarn<std::string>("Optimization", "InputFileName", "", fname);
132 params.readOrWarn<std::string>("Optimization", "LogFileName", "", logFileName);
133
134 params.readOrWarn<bool>("Optimization", "VectorBounds", "", vectorBounds);
135 if ( params.readOrWarn<S>("Optimization", "UpperBound", "", upperBound, false, false) ) {
136 withUpperBound = true;
137 }
138
139 if ( params.readOrWarn<S>("Optimization", "LowerBound", "", lowerBound, false, false) ) {
140 withLowerBound = true;
141 }
142
143 // get the parameters for the gnuplot Analysis from the xml file from the VisualizationGnuplot area
144 params.readOrWarn<std::string>("Optimization", "VisualizationGnuplot", "VisualizedParameters", "", gplotAnalysisString, false, false);
145 // transform the data from the xml file to the enums needed for continueing
146 getGnuplotTagsFromString(gplotAnalysisString, gplotAnalysis);
147
148 // Create Optimizer Object
149 return new OptimizerSteepestDescent<S,C>(dimCtrl, eps, maxIt, lambda, maxStepAttempts, stepCondition,
150 verboseOn, fname, logFileName, withUpperBound, upperBound, withLowerBound, lowerBound,
151 vectorBounds, controlEps, gplotAnalysis);
152}
153
154} // namespace opti
155
156} // namespace olb
157
158#endif
class for marking output with some text
bool readOrWarn(std::string name_parameter_1, std::string name_parameter_2, std::string name_parameter_3, ParameterType &var, bool defaultAvailable=true, bool exitIfMissing=false, bool showWarning=true) const
This wrapper function reads the given parameter from the "type_parameter" and "name_parameter_1" or "...
Definition xmlReader.h:178
Optimization algorithm: LineSearch.
Optimization algorithm: SteepestDescent.
OptimizerSteepestDescent(int dimCtrl, S eps, int maxIt, S lambda, int maxStepAttempts, std::string stepCondition, bool verboseOn=true, const std::string fname="", const std::string logFileName="", bool withUpperBound=false, S upperBound=S(), bool withLowerBound=false, S lowerBound=S(), bool vectorBounds=false, S controlEps=S(std::numeric_limits< double >::epsilon()), std::vector< OptimizerLogType > gplotAnalysis={})
C _derivative
Vector of derivatives of the object functional with respect to the controlled variables.
Definition optimizer.h:71
int _dimCtrl
Number of controlled variables.
Definition optimizer.h:63
C _control
Vector of controlled variables (size _dimCtrl)
Definition optimizer.h:65
void computeDerivatives(const C &control, C &derivatives)
Definition optimizer.h:144
OptimizerSteepestDescent< S, C > * createOptimizerSteepestDescent(XMLreader const &params, std::size_t dimCtrl)
Creator Function for Steepest Decent.
void getGnuplotTagsFromString(std::string gplotAnalysisString, std::vector< OptimizerLogType > &gplotAnalysis)
the gplotAnalysisString is gained from the xml file and the function than separates and prepares it t...
Definition optimizer.hh:236
Top level namespace for all of OpenLB.
Optimization Code.
The description of line search optimization algorithm – header file.