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-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
33// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34
36(
37 const fileName& inst,
38 const IOobject::writeOption wOpt
39)
40{
41 DebugInFunction << "Resetting file instance to " << inst << endl;
42
43 points_.writeOpt(wOpt);
44 points_.instance() = inst;
45
46 faces_.writeOpt(wOpt);
47 faces_.instance() = inst;
48
49 owner_.writeOpt(wOpt);
50 owner_.instance() = inst;
51
52 neighbour_.writeOpt(wOpt);
53 neighbour_.instance() = inst;
54
55 boundary_.writeOpt(wOpt);
56 boundary_.instance() = inst;
57
58 pointZones_.writeOpt(wOpt);
59 pointZones_.instance() = inst;
60
61 faceZones_.writeOpt(wOpt);
62 faceZones_.instance() = inst;
63
64 cellZones_.writeOpt(wOpt);
65 cellZones_.instance() = inst;
66
67 if (tetBasePtIsPtr_)
68 {
69 tetBasePtIsPtr_->writeOpt(wOpt);
70 tetBasePtIsPtr_->instance() = inst;
71 }
72}
73
74
76{
77 DebugInFunction << "Updating mesh based on saved data." << endl;
78
79 // Find the point and cell instance
80 fileName pointsInst(time().findInstance(meshDir(), "points"));
81 fileName facesInst(time().findInstance(meshDir(), "faces"));
82 //fileName boundaryInst(time().findInstance(meshDir(), "boundary"));
83
84 if (debug)
85 {
86 Info<< "Faces instance: old = " << facesInstance()
87 << " new = " << facesInst << nl
88 << "Points instance: old = " << pointsInstance()
89 << " new = " << pointsInst << endl;
90 }
91
92 if (facesInst != facesInstance())
93 {
94 // Topological change
95 if (debug)
96 {
97 Info<< "Topological change" << endl;
98 }
99
100 clearOut();
101
102 // Set instance to new instance. Note that points instance can differ
103 // from from faces instance.
104 setInstance(facesInst);
105 points_.instance() = pointsInst;
106
107 points_ = pointIOField
108 (
110 (
111 "points",
112 pointsInst,
113 meshSubDir,
114 *this,
117 false
118 )
119 );
120
121 faces_ = faceCompactIOList
122 (
124 (
125 "faces",
126 facesInst,
127 meshSubDir,
128 *this,
131 false
132 )
133 );
134
135 owner_ = labelIOList
136 (
138 (
139 "owner",
140 facesInst,
141 meshSubDir,
142 *this,
145 false
146 )
147 );
148
149 neighbour_ = labelIOList
150 (
152 (
153 "neighbour",
154 facesInst,
155 meshSubDir,
156 *this,
159 false
160 )
161 );
162
163 // Reset the boundary patches
164 polyBoundaryMesh newBoundary
165 (
167 (
168 "boundary",
169 facesInst,
170 meshSubDir,
171 *this,
174 false
175 ),
176 *this
177 );
178
179 // Check that patch types and names are unchanged
180 bool boundaryChanged = false;
181
182 if (newBoundary.size() != boundary_.size())
183 {
184 boundaryChanged = true;
185 }
186 else
187 {
188 wordList newTypes = newBoundary.types();
189 wordList newNames = newBoundary.names();
190
191 wordList oldTypes = boundary_.types();
192 wordList oldNames = boundary_.names();
193
194 forAll(oldTypes, patchi)
195 {
196 if
197 (
198 oldTypes[patchi] != newTypes[patchi]
199 || oldNames[patchi] != newNames[patchi]
200 )
201 {
202 boundaryChanged = true;
203 break;
204 }
205 }
206 }
207
208 if (boundaryChanged)
209 {
211 << "Number of patches has changed. This may have "
212 << "unexpected consequences. Proceed with care." << endl;
213
214 boundary_.clear();
215 boundary_.setSize(newBoundary.size());
216
217 forAll(newBoundary, patchi)
218 {
219 boundary_.set(patchi, newBoundary[patchi].clone(boundary_));
220 }
221 }
222 else
223 {
224 forAll(boundary_, patchi)
225 {
226 boundary_[patchi] = polyPatch
227 (
228 newBoundary[patchi].name(),
229 newBoundary[patchi].size(),
230 newBoundary[patchi].start(),
231 patchi,
232 boundary_,
233 newBoundary[patchi].physicalType(),
234 newBoundary[patchi].inGroups()
235 );
236 }
237 }
238
239
240 // Boundary is set so can use initMesh now (uses boundary_ to
241 // determine internal and active faces)
242
243 if (owner_.hasHeaderClass())
244 {
245 initMesh();
246 }
247 else
248 {
250 (
252 (
253 "cells",
254 facesInst,
255 meshSubDir,
256 *this,
259 false
260 )
261 );
262
263 // Recalculate the owner/neighbour addressing and reset the
264 // primitiveMesh
265 initMesh(cells);
266 }
267
268
269 // Even if number of patches stayed same still recalculate boundary
270 // data.
271
272 // Calculate topology for the patches (processor-processor comms etc.)
273 boundary_.updateMesh();
274
275 // Calculate the geometry for the patches (transformation tensors etc.)
276 boundary_.calcGeometry();
277
278 // Derived info
279 bounds_ = boundBox(points_);
280 geometricD_ = Zero;
281 solutionD_ = Zero;
282
283 // Zones
284 pointZoneMesh newPointZones
285 (
287 (
288 "pointZones",
289 facesInst,
290 meshSubDir,
291 *this,
294 false
295 ),
296 *this
297 );
298
299 label oldSize = pointZones_.size();
300
301 if (newPointZones.size() <= pointZones_.size())
302 {
303 pointZones_.setSize(newPointZones.size());
304 }
305
306 // Reset existing ones
307 forAll(pointZones_, czI)
308 {
309 pointZones_[czI] = newPointZones[czI];
310 }
311
312 // Extend with extra ones
313 pointZones_.setSize(newPointZones.size());
314
315 for (label czI = oldSize; czI < newPointZones.size(); czI++)
316 {
317 pointZones_.set(czI, newPointZones[czI].clone(pointZones_));
318 }
319
320
321 faceZoneMesh newFaceZones
322 (
324 (
325 "faceZones",
326 facesInst,
327 meshSubDir,
328 *this,
331 false
332 ),
333 *this
334 );
335
336 oldSize = faceZones_.size();
337
338 if (newFaceZones.size() <= faceZones_.size())
339 {
340 faceZones_.setSize(newFaceZones.size());
341 }
342
343 // Reset existing ones
344 forAll(faceZones_, fzI)
345 {
346 faceZones_[fzI].resetAddressing
347 (
348 newFaceZones[fzI],
349 newFaceZones[fzI].flipMap()
350 );
351 }
352
353 // Extend with extra ones
354 faceZones_.setSize(newFaceZones.size());
355
356 for (label fzI = oldSize; fzI < newFaceZones.size(); fzI++)
357 {
358 faceZones_.set(fzI, newFaceZones[fzI].clone(faceZones_));
359 }
360
361
362 cellZoneMesh newCellZones
363 (
365 (
366 "cellZones",
367 facesInst,
368 meshSubDir,
369 *this,
372 false
373 ),
374 *this
375 );
376
377 oldSize = cellZones_.size();
378
379 if (newCellZones.size() <= cellZones_.size())
380 {
381 cellZones_.setSize(newCellZones.size());
382 }
383
384 // Reset existing ones
385 forAll(cellZones_, czI)
386 {
387 cellZones_[czI] = newCellZones[czI];
388 }
389
390 // Extend with extra ones
391 cellZones_.setSize(newCellZones.size());
392
393 for (label czI = oldSize; czI < newCellZones.size(); czI++)
394 {
395 cellZones_.set(czI, newCellZones[czI].clone(cellZones_));
396 }
397
398 // Re-read tet base points
399 tetBasePtIsPtr_ = readTetBasePtIs();
400
401
402 if (boundaryChanged)
403 {
405 }
406 else
407 {
409 }
410 }
411 else if (pointsInst != pointsInstance())
412 {
413 // Points moved
414 if (debug)
415 {
416 Info<< "Point motion" << endl;
417 }
418
419 pointIOField newPoints
420 (
422 (
423 "points",
424 pointsInst,
425 meshSubDir,
426 *this,
429 false
430 )
431 );
432
433 // Re-read tet base points
434 autoPtr<labelIOList> newTetBasePtIsPtr = readTetBasePtIs();
435
436 // Update all geometry
437 updateGeomPoints(std::move(newPoints), newTetBasePtIsPtr);
438
440 }
441 else
442 {
443 if (debug)
444 {
445 Info<< "No change" << endl;
446 }
447
448 return polyMesh::UNCHANGED;
449 }
450}
451
452
453// ************************************************************************* //
A List of objects of type <T> with automated input and output using a compact storage....
Definition: CompactIOList.H:77
A primitive field of type <T> with automated input and output.
Definition: IOField.H:58
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
const fileName & instance() const noexcept
Read access to instance path component.
Definition: IOobjectI.H:196
writeOption
Enumeration defining the write options.
Definition: IOobject.H:186
writeOption writeOpt() const noexcept
The write option.
Definition: IOobjectI.H:179
void setSize(const label newLen)
Same as resize()
Definition: PtrList.H:151
label size() const noexcept
The number of elements in the list.
Definition: UPtrListI.H:106
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:64
A class for handling file names.
Definition: fileName.H:76
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
wordList types() const
Return a list of patch types.
wordList names() const
Return a list of patch names.
void setInstance(const fileName &instance, const IOobject::writeOption wOpt=IOobject::AUTO_WRITE)
Set the instance for mesh files.
Definition: polyMeshIO.C:36
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:91
@ TOPO_PATCH_CHANGE
Definition: polyMesh.H:95
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in.
Definition: polyMeshIO.C:75
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
const cellShapeList & cells
#define WarningInFunction
Report a warning using Foam::Warning.
#define DebugInFunction
Report an information message using Foam::Info.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:44
IOList< label > labelIOList
Label container classes.
Definition: labelIOList.H:44
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
CompactIOList< face, label > faceCompactIOList
Definition: faceIOList.H:45
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333