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