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 | Copyright (C) 2011-2015 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 "dimensionSet.H"
27 #include "dimensionedScalar.H"
28 #include "simpleRegIOobject.H"
29 #include "demandDrivenData.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 /* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
37 
38 //- Since dimensionSystems() can be reread we actually store a copy of
39 // the controlDict subDict (v.s. a reference to the subDict for e.g.
40 // dimensionedConstants)
41 dictionary* dimensionSystemsPtr_(NULL);
42 HashTable<dimensionedScalar>* unitSetPtr_(NULL);
43 dimensionSets* writeUnitSetPtr_(NULL);
44 
45 //- Helper class to
46 // - register re-reader
47 // - deallocate demand-driven data
49 :
51 {
52 public:
54  :
56  {}
58  {
62 
63  }
64  virtual void readData(Foam::Istream& is)
65  {
70  }
71  virtual void writeData(Foam::Ostream& os) const
72  {
73  os << dimensionSystems();
74  }
75 };
77 
78 
80 {
82  {
83  dictionary* cachedPtr = NULL;
85  (
87  (
88  "DimensionSets",
89  cachedPtr
90  )
91  );
92  }
93  return *dimensionSystemsPtr_;
94 }
95 
96 
98 {
99  if (!unitSetPtr_)
100  {
101  const dictionary& dict = dimensionSystems();
102 
103  if (!dict.found("unitSet"))
104  {
105  FatalIOErrorIn("unitSet()", dict)
106  << "Cannot find unitSet in dictionary " << dict.name()
107  << exit(FatalIOError);
108  }
109 
110  const word unitSetCoeffs(word(dict.lookup("unitSet")) + "Coeffs");
111 
112  if (!dict.found(unitSetCoeffs))
113  {
114  FatalIOErrorIn("unitSet()", dict)
115  << "Cannot find " << unitSetCoeffs << " in dictionary "
116  << dict.name() << exit(FatalIOError);
117  }
118 
119  const dictionary& unitDict = dict.subDict(unitSetCoeffs);
120 
122 
123  forAllConstIter(dictionary, unitDict, iter)
124  {
125  if (iter().keyword() != "writeUnits")
126  {
128  dt.read(iter().stream(), unitDict);
129  bool ok = unitSetPtr_->insert(iter().keyword(), dt);
130  if (!ok)
131  {
132  FatalIOErrorIn("unitSet()", dict)
133  << "Duplicate unit " << iter().keyword()
134  << " in DimensionSets dictionary"
135  << exit(FatalIOError);
136  }
137  }
138  }
139 
140  wordList writeUnitNames
141  (
142  unitDict.lookupOrDefault<wordList>
143  (
144  "writeUnits",
145  wordList(0)
146  )
147  );
148 
149  writeUnitSetPtr_ = new dimensionSets(*unitSetPtr_, writeUnitNames);
150 
151  if (writeUnitNames.size() != 0 && writeUnitNames.size() != 7)
152  {
153  FatalIOErrorIn("unitSet()", dict)
154  << "Cannot find entry \"writeUnits\" in " << unitDict.name()
155  << " or it is not a wordList of size 7"
156  << exit(FatalIOError);
157  }
158  }
159  return *unitSetPtr_;
160 }
161 
162 
164 {
165  if (!writeUnitSetPtr_)
166  {
167  (void)unitSet();
168  }
169  return *writeUnitSetPtr_;
170 }
171 
172 
173 const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0);
174 
175 const dimensionSet dimMass(1, 0, 0, 0, 0, 0, 0);
176 const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0);
177 const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0);
178 const dimensionSet dimTemperature(0, 0, 0, 1, 0, 0, 0);
179 const dimensionSet dimMoles(0, 0, 0, 0, 1, 0, 0);
180 const dimensionSet dimCurrent(0, 0, 0, 0, 0, 1, 0);
181 const dimensionSet dimLuminousIntensity(0, 0, 0, 0, 0, 0, 1);
182 
183 const dimensionSet dimArea(sqr(dimLength));
184 const dimensionSet dimVolume(pow3(dimLength));
185 const dimensionSet dimVol(dimVolume);
186 
187 const dimensionSet dimVelocity(dimLength/dimTime);
188 const dimensionSet dimAcceleration(dimVelocity/dimTime);
189 
190 const dimensionSet dimDensity(dimMass/dimVolume);
191 const dimensionSet dimForce(dimMass*dimAcceleration);
192 const dimensionSet dimEnergy(dimForce*dimLength);
193 const dimensionSet dimPower(dimEnergy/dimTime);
194 
195 const dimensionSet dimPressure(dimForce/dimArea);
196 const dimensionSet dimCompressibility(dimDensity/dimPressure);
197 const dimensionSet dimGasConstant(dimEnergy/dimMass/dimTemperature);
198 const dimensionSet dimSpecificHeatCapacity(dimGasConstant);
199 const dimensionSet dimViscosity(dimArea/dimTime);
200 const dimensionSet dimDynamicViscosity(dimDensity*dimViscosity);
201 
202 
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 
205 } // End namespace Foam
206 
207 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
208 
210 (
211  const HashTable<dimensionedScalar>& units,
212  const wordList& unitNames
213 )
214 :
215  units_(unitNames.size()),
216  conversion_(unitNames.size()),
217  conversionPivots_(unitNames.size()),
218  valid_(false)
219 {
220  forAll(unitNames, i)
221  {
222  units_.set
223  (
224  i,
226  (
227  units[unitNames[i]]
228  )
229  );
230  }
231 
232  if (unitNames.size() == 7)
233  {
234  valid_ = true;
235 
236  // Determine conversion from basic units to write units
237  for (label rowI = 0; rowI < conversion_.n(); rowI++)
238  {
239  scalar* row = conversion_[rowI];
240 
241  for (label columnI = 0; columnI < conversion_.m(); columnI++)
242  {
243  const dimensionedScalar& dSet = units_[columnI];
244  row[columnI] = dSet.dimensions()[rowI];
245  }
246  }
247  conversionPivots_.setSize(conversion_.n());
248  LUDecompose(conversion_, conversionPivots_);
249  }
250 }
251 
252 
254 {
255  LUBacksubstitute(conversion_, conversionPivots_, exponents);
256 }
257 
258 
259 // ************************************************************************* //
const dimensionSet dimPressure
dimensionedScalar pow3(const dimensionedScalar &ds)
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:306
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
LU back-substitution with given source, returning the solution.
const dimensionSet dimForce
addDimensionSetsToDebug addDimensionSetsToDebug_("DimensionSets")
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:51
dimensionSets * writeUnitSetPtr_(NULL)
const dimensionSet dimCompressibility
An STL-conforming hash table.
Definition: HashTable.H:61
const dimensionSet dimMoles(0, 0, 0, 0, 1, 0, 0)
Definition: dimensionSets.H:53
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
const dimensionSet dimVol(dimVolume)
Definition: dimensionSets.H:59
void deleteDemandDrivenData(DataPtr &dataPtr)
const dimensionSet dimArea(sqr(dimLength))
Definition: dimensionSets.H:57
A class for handling words, derived from string.
Definition: word.H:59
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const dimensionSet dimEnergy
dictionary & dimensionSystems()
Top level dictionary.
Definition: dimensionSets.C:79
const dimensionSet dimGasConstant
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:103
const dimensionSet dimDensity
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const dimensionSet dimPower
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:638
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
label size() const
Return number of elements in list.
Definition: DLListBaseI.H:77
const HashTable< dimensionedScalar > & unitSet()
Set of all dimensions.
Definition: dimensionSets.C:97
Namespace for OpenFOAM.
const dimensionSet & dimensions() const
Return const reference to dimensions.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
dictionary dict
dictionary * dimensionSystemsPtr_(NULL)
Since dimensionSystems() can be reread we actually store a copy of.
IOerror FatalIOError
dictionary & switchSet(const char *subDictName, dictionary *&subDictPtr)
Internal function to lookup a sub-dictionary from controlDict.
Definition: debug.C:118
Dimension set for the base types.
Definition: dimensionSet.H:116
#define forAll(list, i)
Definition: UList.H:421
const dimensionSet dimDynamicViscosity
const dimensionSet dimViscosity
const dimensionSet dimMass(1, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:49
Template functions to aid in the implementation of demand driven data.
void addDimensionSetObject(const char *name, simpleRegIOobject *obj)
Register DimensionSets read/write object.
Definition: debug.C:260
const dimensionSets & writeUnitSet()
Set of units.
virtual void readData(Foam::Istream &is)
Read.
Definition: dimensionSets.C:64
Abstract base class for registered object with I/O. Used in debug symbol registration.
addDimensionSetsToDebug(const char *name)
Definition: dimensionSets.C:53
HashTable< dimensionedScalar > * unitSetPtr_(NULL)
const dimensionSet dimAcceleration
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
const dimensionSet dimVolume(pow3(dimLength))
Definition: dimensionSets.H:58
dimensionSets(const HashTable< dimensionedScalar > &, const wordList &unitNames)
Construct from all units and set of units to use for inversion.
const dimensionSet dimCurrent(0, 0, 0, 0, 0, 1, 0)
Definition: dimensionSets.H:54
virtual void writeData(Foam::Ostream &os) const
Write.
Definition: dimensionSets.C:71
void coefficients(scalarField &) const
(if valid) obtain set of coefficients of unitNames
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
const dimensionSet dimLuminousIntensity(0, 0, 0, 0, 0, 0, 1)
Definition: dimensionSets.H:55
const dimensionSet dimTemperature(0, 0, 0, 1, 0, 0, 0)
Definition: dimensionSets.H:52
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
const dimensionSet dimSpecificHeatCapacity(dimGasConstant)
Definition: dimensionSets.H:71
void LUDecompose(scalarSquareMatrix &matrix, labelList &pivotIndices)
LU decompose the matrix with pivoting.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
const dimensionSet dimVelocity
#define FatalIOErrorIn(functionName, ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:325
void read(const dictionary &)
Update the value of dimensioned<Type>