Commit 3c41b80b authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: change from triSurface to meshedSurface storage for iso-surfaces

- this makes it easier to reuse the code, and sampledSurface expect
  a face (not a labelledFace), so this also eliminates a translation
  level and simplifies memory management.

- before/after comparison of the sampled iso-surfaces tested with
  iso-surfaces from interFoam/RAS/angledDuct tutorial (serial and
  parallel)
parent 5e9d916f
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -49,7 +49,6 @@ void Foam::distanceSurface::createGeometry()
}
// Clear any stored topologies
facesPtr_.clear();
isoSurfCellPtr_.clear();
isoSurfPtr_.clear();
......@@ -339,8 +338,7 @@ Foam::distanceSurface::distanceSurface
zoneKey_(keyType::null),
needsUpdate_(true),
isoSurfCellPtr_(nullptr),
isoSurfPtr_(nullptr),
facesPtr_(nullptr)
isoSurfPtr_(nullptr)
{
// dict.readIfPresent("zone", zoneKey_);
//
......@@ -395,8 +393,7 @@ Foam::distanceSurface::distanceSurface
zoneKey_(keyType::null),
needsUpdate_(true),
isoSurfCellPtr_(nullptr),
isoSurfPtr_(nullptr),
facesPtr_(nullptr)
isoSurfPtr_(nullptr)
{}
......@@ -419,13 +416,9 @@ bool Foam::distanceSurface::expire()
if (debug)
{
Pout<< "distanceSurface::expire :"
<< " have-facesPtr_:" << facesPtr_.valid()
<< " needsUpdate_:" << needsUpdate_ << endl;
<< " needsUpdate:" << needsUpdate_ << endl;
}
// Clear any stored topologies
facesPtr_.clear();
// Clear derived data
clearGeom();
......@@ -445,8 +438,7 @@ bool Foam::distanceSurface::update()
if (debug)
{
Pout<< "distanceSurface::update :"
<< " have-facesPtr_:" << facesPtr_.valid()
<< " needsUpdate_:" << needsUpdate_ << endl;
<< " needsUpdate:" << needsUpdate_ << endl;
}
if (!needsUpdate_)
......
......@@ -97,9 +97,6 @@ class distanceSurface
//- Constructed iso surface
autoPtr<isoSurface> isoSurfPtr_;
//- Triangles converted to faceList
mutable autoPtr<faceList> facesPtr_;
// Private Member Functions
......@@ -179,18 +176,7 @@ public:
//- Faces of surface
virtual const faceList& faces() const
{
if (facesPtr_.empty())
{
const triSurface& s = surface();
facesPtr_.reset(new faceList(s.size()));
forAll(s, i)
{
facesPtr_()[i] = s[i].triFaceFace();
}
}
return facesPtr_;
return surface().surfFaces();
}
//- Const access to per-face zone/region information
......@@ -219,7 +205,7 @@ public:
//- The underlying surface
const triSurface& surface() const
const meshedSurface& surface() const
{
if (cell_)
{
......@@ -231,6 +217,7 @@ public:
}
}
//- Sample field on surface
virtual tmp<scalarField> sample
(
......
......@@ -37,6 +37,7 @@ License
#include "surfaceIntersection.H"
#include "intersectedSurface.H"
#include "searchableBox.H"
#include "triSurface.H"
#include "triSurfaceMesh.H"
#include "triPoints.H"
......@@ -687,7 +688,6 @@ void Foam::isoSurface::calcSnappedPoint
pointField collapsedPoint(mesh_.nPoints(), point::max);
// Work arrays
DynamicList<point, 64> localTriPoints(100);
......@@ -1342,6 +1342,7 @@ Foam::isoSurface::isoSurface
const scalar mergeTol
)
:
MeshStorage(),
mesh_(cVals.mesh()),
pVals_(pVals),
iso_(iso),
......@@ -1582,6 +1583,9 @@ Foam::isoSurface::isoSurface
}
// Use a triSurface as a temporary for various operations
triSurface tmpsurf;
{
DynamicList<point> triPoints(3*nCutCells_);
DynamicList<label> triMeshCells(nCutCells_);
......@@ -1633,15 +1637,12 @@ Foam::isoSurface::isoSurface
// Merge points and compact out non-valid triangles
labelList triMap; // merged to unmerged triangle
triSurface::operator=
tmpsurf = stitchTriPoints
(
stitchTriPoints
(
true, // check for duplicate tris
triPoints,
triPointMergeMap_, // unmerged to merged point
triMap
)
true, // check for duplicate tris
triPoints,
triPointMergeMap_, // unmerged to merged point
triMap
);
if (debug)
......@@ -1682,17 +1683,33 @@ Foam::isoSurface::isoSurface
if (debug)
{
Pout<< "isoSurface : checking " << size()
Pout<< "isoSurface : checking " << tmpsurf.size()
<< " triangles for validity." << endl;
forAll(*this, triI)
forAll(tmpsurf, facei)
{
triSurfaceTools::validTri(*this, triI);
triSurfaceTools::validTri(tmpsurf, facei);
}
fileName stlFile = mesh_.time().path() + ".stl";
Pout<< "Dumping surface to " << stlFile << endl;
triSurface::write(stlFile);
tmpsurf.write(stlFile);
}
// Transfer to mesh storage
{
faceList faces;
tmpsurf.triFaceFaces(faces);
// An iso-surface has no zones
surfZoneList zones(0);
// Reset primitive data (points, faces and zones)
this->MeshStorage::reset
(
tmpsurf.xferPoints(), faces.xfer(), zones.xfer()
);
}
}
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -57,18 +57,18 @@ Description
SourceFiles
isoSurface.C
isoSurfaceTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef isoSurface_H
#define isoSurface_H
#include "triSurface.H"
#include "labelPair.H"
#include "pointIndexHit.H"
#include "PackedBoolList.H"
#include "volFields.H"
#include "slicedVolFields.H"
#include "MeshedSurface.H"
#include "MeshedSurfacesFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -78,6 +78,7 @@ namespace Foam
class fvMesh;
class plane;
class treeBoundBox;
class triSurface;
/*---------------------------------------------------------------------------*\
Class isoSurface Declaration
......@@ -85,8 +86,12 @@ class treeBoundBox;
class isoSurface
:
public triSurface
public meshedSurface
{
// Private typedefs for convenience
typedef meshedSurface MeshStorage;
// Private data
enum segmentCutType
......@@ -379,7 +384,7 @@ class isoSurface
static triSurface subsetMesh
(
const triSurface& s,
const triSurface&,
const labelList& newToOldFaces,
labelList& oldToNewPoints,
labelList& newToOldPoints
......@@ -413,7 +418,7 @@ public:
// Member Functions
//- For every triangle the original cell in mesh
//- For every face, the original cell in mesh
const labelList& meshCells() const
{
return meshCells_;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -24,16 +24,17 @@ License
\*---------------------------------------------------------------------------*/
#include "isoSurfaceCell.H"
#include "isoSurface.H"
#include "dictionary.H"
#include "polyMesh.H"
#include "mergePoints.H"
#include "tetMatcher.H"
#include "syncTools.H"
#include "triSurface.H"
#include "triSurfaceTools.H"
#include "addToRunTimeSelectionTable.H"
#include "Time.H"
#include "triPoints.H"
#include "isoSurface.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -1310,6 +1311,7 @@ Foam::isoSurfaceCell::isoSurfaceCell
const scalar mergeTol
)
:
MeshStorage(),
mesh_(mesh),
cVals_(cVals),
pVals_(pVals),
......@@ -1398,6 +1400,9 @@ Foam::isoSurfaceCell::isoSurfaceCell
}
// Use a triSurface as a temporary for various operations
triSurface tmpsurf;
{
DynamicList<point> triPoints(nCutCells_);
DynamicList<label> triMeshCells(nCutCells_);
......@@ -1448,16 +1453,13 @@ Foam::isoSurfaceCell::isoSurfaceCell
// Merge points and compact out non-valid triangles
labelList triMap;
triSurface::operator=
labelList triMap; // merged to unmerged triangle
tmpsurf = stitchTriPoints
(
stitchTriPoints
(
regularise, // check for duplicate tris
triPoints,
triPointMergeMap_, // unmerged to merged point
triMap // merged to unmerged triangle
)
regularise, // check for duplicate tris
triPoints,
triPointMergeMap_, // unmerged to merged point
triMap // merged to unmerged triangle
);
if (debug)
......@@ -1498,12 +1500,12 @@ Foam::isoSurfaceCell::isoSurfaceCell
if (debug)
{
Pout<< "isoSurfaceCell : checking " << size()
Pout<< "isoSurfaceCell : checking " << tmpsurf.size()
<< " triangles for validity." << endl;
forAll(*this, triI)
forAll(tmpsurf, triI)
{
triSurfaceTools::validTri(*this, triI);
triSurfaceTools::validTri(tmpsurf, triI);
}
}
......@@ -1520,7 +1522,7 @@ Foam::isoSurfaceCell::isoSurfaceCell
// Calculate addressing
calcAddressing
(
*this,
tmpsurf,
faceEdges,
edgeFace0,
edgeFace1,
......@@ -1554,21 +1556,33 @@ Foam::isoSurfaceCell::isoSurfaceCell
labelList subsetPointMap;
labelList reversePointMap;
triSurface::operator=
tmpsurf = subsetMesh
(
subsetMesh
(
*this,
subsetTriMap,
reversePointMap,
subsetPointMap
)
tmpsurf,
subsetTriMap,
reversePointMap,
subsetPointMap
);
meshCells_ = labelField(meshCells_, subsetTriMap);
inplaceRenumber(reversePointMap, triPointMergeMap_);
}
}
}
// Transfer to mesh storage
{
faceList faces;
tmpsurf.triFaceFaces(faces);
// An iso-surface has no zones
surfZoneList zones(0);
// Reset primitive data (points, faces and zones)
this->MeshStorage::reset
(
tmpsurf.xferPoints(), faces.xfer(), zones.xfer()
);
}
}
// ************************************************************************* //
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -38,17 +38,19 @@ Description
SourceFiles
isoSurfaceCell.C
isoSurfaceCellTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef isoSurfaceCell_H
#define isoSurfaceCell_H
#include "triSurface.H"
#include "labelPair.H"
#include "pointIndexHit.H"
#include "PackedBoolList.H"
#include "boundBox.H"
#include "MeshedSurface.H"
#include "MeshedSurfacesFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -56,7 +58,7 @@ namespace Foam
{
class polyMesh;
class plane;
class triSurface;
/*---------------------------------------------------------------------------*\
Class isoSurfaceCell Declaration
......@@ -64,8 +66,12 @@ class plane;
class isoSurfaceCell
:
public triSurface
public meshedSurface
{
// Private typedefs for convenience
typedef meshedSurface MeshStorage;
// Private data
enum segmentCutType
......@@ -301,7 +307,7 @@ class isoSurfaceCell
static triSurface subsetMesh
(
const triSurface& s,
const triSurface&,
const labelList& newToOldFaces,
labelList& oldToNewPoints,
labelList& newToOldPoints
......@@ -331,7 +337,7 @@ public:
// Member Functions
//- For every face original cell in mesh
//- For every face, the original cell in mesh
const labelList& meshCells() const
{
return meshCells_;
......
......@@ -24,9 +24,9 @@ License
\*---------------------------------------------------------------------------*/
#include "isoSurfaceCell.H"
#include "isoSurface.H"
#include "polyMesh.H"
#include "tetMatcher.H"
#include "isoSurface.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
......@@ -556,7 +556,7 @@ Foam::isoSurfaceCell::interpolate
return isoSurface::interpolate
(
points().size(),
this->points().size(),
triPointMergeMap_,
interpolatedPoints_,
interpolatedOldPoints_,
......
......@@ -842,7 +842,7 @@ Foam::isoSurface::interpolate
return interpolate
(
points().size(),
this->points().size(),
triPointMergeMap_,
interpolatedPoints_,
interpolatedOldPoints_,
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -393,7 +393,6 @@ bool Foam::sampledIsoSurface::updateGeometry() const
// Clear any stored topo
surfPtr_.clear();
facesPtr_.clear();
// Clear derived data
clearGeom();
......@@ -448,7 +447,7 @@ bool Foam::sampledIsoSurface::updateGeometry() const
<< nl;
}
Pout<< " points : " << points().size() << nl
<< " tris : " << surface().size() << nl
<< " faces : " << surface().size() << nl
<< " cut cells : " << surface().meshCells().size()
<< endl;
}
......@@ -476,7 +475,6 @@ Foam::sampledIsoSurface::sampledIsoSurface
zoneID_(dict.lookupOrDefault("zone", word::null), mesh.cellZones()),
exposedPatchName_(word::null),
surfPtr_(nullptr),
facesPtr_(nullptr),
prevTimeIndex_(-1),
storedVolFieldPtr_(nullptr),
volFieldPtr_(nullptr),
......@@ -535,7 +533,6 @@ bool Foam::sampledIsoSurface::needsUpdate() const
bool Foam::sampledIsoSurface::expire()
{
surfPtr_.clear();
facesPtr_.clear();
subMeshPtr_.clear();
// Clear derived data
......
......@@ -83,9 +83,6 @@ class sampledIsoSurface
mutable autoPtr<isoSurface> surfPtr_;
//- Triangles converted to faceList
mutable autoPtr<faceList> facesPtr_;
// Recreated for every isoSurface
......@@ -185,18 +182,7 @@ public:
//- Faces of surface
virtual const faceList& faces() const
{
if (facesPtr_.empty())
{
const triSurface& s = surface();
facesPtr_.reset(new faceList(s.size()));
forAll(s, i)
{
facesPtr_()[i] = s[i].triFaceFace();
}
}
return facesPtr_;
return surface().surfFaces();
}
//- Const access to per-face zone/region information
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -59,9 +59,6 @@ bool Foam::sampledIsoSurfaceCell::updateGeometry() const
prevTimeIndex_ = fvm.time().timeIndex();
// Clear any stored topo
facesPtr_.clear();
// Clear derived data
sampledSurface::clearGeom();
......@@ -142,7 +139,7 @@ bool Foam::sampledIsoSurfaceCell::updateGeometry() const
cellAvg[celli] /= nPointCells[celli];
}
const isoSurfaceCell iso
isoSurfaceCell iso
(
fvm,
cellAvg,
......@@ -155,13 +152,13 @@ bool Foam::sampledIsoSurfaceCell::updateGeometry() const
const_cast<sampledIsoSurfaceCell&>
(
*this
).triSurface::operator=(iso);
).transfer(static_cast<meshedSurface&>(iso));
meshCells_ = iso.meshCells();
}
else
{
//- Direct from cell field and point field. Gives bad continuity.
const isoSurfaceCell iso
isoSurfaceCell iso
(
fvm,
cellFld.primitiveField(),
......@@ -174,7 +171,7 @@ bool Foam::sampledIsoSurfaceCell::updateGeometry() const
const_cast<sampledIsoSurfaceCell&>
(
*this
).triSurface::operator=(iso);
).transfer(static_cast<meshedSurface&>(iso));
meshCells_ = iso.meshCells();
}
......@@ -189,7 +186,7 @@ bool Foam::sampledIsoSurfaceCell::updateGeometry() const