Loading...
Searching...
No Matches
dimensionSets.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-2016 OpenFOAM Foundation
9 Copyright (C) 2019 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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 "dimensionSet.H"
30#include "dimensionedScalar.H"
31#include "simpleRegIOobject.H"
32#include "demandDrivenData.H"
33
34// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35
36namespace Foam
39/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
40
41// Since dimensionSystems() can be reread we actually store a copy of
42// the controlDict subDict (v.s. a reference to the subDict for e.g.
43// dimensionedConstants)
47
49
50// Helper class to
51// register re-reader
52// deallocate demand-driven data
53class addDimensionSetsToDebug
54:
56{
57public:
58
59 addDimensionSetsToDebug(const addDimensionSetsToDebug&) = delete;
60 void operator=(const addDimensionSetsToDebug&) = delete;
61
62 explicit addDimensionSetsToDebug(const char* name)
63 :
64 ::Foam::simpleRegIOobject(Foam::debug::addDimensionSetObject, name)
65 {}
66
67 virtual ~addDimensionSetsToDebug()
68 {
69 deleteDemandDrivenData(dimensionSystemsPtr_);
70 deleteDemandDrivenData(unitSetPtr_);
71 deleteDemandDrivenData(writeUnitSetPtr_);
72 }
73
74 virtual void readData(Foam::Istream& is)
75 {
76 deleteDemandDrivenData(dimensionSystemsPtr_);
77 deleteDemandDrivenData(unitSetPtr_);
78 deleteDemandDrivenData(writeUnitSetPtr_);
80 }
81
82 virtual void writeData(Foam::Ostream& os) const
83 {
85 }
86};
87
88addDimensionSetsToDebug addDimensionSetsToDebug_("DimensionSets");
89
91
92
94{
96 {
97 dictionary* cachedPtr(nullptr);
99 (
101 (
102 "DimensionSets",
103 cachedPtr
105 );
106 }
107 return *dimensionSystemsPtr_;
108}
109
110
112{
113 if (!unitSetPtr_)
114 {
116
117 if (!dict.found("unitSet"))
118 {
120 << "Cannot find unitSet in dictionary " << dict.name()
121 << exit(FatalIOError);
122 }
123
124 const word unitSetCoeffs(dict.get<word>("unitSet") + "Coeffs");
125
126 const dictionary* unitDictPtr = dict.findDict(unitSetCoeffs);
127
128 if (!unitDictPtr)
129 {
131 << "Cannot find " << unitSetCoeffs << " in dictionary "
132 << dict.name() << nl
133 << exit(FatalIOError);
134 }
135
136 const dictionary& unitDict = *unitDictPtr;
137
138 unitSetPtr_ = new HashTable<dimensionedScalar>(2*unitDict.size());
139
140 wordList writeUnitNames;
141
142 for (const entry& dEntry : unitDict)
143 {
144 if ("writeUnits" == dEntry.keyword())
145 {
146 dEntry.readEntry(writeUnitNames);
147 }
148 else
149 {
151 dt.read(dEntry.stream(), unitDict);
152
153 bool ok = unitSetPtr_->insert(dEntry.keyword(), dt);
154 if (!ok)
155 {
157 << "Duplicate unit " << dEntry.keyword()
158 << " in DimensionSets dictionary"
159 << exit(FatalIOError);
160 }
161 }
162 }
163
164 if (writeUnitNames.size() != 0 && writeUnitNames.size() != 7)
165 {
167 << "Cannot find entry \"writeUnits\" in " << unitDict.name()
168 << " or it is not a wordList of size 7"
169 << exit(FatalIOError);
170 }
171
173 }
174
175 return *unitSetPtr_;
176}
177
178
180{
181 if (!writeUnitSetPtr_)
183 (void)unitSet();
184 }
185 return *writeUnitSetPtr_;
186}
187
188
190
191const dimensionSet dimMass(1, 0, 0, 0, 0, 0, 0);
192const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0);
193const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0);
194const dimensionSet dimTemperature(0, 0, 0, 1, 0, 0, 0);
195const dimensionSet dimMoles(0, 0, 0, 0, 1, 0, 0);
196const dimensionSet dimCurrent(0, 0, 0, 0, 0, 1, 0);
197const dimensionSet dimLuminousIntensity(0, 0, 0, 0, 0, 0, 1);
198
210
217
218
219// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220
221} // End namespace Foam
222
223
224// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
225
227(
228 const HashTable<dimensionedScalar>& units,
229 const wordList& unitNames
230)
231:
232 units_(unitNames.size()),
233 conversion_(unitNames.size()),
234 conversionPivots_(unitNames.size()),
235 valid_(false)
236{
237 forAll(unitNames, i)
238 {
239 units_.set
240 (
241 i,
243 (
244 units[unitNames[i]]
245 )
246 );
247 }
248
249 if (unitNames.size() == 7)
250 {
251 valid_ = true;
252
253 // Determine conversion from basic units to write units
254 for (label rowI = 0; rowI < conversion_.m(); rowI++)
255 {
256 scalar* row = conversion_[rowI];
257
258 for (label columnI = 0; columnI < conversion_.n(); columnI++)
259 {
260 const dimensionedScalar& dSet = units_[columnI];
261 row[columnI] = dSet.dimensions()[rowI];
262 }
264 conversionPivots_.setSize(conversion_.m());
265 LUDecompose(conversion_, conversionPivots_);
266 }
267}
268
269
271{
272 LUBacksubstitute(conversion_, conversionPivots_, exponents);
273}
274
275
276// ************************************************************************* //
label size() const noexcept
The number of elements in list.
Definition DLListBase.H:194
A HashTable similar to std::unordered_map.
Definition HashTable.H:124
void setSize(label n)
Alias for resize().
Definition List.H:536
label m() const noexcept
The number of rows.
Definition Matrix.H:261
label n() const noexcept
The number of columns.
Definition Matrix.H:271
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
const fileName & name() const noexcept
The dictionary name.
Definition dictionaryI.H:41
const dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary pointer if present (and it is a dictionary) otherwise return nullptr...
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Construction of unit sets.
const PtrList< dimensionedScalar > & units() const noexcept
Return the units.
void coefficients(scalarField &exponents) const
(if valid) obtain set of coefficients of unitNames
dimensionSets(const HashTable< dimensionedScalar > &, const wordList &unitNames)
Construct from all units and set of units to use for inversion (writing).
bool read(const dictionary &dict)
Update the value of dimensioned<Type>, lookup in dictionary with the name().
const dimensionSet & dimensions() const noexcept
Return const reference to dimensions.
A keyword and a list of tokens is an 'entry'.
Definition entry.H:66
Abstract base class for registered object with I/O. Used in debug symbol registration.
A class for handling words, derived from Foam::string.
Definition word.H:66
Template functions to aid in the implementation of demand driven data.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
OBJstream os(runTime.globalPath()/outputName)
Namespace for handling debugging switches.
Definition debug.C:45
dictionary & switchSet(const char *subDictName, dictionary *&subDictPtr)
Internal function to lookup a sub-dictionary from controlDict.
Definition debug.C:179
Namespace for OpenFOAM.
const dimensionSet dimPressure
const dimensionSet dimViscosity
List< word > wordList
List of word.
Definition fileName.H:60
const dimensionSet dimPower
const dimensionSet dimless
Dimensionless.
const dimensionSet dimCompressibility
dimensionedSymmTensor sqr(const dimensionedVector &dv)
const dimensionSet dimEnergy
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
dimensionedScalar pow3(const dimensionedScalar &ds)
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
const dimensionSet dimCurrent(0, 0, 0, 0, 0, 1, 0)
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
LU back-substitution with given source, returning the solution in the source.
const dimensionSet dimMoles(0, 0, 0, 0, 1, 0, 0)
const dimensionSet dimArea(sqr(dimLength))
const dimensionSet dimVelocity
void LUDecompose(scalarSquareMatrix &matrix, labelList &pivotIndices)
LU decompose the matrix with pivoting.
const dimensionSet dimGasConstant
dictionary & dimensionSystems()
Top level dictionary.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dictionary * dimensionSystemsPtr_(nullptr)
const dimensionSet dimSpecificHeatCapacity(dimGasConstant)
const dimensionSet dimTemperature(0, 0, 0, 1, 0, 0, 0)
const HashTable< dimensionedScalar > & unitSet()
Set of all dimensions.
const dimensionSet dimForce
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
const dimensionSets & writeUnitSet()
Set of units.
const dimensionSet dimDynamicViscosity
const dimensionSet dimAcceleration
const dimensionSet dimVolume(pow3(dimLength))
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
HashTable< dimensionedScalar > * unitSetPtr_(nullptr)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
const dimensionSet dimDensity
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
dimensionSets * writeUnitSetPtr_(nullptr)
void deleteDemandDrivenData(DataPtr &dataPtr)
const dimensionSet dimMass(1, 0, 0, 0, 0, 0, 0)
const dimensionSet dimVol(dimVolume)
Older spelling for dimVolume.
const dimensionSet dimLuminousIntensity(0, 0, 0, 0, 0, 0, 1)
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299
const bool writeData(pdfDictionary.get< bool >("writeData"))