ENH: Field - read error if insufficient values provided, but allow if more are available

This commit is contained in:
Andrew Heather
2018-01-12 14:19:46 +00:00
parent eedb266c72
commit a2762d16fa
3 changed files with 28 additions and 11 deletions

View File

@ -198,22 +198,35 @@ Foam::Field<Type>::Field
else if (firstToken.wordToken() == "nonuniform")
{
is >> static_cast<List<Type>&>(*this);
if (this->size() != len)
label currentSize = this->size();
if (currentSize != len)
{
FatalIOErrorInFunction
(
dict
) << "size " << this->size()
<< " is not equal to the given value of " << len
<< exit(FatalIOError);
if (len < currentSize && allowConstructFromLargerSize)
{
#ifdef FULLDEBUG
IOWarningInFunction(dict)
<< "Sizes do not match. "
<< "Re-sizing " << currentSize
<< " entries to " << len
<< endl;
#endif
// Resize the data
this->setSize(len);
}
else
{
FatalIOErrorInFunction(dict)
<< "size " << this->size()
<< " is not equal to the given value of " << len
<< exit(FatalIOError);
}
}
}
else
{
FatalIOErrorInFunction
(
dict
) << "expected keyword 'uniform' or 'nonuniform', found "
FatalIOErrorInFunction(dict)
<< "expected keyword 'uniform' or 'nonuniform', found "
<< firstToken.wordToken()
<< exit(FatalIOError);
}

View File

@ -29,5 +29,7 @@ License
const char* const Foam::FieldBase::typeName("Field");
bool Foam::FieldBase::allowConstructFromLargerSize = false;
// ************************************************************************* //

View File

@ -57,6 +57,8 @@ public:
//- Typename for Field
static const char* const typeName;
static bool allowConstructFromLargerSize;
// Constructors