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) 2011-2016 OpenFOAM Foundation
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 "Time.H"
28 #include "cellIOList.H"
29 
30 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31 
33 {
34  if (debug)
35  {
36  InfoInFunction << "Resetting file instance to " << inst << endl;
37  }
38 
39  points_.writeOpt() = IOobject::AUTO_WRITE;
40  points_.instance() = inst;
41 
42  faces_.writeOpt() = IOobject::AUTO_WRITE;
43  faces_.instance() = inst;
44 
45  owner_.writeOpt() = IOobject::AUTO_WRITE;
46  owner_.instance() = inst;
47 
48  neighbour_.writeOpt() = IOobject::AUTO_WRITE;
49  neighbour_.instance() = inst;
50 
51  boundary_.writeOpt() = IOobject::AUTO_WRITE;
52  boundary_.instance() = inst;
53 
54  pointZones_.writeOpt() = IOobject::AUTO_WRITE;
55  pointZones_.instance() = inst;
56 
57  faceZones_.writeOpt() = IOobject::AUTO_WRITE;
58  faceZones_.instance() = inst;
59 
60  cellZones_.writeOpt() = IOobject::AUTO_WRITE;
61  cellZones_.instance() = inst;
62 }
63 
64 
66 {
67  if (debug)
68  {
69  InfoInFunction << "Updating mesh based on saved data." << endl;
70  }
71 
72  // Find the point and cell instance
73  fileName pointsInst(time().findInstance(meshDir(), "points"));
74  fileName facesInst(time().findInstance(meshDir(), "faces"));
75  //fileName boundaryInst(time().findInstance(meshDir(), "boundary"));
76 
77  if (debug)
78  {
79  Info<< "Faces instance: old = " << facesInstance()
80  << " new = " << facesInst << nl
81  << "Points instance: old = " << pointsInstance()
82  << " new = " << pointsInst << endl;
83  }
84 
85  if (facesInst != facesInstance())
86  {
87  // Topological change
88  if (debug)
89  {
90  Info<< "Topological change" << endl;
91  }
92 
93  clearOut();
94 
95  // Set instance to new instance. Note that points instance can differ
96  // from from faces instance.
97  setInstance(facesInst);
98  points_.instance() = pointsInst;
99 
100  points_ = pointIOField
101  (
102  IOobject
103  (
104  "points",
105  pointsInst,
106  meshSubDir,
107  *this,
110  false
111  )
112  );
113 
114  faces_ = faceCompactIOList
115  (
116  IOobject
117  (
118  "faces",
119  facesInst,
120  meshSubDir,
121  *this,
124  false
125  )
126  );
127 
128  owner_ = labelIOList
129  (
130  IOobject
131  (
132  "owner",
133  facesInst,
134  meshSubDir,
135  *this,
138  false
139  )
140  );
141 
142  neighbour_ = labelIOList
143  (
144  IOobject
145  (
146  "neighbour",
147  facesInst,
148  meshSubDir,
149  *this,
152  false
153  )
154  );
155 
156  // Reset the boundary patches
157  polyBoundaryMesh newBoundary
158  (
159  IOobject
160  (
161  "boundary",
162  facesInst,
163  meshSubDir,
164  *this,
167  false
168  ),
169  *this
170  );
171 
172  // Check that patch types and names are unchanged
173  bool boundaryChanged = false;
174 
175  if (newBoundary.size() != boundary_.size())
176  {
177  boundaryChanged = true;
178  }
179  else
180  {
181  wordList newTypes = newBoundary.types();
182  wordList newNames = newBoundary.names();
183 
184  wordList oldTypes = boundary_.types();
185  wordList oldNames = boundary_.names();
186 
187  forAll(oldTypes, patchi)
188  {
189  if
190  (
191  oldTypes[patchi] != newTypes[patchi]
192  || oldNames[patchi] != newNames[patchi]
193  )
194  {
195  boundaryChanged = true;
196  break;
197  }
198  }
199  }
200 
201  if (boundaryChanged)
202  {
204  << "unexpected consequences. Proceed with care." << endl;
205 
206  boundary_.clear();
207  boundary_.setSize(newBoundary.size());
208 
209  forAll(newBoundary, patchi)
210  {
211  boundary_.set(patchi, newBoundary[patchi].clone(boundary_));
212  }
213  }
214  else
215  {
216  forAll(boundary_, patchi)
217  {
218  boundary_[patchi] = polyPatch
219  (
220  newBoundary[patchi].name(),
221  newBoundary[patchi].size(),
222  newBoundary[patchi].start(),
223  patchi,
224  boundary_,
225  newBoundary[patchi].type()
226  );
227  }
228  }
229 
230 
231  // Boundary is set so can use initMesh now (uses boundary_ to
232  // determine internal and active faces)
233 
234  if (exists(owner_.objectPath()))
235  {
236  initMesh();
237  }
238  else
239  {
241  (
242  IOobject
243  (
244  "cells",
245  facesInst,
246  meshSubDir,
247  *this,
250  false
251  )
252  );
253 
254  // Recalculate the owner/neighbour addressing and reset the
255  // primitiveMesh
256  initMesh(cells);
257  }
258 
259 
260  // Even if number of patches stayed same still recalculate boundary
261  // data.
262 
263  // Calculate topology for the patches (processor-processor comms etc.)
264  boundary_.updateMesh();
265 
266  // Calculate the geometry for the patches (transformation tensors etc.)
267  boundary_.calcGeometry();
268 
269  // Derived info
270  bounds_ = boundBox(points_);
271  geometricD_ = Zero;
272  solutionD_ = Zero;
273 
274  // Zones
275  pointZoneMesh newPointZones
276  (
277  IOobject
278  (
279  "pointZones",
280  facesInst,
281  meshSubDir,
282  *this,
285  false
286  ),
287  *this
288  );
289 
290  label oldSize = pointZones_.size();
291 
292  if (newPointZones.size() <= pointZones_.size())
293  {
294  pointZones_.setSize(newPointZones.size());
295  }
296 
297  // Reset existing ones
298  forAll(pointZones_, czI)
299  {
300  pointZones_[czI] = newPointZones[czI];
301  }
302 
303  // Extend with extra ones
304  pointZones_.setSize(newPointZones.size());
305 
306  for (label czI = oldSize; czI < newPointZones.size(); czI++)
307  {
308  pointZones_.set(czI, newPointZones[czI].clone(pointZones_));
309  }
310 
311 
312  faceZoneMesh newFaceZones
313  (
314  IOobject
315  (
316  "faceZones",
317  facesInst,
318  meshSubDir,
319  *this,
322  false
323  ),
324  *this
325  );
326 
327  oldSize = faceZones_.size();
328 
329  if (newFaceZones.size() <= faceZones_.size())
330  {
331  faceZones_.setSize(newFaceZones.size());
332  }
333 
334  // Reset existing ones
335  forAll(faceZones_, fzI)
336  {
337  faceZones_[fzI].resetAddressing
338  (
339  newFaceZones[fzI],
340  newFaceZones[fzI].flipMap()
341  );
342  }
343 
344  // Extend with extra ones
345  faceZones_.setSize(newFaceZones.size());
346 
347  for (label fzI = oldSize; fzI < newFaceZones.size(); fzI++)
348  {
349  faceZones_.set(fzI, newFaceZones[fzI].clone(faceZones_));
350  }
351 
352 
353  cellZoneMesh newCellZones
354  (
355  IOobject
356  (
357  "cellZones",
358  facesInst,
359  meshSubDir,
360  *this,
363  false
364  ),
365  *this
366  );
367 
368  oldSize = cellZones_.size();
369 
370  if (newCellZones.size() <= cellZones_.size())
371  {
372  cellZones_.setSize(newCellZones.size());
373  }
374 
375  // Reset existing ones
376  forAll(cellZones_, czI)
377  {
378  cellZones_[czI] = newCellZones[czI];
379  }
380 
381  // Extend with extra ones
382  cellZones_.setSize(newCellZones.size());
383 
384  for (label czI = oldSize; czI < newCellZones.size(); czI++)
385  {
386  cellZones_.set(czI, newCellZones[czI].clone(cellZones_));
387  }
388 
389 
390  if (boundaryChanged)
391  {
393  }
394  else
395  {
396  return polyMesh::TOPO_CHANGE;
397  }
398  }
399  else if (pointsInst != pointsInstance())
400  {
401  // Points moved
402  if (debug)
403  {
404  Info<< "Point motion" << endl;
405  }
406 
407  clearGeom();
408 
409 
410  label nOldPoints = points_.size();
411 
412  points_.clear();
413 
414  pointIOField newPoints
415  (
416  IOobject
417  (
418  "points",
419  pointsInst,
420  meshSubDir,
421  *this,
424  false
425  )
426  );
427 
428  if (nOldPoints != 0 && nOldPoints != newPoints.size())
429  {
431  << "Point motion detected but number of points "
432  << newPoints.size() << " in "
433  << newPoints.objectPath() << " does not correspond to "
434  << " current " << nOldPoints
435  << exit(FatalError);
436  }
437 
438  points_.transfer(newPoints);
439  points_.instance() = pointsInst;
440 
441  // Calculate the geometry for the patches (transformation tensors etc.)
442  boundary_.calcGeometry();
443 
444  // Derived info
445  bounds_ = boundBox(points_);
446 
447  // Rotation can cause direction vector to change
448  geometricD_ = Zero;
449  solutionD_ = Zero;
450 
451  return polyMesh::POINTS_MOVED;
452  }
453  else
454  {
455  if (debug)
456  {
457  Info<< "No change" << endl;
458  }
459 
460  return polyMesh::UNCHANGED;
461  }
462 }
463 
464 
465 // ************************************************************************* //
const Time & time() const
Return time.
fileName objectPath() const
Return complete path + object name.
Definition: IOobject.H:363
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A class for handling file names.
Definition: fileName.H:69
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
wordList names() const
Return a list of patch names.
error FatalError
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:778
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:42
void clearOut()
Clear all geometry and addressing unnecessary for CFD.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:309
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:58
label size() const
Return number of elements in table.
const cellList & cells() const
writeOption writeOpt() const
Definition: IOobject.H:314
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
Definition: polyMesh.C:766
CompactIOList< face, label > faceCompactIOList
Definition: faceIOList.H:43
void clear()
Clear the list, i.e. set size to zero.
Definition: List.C:356
bool set(const label) const
Is element set.
Definition: PtrListI.H:65
Foam::autoPtr< IOobject > clone() const
Clone.
Definition: IOobject.H:239
static const zero Zero
Definition: zero.H:91
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:131
Foam::polyBoundaryMesh.
void clearGeom()
Clear geometry.
Definition: polyMeshClear.C:53
static const char nl
Definition: Ostream.H:262
void updateMesh()
Correct polyBoundaryMesh after topology update.
A List of objects of type <T> with automated input and output using a compact storage. Behaves like IOList except when binary output in case it writes a CompactListList.
Definition: CompactIOList.H:53
void setInstance(const fileName &)
Set the instance for mesh files.
Definition: polyMeshIO.C:32
wordList types() const
Return a list of patch types.
bool exists(const fileName &, const bool checkGzip=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
Definition: POSIX.C:480
label patchi
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:461
#define WarningInFunction
Report a warning using Foam::Warning.
const fileName & pointsInstance() const
Return the current instance directory for points.
Definition: polyMesh.C:772
void clear()
Clear the PtrList, i.e. set size to zero deleting all the.
Definition: PtrList.C:174
messageStream Info
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:88
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in.
Definition: polyMeshIO.C:65
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
const fileName & instance() const
Definition: IOobject.H:337
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:365
const word & name() const
Return name.
Definition: IOobject.H:260
IOList< label > labelIOList
Label container classes.
Definition: labelIOList.H:42
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
#define InfoInFunction
Report an information message using Foam::Info.