Loading...
Searching...
No Matches
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-2023 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 file will contain these types of entries:
34
35 \par solvers { }
36 A sub-dictionary listing of linear solver settings. For example,
37 \verbatim
38 solvers
39 {
40 p
41 {
42 solver PCG;
43 preconditioner DIC;
44 tolerance 1e-06;
45 relTol 0.05;
46 }
47 }
48 \endverbatim
49
50 \par select
51 This is a rarely used feature to select between different groups of
52 settings within the file. If unspecified, the file contents are used
53 directly.
54
55 There are currently no other specified entries, but the file will
56 often also contain other solution specifications. For example,
57 \verbatim
58 PIMPLE
59 {
60 nOuterCorrectors 2;
61 nCorrectors 1;
62 nNonOrthogonalCorrectors 0;
63 }
64 \endverbatim
65
66Note
67 The solution data are treated as \c READ_MODIFIED even if the
68 requested \p readOption is nominally MUST_READ or READ_IF_PRESENT.
69 This allows run-time modifications to behave as expected. <br>
70 The optional fallback dictionary content for constructors is used
71 when a file is missing or for a NO_READ, with a null pointer being
72 treated like an empty dictionary.
73
74SourceFiles
75 solution.C
76
77\*---------------------------------------------------------------------------*/
78
79#ifndef Foam_solution_H
80#define Foam_solution_H
81
82#include "IOdictionary.H"
83#include "HashPtrTable.H"
84
85// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
86
87namespace Foam
88{
89
90// Forward Declarations
91template<class Type> class Function1;
93/*---------------------------------------------------------------------------*\
94 Class solution Declaration
95\*---------------------------------------------------------------------------*/
96
97class solution
98:
99 public IOdictionary
100{
101 // Private Data
102
103 //- Dictionary of temporary fields to cache
104 dictionary cache_;
105
106 //- Switch for the caching mechanism
107 bool caching_;
108
109 //- Dictionary of relaxation factors for all the fields
110 dictionary fieldRelaxDict_;
111
112 //- Cache of Function1s in above dictionary
113 mutable HashPtrTable<Function1<scalar>> fieldRelaxCache_;
114
115 //- Dictionary of relaxation factors for all the equations
116 dictionary eqnRelaxDict_;
117
118 //- Cache of Function1s in above dictionary
119 mutable HashPtrTable<Function1<scalar>> eqnRelaxCache_;
120
121 //- Optional default relaxation factor for all the fields
122 autoPtr<Function1<scalar>> fieldRelaxDefault_;
123
124 //- Optional default relaxation factor for all the equations
125 autoPtr<Function1<scalar>> eqnRelaxDefault_;
126
127 //- Dictionary of solver parameters for all the fields
128 dictionary solvers_;
129
130
131 // Private Member Functions
132
133 //- Read settings from the dictionary
134 void read(const dictionary&);
135
136 //- The entire dictionary or the optional "select" sub-dictionary.
137 const dictionary& selectedDict() const;
138
139
140 // Generated Methods
141
142 //- No copy construct
143 solution(const solution&) = delete;
144
145 //- No copy assignment
146 void operator=(const solution&) = delete;
147
148
149public:
150
151 //- Update from older solver controls syntax
152 // Usually verbose, since we want to know about the changes
153 // Returns the number of settings changed
154 static label upgradeSolverDict(dictionary& dict, const bool verbose=true);
155
156 //- Debug switch (registered name: "solution")
157 static int debug;
158
159
160 // Constructors
161
162 //- Construct for objectRegistry, readOption, (system) dictionary name.
163 solution
164 (
165 const objectRegistry& obr,
167 const fileName& dictName,
168 const dictionary* fallback = nullptr
169 );
170
171 //- Construct for objectRegistry, (system) dictionary name
172 //- using the readOption from the registry.
173 solution
174 (
175 const objectRegistry& obr,
176 const fileName& dictName,
177 const dictionary* fallback = nullptr
178 );
179
180
181 //- Destructor. Non-default in header (incomplete types)
182 virtual ~solution();
184
185 // Member Functions
186
187 // Access
188
189 //- True if the given field should be cached
190 bool cache(const word& name) const;
191
192 //- True if the relaxation factor is given for the field
193 bool relaxField(const word& name) const;
194
195 //- Get the relaxation factor specified for the field
196 //- or the specified "default" entry, if present.
197 //- Does not change \p factor if neither direct nor "default"
198 //- can be used,
199 // \return True if found
200 bool relaxField(const word& name, scalar& factor) const;
201
202 //- True if the relaxation factor is given for the equation
203 bool relaxEquation(const word& name) const;
204
205 //- Get the relaxation factor specified for the equation
206 //- or the specified "default" entry, if present.
207 //- Does not change \p factor if neither direct nor "default"
208 //- can be used,
209 // \return True if found
210 bool relaxEquation(const word& name, scalar& factor) const;
211
212 //- Get the relaxation factor for the given field.
213 //- Fatal if not found.
214 scalar fieldRelaxationFactor(const word& name) const;
215
216 //- Get the relaxation factor for the given equation.
217 //- Fatal if not found.
218 scalar equationRelaxationFactor(const word& name) const;
219
220 //- The entire dictionary or the optional "select" sub-dictionary.
221 const dictionary& solutionDict() const;
222
223 //- Return \p name sub-dictionary within the solutionDict().
224 // Same as \c solutionDict().subDict(...)
225 const dictionary& solutionDict(const word& name) const;
226
227 //- The solver controls dictionary (all fields)
228 const dictionary& solversDict() const;
229
230 //- The solver controls dictionary for the given field.
231 //- Same as \c solversDict().subDict(...)
232 const dictionary& solverDict(const word& name) const;
233
234 //- The solver controls dictionary for the given field.
235 //- Same as solverDict(...)
236 const dictionary& solver(const word& name) const;
237
238
239 // Read
240
241 //- Read the solution dictionary
242 bool read();
243
244
245 // Other
246
247 //- Helper for printing cache message
248 template<class FieldType>
249 static void cachePrintMessage
250 (
251 const char* message,
252 const word& name,
253 const FieldType& fld
254 );
255};
256
257
258// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259
260} // End namespace Foam
261
262// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263
264#ifdef NoRepository
265 #include "solutionTemplates.C"
266#endif
267
268// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
269
270#endif
271
272// ************************************************************************* //
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition Function1.H:92
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers.
IOdictionary(const IOobject &io, const dictionary *fallback=nullptr)
Construct given an IOobject and optional fallback dictionary content.
readOption
Enumeration defining read preferences.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
const word & name() const
Name function is needed to disambiguate those inherited from regIOobject and dictionary.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
word dictName() const
The local dictionary name (final part of scoped name).
Definition dictionaryI.H:53
A class for handling file names.
Definition fileName.H:75
Registry of regIOobjects.
bool cache(const word &name) const
True if the given field should be cached.
Definition solution.C:290
virtual ~solution()
Destructor. Non-default in header (incomplete types).
Definition solution.C:220
const dictionary & solver(const word &name) const
The solver controls dictionary for the given field. Same as solverDict(...).
Definition solution.C:474
static void cachePrintMessage(const char *message, const word &name, const FieldType &fld)
Helper for printing cache message.
const dictionary & solversDict() const
The solver controls dictionary (all fields).
Definition solution.C:461
bool relaxField(const word &name) const
True if the relaxation factor is given for the field.
Definition solution.C:313
scalar fieldRelaxationFactor(const word &name) const
Get the relaxation factor for the given field. Fatal if not found.
Definition solution.C:414
const dictionary & solverDict(const word &name) const
The solver controls dictionary for the given field. Same as solversDict().subDict(....
Definition solution.C:467
static label upgradeSolverDict(dictionary &dict, const bool verbose=true)
Update from older solver controls syntax.
Definition solution.C:227
scalar equationRelaxationFactor(const word &name) const
Get the relaxation factor for the given equation. Fatal if not found.
Definition solution.C:431
static int debug
Debug switch (registered name: "solution").
Definition solution.H:183
bool relaxEquation(const word &name) const
True if the relaxation factor is given for the equation.
Definition solution.C:323
const dictionary & solutionDict() const
The entire dictionary or the optional "select" sub-dictionary.
Definition solution.C:448
bool read()
Read the solution dictionary.
Definition solution.C:481
A class for handling words, derived from Foam::string.
Definition word.H:66
const auto & fallback
Namespace for OpenFOAM.
dictionary dict