diff --git a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C index 0e3cd19ffe..a5b618f42c 100644 --- a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C +++ b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C @@ -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 -void Foam::dimensioned::initialise(Istream& is) +bool Foam::dimensioned::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::initialise(Istream& is) << " provided do not match the required dimensions " << dimensions_ << abort(FatalIOError); } + + return true; + } + else + { + return false; + } +} + + +template +void Foam::dimensioned::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; } diff --git a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.H b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.H index ad7842c669..8f425175af 100644 --- a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.H +++ b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.H @@ -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); diff --git a/tutorials/incompressibleFluid/cavity/constant/physicalProperties b/tutorials/incompressibleFluid/cavity/constant/physicalProperties index 94254bef01..8053073c29 100644 --- a/tutorials/incompressibleFluid/cavity/constant/physicalProperties +++ b/tutorials/incompressibleFluid/cavity/constant/physicalProperties @@ -16,6 +16,6 @@ FoamFile viscosityModel constant; -nu [0 2 -1 0 0 0 0] 1e-05; +nu 1e-05 [m^2/s]; // ************************************************************************* //