cellMatcher.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "cellMatcher.H"
27 
28 #include "primitiveMesh.H"
29 #include "Map.H"
30 #include "faceList.H"
31 #include "labelList.H"
32 #include "ListOps.H"
33 
34 
35 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 
38 (
39  const label vertPerCell,
40  const label facePerCell,
41  const label maxVertPerFace,
42  const word& cellModelName
43 )
44 :
45  localPoint_(100),
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),
55  cellModelPtr_(NULL)
56 {
57  forAll(localFaces_, faceI)
58  {
59  face& f = localFaces_[faceI];
60 
61  f.setSize(maxVertPerFace);
62  }
63 
64  forAll(pointFaceIndex_, vertI)
65  {
66  pointFaceIndex_[vertI].setSize(facePerCell);
67  }
68 }
69 
70 
71 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
72 
73 // Create localFaces_ , pointMap_ , faceMap_
75 (
76  const faceList& faces,
77  const labelList& myFaces
78 )
79 {
80  // Clear map from global to cell numbering
81  localPoint_.clear();
82 
83  // Renumber face vertices and insert directly into localFaces_
84  label newVertI = 0;
85  forAll(myFaces, myFaceI)
86  {
87  label faceI = myFaces[myFaceI];
88 
89  const face& f = faces[faceI];
90  face& localFace = localFaces_[myFaceI];
91 
92  // Size of localFace
93  faceSize_[myFaceI] = f.size();
94 
95  forAll(f, localVertI)
96  {
97  label vertI = f[localVertI];
98 
99  Map<label>::iterator iter = localPoint_.find(vertI);
100  if (iter == localPoint_.end())
101  {
102  // Not found. Assign local vertex number.
103 
104  if (newVertI >= pointMap_.size())
105  {
106  // Illegal face: more unique vertices than vertPerCell
107  return -1;
108  }
109 
110  localFace[localVertI] = newVertI;
111  localPoint_.insert(vertI, newVertI);
112  newVertI++;
113  }
114  else
115  {
116  // Reuse local vertex number.
117  localFace[localVertI] = *iter;
118  }
119  }
120 
121  // Create face from localvertex labels
122  faceMap_[myFaceI] = faceI;
123  }
124 
125  // Create local to global vertex mapping
126  forAllConstIter(Map<label>, localPoint_, iter)
127  {
128  const label fp = iter();
129  pointMap_[fp] = iter.key();
130  }
131 
133  //write(Info);
134 
135  return newVertI;
136 }
137 
138 
139 // Create edgeFaces_ : map from edge to two localFaces for single cell.
141 {
142  edgeFaces_ = -1;
143 
144  forAll(localFaces_, localFaceI)
145  {
146  const face& f = localFaces_[localFaceI];
147 
148  label prevVertI = faceSize_[localFaceI] - 1;
149  //forAll(f, fp)
150  for
151  (
152  label fp = 0;
153  fp < faceSize_[localFaceI];
154  fp++
155  )
156  {
157  label start = f[prevVertI];
158  label end = f[fp];
159 
160  label key1 = edgeKey(numVert, start, end);
161  label key2 = edgeKey(numVert, end, start);
162 
163  if (edgeFaces_[key1] == -1)
164  {
165  // Entry key1 unoccupied. Store both permutations.
166  edgeFaces_[key1] = localFaceI;
167  edgeFaces_[key2] = localFaceI;
168  }
169  else if (edgeFaces_[key1+1] == -1)
170  {
171  // Entry key1+1 unoccupied
172  edgeFaces_[key1+1] = localFaceI;
173  edgeFaces_[key2+1] = localFaceI;
174  }
175  else
176  {
178  << "edgeFaces_ full at entry:" << key1
179  << " for edge " << start << " " << end
180  << abort(FatalError);
181  }
182 
183  prevVertI = fp;
184  }
185  }
186 }
187 
188 
189 // Create pointFaceIndex_ : map from vertI, faceI to index of vertI on faceI.
191 {
192  // Fill pointFaceIndex_ with -1
193  forAll(pointFaceIndex_, i)
194  {
195  labelList& faceIndices = pointFaceIndex_[i];
196 
197  faceIndices = -1;
198  }
199 
200  forAll(localFaces_, localFaceI)
201  {
202  const face& f = localFaces_[localFaceI];
203 
204  for
205  (
206  label fp = 0;
207  fp < faceSize_[localFaceI];
208  fp++
209  )
210  {
211  label vert = f[fp];
212  pointFaceIndex_[vert][localFaceI] = fp;
213  }
214  }
215 }
216 
217 
218 // Given edge(v0,v1) and (local)faceI return the other face
220 (
221  const label numVert,
222  const label v0,
223  const label v1,
224  const label localFaceI
225 ) const
226 {
227  label key = edgeKey(numVert, v0, v1);
228 
229  if (edgeFaces_[key] == localFaceI)
230  {
231  return edgeFaces_[key+1];
232  }
233  else if (edgeFaces_[key+1] == localFaceI)
234  {
235  return edgeFaces_[key];
236  }
237  else
238  {
240  << "edgeFaces_ does not contain:" << localFaceI
241  << " for edge " << v0 << " " << v1 << " at key " << key
242  << " edgeFaces_[key, key+1]:" << edgeFaces_[key]
243  << " , " << edgeFaces_[key+1]
244  << abort(FatalError);
245 
246  return -1;
247  }
248 }
249 
250 
252 {
253  os << "Faces:" << endl;
254 
255  forAll(localFaces_, faceI)
256  {
257  os << " ";
258 
259  for (label fp = 0; fp < faceSize_[faceI]; fp++)
260  {
261  os << ' ' << localFaces_[faceI][fp];
262  }
263  os << endl;
264  }
265 
266  os << "Face map : " << faceMap_ << endl;
267  os << "Point map : " << pointMap_ << endl;
268 }
269 
270 
271 // ************************************************************************* //
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::cellMatcher::write
void write(Ostream &os) const
Definition: cellMatcher.C:251
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::cellMatcher::localFaces_
faceList localFaces_
Faces using local vertex numbering.
Definition: cellMatcher.H:122
Foam::cellMatcher::calcLocalFaces
label calcLocalFaces(const faceList &faces, const labelList &myFaces)
Calculates localFaces. Returns number of local vertices (or -1.
Definition: cellMatcher.C:75
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: PrimitivePatchTemplate.H:68
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::cellMatcher::calcEdgeAddressing
void calcEdgeAddressing(const label numVert)
Fill edge (start, end) to face number.
Definition: cellMatcher.C:140
faceList.H
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::cellMatcher::edgeFaces_
labelList edgeFaces_
Map from 'edge' to neighbouring faces.
Definition: cellMatcher.H:134
Map.H
Foam::cellMatcher::calcPointFaceIndex
void calcPointFaceIndex()
Fill vertex/face to index in face data structure.
Definition: cellMatcher.C:190
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
labelList.H
Foam::cellMatcher::otherFace
label otherFace(const label numVert, const label v0, const label v1, const label localFaceI) const
Given start,end of edge lookup both faces sharing it and return.
Definition: cellMatcher.C:220
Foam::FatalError
error FatalError
Foam::cellMatcher::edgeKey
static label edgeKey(const label numVert, const label v0, const label v1)
Given start and end of edge generate unique key.
Definition: cellMatcherI.H:100
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::cellMatcher::cellMatcher
cellMatcher(const cellMatcher &)
Disallow default bitwise copy construct and assignment.
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
f
labelList f(nPoints)
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
cellMatcher.H
Foam::cellMatcher::faceSize_
labelList faceSize_
Number of vertices per face in localFaces_.
Definition: cellMatcher.H:125
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
ListOps.H
Various functions to operate on Lists.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53