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:
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -27,26 +27,18 @@ License
|
|||||||
#include "pTraits.H"
|
#include "pTraits.H"
|
||||||
#include "dictionary.H"
|
#include "dictionary.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
void Foam::dimensioned<Type>::initialise(Istream& is)
|
bool Foam::dimensioned<Type>::readDimensions
|
||||||
|
(
|
||||||
|
Istream& is,
|
||||||
|
scalar& multiplier
|
||||||
|
)
|
||||||
{
|
{
|
||||||
token nextToken(is);
|
token nextToken(is);
|
||||||
is.putBack(nextToken);
|
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)
|
if (nextToken == token::BEGIN_SQR)
|
||||||
{
|
{
|
||||||
dimensionSet dims(dimless);
|
dimensionSet dims(dimless);
|
||||||
@ -59,9 +51,46 @@ void Foam::dimensioned<Type>::initialise(Istream& is)
|
|||||||
<< " provided do not match the required dimensions "
|
<< " provided do not match the required dimensions "
|
||||||
<< dimensions_ << abort(FatalIOError);
|
<< 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_;
|
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;
|
value_ *= multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -78,8 +78,10 @@ class dimensioned
|
|||||||
|
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
|
//- Read the dimensions if present
|
||||||
|
bool readDimensions(Istream& is, scalar& multiplier);
|
||||||
|
|
||||||
//- Initialise from Istream
|
//- Initialise from Istream
|
||||||
// Helper-function for constructors
|
|
||||||
void initialise(Istream& is);
|
void initialise(Istream& is);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,6 @@ FoamFile
|
|||||||
|
|
||||||
viscosityModel constant;
|
viscosityModel constant;
|
||||||
|
|
||||||
nu [0 2 -1 0 0 0 0] 1e-05;
|
nu 1e-05 [m^2/s];
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
Reference in New Issue
Block a user