All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dimensionedConstants.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "dimensionedConstants.H"
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32  dictionary* dimensionedConstantsPtr_(nullptr);
33 }
34 
35 
37 {
38  return debug::switchSet
39  (
40  "DimensionedConstants",
42  );
43 }
44 
45 
46 void Foam::registerDimensionedConstant::lookup()
47 {
49 
50  // Check that the entries exist.
51  // Note: should make FatalError robust instead!
52 
53  if (!dict.found("unitSet"))
54  {
55  std::cerr<< "Cannot find unitSet in dictionary " << dict.name()
56  << std::endl;
57  }
58 
59  const word unitSetCoeffs(word(dict.lookup("unitSet")) + "Coeffs");
60 
61  if (!dict.found(unitSetCoeffs))
62  {
63  std::cerr<< "Cannot find " << unitSetCoeffs << " in dictionary "
64  << dict.name() << std::endl;
65  }
66 
68  (
70  (
71  name(),
72  dimensions(),
73  dict.subDict(unitSetCoeffs).subDict(group_)
74  )
75  );
76 }
77 
78 
79 void Foam::registerDimensionedConstantWithDefault::lookup()
80 {
82 
83  const word unitSet(dict.lookup("unitSet"));
84  dictionary& unitDict(dict.subDict(unitSet + "Coeffs"));
85 
86  if (unitDict.found(group_))
87  {
88  dictionary& groupDict = unitDict.subDict(group_);
89  if (groupDict.found(name()))
90  {
92  (
94  (
95  name(),
96  default_.dimensions(),
97  groupDict.lookup(name())
98  )
99  );
100  }
101  else
102  {
103  groupDict.add(name(), default_);
104  dimensionedScalar::operator=(default_);
105  }
106  }
107  else
108  {
109  unitDict.add(group_, dictionary::null);
110  unitDict.subDict(group_).add(name(), default_);
111  dimensionedScalar::operator=(default_);
112  }
113 }
114 
115 
116 // ************************************************************************* //
dictionary dict
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:667
friend Ostream & operator(Ostream &, const dimensioned< Type > &)
dictionary & switchSet(const char *subDictName, dictionary *&subDictPtr)
Internal function to lookup a sub-dictionary from controlDict.
Definition: debug.C:131
Dictionary reading and supplying the dimensioned constants used within OpenFOAM, particularly for the...
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
static const dictionary null
Null dictionary.
Definition: dictionary.H:241
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:1056
dictionary & dimensionedConstants()
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:934
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:111
A class for handling words, derived from string.
Definition: word.H:59
const HashTable< dimensionedScalar > & unitSet()
Set of all dimensions.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
dictionary * dimensionedConstantsPtr_(nullptr)
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:812