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)
This commit is contained in:
Mark Olesen
2019-06-04 15:04:09 +02:00
committed by Andrew Heather
parent b65a6d32f5
commit 298cb46572

View File

@ -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() Foam::fileName Foam::surfaceWriters::ensightWriter::writeCollated()
{ {
@ -119,22 +154,18 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeCollated
dict.readIfPresent("meshes", meshes); dict.readIfPresent("meshes", meshes);
dict.readIfPresent("times", times); dict.readIfPresent("times", times);
timeIndex = 1+findLower(times, timeValue); timeIndex = findTimeIndex(times, timeValue);
if (meshChanged) if (meshChanged)
{ {
meshValue = timeValue; meshValue = timeValue;
meshIndex = 1+findLower(meshes, meshValue); meshIndex = findTimeIndex(meshes, meshValue);
} }
else if (meshes.size()) else if (meshes.size())
{ {
meshIndex = meshes.size()-1; meshIndex = meshes.size()-1;
meshValue = meshes.last(); meshValue = meshes.last();
} }
else
{
meshIndex = 0;
}
} }
} }
@ -142,11 +173,11 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeCollated
meshes.resize(meshIndex+1, -1); meshes.resize(meshIndex+1, -1);
times.resize(timeIndex+1, -1); times.resize(timeIndex+1, -1);
if (meshes[meshIndex] != meshValue) if
{ (
stateChanged = true; !equalTimes(meshes[meshIndex], meshValue)
} || !equalTimes(times[timeIndex], timeValue)
if (times[timeIndex] != timeValue) )
{ {
stateChanged = true; stateChanged = true;
} }