diff --git a/src/meshTools/searchableSurface/triSurfaceMesh.C b/src/meshTools/searchableSurface/triSurfaceMesh.C index e9680b3f8..a5dcb18c8 100644 --- a/src/meshTools/searchableSurface/triSurfaceMesh.C +++ b/src/meshTools/searchableSurface/triSurfaceMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -35,81 +35,58 @@ License namespace Foam { - -defineTypeNameAndDebug(triSurfaceMesh, 0); -addToRunTimeSelectionTable(searchableSurface, triSurfaceMesh, dict); - + defineTypeNameAndDebug(triSurfaceMesh, 0); + addToRunTimeSelectionTable(searchableSurface, triSurfaceMesh, dict); } // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -//// Special version of Time::findInstance that does not check headerOk -//// to search for instances of raw files -//Foam::word Foam::triSurfaceMesh::findRawInstance -//( -// const Time& runTime, -// const fileName& dir, -// const word& name -//) -//{ -// // Check current time first -// if (isFile(runTime.path()/runTime.timeName()/dir/name)) -// { -// return runTime.timeName(); -// } -// instantList ts = runTime.times(); -// label instanceI; -// -// for (instanceI = ts.size()-1; instanceI >= 0; --instanceI) -// { -// if (ts[instanceI].value() <= runTime.timeOutputValue()) -// { -// break; -// } -// } -// -// // continue searching from here -// for (; instanceI >= 0; --instanceI) -// { -// if (isFile(runTime.path()/ts[instanceI].name()/dir/name)) -// { -// return ts[instanceI].name(); -// } -// } -// -// -// // not in any of the time directories, try constant -// -// // Note. This needs to be a hard-coded constant, rather than the -// // constant function of the time, because the latter points to -// // the case constant directory in parallel cases -// -// if (isFile(runTime.path()/runTime.constant()/dir/name)) -// { -// return runTime.constant(); -// } -// -// FatalErrorInFunction -// << "Cannot find file \"" << name << "\" in directory " -// << runTime.constant()/dir -// << exit(FatalError); -// -// return runTime.constant(); -//} - - -const Foam::fileName& Foam::triSurfaceMesh::checkFile -( - const fileName& fName, - const fileName& objectName -) +Foam::fileName Foam::triSurfaceMesh::checkFile(const IOobject& io) { + const fileName fName(io.filePath()); if (fName.empty()) { FatalErrorInFunction << "Cannot find triSurfaceMesh starting from " - << objectName << exit(FatalError); + << io.objectPath() << exit(FatalError); } + + return fName; +} + + +Foam::fileName Foam::triSurfaceMesh::checkFile +( + const IOobject& io, + const dictionary& dict +) +{ + fileName fName; + if (dict.readIfPresent("file", fName, false, false)) + { + fName.expand(); + if (!fName.isAbsolute()) + { + fName = io.objectPath().path()/fName; + } + if (!exists(fName)) + { + FatalErrorInFunction + << "Cannot find triSurfaceMesh at " << fName + << exit(FatalError); + } + } + else + { + fName = io.filePath(); + if (!exists(fName)) + { + FatalErrorInFunction + << "Cannot find triSurfaceMesh starting from " + << io.objectPath() << exit(FatalError); + } + } + return fName; } @@ -247,25 +224,13 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io) : // Find instance for triSurfaceMesh searchableSurface(io), - //( - // IOobject - // ( - // io.name(), - // io.time().findInstance(io.local(), word::null), - // io.local(), - // io.db(), - // io.readOpt(), - // io.writeOpt(), - // io.registerObject() - // ) - //), // Reused found instance in objectRegistry objectRegistry ( IOobject ( io.name(), - static_cast(*this).instance(), + searchableSurface::instance(), io.local(), io.db(), io.readOpt(), @@ -273,14 +238,7 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io) false // searchableSurface already registered under name ) ), - triSurface - ( - checkFile - ( - searchableSurface::filePath(), - searchableSurface::objectPath() - ) - ), + triSurface(checkFile(static_cast(*this))), triSurfaceRegionSearch(static_cast(*this)), minQuality_(-1), surfaceClosed_(-1) @@ -298,25 +256,13 @@ Foam::triSurfaceMesh::triSurfaceMesh ) : searchableSurface(io), - //( - // IOobject - // ( - // io.name(), - // io.time().findInstance(io.local(), word::null), - // io.local(), - // io.db(), - // io.readOpt(), - // io.writeOpt(), - // io.registerObject() - // ) - //), // Reused found instance in objectRegistry objectRegistry ( IOobject ( io.name(), - static_cast(*this).instance(), + searchableSurface::instance(), io.local(), io.db(), io.readOpt(), @@ -324,21 +270,17 @@ Foam::triSurfaceMesh::triSurfaceMesh false // searchableSurface already registered under name ) ), - triSurface - ( - checkFile - ( - searchableSurface::filePath(), - searchableSurface::objectPath() - ) - ), + triSurface(checkFile(static_cast(*this), dict)), triSurfaceRegionSearch(static_cast(*this), dict), minQuality_(-1), surfaceClosed_(-1) { + // Reading from supplied file name instead of objectPath/filePath + dict.readIfPresent("file", fName_, false, false); + scalar scaleFactor = 0; - // allow rescaling of the surface points + // Allow rescaling of the surface points // eg, CAD geometries are often done in millimeters if (dict.readIfPresent("scale", scaleFactor) && scaleFactor > 0) { @@ -470,7 +412,7 @@ Foam::triSurfaceMesh::edgeTree() const label nPoints; PatchTools::calcBounds ( - static_cast(*this), + *this, bb, nPoints ); @@ -501,7 +443,7 @@ Foam::triSurfaceMesh::edgeTree() const bEdges // selected edges ), bb, // bb - maxTreeDepth(), // maxLevel + maxTreeDepth(), // maxLevel 10, // leafsize 3.0 // duplicity ) @@ -527,7 +469,6 @@ const Foam::wordList& Foam::triSurfaceMesh::regions() const } -// Find out if surface is closed. bool Foam::triSurfaceMesh::hasVolumeType() const { if (surfaceClosed_ == -1) @@ -635,7 +576,7 @@ void Foam::triSurfaceMesh::getNormal vectorField& normal ) const { - const triSurface& s = static_cast(*this); + const triSurface& s = *this; const pointField& pts = s.points(); normal.setSize(info.size()); @@ -796,7 +737,24 @@ bool Foam::triSurfaceMesh::writeObject IOstream::compressionType cmp ) const { - fileName fullPath(searchableSurface::objectPath()); + fileName fullPath; + if (fName_.size()) + { + // Override file name + + fullPath = fName_; + + fullPath.expand(); + if (!fullPath.isAbsolute()) + { + // Add directory from regIOobject + fullPath = searchableSurface::objectPath().path()/fullPath; + } + } + else + { + fullPath = searchableSurface::objectPath(); + } if (!mkDir(fullPath.path())) { diff --git a/src/meshTools/searchableSurface/triSurfaceMesh.H b/src/meshTools/searchableSurface/triSurfaceMesh.H index fe512f67a..9f3ea6d0a 100644 --- a/src/meshTools/searchableSurface/triSurfaceMesh.H +++ b/src/meshTools/searchableSurface/triSurfaceMesh.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -68,10 +68,11 @@ class triSurfaceMesh public triSurface, public triSurfaceRegionSearch { -private: - // Private member data + //- Supplied fileName override + fileName fName_; + //- Optional min triangle quality. Triangles below this get // ignored for normal calculation scalar minQuality_; @@ -88,20 +89,11 @@ private: // Private Member Functions - ////- Helper: find instance of files without header - //static word findRawInstance - //( - // const Time&, - // const fileName&, - // const word& - //); + //- Return fileName to load IOobject from + static fileName checkFile(const IOobject& io); - //- Check file existence - static const fileName& checkFile - ( - const fileName& fName, - const fileName& objectName - ); + //- Return fileName to load IOobject from. Optional override of fileName + static fileName checkFile(const IOobject&, const dictionary&); //- Helper function for isSurfaceClosed static bool addFaceToEdge