ENH: improve findInstance handling for optional files

- previously would always return "constant" as the instance for
  an optional dir/file that wasn't found.
  However, this meant retesting to screen out false positives.
  Now support an additional parameter
      'bool constant_fallback = ...'
  to return "constant" or an empty word.

  The method signature changes slightly with a new optional bool
  parameter:

      //! Return \c "constant" instead of \c "" if the search failed
      const bool constant_fallback = true

ENH: code consolidation for findInstancePath

- relocate from Time to TimePaths and provide an additional static
  version that is reused in fileOperations

BUG: distributedTriSurfaceMesh:::findLocalInstance broken (#3135)

- was not checking the parent at all.

COMP: remove unused findInstancePath(const fileName&, ..) method
This commit is contained in:
Mark Olesen
2024-04-08 15:19:58 +02:00
parent 85771c8985
commit d578d48a4f
12 changed files with 197 additions and 180 deletions

View File

@ -53,46 +53,37 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
#include "createTime.H"
fileName coherentInst;
word coherentInst;
coherentInst =
(
runTime.findInstance
(
polyMesh::meshSubDir,
"coherent",
IOobject::READ_IF_PRESENT
IOobject::READ_IF_PRESENT,
word::null, // No stop instance
false // No "constant" fallback (word::null instead)
)
);
// Unfortunately with READ_IF_PRESENT, cannot tell if the file
// was actually found or not
Info<< "check: " << (coherentInst/polyMesh::meshSubDir/"coherent") << nl;
if (!Foam::isFile(coherentInst/polyMesh::meshSubDir/"coherent"))
{
coherentInst.clear();
}
Info<< "found coherent: " << coherentInst << nl;
Info<< "Found coherent \"" << coherentInst << '"' << nl;
PtrList<entry> entries;
if (!coherentInst.empty())
{
IOdictionary coherent
(
IOobject
dictionary coherent =
IOdictionary::readContents
(
"coherent",
coherentInst,
polyMesh::meshSubDir,
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
IOobject::NO_REGISTER
)
);
IOobject
(
"coherent",
coherentInst,
polyMesh::meshSubDir,
runTime,
IOobject::MUST_READ
)
);
ITstream& is = coherent.lookup("boundary");
is >> entries;
@ -105,7 +96,7 @@ int main(int argc, char *argv[])
Info<< "size: " << polyBoundaryMeshEntries::patchSizes(entries) << nl;
Info<< nl;
fileName boundaryInst;
word boundaryInst;
boundaryInst =
(
runTime.findInstance
@ -116,7 +107,7 @@ int main(int argc, char *argv[])
)
);
Info<< "found boundary: " << boundaryInst << nl;
Info<< "Found boundary: \"" << boundaryInst << '"' << nl;
polyBoundaryMeshEntries pbm
(