PrimitivePatchMeshEdges.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 | Copyright (C) 2011-2016 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 "PrimitivePatch.H"
27 
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 template
32 <
33  class Face,
34  template<class> class FaceList,
35  class PointField,
36  class PointType
37 >
41 (
42  const edgeList& allEdges,
43  const labelListList& cellEdges,
44  const labelList& faceCells
45 ) const
46 {
47  if (debug)
48  {
49  Info<< "labelList PrimitivePatch<Face, FaceList, PointField, PointType>"
50  << "::meshEdges() : "
51  << "calculating labels of patch edges in mesh edge list"
52  << endl;
53  }
54 
55  // get reference to the list of edges on the patch
56  const edgeList& PatchEdges = edges();
57 
58  const labelListList& EdgeFaces = edgeFaces();
59 
60  // create the storage
61  labelList meshEdges(PatchEdges.size());
62 
63  bool found = false;
64 
65  // get reference to the points on the patch
66  const labelList& pp = meshPoints();
67 
68  // WARNING: Remember that local edges address into local point list;
69  // local-to-global point label translation is necessary
70  forAll(PatchEdges, edgeI)
71  {
72  const edge curEdge
73  (pp[PatchEdges[edgeI].start()], pp[PatchEdges[edgeI].end()]);
74 
75  found = false;
76 
77  // get the patch faces sharing the edge
78  const labelList& curFaces = EdgeFaces[edgeI];
79 
80  forAll(curFaces, facei)
81  {
82  // get the cell next to the face
83  label curCell = faceCells[curFaces[facei]];
84 
85  // get reference to edges on the cell
86  const labelList& ce = cellEdges[curCell];
87 
88  forAll(ce, cellEdgeI)
89  {
90  if (allEdges[ce[cellEdgeI]] == curEdge)
91  {
92  found = true;
93 
94  meshEdges[edgeI] = ce[cellEdgeI];
95 
96  break;
97  }
98  }
99 
100  if (found) break;
101  }
102  }
103 
104  return meshEdges;
105 }
106 
107 
108 template
109 <
110  class Face,
111  template<class> class FaceList,
112  class PointField,
113  class PointType
114 >
117 meshEdges
118 (
119  const edgeList& allEdges,
120  const labelListList& pointEdges
121 ) const
122 {
123  if (debug)
124  {
125  Info<< "labelList PrimitivePatch<Face, FaceList, PointField, PointType>"
126  << "::meshEdges() : "
127  << "calculating labels of patch edges in mesh edge list"
128  << endl;
129  }
130 
131  // get reference to the list of edges on the patch
132  const edgeList& PatchEdges = edges();
133 
134  // create the storage
135  labelList meshEdges(PatchEdges.size());
136 
137  // get reference to the points on the patch
138  const labelList& pp = meshPoints();
139 
140  // WARNING: Remember that local edges address into local point list;
141  // local-to-global point label translation is necessary
142  forAll(PatchEdges, edgeI)
143  {
144  const label globalPointi = pp[PatchEdges[edgeI].start()];
145  const edge curEdge(globalPointi, pp[PatchEdges[edgeI].end()]);
146 
147  const labelList& pe = pointEdges[globalPointi];
148 
149  forAll(pe, i)
150  {
151  if (allEdges[pe[i]] == curEdge)
152  {
153  meshEdges[edgeI] = pe[i];
154  break;
155  }
156  }
157  }
158 
159  return meshEdges;
160 }
161 
162 
163 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
164 
165 template
166 <
167  class Face,
168  template<class> class FaceList,
169  class PointField,
170  class PointType
171 >
174 whichEdge
175 (
176  const edge& e
177 ) const
178 {
179  // Get pointEdges from the starting point and search all the candidates
180  const edgeList& Edges = edges();
181 
182  if (e.start() > -1 && e.start() < nPoints())
183  {
184  const labelList& pe = pointEdges()[e.start()];
185 
186  forAll(pe, peI)
187  {
188  if (e == Edges[pe[peI]])
189  {
190  return pe[peI];
191  }
192  }
193  }
194 
195  // Edge not found. Return -1
196  return -1;
197 }
198 
199 
200 // ************************************************************************* //
#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:76
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
label nPoints
label start() const
Return start vertex label.
Definition: edgeI.H:81
label whichEdge(const edge &) const
Given an edge in local point labels, return its.
messageStream Info
labelList meshEdges(const edgeList &allEdges, const labelListList &cellEdges, const labelList &faceCells) const
Return labels of patch edges in the global edge list using.
bool found