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))
286 Info<<
"+ Dimensions = " << dimension.
info() <<
nl;
287 Info <<
"+ Exponents = " << dimension <<
nl
300 const string standardName =
301 standardUnitName(dimensionUnitNames, dimlessUnitNames, unit);
304 if (!isFundamental(unit))
306 Info<<
"+ Standard Unit = [" << standardName.c_str() <<
"]"
321 printDimension(iter.key(), iter());
326 printUnit(iter.key(), iter());
344 if (isDimension && !isUnit)
351 if (!isDimension && isUnit)
359 <<
"'" <<
args[1].c_str()
360 <<
"' is not a valid dimension or unit"
367 const string name1(
args[1]);
368 const string name2(
args[2]);
370 auto assertStringIsUnit = [](
const string& str)
375 <<
"'" << str.c_str() <<
"' is a dimension. "
376 <<
"Comparison is only supported for units."
380 assertStringIsUnit(name1);
381 assertStringIsUnit(name2);
408 const string standardName =
409 standardUnitName(dimensionUnitNames, dimlessUnitNames, unit1);
413 Info<< unit2.toUser(unit1.toStandard(scalar(1)));
417 Info<<
"Units [" << name1.c_str() <<
"] [" << name2.c_str() <<
']'
418 <<
nl <<
"+ Dimensions = " << unit1.dimensions().info() <<
nl
419 <<
"+ Standard Unit = [" << standardName.c_str() <<
"]" <<
nl
420 <<
"+ Conversion: " << 1 <<
" [" << name1.c_str() <<
"] = "
421 << unit2.toUser(unit1.toStandard(scalar(1))) <<
" ["
422 << name2.c_str() <<
']' <<
nl
423 <<
"+ Conversion: " << 1 <<
" [" << name2.c_str() <<
"] = "
424 << unit1.toUser(unit2.toStandard(scalar(1))) <<
" ["
425 << name1.c_str() <<
']' <<
nl
442 str << (i ?
" " :
"") <<
"[" << names[i] <<
']';
454 isFundamental(iter())
455 ? fundamentalDimensions
457 ).append(iter.key());
460 print(
"Fundamental Dimensions", fundamentalDimensions);
461 print(
"Derived Dimensions", derivedDimensions);
470 isFundamental(iter()) && iter().standard() ? fundamentalUnits
471 : !isFundamental(iter()) && iter().standard() ? derivedUnits
472 : isFundamental(iter()) && !iter().standard() ? scaledUnits
474 ).append(iter.key());
477 print(
"Fundamental Units", fundamentalUnits);
478 print(
"Derived Units", derivedUnits);
479 print(
"Scaled Units", scaledUnits);
480 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.
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.
const 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)