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-2026 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 #include "demandDrivenData.H"
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 
35 
37 
39 {
41  {
42  dictionary* cachedPtr = nullptr;
43 
45  (
47  (
48  debug::configDict().found("constants")
49  ? "constants"
50  : debug::configDict().found("DimensionedConstants")
51  ? "DimensionedConstants"
52  : "constants",
53  cachedPtr
54  )
55  );
56  }
57 
59 }
60 
61 // Delete the above data at the end of the run
63 {
65  {
67  {
68  Info<< "constants"
70  }
71 
73  }
74 };
75 
77 
78 }
79 
80 
81 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
82 
84 (
85  const char* const group,
86  const char* name,
87  const dimensionSet& dimensions
88 )
89 {
91 
92  const dimensionedScalar dimensionedValue
93  (
94  name,
95  dimensions,
96  dict.isDict(group)
97  && dict.subDict(group).found(name)
98  ? dict.subDict(group).lookup(name)
99  : dict.found(name)
100  ? dict.lookup(name)
101  : dict.isDict(group)
102  ? dict.subDict(group).lookup(name)
103  : dict.lookup(name)
104  );
105 
106  if (!dict.found(group))
107  {
108  dict.add(group, dictionary::null);
109  }
110 
111  dict.subDict(group).set(name, dimensionedValue);
112 
113  if (dict.found(name))
114  {
115  dict.remove(name);
116  }
117 
118  return dimensionedValue;
119 }
120 
121 
123 (
124  const char* const group,
125  const char* name,
126  const dimensionedScalar& valueNoName
127 )
128 {
129  return dimensionedConstant(group, name, name, valueNoName);
130 }
131 
132 
134 (
135  const char* const group,
136  const char* entryName,
137  const char* codeName,
138  const dimensionedScalar& valueNoName
139 )
140 {
142 
143  const dimensionedScalar dimensionedValue(codeName, valueNoName);
144 
145  if (!dict.found(group))
146  {
147  dict.add(group, dictionary::null);
148  }
149 
150  dict.subDict(group).add(entryName, dimensionedValue);
151 
152  return dimensionedValue;
153 }
154 
155 
157 (
158  const char* const group,
159  const char* name,
160  const unitSet& units,
161  const scalar value
162 )
163 {
164  return dimensionedConstant(group, name, name, units, value);
165 }
166 
167 
169 (
170  const char* const group,
171  const char* entryName,
172  const char* codeName,
173  const unitSet& units,
174  const scalar value
175 )
176 {
178 
179  const dimensionedScalar dimensionedValue
180  (
181  codeName,
182  units.dimensions(),
183  units.toStandard(value)
184  );
185 
186  if (!dict.found(group))
187  {
188  dict.add(group, dictionary::null);
189  }
190 
191  dict.subDict(group).add(entryName, dimensionedValue);
192 
193  return dimensionedValue;
194 }
195 
196 
197 // ************************************************************************* //
bool found
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Dimension set for the base types.
Definition: dimensionSet.H:125
Unit conversion structure. Contains the associated dimensions and the multiplier with which to conver...
Definition: unitSet.H:68
const dimensionSet & dimensions() const
Access the dimensions.
Definition: unitSetI.H:50
T toStandard(const T &) const
Convert a value to standard units.
Template functions to aid in the implementation of demand driven data.
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 configDict.
Definition: debug.C:196
dictionary & configDict()
The central control dictionary.
Definition: debug.C:117
int debugSwitch(const char *name, const int defaultValue=0)
Lookup debug switch or add default value.
Definition: debug.C:243
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
dictionary & dimensionedConstantsDict()
void deleteDemandDrivenData(DataType *&dataPtr)
deleteDimensionedConstantsPtr deleteDimensionedConstantsPtr_
messageStream Info
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
dimensionedScalar dimensionedConstant(const char *const group, const char *name, const dimensionSet &dimensions)
Construct and return a constant by looking up from the DimensionedConstants.
dictionary * dimensionedConstantsDictPtr_(nullptr)
int dimensionedConstantsDebug(debug::debugSwitch("constants", 0))
dictionary dict