1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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
27 \*---------------------------------------------------------------------------*/
29 #include "cellAddressing.H"
30 #include "labelHashSet.H"
31 #include "cellModel.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 Foam::labelList Foam::cellAddressing::makeIdentity(const label size)
38 labelList result(size);
39 forAll(result, resultI)
41 result[resultI] = resultI;
47 Foam::label Foam::cellAddressing::findEdge(const edge& e)
51 if (edges_[edgeI] == e)
58 "cellAddressing::findEdge(const edge&)"
59 ) << "Problem: cannot find edge " << e << " in edges " << edges_
66 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
68 // Construct from components
69 Foam::cellAddressing::cellAddressing(const Foam::cellModel& model)
71 modelFaces_(model.modelFaces()),
72 edges_(model.edges(makeIdentity(model.nPoints()))),
73 edgeFaces_(model.nEdges()),
74 faceEdges_(model.nFaces()),
75 pointEdges_(model.nPoints())
77 List<labelHashSet > dynEdgeFaces(edgeFaces_.size());
79 forAll(faceEdges_, faceI)
81 DynamicList<label> fEdges;
83 const face& f = modelFaces_[faceI];
87 label edgeI = findEdge(edge(f[fp], f[(fp+1)%f.size()]));
89 // Append to faceEdges
92 // Append to edgefaces
93 labelHashSet& eFaces = dynEdgeFaces[edgeI];
95 if (!eFaces.found(faceI))
102 // Copy into faceEdges_
103 faceEdges_[faceI].transfer(fEdges.shrink());
106 // Convert dynEdgeFaces into edgeFaces_
108 forAll(dynEdgeFaces, edgeI)
110 edgeFaces_[edgeI] = dynEdgeFaces[edgeI].toc();
114 // Convert edges_ into pointEdges
115 List<DynamicList<label> > dynPointEdges(model.nPoints());
117 forAll(edges_, edgeI)
119 const edge& e = edges_[edgeI];
121 dynPointEdges[e.start()].append(edgeI);
122 dynPointEdges[e.end()].append(edgeI);
125 forAll(dynPointEdges, pointI)
127 pointEdges_[pointI].transfer(dynPointEdges[pointI].shrink());
132 // ************************************************************************* //