ENH: improve PrimitivePatch access for edges

- return internalEdges() and boundaryEdges() sub lists directly

- calculate and return boundaryFaces() to identify faces attached to
  boundary edges.

- minor code cleanup, and add PrimitivePatchBase class for
  non-templated code.

STYLE: mark unused parameter in globalMeshData mergePoints
This commit is contained in:
Mark Olesen
2021-05-10 13:38:02 +02:00
parent ea2bf72740
commit 3bc8ab2839
17 changed files with 322 additions and 296 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -34,6 +34,7 @@ Description
#include "polyMesh.H" #include "polyMesh.H"
#include "primitiveFacePatch.H" #include "primitiveFacePatch.H"
#include "primitivePatch.H" #include "primitivePatch.H"
#include "IndirectList.H"
#include "Fstream.H" #include "Fstream.H"
using namespace Foam; using namespace Foam;
@ -242,6 +243,28 @@ int main(int argc, char *argv[])
writeEdgeFaces(localPoints, localFaces, edges, edgeFaces); writeEdgeFaces(localPoints, localFaces, edges, edgeFaces);
writeFaceFaces(localPoints, localFaces, faceFaces); writeFaceFaces(localPoints, localFaces, faceFaces);
const labelList bndFaceIds(pp.boundaryFaces());
Info<< "Have: " << bndFaceIds.size() << " boundary faces" << nl;
// Can calculate by hand
if (!pp.hasFaceCentres())
{
pointField boundaryCentres(bndFaceIds.size());
forAll(bndFaceIds, facei)
{
boundaryCentres[facei] =
pp[bndFaceIds[facei]].centre(pp.points());
}
Info << "calc faceCentres:"
<< boundaryCentres << nl;
}
// But will often use the cached information
Info<< "faceCentres:"
<< UIndirectList<point>(pp.faceCentres(), bndFaceIds) << nl;
} }
// Move construct // Move construct

View File

@ -655,7 +655,7 @@ $(mapPolyMesh)/mapDistribute/IOmapDistribute.C
$(mapPolyMesh)/mapAddedPolyMesh.C $(mapPolyMesh)/mapAddedPolyMesh.C
PrimitivePatch = $(primitiveMesh)/PrimitivePatch PrimitivePatch = $(primitiveMesh)/PrimitivePatch
$(PrimitivePatch)/PrimitivePatchName.C $(PrimitivePatch)/PrimitivePatchBase.C
pointMesh = meshes/pointMesh pointMesh = meshes/pointMesh
$(pointMesh)/pointMesh.C $(pointMesh)/pointMesh.C

View File

