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