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-2020 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 {
33 }
34 
35 
37 {
38  return debug::switchSet
39  (
40  "DimensionedConstants",
42  );
43 }
44 
45 
47 (
48  const char* const group,
49  const char* name,
51 )
52 {
54 
55  // Check that the entries exist.
56  // Note: should make FatalError robust instead!
57 
58  if (!dict.found("unitSet"))
59  {
60  std::cerr<< "Cannot find unitSet in dictionary " << dict.name()
61  << std::endl;
62  }
63 
64  const word unitSetCoeffs(word(dict.lookup("unitSet")) + "Coeffs");
65 
66  if (!dict.found(unitSetCoeffs))
67  {
68  std::cerr<< "Cannot find " << unitSetCoeffs << " in dictionary "
69  << dict.name() << std::endl;
70  }
71 
72  return dimensionedScalar
73  (
74  name,
75  dimensions,
76  dict.subDict(unitSetCoeffs).subDict(group)
77  );
78 }
79 
80 
82 (
83  const char* const group,
84  const char* name,
85  const dimensionedScalar& defaultValuee
86 )
87 {
89 
90  const word unitSet(dict.lookup("unitSet"));
91  dictionary& unitDict(dict.subDict(unitSet + "Coeffs"));
92 
93  const dimensionedScalar defaultValue(name, defaultValuee);
94 
95  if (unitDict.found(group))
96  {
97  dictionary& groupDict = unitDict.subDict(group);
98  if (groupDict.found(name))
99  {
100  return dimensionedScalar
101  (
102  name,
103  defaultValue.dimensions(),
104  groupDict.lookup(name)
105  );
106  }
107  else
108  {
109  groupDict.add(name, defaultValue);
110  return defaultValue;
111  }
112  }
113  else
114  {
115  unitDict.add(group, dictionary::null);
116  unitDict.subDict(group).add(name, defaultValue);
117  return defaultValue;
118  }
119 }
120 
121 
122 // ************************************************************************* //
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:710
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:843
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:1014
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:509
Dimension set for the base types.
Definition: dimensionSet.H:125
const dimensionSet & dimensions() const
Return const reference to dimensions.
A class for handling words, derived from string.
Definition: word.H:62
Dictionary reading and supplying the dimensioned constants used within OpenFOAM, particularly for the...
const char *const group
Group name for atomic constants.
dictionary & switchSet(const char *subDictName, dictionary *&subDictPtr)
Internal function to lookup a sub-dictionary from controlDict.
Definition: debug.C:164
Namespace for OpenFOAM.
const HashTable< dimensionSet > & dimensions()
Get the table of dimension sets.
Definition: dimensionSets.C:96
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
dimensionedScalar dimensionedConstant(const char *const group, const char *name, const dimensionSet &dimensions)
dictionary & dimensionedConstants()
dictionary * dimensionedConstantsPtr_(nullptr)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
dictionary dict