diff --git a/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C b/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C index 3db3cb4159..75e7515fbb 100644 --- a/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C +++ b/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C @@ -47,97 +47,6 @@ Foam::word Foam::triSurfaceMesh::meshSubDir = "triSurface"; // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -Foam::fileName Foam::triSurfaceMesh::checkFile -( - const IOobject& io, - const bool isGlobal -) -{ - const fileName fName - ( - isGlobal - ? io.globalFilePath(typeName) - : io.localFilePath(typeName) - ); - if (fName.empty()) - { - FatalErrorInFunction - << "Cannot find triSurfaceMesh starting from " - << io.objectPath() << exit(FatalError); - } - - return fName; -} - - -Foam::fileName Foam::triSurfaceMesh::relativeFilePath -( - const IOobject& 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 dictionary& dict, - const bool isGlobal -) -{ - fileName fName; - if (dict.readIfPresent("file", fName, keyType::LITERAL)) - { - const fileName rawFName(fName); - - fName = relativeFilePath(io, rawFName, isGlobal); - - if (!exists(fName)) - { - FatalErrorInFunction - << "Cannot find triSurfaceMesh " << rawFName - << " starting from " << io.objectPath() - << exit(FatalError); - } - } - else - { - fName = - ( - isGlobal - ? io.globalFilePath(typeName) - : io.localFilePath(typeName) - ); - - if (!exists(fName)) - { - FatalErrorInFunction - << "Cannot find triSurfaceMesh starting from " - << io.objectPath() << exit(FatalError); - } - } - - return fName; -} - - bool Foam::triSurfaceMesh::addFaceToEdge ( const edge& e, @@ -308,7 +217,7 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io) false // searchableSurface already registered under name ) ), - triSurface(checkFile(static_cast(*this), true)), + triSurface(static_cast(*this), dictionary::null), triSurfaceRegionSearch(static_cast(*this)), minQuality_(-1), surfaceClosed_(-1), @@ -341,19 +250,16 @@ Foam::triSurfaceMesh::triSurfaceMesh false // searchableSurface already registered under name ) ), - triSurface - ( - checkFile(static_cast(*this), dict, true) - ), + triSurface(static_cast(*this), dict), triSurfaceRegionSearch(static_cast(*this), dict), minQuality_(-1), surfaceClosed_(-1), outsideVolType_(volumeType::UNKNOWN) { - // Reading from supplied file name instead of objectPath/filePath + // Adjust to use supplied file name instead of objectPath/filePath if (dict.readIfPresent("file", fName_, keyType::LITERAL)) { - fName_ = relativeFilePath + fName_ = triSurface::relativeFilePath ( static_cast(*this), fName_, @@ -404,7 +310,7 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io, const readAction r) false // searchableSurface already registered under name ) ), - triSurface(), // construct null + triSurface(), triSurfaceRegionSearch(static_cast(*this)), minQuality_(-1), surfaceClosed_(-1), @@ -502,7 +408,7 @@ Foam::triSurfaceMesh::triSurfaceMesh false // searchableSurface already registered under name ) ), - triSurface(), // construct null + triSurface(), triSurfaceRegionSearch(static_cast(*this), dict), minQuality_(-1), surfaceClosed_(-1), diff --git a/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.H b/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.H index 512d5bf230..c3e62014d1 100644 --- a/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.H +++ b/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.H @@ -106,26 +106,6 @@ protected: // Private Member Functions - //- 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 IOobject&, - const fileName&, - const bool isGlobal - ); - - //- Return fileName to load IOobject from. Optional override of fileName - static fileName checkFile - ( - const IOobject&, - const dictionary&, - const bool isGlobal - ); - //- Helper function for isSurfaceClosed static bool addFaceToEdge ( diff --git a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C index dc75f2f80c..f0b9d40294 100644 --- a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C +++ b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C @@ -2557,7 +2557,7 @@ Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh(const IOobject& io) bounds().reduce(); - const fileName actualFile(checkFile(io, true)); + const fileName actualFile(triSurfaceMesh::checkFile(io, true)); if ( @@ -2697,7 +2697,7 @@ Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh bounds().reduce(); - const fileName actualFile(checkFile(io, dict, true)); + const fileName actualFile(triSurfaceMesh::checkFile(io, dict, true)); if ( diff --git a/src/sampling/sampledSet/triSurfaceMeshPointSet/triSurfaceMeshPointSet.C b/src/sampling/sampledSet/triSurfaceMeshPointSet/triSurfaceMeshPointSet.C index 685d192af6..9e7975f40d 100644 --- a/src/sampling/sampledSet/triSurfaceMeshPointSet/triSurfaceMeshPointSet.C +++ b/src/sampling/sampledSet/triSurfaceMeshPointSet/triSurfaceMeshPointSet.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -121,32 +122,34 @@ Foam::triSurfaceMeshPointSet::triSurfaceMeshPointSet ) : sampledSet(name, mesh, searchEngine, dict), - surface_(dict.get("surface")) + surfaceName_(dict.get("surface")) { - // Load surface. - if (mesh.time().foundObject(surface_)) + // Get or load surface + + const auto* surfPtr = + mesh.time().cfindObject(surfaceName_); + + if (surfPtr) { // Note: should use localPoints() instead of points() but assume // trisurface is compact. - sampleCoords_ = mesh.time().lookupObject - ( - surface_ - ).points(); + sampleCoords_ = surfPtr->points(); } else { - sampleCoords_ = triSurfaceMesh + sampleCoords_ = triSurface ( IOobject ( - surface_, + surfaceName_, mesh.time().constant(), // instance "triSurface", // local mesh.time(), IOobject::MUST_READ, IOobject::NO_WRITE, false - ) + ), + dictionary::null ).points(); } diff --git a/src/sampling/sampledSet/triSurfaceMeshPointSet/triSurfaceMeshPointSet.H b/src/sampling/sampledSet/triSurfaceMeshPointSet/triSurfaceMeshPointSet.H index 5d34a61fd2..c0aa558000 100644 --- a/src/sampling/sampledSet/triSurfaceMeshPointSet/triSurfaceMeshPointSet.H +++ b/src/sampling/sampledSet/triSurfaceMeshPointSet/triSurfaceMeshPointSet.H @@ -60,10 +60,10 @@ class triSurfaceMeshPointSet : public sampledSet { - // Private data + // Private Data - //- Name of triSurfaceMesh - const word surface_; + //- The surface name + const word surfaceName_; //- Sampling points List sampleCoords_; diff --git a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C index 14181bff0d..f00bca3112 100644 --- a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C +++ b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C @@ -33,7 +33,6 @@ License #include "treeDataCell.H" #include "treeDataFace.H" #include "meshTools.H" - #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -78,8 +77,32 @@ namespace Foam } } }; + +} // End namespace Foam + + +// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // + +namespace Foam +{ + +// The IOobject for reading +inline static IOobject selectReadIO(const word& name, const Time& runTime) +{ + return IOobject + ( + name, + runTime.constant(), // instance + "triSurface", // local + runTime, // registry + IOobject::MUST_READ, + IOobject::NO_WRITE, + false // no register + ); } +} // End namespace Foam + // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // @@ -94,14 +117,14 @@ void Foam::sampledTriSurfaceMesh::setZoneMap { sz += zn.size(); } + zoneIds.resize(sz); - zoneIds.setSize(sz); forAll(zoneLst, zonei) { const surfZone& zn = zoneLst[zonei]; // Assign sub-zone Ids - SubList