FreeFOAM The Cross-Platform CFD Toolkit
polyMeshIO.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 "polyMesh.H"
27 #include <OpenFOAM/Time.H>
28 #include <OpenFOAM/cellIOList.H>
29 
30 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31 
33 {
34  if (debug)
35  {
36  Info<< "void polyMesh::setInstance(const fileName& inst) : "
37  << "Resetting file instance to " << inst << endl;
38  }
39 
40  points_.writeOpt() = IOobject::AUTO_WRITE;
41  points_.instance() = inst;
42 
43  faces_.writeOpt() = IOobject::AUTO_WRITE;
44  faces_.instance() = inst;
45 
46  owner_.writeOpt() = IOobject::AUTO_WRITE;
47  owner_.instance() = inst;
48 
49  neighbour_.writeOpt() = IOobject::AUTO_WRITE;
50  neighbour_.instance() = inst;
51 
52  boundary_.writeOpt() = IOobject::AUTO_WRITE;
53  boundary_.instance() = inst;
54 
55  pointZones_.writeOpt() = IOobject::AUTO_WRITE;
56  pointZones_.instance() = inst;
57 
58  faceZones_.writeOpt() = IOobject::AUTO_WRITE;
59  faceZones_.instance() = inst;
60 
61  cellZones_.writeOpt() = IOobject::AUTO_WRITE;
62  cellZones_.instance() = inst;
63 }
64 
65 
67 {
68  if (debug)
69  {
70  Info<< "polyMesh::readUpdateState polyMesh::readUpdate() : "
71  << "Updating mesh based on saved data." << endl;
72  }
73 
74  // Find the point and cell instance
75  fileName pointsInst(time().findInstance(meshDir(), "points"));
76  fileName facesInst(time().findInstance(meshDir(), "faces"));
77 
78  if (debug)
79  {
80  Info<< "Faces instance: old = " << facesInstance()
81  << " new = " << facesInst << nl
82  << "Points instance: old = " << pointsInstance()
83  << " new = " << pointsInst << endl;
84  }
85 
86  if (facesInst != facesInstance())
87  {
88  // Topological change
89  if (debug)
90  {
91  Info << "Topological change" << endl;
92  }
93 
94  clearOut();
95 
96  // Set instance to new instance. Note that points instance can differ
97  // from from faces instance.
98  setInstance(facesInst);
99  points_.instance() = pointsInst;
100 
101  points_ = pointIOField
102  (
103  IOobject
104  (
105  "points",
106  pointsInst,
107  meshSubDir,
108  *this,
111  false
112  )
113  );
114 
115  faces_ = faceIOList
116  (
117  IOobject
118  (
119  "faces",
120  facesInst,
121  meshSubDir,
122  *this,
125  false
126  )
127  );
128 
129  owner_ = labelIOList
130  (
131  IOobject
132  (
133  "owner",
134  facesInst,
135  meshSubDir,
136  *this,
139  false
140  )
141  );
142 
143  neighbour_ = labelIOList
144  (
145  IOobject
146  (
147  "neighbour",
148  facesInst,
149  meshSubDir,
150  *this,
153  false
154  )
155  );
156 
157  // Reset the boundary patches
158  polyBoundaryMesh newBoundary
159  (
160  IOobject
161  (
162  "boundary",
163  facesInst,
164  meshSubDir,
165  *this,
168  false
169  ),
170  *this
171  );
172 
173  // Check that patch types and names are unchanged
174  bool boundaryChanged = false;
175 
176  if (newBoundary.size() != boundary_.size())
177  {
178  boundaryChanged = true;
179  }
180  else
181  {
182  wordList newTypes = newBoundary.types();
183  wordList newNames = newBoundary.names();
184 
185  wordList oldTypes = boundary_.types();
186  wordList oldNames = boundary_.names();
187 
188  forAll (oldTypes, patchI)
189  {
190  if
191  (
192  oldTypes[patchI] != newTypes[patchI]
193  || oldNames[patchI] != newNames[patchI]
194  )
195  {
196  boundaryChanged = true;
197  break;
198  }
199  }
200  }
201 
202  if (boundaryChanged)
203  {
204  WarningIn("polyMesh::readUpdateState polyMesh::readUpdate()")
205  << "Number of patches has changed. This may have "
206  << "unexpected consequences. Proceed with care." << endl;
207 
208  boundary_.clear();
209  boundary_.setSize(newBoundary.size());
210 
211  forAll (newBoundary, patchI)
212  {
213  boundary_.set(patchI, newBoundary[patchI].clone(boundary_));
214  }
215  }
216  else
217  {
218  forAll (boundary_, patchI)
219  {
220  boundary_[patchI] = polyPatch
221  (
222  newBoundary[patchI].name(),
223  newBoundary[patchI].size(),
224  newBoundary[patchI].start(),
225  patchI,
226  boundary_
227  );
228  }
229  }
230 
231 
232  // Boundary is set so can use initMesh now (uses boundary_ to
233  // determine internal and active faces)
234 
235  if (exists(owner_.objectPath()))
236  {
237  initMesh();
238  }
239  else
240  {
242  (
243  IOobject
244  (
245  "cells",
246  facesInst,
247  meshSubDir,
248  *this,
251  false
252  )
253  );
254 
255  // Recalculate the owner/neighbour addressing and reset the
256  // primitiveMesh
257  initMesh(cells);
258  }
259 
260 
261  // Even if number of patches stayed same still recalculate boundary
262  // data.
263 
264  // Calculate topology for the patches (processor-processor comms etc.)
265  boundary_.updateMesh();
266 
267  // Calculate the geometry for the patches (transformation tensors etc.)
268  boundary_.calcGeometry();
269 
270  // Derived info
271  bounds_ = boundBox(points_);
272  geometricD_ = Vector<label>::zero;
273  solutionD_ = Vector<label>::zero;
274 
275  // Zones
276  pointZoneMesh newPointZones
277  (
278  IOobject
279  (
280  "pointZones",
281  facesInst,
282  meshSubDir,
283  *this,
286  false
287  ),
288  *this
289  );
290 
291  label oldSize = pointZones_.size();
292 
293  if (newPointZones.size() <= pointZones_.size())
294  {
295  pointZones_.setSize(newPointZones.size());
296  }
297 
298  // Reset existing ones
299  forAll (pointZones_, czI)
300  {
301  pointZones_[czI] = newPointZones[czI];
302  }
303 
304  // Extend with extra ones
305  pointZones_.setSize(newPointZones.size());
306 
307  for (label czI = oldSize; czI < newPointZones.size(); czI++)
308  {
309  pointZones_.set(czI, newPointZones[czI].clone(pointZones_));
310  }
311 
312 
313  faceZoneMesh newFaceZones
314  (
315  IOobject
316  (
317  "faceZones",
318  facesInst,
319  meshSubDir,
320  *this,
323  false
324  ),
325  *this
326  );
327 
328  oldSize = faceZones_.size();
329 
330  if (newFaceZones.size() <= faceZones_.size())
331  {
332  faceZones_.setSize(newFaceZones.size());
333  }
334 
335  // Reset existing ones
336  forAll (faceZones_, fzI)
337  {
338  faceZones_[fzI].resetAddressing
339  (
340  newFaceZones[fzI],
341  newFaceZones[fzI].flipMap()
342  );
343  }
344 
345  // Extend with extra ones
346  faceZones_.setSize(newFaceZones.size());
347 
348  for (label fzI = oldSize; fzI < newFaceZones.size(); fzI++)
349  {
350  faceZones_.set(fzI, newFaceZones[fzI].clone(faceZones_));
351  }
352 
353 
354  cellZoneMesh newCellZones
355  (
356  IOobject
357  (
358  "cellZones",
359  facesInst,
360  meshSubDir,
361  *this,
364  false
365  ),
366  *this
367  );
368 
369  oldSize = cellZones_.size();
370 
371  if (newCellZones.size() <= cellZones_.size())
372  {
373  cellZones_.setSize(newCellZones.size());
374  }
375 
376  // Reset existing ones
377  forAll (cellZones_, czI)
378  {
379  cellZones_[czI] = newCellZones[czI];
380  }
381 
382  // Extend with extra ones
383  cellZones_.setSize(newCellZones.size());
384 
385  for (label czI = oldSize; czI < newCellZones.size(); czI++)
386  {
387  cellZones_.set(czI, newCellZones[czI].clone(cellZones_));
388  }
389 
390 
391  if (boundaryChanged)
392  {
394  }
395  else
396  {
397  return polyMesh::TOPO_CHANGE;
398  }
399  }
400  else if (pointsInst != pointsInstance())
401  {
402  // Points moved
403  if (debug)
404  {
405  Info << "Point motion" << endl;
406  }
407 
408  clearGeom();
409 
410  points_.instance() = pointsInst;
411 
412  points_ = pointIOField
413  (
414  IOobject
415  (
416  "points",
417  pointsInst,
418  meshSubDir,
419  *this,
422  false
423  )
424  );
425 
426  // Derived info
427  bounds_ = boundBox(points_);
428 
429  // Rotation can cause direction vector to change
430  geometricD_ = Vector<label>::zero;
431  solutionD_ = Vector<label>::zero;
432 
433  return polyMesh::POINTS_MOVED;
434  }
435  else
436  {
437  if (debug)
438  {
439  Info << "No change" << endl;
440  }
441 
442  return polyMesh::UNCHANGED;
443  }
444 }
445 
446 
447 // ************************ vim: set sw=4 sts=4 et: ************************ //