FreeFOAM The Cross-Platform CFD Toolkit
ensightParts.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 
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 Foam::ensightParts::ensightParts(const polyMesh& pMesh)
31 :
32  partsList_()
33 {
34  recalculate(pMesh);
35 }
36 
37 
38 Foam::ensightParts::ensightParts(const IOobject& ioObj)
39 :
40  partsList_()
41 {
42  IOPtrList<ensightPart> ioList(ioObj);
43  partsList_.transfer(ioList);
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
48 
50 {}
51 
52 
53 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
54 
56 {
57  partsList_.clear();
58 
59  // extra space for unzoned cells
60  label nPart =
61  (
62  pMesh.cellZones().size()
63  + pMesh.boundaryMesh().size()
64  + 1
65  );
66 
67  partsList_.setSize(nPart);
68  nPart = 0;
69 
70  label nZoneCells = 0;
71 
72  // do cell zones
73  forAll(pMesh.cellZones(), zoneI)
74  {
75  const cellZone& cZone = pMesh.cellZones()[zoneI];
76  nZoneCells += cZone.size();
77 
78  if (cZone.size())
79  {
80  partsList_.set
81  (
82  nPart,
84  (
85  nPart,
86  pMesh,
87  cZone
88  )
89  );
90 
91  nPart++;
92  }
93  }
94 
95  // collect unzoned cells
96 
97  // special case: no zones at all - do entire mesh
98  if (nZoneCells == 0)
99  {
100  partsList_.set
101  (
102  nPart,
103  new ensightPartCells
104  (
105  nPart,
106  pMesh
107  )
108  );
109 
110  nPart++;
111  }
112  else if (pMesh.nCells() > nZoneCells)
113  {
114  // determine which cells are not in a cellZone
115  labelList unzoned(pMesh.nCells(), -1);
116 
117  forAll(pMesh.cellZones(), zoneI)
118  {
119  const labelList& idList = pMesh.cellZones()[zoneI];
120 
121  forAll(idList, i)
122  {
123  unzoned[idList[i]] = idList[i];
124  }
125  }
126 
127  label nUnzoned = 0;
128  forAll(unzoned, i)
129  {
130  if (unzoned[i] < 0)
131  {
132  unzoned[nUnzoned] = i;
133  nUnzoned++;
134  }
135  }
136  unzoned.setSize(nUnzoned);
137 
138  if (unzoned.size())
139  {
140  partsList_.set
141  (
142  nPart,
143  new ensightPartCells
144  (
145  nPart,
146  pMesh,
147  unzoned
148  )
149  );
150 
151  nPart++;
152  }
153  }
154 
155 
156  // do boundaries, skipping empty and processor patches
157  forAll(pMesh.boundaryMesh(), patchI)
158  {
159  const polyPatch& pPatch = pMesh.boundaryMesh()[patchI];
160  if (pPatch.size() && !isA<processorPolyPatch>(pPatch))
161  {
162  partsList_.set
163  (
164  nPart,
165  new ensightPartFaces
166  (
167  nPart,
168  pMesh,
169  pPatch
170  )
171  );
172 
173  nPart++;
174  }
175  }
176 
177  // truncate to correct size
178  partsList_.setSize(nPart);
179 }
180 
181 
183 (
184  const labelList& origCellId,
185  const labelList& origFaceId
186 )
187 {
188  forAll(partsList_, partI)
189  {
190  if (partsList_[partI].isCellData())
191  {
192  partsList_[partI].renumber(origCellId);
193  }
194  else
195  {
196  partsList_[partI].renumber(origFaceId);
197  }
198  }
199 }
200 
201 
203 {
204  // with some feedback
205  Info<< "write geometry part:" << nl << flush;
206 
207  forAll(partsList_, partI)
208  {
209  Info<< " " << partI << flush;
210  partsList_[partI].writeGeometry(os);
211  }
212 }
213 
214 
216 {
217  forAll(partsList_, partI)
218  {
219  partsList_[partI].writeSummary(os);
220  }
221 
222  return true;
223 }
224 
225 
227 {
228  // Write size of list
229  os << nl << partsList_.size();
230 
231  // Write beginning of contents
232  os << nl << token::BEGIN_LIST;
233 
234  // Write list contents
235  forAll(partsList_, i)
236  {
237  os << nl << partsList_[i];
238  }
239 
240  // Write end of contents
241  os << nl << token::END_LIST << nl;
242 
243  // Check state of IOstream
244  os.check("Ostream& operator<<(Ostream&, const PtrList&)");
245 }
246 
247 
249 (
250  ensightFile& os,
251  const List<scalar>& field,
252  bool useFaceData
253 ) const
254 {
255  forAll(partsList_, partI)
256  {
257  if
258  (
259  useFaceData
260  ? partsList_[partI].isFaceData()
261  : partsList_[partI].isCellData()
262  )
263  {
264  partsList_[partI].writeScalarField(os,field);
265  }
266  }
267 }
268 
269 
271 (
272  ensightFile& os,
273  const List<scalar>& field0,
274  const List<scalar>& field1,
275  const List<scalar>& field2,
276  bool useFaceData
277 ) const
278 {
279  forAll(partsList_, partI)
280  {
281  if
282  (
283  useFaceData
284  ? partsList_[partI].isFaceData()
285  : partsList_[partI].isCellData()
286  )
287  {
288  partsList_[partI].writeVectorField(os, field0, field1, field2);
289  }
290  }
291 }
292 
293 
294 // * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //
295 
296 Foam::ensightGeoFile& Foam::operator<<
297 (
298  ensightGeoFile& os,
299  const ensightParts& parts
300 )
301 {
302  parts.writeGeometry(os);
303  return os;
304 }
305 
306 
307 // ************************ vim: set sw=4 sts=4 et: ************************ //