FreeFOAM The Cross-Platform CFD Toolkit
faceZoneSet.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 "faceZoneSet.H"
27 #include <OpenFOAM/mapPolyMesh.H>
28 #include <OpenFOAM/polyMesh.H>
31 
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 
41 defineTypeNameAndDebug(faceZoneSet, 0);
42 
43 addToRunTimeSelectionTable(topoSet, faceZoneSet, word);
44 addToRunTimeSelectionTable(topoSet, faceZoneSet, size);
45 addToRunTimeSelectionTable(topoSet, faceZoneSet, set);
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
51 {
52  labelList order;
53  sortedOrder(addressing_, order);
54  inplaceReorder(order, addressing_);
55  inplaceReorder(order, flipMap_);
56 
58  faceSet::resize(2*addressing_.size());
59  forAll(addressing_, i)
60  {
61  faceSet::insert(addressing_[i]);
62  }
63 }
64 
65 
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67 
69 (
70  const polyMesh& mesh,
71  const word& name,
72  readOption r,
73  writeOption w
74 )
75 :
76  faceSet(mesh, name, 1000), // do not read faceSet
77  mesh_(mesh),
78  addressing_(0),
79  flipMap_(0)
80 {
81  const faceZoneMesh& faceZones = mesh.faceZones();
82  label zoneID = faceZones.findZoneID(name);
83 
84  if
85  (
86  (r == IOobject::MUST_READ)
87  || (r == IOobject::READ_IF_PRESENT && zoneID != -1)
88  )
89  {
90  const faceZone& fz = faceZones[zoneID];
91  addressing_ = fz;
92  flipMap_ = fz.flipMap();
93  }
94 
95  updateSet();
96 
97  check(mesh.nFaces());
98 }
99 
100 
102 (
103  const polyMesh& mesh,
104  const word& name,
105  const label size,
106  writeOption w
107 )
108 :
109  faceSet(mesh, name, size, w),
110  mesh_(mesh),
111  addressing_(0),
112  flipMap_(0)
113 {
114  updateSet();
115 }
116 
117 
119 (
120  const polyMesh& mesh,
121  const word& name,
122  const topoSet& set,
123  writeOption w
124 )
125 :
126  faceSet(mesh, name, set.size(), w),
127  mesh_(mesh),
128  addressing_(refCast<const faceZoneSet>(set).addressing()),
129  flipMap_(refCast<const faceZoneSet>(set).flipMap())
130 {
131  updateSet();
132 }
133 
134 
135 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
136 
138 {}
139 
140 
141 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
142 
143 void faceZoneSet::invert(const label maxLen)
144 {
145  label n = 0;
146 
147  for (label faceI = 0; faceI < maxLen; faceI++)
148  {
149  if (!found(faceI))
150  {
151  addressing_[n] = faceI;
152  flipMap_[n] = false; //? or true?
153  n++;
154  }
155  }
156  addressing_.setSize(n);
157  flipMap_.setSize(n);
158  updateSet();
159 }
160 
161 
162 void faceZoneSet::subset(const topoSet& set)
163 {
164  label nConflict = 0;
165 
166  DynamicList<label> newAddressing(addressing_.size());
167  DynamicList<bool> newFlipMap(flipMap_.size());
168 
169  Map<label> faceToIndex(addressing_.size());
170  forAll(addressing_, i)
171  {
172  faceToIndex.insert(addressing_[i], i);
173  }
174 
175  const faceZoneSet& fSet = refCast<const faceZoneSet>(set);
176 
177  forAll(fSet.addressing(), i)
178  {
179  label faceI = fSet.addressing()[i];
180 
181  Map<label>::const_iterator iter = faceToIndex.find(faceI);
182 
183  if (iter != faceToIndex.end())
184  {
185  label index = iter();
186 
187  if (fSet.flipMap()[i] != flipMap_[index])
188  {
189  nConflict++;
190  }
191  newAddressing.append(faceI);
192  newFlipMap.append(flipMap_[index]);
193  }
194  }
195 
196  if (nConflict > 0)
197  {
198  WarningIn(" faceZoneSet::subset(const topoSet&)")
199  << "subset : there are " << nConflict
200  << " faces with different orientation in faceZonesSets "
201  << name() << " and " << set.name() << endl;
202  }
203 
204  addressing_.transfer(newAddressing);
205  flipMap_.transfer(newFlipMap);
206  updateSet();
207 }
208 
209 
210 void faceZoneSet::addSet(const topoSet& set)
211 {
212  label nConflict = 0;
213 
214  DynamicList<label> newAddressing(addressing_);
215  DynamicList<bool> newFlipMap(flipMap_);
216 
217  Map<label> faceToIndex(addressing_.size());
218  forAll(addressing_, i)
219  {
220  faceToIndex.insert(addressing_[i], i);
221  }
222 
223  const faceZoneSet& fSet = refCast<const faceZoneSet>(set);
224 
225  forAll(fSet.addressing(), i)
226  {
227  label faceI = fSet.addressing()[i];
228 
229  Map<label>::const_iterator iter = faceToIndex.find(faceI);
230 
231  if (iter != faceToIndex.end())
232  {
233  label index = iter();
234 
235  if (fSet.flipMap()[i] != flipMap_[index])
236  {
237  nConflict++;
238  }
239  }
240  else
241  {
242  newAddressing.append(faceI);
243  newFlipMap.append(fSet.flipMap()[i]);
244  }
245  }
246 
247  if (nConflict > 0)
248  {
249  WarningIn("faceZoneSet::addSet(const topoSet&)")
250  << "addSet : there are " << nConflict
251  << " faces with different orientation in faceZonesSets "
252  << name() << " and " << set.name() << endl;
253  }
254 
255  addressing_.transfer(newAddressing);
256  flipMap_.transfer(newFlipMap);
257  updateSet();
258 }
259 
260 
262 {
263  label nConflict = 0;
264 
265  DynamicList<label> newAddressing(addressing_.size());
266  DynamicList<bool> newFlipMap(flipMap_.size());
267 
268  const faceZoneSet& fSet = refCast<const faceZoneSet>(set);
269 
270  Map<label> faceToIndex(fSet.addressing().size());
271  forAll(fSet.addressing(), i)
272  {
273  faceToIndex.insert(fSet.addressing()[i], i);
274  }
275 
276  forAll(addressing_, i)
277  {
278  label faceI = addressing_[i];
279 
280  Map<label>::const_iterator iter = faceToIndex.find(faceI);
281 
282  if (iter != faceToIndex.end())
283  {
284  label index = iter();
285 
286  if (fSet.flipMap()[index] != flipMap_[i])
287  {
288  nConflict++;
289  }
290  }
291  else
292  {
293  // Not found in fSet so add
294  newAddressing.append(faceI);
295  newFlipMap.append(fSet.flipMap()[i]);
296  }
297  }
298 
299  if (nConflict > 0)
300  {
301  WarningIn("faceZoneSet::deleteSet(const topoSet&)")
302  << "deleteSet : there are " << nConflict
303  << " faces with different orientation in faceZonesSets "
304  << name() << " and " << set.name() << endl;
305  }
306 
307  addressing_.transfer(newAddressing);
308  flipMap_.transfer(newFlipMap);
309  updateSet();
310 }
311 
312 
313 void faceZoneSet::sync(const polyMesh& mesh)
314 {}
315 
316 
317 label faceZoneSet::maxSize(const polyMesh& mesh) const
318 {
319  return mesh.nFaces();
320 }
321 
322 
323 //- Write using given format, version and compression
325 (
329 ) const
330 {
331  // Write shadow faceSet
332  word oldTypeName = typeName;
333  const_cast<word&>(type()) = faceSet::typeName;
334  bool ok = faceSet::writeObject(s, v, c);
335  const_cast<word&>(type()) = oldTypeName;
336 
337  // Modify faceZone
338  faceZoneMesh& faceZones = const_cast<polyMesh&>(mesh_).faceZones();
339  label zoneID = faceZones.findZoneID(name());
340 
341  if (zoneID == -1)
342  {
343  zoneID = faceZones.size();
344 
345  faceZones.setSize(zoneID+1);
346  faceZones.set
347  (
348  zoneID,
349  new faceZone
350  (
351  name(),
352  addressing_,
353  flipMap_,
354  zoneID,
355  faceZones
356  )
357  );
358  }
359  else
360  {
361  faceZones[zoneID].resetAddressing(addressing_, flipMap_);
362  }
363  faceZones.clearAddressing();
364 
365  return ok && faceZones.write();
366 }
367 
368 
370 {
371  // faceZone
372  labelList newAddressing(addressing_.size());
373  boolList newFlipMap(flipMap_.size());
374 
375  label n = 0;
376  forAll(addressing_, i)
377  {
378  label faceI = addressing_[i];
379  label newFaceI = morphMap.reverseFaceMap()[faceI];
380  if (newFaceI >= 0)
381  {
382  newAddressing[n] = newFaceI;
383  newFlipMap[n] = flipMap_[i];
384  n++;
385  }
386  }
387  newAddressing.setSize(n);
388  newFlipMap.setSize(n);
389 
390  addressing_.transfer(newAddressing);
391  flipMap_.transfer(newFlipMap);
392 
393  updateSet();
394 }
395 
396 
398 (
399  Ostream& os,
400  const primitiveMesh& mesh,
401  const label maxLen
402 ) const
403 {
404  faceSet::writeDebug(os, mesh, maxLen);
405 }
406 
407 
408 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
409 
410 } // End namespace Foam
411 
412 // ************************ vim: set sw=4 sts=4 et: ************************ //