Files
openfoam/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsSearch.C
Mark Olesen 722d23f59c ENH: additional methods/operators for boundBox (related to #196)
- Constructor for bounding box of a single point.

- add(boundBox), add(point) ...
  -> Extend box to enclose the second box or point(s).

  Eg,
      bb.add(pt);
  vs.
      bb.min() = Foam::min(bb.min(), pt);
      bb.max() = Foam::max(bb.max(), pt);

Also works with other bounding boxes.
  Eg,
      bb.add(bb2);
      // OR
      bb += bb2;
  vs.
      bb.min() = Foam::min(bb.min(), bb2.min());
      bb.max() = Foam::max(bb.max(), bb2.max());

'+=' operator allows the reduction to be used in parallel
gather/scatter operations.

A global '+' operator is not currently needed.

Note: may be useful in the future to have a 'clear()' method
that resets to a zero-sized (inverted) box.

STYLE: make many bounding box constructors explicit
2017-01-25 19:26:50 +01:00

248 lines
6.2 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Searching and marking zones of the patch.
\*---------------------------------------------------------------------------*/
#include "PatchTools.H"
#include "PackedBoolList.H"
#include "boundBox.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template
<
class BoolListType,
class Face,
template<class> class FaceList,
class PointField,
class PointType
>
void Foam::PatchTools::markZone
(
const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
const BoolListType& borderEdge,
const label facei,
const label currentZone,
labelList& faceZone
)
{
const labelListList& faceEdges = p.faceEdges();
const labelListList& edgeFaces = p.edgeFaces();
// List of faces whose faceZone has been set.
labelList changedFaces(1, facei);
while (true)
{
// Pick up neighbours of changedFaces
DynamicList<label> newChangedFaces(2*changedFaces.size());
forAll(changedFaces, i)
{
label facei = changedFaces[i];
const labelList& fEdges = faceEdges[facei];
forAll(fEdges, fEdgeI)
{
label edgeI = fEdges[fEdgeI];
if (!borderEdge[edgeI])
{
const labelList& eFaceLst = edgeFaces[edgeI];
forAll(eFaceLst, j)
{
label nbrFacei = eFaceLst[j];
if (faceZone[nbrFacei] == -1)
{
faceZone[nbrFacei] = currentZone;
newChangedFaces.append(nbrFacei);
}
else if (faceZone[nbrFacei] != currentZone)
{
FatalErrorInFunction
<< "Zones " << faceZone[nbrFacei]
<< " at face " << nbrFacei
<< " connects to zone " << currentZone
<< " at face " << facei
<< abort(FatalError);
}
}
}
}
}
if (newChangedFaces.empty())
{
break;
}
// transfer from dynamic to normal list
changedFaces.transfer(newChangedFaces);
}
}
template
<
class BoolListType,
class Face,
template<class> class FaceList,
class PointField,
class PointType
>
Foam::label
Foam::PatchTools::markZones
(
const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
const BoolListType& borderEdge,
labelList& faceZone
)
{
faceZone.setSize(p.size());
faceZone = -1;
label zoneI = 0;
for (label startFacei = 0; startFacei < faceZone.size();)
{
// Find next non-visited face
for (; startFacei < faceZone.size(); ++startFacei)
{
if (faceZone[startFacei] == -1)
{
faceZone[startFacei] = zoneI;
markZone(p, borderEdge, startFacei, zoneI, faceZone);
zoneI++;
break;
}
}
}
return zoneI;
}
template
<
class BoolListType,
class Face,
template<class> class FaceList,
class PointField,
class PointType
>
void
Foam::PatchTools::subsetMap
(
const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
const BoolListType& includeFaces,
labelList& pointMap,
labelList& faceMap
)
{
label facei = 0;
label pointi = 0;
const List<Face>& localFaces = p.localFaces();
faceMap.setSize(localFaces.size());
pointMap.setSize(p.nPoints());
boolList pointHad(pointMap.size(), false);
forAll(p, oldFacei)
{
if (includeFaces[oldFacei])
{
// Store new faces compact
faceMap[facei++] = oldFacei;
// Renumber labels for face
const Face& f = localFaces[oldFacei];
forAll(f, fp)
{
const label ptLabel = f[fp];
if (!pointHad[ptLabel])
{
pointHad[ptLabel] = true;
pointMap[pointi++] = ptLabel;
}
}
}
}
// Trim
faceMap.setSize(facei);
pointMap.setSize(pointi);
}
template
<
class Face,
template<class> class FaceList,
class PointField,
class PointType
>
void Foam::PatchTools::calcBounds
(
const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
boundBox& bb,
label& nPoints
)
{
// Unfortunately nPoints constructs meshPoints() so do compact version
// ourselves
const PointField& points = p.points();
PackedBoolList pointIsUsed(points.size());
nPoints = 0;
bb = boundBox::invertedBox;
forAll(p, facei)
{
const Face& f = p[facei];
forAll(f, fp)
{
label pointi = f[fp];
if (pointIsUsed.set(pointi, 1u))
{
bb.add(points[pointi]);
++nPoints;
}
}
}
}
// ************************************************************************* //