diff --git a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C index b9ed09ae80..6a0cbb7861 100644 --- a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C +++ b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C @@ -173,6 +173,26 @@ Foam::dimensioned::dimensioned // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // +template +Foam::dimensioned Foam::dimensioned::lookupOrDefault +( + const word& name, + const dictionary& dict, + const dimensionSet& dims, + const Type& defaultValue +) +{ + if (dict.found(name)) + { + return dimensioned(name, dims, dict.lookup(name)); + } + else + { + return dimensioned(name, dims, defaultValue); + } +} + + template Foam::dimensioned Foam::dimensioned::lookupOrDefault ( @@ -193,6 +213,20 @@ Foam::dimensioned Foam::dimensioned::lookupOrDefault } +template +Foam::dimensioned Foam::dimensioned::lookupOrAddToDict +( + const word& name, + dictionary& dict, + const dimensionSet& dims, + const Type& defaultValue +) +{ + Type value = dict.lookupOrAddDefault(name, defaultValue); + return dimensioned(name, dims, value); +} + + template Foam::dimensioned Foam::dimensioned::lookupOrAddToDict ( diff --git a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.H b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.H index bb7f632918..2fcf61c2db 100644 --- a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.H +++ b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.H @@ -123,7 +123,17 @@ public: // Static member functions - //- Construct from dictionary, with default value. + //- Construct from dictionary, with default dimensions and value. + static dimensioned lookupOrDefault + ( + const word&, + const dictionary&, + const dimensionSet& dims = dimless, + const Type& defaultValue = pTraits::zero + ); + + //- Construct from dictionary, with default value and dimensions. + // Deprecated, use form with dimensions before value. static dimensioned lookupOrDefault ( const word&, @@ -135,6 +145,17 @@ public: //- Construct from dictionary, with default value. // If the value is not found, it is added into the dictionary. static dimensioned lookupOrAddToDict + ( + const word&, + dictionary&, + const dimensionSet& dims = dimless, + const Type& defaultValue = pTraits::zero + ); + + //- Construct from dictionary, with default value. + // If the value is not found, it is added into the dictionary. + // Deprecated, use form with dimensions before value. + static dimensioned lookupOrAddToDict ( const word&, dictionary&,