diff --git a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/phasesSystem/phaseSystem/phaseSystem.C b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/phasesSystem/phaseSystem/phaseSystem.C index e7ca5bdfb29dbeb780dd418f38ce7d85798efbce..8b3850b23dedee390ec4a7a11066745383d6da1c 100644 --- a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/phasesSystem/phaseSystem/phaseSystem.C +++ b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/phasesSystem/phaseSystem/phaseSystem.C @@ -236,7 +236,8 @@ Foam::phaseSystem::phaseSystem phasePairs_(), totalPhasePairs_(), Prt_ - ( dimensioned<scalar>::lookupOrAddToDict + ( + dimensioned<scalar>::lookupOrAddToDict ( "Prt", *this, 1.0 ) diff --git a/applications/test/dimensionedType/Test-dimensionedType.C b/applications/test/dimensionedType/Test-dimensionedType.C index 04c7fda5328abf87ae8cecaf823284acbb382861..c8e69786d2691b4a22ab4ed24021fd9c136e43bd 100644 --- a/applications/test/dimensionedType/Test-dimensionedType.C +++ b/applications/test/dimensionedType/Test-dimensionedType.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2018-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -23,7 +23,9 @@ License \*---------------------------------------------------------------------------*/ +#include "dictionary.H" #include "dimensionedTensor.H" + using namespace Foam; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -100,6 +102,32 @@ int main(int argc, char *argv[]) Pout<< "zero vector: " << dimensionedVector(dimLength) << endl; Pout<< "zero tensor: " << dimensionedTensor(dimLength) << endl; + + dictionary dict; + { + dict.add("test1", scalar(10)); + dict.add("test2a", scalar(21)); + dict.add("test5", dimensionedScalar("", 50)); + // This will fail to tokenize: + // dict.add("test5", dimensionedScalar(50)); + } + + Info<< nl << "Get from dictionary: " << dict << nl; + + Info<< "test1 : " << dimensionedScalar("test1", dict) << nl; + Info<< "test2 : " << dimensionedScalar("test2", dimless, 20, dict) << nl; + Info<< "test2a : " << dimensionedScalar("test2a", dimless, 20, dict) << nl; + Info<< "test3 : " + << dimensionedScalar::lookupOrDefault("test3", dict, 30) << nl; + + Info<< "test4 : " + << dimensionedScalar::lookupOrAddToDict("test4", dict, 40) << nl; + + Info<< "test5 : " + << dimensionedScalar::lookupOrAddToDict("test5", dict, -50) << nl; + + Info<< nl << "Dictionary is now: " << dict << nl; + Info<< "End\n" << endl; return 0; diff --git a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C index 4a932cf84258a2e94a34ad1e672bdf7ce22d629f..652c9bd58d784d46b9d9df8f40480b70468f7804 100644 --- a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C +++ b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C @@ -244,8 +244,12 @@ Foam::dimensioned<Type> Foam::dimensioned<Type>::lookupOrAddToDict const Type& defaultValue ) { - Type value = dict.lookupOrAddDefault<Type>(name, defaultValue); - return dimensioned<Type>(name, dims, value); + if (!dict.found(name)) + { + (void) dict.add(name, defaultValue); + } + + return dimensioned<Type>(name, dims, dict); }