cellMatcher.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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_(nullptr)
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 
74 (
75  const faceList& faces,
76  const labelList& myFaces
77 )
78 {
79  // Clear map from global to cell numbering
80  localPoint_.clear();
81 
82  // Renumber face vertices and insert directly into localFaces_
83  label newVertI = 0;
84  forAll(myFaces, myFacei)
85  {
86  label facei = myFaces[myFacei];
87 
88  const face& f = faces[facei];
89  face& localFace = localFaces_[myFacei];
90 
91  // Size of localFace
92  faceSize_[myFacei] = f.size();
93 
94  forAll(f, localVertI)
95  {
96  label vertI = f[localVertI];
97 
98  Map<label>::iterator iter = localPoint_.find(vertI);
99  if (iter == localPoint_.end())
100  {
101  // Not found. Assign local vertex number.
102 
103  if (newVertI >= pointMap_.size())
104  {
105  // Illegal face: more unique vertices than vertPerCell
106  return -1;
107  }
108 
109  localFace[localVertI] = newVertI;
110  localPoint_.insert(vertI, newVertI);
111  newVertI++;
112  }
113  else
114  {
115  // Reuse local vertex number.
116  localFace[localVertI] = *iter;
117  }
118  }
119 
120  // Create face from localvertex labels
121  faceMap_[myFacei] = facei;
122  }
123 
124  // Create local to global vertex mapping
125  forAllConstIter(Map<label>, localPoint_, iter)
126  {
127  const label fp = iter();
128  pointMap_[fp] = iter.key();
129  }
130 
132  // write(Info);
133 
134  return newVertI;
135 }
136 
137 
139 {
140  edgeFaces_ = -1;
141 
142  forAll(localFaces_, localFacei)
143  {
144  const face& f = localFaces_[localFacei];
145 
146  label prevVertI = faceSize_[localFacei] - 1;
147  // forAll(f, fp)
148  for
149  (
150  label fp = 0;
151  fp < faceSize_[localFacei];
152  fp++
153  )
154  {
155  label start = f[prevVertI];
156  label end = f[fp];
157 
158  label key1 = edgeKey(numVert, start, end);
159  label key2 = edgeKey(numVert, end, start);
160 
161  if (edgeFaces_[key1] == -1)
162  {
163  // Entry key1 unoccupied. Store both permutations.
164  edgeFaces_[key1] = localFacei;
165  edgeFaces_[key2] = localFacei;
166  }
167  else if (edgeFaces_[key1+1] == -1)
168  {
169  // Entry key1+1 unoccupied
170  edgeFaces_[key1+1] = localFacei;
171  edgeFaces_[key2+1] = localFacei;
172  }
173  else
174  {
176  << "edgeFaces_ full at entry:" << key1
177  << " for edge " << start << " " << end
178  << abort(FatalError);
179  }
180 
181  prevVertI = fp;
182  }
183  }
184 }
185 
186 
188 {
189  // Fill pointFaceIndex_ with -1
191  {
192  labelList& faceIndices = pointFaceIndex_[i];
193 
194  faceIndices = -1;
195  }
196 
197  forAll(localFaces_, localFacei)
198  {
199  const face& f = localFaces_[localFacei];
200 
201  for
202  (
203  label fp = 0;
204  fp < faceSize_[localFacei];
205  fp++
206  )
207  {
208  label vert = f[fp];
209  pointFaceIndex_[vert][localFacei] = fp;
210  }
211  }
212 }
213 
214 
216 (
217  const label numVert,
218  const label v0,
219  const label v1,
220  const label localFacei
221 ) const
222 {
223  label key = edgeKey(numVert, v0, v1);
224 
225  if (edgeFaces_[key] == localFacei)
226  {
227  return edgeFaces_[key+1];
228  }
229  else if (edgeFaces_[key+1] == localFacei)
230  {
231  return edgeFaces_[key];
232  }
233  else
234  {
236  << "edgeFaces_ does not contain:" << localFacei
237  << " for edge " << v0 << " " << v1 << " at key " << key
238  << " edgeFaces_[key, key+1]:" << edgeFaces_[key]
239  << " , " << edgeFaces_[key+1]
240  << abort(FatalError);
241 
242  return -1;
243  }
244 }
245 
246 
248 {
249  os << "Faces:" << endl;
250 
251  forAll(localFaces_, facei)
252  {
253  os << " ";
254 
255  for (label fp = 0; fp < faceSize_[facei]; fp++)
256  {
257  os << ' ' << localFaces_[facei][fp];
258  }
259  os << endl;
260  }
261 
262  os << "Face map : " << faceMap_ << endl;
263  os << "Point map : " << pointMap_ << endl;
264 }
265 
266 
267 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
labelList faceMap_
Map from local to mesh face numbering.
Definition: cellMatcher.H:132
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
void calcEdgeAddressing(const label numVert)
Fill edge (start, end) to face number.
Definition: cellMatcher.C:138
labelListList pointFaceIndex_
pointFaceIndex[localVertI][localFacei] is index in localFace
Definition: cellMatcher.H:139
Various functions to operate on Lists.
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:142
cellMatcher(const label vertPerCell, const label facePerCell, const label maxVertPerFace, const word &cellModelName)
Construct given mesh and shape factors.
Definition: cellMatcher.C:38
labelList edgeFaces_
Map from &#39;edge&#39; to neighbouring faces.
Definition: cellMatcher.H:135
void calcPointFaceIndex()
Fill vertex/face to index in face data structure.
Definition: cellMatcher.C:187
A class for handling words, derived from string.
Definition: word.H:59
label calcLocalFaces(const faceList &faces, const labelList &myFaces)
Calculates localFaces. Returns number of local vertices (or -1.
Definition: cellMatcher.C:74
labelList faceSize_
Number of vertices per face in localFaces_.
Definition: cellMatcher.H:126
errorManip< error > abort(error &err)
Definition: errorManip.H:131
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
faceList localFaces_
Faces using local vertex numbering.
Definition: cellMatcher.H:123
labelList f(nPoints)
labelList pointMap_
Map from local to mesh vertex numbering.
Definition: cellMatcher.H:129
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:216
void setSize(const label)
Reset size of List.
Definition: List.C:281
void write(Ostream &os) const
Definition: cellMatcher.C:247
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
A HashTable to objects of type <T> with a label key.
Definition: Map.H:49