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-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 "faceMapper.H"
27 #include "demandDrivenData.H"
28 #include "polyMesh.H"
29 #include "mapPolyMesh.H"
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
34 {
35  if
36  (
39  || weightsPtr_
41  )
42  {
44  << "Addressing already calculated."
45  << abort(FatalError);
46  }
47 
48  if (direct())
49  {
50  // Direct addressing, no weights
51 
53  labelList& directAddr = *directAddrPtr_;
54 
55  // Reset the size of addressing list to contain only live faces
56  directAddr.setSize(mesh_.nFaces());
57 
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 
82 
85 
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 
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 
194 {
195  deleteDemandDrivenData(directAddrPtr_);
196  deleteDemandDrivenData(interpolationAddrPtr_);
197  deleteDemandDrivenData(weightsPtr_);
198  deleteDemandDrivenData(insertedFaceLabelsPtr_);
199 }
200 
201 
202 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
203 
204 // Construct from components
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  << "Requested direct addressing for an interpolative mapper."
308  << abort(FatalError);
309  }
310 
311  if (!insertedObjects())
312  {
313  // No inserted faces. Re-use faceMap
314  return mpm_.faceMap();
315  }
316  else
317  {
318  if (!directAddrPtr_)
319  {
320  calcAddressing();
321  }
322 
323  return *directAddrPtr_;
324  }
325 }
326 
327 
329 {
330  if (direct())
331  {
333  << "Requested interpolative addressing for a direct mapper."
334  << abort(FatalError);
335  }
336 
337  if (!interpolationAddrPtr_)
338  {
339  calcAddressing();
340  }
341 
342  return *interpolationAddrPtr_;
343 }
344 
345 
347 {
348  if (direct())
349  {
351  << "Requested interpolative weights for a direct mapper."
352  << abort(FatalError);
353  }
354 
355  if (!weightsPtr_)
356  {
357  calcAddressing();
358  }
359 
360  return *weightsPtr_;
361 }
362 
363 
365 {
366  if (!insertedFaceLabelsPtr_)
367  {
368  if (!insertedObjects())
369  {
370  // There are no inserted faces
371  insertedFaceLabelsPtr_ = new labelList(0);
372  }
373  else
374  {
375  calcAddressing();
376  }
377  }
378 
379  return *insertedFaceLabelsPtr_;
380 }
381 
382 
384 {
385  return mpm_.flipFaceFlux();
386 }
387 
388 
390 {
391  return mpm_.nOldInternalFaces();
392 }
393 
394 
396 {
397  return mpm_.oldPatchStarts();
398 }
399 
400 
402 {
403  return mpm_.oldPatchSizes();
404 }
405 
406 
407 // ************************************************************************* //
Foam::mapPolyMesh::facesFromPointsMap
const List< objectMap > & facesFromPointsMap() const
Faces inflated from points.
Definition: mapPolyMesh.H:412
Foam::scalarList
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
Foam::faceMapper::directAddressing
virtual const labelUList & directAddressing() const
Return direct addressing.
Definition: faceMapper.C:302
Foam::faceMapper::oldPatchSizes
virtual const labelList & oldPatchSizes() const
Return old patch sizes.
Definition: faceMapper.C:401
w
volScalarField w(IOobject("w", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE), mesh, dimensionedScalar("w", dimensionSet(0, 0, 0, 0, 0, 0, 0), 0.0))
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::faceMapper::size
virtual label size() const
Return size.
Definition: faceMapper.C:284
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::faceMapper::oldPatchStarts
virtual const labelList & oldPatchStarts() const
Return old patch starts.
Definition: faceMapper.C:395
mapPolyMesh.H
Foam::faceMapper::internalSizeBeforeMapping
virtual label internalSizeBeforeMapping() const
Return number of internal faces before mapping.
Definition: faceMapper.C:296
Foam::faceMapper::direct_
bool direct_
Is the mapping direct.
Definition: faceMapper.H:71
Foam::faceMapper::mesh_
const polyMesh & mesh_
Reference to polyMesh.
Definition: faceMapper.H:62
Foam::faceMapper::sizeBeforeMapping
virtual label sizeBeforeMapping() const
Return size of field before mapping.
Definition: faceMapper.C:290
Foam::faceMapper::directAddrPtr_
labelList * directAddrPtr_
Direct addressing (only one for of addressing is used)
Definition: faceMapper.H:77
polyMesh.H
Foam::HashSet< label, Hash< label > >
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:40
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
Foam::faceMapper::insertedFaces_
bool insertedFaces_
Are there any inserted (unmapped) faces.
Definition: faceMapper.H:68
Foam::faceMapper::insertedFaceLabelsPtr_
labelList * insertedFaceLabelsPtr_
Inserted faces.
Definition: faceMapper.H:86
Foam::mapPolyMesh::facesFromEdgesMap
const List< objectMap > & facesFromEdgesMap() const
Faces inflated from edges.
Definition: mapPolyMesh.H:418
Foam::mapPolyMesh::facesFromFacesMap
const List< objectMap > & facesFromFacesMap() const
Faces originating from faces.
Definition: mapPolyMesh.H:424
Foam::faceMapper::calcAddressing
void calcAddressing() const
Calculate addressing for mapping with inserted faces.
Definition: faceMapper.C:33
Foam::faceMapper::weightsPtr_
scalarListList * weightsPtr_
Interpolation weights.
Definition: faceMapper.H:83
faceMapper.H
Foam::FatalError
error FatalError
Foam::faceMapper::weights
virtual const scalarListList & weights() const
Return interpolaion weights.
Definition: faceMapper.C:346
Foam::faceMapper::direct
virtual bool direct() const
Is the mapping direct.
Definition: faceMapper.H:131
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::faceMapper::flipFaceFlux
virtual const labelHashSet & flipFaceFlux() const
Return flux flip map.
Definition: faceMapper.C:383
Foam::faceMapper::~faceMapper
virtual ~faceMapper()
Destructor.
Definition: faceMapper.C:276
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
Foam::faceMapper::clearOut
void clearOut()
Clear out local storage.
Definition: faceMapper.C:193
Foam::faceMapper::mpm_
const mapPolyMesh & mpm_
Reference to mapPolyMesh.
Definition: faceMapper.H:65
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::faceMapper::faceMapper
faceMapper(const faceMapper &)
Disallow default bitwise copy construct.
Foam::primitiveMesh::nFaces
label nFaces() const
Definition: primitiveMeshI.H:58
Foam::faceMapper::insertedObjectLabels
virtual const labelList & insertedObjectLabels() const
Return list of inserted faces.
Definition: faceMapper.C:364
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
Foam::UList
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
Foam::mapPolyMesh::faceMap
const labelList & faceMap() const
Old face map.
Definition: mapPolyMesh.H:406
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::scalarListList
List< scalarList > scalarListList
Definition: scalarList.H:51
Foam::faceMapper::nOldInternalFaces
virtual label nOldInternalFaces() const
Return number of old internalFaces.
Definition: faceMapper.C:389
Foam::faceMapper::interpolationAddrPtr_
labelListList * interpolationAddrPtr_
Interpolated addressing (only one for of addressing is used)
Definition: faceMapper.H:80
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::faceMapper::addressing
virtual const labelListList & addressing() const
Return interpolated addressing.
Definition: faceMapper.C:328