Commit 8a5d108f authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: update PrimitivePatch (#1648)

- simplified templating, which cleans up code and does not appear to
  break any normal user coding.

ENH: unique_ptr instead of homegrown demand-driven handling.
parent 5c9f07df
......@@ -249,7 +249,7 @@ int main(int argc, char *argv[])
faceList patchFaces(patch);
pointField allPoints(patch.points());
PrimitivePatch<face, List, pointField, point> storedPatch
PrimitivePatch<List<face>, pointField> storedPatch
(
patchFaces,
allPoints,
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -53,7 +54,7 @@ class extrudedMesh
:
public polyMesh
{
// Private data
// Private Data
const extrudeModel& model_;
......@@ -64,26 +65,26 @@ class extrudedMesh
static bool sameOrder(const face&, const edge&);
//- Construct and return the extruded mesh points
template<class Face, template<class> class FaceList, class PointField>
template<class FaceList, class PointField>
pointField extrudedPoints
(
const PrimitivePatch<Face, FaceList, PointField>& extrudePatch,
const PrimitivePatch<FaceList, PointField>& extrudePatch,
const extrudeModel&
);
//- Construct and return the extruded mesh faces
template<class Face, template<class> class FaceList, class PointField>
template<class FaceList, class PointField>
faceList extrudedFaces
(
const PrimitivePatch<Face, FaceList, PointField>& extrudePatch,
const PrimitivePatch<FaceList, PointField>& extrudePatch,
const extrudeModel&
);
//- Construct and return the extruded mesh cells
template<class Face, template<class> class FaceList, class PointField>
template<class FaceList, class PointField>
cellList extrudedCells
(
const PrimitivePatch<Face, FaceList, PointField>& extrudePatch,
const PrimitivePatch<FaceList, PointField>& extrudePatch,
const extrudeModel&
);
......@@ -100,11 +101,11 @@ public:
// Constructors
//- Construct from the primitivePatch to extrude
template<class Face, template<class> class FaceList, class PointField>
template<class FaceList, class PointField>
extrudedMesh
(
const IOobject&,
const PrimitivePatch<Face, FaceList, PointField>& extrudePatch,
const PrimitivePatch<FaceList, PointField>& extrudePatch,
const extrudeModel&
);
};
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2012 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -30,15 +31,10 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template
<
class Face,
template<class> class FaceList,
class PointField
>
template<class FaceList, class PointField>
Foam::pointField Foam::extrudedMesh::extrudedPoints
(
const PrimitivePatch<Face, FaceList, PointField>& extrudePatch,
const PrimitivePatch<FaceList, PointField>& extrudePatch,
const extrudeModel& model
)
{
......@@ -68,10 +64,10 @@ Foam::pointField Foam::extrudedMesh::extrudedPoints
}
template<class Face, template<class> class FaceList, class PointField>
template<class FaceList, class PointField>
Foam::faceList Foam::extrudedMesh::extrudedFaces
(
const PrimitivePatch<Face, FaceList, PointField>& extrudePatch,
const PrimitivePatch<FaceList, PointField>& extrudePatch,
const extrudeModel& model
)
{
......@@ -194,10 +190,10 @@ Foam::faceList Foam::extrudedMesh::extrudedFaces
}
template<class Face, template<class> class FaceList, class PointField>
template<class FaceList, class PointField>
Foam::cellList Foam::extrudedMesh::extrudedCells
(
const PrimitivePatch<Face, FaceList, PointField>& extrudePatch,
const PrimitivePatch<FaceList, PointField>& extrudePatch,
const extrudeModel& model
)
{
......@@ -302,16 +298,11 @@ Foam::cellList Foam::extrudedMesh::extrudedCells
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template
<
class Face,
template<class> class FaceList,
class PointField
>
template<class FaceList, class PointField>
Foam::extrudedMesh::extrudedMesh
(
const IOobject& io,
const PrimitivePatch<Face, FaceList, PointField>& extrudePatch,
const PrimitivePatch<FaceList, PointField>& extrudePatch,
const extrudeModel& model
)
:
......
......@@ -81,7 +81,7 @@ SourceFiles
namespace Foam
{
typedef PrimitivePatch<face, List, const pointField, point> bPatch;
typedef PrimitivePatch<::Foam::List<face>, const pointField> bPatch;
typedef treeDataPrimitivePatch<bPatch> treeDataBPatch;
class Time;
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2017 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -199,7 +199,7 @@ Foam::tmp<Foam::triSurfacePointScalarField> Foam::automatic::load()
PrimitivePatchInterpolation
<
PrimitivePatch<labelledTri, ::Foam::List, pointField, point>
PrimitivePatch<::Foam::List<labelledTri>, pointField>
> patchInterpolate(surface_);
const Map<label>& meshPointMap = surface_.meshPointMap();
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2015 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -61,11 +61,11 @@ class nonUniformField
protected:
// Private typedef
// Typedefs
typedef PrimitivePatchInterpolation
<
PrimitivePatch<labelledTri, List, pointField, point>
PrimitivePatch<::Foam::List<labelledTri>, pointField>
> primitivePatchInterpolation;
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -57,7 +58,7 @@ SourceFiles
namespace Foam
{
// Forward declarations
// Forward Declarations
class polyMesh;
class bitSet;
class boundBox;
......@@ -73,16 +74,10 @@ public:
//- Check for orientation issues.
// Returns true if problems were found.
// If a normal flips across an edge, places it in the HashSet
template
<
class Face,
template<class> class FaceList,
class PointField,
class PointType
>
template<class FaceList, class PointField>
static bool checkOrientation
(
const PrimitivePatch<Face, FaceList, PointField, PointType>&,
const PrimitivePatch<FaceList, PointField>&,
const bool report = false,
labelHashSet* marked = 0
);
......@@ -91,17 +86,10 @@ public:
//- Fill faceZone with currentZone for every face reachable
// from facei without crossing edge marked in borderEdge.
// Note: faceZone has to be sized nFaces before calling.
template
<
class BoolListType,
class Face,
template<class> class FaceList,
class PointField,
class PointType
>
template<class BoolListType, class FaceList, class PointField>
static void markZone
(
const PrimitivePatch<Face, FaceList, PointField, PointType>&,
const PrimitivePatch<FaceList, PointField>&,
const BoolListType& borderEdge,
const label facei,
const label currentZone,
......@@ -111,17 +99,10 @@ public:
//- Size and fills faceZone with zone of face.
// Zone is area reachable by edge crossing without crossing borderEdge.
// Returns number of zones.
template
<
class BoolListType,
class Face,
template<class> class FaceList,
class PointField,
class PointType
>
template<class BoolListType, class FaceList, class PointField>
static label markZones
(
const PrimitivePatch<Face, FaceList, PointField, PointType>&,
const PrimitivePatch<FaceList, PointField>&,
const BoolListType& borderEdge,
labelList& faceZone
);
......@@ -132,78 +113,47 @@ public:
// \param[in] includeFaces faces to include
// \param[out] pointMap mapping new to old localPoints
// \param[out] faceMap mapping new to old faces
template
<
class BoolListType,
class Face,
template<class> class FaceList,
class PointField,
class PointType
>
template<class BoolListType, class FaceList, class PointField>
static void subsetMap
(
const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
const PrimitivePatch<FaceList, PointField>& p,
const BoolListType& includeFaces,
labelList& pointMap,
labelList& faceMap
);
//-
template
<
class Face,
template<class> class FaceList,
class PointField,
class PointType
>
template<class FaceList, class PointField>
static void calcBounds
(
const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
const PrimitivePatch<FaceList, PointField>& p,
boundBox& bb,
label& nPoints
);
//- Return edge-face addressing sorted by angle around the edge.
// Orientation is anticlockwise looking from edge.vec(localPoints())
template
<
class Face,
template<class> class FaceList,
class PointField,
class PointType
>
template<class FaceList, class PointField>
static labelListList sortedEdgeFaces
(
const PrimitivePatch<Face, FaceList, PointField, PointType>&
const PrimitivePatch<FaceList, PointField>&
);
//- Return point-edge addressing sorted by order around the point.
template
<
class Face,
template<class> class FaceList,
class PointField,
class PointType
>
template<class FaceList, class PointField>
static labelListList sortedPointEdges
(
const PrimitivePatch<Face, FaceList, PointField, PointType>&
const PrimitivePatch<FaceList, PointField>&
);
//- If 2 face neighbours: label of face where ordering of edge
// is consistent with righthand walk.
// If 1 neighbour: label of only face.
// If >2 neighbours: undetermined.
template
<
class Face,
template<class> class FaceList,
class PointField,
class PointType
>
template<class FaceList, class PointField>
static labelList edgeOwner
(
const PrimitivePatch<Face, FaceList, PointField, PointType>&
const PrimitivePatch<FaceList, PointField>&
);
......@@ -212,19 +162,13 @@ public:
// p2PointLabels : corresponding points on p2
template
<
class Face1,
template<class> class FaceList1,
class PointField1,
class PointType1,
class Face2,
template<class> class FaceList2,
class PointField2,
class PointType2
class FaceList1, class PointField1,
class FaceList2, class PointField2
>
static void matchPoints
(
const PrimitivePatch<Face1, FaceList1, PointField1, PointType1>& p1,
const PrimitivePatch<Face2, FaceList2, PointField2, PointType2>& p2,
const PrimitivePatch<FaceList1, PointField1>& p1,
const PrimitivePatch<FaceList2, PointField2>& p2,
labelList& p1PointLabels,
labelList& p2PointLabels
......@@ -236,19 +180,13 @@ public:
// sameOrientation : same orientation?
template
<
class Face1,
template<class> class FaceList1,
class PointField1,
class PointType1,
class Face2,
template<class> class FaceList2,
class PointField2,
class PointType2
class FaceList1, class PointField1,
class FaceList2, class PointField2
>
static void matchEdges
(
const PrimitivePatch<Face1, FaceList1, PointField1, PointType1>& p1,
const PrimitivePatch<Face2, FaceList2, PointField2, PointType2>& p2,
const PrimitivePatch<FaceList1, PointField1>& p1,
const PrimitivePatch<FaceList2, PointField2>& p2,
labelList& p1EdgeLabels,
labelList& p2EdgeLabels,
......@@ -257,33 +195,21 @@ public:
//- Return parallel consistent point normals for patches using mesh points.
template
<
class Face,
template<class> class FaceList,
class PointField,
class PointType
>
template<class FaceList, class PointField>
static tmp<pointField> pointNormals
(
const polyMesh&,
const PrimitivePatch<Face, FaceList, PointField, PointType>&
const PrimitivePatch<FaceList, PointField>&
);
//- Return parallel consistent edge normals for patches using mesh points.
// Supply with patch matching info from matchEdges.
template
<
class Face,
template<class> class FaceList,
class PointField,
class PointType
>
template<class FaceList, class PointField>
static tmp<pointField> edgeNormals
(
const polyMesh&,
const PrimitivePatch<Face, FaceList, PointField, PointType>&,
const PrimitivePatch<FaceList, PointField>&,
const labelList& patchEdges,
const labelList& coupledEdges
);
......@@ -291,19 +217,19 @@ public:
//- Gather points and faces onto master and merge into single patch.
// Note: uses faces/points, not localFaces/localPoints.
template
<
class Face,
template<class> class FaceList,
class PointField,
class PointType
>
template<class FaceList, class PointField>
static void gatherAndMerge
(
const scalar mergeDist,
const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
Field<PointType>& mergedPoints,
List<Face>& mergedFaces,
const PrimitivePatch<FaceList, PointField>& p,
Field
<
typename PrimitivePatch<FaceList, PointField>::point_type
>& mergedPoints,
List
<
typename PrimitivePatch<FaceList, PointField>::face_type
>& mergedFaces,
labelList& pointMergeMap
);
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -29,22 +30,17 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template
<
class Face,
template<class> class FaceList,
class PointField,
class PointType
>
template<class FaceList, class PointField>
bool
Foam::PatchTools::checkOrientation
(
const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
const PrimitivePatch<FaceList, PointField>& p,
const bool report,
labelHashSet* setPtr
)
{
typedef typename PrimitivePatch<FaceList, PointField>::face_type FaceType;
bool foundError = false;
// Check edge normals, face normals, point normals.
......@@ -93,7 +89,7 @@ Foam::PatchTools::checkOrientation
//
//- Compute normal from 3 points, use the first as the origin
// minor warpage should not be a problem
const Face& f = p[facei];
const FaceType& f = p[facei];
const point& p0 = p.points()[f[0]];
const point& p1 = p.points()[f[1]];
const point& p2 = p.points()[f.last()];
......@@ -126,8 +122,8 @@ Foam::PatchTools::checkOrientation
{
// we use localFaces() since edges() are LOCAL
// these are both already available
const Face& faceA = p.localFaces()[neighbouringFaces[0]];
const Face& faceB = p.localFaces()[neighbouringFaces[1]];
const FaceType& faceA = p.localFaces()[neighbouringFaces[0]];
const FaceType& faceB = p.localFaces()[neighbouringFaces[1]];
// If the faces are correctly oriented, the edges must go in
// different directions on connected faces.
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -29,23 +30,18 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template
<
class Face,
template<class> class FaceList,
class PointField,
class PointType
>
template<class FaceList, class PointField>
Foam::labelList
Foam::PatchTools::edgeOwner
(
const PrimitivePatch<Face, FaceList, PointField, PointType>& p
const PrimitivePatch<FaceList, PointField>& p
)
{
typedef typename PrimitivePatch<FaceList, PointField>::face_type FaceType;
const edgeList& edges = p.edges();
const labelListList& edgeFaces = p.edgeFaces();
const List<Face>& localFaces = p.localFaces();
const List<FaceType>& localFaces = p.localFaces();
// create the owner list
labelList edgeOwner(edges.size(), -1);
......@@ -62,13 +58,13 @@ Foam::PatchTools::edgeOwner
{
// Find the first face whose vertices are aligned with the edge.
// with multiply connected edges, this is the best we can do
forAll(nbrFaces, i)
for (const label nbrFacei : nbrFaces)
{
const Face& f = localFaces[nbrFaces[i]];
const FaceType& f = localFaces[nbrFacei];
if (f.edgeDirection(edges[edgeI]) > 0)
{
edgeOwner[edgeI] = nbrFaces[i];