dimensioned<Type>: Added support for reading the dimensions or units before or after the value

e.g. in physicalProperties

    viscosityModel  constant;

    nu              [0 2 -1 0 0 0 0] 1e-05;

or

    nu              [m^2/s] 1e-05;

or

    nu              1e-05 [0 2 -1 0 0 0 0];

or

    nu              1e-05 [m^2/s];
This commit is contained in:
Henry Weller
2024-03-16 11:54:38 +00:00
parent 7918e4d292
commit 209a375683
3 changed files with 49 additions and 18 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -27,26 +27,18 @@ License
#include "pTraits.H"
#include "dictionary.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
void Foam::dimensioned<Type>::initialise(Istream& is)
bool Foam::dimensioned<Type>::readDimensions
(
Istream& is,
scalar& multiplier
)
{
token nextToken(is);
is.putBack(nextToken);
// Check if the original format is used in which the name is provided
// and reset the name to that read
if (nextToken.isWord())
{
is >> name_;
is >> nextToken;
is.putBack(nextToken);
}
// If the dimensions are provided compare with the argument
scalar multiplier = 1.0;
if (nextToken == token::BEGIN_SQR)
{
dimensionSet dims(dimless);
@ -59,9 +51,46 @@ void Foam::dimensioned<Type>::initialise(Istream& is)
<< " provided do not match the required dimensions "
<< dimensions_ << abort(FatalIOError);
}
return true;
}
else
{
return false;
}
}
template<class Type>
void Foam::dimensioned<Type>::initialise(Istream& is)
{
token nextToken(is);
is.putBack(nextToken);
// Check if the original format is used in which the name is provided
// and reset the name to that read
if (nextToken.isWord())
{
is >> name_;
}
scalar multiplier = 1;
// Read dimensions if they are before the value,
// compare with the argument with current
// and set the multiplier
const bool dimensionsRead = readDimensions(is, multiplier);
is >> value_;
// Read dimensions if they are after the value,
// compare with the argument with current
// and set the multiplier
if (!dimensionsRead && !is.eof())
{
readDimensions(is, multiplier);
}
value_ *= multiplier;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -78,8 +78,10 @@ class dimensioned
// Private Member Functions
//- Read the dimensions if present
bool readDimensions(Istream& is, scalar& multiplier);
//- Initialise from Istream
// Helper-function for constructors
void initialise(Istream& is);

View File

@ -16,6 +16,6 @@ FoamFile
viscosityModel constant;
nu [0 2 -1 0 0 0 0] 1e-05;
nu 1e-05 [m^2/s];
// ************************************************************************* //