1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "cellMatcher.H"
28 #include "primitiveMesh.H"
31 #include "labelList.H"
35 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 Foam::cellMatcher::cellMatcher
39 const label vertPerCell,
40 const label facePerCell,
41 const label maxVertPerFace,
42 const word& cellModelName
46 localFaces_(facePerCell),
47 faceSize_(facePerCell, -1),
48 pointMap_(vertPerCell),
49 faceMap_(facePerCell),
50 edgeFaces_(2*vertPerCell*vertPerCell),
51 pointFaceIndex_(vertPerCell),
52 vertLabels_(vertPerCell),
53 faceLabels_(facePerCell),
54 cellModelName_(cellModelName),
57 forAll(localFaces_, faceI)
59 face& f = localFaces_[faceI];
61 f.setSize(maxVertPerFace);
64 forAll(pointFaceIndex_, vertI)
66 pointFaceIndex_[vertI].setSize(facePerCell);
71 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
73 // Create localFaces_ , pointMap_ , faceMap_
74 Foam::label Foam::cellMatcher::calcLocalFaces
76 const faceList& faces,
77 const labelList& myFaces
80 // Clear map from global to cell numbering
83 // Renumber face vertices and insert directly into localFaces_
85 forAll(myFaces, myFaceI)
87 label faceI = myFaces[myFaceI];
89 const face& f = faces[faceI];
90 face& localFace = localFaces_[myFaceI];
93 faceSize_[myFaceI] = f.size();
97 label vertI = f[localVertI];
99 Map<label>::iterator iter = localPoint_.find(vertI);
100 if (iter == localPoint_.end())
102 // Not found. Assign local vertex number.
104 if (newVertI >= pointMap_.size())
106 // Illegal face: more unique vertices than vertPerCell
110 localFace[localVertI] = newVertI;
111 localPoint_.insert(vertI, newVertI);
116 // Reuse local vertex number.
117 localFace[localVertI] = *iter;
121 // Create face from localvertex labels
122 faceMap_[myFaceI] = faceI;
125 // Create local to global vertex mapping
126 forAllConstIter(Map<label>, localPoint_, iter)
128 const label fp = iter();
129 pointMap_[fp] = iter.key();
139 // Create edgeFaces_ : map from edge to two localFaces for single cell.
140 void Foam::cellMatcher::calcEdgeAddressing(const label numVert)
144 forAll(localFaces_, localFaceI)
146 const face& f = localFaces_[localFaceI];
148 label prevVertI = faceSize_[localFaceI] - 1;
153 fp < faceSize_[localFaceI];
157 label start = f[prevVertI];
160 label key1 = edgeKey(numVert, start, end);
161 label key2 = edgeKey(numVert, end, start);
163 if (edgeFaces_[key1] == -1)
165 // Entry key1 unoccupied. Store both permutations.
166 edgeFaces_[key1] = localFaceI;
167 edgeFaces_[key2] = localFaceI;
169 else if (edgeFaces_[key1+1] == -1)
171 // Entry key1+1 unoccupied
172 edgeFaces_[key1+1] = localFaceI;
173 edgeFaces_[key2+1] = localFaceI;
180 "(const faceList&, const label)"
181 ) << "edgeFaces_ full at entry:" << key1
182 << " for edge " << start << " " << end
183 << abort(FatalError);
192 // Create pointFaceIndex_ : map from vertI, faceI to index of vertI on faceI.
193 void Foam::cellMatcher::calcPointFaceIndex()
195 // Fill pointFaceIndex_ with -1
196 forAll(pointFaceIndex_, i)
198 labelList& faceIndices = pointFaceIndex_[i];
203 forAll(localFaces_, localFaceI)
205 const face& f = localFaces_[localFaceI];
210 fp < faceSize_[localFaceI];
215 pointFaceIndex_[vert][localFaceI] = fp;
221 // Given edge(v0,v1) and (local)faceI return the other face
222 Foam::label Foam::cellMatcher::otherFace
227 const label localFaceI
230 label key = edgeKey(numVert, v0, v1);
232 if (edgeFaces_[key] == localFaceI)
234 return edgeFaces_[key+1];
236 else if (edgeFaces_[key+1] == localFaceI)
238 return edgeFaces_[key];
245 "(const label, const labelList&, const label, const label, "
247 ) << "edgeFaces_ does not contain:" << localFaceI
248 << " for edge " << v0 << " " << v1 << " at key " << key
249 << " edgeFaces_[key, key+1]:" << edgeFaces_[key]
250 << " , " << edgeFaces_[key+1]
251 << abort(FatalError);
258 void Foam::cellMatcher::write(Foam::Ostream& os) const
260 os << "Faces:" << endl;
262 forAll(localFaces_, faceI)
266 for (label fp = 0; fp < faceSize_[faceI]; fp++)
268 os << ' ' << localFaces_[faceI][fp];
273 os << "Face map : " << faceMap_ << endl;
274 os << "Point map : " << pointMap_ << endl;
278 // ************************************************************************* //