Preconditioning bugfix by Alexander Monakov
[OpenFOAM-1.6-ext.git] / src / OpenFOAM / meshes / primitiveMesh / primitiveMeshCellEdges.C
blob3662b5ea874e0d69dc8da2986f295089696da566
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "primitiveMesh.H"
28 #include "DynamicList.H"
29 #include "ListOps.H"
31 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
33 void Foam::primitiveMesh::calcCellEdges() const
35     // Loop through all faces and mark up cells with edges of the face.
36     // Check for duplicates
38     if (debug)
39     {
40         Pout<< "primitiveMesh::calcCellEdges() : "
41             << "calculating cellEdges"
42             << endl;
44         if (debug == -1)
45         {
46             // For checking calls:abort so we can quickly hunt down
47             // origin of call
48             FatalErrorIn("primitiveMesh::calcCellEdges()")
49                 << abort(FatalError);
50         }
51     }
53     // It is an error to attempt to recalculate cellEdges
54     // if the pointer is already set
55     if (cePtr_)
56     {
57         FatalErrorIn("primitiveMesh::calcCellEdges() const")
58             << "cellEdges already calculated"
59             << abort(FatalError);
60     }
61     else
62     {
63         // Set up temporary storage
64         List<DynamicList<label, edgesPerCell_> > ce(nCells());
67         // Get reference to faceCells and faceEdges
68         const labelList& own = faceOwner();
69         const labelList& nei = faceNeighbour();
70         const labelListList& fe = faceEdges();
72         // loop through the list again and add edges; checking for duplicates
73         forAll (own, faceI)
74         {
75             DynamicList<label, edgesPerCell_>& curCellEdges = ce[own[faceI]];
77             const labelList& curEdges = fe[faceI];
79             forAll (curEdges, edgeI)
80             {
81                 if (findIndex(curCellEdges, curEdges[edgeI]) == -1)
82                 {
83                     // Add the edge
84                     curCellEdges.append(curEdges[edgeI]);
85                 }
86             }
87         }
89         forAll (nei, faceI)
90         {
91             DynamicList<label, edgesPerCell_>& curCellEdges = ce[nei[faceI]];
93             const labelList& curEdges = fe[faceI];
95             forAll (curEdges, edgeI)
96             {
97                 if (findIndex(curCellEdges, curEdges[edgeI]) == -1)
98                 {
99                     // add the edge
100                     curCellEdges.append(curEdges[edgeI]);
101                 }
102             }
103         }
105         cePtr_ = new labelListList(ce.size());
106         labelListList& cellEdgeAddr = *cePtr_;
108         // reset the size
109         forAll (ce, cellI)
110         {
111             cellEdgeAddr[cellI].transfer(ce[cellI]);
112         }
113     }
117 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
119 const Foam::labelListList& Foam::primitiveMesh::cellEdges() const
121     if (!cePtr_)
122     {
123         calcCellEdges();
124     }
126     return *cePtr_;
130 // ************************************************************************* //