static label Time::findClosestTimeIndex(const instantList&, const scalar)

- avoid code duplication in vtkPV3Foam.C and checkTimeOption.H
  - can also be used in Time::findClosestTime(), but didn't touch that
This commit is contained in:
Mark Olesen
2008-07-25 15:37:38 +02:00
parent 8a2596a05c
commit 3cdc8ca03c
6 changed files with 54 additions and 62 deletions

View File

@ -183,24 +183,10 @@ bool Foam::vtkPV3Foam::setTime(const double& requestedTime)
Time& runTime = dbPtr_();
// Get times list
instantList times = runTime.times();
instantList Times = runTime.times();
// logic as per "checkTimeOption.H"
bool found = false;
int nearestIndex = -1;
scalar nearestDiff = Foam::GREAT;
forAll (times, timeIndex)
{
if (times[timeIndex].name() == "constant") continue;
scalar diff = fabs(times[timeIndex].value() - requestedTime);
if (diff < nearestDiff)
{
nearestDiff = diff;
nearestIndex = timeIndex;
}
}
int nearestIndex = Time::findClosestTimeIndex(Times, requestedTime);
if (nearestIndex == -1)
{
@ -212,12 +198,12 @@ bool Foam::vtkPV3Foam::setTime(const double& requestedTime)
found = true;
}
runTime.setTime(times[nearestIndex], nearestIndex);
runTime.setTime(Times[nearestIndex], nearestIndex);
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::setTime() - selected time "
<< times[nearestIndex].name() << endl;
<< Times[nearestIndex].name() << endl;
}
return found;