1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 This function calculates the list of patch edges, defined on the list of
27 points supporting the patch. The edges are ordered:
28 - 0..nInternalEdges-1 : upper triangular order
29 - nInternalEdges.. : boundary edges (no particular order)
31 Other patch addressing information is also calculated:
32 - faceFaces with neighbour faces in ascending order
33 - edgeFaces with ascending face order
34 - faceEdges sorted according to edges of a face
36 \*---------------------------------------------------------------------------*/
38 #include "PrimitivePatch.H"
39 #include "DynamicList.H"
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 template<class> class FaceList,
52 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
53 calcAddressing() const
57 Info<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
58 << "calcAddressing() : calculating patch addressing"
62 if (edgesPtr_ || faceFacesPtr_ || edgeFacesPtr_ || faceEdgesPtr_)
64 // it is considered an error to attempt to recalculate
65 // if already allocated
68 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
70 ) << "addressing already calculated"
74 if (this->size() == 0)
76 // No faces in patch. All lists are empty
78 edgesPtr_ = new edgeList(0);
79 faceFacesPtr_ = new labelListList(0);
80 edgeFacesPtr_ = new labelListList(0);
81 faceEdgesPtr_ = new labelListList(0);
87 // Get reference to localFaces
88 const List<Face>& locFcs = localFaces();
90 // Get reference to pointFaces
91 const labelListList& pf = pointFaces();
93 // Guess the max number of edges and neighbours for a face
95 forAll (locFcs, faceI)
97 maxEdges += locFcs[faceI].size();
100 // Create the lists for the various results. (resized on completion)
101 edgesPtr_ = new edgeList(maxEdges);
102 edgeList& edges = *edgesPtr_;
104 edgeFacesPtr_ = new labelListList(maxEdges);
105 labelListList& edgeFaces = *edgeFacesPtr_;
107 // faceFaces created using a dynamic list. Cannot guess size because
108 // of multiple connections
109 List<DynamicList<label> > ff(locFcs.size());
111 faceEdgesPtr_ = new labelListList(locFcs.size());
112 labelListList& faceEdges = *faceEdgesPtr_;
114 // Count the number of face neighbours
115 labelList noFaceFaces(locFcs.size());
117 // initialise the lists of subshapes for each face to avoid duplication
118 edgeListList faceIntoEdges(locFcs.size());
120 forAll (locFcs, faceI)
122 faceIntoEdges[faceI] = locFcs[faceI].edges();
124 labelList& curFaceEdges = faceEdges[faceI];
125 curFaceEdges.setSize(faceIntoEdges[faceI].size());
127 forAll (curFaceEdges, faceEdgeI)
129 curFaceEdges[faceEdgeI] = -1;
133 // This algorithm will produce a separated list of edges, internal edges
134 // starting from 0 and boundary edges starting from the top and
141 // Note that faceIntoEdges is sorted acc. to local vertex numbering
142 // in face (i.e. curEdges[0] is edge between f[0] and f[1])
144 // For all local faces ...
145 forAll (locFcs, faceI)
147 // Get reference to vertices of current face and corresponding edges.
148 const Face& curF = locFcs[faceI];
149 const edgeList& curEdges = faceIntoEdges[faceI];
151 // Record the neighbour face. Multiple connectivity allowed
152 List<DynamicList<label> > neiFaces(curF.size());
153 List<DynamicList<label> > edgeOfNeiFace(curF.size());
155 label nNeighbours = 0;
158 forAll (curEdges, edgeI)
160 // If the edge is already detected, skip
161 if (faceEdges[faceI][edgeI] >= 0) continue;
165 // Set reference to the current edge
166 const edge& e = curEdges[edgeI];
168 // Collect neighbours for the current face vertex.
170 const labelList& nbrFaces = pf[e.start()];
172 forAll (nbrFaces, nbrFaceI)
174 // set reference to the current neighbour
175 label curNei = nbrFaces[nbrFaceI];
177 // Reject neighbours with the lower label
180 // get the reference to subshapes of the neighbour
181 const edgeList& searchEdges = faceIntoEdges[curNei];
183 forAll (searchEdges, neiEdgeI)
185 if (searchEdges[neiEdgeI] == e)
190 neiFaces[edgeI].append(curNei);
191 edgeOfNeiFace[edgeI].append(neiEdgeI);
193 // Record faceFaces both ways
194 ff[faceI].append(curNei);
195 ff[curNei].append(faceI);
197 // Keep searching due to multiple connectivity
201 } // End of neighbouring faces
205 // Register another detected internal edge
208 } // End of current edges
210 // Add the edges in increasing number of neighbours.
211 // Note: for multiply connected surfaces, the lower index neighbour for
212 // an edge will come first.
214 // Add the faces in the increasing order of neighbours
215 for (label neiSearch = 0; neiSearch < nNeighbours; neiSearch++)
217 // Find the lowest neighbour which is still valid
219 label minNei = locFcs.size();
221 forAll (neiFaces, nfI)
223 if (neiFaces[nfI].size() && neiFaces[nfI][0] < minNei)
226 minNei = neiFaces[nfI][0];
232 // Add the face to the list of faces
233 edges[nEdges] = curEdges[nextNei];
235 // Set face-edge and face-neighbour-edge to current face label
236 faceEdges[faceI][nextNei] = nEdges;
238 DynamicList<label>& cnf = neiFaces[nextNei];
239 DynamicList<label>& eonf = edgeOfNeiFace[nextNei];
241 // Set edge-face addressing
242 labelList& curEf = edgeFaces[nEdges];
243 curEf.setSize(cnf.size() + 1);
248 faceEdges[cnf[cnfI]][eonf[cnfI]] = nEdges;
250 curEf[cnfI + 1] = cnf[cnfI];
253 // Stop the neighbour from being used again
257 // Increment number of faces counter
264 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
266 ) << "Error in internal edge insertion"
267 << abort(FatalError);
272 nInternalEdges_ = nEdges;
276 forAll (faceEdges, faceI)
278 labelList& curEdges = faceEdges[faceI];
280 forAll (curEdges, edgeI)
282 if (curEdges[edgeI] < 0)
284 // Grab edge and faceEdge
285 edges[nEdges] = faceIntoEdges[faceI][edgeI];
286 curEdges[edgeI] = nEdges;
289 labelList& curEf = edgeFaces[nEdges];
299 edges.setSize(nEdges);
302 edgeFaces.setSize(nEdges);
305 faceFacesPtr_ = new labelListList(locFcs.size());
306 labelListList& faceFaces = *faceFacesPtr_;
308 forAll (faceFaces, faceI)
310 faceFaces[faceI].transfer(ff[faceI]);
316 Info<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
317 << "calcAddressing() : finished calculating patch addressing"
323 // ************************************************************************* //