faceMapper.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-2014 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  {
43  FatalErrorIn("void faceMapper::calcAddressing() const")
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  {
97  FatalErrorIn("void faceMapper::calcAddressing() const")
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  {
119  FatalErrorIn("void faceMapper::calcAddressing() const")
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  {
141  FatalErrorIn("void faceMapper::calcAddressing() const")
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 
204 // Construct from components
205 Foam::faceMapper::faceMapper(const mapPolyMesh& mpm)
206 :
207  mesh_(mpm.mesh()),
208  mpm_(mpm),
209  insertedFaces_(true),
210  direct_(false),
211  directAddrPtr_(NULL),
212  interpolationAddrPtr_(NULL),
213  weightsPtr_(NULL),
214  insertedFaceLabelsPtr_(NULL)
215 {
216  // Check for possibility of direct mapping
217  if
218  (
219  mpm_.facesFromPointsMap().empty()
220  && mpm_.facesFromEdgesMap().empty()
221  && mpm_.facesFromFacesMap().empty()
222  )
223  {
224  direct_ = true;
225  }
226  else
227  {
228  direct_ = false;
229  }
230 
231  // Check for inserted faces
232  if (direct_ && (mpm_.faceMap().empty() || min(mpm_.faceMap()) > -1))
233  {
234  insertedFaces_ = false;
235  }
236  else
237  {
238  // Need to check all 3 lists to see if there are inserted faces
239  // with no owner
240 
241  // Make a copy of the face map, add the entries for faces from points
242  // and faces from edges and check for left-overs
243  labelList fm(mesh_.nFaces(), -1);
244 
245  const List<objectMap>& ffp = mpm_.facesFromPointsMap();
246 
247  forAll(ffp, ffpI)
248  {
249  fm[ffp[ffpI].index()] = 0;
250  }
251 
252  const List<objectMap>& ffe = mpm_.facesFromEdgesMap();
253 
254  forAll(ffe, ffeI)
255  {
256  fm[ffe[ffeI].index()] = 0;
257  }
258 
259  const List<objectMap>& fff = mpm_.facesFromFacesMap();
260 
261  forAll(fff, fffI)
262  {
263  fm[fff[fffI].index()] = 0;
264  }
265 
266  if (min(fm) < 0)
267  {
268  insertedFaces_ = true;
269  }
270  }
271 }
272 
273 
274 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
275 
277 {
278  clearOut();
279 }
280 
281 
282 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
283 
285 {
286  return mesh_.nFaces();
287 }
288 
289 
291 {
292  return mpm_.nOldFaces();
293 }
294 
295 
297 {
298  return mpm_.nOldInternalFaces();
299 }
300 
301 
303 {
304  if (!direct())
305  {
307  (
308  "const labelUList& faceMapper::directAddressing() const"
309  ) << "Requested direct addressing for an interpolative mapper."
310  << abort(FatalError);
311  }
312 
313  if (!insertedObjects())
314  {
315  // No inserted faces. Re-use faceMap
316  return mpm_.faceMap();
317  }
318  else
319  {
320  if (!directAddrPtr_)
321  {
322  calcAddressing();
323  }
324 
325  return *directAddrPtr_;
326  }
327 }
328 
329 
331 {
332  if (direct())
333  {
335  (
336  "const labelListList& faceMapper::addressing() const"
337  ) << "Requested interpolative addressing for a direct mapper."
338  << abort(FatalError);
339  }
340 
341  if (!interpolationAddrPtr_)
342  {
343  calcAddressing();
344  }
345 
346  return *interpolationAddrPtr_;
347 }
348 
349 
351 {
352  if (direct())
353  {
355  (
356  "const scalarListList& faceMapper::weights() const"
357  ) << "Requested interpolative weights for a direct mapper."
358  << abort(FatalError);
359  }
360 
361  if (!weightsPtr_)
362  {
363  calcAddressing();
364  }
365 
366  return *weightsPtr_;
367 }
368 
369 
371 {
372  if (!insertedFaceLabelsPtr_)
373  {
374  if (!insertedObjects())
375  {
376  // There are no inserted faces
377  insertedFaceLabelsPtr_ = new labelList(0);
378  }
379  else
380  {
381  calcAddressing();
382  }
383  }
384 
385  return *insertedFaceLabelsPtr_;
386 }
387 
388 
390 {
391  return mpm_.flipFaceFlux();
392 }
393 
394 
396 {
397  return mpm_.nOldInternalFaces();
398 }
399 
400 
402 {
403  return mpm_.oldPatchStarts();
404 }
405 
406 
408 {
409  return mpm_.oldPatchSizes();
410 }
411 
412 
413 // ************************************************************************* //
virtual const labelList & oldPatchSizes() const
Return old patch sizes.
Definition: faceMapper.C:407
virtual label size() const
Return size.
Definition: faceMapper.C:284
virtual const labelList & insertedObjectLabels() const
Return list of inserted faces.
Definition: faceMapper.C:370
const List< objectMap > & facesFromEdgesMap() const
Faces inflated from edges.
Definition: mapPolyMesh.H:418
label nFaces() const
List< scalarList > scalarListList
Definition: scalarList.H:51
virtual const labelListList & addressing() const
Return interpolated addressing.
Definition: faceMapper.C:330
virtual const labelUList & directAddressing() const
Return direct addressing.
Definition: faceMapper.C:302
virtual const scalarListList & weights() const
Return interpolaion weights.
Definition: faceMapper.C:350
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
bool empty() const
Return true if the UList is empty (ie, size() is zero).
Definition: UListI.H:313
virtual bool direct() const
Is the mapping direct.
Definition: faceMapper.H:131
virtual bool insertedObjects() const
Are there any inserted faces.
Definition: faceMapper.H:163
const List< objectMap > & facesFromPointsMap() const
Faces inflated from points.
Definition: mapPolyMesh.H:412
void deleteDemandDrivenData(DataPtr &dataPtr)
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 const labelList & oldPatchStarts() const
Return old patch starts.
Definition: faceMapper.C:401
virtual label nOldInternalFaces() const
Return number of old internalFaces.
Definition: faceMapper.C:395
const List< objectMap > & facesFromFacesMap() const
Faces originating from faces.
Definition: mapPolyMesh.H:424
dynamicFvMesh & mesh
virtual ~faceMapper()
Destructor.
Definition: faceMapper.C:276
label nOldFaces() const
Number of old faces.
Definition: mapPolyMesh.H:377
void setSize(const label)
Reset size of List.
Definition: List.C:318
virtual label internalSizeBeforeMapping() const
Return number of internal faces before mapping.
Definition: faceMapper.C:296
virtual label sizeBeforeMapping() const
Return size of field before mapping.
Definition: faceMapper.C:290
#define forAll(list, i)
Definition: UList.H:421
const labelList & faceMap() const
Old face map.
Definition: mapPolyMesh.H:406
Template functions to aid in the implementation of demand driven data.
virtual const labelHashSet & flipFaceFlux() const
Return flux flip map.
Definition: faceMapper.C:389
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
errorManip< error > abort(error &err)
Definition: errorManip.H:131
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
label nOldInternalFaces() const
Number of old internal faces.
Definition: mapPolyMesh.H:371
error FatalError
List< label > labelList
A List of labels.
Definition: labelList.H:56
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
const labelHashSet & flipFaceFlux() const
Map of flipped face flux faces.
Definition: mapPolyMesh.H:558
const labelList & oldPatchSizes() const
Return list of the old patch sizes.
Definition: mapPolyMesh.H:622
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
const labelList & oldPatchStarts() const
Return list of the old patch start labels.
Definition: mapPolyMesh.H:628