diff --git a/src/OpenFOAM/db/Time/Time.H b/src/OpenFOAM/db/Time/Time.H index 2d5391990e69f204c58c3a3d1c0445ffee91cc2d..4d3268423de30a2f30dd6cf09c458c22b514bf94 100644 --- a/src/OpenFOAM/db/Time/Time.H +++ b/src/OpenFOAM/db/Time/Time.H @@ -283,10 +283,11 @@ public: //- Return the location of "dir" containing the file "name". // (Used in reading mesh data) + // If name is null search for a directory "dir" word findInstance ( const fileName& dir, - const word& name, + const word& name = word::null, const IOobject::readOption rOpt = IOobject::MUST_READ ) const; diff --git a/src/OpenFOAM/db/Time/findInstance.C b/src/OpenFOAM/db/Time/findInstance.C index 348ad4ebe55536b0c732415c56a2f06749ba0ca0..7b8bddd12029c38396f43e26ee4c3e3545725b25 100644 --- a/src/OpenFOAM/db/Time/findInstance.C +++ b/src/OpenFOAM/db/Time/findInstance.C @@ -23,7 +23,9 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Description - Return the location of "directory" containing the file "name". + If "name" is empty: return the location of "directory" + If "name" is not empty: return the location of "directory" containing the + file "name". Used in reading mesh data. \*---------------------------------------------------------------------------*/ @@ -43,15 +45,20 @@ Foam::word Foam::Time::findInstance // Is the mesh data in the current time directory ? if ( - file(path()/timeName()/dir/name) - && IOobject(name, timeName(), dir, *this).headerOk() + (name.empty() && Foam::dir(path()/timeName()/dir)) + || + ( + !name.empty() + && file(path()/timeName()/dir/name) + && IOobject(name, timeName(), dir, *this).headerOk() + ) ) { if (debug) { - Info<< "Time::findInstance(const word& dir, const word& name) : " - << "reading " << name - << " from " << timeName()/dir + Info<< "Time::findInstance(const word&, const word&) : " + << "found " << name + << " in " << timeName()/dir << endl; } @@ -81,16 +88,21 @@ Foam::word Foam::Time::findInstance { if ( - file(path()/ts[j].name()/dir/name) - && IOobject(name, ts[j].name(), dir, *this).headerOk() + (name.empty() && Foam::dir(path()/ts[j].name()/dir)) + || + ( + !name.empty() + && file(path()/ts[j].name()/dir/name) + && IOobject(name, ts[j].name(), dir, *this).headerOk() + ) ) { if (debug) { - Info<< "Time::findInstance(const word& dir, " - << "const word& name) : " - << "reading " << name - << " from " << ts[j].name()/dir + Info<< "Time::findInstance(const word&, " + << "const word&) : " + << "found " << name + << " in " << ts[j].name()/dir << endl; } @@ -109,16 +121,20 @@ Foam::word Foam::Time::findInstance if ( - file(path()/constant()/dir/name) - && IOobject(name, constant(), dir, *this).headerOk() + (name.empty() && Foam::dir(path()/constant()/dir)) + || ( + !name.empty() + && file(path()/constant()/dir/name) + && IOobject(name, constant(), dir, *this).headerOk() + ) ) { if (debug) { - Info<< "Time::findInstance(const word& dir, " - << "const word& name) : " - << "reading " << name - << " from " << constant()/dir + Info<< "Time::findInstance(const word&, " + << "const word&) : " + << "found " << name + << " in " << constant()/dir << endl; } @@ -127,7 +143,7 @@ Foam::word Foam::Time::findInstance if (rOpt == IOobject::MUST_READ) { - FatalErrorIn("Time::findInstance(const word& dir, const word& name)") + FatalErrorIn("Time::findInstance(const word&, const word&)") << "Cannot find file \"" << name << "\" in directory " << constant()/dir << exit(FatalError); @@ -136,4 +152,5 @@ Foam::word Foam::Time::findInstance return constant(); } + // ************************************************************************* //