diff --git a/src/meshTools/searchableSurface/triSurfaceMesh.C b/src/meshTools/searchableSurface/triSurfaceMesh.C index 7b6b8ad6ad..4dfa21fd25 100644 --- a/src/meshTools/searchableSurface/triSurfaceMesh.C +++ b/src/meshTools/searchableSurface/triSurfaceMesh.C @@ -2,8 +2,8 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation - \\/ M anipulation | + \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -39,6 +39,8 @@ namespace Foam defineTypeNameAndDebug(triSurfaceMesh, 0); addToRunTimeSelectionTable(searchableSurface, triSurfaceMesh, dict); +word triSurfaceMesh::meshSubDir = "triSurface"; + } // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -231,7 +233,7 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io, const triSurface& s) ( io.name(), io.instance(), - io.local(), + io.local(), //"triSurfaceFields", io.db(), io.readOpt(), io.writeOpt(), @@ -239,9 +241,10 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io, const triSurface& s) ) ), triSurface(s), - triSurfaceRegionSearch(s), + triSurfaceRegionSearch(static_cast(*this)), minQuality_(-1), - surfaceClosed_(-1) + surfaceClosed_(-1), + outsideVolType_(volumeType::UNKNOWN) { const pointField& pts = triSurface::points(); @@ -272,7 +275,7 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io) ( io.name(), static_cast(*this).instance(), - io.local(), + io.local(), //"triSurfaceFields", io.db(), io.readOpt(), io.writeOpt(), @@ -289,7 +292,8 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io) ), triSurfaceRegionSearch(static_cast(*this)), minQuality_(-1), - surfaceClosed_(-1) + surfaceClosed_(-1), + outsideVolType_(volumeType::UNKNOWN) { const pointField& pts = triSurface::points(); @@ -323,7 +327,7 @@ Foam::triSurfaceMesh::triSurfaceMesh ( io.name(), static_cast(*this).instance(), - io.local(), + io.local(), //"triSurfaceFields", io.db(), io.readOpt(), io.writeOpt(), @@ -340,7 +344,8 @@ Foam::triSurfaceMesh::triSurfaceMesh ), triSurfaceRegionSearch(static_cast(*this), dict), minQuality_(-1), - surfaceClosed_(-1) + surfaceClosed_(-1), + outsideVolType_(volumeType::UNKNOWN) { scalar scaleFactor = 0; @@ -377,6 +382,7 @@ Foam::triSurfaceMesh::~triSurfaceMesh() void Foam::triSurfaceMesh::clearOut() { + outsideVolType_ = volumeType::UNKNOWN; triSurfaceRegionSearch::clearOut(); edgeTree_.clear(); triSurface::clearOut(); @@ -447,9 +453,22 @@ bool Foam::triSurfaceMesh::overlaps(const boundBox& bb) const void Foam::triSurfaceMesh::movePoints(const pointField& newPoints) { + outsideVolType_ = volumeType::UNKNOWN; + + // Update local information (instance, event number) + searchableSurface::instance() = objectRegistry::time().timeName(); + objectRegistry::instance() = searchableSurface::instance(); + + label event = getEvent(); + searchableSurface::eventNo() = event; + objectRegistry::eventNo() = searchableSurface::eventNo(); + + // Clear additional addressing triSurfaceRegionSearch::clearOut(); edgeTree_.clear(); triSurface::movePoints(newPoints); + + bounds() = boundBox(triSurface::points()); } @@ -714,27 +733,41 @@ void Foam::triSurfaceMesh::getNormal void Foam::triSurfaceMesh::setField(const labelList& values) { - autoPtr fldPtr - ( - new triSurfaceLabelField + if (foundObject("values")) + { + triSurfaceLabelField& fld = const_cast ( - IOobject + lookupObject ( - "values", - objectRegistry::time().timeName(), // instance - "triSurface", // local + "values" + ) + ); + fld.field() = values; + } + else + { + autoPtr fldPtr + ( + new triSurfaceLabelField + ( + IOobject + ( + "values", + objectRegistry::time().timeName(), // instance + meshSubDir, // local + *this, + IOobject::NO_READ, + IOobject::AUTO_WRITE + ), *this, - IOobject::NO_READ, - IOobject::AUTO_WRITE - ), - *this, - dimless, - labelField(values) - ) - ); + dimless, + labelField(values) + ) + ); - // Store field on triMesh - fldPtr.ptr()->store(); + // Store field on triMesh + fldPtr.ptr()->store(); + } } @@ -781,17 +814,26 @@ void Foam::triSurfaceMesh::getVolumeType if (!tree().bb().contains(pt)) { - // Have to calculate directly as outside the octree - volType[pointI] = tree().shapes().getVolumeType(tree(), pt); + if (hasVolumeType()) + { + // Precalculate and cache value for this outside point + if (outsideVolType_ == volumeType::UNKNOWN) + { + outsideVolType_ = tree().shapes().getVolumeType(tree(), pt); + } + volType[pointI] = outsideVolType_; + } + else + { + // Have to calculate directly as outside the octree + volType[pointI] = tree().shapes().getVolumeType(tree(), pt); + } } else { // - use cached volume type per each tree node volType[pointI] = tree().getVolumeType(pt); } - -// Info<< "octree : " << pt << " = " -// << volumeType::names[volType[pointI]] << endl; } indexedOctree::perturbTol() = oldTol; @@ -806,6 +848,24 @@ bool Foam::triSurfaceMesh::writeObject IOstream::compressionType cmp ) const { + const Time& runTime = searchableSurface::time(); + const fileName& instance = searchableSurface::instance(); + + if + ( + instance != runTime.timeName() + && instance != runTime.system() + && instance != runTime.caseSystem() + && instance != runTime.constant() + && instance != runTime.caseConstant() + ) + { + const_cast(*this).searchableSurface::instance() = + runTime.timeName(); + const_cast(*this).objectRegistry::instance() = + runTime.timeName(); + } + fileName fullPath(searchableSurface::objectPath()); if (!mkDir(fullPath.path())) diff --git a/src/meshTools/searchableSurface/triSurfaceMesh.H b/src/meshTools/searchableSurface/triSurfaceMesh.H index 5751ead958..0841ce8887 100644 --- a/src/meshTools/searchableSurface/triSurfaceMesh.H +++ b/src/meshTools/searchableSurface/triSurfaceMesh.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -85,6 +85,9 @@ private: //- Is surface closed mutable label surfaceClosed_; + //- If surface is closed, what is type of outside points + mutable volumeType outsideVolType_; + // Private Member Functions @@ -137,6 +140,9 @@ public: //- Runtime type information TypeName("triSurfaceMesh"); + //- Return the mesh sub-directory name (usually "triSurface") + static word meshSubDir; + // Constructors