Loading...
Searching...
No Matches
optimisationManager.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-2023 PCOpt/NTUA
9 Copyright (C) 2013-2023 FOSS GP
10 Copyright (C) 2019 OpenCFD Ltd.
11-------------------------------------------------------------------------------
12License
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
29Class
30 Foam::optimisationManager
31
32Description
33 Abstract base class for optimisation methods
34
35SourceFiles
36 optimisationManager.C
37
38\*---------------------------------------------------------------------------*/
39
40#ifndef optimisationManager_H
41#define optimisationManager_H
42
44#include "IOdictionary.H"
45#include "primalSolver.H"
46#include "designVariables.H"
49
50// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51
52namespace Foam
53{
55/*---------------------------------------------------------------------------*\
56 Class optimisationManager Declaration
57\*---------------------------------------------------------------------------*/
58
59class optimisationManager
60:
61 public IOdictionary
62{
63protected:
64
65 // Protected data
66
67 //- Reference to the mesh
69
70 //- Reference to the time
71 Time& time_;
72
73 //- Design variables of the optimisation problem.
74 // Constructed before the adjoint solvers, since
75 // some objective functions depend on their values
77
78 //- List of primal solvers to be included in the optimisation
80
81 //- List of adjoint solver managers to be included in the optimisation
84 //- Type of the optimisation manager (singleRun, (un)steadyOptimisation)
85 const word managerType_;
86
87 //- Helper class managing parts of the optimisation.
88 // Allocated only when an actual optimisation is conducted.
90
91 //- Switch defining if the design variables should be updated or not.
94
95 // Protected Member Functions
96
97 //- Reset time
98 // Does nothing in base, useful in unsteady adjoint
99 virtual void resetTime
102 const label startTimeIndex,
103 const scalar endTime
104 );
106 //- Update design variables
107 virtual void moveDesignVariables();
108
109 //- Update design variables. Multiplication with line search step
110 // happens inside the update(direction) function
111 virtual void moveDesignVariables
112 (
114 );
115
116 //- Update design variables using a line-search
117 void lineSearchUpdate();
118
119 //- Update design variables using a fixed step
120 void fixedStepUpdate();
121
122 //- Initialization. Construct primal and adjoint solvers
123 virtual void initialize();
124
125
126private:
127
128 // Private Member Functions
129
130 //- No copy construct
131 optimisationManager(const optimisationManager&) = delete;
132
133 //- No copy assignment
134 void operator=(const optimisationManager&) = delete;
135
136
137public:
138
139 //- Runtime type information
140 TypeName("optimisationManager");
141
142
143 // Declare run-time constructor selection table
144
146 (
147 autoPtr,
148 optimisationManager,
150 (
151 fvMesh& mesh
152 ),
153 (mesh)
154 );
155
156
157 // Constructors
158
159 //- Construct from components
160 optimisationManager(fvMesh& mesh);
161
162
163 // Selectors
164
165 //- Return a reference to the selected turbulence model
167
168
169 //- Destructor
170 virtual ~optimisationManager() = default;
171
172
173 // Member Functions
174
175 // Access
176
177 //- Get the primal solvers
179 {
180 return primalSolvers_;
181 }
182
183 //- Get the adjoint solver managers
185 {
187 }
188
189 //- Get the design variables
190 inline autoPtr<designVariables>& getDesignVariables()
191 {
192 return designVars_;
193 }
194
195 //- Get the mechanism supporting the update of the design variables
196 inline autoPtr<designVariablesUpdate>& getOptimisationType()
197 {
198 return dvUpdate_;
199 }
200
201
202 // Evolution
203
204 //- Changes in case of run-time update of optimisationDict
205 virtual bool read();
206
207 //- Prefix increment
208 virtual optimisationManager& operator++() = 0;
210 //- Postfix increment, this is identical to the prefix increment
211 virtual optimisationManager& operator++(int) = 0;
212
213 //- Return true if end of optimisation run.
214 // Also, updates the design variables if needed
215 virtual bool checkEndOfLoopAndUpdate() = 0;
216
217 //- Return true if end of optimisation run
218 virtual bool end() = 0;
220 //- Whether to update the design variables
221 virtual bool update() = 0;
222
223 //- Update design variables.
224 // Might employ a line search to find a correction satisfying the
225 // step convergence criteria
226 virtual void updateDesignVariables();
228 //- Solve all primal equations
229 virtual void solvePrimalEquations();
230
231 //- Solve all adjoint equations
232 virtual void solveAdjointEquations();
233
234 //- Compute all adjoint sensitivities
235 virtual void computeSensitivities();
236
237 //- Clear all adjoint sensitivities
238 virtual void clearSensitivities();
239
240 //- Solve all primal equations
241 virtual void updatePrimalBasedQuantities();
242};
244
245// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246
247} // End namespace Foam
248
249// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
250
251#endif
252
253// ************************************************************************* //
Foam::label startTime
IOdictionary(const IOobject &io, const dictionary *fallback=nullptr)
Construct given an IOobject and optional fallback dictionary content.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition PtrList.H:67
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition Switch.H:81
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
virtual void clearSensitivities()
Clear all adjoint sensitivities.
virtual ~optimisationManager()=default
Destructor.
virtual bool end()=0
Return true if end of optimisation run.
virtual bool checkEndOfLoopAndUpdate()=0
Return true if end of optimisation run.
TypeName("optimisationManager")
Runtime type information.
virtual void initialize()
Initialization. Construct primal and adjoint solvers.
virtual void resetTime(const dimensionedScalar startTime, const label startTimeIndex, const scalar endTime)
Reset time.
virtual optimisationManager & operator++(int)=0
Postfix increment, this is identical to the prefix increment.
const word managerType_
Type of the optimisation manager (singleRun, (un)steadyOptimisation).
autoPtr< designVariablesUpdate > dvUpdate_
Helper class managing parts of the optimisation.
virtual void moveDesignVariables()
Update design variables.
autoPtr< designVariablesUpdate > & getOptimisationType()
Get the mechanism supporting the update of the design variables.
declareRunTimeSelectionTable(autoPtr, optimisationManager, dictionary,(fvMesh &mesh),(mesh))
virtual optimisationManager & operator++()=0
Prefix increment.
Switch shouldUpdateDesignVariables_
Switch defining if the design variables should be updated or not.
virtual bool update()=0
Whether to update the design variables.
virtual void solvePrimalEquations()
Solve all primal equations.
virtual void updateDesignVariables()
Update design variables.
virtual void updatePrimalBasedQuantities()
Solve all primal equations.
autoPtr< designVariables > designVars_
Design variables of the optimisation problem.
Time & time_
Reference to the time.
PtrList< adjointSolverManager > adjointSolverManagers_
List of adjoint solver managers to be included in the optimisation.
autoPtr< designVariables > & getDesignVariables()
Get the design variables.
virtual void solveAdjointEquations()
Solve all adjoint equations.
void lineSearchUpdate()
Update design variables using a line-search.
PtrList< primalSolver > primalSolvers_
List of primal solvers to be included in the optimisation.
static autoPtr< optimisationManager > New(fvMesh &mesh)
Return a reference to the selected turbulence model.
PtrList< adjointSolverManager > & adjointSolverManagers()
Get the adjoint solver managers.
fvMesh & mesh_
Reference to the mesh.
PtrList< primalSolver > & primalSolvers()
Get the primal solvers.
virtual void computeSensitivities()
Compute all adjoint sensitivities.
virtual bool read()
Changes in case of run-time update of optimisationDict.
void fixedStepUpdate()
Update design variables using a fixed step.
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
Namespace for OpenFOAM.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
uint8_t direction
Definition direction.H:49
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Macros to ease declaration of run-time selection tables.
#define declareRunTimeSelectionTable(ptrWrapper, baseType, argNames, argList, parList)
Declare a run-time selection (variables and adder classes).
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68