Loading...
Searching...
No Matches
adjointSolverManager.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::adjointSolverManager
31
32Description
33 Class for managing adjoint solvers, which may be more than one per
34 operating point
35
36SourceFiles
37 adjointSolverManager.C
38
39\*---------------------------------------------------------------------------*/
40
41#ifndef adjointSolverManager_H
42#define adjointSolverManager_H
43
44#include "adjointSolver.H"
45
46// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47
48namespace Foam
49{
51/*---------------------------------------------------------------------------*\
52 Class adjointSolverManager Declaration
53\*---------------------------------------------------------------------------*/
54
55class adjointSolverManager
56:
57 public regIOobject
58{
59private:
60
61 // Private Member Functions
62
63 //- No copy construct
64 adjointSolverManager(const adjointSolverManager&) = delete;
65
66 //- No copy assignment
67 void operator=(const adjointSolverManager&) = delete;
68
69
70protected:
71
72 // Protected Data
78 const word managerName_;
80 const word managerType_;
97
98
99public:
101 TypeName("adjointSolverManager");
102
103
104 // Constructors
105
106 //- Construct from components
107 adjointSolverManager
108 (
109 fvMesh& mesh,
110 autoPtr<designVariables>& designVars,
111 const word& managerType,
112 const dictionary& dict,
113 bool overrideUseSolverName
114 );
115
116
117 //- Destructor
118 virtual ~adjointSolverManager() = default;
119
120
121 // Member Functions
122
123 bool readDict(const dictionary& dict);
124
125
126 // Access
127
128 //- Const access to the manager name
129 const word& managerName() const;
130
131 //- Const access to the primal solver name
132 const word& primalSolverName() const;
133
134 //- Const access to the construction dictionary
135 const dictionary& dict() const;
136
137 //- Const access to adjoint solvers
139
140 //- Non-const access to adjoint solvers
142
143 //- Return the names of all adjointSolvers
145
146 //- Const access to adjoint solvers
147 scalar operatingPointWeight() const;
148
149 //- Return number of active adjoint solvers, either corresponding
150 // to objectives or constraints
151 label nActiveAdjointSolvers() const;
152
153 //- Static function returning the number of active adjoint
154 // solvers reading dict
155 static label nActiveAdjointSolvers(const dictionary& dict);
156
157 //- Number of constraints
158 // Is the sum of one-sided and double-sided constraints, the
159 // latter multiplied by two
160 label nConstraints() const;
161
162 //- Number of adjoint solvers corresponding to one-sided
163 //- constraints
164 label nOneSidedConstraints() const;
165
166 //- Number of adjoint solvers corresponding to double-sided
167 //- constraints
168 label nDoubleSidedConstraints() const;
169
170 //- Number of adjoint solvers corresponding to objectives
171 label nObjectives() const;
172
173 //- Total number of adjoint solvers
174 label nAdjointSolvers() const;
175
176
177 // Evolution
178
179 //- Update objective function-related values and solve adjoint
180 //- equations
182
183 //- Aggregate sensitivities from various adjoint solvers
185
186 //- Get constraint sensitivities. One scalarField per constraint
188
189 //- Compute sensitivities for all adjoint solvers
190 //- (both objective- and constraint-related ones)
192
193 //- Clear sensitivity fields from all adjoint solvers
194 void clearSensitivities();
195
196 //- Get objective value
197 scalar objectiveValue();
198
199 //- Get constraint values
201
202 //- Update fields related to primal solution.
203 // For instance, primal fields of adjoint turbulence models
205
206 //- Whether the primal solver corresponding to the
207 //- adjointSolverManager is the master one, in case of coupled
208 //- solvers
209 bool isMaster() const;
210
211
212 // IO
213
214 virtual bool writeData(Ostream&) const
215 {
216 return true;
217 }
218};
219
220
221// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
222
223} // End namespace Foam
224
225// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226
227#endif
228
229// ************************************************************************* //
const word & name() const noexcept
Return the object name.
Definition IOobjectI.H:205
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition PtrList.H:67
void clearSensitivities()
Clear sensitivity fields from all adjoint solvers.
TypeName("adjointSolverManager")
label nOneSidedConstraints() const
Number of adjoint solvers corresponding to one-sided constraints.
scalar objectiveValue()
Get objective value.
PtrList< scalarField > constraintSensitivities()
Get constraint sensitivities. One scalarField per constraint.
label nAdjointSolvers() const
Total number of adjoint solvers.
tmp< scalarField > constraintValues()
Get constraint values.
bool isMaster() const
Whether the primal solver corresponding to the adjointSolverManager is the master one,...
bool readDict(const dictionary &dict)
tmp< scalarField > aggregateSensitivities()
Aggregate sensitivities from various adjoint solvers.
void computeAllSensitivities()
Compute sensitivities for all adjoint solvers (both objective- and constraint-related ones).
const word & primalSolverName() const
Const access to the primal solver name.
void updatePrimalBasedQuantities(const word &name)
Update fields related to primal solution.
wordList adjointSolversNames() const
Return the names of all adjointSolvers.
PtrList< adjointSolver > adjointSolvers_
label nConstraints() const
Number of constraints.
virtual bool writeData(Ostream &) const
Pure virtual writeData function.
void solveAdjointEquations()
Update objective function-related values and solve adjoint equations.
const dictionary & dict() const
Const access to the construction dictionary.
label nDoubleSidedConstraints() const
Number of adjoint solvers corresponding to double-sided constraints.
scalar operatingPointWeight() const
Const access to adjoint solvers.
autoPtr< designVariables > & designVars_
virtual ~adjointSolverManager()=default
Destructor.
const PtrList< adjointSolver > & adjointSolvers() const
Const access to adjoint solvers.
label nActiveAdjointSolvers() const
Return number of active adjoint solvers, either corresponding.
label nObjectives() const
Number of adjoint solvers corresponding to objectives.
const word & managerName() const
Const access to the manager name.
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
regIOobject(const IOobject &io, const bool isTimeObject=false)
Construct from IOobject. The optional flag adds special handling if the object is the top-level regIO...
Definition regIOobject.C:43
A class for managing temporary objects.
Definition tmp.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
List< label > labelList
A List of labels.
Definition List.H:62
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68