Loading...
Searching...
No Matches
solver.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 Copyright (C) 2019 OpenCFD Ltd.
11-------------------------------------------------------------------------------
12License
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
28Class
29 Foam::solver
30
31Description
32 Base solver class
33
34\*---------------------------------------------------------------------------*/
35
36#ifndef solver_H
37#define solver_H
38
39#include "fvMesh.H"
40#include "fvMatrix.H"
41#include "localIOdictionary.H"
42#include "variablesSet.H"
43
44// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46namespace Foam
47{
48/*---------------------------------------------------------------------------*\
49 Class solver Declaration
50\*---------------------------------------------------------------------------*/
51
52class solver
53:
55{
56protected:
57
58 // Protected Data
59
60 //- Reference to the mesh database
62
63 //- The optimisation type
64 const word managerType_;
65
66 //- Dictionary holding the solver info
68
69 //- Solver name
70 const word solverName_;
72 //- Solve equations?
73 bool active_;
74
75 //- Is the solver the master one
76 // Used in cases where a solver needs to work in tandem with another
77 bool isMaster_;
78
79 //- Append the variables related to the solver with it name
81
82 //- Base variableSet pointer.
83 // To be allocated in derived classes
85
86
87 // Protected Member Functions
89 //- No copy construct
90 solver(const solver&) = delete;
91
92 //- No copy assignment
93 void operator=(const solver&) = delete;
94
96public:
97
98
99 // Static Data Members
100
101 //- Run-time type information
102 TypeName("solver");
104
105 // Constructors
106
107 //- Construct from mesh and dictionary
109 (
110 fvMesh& mesh,
111 const word& managerType,
112 const dictionary& dict,
113 const word& solverName
114 );
115
116
117 //- Destructor
118 virtual ~solver() = default;
120
121 // Member Functions
122
123 virtual bool readDict(const dictionary& dict);
124
125
126 // Access
127
128 //- Return the solver mesh
129 inline const fvMesh& mesh() const;
130
131 //- Return the solver name
132 inline const word& solverName() const;
133
134 //- Use solver name as a suffix to the involved fields
135 inline bool useSolverNameForFields() const;
136
137 //- Given a variable name, return a name that is possibly appended
138 //- by the solverName, depending on useSolverNameForFields
139 inline word extendedVariableName(const word& varName) const;
140
141 //- Return state of solver
142 inline bool active();
143
144 //- Return the solver dictionary
145 inline const dictionary& dict() const;
146
147 //- Return constant reference to variableSet used by the solver
148 inline const variablesSet& getVariablesSet() const;
149
150 //- Return non-constant reference to variableSet used by the solver
152
153 //- Return the manager type
154 inline const word& managerType() const;
155
156 //- Whether the solver is the master one, in case of coupled
157 //- solvers
158 inline bool isMaster() const;
159
160
161 // Evolution
162
163 //- Execute one iteration of the solution algorithm
164 virtual void solveIter() = 0;
165
166 //- Main control loop
167 virtual void solve() = 0;
168
169 //- Looper (advances iters, time step)
170 virtual bool loop() = 0;
171
172 //- Restore initial field values if necessary
173 virtual void restoreInitValues();
174
175 //- Functions to be called before loop
176 virtual void preLoop();
177
178 //- Functions to be called after loop
179 virtual void postLoop();
180
181 //- Main control loop.
182 // Gets a list of function pointers to be called at the end of
183 // each solver iteration
184 template<class Type>
185 void solveWithArgs
186 (
187 Type& type,
188 List<void (Type::*)()>& funcs
189 );
190
191 //- Add topO fvOptions
192 // Does nothing in base
193 virtual void addTopOFvOptions() const;
194
195
196 // IO
197
198 //- Required by regIOobject
199 virtual bool writeData(Ostream&) const
200 {
201 return true;
202 }
203
204 //- Workaround for turbulent fields on multi-point runs
205 virtual bool write(const bool valid = true) const
206 {
207 return false;
208 }
209
210 //- Workaround for turbulent fields on multi-point runs
211 virtual bool writeNow() const
213 return false;
214 }
215};
216
218// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219
220} // End namespace Foam
221
222// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223
224#ifdef NoRepository
225# include "solverTemplates.C"
226#endif
227#include "solverI.H"
228
229// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230
231#endif
232
233// ************************************************************************* //
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
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
localIOdictionary(const IOobject &io, const dictionary *fallback=nullptr)
Construct given an IOobject and optional fallback dictionary content.
autoPtr< variablesSet > vars_
Base variableSet pointer.
Definition solver.H:95
const word & managerType() const
Return the manager type.
Definition solverI.H:72
bool active()
Return state of solver.
Definition solverI.H:48
void solveWithArgs(Type &type, List< void(Type::*)()> &funcs)
Main control loop.
bool active_
Solve equations?
Definition solver.H:76
bool useSolverNameForFields_
Append the variables related to the solver with it name.
Definition solver.H:88
bool isMaster_
Is the solver the master one.
Definition solver.H:83
const word managerType_
The optimisation type.
Definition solver.H:61
virtual void restoreInitValues()
Restore initial field values if necessary.
Definition solver.C:84
virtual void solveIter()=0
Execute one iteration of the solution algorithm.
dictionary dict_
Dictionary holding the solver info.
Definition solver.H:66
bool isMaster() const
Whether the solver is the master one, in case of coupled solvers.
Definition solverI.H:78
virtual bool write(const bool valid=true) const
Workaround for turbulent fields on multi-point runs.
Definition solver.H:268
virtual bool readDict(const dictionary &dict)
Definition solver.C:70
word extendedVariableName(const word &varName) const
Given a variable name, return a name that is possibly appended by the solverName, depending on useSol...
Definition solverI.H:42
bool useSolverNameForFields() const
Use solver name as a suffix to the involved fields.
Definition solverI.H:36
virtual void addTopOFvOptions() const
Add topO fvOptions.
Definition solver.C:102
const variablesSet & getVariablesSet() const
Return constant reference to variableSet used by the solver.
Definition solverI.H:60
virtual ~solver()=default
Destructor.
virtual void solve()=0
Main control loop.
void operator=(const solver &)=delete
No copy assignment.
virtual bool writeData(Ostream &) const
Required by regIOobject.
Definition solver.H:260
virtual bool writeNow() const
Workaround for turbulent fields on multi-point runs.
Definition solver.H:276
const dictionary & dict() const
Return the solver dictionary.
Definition solverI.H:54
virtual void preLoop()
Functions to be called before loop.
Definition solver.C:90
TypeName("solver")
Run-time type information.
const word solverName_
Solver name.
Definition solver.H:71
const fvMesh & mesh() const
Return the solver mesh.
Definition solverI.H:24
const word & solverName() const
Return the solver name.
Definition solverI.H:30
fvMesh & mesh_
Reference to the mesh database.
Definition solver.H:56
virtual void postLoop()
Functions to be called after loop.
Definition solver.C:96
solver(const solver &)=delete
No copy construct.
virtual bool loop()=0
Looper (advances iters, time step).
Base class for creating a set of variables.
A class for handling words, derived from Foam::string.
Definition word.H:66
Namespace for OpenFOAM.
runTime write()
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68