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-2019 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<class FaceList, class PointField>
32 (
34 )
35 {
36  // Now order the edges of each point according to whether they share a
37  // face
38  const labelListList& pointEdges = p.pointEdges();
39  const edgeList& edges = p.edges();
40  const labelListList& edgeFaces = p.edgeFaces();
41  const labelListList& faceEdges = p.faceEdges();
42 
43  // create the lists for the various results. (resized on completion)
44  labelListList sortedPointEdges(pointEdges);
45 
46  DynamicList<label> newEdgeList;
47 
48  forAll(pointEdges, pointi)
49  {
50  const labelList& pEdges = pointEdges[pointi];
51 
52  label nPointEdges = pEdges.size();
53 
54  label edgeI = pEdges[0];
55 
56  label prevFacei = edgeFaces[edgeI][0];
57 
58  newEdgeList.clear();
59  newEdgeList.setCapacity(nPointEdges);
60 
61  label nVisitedEdges = 0;
62 
63  do
64  {
65  newEdgeList.append(edgeI);
66 
67  // Cross edge to next face
68  const labelList& eFaces = edgeFaces[edgeI];
69 
70  if (eFaces.size() != 2)
71  {
72  break;
73  }
74 
75  label facei = eFaces[0];
76  if (facei == prevFacei)
77  {
78  facei = eFaces[1];
79  }
80 
81  // Cross face to next edge
82  const labelList& fEdges = faceEdges[facei];
83 
84  forAll(fEdges, feI)
85  {
86  const label nextEdgeI = fEdges[feI];
87  const edge& nextEdge = edges[nextEdgeI];
88 
89  if
90  (
91  nextEdgeI != edgeI
92  && (nextEdge.start() == pointi || nextEdge.end() == pointi)
93  )
94  {
95  edgeI = nextEdgeI;
96  break;
97  }
98  }
99 
100  prevFacei = facei;
101 
102  nVisitedEdges++;
103  if (nVisitedEdges > nPointEdges)
104  {
106  << "Unable to order pointEdges as the face connections "
107  << "are not circular" << nl
108  << " Original pointEdges = " << pEdges << nl
109  << " New pointEdges = " << newEdgeList
110  << endl;
111 
112  newEdgeList = pEdges;
113 
114  break;
115  }
116 
117  } while (edgeI != pEdges[0]);
118 
119  if (newEdgeList.size() == nPointEdges)
120  {
121  forAll(pEdges, eI)
122  {
123  if (findIndex(newEdgeList, pEdges[eI]) == -1)
124  {
126  << "Cannot find all original edges in the new list"
127  << nl
128  << " Original pointEdges = " << pEdges << nl
129  << " New pointEdges = " << newEdgeList
130  << endl;
131 
132  newEdgeList = pEdges;
133 
134  break;
135  }
136  }
137 
138  sortedPointEdges[pointi] = newEdgeList;
139  }
140  }
141 
142  return sortedPointEdges;
143 }
144 
145 
146 // ************************************************************************* //
const labelListList & pointEdges() const
Return point-edge addressing.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
A list of faces which address into the list of points.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
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:130
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
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:260
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:236
label start() const
Return start vertex label.
Definition: edgeI.H:81
static labelListList sortedPointEdges(const PrimitivePatch< FaceList, PointField > &)
Return point-edge addressing sorted by order around the point.