From eaacf0a20ad2cbc99c7f4129979f0ae45f6916c4 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 5 Jul 2019 11:04:06 +0200 Subject: [PATCH] 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 --- .../fileOperation/fileOperation.C | 15 ++-- .../points0/points0MotionSolver.C | 69 ++++++------------- 2 files changed, 28 insertions(+), 56 deletions(-) diff --git a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C index 1c4e484d50..6611940880 100644 --- a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C +++ b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C @@ -757,8 +757,8 @@ Foam::IOobject Foam::fileOperation::findInstance return io; } - // Search back through the time directories to find the time - // closest to and lower than current time + // Search back through the time directories to find the first time + // that is less than or equal to the current time instantList ts = time.times(); 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) { + io.instance() = ts[instanceI].name(); + // Shortcut: if actual directory is the timeName we've already tested it if ( - ts[instanceI].name() == startIO.instance() - && ts[instanceI].name() != stopInstance + io.instance() == startIO.instance() + && io.instance() != stopInstance ) { continue; } - io.instance() = ts[instanceI].name(); if (exists(io)) { DebugInFunction @@ -796,7 +797,7 @@ Foam::IOobject Foam::fileOperation::findInstance } // Check if hit minimum instance - if (ts[instanceI].name() == stopInstance) + if (io.instance() == stopInstance) { DebugInFunction << "Hit stopInstance " << stopInstance << endl; diff --git a/src/dynamicMesh/motionSolvers/displacement/points0/points0MotionSolver.C b/src/dynamicMesh/motionSolvers/displacement/points0/points0MotionSolver.C index aafc2afa12..2fedc2355c 100644 --- a/src/dynamicMesh/motionSolvers/displacement/points0/points0MotionSolver.C +++ b/src/dynamicMesh/motionSolvers/displacement/points0/points0MotionSolver.C @@ -48,58 +48,29 @@ Foam::IOobject Foam::points0MotionSolver::points0IO(const polyMesh& mesh) IOobject::READ_IF_PRESENT ); - if (instance != mesh.time().constant()) + IOobject io + ( + "points0", + instance, + polyMesh::meshSubDir, + mesh, + IOobject::MUST_READ, + IOobject::NO_WRITE, + false + ); + + // If points0 are located in constant directory, verify their existence + // or fallback to a copy of the original mesh points + if + ( + instance == mesh.time().constant() + && !io.typeHeaderOk() + ) { - // points0 written to a time folder - - return - IOobject - ( - "points0", - instance, - polyMesh::meshSubDir, - mesh, - IOobject::MUST_READ, - IOobject::NO_WRITE, - false - ); + io.rename("points"); } - else - { - // Check that points0 are actually in constant directory - IOobject io - ( - "points0", - instance, - polyMesh::meshSubDir, - mesh, - IOobject::MUST_READ, - IOobject::NO_WRITE, - false - ); - - if (io.typeHeaderOk()) - { - return io; - } - else - { - // Copy of original mesh points - - return - IOobject - ( - "points", - instance, - polyMesh::meshSubDir, - mesh, - IOobject::MUST_READ, - IOobject::NO_WRITE, - false - ); - } - } + return io; }