steadyOptimisation.C
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-2020 OpenCFD Ltd.
11 -------------------------------------------------------------------------------
12 License
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 \*---------------------------------------------------------------------------*/
29 
30 #include "steadyOptimisation.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(steadyOptimisation, 0);
39  (
40  optimisationManager,
41  steadyOptimisation,
43  );
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
49 Foam::steadyOptimisation::steadyOptimisation(fvMesh& mesh)
50 :
52 {
53  initialize();
54  // Force the construction of the design variables, if they are not
55  // already present
56  if (!designVars_)
57  {
58  designVars_.reset
59  (
61  (
62  mesh_,
63  subDict("optimisation").subDict("designVariables")
64  ).ptr()
65  );
66  }
67  designVars_().setInitialValues();
68  dvUpdate_.reset
69  (
70  new designVariablesUpdate
71  (
72  mesh,
73  subDict("optimisation"),
76  )
77  );
78 }
79 
80 
81 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
82 
84 {
85  time_++;
86  if (!end())
87  {
88  Info<< "\n* * * * * * * * * * * * * * * * *" << endl;
89  Info<< "Optimisation cycle " << time_.value() << endl;
90  Info<< "* * * * * * * * * * * * * * * * *\n" << endl;
91  }
92  return *this;
93 }
94 
95 
97 {
98  return operator++();
99 }
100 
101 
103 {
104  if (update())
105  {
106  dvUpdate_->update();
107  }
108  return end();
109 }
110 
113 {
114  return time_.end();
115 }
116 
117 
119 {
120  return (time_.timeIndex() != 1 && !end());
121 }
122 
123 
124 // ************************************************************************* //
virtual bool update()
Whether to update the design variables.
PtrList< adjointSolverManager > adjointSolverManagers_
List of adjoint solver managers to be included in the optimisation.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual bool checkEndOfLoopAndUpdate()
Return true if end of optimisation run.
fvMesh & mesh_
Reference to the mesh.
Abstract base class for optimisation methods.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
autoPtr< designVariablesUpdate > dvUpdate_
Helper class managing parts of the optimisation.
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:441
virtual void initialize()
Initialization. Construct primal and adjoint solvers.
Macros for easy insertion into run-time selection tables.
dynamicFvMesh & mesh
virtual optimisationManager & operator++()
Prefix increment.
virtual bool end()
Return true if end of optimisation run.
autoPtr< designVariables > designVars_
Design variables of the optimisation problem.
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:201
mesh update()
defineTypeNameAndDebug(combustionModel, 0)
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
static autoPtr< designVariables > New(fvMesh &mesh, const dictionary &dict)
Return a reference to the selected design variables.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)