From 549337c36766bb0fc9cc40dbf5fad6ae0a0c70ff Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Fri, 14 Jul 2017 12:38:21 +0100 Subject: [PATCH] triSurfaceMesh: corrected parallel operation of 'file' specification Patch contributed by Mattijs Janssens Resolves bug-report https://bugs.openfoam.org/view.php?id=2614 --- .../triSurfaceMesh/triSurfaceMesh.C | 52 ++++++++++++++++--- .../triSurfaceMesh/triSurfaceMesh.H | 9 ++++ 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C b/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C index 6a9f99553..fe1eb04ca 100644 --- a/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C +++ b/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C @@ -64,6 +64,31 @@ 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 regIOobject& io, @@ -74,11 +99,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 @@ -295,7 +317,15 @@ Foam::triSurfaceMesh::triSurfaceMesh surfaceClosed_(-1) { // 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(*this), + fName_, + true + ); + } scalar scaleFactor = 0; @@ -385,7 +415,15 @@ Foam::triSurfaceMesh::triSurfaceMesh surfaceClosed_(-1) { // 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(*this), + fName_, + isGlobal + ); + } scalar scaleFactor = 0; diff --git a/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.H b/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.H index 74dba39e9..338da94ac 100644 --- a/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.H +++ b/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.H @@ -92,6 +92,15 @@ class triSurfaceMesh //- Return fileName to load IOobject from static fileName checkFile(const regIOobject& 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 (