BUG: questionable findInstance handling of constant (related to #1112)

- when searching for a file that may not actually exist,
  the short-cut optimization could lead to the 'constant' directory
  being ignored.

STYLE: simplify logic in points0MotionSolver::points0IO
This commit is contained in:
Mark Olesen
2019-07-05 11:04:06 +02:00
committed by Andrew Heather
parent 79bf4fafb6
commit eaacf0a20a
2 changed files with 28 additions and 56 deletions

View File

@ -757,8 +757,8 @@ Foam::IOobject Foam::fileOperation::findInstance
return io; return io;
} }
// Search back through the time directories to find the time // Search back through the time directories to find the first time
// closest to and lower than current time // that is less than or equal to the current time
instantList ts = time.times(); instantList ts = time.times();
label instanceI = ts.size()-1; label instanceI = ts.size()-1;
@ -771,20 +771,21 @@ Foam::IOobject Foam::fileOperation::findInstance
} }
} }
// Continue searching from here // Found the time, continue from here
for (; instanceI >= 0; --instanceI) for (; instanceI >= 0; --instanceI)
{ {
io.instance() = ts[instanceI].name();
// Shortcut: if actual directory is the timeName we've already tested it // Shortcut: if actual directory is the timeName we've already tested it
if if
( (
ts[instanceI].name() == startIO.instance() io.instance() == startIO.instance()
&& ts[instanceI].name() != stopInstance && io.instance() != stopInstance
) )
{ {
continue; continue;
} }
io.instance() = ts[instanceI].name();
if (exists(io)) if (exists(io))
{ {
DebugInFunction DebugInFunction
@ -796,7 +797,7 @@ Foam::IOobject Foam::fileOperation::findInstance
} }
// Check if hit minimum instance // Check if hit minimum instance
if (ts[instanceI].name() == stopInstance) if (io.instance() == stopInstance)
{ {
DebugInFunction DebugInFunction
<< "Hit stopInstance " << stopInstance << endl; << "Hit stopInstance " << stopInstance << endl;

View File

@ -48,26 +48,6 @@ Foam::IOobject Foam::points0MotionSolver::points0IO(const polyMesh& mesh)
IOobject::READ_IF_PRESENT IOobject::READ_IF_PRESENT
); );
if (instance != mesh.time().constant())
{
// points0 written to a time folder
return
IOobject
(
"points0",
instance,
polyMesh::meshSubDir,
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
);
}
else
{
// Check that points0 are actually in constant directory
IOobject io IOobject io
( (
"points0", "points0",
@ -79,27 +59,18 @@ Foam::IOobject Foam::points0MotionSolver::points0IO(const polyMesh& mesh)
false false
); );
if (io.typeHeaderOk<pointIOField>()) // If points0 are located in constant directory, verify their existence
{ // or fallback to a copy of the original mesh points
return io; if
}
else
{
// Copy of original mesh points
return
IOobject
( (
"points", instance == mesh.time().constant()
instance, && !io.typeHeaderOk<pointIOField>()
polyMesh::meshSubDir, )
mesh, {
IOobject::MUST_READ, io.rename("points");
IOobject::NO_WRITE,
false
);
}
} }
return io;
} }