Commit 5e50800e authored by Mark OLESEN's avatar Mark OLESEN Committed by Andrew Heather
Browse files

ENH: improve missing entry message for Function1 or PatchFunction1

- now indicate that the dictionary entry is missing, not that it is
  an unknown function type.
parent 87330972
......@@ -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")
);
}
......
......@@ -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
);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment