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 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 
37 Foam::cellMatcher::cellMatcher
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  (
179  "calcEdgeAddressing"
180  "(const faceList&, const label)"
181  ) << "edgeFaces_ full at entry:" << key1
182  << " for edge " << start << " " << end
183  << abort(FatalError);
184  }
185 
186  prevVertI = fp;
187  }
188  }
189 }
190 
191 
192 // Create pointFaceIndex_ : map from vertI, faceI to index of vertI on faceI.
194 {
195  // Fill pointFaceIndex_ with -1
197  {
198  labelList& faceIndices = pointFaceIndex_[i];
199 
200  faceIndices = -1;
201  }
202 
203  forAll(localFaces_, localFaceI)
204  {
205  const face& f = localFaces_[localFaceI];
206 
207  for
208  (
209  label fp = 0;
210  fp < faceSize_[localFaceI];
211  fp++
212  )
213  {
214  label vert = f[fp];
215  pointFaceIndex_[vert][localFaceI] = fp;
216  }
217  }
218 }
219 
220 
221 // Given edge(v0,v1) and (local)faceI return the other face
223 (
224  const label numVert,
225  const label v0,
226  const label v1,
227  const label localFaceI
228 ) const
229 {
230  label key = edgeKey(numVert, v0, v1);
231 
232  if (edgeFaces_[key] == localFaceI)
233  {
234  return edgeFaces_[key+1];
235  }
236  else if (edgeFaces_[key+1] == localFaceI)
237  {
238  return edgeFaces_[key];
239  }
240  else
241  {
243  (
244  "otherFace"
245  "(const label, const labelList&, const label, const label, "
246  "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);
252 
253  return -1;
254  }
255 }
256 
257 
259 {
260  os << "Faces:" << endl;
261 
262  forAll(localFaces_, faceI)
263  {
264  os << " ";
265 
266  for (label fp = 0; fp < faceSize_[faceI]; fp++)
267  {
268  os << ' ' << localFaces_[faceI][fp];
269  }
270  os << endl;
271  }
272 
273  os << "Face map : " << faceMap_ << endl;
274  os << "Point map : " << pointMap_ << endl;
275 }
276 
277 
278 // ************************************************************************* //
void calcPointFaceIndex()
Fill vertex/face to index in face data structure.
Definition: cellMatcher.C:193
void write(Ostream &os) const
Definition: cellMatcher.C:258
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:223
labelList faceSize_
Number of vertices per face in localFaces_.
Definition: cellMatcher.H:125
labelList f(nPoints)
A HashTable to objects of type <T> with a label key.
Definition: Map.H:49
A class for handling words, derived from string.
Definition: word.H:59
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
Various functions to operate on Lists.
void calcEdgeAddressing(const label numVert)
Fill edge (start, end) to face number.
Definition: cellMatcher.C:140
faceList localFaces_
Faces using local vertex numbering.
Definition: cellMatcher.H:122
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
void setSize(const label)
Reset size of List.
Definition: List.C:318
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
labelList pointMap_
Map from local to mesh vertex numbering.
Definition: cellMatcher.H:128
label calcLocalFaces(const faceList &faces, const labelList &myFaces)
Calculates localFaces. Returns number of local vertices (or -1.
Definition: cellMatcher.C:75
#define forAll(list, i)
Definition: UList.H:421
labelList edgeFaces_
Map from &#39;edge&#39; to neighbouring faces.
Definition: cellMatcher.H:134
errorManip< error > abort(error &err)
Definition: errorManip.H:131
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
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
error FatalError
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:106
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:139
labelListList pointFaceIndex_
pointFaceIndex[localVertI][localFaceI] is index in localFace
Definition: cellMatcher.H:138
labelList faceMap_
Map from local to mesh face numbering.
Definition: cellMatcher.H:131