FreeFOAM The Cross-Platform CFD Toolkit
cellZoneSet.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 "cellZoneSet.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(cellZoneSet, 0);
42 
43 addToRunTimeSelectionTable(topoSet, cellZoneSet, word);
44 addToRunTimeSelectionTable(topoSet, cellZoneSet, size);
45 addToRunTimeSelectionTable(topoSet, cellZoneSet, set);
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
51 {
52  labelList order;
53  sortedOrder(addressing_, order);
54  inplaceReorder(order, addressing_);
55 
57  cellSet::resize(2*addressing_.size());
58  forAll(addressing_, i)
59  {
60  cellSet::insert(addressing_[i]);
61  }
62 }
63 
64 
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 
68 (
69  const polyMesh& mesh,
70  const word& name,
71  readOption r,
72  writeOption w
73 )
74 :
75  cellSet(mesh, name, 1000), // do not read cellSet
76  mesh_(mesh),
77  addressing_(0)
78 {
79  const cellZoneMesh& cellZones = mesh.cellZones();
80  label zoneID = cellZones.findZoneID(name);
81 
82  if
83  (
84  (r == IOobject::MUST_READ)
85  || (r == IOobject::READ_IF_PRESENT && zoneID != -1)
86  )
87  {
88  const cellZone& fz = cellZones[zoneID];
89  addressing_ = fz;
90  }
91 
92  updateSet();
93 
94  check(mesh.nCells());
95 }
96 
97 
99 (
100  const polyMesh& mesh,
101  const word& name,
102  const label size,
103  writeOption w
104 )
105 :
106  cellSet(mesh, name, size, w),
107  mesh_(mesh),
108  addressing_(0)
109 {
110  updateSet();
111 }
112 
113 
115 (
116  const polyMesh& mesh,
117  const word& name,
118  const topoSet& set,
119  writeOption w
120 )
121 :
122  cellSet(mesh, name, set.size(), w),
123  mesh_(mesh),
124  addressing_(refCast<const cellZoneSet>(set).addressing())
125 {
126  updateSet();
127 }
128 
129 
130 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
131 
133 {}
134 
135 
136 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
137 
138 void cellZoneSet::invert(const label maxLen)
139 {
140  label n = 0;
141 
142  for (label cellI = 0; cellI < maxLen; cellI++)
143  {
144  if (!found(cellI))
145  {
146  addressing_[n] = cellI;
147  n++;
148  }
149  }
150  addressing_.setSize(n);
151  updateSet();
152 }
153 
154 
155 void cellZoneSet::subset(const topoSet& set)
156 {
157  DynamicList<label> newAddressing(addressing_.size());
158 
159  const cellZoneSet& fSet = refCast<const cellZoneSet>(set);
160 
161  forAll(fSet.addressing(), i)
162  {
163  label cellI = fSet.addressing()[i];
164 
165  if (found(cellI))
166  {
167  newAddressing.append(cellI);
168  }
169  }
170 
171  addressing_.transfer(newAddressing);
172  updateSet();
173 }
174 
175 
176 void cellZoneSet::addSet(const topoSet& set)
177 {
178  DynamicList<label> newAddressing(addressing_);
179 
180  const cellZoneSet& fSet = refCast<const cellZoneSet>(set);
181 
182  forAll(fSet.addressing(), i)
183  {
184  label cellI = fSet.addressing()[i];
185 
186  if (!found(cellI))
187  {
188  newAddressing.append(cellI);
189  }
190  }
191 
192  addressing_.transfer(newAddressing);
193  updateSet();
194 }
195 
196 
198 {
199  DynamicList<label> newAddressing(addressing_.size());
200 
201  const cellZoneSet& fSet = refCast<const cellZoneSet>(set);
202 
203  forAll(addressing_, i)
204  {
205  label cellI = addressing_[i];
206 
207  if (!fSet.found(cellI))
208  {
209  // Not found in fSet so add
210  newAddressing.append(cellI);
211  }
212  }
213 
214  addressing_.transfer(newAddressing);
215  updateSet();
216 }
217 
218 
219 void cellZoneSet::sync(const polyMesh& mesh)
220 {}
221 
222 
223 label cellZoneSet::maxSize(const polyMesh& mesh) const
224 {
225  return mesh.nCells();
226 }
227 
228 
229 //- Write using given format, version and compression
231 (
235 ) const
236 {
237  // Write shadow cellSet
238  word oldTypeName = typeName;
239  const_cast<word&>(type()) = cellSet::typeName;
240  bool ok = cellSet::writeObject(s, v, c);
241  const_cast<word&>(type()) = oldTypeName;
242 
243  // Modify cellZone
244  cellZoneMesh& cellZones = const_cast<polyMesh&>(mesh_).cellZones();
245  label zoneID = cellZones.findZoneID(name());
246 
247  if (zoneID == -1)
248  {
249  zoneID = cellZones.size();
250 
251  cellZones.setSize(zoneID+1);
252  cellZones.set
253  (
254  zoneID,
255  new cellZone
256  (
257  name(),
258  addressing_,
259  zoneID,
260  cellZones
261  )
262  );
263  }
264  else
265  {
266  cellZones[zoneID] = addressing_;
267  }
268  cellZones.clearAddressing();
269 
270  return ok && cellZones.write();
271 }
272 
273 
275 {
276  // cellZone
277  labelList newAddressing(addressing_.size());
278 
279  label n = 0;
280  forAll(addressing_, i)
281  {
282  label cellI = addressing_[i];
283  label newCellI = morphMap.reverseCellMap()[cellI];
284  if (newCellI >= 0)
285  {
286  newAddressing[n] = newCellI;
287  n++;
288  }
289  }
290  newAddressing.setSize(n);
291 
292  addressing_.transfer(newAddressing);
293 
294  updateSet();
295 }
296 
297 
299 (
300  Ostream& os,
301  const primitiveMesh& mesh,
302  const label maxLen
303 ) const
304 {
305  cellSet::writeDebug(os, mesh, maxLen);
306 }
307 
308 
309 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
310 
311 } // End namespace Foam
312 
313 // ************************ vim: set sw=4 sts=4 et: ************************ //