@ -2507,7 +2507,7 @@ Foam::autoPtr<Foam::globalIndex> Foam::globalMeshData::mergePoints
Foam::autoPtr<Foam::globalIndex> Foam::globalMeshData::mergePoints Foam::autoPtr<Foam::globalIndex> Foam::globalMeshData::mergePoints
( (
const labelList& meshPoints, const labelList& meshPoints,
const Map<label>& meshPointMap, const Map<label>& /* unused: meshPointMap */,
labelList& pointToGlobal, labelList& pointToGlobal,
labelList& uniqueMeshPoints labelList& uniqueMeshPoints
) const ) const

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -342,7 +342,7 @@ public:
// Access // Access
//- Return the mesh reference //- Return the mesh reference
const polyMesh& mesh() const const polyMesh& mesh() const noexcept
{ {
return mesh_; return mesh_;
} }
@ -351,25 +351,25 @@ public:
// not running parallel) // not running parallel)
bool parallel() const bool parallel() const
{ {
return processorPatches_.size() > 0; return !processorPatches_.empty();
} }
//- Return total number of points in decomposed mesh. Not //- Return total number of points in decomposed mesh. Not
// compensated for duplicate points! // compensated for duplicate points!
label nTotalPoints() const label nTotalPoints() const noexcept
{ {
return nTotalPoints_; return nTotalPoints_;
} }
//- Return total number of faces in decomposed mesh. Not //- Return total number of faces in decomposed mesh. Not
// compensated for duplicate faces! // compensated for duplicate faces!
label nTotalFaces() const label nTotalFaces() const noexcept
{ {
return nTotalFaces_; return nTotalFaces_;
} }
//- Return total number of cells in decomposed mesh. //- Return total number of cells in decomposed mesh.
label nTotalCells() const label nTotalCells() const noexcept
{ {
return nTotalCells_; return nTotalCells_;
} }
@ -379,7 +379,7 @@ public:
//- Return list of processor patch labels //- Return list of processor patch labels
// (size of list = number of processor patches) // (size of list = number of processor patches)
const labelList& processorPatches() const const labelList& processorPatches() const noexcept
{ {
return processorPatches_; return processorPatches_;
} }
@ -387,14 +387,14 @@ public:
//- Return list of indices into processorPatches_ for each patch. //- Return list of indices into processorPatches_ for each patch.
// Index = -1 for non-processor parches. // Index = -1 for non-processor parches.
// (size of list = number of patches) // (size of list = number of patches)
const labelList& processorPatchIndices() const const labelList& processorPatchIndices() const noexcept
{ {
return processorPatchIndices_; return processorPatchIndices_;
} }
//- Return processorPatchIndices of the neighbours //- Return processorPatchIndices of the neighbours
// processor patches. -1 if not running parallel. // processor patches. -1 if not running parallel.
const labelList& processorPatchNeighbours() const const labelList& processorPatchNeighbours() const noexcept
{ {
return processorPatchNeighbours_; return processorPatchNeighbours_;
} }
@ -577,7 +577,7 @@ public:
autoPtr<globalIndex> mergePoints autoPtr<globalIndex> mergePoints
( (
const labelList& meshPoints, const labelList& meshPoints,
const Map<label>& meshPointMap, const Map<label>& meshPointMap, //!< currently unused
labelList& pointToGlobal, labelList& pointToGlobal,
labelList& uniqueMeshPoints labelList& uniqueMeshPoints
) const; ) const;

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -130,7 +130,6 @@ Foam::PrimitivePatch<FaceList, PointField>::PrimitivePatch
const PrimitivePatch<FaceList, PointField>& pp const PrimitivePatch<FaceList, PointField>& pp
) )
: :
PrimitivePatchName(),
FaceList(pp), FaceList(pp),
points_(pp.points_), points_(pp.points_),
edgesPtr_(nullptr), edgesPtr_(nullptr),
@ -173,13 +172,7 @@ Foam::PrimitivePatch<FaceList, PointField>::movePoints
const Field<point_type>& const Field<point_type>&
) )
{ {
if (debug) DebugInFunction << "Recalculating geometry following mesh motion" << endl;
{
Pout<< "PrimitivePatch<FaceList, PointField>::"
<< "movePoints() : "
<< "recalculating PrimitivePatch geometry following mesh motion"
<< endl;
}
clearGeom(); clearGeom();
} }
@ -198,6 +191,24 @@ Foam::PrimitivePatch<FaceList, PointField>::edges() const
} }
template<class FaceList, class PointField>
const Foam::edgeList::subList
Foam::PrimitivePatch<FaceList, PointField>::internalEdges() const
{
const edgeList& allEdges = this->edges(); // Force demand-driven
return edgeList::subList(allEdges, nInternalEdges());
}
template<class FaceList, class PointField>
const Foam::edgeList::subList
Foam::PrimitivePatch<FaceList, PointField>::boundaryEdges() const
{
const edgeList& allEdges = this->edges(); // Force demand-driven
return edgeList::subList(allEdges, nBoundaryEdges(), nInternalEdges());
}
template<class FaceList, class PointField> template<class FaceList, class PointField>
Foam::label Foam::label
Foam::PrimitivePatch<FaceList, PointField>::nInternalEdges() const Foam::PrimitivePatch<FaceList, PointField>::nInternalEdges() const
@ -211,6 +222,15 @@ Foam::PrimitivePatch<FaceList, PointField>::nInternalEdges() const
} }
template<class FaceList, class PointField>
Foam::label
Foam::PrimitivePatch<FaceList, PointField>::nBoundaryEdges() const
{
const edgeList& allEdges = this->edges(); // Force demand-driven
return (allEdges.size() - this->nInternalEdges());
}
template<class FaceList, class PointField> template<class FaceList, class PointField>
const Foam::labelList& const Foam::labelList&
Foam::PrimitivePatch<FaceList, PointField>::boundaryPoints() const Foam::PrimitivePatch<FaceList, PointField>::boundaryPoints() const
@ -496,6 +516,7 @@ Foam::PrimitivePatch<FaceList, PointField>::operator=
#include "PrimitivePatchAddressing.C" #include "PrimitivePatchAddressing.C"
#include "PrimitivePatchEdgeLoops.C" #include "PrimitivePatchEdgeLoops.C"
#include "PrimitivePatchClear.C" #include "PrimitivePatchClear.C"
#include "PrimitivePatchBdryFaces.C"
#include "PrimitivePatchBdryPoints.C" #include "PrimitivePatchBdryPoints.C"
#include "PrimitivePatchLocalPointOrder.C" #include "PrimitivePatchLocalPointOrder.C"
#include "PrimitivePatchMeshData.C" #include "PrimitivePatchMeshData.C"

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd. Copyright (C) 2016-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -36,16 +36,16 @@ Description
using List and pointField. using List and pointField.
SourceFiles SourceFiles
PrimitivePatchAddressing.C
PrimitivePatchBdryPoints.C
PrimitivePatch.C PrimitivePatch.C
PrimitivePatchAddressing.C
PrimitivePatchBdryFaces.C
PrimitivePatchBdryPoints.C
PrimitivePatchCheck.C PrimitivePatchCheck.C
PrimitivePatchClear.C PrimitivePatchClear.C
PrimitivePatchEdgeLoops.C PrimitivePatchEdgeLoops.C
PrimitivePatchLocalPointOrder.C PrimitivePatchLocalPointOrder.C
PrimitivePatchMeshData.C PrimitivePatchMeshData.C
PrimitivePatchMeshEdges.C PrimitivePatchMeshEdges.C
PrimitivePatchName.C
PrimitivePatchPointAddressing.C PrimitivePatchPointAddressing.C
PrimitivePatchProjectPoints.C PrimitivePatchProjectPoints.C
@ -61,6 +61,7 @@ SourceFiles
#include "intersection.H" #include "intersection.H"
#include "HashSet.H" #include "HashSet.H"
#include "objectHit.H" #include "objectHit.H"
#include "PrimitivePatchBase.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -71,13 +72,6 @@ namespace Foam
class face; class face;
template<class T> class Map; template<class T> class Map;
/*---------------------------------------------------------------------------*\
Class PrimitivePatchName Declaration
\*---------------------------------------------------------------------------*/
TemplateName(PrimitivePatch);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class PrimitivePatch Declaration Class PrimitivePatch Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -85,7 +79,7 @@ TemplateName(PrimitivePatch);
template<class FaceList, class PointField> template<class FaceList, class PointField>
class PrimitivePatch class PrimitivePatch
: :
public PrimitivePatchName, public PrimitivePatchBase,
public FaceList public FaceList
{ {
public: public:
@ -129,7 +123,7 @@ private:
PointField points_; PointField points_;
// Demand driven private data // Demand-driven Private Data
//- Edges of the patch; address into local point list; //- Edges of the patch; address into local point list;
// sorted with internal edges first in upper-triangular order // sorted with internal edges first in upper-triangular order
@ -194,10 +188,10 @@ private:
// Private Member Functions // Private Member Functions
//- Calculate edges of the patch //- Calculate internal points on a patch
void calcIntBdryEdges() const; void calcInternPoints() const;
//- Calculated boundary points on a patch //- Calculate boundary points on a patch
void calcBdryPoints() const; void calcBdryPoints() const;
//- Calculate addressing //- Calculate addressing
@ -308,18 +302,24 @@ public:
return points_; return points_;
} }
//- Number of faces in the patch
label nFaces() const
{
return FaceList::size();
}
// Access functions for demand-driven data // Access functions for demand-driven data
// Topological data; no mesh required. // Topological data; no mesh required.
//- Return number of points supporting patch faces //- Number of points supporting patch faces
label nPoints() const label nPoints() const
{ {
return meshPoints().size(); return meshPoints().size();
} }
//- Return number of edges in patch //- Number of edges in patch
label nEdges() const label nEdges() const
{ {
return edges().size(); return edges().size();
@ -328,9 +328,18 @@ public:
//- Return list of edges, address into LOCAL point list //- Return list of edges, address into LOCAL point list
const edgeList& edges() const; const edgeList& edges() const;
//- Return sub-list of internal edges, address into LOCAL point list
const edgeList::subList internalEdges() const;
//- Return sub-list of boundary edges, address into LOCAL point list
const edgeList::subList boundaryEdges() const;
//- Number of internal edges //- Number of internal edges
label nInternalEdges() const; label nInternalEdges() const;
//- Number of boundary edges == (nEdges() - nInternalEdges())
label nBoundaryEdges() const;
//- Is internal edge? //- Is internal edge?
bool isInternalEdge(const label edgei) const bool isInternalEdge(const label edgei) const
{ {
@ -358,6 +367,10 @@ public:
//- Return patch faces addressing into local point list //- Return patch faces addressing into local point list
const List<face_type>& localFaces() const; const List<face_type>& localFaces() const;
//- Calculate and return list of local boundary faces.
// These are the faces attached to boundary edges.
labelList boundaryFaces() const;
// Addressing into mesh // Addressing into mesh
@ -382,7 +395,7 @@ public:
//- Given an edge in local point labels, return its //- Given an edge in local point labels, return its
//- index in the edge list. If the edge is not found, return -1 //- index in the edge list. If the edge is not found, return -1
label whichEdge(const edge&) const; label whichEdge(const edge& e) const;
//- Return labels of patch edges in the global edge list using //- Return labels of patch edges in the global edge list using
//- cell addressing //- cell addressing

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -76,40 +76,29 @@ Foam::PrimitivePatch<FaceList, PointField>::calcAddressing() const
edgeFacesPtr_.reset(new labelListList(maxEdges)); edgeFacesPtr_.reset(new labelListList(maxEdges));
auto& edgeFaces = *edgeFacesPtr_; auto& edgeFaces = *edgeFacesPtr_;
// faceFaces created using a dynamic list. Cannot guess size because
// of multiple connections
List<DynamicList<label>> ff(locFcs.size());
faceEdgesPtr_.reset(new labelListList(locFcs.size())); faceEdgesPtr_.reset(new labelListList(locFcs.size()));
auto& faceEdges = *faceEdgesPtr_; auto& faceEdges = *faceEdgesPtr_;
// count the number of face neighbours
labelList noFaceFaces(locFcs.size());
// initialise the lists of subshapes for each face to avoid duplication // initialise the lists of subshapes for each face to avoid duplication
edgeListList faceIntoEdges(locFcs.size()); edgeListList faceIntoEdges(locFcs.size());
forAll(locFcs, facei) forAll(locFcs, facei)
{ {
faceIntoEdges[facei] = locFcs[facei].edges(); faceIntoEdges[facei] = locFcs[facei].edges();
faceEdges[facei].resize(faceIntoEdges[facei].size(), -1);
labelList& curFaceEdges = faceEdges[facei];
curFaceEdges.setSize(faceIntoEdges[facei].size());
forAll(curFaceEdges, faceEdgeI)
{
curFaceEdges[faceEdgeI] = -1;
}
} }
// faceFaces created using a dynamic list. Cannot guess size because
// of multiple connections
List<DynamicList<label>> ff(locFcs.size());
// This algorithm will produce a separated list of edges, internal edges // This algorithm will produce a separated list of edges, internal edges
// starting from 0 and boundary edges starting from the top and // starting from 0 and boundary edges starting from the top and
// growing down. // growing down.
label nEdges = 0; label nEdges = 0;
bool found = false;
// Note that faceIntoEdges is sorted acc. to local vertex numbering // Note that faceIntoEdges is sorted acc. to local vertex numbering
// in face (i.e. curEdges[0] is edge between f[0] and f[1]) // in face (i.e. curEdges[0] is edge between f[0] and f[1])
@ -132,8 +121,6 @@ Foam::PrimitivePatch<FaceList, PointField>::calcAddressing() const
// If the edge is already detected, skip // If the edge is already detected, skip
if (faceEdges[facei][edgeI] >= 0) continue; if (faceEdges[facei][edgeI] >= 0) continue;
found = false;
// Set reference to the current edge // Set reference to the current edge
const edge& e = curEdges[edgeI]; const edge& e = curEdges[edgeI];
@ -141,6 +128,8 @@ Foam::PrimitivePatch<FaceList, PointField>::calcAddressing() const
const labelList& nbrFaces = pf[e.start()]; const labelList& nbrFaces = pf[e.start()];
bool found = false;
forAll(nbrFaces, nbrFacei) forAll(nbrFaces, nbrFacei)
{ {
// set reference to the current neighbour // set reference to the current neighbour
@ -212,7 +201,7 @@ Foam::PrimitivePatch<FaceList, PointField>::calcAddressing() const
// Set edge-face addressing // Set edge-face addressing
labelList& curEf = edgeFaces[nEdges]; labelList& curEf = edgeFaces[nEdges];
curEf.setSize(cnf.size() + 1); curEf.resize(cnf.size() + 1);
curEf[0] = facei; curEf[0] = facei;
forAll(cnf, cnfI) forAll(cnf, cnfI)
@ -256,7 +245,7 @@ Foam::PrimitivePatch<FaceList, PointField>::calcAddressing() const
// Add edgeFace // Add edgeFace
labelList& curEf = edgeFaces[nEdges]; labelList& curEf = edgeFaces[nEdges];
curEf.setSize(1); curEf.resize(1);
curEf[0] = facei; curEf[0] = facei;
nEdges++; nEdges++;
@ -265,10 +254,10 @@ Foam::PrimitivePatch<FaceList, PointField>::calcAddressing() const
} }
// edges // edges
edges.setSize(nEdges); edges.resize(nEdges);
// edgeFaces list // edgeFaces list
edgeFaces.setSize(nEdges); edgeFaces.resize(nEdges);
// faceFaces list // faceFaces list
faceFacesPtr_.reset(new labelListList(locFcs.size())); faceFacesPtr_.reset(new labelListList(locFcs.size()));

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2012 OpenFOAM Foundation Copyright (C) 2011-2012 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,13 +26,13 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "PrimitivePatch.H" #include "PrimitivePatchBase.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(PrimitivePatchName, 0); defineTypeNameAndDebug(PrimitivePatchBase, 0);
} }

View File

@ -0,0 +1,72 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 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/>.
Class
Foam::PrimitivePatchBase
Description
Non-templated base elements for PrimitivePatch
SourceFiles
PrimitivePatchBase.C
\*---------------------------------------------------------------------------*/
#ifndef PrimitivePatchBase_H
#define PrimitivePatchBase_H
#include "className.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class PrimitivePatchBase Declaration
\*---------------------------------------------------------------------------*/
class PrimitivePatchBase
{
public:
//- Runtime type information
ClassName("PrimitivePatch");
// Constructors
//- Default construct
PrimitivePatchBase() = default;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
#endif
// ************************************************************************* //

View File

@ -0,0 +1,53 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 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/>.
\*---------------------------------------------------------------------------*/
#include "PrimitivePatch.H"
#include "HashSet.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class FaceList, class PointField>
Foam::labelList
Foam::PrimitivePatch<FaceList, PointField>::boundaryFaces() const
{
// By definition boundary edges have a _single_ face attached,
// but a face can easily have multiple boundary edges.
const labelListList& edgeToFace = edgeFaces();
labelHashSet bndFaces(2*nBoundaryEdges());
for (label edgei = nInternalEdges(); edgei < edgeToFace.size(); ++edgei)
{
bndFaces.insert(edgeToFace[edgei][0]);
}
return bndFaces.sortedToc();
}
// ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -45,16 +45,12 @@ Foam::PrimitivePatch<FaceList, PointField>::calcBdryPoints() const
<< abort(FatalError); << abort(FatalError);
} }
const edgeList& e = edges(); labelHashSet bp(2*nEdges());
labelHashSet bp(2*e.size()); for (const edge& e : boundaryEdges())
for (label edgeI = nInternalEdges_; edgeI < e.size(); edgeI++)
{ {
const edge& curEdge = e[edgeI]; bp.insert(e.first());
bp.insert(e.second());
bp.insert(curEdge.start());
bp.insert(curEdge.end());
} }
boundaryPointsPtr_.reset(new labelList(bp.sortedToc())); boundaryPointsPtr_.reset(new labelList(bp.sortedToc()));

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -49,12 +49,15 @@ Foam::PrimitivePatch<FaceList, PointField>::calcEdgeLoops() const
} }
const edgeList& patchEdges = edges(); const edgeList& patchEdges = edges();
label nIntEdges = nInternalEdges(); const label nIntEdges = nInternalEdges();
label nBdryEdges = patchEdges.size() - nIntEdges; const label nBdryEdges = patchEdges.size() - nIntEdges;
// Size return list plenty big
edgeLoopsPtr_.reset(new labelListList(nBdryEdges));
auto& edgeLoops = *edgeLoopsPtr_;
if (nBdryEdges == 0) if (nBdryEdges == 0)
{ {
edgeLoopsPtr_.reset(new labelListList(0));
return; return;
} }
@ -68,11 +71,6 @@ Foam::PrimitivePatch<FaceList, PointField>::calcEdgeLoops() const
// Loop per (boundary) edge. // Loop per (boundary) edge.
labelList loopNumber(nBdryEdges, -1); labelList loopNumber(nBdryEdges, -1);
// Size return list plenty big
edgeLoopsPtr_.reset(new labelListList(nBdryEdges));
auto& edgeLoops = *edgeLoopsPtr_;
// Current loop number. // Current loop number.
label loopI = 0; label loopI = 0;

