diff --git a/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C b/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C index 64af5e5298dcbc3ff62787c7e43c9cd0eea09369..2aff7124af2ad811bbd49150d9c12a8a44a6a453 100644 --- a/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C +++ b/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C @@ -65,9 +65,34 @@ Foam::fileName Foam::triSurfaceMesh::checkFile } +Foam::fileName Foam::triSurfaceMesh::relativeFilePath +( + const regIOobject& io, + const fileName& f, + const bool isGlobal +) +{ + fileName fName(f); + fName.expand(); + if (!fName.isAbsolute()) + { + // Is the specified file: + // - local to the cwd? + // - local to the case dir? + // - or just another name? + fName = fileHandler().filePath + ( + isGlobal, + IOobject(io, fName), + word::null + ); + } + return fName; +} + Foam::fileName Foam::triSurfaceMesh::checkFile ( - const IOobject& io, + const regIOobject& io, const dictionary& dict, const bool isGlobal ) @@ -75,11 +100,8 @@ Foam::fileName Foam::triSurfaceMesh::checkFile fileName fName; if (dict.readIfPresent("file", fName, false, false)) { - fName.expand(); - if (!fName.isAbsolute()) - { - fName = io.objectPath().path()/fName; - } + fName = relativeFilePath(io, fName, isGlobal); + if (!exists(fName)) { FatalErrorInFunction @@ -299,7 +321,15 @@ Foam::triSurfaceMesh::triSurfaceMesh outsideVolType_(volumeType::UNKNOWN) { // Reading from supplied file name instead of objectPath/filePath - dict.readIfPresent("file", fName_, false, false); + if (dict.readIfPresent("file", fName_, false, false)) + { + fName_ = relativeFilePath + ( + static_cast<const searchableSurface&>(*this), + fName_, + true + ); + } scalar scaleFactor = 0; @@ -391,7 +421,15 @@ Foam::triSurfaceMesh::triSurfaceMesh outsideVolType_(volumeType::UNKNOWN) { // Reading from supplied file name instead of objectPath/filePath - dict.readIfPresent("file", fName_, false, false); + if (dict.readIfPresent("file", fName_, false, false)) + { + fName_ = relativeFilePath + ( + static_cast<const searchableSurface&>(*this), + fName_, + isGlobal + ); + } scalar scaleFactor = 0; diff --git a/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.H b/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.H index d35abbad2ebf98b26aa631f9aee7a227fe7bf952..110ee7944b29bb1a71696612e4899bd58b5a15d1 100644 --- a/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.H +++ b/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.H @@ -95,10 +95,19 @@ class triSurfaceMesh //- Return fileName to load IOobject from static fileName checkFile(const IOobject& io, const bool isGlobal); + //- Return fileName. If fileName is relative gets treated local to + // IOobject + static fileName relativeFilePath + ( + const regIOobject&, + const fileName&, + const bool isGlobal + ); + //- Return fileName to load IOobject from. Optional override of fileName static fileName checkFile ( - const IOobject&, + const regIOobject&, const dictionary&, const bool isGlobal );