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

PrimitivePatchEdgeLoops.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     Create the list of loops of outside vertices. Goes wrong on multiply
00027     connected edges (loops will be unclosed).
00028 
00029 \*---------------------------------------------------------------------------*/
00030 
00031 #include "PrimitivePatch.H"
00032 
00033 
00034 
00035 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00036 
00037 template
00038 <
00039     class Face,
00040     template<class> class FaceList,
00041     class PointField,
00042     class PointType
00043 >
00044 
00045 void
00046 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
00047 calcEdgeLoops() const
00048 {
00049     if (debug)
00050     {
00051         Info<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00052             << "calcEdgeLoops() : "
00053             << "calculating boundary edge loops"
00054             << endl;
00055     }
00056 
00057     if (edgeLoopsPtr_)
00058     {
00059         // it is considered an error to attempt to recalculate
00060         // if already allocated
00061         FatalErrorIn
00062         (
00063             "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00064             "calcIntBdryEdges()"
00065         )   << "edge loops already calculated"
00066             << abort(FatalError);
00067     }
00068 
00069     const edgeList& patchEdges = edges();
00070     label nIntEdges = nInternalEdges();
00071     label nBdryEdges = patchEdges.size() - nIntEdges;
00072 
00073     if (nBdryEdges == 0)
00074     {
00075         edgeLoopsPtr_ = new labelListList(0);
00076         return;
00077     }
00078 
00079     const labelListList& patchPointEdges = pointEdges();
00080 
00081 
00082     //
00083     // Walk point-edge-point and assign loop number
00084     //
00085 
00086     // Loop per (boundary) edge.
00087     labelList loopNumber(nBdryEdges, -1);
00088 
00089     // Size return list plenty big
00090     edgeLoopsPtr_ = new labelListList(nBdryEdges);
00091     labelListList& edgeLoops = *edgeLoopsPtr_;
00092 
00093 
00094     // Current loop number.
00095     label loopI = 0;
00096 
00097     while (true)
00098     {
00099         // Find edge not yet given a loop number.
00100         label currentEdgeI = -1;
00101 
00102         for (label edgeI = nIntEdges; edgeI < patchEdges.size(); edgeI++)
00103         {
00104             if (loopNumber[edgeI-nIntEdges] == -1)
00105             {
00106                 currentEdgeI = edgeI;
00107                 break;
00108             }
00109         }
00110 
00111         if (currentEdgeI == -1)
00112         {
00113             // Did not find edge not yet assigned a loop number so done all.
00114             break;
00115         }
00116 
00117         // Temporary storage for vertices of current loop
00118         DynamicList<label> loop(nBdryEdges);
00119 
00120         // Walk from first all the way round, assigning loops
00121         label currentVertI = patchEdges[currentEdgeI].start();
00122 
00123         do
00124         {
00125             loop.append(currentVertI);
00126 
00127             loopNumber[currentEdgeI - nIntEdges] = loopI;
00128 
00129             // Step to next vertex
00130             currentVertI = patchEdges[currentEdgeI].otherVertex(currentVertI);
00131 
00132             // Step to next (unmarked, boundary) edge.
00133             const labelList& curEdges = patchPointEdges[currentVertI];
00134 
00135             currentEdgeI = -1;
00136 
00137             forAll(curEdges, pI)
00138             {
00139                 label edgeI = curEdges[pI];
00140 
00141                 if (edgeI >= nIntEdges && (loopNumber[edgeI - nIntEdges] == -1))
00142                 {
00143                     // Unassigned boundary edge.
00144                     currentEdgeI = edgeI;
00145 
00146                     break;
00147                 }
00148             }
00149         }
00150         while (currentEdgeI != -1);
00151 
00152         // Done all for current loop. Transfer to edgeLoops.
00153         edgeLoops[loopI].transfer(loop);
00154 
00155         loopI++;
00156     }
00157 
00158     edgeLoops.setSize(loopI);
00159 
00160     if (debug)
00161     {
00162         Info<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00163             << "calcEdgeLoops() : "
00164             << "finished calculating boundary edge loops"
00165             << endl;
00166     }
00167 }
00168 
00169 
00170 template
00171 <
00172     class Face,
00173     template<class> class FaceList,
00174     class PointField,
00175     class PointType
00176 >
00177 
00178 const Foam::labelListList&
00179 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
00180 edgeLoops() const
00181 {
00182     if (!edgeLoopsPtr_)
00183     {
00184         calcEdgeLoops();
00185     }
00186 
00187     return *edgeLoopsPtr_;
00188 }
00189 
00190 
00191 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd