solverControl.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 
29 Class
30  Foam::solverControl
31 
32 Description
33  Base class for solver control classes
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef solverControl_H
38 #define solverControl_H
39 
40 #include "fvMesh.H"
41 #include "solver.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class solverControl Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 class solverControl
53 {
54 protected:
55 
56  // Protected data
57 
58  //- Reference to the underlaying solver
59  const solver& solver_;
60 
61  // Solution controls
62 
63  //- Whether to print the max magnitude during each solver iteration
64  // Useful for adjoint solvers
65  bool printMaxMags_;
66 
67 
68  // Evolution
69 
70  //- Current iteration index
71  label iter_;
72 
73  //- Current averaging iteration index
74  label averageIter_;
75 
76  //- Averaging start index
77  label averageStartIter_;
78 
79  // Non run-time modifiable entries
80 
81  //- Whether to re-initialize the solution based on the initial
82  //- time step. Makes sense only for optimisation or FD runs
83  bool storeInitValues_;
84 
85  //- Do averaging
86  bool average_;
87 
88 
89  // Protected Member Functions
90 
91  //- Read controls from optimisationDict
92  virtual bool read();
93 
94 
95 private:
96 
97  //- No copy construct
98  solverControl(const solverControl&) = delete;
99 
100  //- No copy assignment
101  void operator=(const solverControl&) = delete;
102 
103 
104 public:
105 
106 
107  // Static Data Members
108 
109  //- Run-time type information
110  TypeName("solverControl");
111 
112 
113  // Constructors
114 
115  //- Construct from solver
116  solverControl(const solver& solver);
117 
118 
119  //- Destructor
120  virtual ~solverControl() = default;
121 
122 
123  // Member Functions
124 
125  //- Read controls from optimisationDict
126 
127  //- Return the solver dictionary
128  inline virtual const dictionary solverDict() const;
129 
130  //- Return the solutionControls dictionary
131  inline virtual const dictionary solutionDict() const;
132 
133  //- Print max mags of solver fields
134  inline bool printMaxMags() const;
135 
136 
137  // Solution control
138 
139  //- Re-initialize
140  inline bool storeInitValues() const;
141 
142  //- Return iteration index
143  inline label iter() const;
144 
145  //- Return average iteration index reference
146  inline label& averageIter();
147 
148  //- Return const average iteration index reference
149  inline label averageIter() const;
150 
151  //- Return iteration index
152  inline label averageStartIter() const;
153 
154  //- Whether or not to add fields of the current iteration to the
155  //- average fields
156  inline bool doAverageIter() const;
157 
158  //- Use averaged fields?
159  //- For solving the adjoint equations or computing sensitivities
160  //- based on averaged fields
161  inline bool useAveragedFields() const;
162 
163  //- Whether averaging is enabled or not
164  inline bool average() const;
165 };
166 
167 
168 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169 
170 } // End namespace Foam
171 
172 #include "solverControlI.H"
173 
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
175 
176 #endif
177 
178 // ************************************************************************* //
Foam::solverControl::doAverageIter
bool doAverageIter() const
Definition: solverControlI.H:81
Foam::solverControl::~solverControl
virtual ~solverControl()=default
Destructor.
Foam::solverControl::averageStartIter_
label averageStartIter_
Averaging start index.
Definition: solverControl.H:76
Foam::solverControl::read
virtual bool read()
Read controls from optimisationDict.
Definition: solverControl.C:41
solver.H
Foam::solverControl::TypeName
TypeName("solverControl")
Run-time type information.
Foam::solverControl::iter
label iter() const
Return iteration index.
Definition: solverControlI.H:57
Foam::solverControl::average_
bool average_
Do averaging.
Definition: solverControl.H:85
Foam::solverControl
Base class for solver control classes.
Definition: solverControl.H:51
Foam::solverControl::storeInitValues
bool storeInitValues() const
Re-initialize.
Definition: solverControlI.H:51
Foam::solverControl::averageStartIter
label averageStartIter() const
Return iteration index.
Definition: solverControlI.H:75
solverControlI.H
Foam::solverControl::storeInitValues_
bool storeInitValues_
Definition: solverControl.H:82
Foam::solverControl::printMaxMags
bool printMaxMags() const
Print max mags of solver fields.
Definition: solverControlI.H:45
Foam::solver
Base class for solution control classes.
Definition: solver.H:51
Foam::solverControl::iter_
label iter_
Current iteration index.
Definition: solverControl.H:70
Foam::solverControl::useAveragedFields
bool useAveragedFields() const
Definition: solverControlI.H:94
Foam::solverControl::printMaxMags_
bool printMaxMags_
Whether to print the max magnitude during each solver iteration.
Definition: solverControl.H:64
Foam::solverControl::averageIter
label & averageIter()
Return average iteration index reference.
Definition: solverControlI.H:63
Foam::solverControl::solver_
const solver & solver_
Reference to the underlaying solver.
Definition: solverControl.H:58
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::solverControl::solutionDict
virtual const dictionary solutionDict() const
Return the solutionControls dictionary.
Definition: solverControlI.H:39
Foam::solverControl::solverDict
virtual const dictionary solverDict() const
Read controls from optimisationDict.
Definition: solverControlI.H:33
Foam::solverControl::averageIter_
label averageIter_
Current averaging iteration index.
Definition: solverControl.H:73
Foam::solverControl::average
bool average() const
Whether averaging is enabled or not.
Definition: solverControlI.H:107