View File

@ -41,13 +41,7 @@ Foam::PrimitivePatch<FaceList, PointField>::calcLocalPointOrder() const
// Note: Cannot use bandCompressing as point-point addressing does // Note: Cannot use bandCompressing as point-point addressing does
// not exist and is not considered generally useful. // not exist and is not considered generally useful.
if (debug) DebugInFunction << "Calculating local point order" << endl;
{
Pout<< "PrimitivePatch<FaceList, PointField>::"
<< "calcLocalPointOrder() : "
<< "calculating local point order"
<< endl;
}
if (localPointOrderPtr_) if (localPointOrderPtr_)
{ {
@ -116,13 +110,7 @@ Foam::PrimitivePatch<FaceList, PointField>::calcLocalPointOrder() const
} }
} }
if (debug) DebugInfo << "Calculated local point order" << endl;
{
Pout<< "PrimitivePatch<FaceList, PointField>::"
<< "calcLocalPointOrder() "
<< "finished calculating local point order"
<< endl;
}
} }

View File

@ -35,13 +35,7 @@ template<class FaceList, class PointField>
void void
Foam::PrimitivePatch<FaceList, PointField>::calcMeshData() const Foam::PrimitivePatch<FaceList, PointField>::calcMeshData() const
{ {
if (debug) DebugInFunction << "Calculating mesh data" << endl;
{
Pout<< "PrimitivePatch<FaceList, PointField>::"
"calcMeshData() : "
"calculating mesh data in PrimitivePatch"
<< endl;
}
if (meshPointsPtr_ || localFacesPtr_) if (meshPointsPtr_ || localFacesPtr_)
{ {
@ -117,13 +111,7 @@ Foam::PrimitivePatch<FaceList, PointField>::calcMeshData() const
} }
} }
if (debug) DebugInfo << "Calculated mesh data" << endl;
{
Pout<< "PrimitivePatch<FaceList, PointField>::"
"calcMeshData() : "
"finished calculating mesh data in PrimitivePatch"
<< endl;
}
} }
@ -131,13 +119,7 @@ template<class FaceList, class PointField>
void void
Foam::PrimitivePatch<FaceList, PointField>::calcMeshPointMap() const Foam::PrimitivePatch<FaceList, PointField>::calcMeshPointMap() const
{ {
if (debug) DebugInFunction << "Calculating mesh point map" << endl;
{
Pout<< "PrimitivePatch<FaceList, PointField>::"
"calcMeshPointMap() : "
"calculating mesh point map in PrimitivePatch"
<< endl;
}
if (meshPointMapPtr_) if (meshPointMapPtr_)
{ {
@ -157,13 +139,7 @@ Foam::PrimitivePatch<FaceList, PointField>::calcMeshPointMap() const
mpMap.insert(mp[i], i); mpMap.insert(mp[i], i);
} }
if (debug) DebugInfo << "Calculated mesh point map" << endl;
{
Pout<< "PrimitivePatch<FaceList, PointField>::"
"calcMeshPointMap() : "
"finished calculating mesh point map in PrimitivePatch"
<< endl;
}
} }
@ -171,13 +147,7 @@ template<class FaceList, class PointField>
void void
Foam::PrimitivePatch<FaceList, PointField>::calcLocalPoints() const Foam::PrimitivePatch<FaceList, PointField>::calcLocalPoints() const
{ {
if (debug) DebugInFunction << "Calculating localPoints" << endl;
{
Pout<< "PrimitivePatch<FaceList, PointField>::"
"calcLocalPoints() : "
"calculating localPoints in PrimitivePatch"
<< endl;
}
if (localPointsPtr_) if (localPointsPtr_)
{ {
@ -197,13 +167,7 @@ Foam::PrimitivePatch<FaceList, PointField>::calcLocalPoints() const
locPts[pointi] = points_[meshPts[pointi]]; locPts[pointi] = points_[meshPts[pointi]];
} }
if (debug) DebugInfo << "Calculated localPoints" << endl;
{
Pout<< "PrimitivePatch<FaceList, PointField>::"
<< "calcLocalPoints() : "
<< "finished calculating localPoints in PrimitivePatch"
<< endl;
}
} }
@ -211,13 +175,7 @@ template<class FaceList, class PointField>
void void
Foam::PrimitivePatch<FaceList, PointField>::calcPointNormals() const Foam::PrimitivePatch<FaceList, PointField>::calcPointNormals() const
{ {
if (debug) DebugInFunction << "Calculating pointNormals" << endl;
{
Pout<< "PrimitivePatch<FaceList, PointField>::"
"calcPointNormals() : "
"calculating pointNormals in PrimitivePatch"
<< endl;
}
if (pointNormalsPtr_) if (pointNormalsPtr_)
{ {
@ -248,13 +206,7 @@ Foam::PrimitivePatch<FaceList, PointField>::calcPointNormals() const
curNormal.normalise(); curNormal.normalise();
} }
if (debug) DebugInfo << "Calculated pointNormals" << endl;
{
Pout<< "PrimitivePatch<FaceList, PointField>::"
"calcPointNormals() : "
"finished calculating pointNormals in PrimitivePatch"
<< endl;
}
} }
@ -262,13 +214,7 @@ template<class FaceList, class PointField>
void void
Foam::PrimitivePatch<FaceList, PointField>::calcFaceCentres() const Foam::PrimitivePatch<FaceList, PointField>::calcFaceCentres() const
{ {
if (debug) DebugInFunction << "Calculating faceCentres" << endl;
{
Pout<< "PrimitivePatch<FaceList, PointField>::"
"calcFaceCentres() : "
"calculating faceCentres in PrimitivePatch"
<< endl;
}
if (faceCentresPtr_) if (faceCentresPtr_)
{ {
@ -286,13 +232,7 @@ Foam::PrimitivePatch<FaceList, PointField>::calcFaceCentres() const
c[facei] = this->operator[](facei).centre(points_); c[facei] = this->operator[](facei).centre(points_);
} }
if (debug) DebugInfo << "Calculated faceCentres" << endl;
{
Pout<< "PrimitivePatch<FaceList, PointField>::"
"calcFaceCentres() : "
"finished calculating faceCentres in PrimitivePatch"
<< endl;
}
} }
@ -300,13 +240,7 @@ template<class FaceList, class PointField>
void void
Foam::PrimitivePatch<FaceList, PointField>::calcMagFaceAreas() const Foam::PrimitivePatch<FaceList, PointField>::calcMagFaceAreas() const
{ {
if (debug) DebugInFunction << "Calculating magFaceAreas" << endl;
{
Pout<< "PrimitivePatch<FaceList, PointField>::"
"calcMagFaceAreas() : "
"calculating magFaceAreas in PrimitivePatch"
<< endl;
}
if (magFaceAreasPtr_) if (magFaceAreasPtr_)
{ {
@ -324,13 +258,7 @@ Foam::PrimitivePatch<FaceList, PointField>::calcMagFaceAreas() const
a[facei] = this->operator[](facei).mag(points_); a[facei] = this->operator[](facei).mag(points_);
} }
if (debug) DebugInfo << "Calculated magFaceAreas" << endl;
{
Pout<< "PrimitivePatch<FaceList, PointField>::"
"calcMagFaceAreas() : "
"finished calculating magFaceAreas in PrimitivePatch"
<< endl;
}
} }
@ -338,13 +266,7 @@ template<class FaceList, class PointField>
void void
Foam::PrimitivePatch<FaceList, PointField>::calcFaceAreas() const Foam::PrimitivePatch<FaceList, PointField>::calcFaceAreas() const
{ {
if (debug) DebugInFunction << "Calculating faceAreas" << endl;
{
Pout<< "PrimitivePatch<FaceList, PointField>::"
"calcFaceAreas() : "
"calculating faceAreas in PrimitivePatch"
<< endl;
}
if (faceAreasPtr_) if (faceAreasPtr_)
{ {
@ -362,13 +284,7 @@ Foam::PrimitivePatch<FaceList, PointField>::calcFaceAreas() const
n[facei] = this->operator[](facei).areaNormal(points_); n[facei] = this->operator[](facei).areaNormal(points_);
} }
if (debug) DebugInfo << "Calculated faceAreas" << endl;
{
Pout<< "PrimitivePatch<FaceList, PointField>::"
"calcFaceAreas() : "
"finished calculating faceAreas in PrimitivePatch"
<< endl;
}
} }
@ -376,13 +292,7 @@ template<class FaceList, class PointField>
void void
Foam::PrimitivePatch<FaceList, PointField>::calcFaceNormals() const Foam::PrimitivePatch<FaceList, PointField>::calcFaceNormals() const
{ {
if (debug) DebugInFunction << "Calculating faceNormals" << endl;
{
Pout<< "PrimitivePatch<FaceList, PointField>::"
"calcFaceNormals() : "
"calculating faceNormals in PrimitivePatch"
<< endl;
}
if (faceNormalsPtr_) if (faceNormalsPtr_)
{ {
@ -400,13 +310,7 @@ Foam::PrimitivePatch<FaceList, PointField>::calcFaceNormals() const
n[facei] = this->operator[](facei).unitNormal(points_); n[facei] = this->operator[](facei).unitNormal(points_);
} }
if (debug) DebugInfo << "Calculated faceNormals" << endl;
{
Pout<< "PrimitivePatch<FaceList, PointField>::"
"calcFaceNormals() : "
"finished calculating faceNormals in PrimitivePatch"
<< endl;
}
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -43,47 +43,38 @@ meshEdges
DebugInFunction DebugInFunction
<< "Calculating labels of patch edges in mesh edge list" << nl; << "Calculating labels of patch edges in mesh edge list" << nl;
// get reference to the list of edges on the patch // The list of edges on the patch
const edgeList& PatchEdges = edges(); const edgeList& PatchEdges = edges();
// The output storage
labelList meshEdges(PatchEdges.size());
const labelListList& EdgeFaces = edgeFaces(); const labelListList& EdgeFaces = edgeFaces();
// create the storage // The mesh points associated with the patch
labelList meshEdges(PatchEdges.size());
bool found = false;
// get reference to the points on the patch
const labelList& pp = meshPoints(); const labelList& pp = meshPoints();
// WARNING: Remember that local edges address into local point list; // WARNING: Remember that local edges address into local point list;
// local-to-global point label translation is necessary // local-to-global point label translation is necessary
forAll(PatchEdges, edgeI) forAll(PatchEdges, edgei)
{ {
const edge curEdge bool found = false;
(pp[PatchEdges[edgeI].start()], pp[PatchEdges[edgeI].end()]);
found = false; const edge globalEdge(pp, PatchEdges[edgei]);
// get the patch faces sharing the edge // For each patch face sharing the edge
const labelList& curFaces = EdgeFaces[edgeI]; for (const label patchFacei : EdgeFaces[edgei])
forAll(curFaces, facei)
{ {
// get the cell next to the face // The cell next to the face
label curCell = faceCells[curFaces[facei]]; const label curCelli = faceCells[patchFacei];
// get reference to edges on the cell // Check the cell edges
const labelList& ce = cellEdges[curCell]; for (const label cellEdgei : cellEdges[curCelli])
forAll(ce, cellEdgeI)
{ {
if (allEdges[ce[cellEdgeI]] == curEdge) if (allEdges[cellEdgei] == globalEdge)
{ {
found = true; found = true;
meshEdges[edgei] = cellEdgei;
meshEdges[edgeI] = ce[cellEdgeI];
break; break;
} }
} }
@ -107,29 +98,27 @@ Foam::PrimitivePatch<FaceList, PointField>::meshEdges
DebugInFunction DebugInFunction
<< "Calculating labels of patch edges in mesh edge list" << nl; << "Calculating labels of patch edges in mesh edge list" << nl;
// get reference to the list of edges on the patch // The list of edges on the patch
const edgeList& PatchEdges = edges(); const edgeList& PatchEdges = edges();
// create the storage // The output storage
labelList meshEdges(PatchEdges.size()); labelList meshEdges(PatchEdges.size());
// get reference to the points on the patch // The mesh points associated with the patch
const labelList& pp = meshPoints(); const labelList& pp = meshPoints();
// WARNING: Remember that local edges address into local point list; // WARNING: Remember that local edges address into local point list;
// local-to-global point label translation is necessary // local-to-global point label translation is necessary
forAll(PatchEdges, edgeI) forAll(PatchEdges, edgei)
{ {
const label globalPointi = pp[PatchEdges[edgeI].start()]; const edge globalEdge(pp, PatchEdges[edgei]);
const edge curEdge(globalPointi, pp[PatchEdges[edgeI].end()]);
const labelList& pe = pointEdges[globalPointi]; // Check the attached edges
for (const label patchEdgei : pointEdges[globalEdge.start()])
forAll(pe, i)
{ {
if (allEdges[pe[i]] == curEdge) if (allEdges[patchEdgei] == globalEdge)
{ {
meshEdges[edgeI] = pe[i]; meshEdges[edgei] = patchEdgei;
break; break;
} }
} }
@ -148,18 +137,16 @@ Foam::PrimitivePatch<FaceList, PointField>::whichEdge
const edge& e const edge& e
) const ) const
{ {
// Get pointEdges from the starting point and search all the candidates if (e.start() >= 0 && e.start() < nPoints())
const edgeList& Edges = edges();
if (e.start() > -1 && e.start() < nPoints())
{ {
const labelList& pe = pointEdges()[e.start()]; // Get pointEdges from the starting point and search all the candidates
const edgeList& Edges = edges();
forAll(pe, peI) for (const label patchEdgei : pointEdges()[e.start()])
{ {
if (e == Edges[pe[peI]]) if (e == Edges[patchEdgei])
{ {
return pe[peI]; return patchEdgei;
} }
} }
} }

View File

@ -54,8 +54,7 @@ Foam::PrimitivePatch<FaceList, PointField>::calcPointEdges() const
invertManyToMany(pe.size(), edges(), pe); invertManyToMany(pe.size(), edges(), pe);
DebugInfo DebugInfo << " Finished." << endl;
<< " Finished." << endl;
} }
@ -81,9 +80,7 @@ Foam::PrimitivePatch<FaceList, PointField>::calcPointFaces() const
forAll(locFcs, facei) forAll(locFcs, facei)
{ {
const face_type& curPoints = locFcs[facei]; for (const label pointi : locFcs[facei])
for (const label pointi : curPoints)
{ {
pointFcs[pointi].append(facei); pointFcs[pointi].append(facei);
} }
@ -98,8 +95,7 @@ Foam::PrimitivePatch<FaceList, PointField>::calcPointFaces() const
pf[pointi] = pointFcs[pointi]; pf[pointi] = pointFcs[pointi];
} }
DebugInfo DebugInfo << " Finished." << endl;
<< " Finished." << endl;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -200,7 +200,7 @@ Foam::PrimitivePatch<FaceList, PointField>::projectPoints
} }
} }
if (debug) Info<< "."; DebugInfo << '.';
} while (closer); } while (closer);
} }
@ -211,10 +211,7 @@ Foam::PrimitivePatch<FaceList, PointField>::projectPoints
{ {
nNSquaredSearches++; nNSquaredSearches++;
if (debug) DebugInfo << "p " << curLocalPointLabel << ": ";
{
Info<< "p " << curLocalPointLabel << ": ";
}
result[curLocalPointLabel] = objectHit(false, -1); result[curLocalPointLabel] = objectHit(false, -1);
scalar minDistance = GREAT; scalar minDistance = GREAT;
@ -254,23 +251,18 @@ Foam::PrimitivePatch<FaceList, PointField>::projectPoints
} }
} }
if (debug) DebugInfo << result[curLocalPointLabel] << nl;
{
Info<< result[curLocalPointLabel] << nl;
}
} }
else else
{ {
if (debug) Info<< "x"; DebugInfo << 'x';
} }
} }
if (debug) DebugInfo
{ << nl << "Executed " << nNSquaredSearches
Info<< nl << "Executed " << nNSquaredSearches << " n-squared searches out of total of "
<< " n-squared searches out of total of " << nPoints() << endl;
<< nPoints() << endl;
}
return result; return result;
} }
@ -439,7 +431,7 @@ Foam::PrimitivePatch<FaceList, PointField>::projectFaceCentres
} }
} }
if (debug) Info<< "."; DebugInfo << '.';
} while (closer); } while (closer);
} }
@ -447,10 +439,7 @@ Foam::PrimitivePatch<FaceList, PointField>::projectFaceCentres
{ {
nNSquaredSearches++; nNSquaredSearches++;
if (debug) DebugInfo << "p " << curLocalFaceLabel << ": ";
{
Info<< "p " << curLocalFaceLabel << ": ";
}
result[curLocalFaceLabel] = objectHit(false, -1); result[curLocalFaceLabel] = objectHit(false, -1);
scalar minDistance = GREAT; scalar minDistance = GREAT;
@ -490,23 +479,19 @@ Foam::PrimitivePatch<FaceList, PointField>::projectFaceCentres
} }
} }
if (debug) DebugInfo << result[curLocalFaceLabel] << nl;
{
Info<< result[curLocalFaceLabel] << nl;
}
} }
else else
{ {
if (debug) Info<< "x"; DebugInfo << 'x';
} }
} }
if (debug) DebugInfo
{ << nl
Info<< nl << "Executed " << nNSquaredSearches << "Executed " << nNSquaredSearches
<< " n-squared searches out of total of " << " n-squared searches out of total of "
<< this->size() << endl; << this->size() << endl;
}
return result; return result;
} }