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

primitiveMeshCellEdges.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 \*---------------------------------------------------------------------------*/
00025 
00026 #include "primitiveMesh.H"
00027 #include <OpenFOAM/DynamicList.H>
00028 #include <OpenFOAM/ListOps.H>
00029 
00030 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00031 
00032 void Foam::primitiveMesh::calcCellEdges() const
00033 {
00034     // Loop through all faces and mark up cells with edges of the face.
00035     // Check for duplicates
00036 
00037     if (debug)
00038     {
00039         Pout<< "primitiveMesh::calcCellEdges() : "
00040             << "calculating cellEdges"
00041             << endl;
00042 
00043         if (debug == -1)
00044         {
00045             // For checking calls:abort so we can quickly hunt down
00046             // origin of call
00047             FatalErrorIn("primitiveMesh::calcCellEdges()")
00048                 << abort(FatalError);
00049         }
00050     }
00051 
00052     // It is an error to attempt to recalculate cellEdges
00053     // if the pointer is already set
00054     if (cePtr_)
00055     {
00056         FatalErrorIn("primitiveMesh::calcCellEdges() const")
00057             << "cellEdges already calculated"
00058             << abort(FatalError);
00059     }
00060     else
00061     {
00062         // Set up temporary storage
00063         List<DynamicList<label, edgesPerCell_> > ce(nCells());
00064 
00065 
00066         // Get reference to faceCells and faceEdges
00067         const labelList& own = faceOwner();
00068         const labelList& nei = faceNeighbour();
00069         const labelListList& fe = faceEdges();
00070 
00071         // loop through the list again and add edges; checking for duplicates
00072         forAll (own, faceI)
00073         {
00074             DynamicList<label, edgesPerCell_>& curCellEdges = ce[own[faceI]];
00075 
00076             const labelList& curEdges = fe[faceI];
00077 
00078             forAll (curEdges, edgeI)
00079             {
00080                 if (findIndex(curCellEdges, curEdges[edgeI]) == -1)
00081                 {
00082                     // Add the edge
00083                     curCellEdges.append(curEdges[edgeI]);
00084                 }
00085             }
00086         }
00087 
00088         forAll (nei, faceI)
00089         {
00090             DynamicList<label, edgesPerCell_>& curCellEdges = ce[nei[faceI]];
00091 
00092             const labelList& curEdges = fe[faceI];
00093 
00094             forAll (curEdges, edgeI)
00095             {
00096                 if (findIndex(curCellEdges, curEdges[edgeI]) == -1)
00097                 {
00098                     // add the edge
00099                     curCellEdges.append(curEdges[edgeI]);
00100                 }
00101             }
00102         }
00103 
00104         cePtr_ = new labelListList(ce.size());
00105         labelListList& cellEdgeAddr = *cePtr_;
00106 
00107         // reset the size
00108         forAll (ce, cellI)
00109         {
00110             cellEdgeAddr[cellI].transfer(ce[cellI]);
00111         }
00112     }
00113 }
00114 
00115 
00116 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00117 
00118 const Foam::labelListList& Foam::primitiveMesh::cellEdges() const
00119 {
00120     if (!cePtr_)
00121     {
00122         calcCellEdges();
00123     }
00124 
00125     return *cePtr_;
00126 }
00127 
00128 
00129 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines