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