solution.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2020-2022 OpenCFD Ltd.
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
27Class
28 Foam::solution
29
30Description
31 Selector class for relaxation factors, solver type and solution.
32
33 The solution data are treated as MUST_READ_IF_MODIFIED even if
34 the requested readOption is nominally MUST_READ or READ_IF_PRESENT.
35 This allows run-time modifications to behave as expected.
36
37 The optional fallback dictionary content for constructors is used
38 when a file is missing or for a NO_READ, with a null pointer being
39 treated like an empty dictionary.
40
41SourceFiles
42 solution.C
43
44\*---------------------------------------------------------------------------*/
45
46#ifndef Foam_solution_H
47#define Foam_solution_H
48
49#include "IOdictionary.H"
50#include "HashPtrTable.H"
51
52// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53
54namespace Foam
55{
56
57// Forward Declarations
58template<class Type> class Function1;
59
60/*---------------------------------------------------------------------------*\
61 Class solution Declaration
62\*---------------------------------------------------------------------------*/
64class solution
65:
66 public IOdictionary
67{
68 // Private Data
69
70 //- Dictionary of temporary fields to cache
71 dictionary cache_;
72
73 //- Switch for the caching mechanism
74 bool caching_;
75
76 //- Dictionary of relaxation factors for all the fields
77 dictionary fieldRelaxDict_;
78
79 //- Cache of Function1s in above dictionary
80 mutable HashPtrTable<Function1<scalar>> fieldRelaxCache_;
81
82 //- Dictionary of relaxation factors for all the equations
83 dictionary eqnRelaxDict_;
84
85 //- Cache of Function1s in above dictionary
86 mutable HashPtrTable<Function1<scalar>> eqnRelaxCache_;
87
88 //- Optional default relaxation factor for all the fields
89 autoPtr<Function1<scalar>> fieldRelaxDefault_;
90
91 //- Optional default relaxation factor for all the equations
92 autoPtr<Function1<scalar>> eqnRelaxDefault_;
93
94 //- Dictionary of solver parameters for all the fields
95 dictionary solvers_;
96
97
98 // Private Member Functions
99
100 //- Read settings from the dictionary
101 void read(const dictionary&);
102
103 //- No copy construct
104 solution(const solution&) = delete;
105
106 //- No copy assignment
107 void operator=(const solution&) = delete;
108
109
110public:
111
112 //- Update from older solver controls syntax
113 // Usually verbose, since we want to know about the changes
114 // Returns the number of settings changed
115 static label upgradeSolverDict(dictionary& dict, const bool verbose=true);
116
117 //- Debug switch
118 static int debug;
119
120
121 // Constructors
122
123 //- Construct for objectRegistry, readOption, (system) dictionary name.
125 (
126 const objectRegistry& obr,
127 const IOobject::readOption rOpt,
128 const fileName& dictName,
129 const dictionary* fallback = nullptr
130 );
131
132 //- Construct for objectRegistry, (system) dictionary name
133 //- using the readOption from the registry.
135 (
136 const objectRegistry& obr,
137 const fileName& dictName,
138 const dictionary* fallback = nullptr
139 );
140
141
142 //- Destructor
143 virtual ~solution();
144
145
146 // Member Functions
147
148 // Access
149
150 //- Return true if the given field should be cached
151 bool cache(const word& name) const;
152
153 //- Return true if the relaxation factor is given for the field
154 bool relaxField(const word& name) const;
155
156 //- Return true if the relaxation factor is given for the equation
157 bool relaxEquation(const word& name) const;
158
159 //- Return the relaxation factor for the given field
160 scalar fieldRelaxationFactor(const word& name) const;
161
162 //- Return the relaxation factor for the given equation
163 scalar equationRelaxationFactor(const word& name) const;
164
165 //- Return the selected sub-dictionary of solvers if the "select"
166 //- keyword is given, otherwise return the complete dictionary
167 const dictionary& solutionDict() const;
168
169 //- Return the solver controls dictionary for the given field
170 const dictionary& solverDict(const word& name) const;
171
172 //- Return the solver controls dictionary for the given field
173 const dictionary& solver(const word& name) const;
174
175
176 // Read
177
178 //- Read the solution dictionary
179 bool read();
180
181
182 // Other
183
184 //- Helper for printing cache message
185 template<class FieldType>
186 static void cachePrintMessage
187 (
188 const char* message,
189 const word& name,
190 const FieldType& vf
191 );
192};
193
194
195// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196
197} // End namespace Foam
198
199// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200
201#ifdef NoRepository
202 #include "solutionTemplates.C"
203#endif
204
205// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206
207#endif
208
209// ************************************************************************* //
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers.
Definition: HashPtrTable.H:68
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
readOption
Enumeration defining the read options.
Definition: IOobject.H:177
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
const word & name() const
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
word dictName() const
The local dictionary name (final part of scoped name)
Definition: dictionaryI.H:60
A class for handling file names.
Definition: fileName.H:76
Registry of regIOobjects.
Selector class for relaxation factors, solver type and solution.
Definition: solution.H:66
bool cache(const word &name) const
Return true if the given field should be cached.
Definition: solution.C:270
virtual ~solution()
Destructor.
Definition: solution.C:201
static void cachePrintMessage(const char *message, const word &name, const FieldType &vf)
Helper for printing cache message.
bool relaxField(const word &name) const
Return true if the relaxation factor is given for the field.
Definition: solution.C:282
scalar fieldRelaxationFactor(const word &name) const
Return the relaxation factor for the given field.
Definition: solution.C:299
const dictionary & solverDict(const word &name) const
Return the solver controls dictionary for the given field.
Definition: solution.C:366
static label upgradeSolverDict(dictionary &dict, const bool verbose=true)
Update from older solver controls syntax.
Definition: solution.C:208
scalar equationRelaxationFactor(const word &name) const
Return the relaxation factor for the given equation.
Definition: solution.C:327
static int debug
Debug switch.
Definition: solution.H:117
bool relaxEquation(const word &name) const
Return true if the relaxation factor is given for the equation.
Definition: solution.C:292
const dictionary & solutionDict() const
Definition: solution.C:355
bool read()
Read the solution dictionary.
Definition: solution.C:380
Base class for solution control classes.
Definition: solver.H:54
A class for handling words, derived from Foam::string.
Definition: word.H:68
Namespace for OpenFOAM.
dictionary dict