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
25 \*---------------------------------------------------------------------------*/
28 #include "mergePoints.H"
29 #include "StaticHashTable.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38 void edgeMesh::calcPointEdges() const
40 if (pointEdgesPtr_.valid())
42 FatalErrorIn("edgeMesh::calcPointEdges() const")
43 << "pointEdges already calculated." << abort(FatalError);
46 pointEdgesPtr_.reset(new labelListList(points_.size()));
47 labelListList& pointEdges = pointEdgesPtr_();
50 labelList nEdgesPerPoint(points_.size(), 0);
54 const edge& e = edges_[edgeI];
56 nEdgesPerPoint[e[0]]++;
57 nEdgesPerPoint[e[1]]++;
61 forAll(pointEdges, pointI)
63 pointEdges[pointI].setSize(nEdgesPerPoint[pointI]);
71 const edge& e = edges_[edgeI];
74 pointEdges[p0][nEdgesPerPoint[p0]++] = edgeI;
76 pointEdges[p1][nEdgesPerPoint[p1]++] = edgeI;
81 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
83 // construct from components
84 edgeMesh::edgeMesh(const pointField& points, const edgeList& edges)
92 edgeMesh::edgeMesh(const edgeMesh& em)
100 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
102 label edgeMesh::regions(labelList& edgeRegion) const
104 edgeRegion.setSize(edges_.size());
107 label startEdgeI = 0;
109 label currentRegion = 0;
113 while (startEdgeI < edges_.size() && edgeRegion[startEdgeI] != -1)
118 if (startEdgeI == edges_.size())
123 // Found edge that has not yet been assigned a region.
124 // Mark connected region with currentRegion starting at startEdgeI.
126 edgeRegion[startEdgeI] = currentRegion;
127 labelList edgesToVisit(1, startEdgeI);
129 while (edgesToVisit.size() > 0)
131 // neighbours of current edgesToVisit
132 DynamicList<label> newEdgesToVisit(edgesToVisit.size());
134 // Mark all point connected edges with current region.
135 forAll(edgesToVisit, i)
137 label edgeI = edgesToVisit[i];
139 // Mark connected edges
140 const edge& e = edges_[edgeI];
144 const labelList& pEdges = pointEdges()[e[fp]];
146 forAll(pEdges, pEdgeI)
148 label nbrEdgeI = pEdges[pEdgeI];
150 if (edgeRegion[nbrEdgeI] == -1)
152 edgeRegion[nbrEdgeI] = currentRegion;
153 newEdgesToVisit.append(nbrEdgeI);
159 edgesToVisit.transfer(newEdgesToVisit.shrink());
164 return currentRegion;
168 void edgeMesh::mergePoints(const scalar mergeDist)
170 pointField newPoints;
173 bool hasMerged = Foam::mergePoints
185 pointEdgesPtr_.clear();
187 points_.transfer(newPoints);
189 // Renumber and make sure e[0] < e[1] (not really nessecary)
190 forAll(edges_, edgeI)
192 edge& e = edges_[edgeI];
194 label p0 = pointMap[e[0]];
195 label p1 = pointMap[e[1]];
209 // Compact using a hashtable and commutative hash of edge.
210 StaticHashTable<label, edge, Hash<edge> > edgeToLabel
217 forAll(edges_, edgeI)
219 const edge& e = edges_[edgeI];
223 if (edgeToLabel.insert(e, newEdgeI))
230 edges_.setSize(newEdgeI);
234 StaticHashTable<label, edge, Hash<edge> >::const_iterator iter =
236 iter != edgeToLabel.end();
240 edges_[iter()] = iter.key();
246 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
248 void edgeMesh::operator=(const edgeMesh& rhs)
250 points_ = rhs.points_;
252 pointEdgesPtr_.reset(NULL);
256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
258 } // End namespace Foam
260 // ************************************************************************* //