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 -------------------------------------------------------------------------------
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 \*---------------------------------------------------------------------------*/
28 
29 #include "tolerances.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 Foam::tolerances::tolerances(const Time& t, const fileName& dictName)
34 :
36  (
37  IOobject
38  (
39  dictName,
40  t.system(),
41  t,
42  IOobject::MUST_READ_IF_MODIFIED,
43  IOobject::NO_WRITE
44  )
45  ),
46 
47  // Named, but empty dictionaries
48  relaxationFactors_("relaxationFactors"),
49  solverTolerances_("solverTolerances"),
50  solverRelativeTolerances_("solverRelativeTolerances")
51 {
52  read();
53 }
54 
55 
56 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
57 
59 {
60  if (regIOobject::read())
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 
87 
88 bool Foam::tolerances::relax(const word& name) const
89 {
90  return relaxationFactors_.found(name);
91 }
92 
93 
94 Foam::scalar Foam::tolerances::relaxationFactor(const word& name) const
95 {
96  return relaxationFactors_.get<scalar>(name);
97 }
98 
99 
100 Foam::scalar Foam::tolerances::solverTolerance(const word& name) const
101 {
102  return solverTolerances_.get<scalar>(name);
103 }
104 
105 
107 {
108  return solverRelativeTolerances_.size();
109 }
110 
111 
113 {
114  return solverRelativeTolerances_.get<scalar>(name);
115 }
116 
117 
118 // ************************************************************************* //
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
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::dictionary::found
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionaryI.H:87
Foam::tolerances::solverRelativeTolerances
bool solverRelativeTolerances() const
Definition: tolerances.C:106
dictName
const word dictName("faMeshDefinition")
Foam::system
int system(const std::string &command, const bool bg=false)
Execute the specified command via the shell.
Definition: MSwindows.C:1150
Foam::regIOobject::read
virtual bool read()
Read object.
Definition: regIOobjectRead.C:191
tolerances.H
Foam::tolerances::relax
bool relax(const word &name) const
Definition: tolerances.C:88
Foam::dictionary::subDict
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:460
Foam::tolerances::solverRelativeTolerance
scalar solverRelativeTolerance(const word &name) const
Definition: tolerances.C:112
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::tolerances::read
bool read()
Read the tolerances.
Definition: tolerances.C:58
Foam::tolerances::relaxationFactor
scalar relaxationFactor(const word &name) const
Definition: tolerances.C:94
Foam::tolerances::solverTolerance
scalar solverTolerance(const word &name) const
Definition: tolerances.C:100
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59