diff --git a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1New.C b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1New.C index 91c10797e392c293009ea1178c8ecdafed224623..c1490ef88df45553858a210dfd902a41d517c51c 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1New.C +++ b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1New.C @@ -38,26 +38,38 @@ Foam::autoPtr<Foam::Function1<Type>> Foam::Function1<Type>::New const word& redirectType ) { - if (dict.isDict(entryName)) + word modelType(redirectType); + + const entry* eptr = dict.findEntry(entryName, keyType::LITERAL); + + if (!eptr && modelType.empty()) { - const dictionary& coeffsDict(dict.subDict(entryName)); + FatalIOErrorInFunction(dict) + << "No Function1 dictionary entry: " + << entryName << nl << nl + << exit(FatalIOError); + } - const word Function1Type + if (eptr->isDict()) + { + const dictionary& coeffsDict = eptr->dict(); + + coeffsDict.readEntry ( - redirectType.empty() - ? coeffsDict.get<word>("type") - : coeffsDict.lookupOrDefault<word>("type", redirectType) + "type", + modelType, + keyType::LITERAL, + redirectType.empty() // mandatory when redirectType is empty ); - auto cstrIter = dictionaryConstructorTablePtr_->cfind(Function1Type); + auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType); if (!cstrIter.found()) { FatalIOErrorInFunction(dict) << "Unknown Function1 type " - << Function1Type << " for " - << entryName << nl << nl - << "Valid Function1 types :" << nl + << modelType << " for " << entryName + << "\n\nValid Function1 types :\n" << dictionaryConstructorTablePtr_->sortedToc() << nl << exit(FatalIOError); } @@ -66,66 +78,40 @@ Foam::autoPtr<Foam::Function1<Type>> Foam::Function1<Type>::New } else { - const dictionary::const_searcher finder - ( - dict.csearch(entryName, keyType::REGEX) - ); + Istream& is = eptr->stream(); - word Function1Type; - if (finder.found()) - { - Istream& is = finder.ref().stream(); - - token firstToken(is); - - if (!firstToken.isWord()) - { - is.putBack(firstToken); - return autoPtr<Function1<Type>> - ( - new Function1Types::Constant<Type>(entryName, is) - ); - } - else - { - Function1Type = firstToken.wordToken(); - } - } - else if (redirectType != word::null) - { - Function1Type = redirectType; - } - else + token firstToken(is); + + if (!firstToken.isWord()) { - FatalIOErrorInFunction(dict) - << "Cannot find specification for Function1 " - << entryName << nl << nl - << "Valid Function1 types :" << nl - << dictionaryConstructorTablePtr_->sortedToc() << nl - << exit(FatalIOError); + is.putBack(firstToken); + return autoPtr<Function1<Type>> + ( + new Function1Types::Constant<Type>(entryName, is) + ); } - auto cstrIter = dictionaryConstructorTablePtr_->cfind(Function1Type); + modelType = firstToken.wordToken(); + } - if (!cstrIter.found()) - { - FatalIOErrorInFunction(dict) - << "Unknown Function1 type " - << Function1Type << " for " - << entryName << nl << nl - << "Valid Function1 types :" << nl - << dictionaryConstructorTablePtr_->sortedToc() << nl - << exit(FatalIOError); - } - return cstrIter() - ( - entryName, - dict.found(entryName + "Coeffs") - ? dict.subDict(entryName + "Coeffs") - : dict - ); + auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType); + + if (!cstrIter.found()) + { + FatalIOErrorInFunction(dict) + << "Unknown Function1 type " + << modelType << " for " << entryName + << "\n\nValid Function1 types :\n" + << dictionaryConstructorTablePtr_->sortedToc() << nl + << exit(FatalIOError); } + + return cstrIter() + ( + entryName, + dict.optionalSubDict(entryName + "Coeffs") + ); } diff --git a/src/meshTools/PatchFunction1/PatchFunction1New.C b/src/meshTools/PatchFunction1/PatchFunction1New.C index f74486972846a9a2d6bee08148fc448528aeddb9..a04939c7939ebaea8e82fc4bc87614d18102321d 100644 --- a/src/meshTools/PatchFunction1/PatchFunction1New.C +++ b/src/meshTools/PatchFunction1/PatchFunction1New.C @@ -38,11 +38,21 @@ Foam::autoPtr<Foam::PatchFunction1<Type>> Foam::PatchFunction1<Type>::New const bool faceValues ) { - if (dict.isDict(entryName)) + const entry* eptr = dict.findEntry(entryName, keyType::LITERAL); + + if (!eptr) { - const dictionary& coeffsDict(dict.subDict(entryName)); + FatalIOErrorInFunction(dict) + << "No PatchFunction1 dictionary entry: " + << entryName << nl << nl + << exit(FatalIOError); + } - const word modelType(coeffsDict.getWord("type")); + if (eptr->isDict()) + { + const dictionary& coeffsDict = eptr->dict(); + + const word modelType(coeffsDict.getWord("type", keyType::LITERAL)); auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType); @@ -50,9 +60,8 @@ Foam::autoPtr<Foam::PatchFunction1<Type>> Foam::PatchFunction1<Type>::New { FatalIOErrorInFunction(coeffsDict) << "Unknown PatchFunction1 type " - << modelType << " for PatchFunction1 " - << entryName << nl << nl - << "Valid PatchFunction1 types :" << nl + << modelType << " for " << entryName + << "\n\nValid PatchFunction1 types :\n" << dictionaryConstructorTablePtr_->sortedToc() << nl << exit(FatalIOError); } @@ -61,7 +70,7 @@ Foam::autoPtr<Foam::PatchFunction1<Type>> Foam::PatchFunction1<Type>::New } else { - ITstream& is = dict.lookup(entryName, keyType::LITERAL); + ITstream& is = eptr->stream(); token firstToken(is); @@ -110,15 +119,15 @@ Foam::autoPtr<Foam::PatchFunction1<Type>> Foam::PatchFunction1<Type>::New ); } + auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType); if (!cstrIter.found()) { FatalIOErrorInFunction(dict) << "Unknown PatchFunction1 type " - << modelType << " for PatchFunction1 " - << entryName << nl << nl - << "Valid PatchFunction1 types :" << nl + << modelType << " for " << entryName + << "\n\nValid PatchFunction1 types :\n" << dictionaryConstructorTablePtr_->sortedToc() << nl << exit(FatalIOError); } @@ -128,9 +137,7 @@ Foam::autoPtr<Foam::PatchFunction1<Type>> Foam::PatchFunction1<Type>::New pp, modelType, entryName, - dict.found(entryName + "Coeffs") - ? dict.subDict(entryName + "Coeffs") - : dict, + dict.optionalSubDict(entryName + "Coeffs"), faceValues ); }