PatchToolsSortPoints.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "PatchTools.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 template<class FaceList, class PointField>
36 (
38 )
39 {
40  // Now order the edges of each point according to whether they share a
41  // face
42  const labelListList& pointEdges = p.pointEdges();
43  const edgeList& edges = p.edges();
44  const labelListList& edgeFaces = p.edgeFaces();
45  const labelListList& faceEdges = p.faceEdges();
46 
47  // create the lists for the various results. (resized on completion)
48  labelListList sortedPointEdges(pointEdges);
49 
50  DynamicList<label> newEdgeList;
51 
52  forAll(pointEdges, pointi)
53  {
54  const labelList& pEdges = pointEdges[pointi];
55 
56  label nPointEdges = pEdges.size();
57 
58  label edgeI = pEdges[0];
59 
60  label prevFacei = edgeFaces[edgeI][0];
61 
62  newEdgeList.clear();
63  newEdgeList.setCapacity(nPointEdges);
64 
65  label nVisitedEdges = 0;
66 
67  do
68  {
69  newEdgeList.append(edgeI);
70 
71  // Cross edge to next face
72  const labelList& eFaces = edgeFaces[edgeI];
73 
74  if (eFaces.size() != 2)
75  {
76  break;
77  }
78 
79  label facei = eFaces[0];
80  if (facei == prevFacei)
81  {
82  facei = eFaces[1];
83  }
84 
85  // Cross face to next edge
86  const labelList& fEdges = faceEdges[facei];
87 
88  forAll(fEdges, feI)
89  {
90  const label nextEdgeI = fEdges[feI];
91  const edge& nextEdge = edges[nextEdgeI];
92 
93  if
94  (
95  nextEdgeI != edgeI
96  && (nextEdge.start() == pointi || nextEdge.end() == pointi)
97  )
98  {
99  edgeI = nextEdgeI;
100  break;
101  }
102  }
103 
104  prevFacei = facei;
105 
106  nVisitedEdges++;
107  if (nVisitedEdges > nPointEdges)
108  {
110  << "Unable to order pointEdges as the face connections "
111  << "are not circular" << nl
112  << " Original pointEdges = " << pEdges << nl
113  << " New pointEdges = " << newEdgeList
114  << endl;
115 
116  newEdgeList = pEdges;
117 
118  break;
119  }
120 
121  } while (edgeI != pEdges[0]);
122 
123  if (newEdgeList.size() == nPointEdges)
124  {
125  forAll(pEdges, eI)
126  {
127  if (!newEdgeList.found(pEdges[eI]))
128  {
130  << "Cannot find all original edges in the new list"
131  << nl
132  << " Original pointEdges = " << pEdges << nl
133  << " New pointEdges = " << newEdgeList
134  << endl;
135 
136  newEdgeList = pEdges;
137 
138  break;
139  }
140  }
141 
142  sortedPointEdges[pointi] = newEdgeList;
143  }
144  }
145 
146  return sortedPointEdges;
147 }
148 
149 
150 // ************************************************************************* //
p
volScalarField & p
Definition: createFieldRefs.H:8
PatchTools.H
Foam::DynamicList< label >
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:63
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::PatchTools::sortedPointEdges
static labelListList sortedPointEdges(const PrimitivePatch< FaceList, PointField > &)
Return point-edge addressing sorted by order around the point.
Foam::DynamicList::clear
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:391
Foam::DynamicList::setCapacity
void setCapacity(const label len)
Alter the size of the underlying storage.
Definition: DynamicListI.H:303
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::edge::start
label start() const
Return start (first) vertex label.
Definition: edgeI.H:95
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:511
Foam::edge::end
label end() const
Return end (last/second) vertex label.
Definition: edgeI.H:106
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::List< labelList >
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:79