faceMapper.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-2019 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 "faceMapper.H"
27 #include "demandDrivenData.H"
28 #include "polyMesh.H"
29 #include "mapPolyMesh.H"
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 void Foam::faceMapper::calcAddressing() const
34 {
35  if
36  (
37  directAddrPtr_
38  || interpolationAddrPtr_
39  || weightsPtr_
40  || insertedFaceLabelsPtr_
41  )
42  {
44  << "Addressing already calculated."
45  << abort(FatalError);
46  }
47 
48  if (direct())
49  {
50  // Direct addressing, no weights
51 
52  directAddrPtr_ = new labelList(mpm_.faceMap());
53  labelList& directAddr = *directAddrPtr_;
54 
55  // Reset the size of addressing list to contain only live faces
56  directAddr.setSize(mesh_.nFaces());
57 
58  insertedFaceLabelsPtr_ = new labelList(mesh_.nFaces());
59  labelList& insertedFaces = *insertedFaceLabelsPtr_;
60 
61  label nInsertedFaces = 0;
62 
63  forAll(directAddr, facei)
64  {
65  if (directAddr[facei] < 0)
66  {
67  // Found inserted face
68  directAddr[facei] = 0;
69  insertedFaces[nInsertedFaces] = facei;
70  nInsertedFaces++;
71  }
72  }
73 
74  insertedFaces.setSize(nInsertedFaces);
75  }
76  else
77  {
78  // Interpolative addressing
79 
80  interpolationAddrPtr_ = new labelListList(mesh_.nFaces());
81  labelListList& addr = *interpolationAddrPtr_;
82 
83  weightsPtr_ = new scalarListList(mesh_.nFaces());
84  scalarListList& w = *weightsPtr_;
85 
86  const List<objectMap>& ffp = mpm_.facesFromPointsMap();
87 
88  forAll(ffp, ffpI)
89  {
90  // Get addressing
91  const labelList& mo = ffp[ffpI].masterObjects();
92 
93  label facei = ffp[ffpI].index();
94 
95  if (addr[facei].size())
96  {
98  << "Master face " << facei
99  << " mapped from point faces " << mo
100  << " already destination of mapping." << abort(FatalError);
101  }
102 
103  // Map from masters, uniform weights
104  addr[facei] = mo;
105  w[facei] = scalarList(mo.size(), 1.0/mo.size());
106  }
107 
108  const List<objectMap>& ffe = mpm_.facesFromEdgesMap();
109 
110  forAll(ffe, ffeI)
111  {
112  // Get addressing
113  const labelList& mo = ffe[ffeI].masterObjects();
114 
115  label facei = ffe[ffeI].index();
116 
117  if (addr[facei].size())
118  {
120  << "Master face " << facei
121  << " mapped from edge faces " << mo
122  << " already destination of mapping." << abort(FatalError);
123  }
124 
125  // Map from masters, uniform weights
126  addr[facei] = mo;
127  w[facei] = scalarList(mo.size(), 1.0/mo.size());
128  }
129 
130  const List<objectMap>& fff = mpm_.facesFromFacesMap();
131 
132  forAll(fff, fffI)
133  {
134  // Get addressing
135  const labelList& mo = fff[fffI].masterObjects();
136 
137  label facei = fff[fffI].index();
138 
139  if (addr[facei].size())
140  {
142  << "Master face " << facei
143  << " mapped from face faces " << mo
144  << " already destination of mapping." << abort(FatalError);
145  }
146 
147  // Map from masters, uniform weights
148  addr[facei] = mo;
149  w[facei] = scalarList(mo.size(), 1.0/mo.size());
150  }
151 
152 
153  // Do mapped faces. Note that can already be set from facesFromFaces
154  // so check if addressing size still zero.
155  const labelList& fm = mpm_.faceMap();
156 
157  forAll(fm, facei)
158  {
159  if (fm[facei] > -1 && addr[facei].empty())
160  {
161  // Mapped from a single face
162  addr[facei] = labelList(1, fm[facei]);
163  w[facei] = scalarList(1, 1.0);
164  }
165  }
166 
167 
168  // Grab inserted faces (for them the size of addressing is still zero)
169 
170  insertedFaceLabelsPtr_ = new labelList(mesh_.nFaces());
171  labelList& insertedFaces = *insertedFaceLabelsPtr_;
172 
173  label nInsertedFaces = 0;
174 
175  forAll(addr, facei)
176  {
177  if (addr[facei].empty())
178  {
179  // Mapped from a dummy face
180  addr[facei] = labelList(1, label(0));
181  w[facei] = scalarList(1, 1.0);
182 
183  insertedFaces[nInsertedFaces] = facei;
184  nInsertedFaces++;
185  }
186  }
187 
188  insertedFaces.setSize(nInsertedFaces);
189  }
190 }
191 
192 
193 void Foam::faceMapper::clearOut()
194 {
195  deleteDemandDrivenData(directAddrPtr_);
196  deleteDemandDrivenData(interpolationAddrPtr_);
197  deleteDemandDrivenData(weightsPtr_);
198  deleteDemandDrivenData(insertedFaceLabelsPtr_);
199 }
200 
201 
202 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
203 
205 :
206  mesh_(mpm.mesh()),
207  mpm_(mpm),
208  insertedFaces_(true),
209  direct_(false),
210  directAddrPtr_(nullptr),
211  interpolationAddrPtr_(nullptr),
212  weightsPtr_(nullptr),
213  insertedFaceLabelsPtr_(nullptr)
214 {
215  // Check for possibility of direct mapping
216  if
217  (
218  mpm_.facesFromPointsMap().empty()
219  && mpm_.facesFromEdgesMap().empty()
220  && mpm_.facesFromFacesMap().empty()
221  )
222  {
223  direct_ = true;
224  }
225  else
226  {
227  direct_ = false;
228  }
229 
230  // Check for inserted faces
231  if (direct_ && (mpm_.faceMap().empty() || min(mpm_.faceMap()) > -1))
232  {
233  insertedFaces_ = false;
234  }
235  else
236  {
237  // Need to check all 3 lists to see if there are inserted faces
238  // with no owner
239 
240  // Make a copy of the face map, add the entries for faces from points
241  // and faces from edges and check for left-overs
242  labelList fm(mesh_.nFaces(), -1);
243 
244  const List<objectMap>& ffp = mpm_.facesFromPointsMap();
245 
246  forAll(ffp, ffpI)
247  {
248  fm[ffp[ffpI].index()] = 0;
249  }
250 
251  const List<objectMap>& ffe = mpm_.facesFromEdgesMap();
252 
253  forAll(ffe, ffeI)
254  {
255  fm[ffe[ffeI].index()] = 0;
256  }
257 
258  const List<objectMap>& fff = mpm_.facesFromFacesMap();
259 
260  forAll(fff, fffI)
261  {
262  fm[fff[fffI].index()] = 0;
263  }
264 
265  if (min(fm) < 0)
266  {
267  insertedFaces_ = true;
268  }
269  }
270 }
271 
272 
273 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
274 
276 {
277  clearOut();
278 }
279 
280 
281 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
282 
284 {
285  return mpm_.nOldFaces();
286 }
287 
288 
290 {
291  return mpm_.nOldInternalFaces();
292 }
293 
294 
296 {
297  if (!direct())
298  {
300  << "Requested direct addressing for an interpolative mapper."
301  << abort(FatalError);
302  }
303 
304  if (!insertedObjects())
305  {
306  // No inserted faces. Re-use faceMap
307  return mpm_.faceMap();
308  }
309  else
310  {
311  if (!directAddrPtr_)
312  {
313  calcAddressing();
314  }
315 
316  return *directAddrPtr_;
317  }
318 }
319 
320 
322 {
323  if (direct())
324  {
326  << "Requested interpolative addressing for a direct mapper."
327  << abort(FatalError);
328  }
329 
330  if (!interpolationAddrPtr_)
331  {
332  calcAddressing();
333  }
334 
335  return *interpolationAddrPtr_;
336 }
337 
338 
340 {
341  if (direct())
342  {
344  << "Requested interpolative weights for a direct mapper."
345  << abort(FatalError);
346  }
347 
348  if (!weightsPtr_)
349  {
350  calcAddressing();
351  }
352 
353  return *weightsPtr_;
354 }
355 
356 
358 {
359  if (!insertedFaceLabelsPtr_)
360  {
361  if (!insertedObjects())
362  {
363  // There are no inserted faces
364  insertedFaceLabelsPtr_ = new labelList(0);
365  }
366  else
367  {
368  calcAddressing();
369  }
370  }
371 
372  return *insertedFaceLabelsPtr_;
373 }
374 
375 
377 {
378  return mpm_.flipFaceFlux();
379 }
380 
381 
383 {
384  return mpm_.nOldInternalFaces();
385 }
386 
387 
389 {
390  return mpm_.oldPatchStarts();
391 }
392 
393 
395 {
396  return mpm_.oldPatchSizes();
397 }
398 
399 
400 // ************************************************************************* //
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
bool empty() const
Return true if the UList is empty (ie, size() is zero)
Definition: UListI.H:313
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
virtual label internalSizeBeforeMapping() const
Return number of internal faces before mapping.
Definition: faceMapper.C:289
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
faceMapper(const mapPolyMesh &mpm)
Construct from mapPolyMesh.
Definition: faceMapper.C:204
label nFaces() const
const List< objectMap > & facesFromEdgesMap() const
Faces inflated from edges.
Definition: mapPolyMesh.H:411
virtual const labelList & insertedObjectLabels() const
Return list of inserted faces.
Definition: faceMapper.C:357
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
const labelHashSet & flipFaceFlux() const
Map of flipped face flux faces.
Definition: mapPolyMesh.H:551
virtual label sizeBeforeMapping() const
Return size of field before mapping.
Definition: faceMapper.C:283
label nOldInternalFaces() const
Number of old internal faces.
Definition: mapPolyMesh.H:364
const labelList & oldPatchSizes() const
Return list of the old patch sizes.
Definition: mapPolyMesh.H:615
dynamicFvMesh & mesh
virtual bool insertedObjects() const
Are there any inserted faces.
Definition: faceMapper.H:156
virtual const labelListList & addressing() const
Return interpolated addressing.
Definition: faceMapper.C:321
virtual const labelHashSet & flipFaceFlux() const
Return flux flip map.
Definition: faceMapper.C:376
List< scalarList > scalarListList
Definition: scalarList.H:51
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
virtual const scalarListList & weights() const
Return interpolaion weights.
Definition: faceMapper.C:339
List< label > labelList
A List of labels.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:131
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
virtual bool direct() const
Is the mapping direct.
Definition: faceMapper.H:124
const labelList & faceMap() const
Old face map.
Definition: mapPolyMesh.H:399
const labelList & oldPatchStarts() const
Return list of the old patch start labels.
Definition: mapPolyMesh.H:621
virtual ~faceMapper()
Destructor.
Definition: faceMapper.C:275
void setSize(const label)
Reset size of List.
Definition: List.C:281
Template functions to aid in the implementation of demand driven data.
virtual const labelList & oldPatchStarts() const
Return old patch starts.
Definition: faceMapper.C:388
const List< objectMap > & facesFromFacesMap() const
Faces originating from faces.
Definition: mapPolyMesh.H:417
virtual label nOldInternalFaces() const
Return number of old internalFaces.
Definition: faceMapper.C:382
const List< objectMap > & facesFromPointsMap() const
Faces inflated from points.
Definition: mapPolyMesh.H:405
void deleteDemandDrivenData(DataPtr &dataPtr)
label nOldFaces() const
Number of old faces.
Definition: mapPolyMesh.H:370
virtual const labelUList & directAddressing() const
Return direct addressing.
Definition: faceMapper.C:295
virtual const labelList & oldPatchSizes() const
Return old patch sizes.
Definition: faceMapper.C:394