quasiNewton.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) 2021-2023 PCOpt/NTUA
9  Copyright (C) 2021-2023 FOSS GP
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 
28 Class
29  Foam::quasiNewton
30 
31 Description
32  Base class for quasi-Newton methods
33 
34 SourceFiles
35  quasiNewton.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef quasiNewton_H
40 #define quasiNewton_H
41 
42 #include "updateMethod.H"
43 #include "scalarMatrices.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class quasiNewton Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class quasiNewton
55 :
56  public updateMethod
57 {
58 protected:
59 
60  // Protected data
61 
62  //- Step for the Newton method
63  scalar etaHessian_;
64 
65  //- Number of first steepest descent steps
66  label nSteepestDescent_;
67 
68  //- Scale the initial unitary Hessian approximation
69  bool scaleFirstHessian_;
70 
71  //- The Hessian or its inverse, depending on the deriving class.
72  // Has the size of the active design variables.
73  // autoPtr to avoid allocation by limited memory variants
75 
76  //- The previous derivatives
78 
79  //- The previous correction
81 
82 
83  // Protected Member Functions
84 
85  //- Update approximation of the inverse Hessian
86  virtual void updateHessian() = 0;
87 
88  //- Update design variables
89  virtual void update() = 0;
90 
91  //- Allocate the Hessian matrix
92  void allocateHessian();
93 
94 
95 private:
96 
97  // Private Member Functions
98 
99  //- No copy construct
100  quasiNewton(const quasiNewton&) = delete;
101 
102  //- No copy assignment
103  void operator=(const quasiNewton&) = delete;
104 
105 
106 public:
107 
108  //- Runtime type information
109  TypeName("quasiNewton");
110 
111 
112  // Constructors
113 
114  //- Construct from components
116  (
117  const fvMesh& mesh,
118  const dictionary& dict,
119  autoPtr<designVariables>& designVars,
120  const label nConstraints,
121  const word& type
122  );
123 
124 
125  //- Destructor
126  virtual ~quasiNewton() = default;
127 
128 
129  // Member Functions
130 
131  //- Compute design variables correction
132  void computeCorrection();
133 
134  //- Update old correction. Useful for quasi-Newton methods coupled with
135  //- line search
136  virtual void updateOldCorrection(const scalarField& oldCorrection);
137 
138  //- Write useful quantities to files
139  virtual bool writeData(Ostream& os) const;
140 };
141 
142 
143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
144 
145 } // End namespace Foam
146 
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 
149 #endif
150 
151 // ************************************************************************* //
virtual void update()=0
Update design variables.
dictionary dict
label nConstraints() const
Get the number of constraints.
Definition: updateMethod.C:393
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Abstract base class for optimisation methods.
Definition: updateMethod.H:50
virtual void updateHessian()=0
Update approximation of the inverse Hessian.
bool scaleFirstHessian_
Scale the initial unitary Hessian approximation.
Definition: quasiNewton.H:70
virtual bool writeData(Ostream &os) const
Write useful quantities to files.
Definition: quasiNewton.C:103
TypeName("quasiNewton")
Runtime type information.
void computeCorrection()
Compute design variables correction.
Definition: quasiNewton.C:83
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
dynamicFvMesh & mesh
Base class for quasi-Newton methods.
Definition: quasiNewton.H:49
A class for handling words, derived from Foam::string.
Definition: word.H:63
autoPtr< SquareMatrix< scalar > > Hessian_
The Hessian or its inverse, depending on the deriving class.
Definition: quasiNewton.H:78
scalarField derivativesOld_
The previous derivatives.
Definition: quasiNewton.H:83
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
void allocateHessian()
Allocate the Hessian matrix.
Definition: quasiNewton.C:35
OBJstream os(runTime.globalPath()/outputName)
virtual void updateOldCorrection(const scalarField &oldCorrection)
Update old correction. Useful for quasi-Newton methods coupled with line search.
Definition: quasiNewton.C:96
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
virtual ~quasiNewton()=default
Destructor.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
label nSteepestDescent_
Number of first steepest descent steps.
Definition: quasiNewton.H:65
Namespace for OpenFOAM.
scalar etaHessian_
Step for the Newton method.
Definition: quasiNewton.H:60
scalarField correctionOld_
The previous correction.
Definition: quasiNewton.H:88