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-2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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  Info<< "void polyMesh::setInstance(const fileName& inst) : "
37  << "Resetting file instance to " << inst << endl;
38  }
39 
41  points_.instance() = inst;
42 
43  faces_.writeOpt() = IOobject::AUTO_WRITE;
44  faces_.instance() = inst;
45 
47  owner_.instance() = inst;
48 
50  neighbour_.instance() = inst;
51 
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  //fileName boundaryInst(time().findInstance(meshDir(), "boundary"));
78 
79  if (debug)
80  {
81  Info<< "Faces instance: old = " << facesInstance()
82  << " new = " << facesInst << nl
83  //<< "Boundary instance: old = " << boundary_.instance()
84  //<< " new = " << boundaryInst << nl
85  << "Points instance: old = " << pointsInstance()
86  << " new = " << pointsInst << endl;
87  }
88 
89  if (facesInst != facesInstance())
90  {
91  // Topological change
92  if (debug)
93  {
94  Info<< "Topological change" << endl;
95  }
96 
97  clearOut();
98 
99  // Set instance to new instance. Note that points instance can differ
100  // from from faces instance.
101  setInstance(facesInst);
102  points_.instance() = pointsInst;
103 
104  points_ = pointIOField
105  (
106  IOobject
107  (
108  "points",
109  pointsInst,
110  meshSubDir,
111  *this,
114  false
115  )
116  );
117 
118  faces_ = faceCompactIOList
119  (
120  IOobject
121  (
122  "faces",
123  facesInst,
124  meshSubDir,
125  *this,
128  false
129  )
130  );
131 
132  owner_ = labelIOList
133  (
134  IOobject
135  (
136  "owner",
137  facesInst,
138  meshSubDir,
139  *this,
142  false
143  )
144  );
145 
146  neighbour_ = labelIOList
147  (
148  IOobject
149  (
150  "neighbour",
151  facesInst,
152  meshSubDir,
153  *this,
156  false
157  )
158  );
159 
160  // Reset the boundary patches
161  polyBoundaryMesh newBoundary
162  (
163  IOobject
164  (
165  "boundary",
166  facesInst,
167  meshSubDir,
168  *this,
171  false
172  ),
173  *this
174  );
175 
176  // Check that patch types and names are unchanged
177  bool boundaryChanged = false;
178 
179  if (newBoundary.size() != boundary_.size())
180  {
181  boundaryChanged = true;
182  }
183  else
184  {
185  wordList newTypes = newBoundary.types();
186  wordList newNames = newBoundary.names();
187 
188  wordList oldTypes = boundary_.types();
189  wordList oldNames = boundary_.names();
190 
191  forAll(oldTypes, patchI)
192  {
193  if
194  (
195  oldTypes[patchI] != newTypes[patchI]
196  || oldNames[patchI] != newNames[patchI]
197  )
198  {
199  boundaryChanged = true;
200  break;
201  }
202  }
203  }
204 
205  if (boundaryChanged)
206  {
208  << "unexpected consequences. Proceed with care." << endl;
209 
210  boundary_.clear();
211  boundary_.setSize(newBoundary.size());
212 
213  forAll(newBoundary, patchI)
214  {
215  boundary_.set(patchI, newBoundary[patchI].clone(boundary_));
216  }
217  }
218  else
219  {
220  forAll(boundary_, patchI)
221  {
222  boundary_[patchI] = polyPatch
223  (
224  newBoundary[patchI].name(),
225  newBoundary[patchI].size(),
226  newBoundary[patchI].start(),
227  patchI,
228  boundary_,
229  newBoundary[patchI].physicalType(),
230  newBoundary[patchI].inGroups()
231  );
232  }
233  }
234 
235 
236  // Boundary is set so can use initMesh now (uses boundary_ to
237  // determine internal and active faces)
238 
239  if (exists(owner_.objectPath()))
240  {
241  initMesh();
242  }
243  else
244  {
246  (
247  IOobject
248  (
249  "cells",
250  facesInst,
251  meshSubDir,
252  *this,
255  false
256  )
257  );
258 
259  // Recalculate the owner/neighbour addressing and reset the
260  // primitiveMesh
261  initMesh(cells);
262  }
263 
264 
265  // Even if number of patches stayed same still recalculate boundary
266  // data.
267 
268  // Calculate topology for the patches (processor-processor comms etc.)
269  boundary_.updateMesh();
270 
271  // Calculate the geometry for the patches (transformation tensors etc.)
272  boundary_.calcGeometry();
273 
274  // Derived info
275  bounds_ = boundBox(points_);
276  geometricD_ = Vector<label>::zero;
277  solutionD_ = Vector<label>::zero;
278 
279  // Zones
280  pointZoneMesh newPointZones
281  (
282  IOobject
283  (
284  "pointZones",
285  facesInst,
286  meshSubDir,
287  *this,
290  false
291  ),
292  *this
293  );
294 
295  label oldSize = pointZones_.size();
296 
297  if (newPointZones.size() <= pointZones_.size())
298  {
299  pointZones_.setSize(newPointZones.size());
300  }
301 
302  // Reset existing ones
303  forAll(pointZones_, czI)
304  {
305  pointZones_[czI] = newPointZones[czI];
306  }
307 
308  // Extend with extra ones
309  pointZones_.setSize(newPointZones.size());
310 
311  for (label czI = oldSize; czI < newPointZones.size(); czI++)
312  {
313  pointZones_.set(czI, newPointZones[czI].clone(pointZones_));
314  }
315 
316 
317  faceZoneMesh newFaceZones
318  (
319  IOobject
320  (
321  "faceZones",
322  facesInst,
323  meshSubDir,
324  *this,
327  false
328  ),
329  *this
330  );
331 
332  oldSize = faceZones_.size();
333 
334  if (newFaceZones.size() <= faceZones_.size())
335  {
336  faceZones_.setSize(newFaceZones.size());
337  }
338 
339  // Reset existing ones
340  forAll(faceZones_, fzI)
341  {
342  faceZones_[fzI].resetAddressing
343  (
344  newFaceZones[fzI],
345  newFaceZones[fzI].flipMap()
346  );
347  }
348 
349  // Extend with extra ones
350  faceZones_.setSize(newFaceZones.size());
351 
352  for (label fzI = oldSize; fzI < newFaceZones.size(); fzI++)
353  {
354  faceZones_.set(fzI, newFaceZones[fzI].clone(faceZones_));
355  }
356 
357 
358  cellZoneMesh newCellZones
359  (
360  IOobject
361  (
362  "cellZones",
363  facesInst,
364  meshSubDir,
365  *this,
368  false
369  ),
370  *this
371  );
372 
373  oldSize = cellZones_.size();
374 
375  if (newCellZones.size() <= cellZones_.size())
376  {
377  cellZones_.setSize(newCellZones.size());
378  }
379 
380  // Reset existing ones
381  forAll(cellZones_, czI)
382  {
383  cellZones_[czI] = newCellZones[czI];
384  }
385 
386  // Extend with extra ones
387  cellZones_.setSize(newCellZones.size());
388 
389  for (label czI = oldSize; czI < newCellZones.size(); czI++)
390  {
391  cellZones_.set(czI, newCellZones[czI].clone(cellZones_));
392  }
393 
394 
395  if (boundaryChanged)
396  {
398  }
399  else
400  {
401  return polyMesh::TOPO_CHANGE;
402  }
403  }
404  else if (pointsInst != pointsInstance())
405  {
406  // Points moved
407  if (debug)
408  {
409  Info<< "Point motion" << endl;
410  }
411 
412  clearGeom();
413 
414 
415  label nOldPoints = points_.size();
416 
417  points_.clear();
418 
419  pointIOField newPoints
420  (
421  IOobject
422  (
423  "points",
424  pointsInst,
425  meshSubDir,
426  *this,
429  false
430  )
431  );
432 
433  if (nOldPoints != 0 && nOldPoints != newPoints.size())
434  {
436  << "Point motion detected but number of points "
437  << newPoints.size() << " in "
438  << newPoints.objectPath() << " does not correspond to "
439  << " current " << nOldPoints
440  << exit(FatalError);
441  }
442 
443  points_.transfer(newPoints);
444  points_.instance() = pointsInst;
445 
446  // Derived info
447  bounds_ = boundBox(points_);
448 
449  // Rotation can cause direction vector to change
450  geometricD_ = Vector<label>::zero;
451  solutionD_ = Vector<label>::zero;
452 
453 
454  //if (boundaryInst != boundary_.instance())
455  //{
456  // // Boundary file but no topology change
457  // if (debug)
458  // {
459  // Info<< "Boundary state change" << endl;
460  // }
461  //
462  // // Reset the boundary patches
463  // polyBoundaryMesh newBoundary
464  // (
465  // IOobject
466  // (
467  // "boundary",
468  // facesInst,
469  // meshSubDir,
470  // *this,
471  // IOobject::MUST_READ,
472  // IOobject::NO_WRITE,
473  // false
474  // ),
475  // *this
476  // );
477  //
478  //
479  //
480  //
481  // boundary_.clear();
482  // boundary_.setSize(newBoundary.size());
483  //
484  // forAll(newBoundary, patchI)
485  // {
486  // boundary_.set(patchI, newBoundary[patchI].clone(boundary_));
487  // }
488  // // Calculate topology for the patches (processor-processor comms
489  // // etc.)
490  // boundary_.updateMesh();
491  //
492  // // Calculate the geometry for the patches (transformation tensors
493  // // etc.)
494  // boundary_.calcGeometry();
495  //}
496 
497  return polyMesh::POINTS_MOVED;
498  }
499  else
500  {
501  if (debug)
502  {
503  Info<< "No change" << endl;
504  }
505 
506  return polyMesh::UNCHANGED;
507  }
508 }
509 
510 
511 // ************************************************************************* //
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::exists
bool exists(const fileName &, const bool checkGzip=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
Definition: POSIX.C:608
Foam::IOField< vector >
Foam::polyBoundaryMesh
Foam::polyBoundaryMesh.
Definition: polyBoundaryMesh.H:60
Foam::polyMesh::POINTS_MOVED
@ POINTS_MOVED
Definition: polyMesh.H:91
Foam::IOobject::AUTO_WRITE
@ AUTO_WRITE
Definition: IOobject.H:117
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::polyMesh::faces_
faceCompactIOList faces_
Faces.
Definition: polyMesh.H:121
Foam::polyMesh::faceZones_
faceZoneMesh faceZones_
Face zones.
Definition: polyMesh.H:164
Foam::polyMesh::neighbour_
labelIOList neighbour_
Face neighbour.
Definition: polyMesh.H:127
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::IOobject::instance
const fileName & instance() const
Definition: IOobject.H:350
polyMesh.H
Foam::IOobject::writeOpt
writeOption writeOpt() const
Definition: IOobject.H:327
Foam::labelIOList
IOList< label > labelIOList
Label container classes.
Definition: labelIOList.H:42
Foam::polyBoundaryMesh::types
wordList types() const
Return a list of patch types.
Definition: polyBoundaryMesh.C:542
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
Foam::polyBoundaryMesh::names
wordList names() const
Return a list of patch names.
Definition: polyBoundaryMesh.C:527
Foam::IOobject::objectPath
fileName objectPath() const
Return complete path + object name.
Definition: IOobject.H:376
Foam::polyMesh::TOPO_PATCH_CHANGE
@ TOPO_PATCH_CHANGE
Definition: polyMesh.H:93
Foam::polyMesh::owner_
labelIOList owner_
Face owner.
Definition: polyMesh.H:124
Foam::label
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
Foam::pointIOField
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:42
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::polyMesh::boundary_
polyBoundaryMesh boundary_
Boundary mesh.
Definition: polyMesh.H:134
Foam::ZoneMesh
A list of mesh zones.
Definition: cellZoneMeshFwd.H:39
Foam::CompactIOList
A List of objects of type <T> with automated input and output using a compact storage....
Definition: CompactIOList.H:53
Foam::polyMesh::UNCHANGED
@ UNCHANGED
Definition: polyMesh.H:90
Foam::polyMesh::TOPO_CHANGE
@ TOPO_CHANGE
Definition: polyMesh.H:92
Foam::polyMesh::pointZones_
pointZoneMesh pointZones_
Point zones.
Definition: polyMesh.H:161
Foam::FatalError
error FatalError
Foam::polyMesh::points_
pointIOField points_
Points.
Definition: polyMesh.H:118
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::polyMesh::readUpdateState
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:88
Foam::polyMesh::setInstance
void setInstance(const fileName &)
Set the instance for mesh files.
Definition: polyMeshIO.C:32
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::Vector
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:57
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::PtrList::size
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
Foam::boundBox
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:55
Foam::polyMesh::cellZones_
cellZoneMesh cellZones_
Cell zones.
Definition: polyMesh.H:167
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::faceCompactIOList
CompactIOList< face, label > faceCompactIOList
Definition: faceIOList.H:43
Foam::IOobject::READ_IF_PRESENT
@ READ_IF_PRESENT
Definition: IOobject.H:110
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
cellIOList.H
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::polyMesh::readUpdate
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in.
Definition: polyMeshIO.C:66