OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

PrimitivePatchAddressing.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026     This function calculates the list of patch edges, defined on the list of
00027     points supporting the patch. The edges are ordered:
00028     - 0..nInternalEdges-1 : upper triangular order
00029     - nInternalEdges..    : boundary edges (no particular order)
00030 
00031     Other patch addressing information is also calculated:
00032     - faceFaces with neighbour faces in ascending order
00033     - edgeFaces with ascending face order
00034     - faceEdges sorted according to edges of a face
00035 
00036 \*---------------------------------------------------------------------------*/
00037 
00038 #include "PrimitivePatch.H"
00039 #include "DynamicList.H"
00040 
00041 
00042 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00043 
00044 template
00045 <
00046     class Face,
00047     template<class> class FaceList,
00048     class PointField,
00049     class PointType
00050 >
00051 
00052 void
00053 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
00054 calcAddressing() const
00055 {
00056     if (debug)
00057     {
00058         Info<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00059             << "calcAddressing() : calculating patch addressing"
00060             << endl;
00061     }
00062 
00063     if (edgesPtr_ || faceFacesPtr_ || edgeFacesPtr_ || faceEdgesPtr_)
00064     {
00065         // it is considered an error to attempt to recalculate
00066         // if already allocated
00067         FatalErrorIn
00068         (
00069             "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00070             "calcAddressing()"
00071         )   << "addressing already calculated"
00072             << abort(FatalError);
00073     }
00074 
00075     // get reference to localFaces
00076     const List<Face>& locFcs = localFaces();
00077 
00078     // get reference to pointFaces
00079     const labelListList& pf = pointFaces();
00080 
00081     // Guess the max number of edges and neighbours for a face
00082     label maxEdges = 0;
00083     forAll (locFcs, faceI)
00084     {
00085         maxEdges += locFcs[faceI].size();
00086     }
00087 
00088     // create the lists for the various results. (resized on completion)
00089     edgesPtr_ = new edgeList(maxEdges);
00090     edgeList& edges = *edgesPtr_;
00091 
00092     edgeFacesPtr_ = new labelListList(maxEdges);
00093     labelListList& edgeFaces = *edgeFacesPtr_;
00094 
00095     // faceFaces created using a dynamic list.  Cannot guess size because
00096     // of multiple connections
00097     List<DynamicList<label> > ff(locFcs.size());
00098 
00099     faceEdgesPtr_ = new labelListList(locFcs.size());
00100     labelListList& faceEdges = *faceEdgesPtr_;
00101 
00102     // count the number of face neighbours
00103     labelList noFaceFaces(locFcs.size());
00104 
00105     // initialise the lists of subshapes for each face to avoid duplication
00106     edgeListList faceIntoEdges(locFcs.size());
00107 
00108     forAll (locFcs, faceI)
00109     {
00110         faceIntoEdges[faceI] = locFcs[faceI].edges();
00111 
00112         labelList& curFaceEdges = faceEdges[faceI];
00113         curFaceEdges.setSize(faceIntoEdges[faceI].size());
00114 
00115         forAll (curFaceEdges, faceEdgeI)
00116         {
00117             curFaceEdges[faceEdgeI] = -1;
00118         }
00119     }
00120 
00121     // This algorithm will produce a separated list of edges, internal edges
00122     // starting from 0 and boundary edges starting from the top and
00123     // growing down.
00124 
00125     label nEdges = 0;
00126 
00127     bool found = false;
00128 
00129     // Note that faceIntoEdges is sorted acc. to local vertex numbering
00130     // in face (i.e. curEdges[0] is edge between f[0] and f[1])
00131 
00132     // For all local faces ...
00133     forAll (locFcs, faceI)
00134     {
00135         // Get reference to vertices of current face and corresponding edges.
00136         const Face& curF = locFcs[faceI];
00137         const edgeList& curEdges = faceIntoEdges[faceI];
00138 
00139         // Record the neighbour face.  Multiple connectivity allowed
00140         List<DynamicList<label> > neiFaces(curF.size());
00141         List<DynamicList<label> > edgeOfNeiFace(curF.size());
00142 
00143         label nNeighbours = 0;
00144 
00145         // For all edges ...
00146         forAll (curEdges, edgeI)
00147         {
00148             // If the edge is already detected, skip
00149             if (faceEdges[faceI][edgeI] >= 0) continue;
00150 
00151             found = false;
00152 
00153             // Set reference to the current edge
00154             const edge& e = curEdges[edgeI];
00155 
00156             // Collect neighbours for the current face vertex.
00157 
00158             const labelList& nbrFaces = pf[e.start()];
00159 
00160             forAll (nbrFaces, nbrFaceI)
00161             {
00162                 // set reference to the current neighbour
00163                 label curNei = nbrFaces[nbrFaceI];
00164 
00165                 // Reject neighbours with the lower label
00166                 if (curNei > faceI)
00167                 {
00168                     // get the reference to subshapes of the neighbour
00169                     const edgeList& searchEdges = faceIntoEdges[curNei];
00170 
00171                     forAll (searchEdges, neiEdgeI)
00172                     {
00173                         if (searchEdges[neiEdgeI] == e)
00174                         {
00175                             // Match
00176                             found = true;
00177 
00178                             neiFaces[edgeI].append(curNei);
00179                             edgeOfNeiFace[edgeI].append(neiEdgeI);
00180 
00181                             // Record faceFaces both ways
00182                             ff[faceI].append(curNei);
00183                             ff[curNei].append(faceI);
00184 
00185                             // Keep searching due to multiple connectivity
00186                         }
00187                     }
00188                 }
00189             } // End of neighbouring faces
00190 
00191             if (found)
00192             {
00193                 // Register another detected internal edge
00194                 nNeighbours++;
00195             }
00196         } // End of current edges
00197 
00198         // Add the edges in increasing number of neighbours.
00199         // Note: for multiply connected surfaces, the lower index neighbour for
00200         // an edge will come first.
00201 
00202         // Add the faces in the increasing order of neighbours
00203         for (label neiSearch = 0; neiSearch < nNeighbours; neiSearch++)
00204         {
00205             // Find the lowest neighbour which is still valid
00206             label nextNei = -1;
00207             label minNei = locFcs.size();
00208 
00209             forAll (neiFaces, nfI)
00210             {
00211                 if (neiFaces[nfI].size() && neiFaces[nfI][0] < minNei)
00212                 {
00213                     nextNei = nfI;
00214                     minNei = neiFaces[nfI][0];
00215                 }
00216             }
00217 
00218             if (nextNei > -1)
00219             {
00220                 // Add the face to the list of faces
00221                 edges[nEdges] = curEdges[nextNei];
00222 
00223                 // Set face-edge and face-neighbour-edge to current face label
00224                 faceEdges[faceI][nextNei] = nEdges;
00225 
00226                 DynamicList<label>& cnf = neiFaces[nextNei];
00227                 DynamicList<label>& eonf = edgeOfNeiFace[nextNei];
00228 
00229                 // Set edge-face addressing
00230                 labelList& curEf = edgeFaces[nEdges];
00231                 curEf.setSize(cnf.size() + 1);
00232                 curEf[0] = faceI;
00233 
00234                 forAll (cnf, cnfI)
00235                 {
00236                     faceEdges[cnf[cnfI]][eonf[cnfI]] = nEdges;
00237 
00238                     curEf[cnfI + 1] = cnf[cnfI];
00239                 }
00240 
00241                 // Stop the neighbour from being used again
00242                 cnf.clear();
00243                 eonf.clear();
00244 
00245                 // Increment number of faces counter
00246                 nEdges++;
00247             }
00248             else
00249             {
00250                 FatalErrorIn
00251                 (
00252                     "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00253                     "calcAddressing()"
00254                 )   << "Error in internal edge insertion"
00255                     << abort(FatalError);
00256             }
00257         }
00258     }
00259 
00260     nInternalEdges_ = nEdges;
00261 
00262     // Do boundary faces
00263 
00264     forAll (faceEdges, faceI)
00265     {
00266         labelList& curEdges = faceEdges[faceI];
00267 
00268         forAll (curEdges, edgeI)
00269         {
00270             if (curEdges[edgeI] < 0)
00271             {
00272                 // Grab edge and faceEdge
00273                 edges[nEdges] = faceIntoEdges[faceI][edgeI];
00274                 curEdges[edgeI] = nEdges;
00275 
00276                 // Add edgeFace
00277                 labelList& curEf = edgeFaces[nEdges];
00278                 curEf.setSize(1);
00279                 curEf[0] = faceI;
00280 
00281                 nEdges++;
00282             }
00283         }
00284     }
00285 
00286     // edges
00287     edges.setSize(nEdges);
00288 
00289     // edgeFaces list
00290     edgeFaces.setSize(nEdges);
00291 
00292     // faceFaces list
00293     faceFacesPtr_ = new labelListList(locFcs.size());
00294     labelListList& faceFaces = *faceFacesPtr_;
00295 
00296     forAll (faceFaces, faceI)
00297     {
00298         faceFaces[faceI].transfer(ff[faceI]);
00299     }
00300 
00301 
00302     if (debug)
00303     {
00304         Info<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00305             << "calcAddressing() : finished calculating patch addressing"
00306             << endl;
00307     }
00308 }
00309 
00310 
00311 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd