Loading...
Searching...
No Matches
designVariables.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-------------------------------------------------------------------------------
11License
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
28Class
29 Foam::designVariables
30
31Description
32 Abstract base class for defining design variables.
33
34SourceFiles
35 designVariables.C
36
37\*---------------------------------------------------------------------------*/
38
39#ifndef designVariables_H
40#define designVariables_H
41
42#include "fvMesh.H"
43#include "volFieldsFwd.H"
44#include "volFields.H"
45#include "dictionary.H"
46#include "primalSolver.H"
48#include "adjointSensitivity.H"
50
51// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52
53namespace Foam
54{
55
58/*---------------------------------------------------------------------------*\
59 Class designVariables Declaration
60\*---------------------------------------------------------------------------*/
61
62class designVariables
63:
64 public scalarField
66protected:
67
68 // Protected data
69
72
73 //- Which of the design variables will be updated
75
76 //- Copy of old design variables. Useful when performing line-search
78
79 //- Maximum design variables' change in the first optimisation cycle
80 // Used when eta is not used in updateMethod
82
83 //- Lower bounds of the design variables
85
86 //- Upper bounds of the design variables
89
90 // Protected Member Functions
91
92 //- Read bounds for design variables, if present
94 (
95 autoPtr<scalar> lowerBoundPtr = nullptr,
96 autoPtr<scalar> upperBoundPtr = nullptr
97 );
98
99
100private:
101
102 // Private Member Functions
103
104 //- Disallow default bitwise copy construct
105 designVariables(const designVariables&) = delete;
106
107 //- Disallow default bitwise assignment
108 void operator=(const designVariables&) = delete;
109
110
111public:
112
113 //- Runtime type information
114 TypeName("designVariables");
115
116
117 // Declare run-time constructor selection table
118
120 (
121 autoPtr,
122 designVariables,
123 designVariables,
124 (
125 fvMesh& mesh,
126 const dictionary& dict
127 ),
129 );
130
131
132 // Constructors
134 //- Construct from dictionary
135 designVariables
136 (
137 fvMesh& mesh,
138 const dictionary& dict
139 );
140
141 //- Construct from dictionary and size
142 designVariables
143 (
144 fvMesh& mesh,
145 const dictionary& dict,
146 const label size
147 );
148
149
150 // Selectors
151
152 //- Return a reference to the selected design variables
154 (
155 fvMesh& mesh,
156 const dictionary& dict
157 );
158
159
160 //- Destructor
161 virtual ~designVariables() = default;
162
163
164 // Member Functions
165
166 //- Read dictionary if changed
167 virtual bool readDict(const dictionary& dict);
168
169 //- Get the design variables
170 // Defaults to *this.
171 // Virtual for potential overriding from derived classes
172 virtual const scalarField& getVars() const;
173
174 //- Get the design variables
175 // Defaults to *this.
176 // Virtual for potential overriding from derived classes
177 virtual scalarField& getVars();
178
179 //- Update design variables based on a given correction
180 // Translates the scalarField of corrections to a meaningful
181 // update of the design variables
182 virtual void update(scalarField& correction) = 0;
184 //- Store design variables, as the starting point for line search
185 virtual void storeDesignVariables();
186
187 //- Reset to the starting point of line search
188 virtual void resetDesignVariables();
189
190 //- Compute eta if not set in the first step
191 virtual scalar computeEta(scalarField& correction) = 0;
192
193 //- Whether to use global sum when computing matrix-vector products
194 //- in update methods
195 // Depends on whether the design variables are common for all
196 // processors (e.g. volumetric B-Splines control points) or distributed
197 // across them (e.g. topology optimisation)
198 virtual bool globalSum() const = 0;
199
200 //- Return list of active design variables
201 inline const labelList& activeDesignVariables() const;
202
203 //- Check whether the max. initial change of the design variables has
204 //- been set
205 inline bool isMaxInitChangeSet() const;
206
207 //- Get maxInitChange
208 inline const autoPtr<scalar>& getMaxInitChange();
209
210 //- Set maxInitChange
211 inline void setMaxInitChange(const scalar maxInitChange);
212
213 //- Trigger the recomputation of eta by updateMethod
214 inline virtual bool resetEta() const;
216 //- Get min bounds for the design variables
217 inline const autoPtr<scalarField>& lowerBounds() const;
218
219 //- Get max bounds for the design variables
220 inline const autoPtr<scalarField>& upperBounds() const;
221
222 //- Get min bounds for the design variables
223 inline scalarField& lowerBoundsRef();
224
225 //- Get max bounds for the design variables
226 inline scalarField& upperBoundsRef();
227
228 //- Post process sensitivities if needed
229 virtual void postProcessSens
231 scalarField& objectiveSens,
232 PtrList<scalarField>& constraintSens,
233 const wordList& adjointSolversNames,
234 bool isMaster
235 );
236
237 //- Assemble sensitivity derivatives, by combining the part related
238 //- to the primal and adjoint solution with the part related to the
239 //- design variables
241 (
243 ) = 0;
244
245 //- For design variables with a dynamic character (i.e. changing
246 //- number), perform the evolution
247 virtual void evolveNumber();
248
249 //- Set initial values of the design variables
250 // For design variables sets that need to be initialised after the
251 // construction of the primal fields.
252 // Does nothing in base
253 virtual void setInitialValues();
254
255 //- Add fvOptions depending on the design variables
256 virtual void addFvOptions
257 (
260 );
261
262 //- Design variables might add constraints related to themselves
263 //- (e.g. linear combinations of the design variables)
264 //- Return the values and gradients of these constraints
267
268 //- Write useful quantities to files
269 virtual void writeDesignVars();
270};
271
272
273// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274
275} // End namespace Foam
276
277// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
278
279#include "designVariablesI.H"
280
281// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
282
283#endif
284
285// ************************************************************************* //
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition PtrList.H:67
void size(const label n)
Definition UList.H:118
Abstract base class for adjoint-based sensitivities.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
autoPtr< scalarField > oldDesignVariables_
Copy of old design variables. Useful when performing line-search.
virtual void evolveNumber()
For design variables with a dynamic character (i.e. changing number), perform the evolution.
static autoPtr< designVariables > New(fvMesh &mesh, const dictionary &dict)
Return a reference to the selected design variables.
autoPtr< scalarField > upperBounds_
Upper bounds of the design variables.
autoPtr< scalar > maxInitChange_
Maximum design variables' change in the first optimisation cycle.
const autoPtr< scalarField > & upperBounds() const
Get max bounds for the design variables.
void setMaxInitChange(const scalar maxInitChange)
Set maxInitChange.
TypeName("designVariables")
Runtime type information.
virtual void resetDesignVariables()
Reset to the starting point of line search.
virtual bool globalSum() const =0
Whether to use global sum when computing matrix-vector products in update methods.
virtual PtrList< scalarField > constraintDerivatives()
scalarField & upperBoundsRef()
Get max bounds for the design variables.
bool isMaxInitChangeSet() const
Check whether the max. initial change of the design variables has been set.
virtual void addFvOptions(const PtrList< primalSolver > &primalSolver, const PtrList< adjointSolverManager > &adjointSolverManagers)
Add fvOptions depending on the design variables.
void readBounds(autoPtr< scalar > lowerBoundPtr=nullptr, autoPtr< scalar > upperBoundPtr=nullptr)
Read bounds for design variables, if present.
virtual const scalarField & getVars() const
Get the design variables.
scalarField & lowerBoundsRef()
Get min bounds for the design variables.
virtual tmp< scalarField > constraintValues()
Design variables might add constraints related to themselves (e.g. linear combinations of the design ...
autoPtr< scalarField > lowerBounds_
Lower bounds of the design variables.
virtual bool readDict(const dictionary &dict)
Read dictionary if changed.
declareRunTimeNewSelectionTable(autoPtr, designVariables, designVariables,(fvMesh &mesh, const dictionary &dict),(mesh, dict))
virtual bool resetEta() const
Trigger the recomputation of eta by updateMethod.
virtual void setInitialValues()
Set initial values of the design variables.
const labelList & activeDesignVariables() const
Return list of active design variables.
const autoPtr< scalarField > & lowerBounds() const
Get min bounds for the design variables.
labelList activeDesignVariables_
Which of the design variables will be updated.
virtual void update(scalarField &correction)=0
Update design variables based on a given correction.
virtual tmp< scalarField > assembleSensitivities(adjointSensitivity &sens)=0
Assemble sensitivity derivatives, by combining the part related to the primal and adjoint solution wi...
virtual void storeDesignVariables()
Store design variables, as the starting point for line search.
virtual ~designVariables()=default
Destructor.
virtual void postProcessSens(scalarField &objectiveSens, PtrList< scalarField > &constraintSens, const wordList &adjointSolversNames, bool isMaster)
Post process sensitivities if needed.
const autoPtr< scalar > & getMaxInitChange()
Get maxInitChange.
virtual void writeDesignVars()
Write useful quantities to files.
virtual scalar computeEta(scalarField &correction)=0
Compute eta if not set in the first step.
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
Base class for primal solvers.
A class for managing temporary objects.
Definition tmp.H:75
mesh update()
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
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Return the correction form of the given matrix by subtracting the matrix multiplied by the current fi...
Macros to ease declaration of run-time selection tables.
#define declareRunTimeNewSelectionTable(ptrWrapper, baseType, argNames, argList, parList)
Declare a run-time selection for derived classes.
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68
PtrList< adjointSolverManager > & adjointSolverManagers
Definition createFields.H:8
Forwards and collection of common volume field types.