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

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