FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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"
28 #include <OpenFOAM/polyMesh.H>
29 #include <OpenFOAM/mapPolyMesh.H>
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 
34 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 
36 void Foam::faceMapper::calcAddressing() const
37 {
38  if
39  (
40  directAddrPtr_
41  || interpolationAddrPtr_
42  || weightsPtr_
43  || insertedFaceLabelsPtr_
44  )
45  {
46  FatalErrorIn("void faceMapper::calcAddressing() const")
47  << "Addressing already calculated."
48  << abort(FatalError);
49  }
50 
51  if (direct())
52  {
53  // Direct addressing, no weights
54 
55  directAddrPtr_ = new labelList(mpm_.faceMap());
56  labelList& directAddr = *directAddrPtr_;
57 
58  // Reset the size of addressing list to contain only live faces
59  directAddr.setSize(mesh_.nFaces());
60 
61  insertedFaceLabelsPtr_ = new labelList(mesh_.nFaces());
62  labelList& insertedFaces = *insertedFaceLabelsPtr_;
63 
64  label nInsertedFaces = 0;
65 
66  forAll (directAddr, faceI)
67  {
68  if (directAddr[faceI] < 0)
69  {
70  // Found inserted face
71  directAddr[faceI] = 0;
72  insertedFaces[nInsertedFaces] = faceI;
73  nInsertedFaces++;
74  }
75  }
76 
77  insertedFaces.setSize(nInsertedFaces);
78  }
79  else
80  {
81  // Interpolative addressing
82 
83  interpolationAddrPtr_ = new labelListList(mesh_.nFaces());
84  labelListList& addr = *interpolationAddrPtr_;
85 
86  weightsPtr_ = new scalarListList(mesh_.nFaces());
87  scalarListList& w = *weightsPtr_;
88 
89  const List<objectMap>& ffp = mpm_.facesFromPointsMap();
90 
91  forAll (ffp, ffpI)
92  {
93  // Get addressing
94  const labelList& mo = ffp[ffpI].masterObjects();
95 
96  label faceI = ffp[ffpI].index();
97 
98  if (addr[faceI].size())
99  {
100  FatalErrorIn("void faceMapper::calcAddressing() const")
101  << "Master face " << faceI
102  << " mapped from point faces " << mo
103  << " already destination of mapping." << abort(FatalError);
104  }
105 
106  // Map from masters, uniform weights
107  addr[faceI] = mo;
108  w[faceI] = scalarList(mo.size(), 1.0/mo.size());
109  }
110 
111  const List<objectMap>& ffe = mpm_.facesFromEdgesMap();
112 
113  forAll (ffe, ffeI)
114  {
115  // Get addressing
116  const labelList& mo = ffe[ffeI].masterObjects();
117 
118  label faceI = ffe[ffeI].index();
119 
120  if (addr[faceI].size())
121  {
122  FatalErrorIn("void faceMapper::calcAddressing() const")
123  << "Master face " << faceI
124  << " mapped from edge faces " << mo
125  << " already destination of mapping." << abort(FatalError);
126  }
127 
128  // Map from masters, uniform weights
129  addr[faceI] = mo;
130  w[faceI] = scalarList(mo.size(), 1.0/mo.size());
131  }
132 
133  const List<objectMap>& fff = mpm_.facesFromFacesMap();
134 
135  forAll (fff, fffI)
136  {
137  // Get addressing
138  const labelList& mo = fff[fffI].masterObjects();
139 
140  label faceI = fff[fffI].index();
141 
142  if (addr[faceI].size())
143  {
144  FatalErrorIn("void faceMapper::calcAddressing() const")
145  << "Master face " << faceI
146  << " mapped from face faces " << mo
147  << " already destination of mapping." << abort(FatalError);
148  }
149 
150  // Map from masters, uniform weights
151  addr[faceI] = mo;
152  w[faceI] = scalarList(mo.size(), 1.0/mo.size());
153  }
154 
155 
156  // Do mapped faces. Note that can already be set from facesFromFaces
157  // so check if addressing size still zero.
158  const labelList& fm = mpm_.faceMap();
159 
160  forAll (fm, faceI)
161  {
162  if (fm[faceI] > -1 && addr[faceI].empty())
163  {
164  // Mapped from a single face
165  addr[faceI] = labelList(1, fm[faceI]);
166  w[faceI] = scalarList(1, 1.0);
167  }
168  }
169 
170 
171  // Grab inserted points (for them the size of addressing is still zero)
172 
173  insertedFaceLabelsPtr_ = new labelList(mesh_.nFaces());
174  labelList& insertedFaces = *insertedFaceLabelsPtr_;
175 
176  label nInsertedFaces = 0;
177 
178  forAll (addr, faceI)
179  {
180  if (addr[faceI].empty())
181  {
182  // Mapped from a dummy face
183  addr[faceI] = labelList(1, 0);
184  w[faceI] = scalarList(1, 1.0);
185 
186  insertedFaces[nInsertedFaces] = faceI;
187  nInsertedFaces++;
188  }
189  }
190 
191  insertedFaces.setSize(nInsertedFaces);
192  }
193 }
194 
195 
196 void Foam::faceMapper::clearOut()
197 {
198  deleteDemandDrivenData(directAddrPtr_);
199  deleteDemandDrivenData(interpolationAddrPtr_);
200  deleteDemandDrivenData(weightsPtr_);
201  deleteDemandDrivenData(insertedFaceLabelsPtr_);
202 }
203 
204 
205 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
206 
207 // Construct from components
208 Foam::faceMapper::faceMapper(const mapPolyMesh& mpm)
209 :
210  mesh_(mpm.mesh()),
211  mpm_(mpm),
212  insertedFaces_(true),
213  direct_(false),
214  directAddrPtr_(NULL),
215  interpolationAddrPtr_(NULL),
216  weightsPtr_(NULL),
217  insertedFaceLabelsPtr_(NULL)
218 {
219  // Check for possibility of direct mapping
220  if
221  (
222  mpm_.facesFromPointsMap().empty()
223  && mpm_.facesFromEdgesMap().empty()
224  && mpm_.facesFromFacesMap().empty()
225  )
226  {
227  direct_ = true;
228  }
229  else
230  {
231  direct_ = false;
232  }
233 
234  // Check for inserted faces
235  if (direct_ && (mpm_.faceMap().empty() || min(mpm_.faceMap()) > -1))
236  {
237  insertedFaces_ = false;
238  }
239  else
240  {
241  // Need to check all 3 lists to see if there are inserted faces
242  // with no owner
243 
244  // Make a copy of the face map, add the entries for faces from points
245  // and faces from edges and check for left-overs
246  labelList fm(mesh_.nFaces(), -1);
247 
248  const List<objectMap>& ffp = mpm_.facesFromPointsMap();
249 
250  forAll (ffp, ffpI)
251  {
252  fm[ffp[ffpI].index()] = 0;
253  }
254 
255  const List<objectMap>& ffe = mpm_.facesFromEdgesMap();
256 
257  forAll (ffe, ffeI)
258  {
259  fm[ffe[ffeI].index()] = 0;
260  }
261 
262  const List<objectMap>& fff = mpm_.facesFromFacesMap();
263 
264  forAll (fff, fffI)
265  {
266  fm[fff[fffI].index()] = 0;
267  }
268 
269  if (min(fm) < 0)
270  {
271  insertedFaces_ = true;
272  }
273  }
274 }
275 
276 
277 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
278 
280 {
281  clearOut();
282 }
283 
284 
285 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
286 
287 Foam::label Foam::faceMapper::size() const
288 {
289  return mesh_.nFaces();
290 }
291 
292 
294 {
295  return mpm_.nOldFaces();
296 }
297 
298 
300 {
301  return mpm_.nOldInternalFaces();
302 }
303 
304 
306 {
307  if (!direct())
308  {
310  (
311  "const unallocLabelList& faceMapper::directAddressing() const"
312  ) << "Requested direct addressing for an interpolative mapper."
313  << abort(FatalError);
314  }
315 
316  if (!insertedObjects())
317  {
318  // No inserted faces. Re-use faceMap
319  return mpm_.faceMap();
320  }
321  else
322  {
323  if (!directAddrPtr_)
324  {
325  calcAddressing();
326  }
327 
328  return *directAddrPtr_;
329  }
330 }
331 
332 
334 {
335  if (direct())
336  {
338  (
339  "const labelListList& faceMapper::addressing() const"
340  ) << "Requested interpolative addressing for a direct mapper."
341  << abort(FatalError);
342  }
343 
344  if (!interpolationAddrPtr_)
345  {
346  calcAddressing();
347  }
348 
349  return *interpolationAddrPtr_;
350 }
351 
352 
354 {
355  if (direct())
356  {
358  (
359  "const scalarListList& faceMapper::weights() const"
360  ) << "Requested interpolative weights for a direct mapper."
361  << abort(FatalError);
362  }
363 
364  if (!weightsPtr_)
365  {
366  calcAddressing();
367  }
368 
369  return *weightsPtr_;
370 }
371 
372 
374 {
375  if (!insertedFaceLabelsPtr_)
376  {
377  if (!insertedObjects())
378  {
379  // There are no inserted faces
380  insertedFaceLabelsPtr_ = new labelList(0);
381  }
382  else
383  {
384  calcAddressing();
385  }
386  }
387 
388  return *insertedFaceLabelsPtr_;
389 }
390 
391 
393 {
394  return mpm_.flipFaceFlux();
395 }
396 
397 
399 {
400  return mpm_.nOldInternalFaces();
401 }
402 
403 
405 {
406  return mpm_.oldPatchStarts();
407 }
408 
409 
411 {
412  return mpm_.oldPatchSizes();
413 }
414 
415 
416 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
417 
418 
419 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
420 
421 
422 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
423 
424 
425 // ************************ vim: set sw=4 sts=4 et: ************************ //