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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2015-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "polyMesh.H"
30 #include "Time.H"
31 #include "cellIOList.H"
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 
35 (
36  const fileName& inst,
37  const IOobject::writeOption wOpt
38 )
39 {
40  if (debug)
41  {
42  InfoInFunction << "Resetting file instance to " << inst << endl;
43  }
44 
45  points_.writeOpt() = wOpt;
46  points_.instance() = inst;
47 
48  faces_.writeOpt() = wOpt;
49  faces_.instance() = inst;
50 
51  owner_.writeOpt() = wOpt;
52  owner_.instance() = inst;
53 
54  neighbour_.writeOpt() = wOpt;
55  neighbour_.instance() = inst;
56 
57  boundary_.writeOpt() = wOpt;
58  boundary_.instance() = inst;
59 
60  pointZones_.writeOpt() = wOpt;
61  pointZones_.instance() = inst;
62 
63  faceZones_.writeOpt() = wOpt;
64  faceZones_.instance() = inst;
65 
66  cellZones_.writeOpt() = wOpt;
67  cellZones_.instance() = inst;
68 
69  if (tetBasePtIsPtr_.valid())
70  {
71  tetBasePtIsPtr_->writeOpt() = wOpt;
72  tetBasePtIsPtr_->instance() = inst;
73  }
74 }
75 
76 
78 {
79  if (debug)
80  {
81  InfoInFunction << "Updating mesh based on saved data." << endl;
82  }
83 
84  // Find the point and cell instance
85  fileName pointsInst(time().findInstance(meshDir(), "points"));
86  fileName facesInst(time().findInstance(meshDir(), "faces"));
87  //fileName boundaryInst(time().findInstance(meshDir(), "boundary"));
88 
89  if (debug)
90  {
91  Info<< "Faces instance: old = " << facesInstance()
92  << " new = " << facesInst << nl
93  << "Points instance: old = " << pointsInstance()
94  << " new = " << pointsInst << endl;
95  }
96 
97  if (facesInst != facesInstance())
98  {
99  // Topological change
100  if (debug)
101  {
102  Info<< "Topological change" << endl;
103  }
104 
105  clearOut();
106 
107  // Set instance to new instance. Note that points instance can differ
108  // from from faces instance.
109  setInstance(facesInst);
110  points_.instance() = pointsInst;
111 
112  points_ = pointIOField
113  (
114  IOobject
115  (
116  "points",
117  pointsInst,
118  meshSubDir,
119  *this,
122  false
123  )
124  );
125 
126  faces_ = faceCompactIOList
127  (
128  IOobject
129  (
130  "faces",
131  facesInst,
132  meshSubDir,
133  *this,
136  false
137  )
138  );
139 
140  owner_ = labelIOList
141  (
142  IOobject
143  (
144  "owner",
145  facesInst,
146  meshSubDir,
147  *this,
150  false
151  )
152  );
153 
154  neighbour_ = labelIOList
155  (
156  IOobject
157  (
158  "neighbour",
159  facesInst,
160  meshSubDir,
161  *this,
164  false
165  )
166  );
167 
168  // Reset the boundary patches
169  polyBoundaryMesh newBoundary
170  (
171  IOobject
172  (
173  "boundary",
174  facesInst,
175  meshSubDir,
176  *this,
179  false
180  ),
181  *this
182  );
183 
184  // Check that patch types and names are unchanged
185  bool boundaryChanged = false;
186 
187  if (newBoundary.size() != boundary_.size())
188  {
189  boundaryChanged = true;
190  }
191  else
192  {
193  wordList newTypes = newBoundary.types();
194  wordList newNames = newBoundary.names();
195 
196  wordList oldTypes = boundary_.types();
197  wordList oldNames = boundary_.names();
198 
199  forAll(oldTypes, patchi)
200  {
201  if
202  (
203  oldTypes[patchi] != newTypes[patchi]
204  || oldNames[patchi] != newNames[patchi]
205  )
206  {
207  boundaryChanged = true;
208  break;
209  }
210  }
211  }
212 
213  if (boundaryChanged)
214  {
216  << "Number of patches has changed. This may have "
217  << "unexpected consequences. Proceed with care." << endl;
218 
219  boundary_.clear();
220  boundary_.setSize(newBoundary.size());
221 
222  forAll(newBoundary, patchi)
223  {
224  boundary_.set(patchi, newBoundary[patchi].clone(boundary_));
225  }
226  }
227  else
228  {
229  forAll(boundary_, patchi)
230  {
231  boundary_[patchi] = polyPatch
232  (
233  newBoundary[patchi].name(),
234  newBoundary[patchi].size(),
235  newBoundary[patchi].start(),
236  patchi,
237  boundary_,
238  newBoundary[patchi].physicalType(),
239  newBoundary[patchi].inGroups()
240  );
241  }
242  }
243 
244 
245  // Boundary is set so can use initMesh now (uses boundary_ to
246  // determine internal and active faces)
247 
248  if (!owner_.headerClassName().empty())
249  {
250  initMesh();
251  }
252  else
253  {
255  (
256  IOobject
257  (
258  "cells",
259  facesInst,
260  meshSubDir,
261  *this,
264  false
265  )
266  );
267 
268  // Recalculate the owner/neighbour addressing and reset the
269  // primitiveMesh
270  initMesh(cells);
271  }
272 
273 
274  // Even if number of patches stayed same still recalculate boundary
275  // data.
276 
277  // Calculate topology for the patches (processor-processor comms etc.)
278  boundary_.updateMesh();
279 
280  // Calculate the geometry for the patches (transformation tensors etc.)
281  boundary_.calcGeometry();
282 
283  // Derived info
284  bounds_ = boundBox(points_);
285  geometricD_ = Zero;
286  solutionD_ = Zero;
287 
288  // Zones
289  pointZoneMesh newPointZones
290  (
291  IOobject
292  (
293  "pointZones",
294  facesInst,
295  meshSubDir,
296  *this,
299  false
300  ),
301  *this
302  );
303 
304  label oldSize = pointZones_.size();
305 
306  if (newPointZones.size() <= pointZones_.size())
307  {
308  pointZones_.setSize(newPointZones.size());
309  }
310 
311  // Reset existing ones
312  forAll(pointZones_, czI)
313  {
314  pointZones_[czI] = newPointZones[czI];
315  }
316 
317  // Extend with extra ones
318  pointZones_.setSize(newPointZones.size());
319 
320  for (label czI = oldSize; czI < newPointZones.size(); czI++)
321  {
322  pointZones_.set(czI, newPointZones[czI].clone(pointZones_));
323  }
324 
325 
326  faceZoneMesh newFaceZones
327  (
328  IOobject
329  (
330  "faceZones",
331  facesInst,
332  meshSubDir,
333  *this,
336  false
337  ),
338  *this
339  );
340 
341  oldSize = faceZones_.size();
342 
343  if (newFaceZones.size() <= faceZones_.size())
344  {
345  faceZones_.setSize(newFaceZones.size());
346  }
347 
348  // Reset existing ones
349  forAll(faceZones_, fzI)
350  {
351  faceZones_[fzI].resetAddressing
352  (
353  newFaceZones[fzI],
354  newFaceZones[fzI].flipMap()
355  );
356  }
357 
358  // Extend with extra ones
359  faceZones_.setSize(newFaceZones.size());
360 
361  for (label fzI = oldSize; fzI < newFaceZones.size(); fzI++)
362  {
363  faceZones_.set(fzI, newFaceZones[fzI].clone(faceZones_));
364  }
365 
366 
367  cellZoneMesh newCellZones
368  (
369  IOobject
370  (
371  "cellZones",
372  facesInst,
373  meshSubDir,
374  *this,
377  false
378  ),
379  *this
380  );
381 
382  oldSize = cellZones_.size();
383 
384  if (newCellZones.size() <= cellZones_.size())
385  {
386  cellZones_.setSize(newCellZones.size());
387  }
388 
389  // Reset existing ones
390  forAll(cellZones_, czI)
391  {
392  cellZones_[czI] = newCellZones[czI];
393  }
394 
395  // Extend with extra ones
396  cellZones_.setSize(newCellZones.size());
397 
398  for (label czI = oldSize; czI < newCellZones.size(); czI++)
399  {
400  cellZones_.set(czI, newCellZones[czI].clone(cellZones_));
401  }
402 
403  // Re-read tet base points
404  tetBasePtIsPtr_ = readTetBasePtIs();
405 
406 
407  if (boundaryChanged)
408  {
410  }
411  else
412  {
413  return polyMesh::TOPO_CHANGE;
414  }
415  }
416  else if (pointsInst != pointsInstance())
417  {
418  // Points moved
419  if (debug)
420  {
421  Info<< "Point motion" << endl;
422  }
423 
424  pointIOField newPoints
425  (
426  IOobject
427  (
428  "points",
429  pointsInst,
430  meshSubDir,
431  *this,
434  false
435  )
436  );
437 
438  // Re-read tet base points
439  autoPtr<labelIOList> newTetBasePtIsPtr = readTetBasePtIs();
440 
441  // Update all geometry
442  updateGeom(newPoints, newTetBasePtIsPtr);
443 
444  return polyMesh::POINTS_MOVED;
445  }
446  else
447  {
448  if (debug)
449  {
450  Info<< "No change" << endl;
451  }
452 
453  return polyMesh::UNCHANGED;
454  }
455 }
456 
457 
458 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
Foam::HashTable< regIOobject * >::size
label size() const noexcept
The number of elements in table.
Definition: HashTableI.H:52
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
InfoInFunction
#define InfoInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:316
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobjectI.H:46
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.H:61
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:62
Foam::polyMesh::POINTS_MOVED
Definition: polyMesh.H:94
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:186
Foam::polyMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:315
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:138
Foam::polyMesh::facesInstance
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:821
Foam::polyMesh::updateGeom
void updateGeom(pointIOField &newPoints, autoPtr< labelIOList > &newTetBasePtIsPtr)
Update geometry; keep topology. Optional new face decomposition.
Definition: polyMeshClear.C:80
Foam::polyMesh::clearOut
void clearOut()
Clear all geometry and addressing unnecessary for CFD.
Definition: polyMeshClear.C:232
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
polyMesh.H
Foam::labelIOList
IOList< label > labelIOList
Label container classes.
Definition: labelIOList.H:44
Foam::polyBoundaryMesh::types
wordList types() const
Return a list of patch types.
Definition: polyBoundaryMesh.C:599
Foam::polyBoundaryMesh::names
wordList names() const
Return a list of patch names.
Definition: polyBoundaryMesh.C:593
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::polyMesh::TOPO_PATCH_CHANGE
Definition: polyMesh.H:96
Foam::polyMesh::pointsInstance
const fileName & pointsInstance() const
Return the current instance directory for points.
Definition: polyMesh.C:815
Foam::IOobject::writeOption
writeOption
Enumeration defining the write options.
Definition: IOobject.H:127
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:62
Foam::pointIOField
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:44
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::IOobject::READ_IF_PRESENT
Definition: IOobject.H:122
Foam::PtrList::setSize
void setSize(const label newLen)
Same as resize()
Definition: PtrListI.H:108
Foam::ZoneMesh< pointZone, polyMesh >
Foam::CompactIOList
A List of objects of type <T> with automated input and output using a compact storage....
Definition: CompactIOList.H:55
Foam::polyMesh::UNCHANGED
Definition: polyMesh.H:93
Foam::IOobject::clone
autoPtr< IOobject > clone() const
Clone.
Definition: IOobject.H:326
Foam::polyMesh::TOPO_CHANGE
Definition: polyMesh.H:95
Foam::PtrList::clear
void clear()
Clear the PtrList. Delete allocated entries and set size to zero.
Definition: PtrListI.H:100
Foam::PtrList::set
const T * set(const label i) const
Return const pointer to element (if set) or nullptr.
Definition: PtrListI.H:143
Foam::polyMesh::meshDir
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
Definition: polyMesh.C:809
Foam::IOobject::headerClassName
const word & headerClassName() const
Return name of the class name read from header.
Definition: IOobjectI.H:64
Foam::polyMesh::readUpdateState
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:91
Foam::polyBoundaryMesh::updateMesh
void updateMesh()
Correct polyBoundaryMesh after topology update.
Definition: polyBoundaryMesh.C:1141
Time.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::List< word >
Foam::start
label ListType::const_reference const label start
Definition: ListOps.H:408
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Foam::faceCompactIOList
CompactIOList< face, label > faceCompactIOList
Definition: faceIOList.H:45
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294
cellIOList.H
Foam::polyMesh::setInstance
void setInstance(const fileName &instance, const IOobject::writeOption wOpt=IOobject::AUTO_WRITE)
Set the instance for mesh files.
Definition: polyMeshIO.C:35
Foam::polyMesh::readUpdate
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in.
Definition: polyMeshIO.C:77
Foam::IOobject::MUST_READ
Definition: IOobject.H:120