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-2025 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 
34 int dimensionedConstantsDebug(debug::debugSwitch("dimensionedConstants", 0));
35 
37 
39 {
41  {
42  dictionary* cachedPtr = nullptr;
43 
45  (
47  (
48  "DimensionedConstants",
49  cachedPtr
50  )
51  );
52  }
53 
55 }
56 
57 // Delete the above data at the end of the run
59 {
61  {
63  {
64  Info<< "DimensionedConstants" << dimensionedConstantsDict() << endl;
65  }
66 
68  }
69 };
70 
72 
73 }
74 
75 
76 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
77 
79 (
80  const char* const group,
81  const char* name,
83 )
84 {
86 
87  const dimensionedScalar dimensionedValue
88  (
89  name,
90  dimensions,
91  dict.subDict(group).lookup(name)
92  );
93 
94  dict.subDict(group).set(name, dimensionedValue);
95 
96  return dimensionedValue;
97 }
98 
99 
101 (
102  const char* const group,
103  const char* name,
104  const dimensionedScalar& valueNoName
105 )
106 {
107  return dimensionedConstant(group, name, name, valueNoName);
108 }
109 
110 
112 (
113  const char* const group,
114  const char* entryName,
115  const char* codeName,
116  const dimensionedScalar& valueNoName
117 )
118 {
120 
121  const dimensionedScalar dimensionedValue(codeName, valueNoName);
122 
123  if (!dict.found(group))
124  {
125  dict.add(group, dictionary());
126  }
127 
128  dict.subDict(group).add(entryName, dimensionedValue);
129 
130  return dimensionedValue;
131 }
132 
133 
135 (
136  const char* const group,
137  const char* name,
138  const unitConversion& units,
139  const scalar value
140 )
141 {
142  return dimensionedConstant(group, name, name, units, value);
143 }
144 
145 
147 (
148  const char* const group,
149  const char* entryName,
150  const char* codeName,
151  const unitConversion& units,
152  const scalar value
153 )
154 {
156 
157  const dimensionedScalar dimensionedValue
158  (
159  codeName,
160  units.dimensions(),
161  units.toStandard(value)
162  );
163 
164  if (!dict.found(group))
165  {
166  dict.add(group, dictionary());
167  }
168 
169  dict.subDict(group).add(entryName, dimensionedValue);
170 
171  return dimensionedValue;
172 }
173 
174 
175 // ************************************************************************* //
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...
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 controlDict.
Definition: debug.C:164
int debugSwitch(const char *name, const int defaultValue=0)
Lookup debug switch or add default value.
Definition: debug.C:211
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:258
dictionary & dimensionedConstantsDict()
void deleteDemandDrivenData(DataType *&dataPtr)
deleteDimensionedConstantsPtr deleteDimensionedConstantsPtr_
messageStream Info
const HashTable< unitConversion > & units()
Get the table of unit conversions.
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.
int dimensionedConstantsDebug(debug::debugSwitch("dimensionedConstants", 0))
dictionary * dimensionedConstantsDictPtr_(nullptr)
dictionary dict