1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 "cellMatcher.H"
31 #include "primitiveMesh.H"
34 #include "labelList.H"
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 Foam::labelList Foam::cellMatcher::makeIdentity(const label nElems)
40 labelList result(nElems);
44 result[elemI] = elemI;
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 // Construct from components
53 Foam::cellMatcher::cellMatcher
55 const label vertPerCell,
56 const label facePerCell,
57 const label maxVertPerFace,
58 const word& cellModelName
62 localFaces_(facePerCell),
63 faceSize_(facePerCell, -1),
64 pointMap_(vertPerCell),
65 faceMap_(facePerCell),
66 edgeFaces_(2*vertPerCell*vertPerCell),
67 pointFaceIndex_(vertPerCell),
68 vertLabels_(vertPerCell),
69 faceLabels_(facePerCell),
70 cellModelName_(cellModelName),
73 forAll(localFaces_, faceI)
75 face& f = localFaces_[faceI];
77 f.setSize(maxVertPerFace);
80 forAll(pointFaceIndex_, vertI)
82 pointFaceIndex_[vertI].setSize(facePerCell);
87 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
89 // Create localFaces_ , pointMap_ , faceMap_
90 Foam::label Foam::cellMatcher::calcLocalFaces
92 const faceList& faces,
93 const labelList& myFaces
96 // Clear map from global to cell numbering
99 // Renumber face vertices and insert directly into localFaces_
101 forAll(myFaces, myFaceI)
103 label faceI = myFaces[myFaceI];
105 const face& f = faces[faceI];
106 face& localFace = localFaces_[myFaceI];
109 faceSize_[myFaceI] = f.size();
111 forAll(f, localVertI)
113 label vertI = f[localVertI];
115 Map<label>::iterator iter = localPoint_.find(vertI);
116 if (iter == localPoint_.end())
118 // Not found. Assign local vertex number.
120 if (newVertI >= pointMap_.size())
122 // Illegal face: more unique vertices than vertPerCell
126 localFace[localVertI] = newVertI;
127 localPoint_.insert(vertI, newVertI);
132 // Reuse local vertex number.
133 localFace[localVertI] = *iter;
137 // Create face from localvertex labels
138 faceMap_[myFaceI] = faceI;
141 // Create local to global vertex mapping
144 Map<label>::iterator iter = localPoint_.begin();
145 iter != localPoint_.end();
150 pointMap_[fp] = iter.key();
160 // Create edgeFaces_ : map from edge to two localFaces for single cell.
161 void Foam::cellMatcher::calcEdgeAddressing(const label numVert)
165 forAll(localFaces_, localFaceI)
167 const face& f = localFaces_[localFaceI];
169 label prevVertI = faceSize_[localFaceI] - 1;
174 fp < faceSize_[localFaceI];
178 label start = f[prevVertI];
181 label key1 = edgeKey(numVert, start, end);
182 label key2 = edgeKey(numVert, end, start);
184 if (edgeFaces_[key1] == -1)
186 // Entry key1 unoccupied. Store both permutations.
187 edgeFaces_[key1] = localFaceI;
188 edgeFaces_[key2] = localFaceI;
190 else if (edgeFaces_[key1+1] == -1)
192 // Entry key1+1 unoccupied
193 edgeFaces_[key1+1] = localFaceI;
194 edgeFaces_[key2+1] = localFaceI;
201 "(const faceList&, const label)"
202 ) << "edgeFaces_ full at entry:" << key1
203 << " for edge " << start << " " << end
204 << abort(FatalError);
213 // Create pointFaceIndex_ : map from vertI, faceI to index of vertI on faceI.
214 void Foam::cellMatcher::calcPointFaceIndex()
216 // Fill pointFaceIndex_ with -1
217 forAll(pointFaceIndex_, i)
219 labelList& faceIndices = pointFaceIndex_[i];
224 forAll(localFaces_, localFaceI)
226 const face& f = localFaces_[localFaceI];
231 fp < faceSize_[localFaceI];
236 pointFaceIndex_[vert][localFaceI] = fp;
242 // Given edge(v0,v1) and (local)faceI return the other face
243 Foam::label Foam::cellMatcher::otherFace
248 const label localFaceI
251 label key = edgeKey(numVert, v0, v1);
253 if (edgeFaces_[key] == localFaceI)
255 return edgeFaces_[key+1];
257 else if (edgeFaces_[key+1] == localFaceI)
259 return edgeFaces_[key];
266 "(const label, const labelList&, const label, const label, "
268 ) << "edgeFaces_ does not contain:" << localFaceI
269 << " for edge " << v0 << " " << v1 << " at key " << key
270 << " edgeFaces_[key, key+1]:" << edgeFaces_[key]
271 << " , " << edgeFaces_[key+1]
272 << abort(FatalError);
279 void Foam::cellMatcher::write(Foam::Ostream& os) const
281 os << "Faces:" << endl;
283 forAll(localFaces_, faceI)
287 for(label fp = 0; fp < faceSize_[faceI]; fp++)
289 os << ' ' << localFaces_[faceI][fp];
294 os << "Face map : " << faceMap_ << endl;
295 os << "Point map : " << pointMap_ << endl;
299 // ************************************************************************* //