Commit 298cb465 authored by Mark OLESEN's avatar Mark OLESEN Committed by Andrew Heather
Browse files

BUG: fix spurious time indexing in collated ensight output (#1333)

- need additional tolerance when comparing time values to those
  stored in the fieldDict (both less and equal operators)
parent b65a6d32
......@@ -25,7 +25,42 @@ License
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
{
// Compare time values with tolerance
static const equalOp<scalar> equalTimes(ROOTSMALL);
// Use ListOps findLower (with tolerance), to find the location of the next
// time-related index.
static label findTimeIndex(const UList<scalar>& list, const scalar val)
{
label idx =
findLower
(
list,
val,
0,
[](const scalar a, const scalar b)
{
return (a < b) && (Foam::mag(b - a) > ROOTSMALL);
}
);
if (idx < 0 || !equalTimes(list[idx], val))
{
++idx;
}
return idx;
}
} // End namespace Foam
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::fileName Foam::surfaceWriters::ensightWriter::writeCollated()
{
......@@ -119,22 +154,18 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeCollated
dict.readIfPresent("meshes", meshes);
dict.readIfPresent("times", times);
timeIndex = 1+findLower(times, timeValue);
timeIndex = findTimeIndex(times, timeValue);
if (meshChanged)
{
meshValue = timeValue;
meshIndex = 1+findLower(meshes, meshValue);
meshIndex = findTimeIndex(meshes, meshValue);
}
else if (meshes.size())
{
meshIndex = meshes.size()-1;
meshValue = meshes.last();
}
else
{
meshIndex = 0;
}
}
}
......@@ -142,11 +173,11 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeCollated
meshes.resize(meshIndex+1, -1);
times.resize(timeIndex+1, -1);
if (meshes[meshIndex] != meshValue)
{
stateChanged = true;
}
if (times[timeIndex] != timeValue)
if
(
!equalTimes(meshes[meshIndex], meshValue)
|| !equalTimes(times[timeIndex], timeValue)
)
{
stateChanged = true;
}
......
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