lineSearch.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2007-2019 PCOpt/NTUA
9  Copyright (C) 2013-2019 FOSS GP
10  Copyright (C) 2019 OpenCFD Ltd.
11 -------------------------------------------------------------------------------
12 License
13  This file is part of OpenFOAM.
14 
15  OpenFOAM is free software: you can redistribute it and/or modify it
16  under the terms of the GNU General Public License as published by
17  the Free Software Foundation, either version 3 of the License, or
18  (at your option) any later version.
19 
20  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27 
28 
29 Class
30  Foam::lineSearch
31 
32 Description
33  Abstract base class for line search methods
34 
35 SourceFiles
36  lineSearch.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef lineSearch_H
41 #define lineSearch_H
42 
43 #include "runTimeSelectionTables.H"
44 #include "IOdictionary.H"
45 #include "scalarField.H"
46 #include "stepUpdate.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class lineSearch Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 class lineSearch
58 {
59 protected:
60 
61  // Protected data
62 
63  //- Subdict within updateMethod
64  const dictionary dict_;
65 
66  //- IOdictionary under time/uniform for continuation
68 
69  //- Directional derivative of the merit function
70  scalar directionalDeriv_;
71 
72  //- Update direction
74 
75  //- Old merit value from this opt cycle
77 
78  //- New merit value from this opt cycle
79  scalar newMeritValue_;
80 
81  //- Merit directional deriv from the previous opt cycle
82  scalar prevMeritDeriv_;
83 
84  //- Correction multiplier at the first step of line search
85  scalar initialStep_;
86 
87  //- Minimum allowed correction multiplier
88  scalar minStep_;
89 
90  //- Correction multiplier
91  scalar step_;
92 
93  //- Inner line search iteration
94  label iter_;
95 
96  //- Maximum line search iterations
97  label maxIters_;
98 
99  //- Whether to extrapolate the correction multiplier for
100  //- this optimisation cycle based on the previous ones.
101  // Useful for non-quasi Newton methods
103 
104  //- Mechanism to update method if line search conditions are not set
107 
108  // Protected Member Functions
109 
110  //- Optional coeffs dict
112 
113 
114 private:
115 
116  // Private Member Functions
117 
118  //- No copy construct
119  lineSearch(const lineSearch&) = delete;
120 
121  //- No copy assignment
122  void operator=(const lineSearch&) = delete;
123 
125 public:
126 
127  //- Runtime type information
128  TypeName("lineSearch");
130 
131  // Declare run-time constructor selection table
132 
134  (
135  autoPtr,
136  lineSearch,
137  dictionary,
138  (
139  const dictionary& dict,
140  const Time& time
141  ),
142  (dict, time)
143  );
144 
145 
146  // Constructors
147 
148  //- Construct from components
149  lineSearch(const dictionary& dict, const Time& time);
150 
151  // Selectors
152 
153  //- Return a reference to the selected turbulence model
154  static autoPtr<lineSearch> New
155  (
156  const dictionary& dict,
157  const Time& time
158  );
159 
160 
161  //- Destructor
162  virtual ~lineSearch() = default;
163 
164 
165  // Member Functions
166 
167  //- Set objective derivative
168  virtual void setDeriv(const scalar deriv);
169 
170  //- Set direction
171  void setDirection(const scalarField& direction);
172 
173  //- Set new objective value
174  void setNewMeritValue(const scalar value);
175 
176  //- Set old objective value
177  void setOldMeritValue(const scalar value);
178 
179  //- Reset step to initial value
180  virtual void reset();
181 
182  //- Get max number of iterations
183  label maxIters() const;
184 
185  //- Get current step
186  scalar step() const;
187 
188  //- Return the correction of the design variables
189  virtual bool converged() = 0;
190 
191  //- Update the line search step based on the specific line search
192  //- strategy, e.g. bisection, quadratic fit, etc.
193  virtual void updateStep() = 0;
194 
195  //- Update the step using the supplied value
196  virtual void updateStep(const scalar newStep);
197 
198 
199  // Member operators
200 
201  //- Increment iteration number and store merit value corresponding to
202  //- the previous optimisation cycle
203  virtual lineSearch& operator++();
204 
205  //- Postfix increment. Necessary for compilation
206  virtual lineSearch& operator++(int);
207 };
208 
209 
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 
212 } // End namespace Foam
213 
214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 
216 #endif
217 
218 // ************************************************************************* //
scalar prevMeritDeriv_
Merit directional deriv from the previous opt cycle.
Definition: lineSearch.H:91
dictionary dict
void setDirection(const scalarField &direction)
Set direction.
Definition: lineSearch.C:136
scalarField direction_
Update direction.
Definition: lineSearch.H:76
autoPtr< stepUpdate > stepUpdate_
Mechanism to update method if line search conditions are not set.
Definition: lineSearch.H:129
uint8_t direction
Definition: direction.H:48
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
virtual void updateStep()=0
Update the line search step based on the specific line search strategy, e.g. bisection, quadratic fit, etc.
const dictionary dict_
Subdict within updateMethod.
Definition: lineSearch.H:61
bool extrapolateInitialStep_
Whether to extrapolate the correction multiplier for this optimisation cycle based on the previous on...
Definition: lineSearch.H:124
const dictionary & coeffsDict()
Optional coeffs dict.
Definition: lineSearch.C:37
TypeName("lineSearch")
Runtime type information.
static autoPtr< lineSearch > New(const dictionary &dict, const Time &time)
Return a reference to the selected turbulence model.
Definition: lineSearch.C:89
void setNewMeritValue(const scalar value)
Set new objective value.
Definition: lineSearch.C:142
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
virtual void setDeriv(const scalar deriv)
Set objective derivative.
Definition: lineSearch.C:129
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:50
scalar newMeritValue_
New merit value from this opt cycle.
Definition: lineSearch.H:86
scalar minStep_
Minimum allowed correction multiplier.
Definition: lineSearch.H:101
scalar directionalDeriv_
Directional derivative of the merit function.
Definition: lineSearch.H:71
void setOldMeritValue(const scalar value)
Set old objective value.
Definition: lineSearch.C:149
virtual lineSearch & operator++()
Increment iteration number and store merit value corresponding to the previous optimisation cycle...
Definition: lineSearch.C:195
virtual void reset()
Reset step to initial value.
Definition: lineSearch.C:156
scalar step_
Correction multiplier.
Definition: lineSearch.H:106
label iter_
Inner line search iteration.
Definition: lineSearch.H:111
virtual ~lineSearch()=default
Destructor.
scalar initialStep_
Correction multiplier at the first step of line search.
Definition: lineSearch.H:96
label maxIters_
Maximum line search iterations.
Definition: lineSearch.H:116
scalar step() const
Get current step.
Definition: lineSearch.C:183
Abstract base class for line search methods.
Definition: lineSearch.H:52
IOdictionary lineSearchDict_
IOdictionary under time/uniform for continuation.
Definition: lineSearch.H:66
declareRunTimeSelectionTable(autoPtr, lineSearch, dictionary,(const dictionary &dict, const Time &time),(dict, time))
scalar oldMeritValue_
Old merit value from this opt cycle.
Definition: lineSearch.H:81
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Macros to ease declaration of run-time selection tables.
virtual bool converged()=0
Return the correction of the design variables.
label maxIters() const
Get max number of iterations.
Definition: lineSearch.C:177
Namespace for OpenFOAM.