FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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