BUG: triSurfaceMesh: fix writing to time directory

Also various speed ups to do with getting volume type outside of bounding box.
This commit is contained in:
mattijs
2015-10-14 11:36:35 +01:00
committed by Andrew Heather
parent 06e3b9c4c4
commit f1b22fa163
2 changed files with 98 additions and 32 deletions

View File

@ -2,8 +2,8 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -39,6 +39,8 @@ namespace Foam
defineTypeNameAndDebug(triSurfaceMesh, 0); defineTypeNameAndDebug(triSurfaceMesh, 0);
addToRunTimeSelectionTable(searchableSurface, triSurfaceMesh, dict); addToRunTimeSelectionTable(searchableSurface, triSurfaceMesh, dict);
word triSurfaceMesh::meshSubDir = "triSurface";
} }
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -231,7 +233,7 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io, const triSurface& s)
( (
io.name(), io.name(),
io.instance(), io.instance(),
io.local(), io.local(), //"triSurfaceFields",
io.db(), io.db(),
io.readOpt(), io.readOpt(),
io.writeOpt(), io.writeOpt(),
@ -239,9 +241,10 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io, const triSurface& s)
) )
), ),
triSurface(s), triSurface(s),
triSurfaceRegionSearch(s), triSurfaceRegionSearch(static_cast<const triSurface&>(*this)),
minQuality_(-1), minQuality_(-1),
surfaceClosed_(-1) surfaceClosed_(-1),
outsideVolType_(volumeType::UNKNOWN)
{ {
const pointField& pts = triSurface::points(); const pointField& pts = triSurface::points();
@ -272,7 +275,7 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io)
( (
io.name(), io.name(),
static_cast<const searchableSurface&>(*this).instance(), static_cast<const searchableSurface&>(*this).instance(),
io.local(), io.local(), //"triSurfaceFields",
io.db(), io.db(),
io.readOpt(), io.readOpt(),
io.writeOpt(), io.writeOpt(),
@ -289,7 +292,8 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io)
), ),
triSurfaceRegionSearch(static_cast<const triSurface&>(*this)), triSurfaceRegionSearch(static_cast<const triSurface&>(*this)),
minQuality_(-1), minQuality_(-1),
surfaceClosed_(-1) surfaceClosed_(-1),
outsideVolType_(volumeType::UNKNOWN)
{ {
const pointField& pts = triSurface::points(); const pointField& pts = triSurface::points();
@ -323,7 +327,7 @@ Foam::triSurfaceMesh::triSurfaceMesh
( (
io.name(), io.name(),
static_cast<const searchableSurface&>(*this).instance(), static_cast<const searchableSurface&>(*this).instance(),
io.local(), io.local(), //"triSurfaceFields",
io.db(), io.db(),
io.readOpt(), io.readOpt(),
io.writeOpt(), io.writeOpt(),
@ -340,7 +344,8 @@ Foam::triSurfaceMesh::triSurfaceMesh
), ),
triSurfaceRegionSearch(static_cast<const triSurface&>(*this), dict), triSurfaceRegionSearch(static_cast<const triSurface&>(*this), dict),
minQuality_(-1), minQuality_(-1),
surfaceClosed_(-1) surfaceClosed_(-1),
outsideVolType_(volumeType::UNKNOWN)
{ {
scalar scaleFactor = 0; scalar scaleFactor = 0;
@ -377,6 +382,7 @@ Foam::triSurfaceMesh::~triSurfaceMesh()
void Foam::triSurfaceMesh::clearOut() void Foam::triSurfaceMesh::clearOut()
{ {
outsideVolType_ = volumeType::UNKNOWN;
triSurfaceRegionSearch::clearOut(); triSurfaceRegionSearch::clearOut();
edgeTree_.clear(); edgeTree_.clear();
triSurface::clearOut(); triSurface::clearOut();
@ -447,9 +453,22 @@ bool Foam::triSurfaceMesh::overlaps(const boundBox& bb) const
void Foam::triSurfaceMesh::movePoints(const pointField& newPoints) 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(); triSurfaceRegionSearch::clearOut();
edgeTree_.clear(); edgeTree_.clear();
triSurface::movePoints(newPoints); triSurface::movePoints(newPoints);
bounds() = boundBox(triSurface::points());
} }
@ -713,6 +732,19 @@ void Foam::triSurfaceMesh::getNormal
void Foam::triSurfaceMesh::setField(const labelList& values) void Foam::triSurfaceMesh::setField(const labelList& values)
{
if (foundObject<triSurfaceLabelField>("values"))
{
triSurfaceLabelField& fld = const_cast<triSurfaceLabelField&>
(
lookupObject<triSurfaceLabelField>
(
"values"
)
);
fld.field() = values;
}
else
{ {
autoPtr<triSurfaceLabelField> fldPtr autoPtr<triSurfaceLabelField> fldPtr
( (
@ -722,7 +754,7 @@ void Foam::triSurfaceMesh::setField(const labelList& values)
( (
"values", "values",
objectRegistry::time().timeName(), // instance objectRegistry::time().timeName(), // instance
"triSurface", // local meshSubDir, // local
*this, *this,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::AUTO_WRITE IOobject::AUTO_WRITE
@ -736,6 +768,7 @@ void Foam::triSurfaceMesh::setField(const labelList& values)
// Store field on triMesh // Store field on triMesh
fldPtr.ptr()->store(); fldPtr.ptr()->store();
} }
}
void Foam::triSurfaceMesh::getField void Foam::triSurfaceMesh::getField
@ -780,18 +813,27 @@ void Foam::triSurfaceMesh::getVolumeType
const point& pt = points[pointI]; const point& pt = points[pointI];
if (!tree().bb().contains(pt)) if (!tree().bb().contains(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 // Have to calculate directly as outside the octree
volType[pointI] = tree().shapes().getVolumeType(tree(), pt); volType[pointI] = tree().shapes().getVolumeType(tree(), pt);
} }
}
else else
{ {
// - use cached volume type per each tree node // - use cached volume type per each tree node
volType[pointI] = tree().getVolumeType(pt); volType[pointI] = tree().getVolumeType(pt);
} }
// Info<< "octree : " << pt << " = "
// << volumeType::names[volType[pointI]] << endl;
} }
indexedOctree<treeDataTriSurface>::perturbTol() = oldTol; indexedOctree<treeDataTriSurface>::perturbTol() = oldTol;
@ -806,6 +848,24 @@ bool Foam::triSurfaceMesh::writeObject
IOstream::compressionType cmp IOstream::compressionType cmp
) const ) 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<triSurfaceMesh&>(*this).searchableSurface::instance() =
runTime.timeName();
const_cast<triSurfaceMesh&>(*this).objectRegistry::instance() =
runTime.timeName();
}
fileName fullPath(searchableSurface::objectPath()); fileName fullPath(searchableSurface::objectPath());
if (!mkDir(fullPath.path())) if (!mkDir(fullPath.path()))

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -85,6 +85,9 @@ private:
//- Is surface closed //- Is surface closed
mutable label surfaceClosed_; mutable label surfaceClosed_;
//- If surface is closed, what is type of outside points
mutable volumeType outsideVolType_;
// Private Member Functions // Private Member Functions
@ -137,6 +140,9 @@ public:
//- Runtime type information //- Runtime type information
TypeName("triSurfaceMesh"); TypeName("triSurfaceMesh");
//- Return the mesh sub-directory name (usually "triSurface")
static word meshSubDir;
// Constructors // Constructors