Commit 8f1bad1c authored by Mark OLESEN's avatar Mark OLESEN
Browse files

BUG: decomposing ConstantField loses information (#2101)

- previously had a patch-size check, which caused a zero-sized patch
  to be "sticky" as uniform Zero regardless of what the original input
  stated (eg, "constant 0.5")

  This was caused by short-circuiting logic that circumvented reading
  on zero-size patches.
parent 10dd0d34
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -91,74 +91,74 @@ Foam::PatchFunction1Types::ConstantField<Type>::getValue
Field<Type> fld;
if (len)
if (!eptr || !eptr->isStream())
{
if (!eptr || !eptr->isStream())
FatalIOErrorInFunction(dict)
<< "Null or invalid entry" << nl
<< exit(FatalIOError);
}
ITstream& is = eptr->stream();
if (is.peek().isWord())
{
const word contentType(is);
if (contentType == "constant" || contentType == "uniform")
{
FatalIOErrorInFunction(dict)
<< "Null or invalid entry" << nl
<< exit(FatalIOError);
is >> uniformValue;
fld.resize(len);
fld = uniformValue;
}
ITstream& is = eptr->stream();
if (is.peek().isWord())
else if (contentType == "nonuniform")
{
const word contentType(is);
if (contentType == "uniform" || contentType == "constant")
if (len)
{
is >> uniformValue;
fld.resize(len);
fld = uniformValue;
isUniform = false;
}
else if (contentType == "nonuniform")
is >> static_cast<List<Type>&>(fld);
const label lenRead = fld.size();
if (len != lenRead)
{
isUniform = false;
is >> static_cast<List<Type>&>(fld);
const label lenRead = fld.size();
if (len != lenRead)
if
(
len < lenRead
&& FieldBase::allowConstructFromLargerSize
)
{
if
(
len < lenRead
&& FieldBase::allowConstructFromLargerSize
)
{
#ifdef FULLDEBUG
IOWarningInFunction(dict)
<< "Sizes do not match. Truncating " << lenRead
<< " entries to " << len << endl;
#endif
// Truncate the data
fld.resize(len);
}
else
{
FatalIOErrorInFunction(dict)
<< "size " << lenRead
<< " is not equal to the expected length " << len
<< exit(FatalIOError);
}
#ifdef FULLDEBUG
IOWarningInFunction(dict)
<< "Sizes do not match. Truncating " << lenRead
<< " entries to " << len << endl;
#endif
// Truncate the data
fld.resize(len);
}
else
{
FatalIOErrorInFunction(dict)
<< "size " << lenRead
<< " is not equal to the expected length " << len
<< exit(FatalIOError);
}
}
else
{
isUniform = false;
FatalIOErrorInFunction(dict)
<< "Expected keyword 'uniform', 'nonuniform' or 'constant'"
<< ", found " << contentType
<< exit(FatalIOError);
}
}
else
{
// Uniform (constant) field
is >> uniformValue;
fld.resize(len);
fld = uniformValue;
FatalIOErrorInFunction(dict)
<< "Expected keyword 'constant', 'uniform', or 'nonuniform'"
<< ", found " << contentType
<< exit(FatalIOError);
}
}
else
{
// Uniform (constant) field
is >> uniformValue;
fld.resize(len);
fld = uniformValue;
}
return fld;
}
......
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