Loading...
Searching...
No Matches
nullSpace.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) 2023 PCOpt/NTUA
9 Copyright (C) 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::nullSpace
30
31Description
32 Update design variables using a null space approach.
33 Can handle inequality and bound constraints.
34
35 Reference:
36 \verbatim
37 Feppon, F., Allaire, G., & Dapogny, C. (2020).
38 Null space gradient flows for constrained optimization with
39 applications to shape optimization.
40 ESAIM: COCV, 26, 90.
41 https://doi.org/10.1051/cocv/2020015
42 \endverbatim
43
44SourceFiles
45 nullSpace.C
46
47\*---------------------------------------------------------------------------*/
48
49#ifndef nullSpace_H
50#define nullSpace_H
51
53#include "updateMethod.H"
54
55// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56
57namespace Foam
58{
60/*---------------------------------------------------------------------------*\
61 Class nullSpace Declaration
62\*---------------------------------------------------------------------------*/
63
64class nullSpace
65:
66 public constrainedOptimisationMethod,
67 public updateMethod
68{
69protected:
70
71 // Protected data
72
73 //- Are bound constraints included?
75
76 //- Lagrange multipliers for flow-reated constraints
78
79 //- Lagrange multipliers for the lower bound constraints
82 //- Lagrange multipliers for the upper bound constraints
84
85
86 // Dual variables
87
88 //- Solve the dual problem?
90
91 //- Lagrange multipliers of the dual problem for flow-related
92 //- constraints
95 //- Lagrange multipliers of the dual problem for the lower bound
96 //- constraints
98
99 //- Lagrange multipliers of the dual problem for the upper bound
100 //- constraints
102
103
104 // Constraint subsets
105
106 //- List of saturated or violated constraints
107 // List[0]: flow related constraints
108 // List[1]: lower bound constraints
109 // List[2]: upper bound constraints
110 // Sub-list meaning is the same for all labelListLists that follow
113 //- List of saturated or violated constraints (up to epsConstr_)
115
116 //- List of constraints that must remain active
117 // Determines the null space update
119
120 //- List of constraints the values of which need to be reduced
121 // Determines the range space update
123
124
125 // Fields holding the updates of the Lagrange multipliers of the primal
126 // and dual problems
127
134
135
136 //- Infinitesimal quantity
137 // Updated during the inner iterations of the dual problem
138 scalar eps_;
139
140 //- Maxmimum number of Newton iterations for the dual problem
141 label maxNewtonIters_;
142
143 //- Maxmimum number of line search iterations for each Newton iteration
144 //- of the dual problem
146
147 //- Maxmimum number of CG iterations for obtaining the null space and
148 //- range space updates
149 label maxCGIters_;
151 //- Tolerance of the dual problem
155 // Constant parameters
156
157 //- Value for considering a constraint as marginally active
158 // Used to avoid the frequent change of the active set of
159 // constraints
160 scalar epsConstr_;
161
162 //- Value to perturb the design variables by, if all of them
163 //- lay on their bounds at the beginning of the optimisation
164 scalar epsPerturb_;
165
166 //- Multiplier of the null space update
167 scalar aJ_;
169 //- Multiplier of the range space update
170 scalar aC_;
171
172 //- Change aJ and aC adaptively
173 bool adaptiveStep_;
175 //- Last cycle on which to reset aJ
177
178 //- Max change of the design variables, pertaining to the objective
179 //- reduction.
180 // If adaptiveStep is set to true, aJ will be set in such a way
181 // to obtain a maxDVChange_ for the design variables, for all
182 // optimisation cycles up to lastAcceleratedCycle_
184
185 //- Whether to impose maxDVChange strictly on all optimisation
186 //- cycles or just up to the lastAcceleratedCycle
188
189 //- Target reduction of active constraints (range in [0-1])
190 // 1: active constraints will become zero (first-order approx)
191 // 0: no change in the constraints
193
194 //- Downplay the importance of the bound constraint reduction
195 //- by this ammount
196 scalar bcMult_;
197
198
199 // Protected Member Functions
200
201 //- Update sizes of fields related to the constraints
203
204 //- Zero the updates computed in the previous optimisation cycle
205 void zeroUpdates();
206
208 // Functions related to the solution of the dual subproblem
209
210 //- Solve the dual problem for computing the Lagrange multiplier
211 //- using a Newton solver
213
214 //- Compute and return residuals based on the current solution
216
217 //- Compute direction for the Newton problem
219
220 //- Perform line search and return max residual corresponding to
221 //- the updated solution
222 scalar lineSearch();
223
224 //- Update the current solution using the known direction and the
225 //- given step length
226 void updateSolution(const scalar step);
227
228 //- Adjust step to satisfy cireteria
229 void adjustStep
230 (
231 scalar& step,
232 const scalar value,
233 const scalar update
234 );
235
236
237 // Functions related to the computation of the design variables update
239 //- Update the constraint subsets
241
242 //- Update the constraint subsets
244
245 //- Update violated constraints indices (iTilda and iTildaEps)
247 (
248 const label i,
249 const scalarField& constraints
250 );
251
252 //- Update constraint indices related to the null and range space
253 //- part of the correction
255 (
256 const label i,
257 const scalarField& LagrangeMults,
258 const scalarField& dual
259 );
260
261 //- Compute the update of the design variables as a combination of
262 //- null space and range space parts
263 void correction();
264
265 //- A & v
266 // where A is the Jacobian of all constraints, identified by
267 // the labelList addressings, w.r.t. the active design variables
269 (
270 const scalarField& v,
271 const labelListList& subsets
272 );
273
274 //- A.T & v
275 // where A is the Jacobian of all constraints, identified by
276 // the labelList addressings, w.r.t. the active design variables
278 (
279 const scalarField& v,
280 const labelListList& subsets
281 );
282
283 //- Collect all constraint values corresponding to the provided
284 //- indices
286 (
287 const labelListList& subsets
288 );
289
290 //- Computes the parts of ksiJ and ksiC that require a system
291 //- solution
292 // Formulated in terms of the flow constraints, which are usually
293 // few
295 (
296 const scalarField& rhs,
297 const labelListList& subsets
298 );
299
300 //- Print statistics on the number of flow- and bound-related
301 //- constraints included in the subset
302 void statistics
303 (
304 const labelListList& subset,
305 const word& description
306 );
307
308
309private:
310
311 // Private Member Functions
312
313 //- No copy construct
314 nullSpace(const nullSpace&) = delete;
315
316 //- No copy assignment
317 void operator=(const nullSpace&) = delete;
318
319
320public:
321
322 //- Runtime type information
323 TypeName("nullSpace");
324
325
326 // Constructors
327
328 //- Construct from components
329 nullSpace
330 (
331 const fvMesh& mesh,
332 const dictionary& dict,
333 autoPtr<designVariables>& designVars,
334 const label nConstraints,
335 const word& type
336 );
337
338
339 //- Destructor
340 virtual ~nullSpace() = default;
341
342
343 // Member Functions
344
345 //- Compute design variables correction
346 virtual void computeCorrection();
347
348 //- Compute the merit function for line search
349 virtual scalar computeMeritFunction();
350
351 //- Directional derivative of the merit function, in the direction of
352 //- the correction
353 virtual scalar meritFunctionDirectionalDerivative();
354
355 //- Write useful quantities to files
356 virtual bool writeData(Ostream& os) const;
357};
358
359
360// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
361
362} // End namespace Foam
363
364// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
365
366#endif
367
368// ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
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
scalar lineSearch()
Perform line search and return max residual corresponding to the updated solution.
Definition nullSpace.C:321
scalar targetConstraintReduction_
Target reduction of active constraints (range in [0-1]).
Definition nullSpace.H:246
void updateCorrectionIndices(const label i, const scalarField &LagrangeMults, const scalarField &dual)
Update constraint indices related to the null and range space part of the correction.
Definition nullSpace.C:504
void updateSolution(const scalar step)
Update the current solution using the known direction and the given step length.
Definition nullSpace.C:419
virtual void computeCorrection()
Compute design variables correction.
Definition nullSpace.C:1065
virtual scalar meritFunctionDirectionalDerivative()
Directional derivative of the merit function, in the direction of the correction.
Definition nullSpace.C:1134
void initialise()
Update sizes of fields related to the constraints.
Definition nullSpace.C:47
autoPtr< scalar > maxDVChange_
Max change of the design variables, pertaining to the objective reduction.
Definition nullSpace.H:232
bool adaptiveStep_
Change aJ and aC adaptively.
Definition nullSpace.H:217
scalar dualTolerance_
Tolerance of the dual problem.
Definition nullSpace.H:185
void updateNullAndRangeSpaceSubsets()
Update the constraint subsets.
Definition nullSpace.C:452
scalarField mu_
Lagrange multipliers for flow-reated constraints.
Definition nullSpace.H:76
void correction()
Compute the update of the design variables as a combination of null space and range space parts.
Definition nullSpace.C:544
tmp< scalarField > activeConstraints(const labelListList &subsets)
Collect all constraint values corresponding to the provided indices.
Definition nullSpace.C:732
void adjustStep(scalar &step, const scalar value, const scalar update)
Adjust step to satisfy cireteria.
Definition nullSpace.C:406
scalarField dualL_
Lagrange multipliers of the dual problem for the lower bound constraints.
Definition nullSpace.H:106
scalar bcMult_
Downplay the importance of the bound constraint reduction by this ammount.
Definition nullSpace.H:252
virtual bool writeData(Ostream &os) const
Write useful quantities to files.
Definition nullSpace.C:1157
scalar epsConstr_
Value for considering a constraint as marginally active.
Definition nullSpace.H:196
tmp< scalarField > ATv(const scalarField &v, const labelListList &subsets)
A.T & v.
Definition nullSpace.C:688
bool strictMaxDVChange_
Whether to impose maxDVChange strictly on all optimisation cycles or just up to the lastAcceleratedCy...
Definition nullSpace.H:238
labelListList iHat_
List of constraints that must remain active.
Definition nullSpace.H:137
void computeNewtonDirection()
Compute direction for the Newton problem.
Definition nullSpace.C:209
scalarField dualU_
Lagrange multipliers of the dual problem for the upper bound constraints.
Definition nullSpace.H:112
label lastAcceleratedCycle_
Last cycle on which to reset aJ.
Definition nullSpace.H:222
scalarField deltaMu_
Definition nullSpace.H:150
void solveDualProblem()
Solve the dual problem for computing the Lagrange multiplier using a Newton solver.
Definition nullSpace.C:83
label maxCGIters_
Maxmimum number of CG iterations for obtaining the null space and range space updates.
Definition nullSpace.H:180
labelListList iRangeSpace_
List of constraints the values of which need to be reduced.
Definition nullSpace.H:144
scalar aC_
Multiplier of the range space update.
Definition nullSpace.H:212
void statistics(const labelListList &subset, const word &description)
Print statistics on the number of flow- and bound-related constraints included in the subset.
Definition nullSpace.C:894
void zeroUpdates()
Zero the updates computed in the previous optimisation cycle.
Definition nullSpace.C:72
virtual scalar computeMeritFunction()
Compute the merit function for line search.
Definition nullSpace.C:1085
scalar eps_
Infinitesimal quantity.
Definition nullSpace.H:163
labelListList iTildaEps_
List of saturated or violated constraints (up to epsConstr_).
Definition nullSpace.H:130
scalarField dualMu_
Lagrange multipliers of the dual problem for flow-related constraints.
Definition nullSpace.H:100
tmp< scalarField > constraintRelatedUpdate(const scalarField &rhs, const labelListList &subsets)
Computes the parts of ksiJ and ksiC that require a system solution.
Definition nullSpace.C:770
label maxLineSearchIters_
Maxmimum number of line search iterations for each Newton iteration of the dual problem.
Definition nullSpace.H:174
void updateViolatedIndices(const label i, const scalarField &constraints)
Update violated constraints indices (iTilda and iTildaEps).
Definition nullSpace.C:472
scalarField l_
Lagrange multipliers for the lower bound constraints.
Definition nullSpace.H:81
scalarField deltaU_
Definition nullSpace.H:152
bool includeBoundConstraints_
Are bound constraints included?
Definition nullSpace.H:71
void updateViolatedConstraintsSubsets()
Update the constraint subsets.
Definition nullSpace.C:432
TypeName("nullSpace")
Runtime type information.
labelListList iTilda_
List of saturated or violated constraints.
Definition nullSpace.H:125
scalarField deltaDualU_
Definition nullSpace.H:155
scalarField deltaDualMu_
Definition nullSpace.H:153
scalar epsPerturb_
Value to perturb the design variables by, if all of them lay on their bounds at the beginning of the ...
Definition nullSpace.H:202
scalar aJ_
Multiplier of the null space update.
Definition nullSpace.H:207
scalarField u_
Lagrange multipliers for the upper bound constraints.
Definition nullSpace.H:86
virtual ~nullSpace()=default
Destructor.
tmp< scalarField > computeResiduals()
Compute and return residuals based on the current solution.
Definition nullSpace.C:132
scalarField deltaDualL_
Definition nullSpace.H:154
bool solveDualProblem_
Solve the dual problem?
Definition nullSpace.H:94
scalarField deltaL_
Definition nullSpace.H:151
label maxNewtonIters_
Maxmimum number of Newton iterations for the dual problem.
Definition nullSpace.H:168
tmp< scalarField > Av(const scalarField &v, const labelListList &subsets)
A & v.
Definition nullSpace.C:644
A class for managing temporary objects.
Definition tmp.H:75
label nConstraints() const
Get the number of constraints.
A class for handling words, derived from Foam::string.
Definition word.H:66
mesh update()
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
List< labelList > labelListList
List of labelList.
Definition labelList.H:38
List< T > subset(const BoolListType &select, const UList< T > &input, const bool invert=false)
Extract elements of the input list when select is true.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68