Loading...
Searching...
No Matches
tolerances.C
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 OpenFOAM Foundation
9 Copyright (C) 2021 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/>.
27\*---------------------------------------------------------------------------*/
28
29#include "tolerances.H"
30
31// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32
33Foam::tolerances::tolerances(const Time& t, const fileName& dictName)
34:
36 (
38 (
40 t.system(),
41 t,
44 )
45 ),
46
47 // Named, but empty dictionaries
48 relaxationFactors_("relaxationFactors"),
49 solverTolerances_("solverTolerances"),
50 solverRelativeTolerances_("solverRelativeTolerances")
52 read();
53}
54
55
56// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
57
59{
61 {
62 const word toleranceSetName(get<word>("toleranceSet"));
63 const dictionary& toleranceSet = subDict(toleranceSetName);
64
65 if (toleranceSet.found("relaxationFactors"))
66 {
67 relaxationFactors_ = toleranceSet.subDict("relaxationFactors");
68 }
69
70 if (toleranceSet.found("solverTolerances"))
71 {
72 solverTolerances_ = toleranceSet.subDict("solverTolerances");
73 }
74
75 if (toleranceSet.found("solverRelativeTolerances"))
76 {
77 solverRelativeTolerances_ =
78 toleranceSet.subDict("solverRelativeTolerances");
79 }
80
81 return true;
82 }
83
84 return false;
85}
86
88bool Foam::tolerances::relax(const word& name) const
89{
90 return relaxationFactors_.found(name);
91}
92
94Foam::scalar Foam::tolerances::relaxationFactor(const word& name) const
95{
96 return relaxationFactors_.get<scalar>(name);
97}
98
100Foam::scalar Foam::tolerances::solverTolerance(const word& name) const
101{
102 return solverTolerances_.get<scalar>(name);
103}
104
107{
108 return solverRelativeTolerances_.size();
109}
110
111
112Foam::scalar Foam::tolerances::solverRelativeTolerance(const word& name) const
113{
114 return solverRelativeTolerances_.get<scalar>(name);
115}
116
117
118// ************************************************************************* //
IOdictionary(const IOobject &io, const dictionary *fallback=nullptr)
Construct given an IOobject and optional fallback dictionary content.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
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
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition dictionary.C:441
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
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
virtual bool read()
Read object.
scalar solverTolerance(const word &name) const
Definition tolerances.C:93
bool solverRelativeTolerances() const
Definition tolerances.C:99
bool relax(const word &name) const
Definition tolerances.C:81
scalar relaxationFactor(const word &name) const
Definition tolerances.C:87
scalar solverRelativeTolerance(const word &name) const
Definition tolerances.C:105
bool read()
Read the tolerances.
Definition tolerances.C:51
A class for handling words, derived from Foam::string.
Definition word.H:66
int system(const std::string &command, const bool bg=false)
Execute the specified command via the shell.
Definition POSIX.C:1704
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127