68 string standardUnitName
81 result.append(dimensionUnitNames[i]);
82 if (
e != 1) result.append(
"^" +
name(
e));
89 result.append(dimlessUnitNames[i]);
90 if (
e != 1) result.append(
"^" +
name(
e));
94 return result(result.size() - 1);
103 const size_t i0 = str.find(iter.key());
104 const size_t i1 = i0 + iter.key().size();
106 if (i0 == std::string::npos)
continue;
108 if (i0 > 0 && isalnum(str[i0 - 1]))
continue;
110 if (i1 < str.size() && isalnum(str[i1]))
continue;
129 result == 0 && dimension[t] == 1 ? 1
130 : dimension[t] == 0 ? result
138 bool isFundamental(
const unitSet& unit)
148 result == 0 && unit[t] == 1 ? 1
149 : unit[t] == 0 ? result
159 result == 0 && unit[t] == 1 ? 1
160 : unit[t] == 0 ? result
169 int main(
int argc,
char *argv[])
177 "list only the names of the dimensions and units"
182 "print only the conversion factor value"
201 "This utility can be run with no arguments, one argument or two\n"
202 "arguments. If no arguments are given this utility will print the\n"
203 "names of all dimensions and units. If one argument is given then \n"
204 "this is taken to be the name of a dimension or a unit and\n"
205 "information will be printed regarding its relationship to the\n"
206 "corresponding fundamental dimension or unit. If two arguments are\n"
207 "given then these must be units (not dimensions) and conversions\n"
208 "between them will be printed.\n"
213 " foamUnits specificHeatCapacity\n"
214 " foamUnits \"(mol/cm^3)^-0.5/s\" \"(kmol/m^3)^-0.5/s\""
225 <<
"Options -all and -value can not be used together"
228 if (nArgs == 0 && value)
231 <<
"Option -value requires a unit argument"
242 label dimensioni = -1, dimlessUniti = -1;
247 if (dimensioni >= 0 && unit[t] != 0)
251 if (dimensioni == -1 && unit[t] == 1 && unit.
standard())
260 if (dimlessUniti >= 0 && unit[t] != 0)
264 if (dimlessUniti == -1 && unit[t] == 1 && unit.
standard())
270 if (dimensioni >= 0 && dimlessUniti == -1)
272 dimensionUnitNames[dimensioni] = iter.key();
274 if (dimensioni == -1 && dimlessUniti >= 0)
276 dimlessUnitNames[dimlessUniti] = iter.key();
285 if (!isFundamental(dimension))
287 Info<<
"+ Dimensions = " << dimension.
info() <<
nl;
289 Info <<
"+ Exponents = " << dimension <<
nl;
290 const string standardName =
301 if (iter.key() != standardName && (iter()/dimension).
unitless())
303 (iter().standard() ? standardNames : otherNames).append
309 Info<<
"+ Standard Unit"
310 << (standardNames.size() > 1 ?
"s" :
"") <<
" =";
311 forAll(standardNames, i)
Info<<
" [" << standardNames[i] <<
"]";
313 if (otherNames.
size())
315 Info<<
"+ Other Units =";
316 forAll(otherNames, i)
Info<<
" [" << otherNames[i] <<
"]";
331 const string standardName =
332 standardUnitName(dimensionUnitNames, dimlessUnitNames, unit);
335 if (!isFundamental(unit))
337 Info<<
"+ Standard Unit = [" << standardName.c_str() <<
"]"
352 printDimension(iter.key(), iter());
357 printUnit(iter.key(), iter());
375 if (isDimension && !isUnit)
382 if (!isDimension && isUnit)
390 <<
"'" <<
args[1].c_str()
391 <<
"' is not a valid dimension or unit"
398 const string name1(
args[1]);
399 const string name2(
args[2]);
401 auto assertStringIsUnit = [](
const string& str)
406 <<
"'" << str.c_str() <<
"' is a dimension. "
407 <<
"Comparison is only supported for units."
411 assertStringIsUnit(name1);
412 assertStringIsUnit(name2);
439 const string standardName =
440 standardUnitName(dimensionUnitNames, dimlessUnitNames, unit1);
444 Info<< unit2.toUser(unit1.toStandard(scalar(1)));
448 Info<<
"Units [" << name1.c_str() <<
"] [" << name2.c_str() <<
']'
449 <<
nl <<
"+ Dimensions = " << unit1.dimensions().info() <<
nl
450 <<
"+ Standard Unit = [" << standardName.c_str() <<
"]" <<
nl
451 <<
"+ Conversion: " << 1 <<
" [" << name1.c_str() <<
"] = "
452 << unit2.toUser(unit1.toStandard(scalar(1))) <<
" ["
453 << name2.c_str() <<
']' <<
nl
454 <<
"+ Conversion: " << 1 <<
" [" << name2.c_str() <<
"] = "
455 << unit1.toUser(unit2.toStandard(scalar(1))) <<
" ["
456 << name1.c_str() <<
']' <<
nl
473 str << (i ?
" " :
"") <<
"[" << names[i] <<
']';
485 isFundamental(iter())
486 ? fundamentalDimensions
488 ).append(iter.key());
491 print(
"Fundamental Dimensions", fundamentalDimensions);
492 print(
"Derived Dimensions", derivedDimensions);
501 isFundamental(iter()) && iter().standard() ? fundamentalUnits
502 : !isFundamental(iter()) && iter().standard() ? derivedUnits
503 : isFundamental(iter()) && !iter().standard() ? scaledUnits
505 ).append(iter.key());
508 print(
"Fundamental Units", fundamentalUnits);
509 print(
"Derived Units", derivedUnits);
510 print(
"Scaled Units", scaledUnits);
511 print(
"Derived-Scaled Units", derivedScaledUnits);
#define forAll(list, i)
Loop across all elements in list.
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
An STL-conforming hash table.
static Stream & writeDivider(Stream &os)
Write the standard file section divider.
Input from memory buffer stream.
void size(const label)
Override size to be inconsistent with allocated storage.
Output to memory buffer stream.
string str() const
Return the string.
Extract command arguments and options from the supplied argc and argv parameters.
static label nArgs(int argc, char *argv[])
Return the number of arguments (not options)
static void addNote(const string &)
Add extra notes for the usage information.
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
bool optionFound(const word &opt) const
Return true if the named option is found.
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Dimension set for the base types.
InfoProxy< dimensionSet > info() const
Return info proxy.
dimensionType
Define an enumeration for the names of the dimension exponents.
Unit conversion structure. Contains the associated dimensions and the multiplier with which to conver...
const dimensionSet & dimensions() const
Access the dimensions.
bool standard() const
Return whether this unit is standard. I.e., is its multiplier one?
T toStandard(const T &) const
Convert a value to standard units.
dimlessUnitType
Define an enumeration for the names of the dimensionless unit.
A class for handling words, derived from string.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
int main(int argc, char *argv[])
const char *const group
Group name for atomic constants.
HashTable< dimensionSet > table
Table of dimensions.
string breakIntoIndentedLines(const string &str, const string::size_type nLength=80, const string::size_type nIndent=0)
Break a string up into indented lines.
const HashTable< unitSet > & table()
Get the table of unit conversions.
errorManipArg< error, int > exit(error &err, const int errNo=1)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
Foam::argList args(argc, argv)