objectiveManager.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-2019 PCOpt/NTUA
9  Copyright (C) 2013-2019 FOSS GP
10  Copyright (C) 2019 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 Class
29  Foam::objectiveManager
30 
31 Description
32  class for managing incompressible objective functions.
33 
34 SourceFiles
35  objectiveManager.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef objectiveManager_H
40 #define objectiveManager_H
41 
42 #include "fvMesh.H"
43 #include "objective.H"
44 #include "runTimeSelectionTables.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class objectiveManager Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 class objectiveManager
56 :
57  public regIOobject
58 {
59 protected:
60 
61  // Protected data
62 
63  const fvMesh& mesh_;
64  const dictionary& dict_;
68 
69 
70 private:
71 
72  // Private Member Functions
73 
74  //- No copy construct
75  objectiveManager(const objectiveManager&) = delete;
76 
77  //- No copy assignment
78  void operator=(const objectiveManager&) = delete;
79 
80 
81 public:
82 
83  TypeName("objectiveManager");
84 
85  // Declare run-time constructor selection table
86 
88  (
89  autoPtr,
91  dictionary,
92  (
93  const fvMesh& mesh,
94  const dictionary& dict,
95  const word& adjointSolverName,
96  const word& primalSolverName
97  ),
99  );
100 
101  // Constructors
102 
103  //- Construct from components
105  (
106  const fvMesh& mesh,
107  const dictionary& dict,
108  const word& adjointSolverName,
109  const word& primalSolverName
110  );
111 
112  // Selectors
113 
114  //- Return a reference to the selected turbulence model
116  (
117  const fvMesh& mesh,
118  const dictionary& dict,
119  const word& adjointSolverName,
120  const word& primalSolverName
121  );
122 
123 
124  //- Destructor
125  virtual ~objectiveManager() = default;
126 
127 
128  // Member Functions
129 
130  virtual bool readDict(const dictionary& dict);
131 
132  //- Update objective function related values
134 
135  //- Update objective function related values
136  void update();
137 
138  //- Update contributions to adjoint if true, otherwise return nulls
139  void updateOrNullify();
140 
141  //- Increment integration times by the optimisation cycle time-span
142  void incrementIntegrationTimes(const scalar timeSpan);
143 
144  //- Print to screen
145  scalar print();
146 
147  //- Write objective function history
148  virtual bool write(const bool valid = true) const;
149 
150  //- Call all functions required prior to the solution of the adjoint
151  //- equations
152  void updateAndWrite();
153 
154  //- Return reference to objective functions
156 
157  //- Return constant reference to objective functions
159 
160  //- Return name of adjointSolverManager
161  const word& adjointSolverManagerName() const;
162 
163  //- Return name of the adjointSolver
164  const word& adjointSolverName() const;
165 
166  //- Return name of the primalSolver
167  const word& primalSolverName() const;
168 
169  //- Check integration times for unsteady runs
170  void checkIntegrationTimes() const;
171 
172  //- Add contribution to adjoint momentum PDEs
173  virtual void addUaEqnSource(fvVectorMatrix& UaEqn) = 0;
174 
175  //- Add contribution to adjoint momentum PDEs
176  virtual void addPaEqnSource(fvScalarMatrix& paEqn) = 0;
177 
178  //- Add contribution to first adjoint turbulence model PDE
179  virtual void addTMEqn1Source(fvScalarMatrix& adjTMEqn1) = 0;
180 
181  //- Add contribution to second adjoint turbulence model PDE
182  virtual void addTMEqn2Source(fvScalarMatrix& adjTMEqn2) = 0;
183 
184 
185  // IO
186 
187  virtual bool writeData(Ostream&) const
188  {
189  return true;
190  }
191 };
192 
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 } // End namespace Foam
197 
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 
200 #endif
201 
202 // ************************************************************************* //
Foam::objectiveManager::updateNormalizationFactor
void updateNormalizationFactor()
Update objective function related values.
Definition: objectiveManager.C:155
Foam::objectiveManager
class for managing incompressible objective functions.
Definition: objectiveManager.H:54
Foam::objectiveManager::addPaEqnSource
virtual void addPaEqnSource(fvScalarMatrix &paEqn)=0
Add contribution to adjoint momentum PDEs.
Foam::objectiveManager::primalSolverName
const word & primalSolverName() const
Return name of the primalSolver.
Definition: objectiveManager.C:265
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::objectiveManager::print
scalar print()
Print to screen.
Definition: objectiveManager.C:206
Foam::objectiveManager::objectives_
PtrList< objective > objectives_
Definition: objectiveManager.H:66
Foam::objectiveManager::readDict
virtual bool readDict(const dictionary &dict)
Definition: objectiveManager.C:141
Foam::objectiveManager::update
void update()
Update objective function related values.
Definition: objectiveManager.C:168
Foam::objectiveManager::~objectiveManager
virtual ~objectiveManager()=default
Destructor.
Foam::objectiveManager::write
virtual bool write(const bool valid=true) const
Write objective function history.
Definition: objectiveManager.C:225
Foam::objectiveManager::addUaEqnSource
virtual void addUaEqnSource(fvVectorMatrix &UaEqn)=0
Add contribution to adjoint momentum PDEs.
Foam::objectiveManager::TypeName
TypeName("objectiveManager")
Foam::objectiveManager::incrementIntegrationTimes
void incrementIntegrationTimes(const scalar timeSpan)
Increment integration times by the optimisation cycle time-span.
Definition: objectiveManager.C:195
Foam::objectiveManager::adjointSolverManagerName
const word & adjointSolverManagerName() const
Return name of adjointSolverManager.
Foam::objectiveManager::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, objectiveManager, dictionary,(const fvMesh &mesh, const dictionary &dict, const word &adjointSolverName, const word &primalSolverName),(mesh, dict, adjointSolverName, primalSolverName))
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:62
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::objectiveManager::primalSolverName_
const word primalSolverName_
Definition: objectiveManager.H:65
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::objectiveManager::adjointSolverName_
const word adjointSolverName_
Definition: objectiveManager.H:64
Foam::objectiveManager::checkIntegrationTimes
void checkIntegrationTimes() const
Check integration times for unsteady runs.
Definition: objectiveManager.C:271
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:68
Foam::objectiveManager::New
static autoPtr< objectiveManager > New(const fvMesh &mesh, const dictionary &dict, const word &adjointSolverName, const word &primalSolverName)
Return a reference to the selected turbulence model.
Definition: objectiveManager.C:108
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::objectiveManager::writeData
virtual bool writeData(Ostream &) const
Pure virtual writeData function.
Definition: objectiveManager.H:186
Foam::objectiveManager::updateAndWrite
void updateAndWrite()
Definition: objectiveManager.C:238
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:76
Foam::objectiveManager::addTMEqn2Source
virtual void addTMEqn2Source(fvScalarMatrix &adjTMEqn2)=0
Add contribution to second adjoint turbulence model PDE.
Foam::objectiveManager::mesh_
const fvMesh & mesh_
Definition: objectiveManager.H:62
Foam::objectiveManager::addTMEqn1Source
virtual void addTMEqn1Source(fvScalarMatrix &adjTMEqn1)=0
Add contribution to first adjoint turbulence model PDE.
Foam::objectiveManager::updateOrNullify
void updateOrNullify()
Update contributions to adjoint if true, otherwise return nulls.
Definition: objectiveManager.C:178
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::objectiveManager::adjointSolverName
const word & adjointSolverName() const
Return name of the adjointSolver.
Definition: objectiveManager.C:259
Foam::objectiveManager::dict_
const dictionary & dict_
Definition: objectiveManager.H:63
objective.H
Foam::objectiveManager::getObjectiveFunctions
PtrList< objective > & getObjectiveFunctions()
Return reference to objective functions.
Definition: objectiveManager.C:247