surfMeshIO.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-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2021 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 "surfMesh.H"
30 #include "Time.H"
31 
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 
35 (
36  const fileName& inst,
38 )
39 {
40  DebugInFunction << "Resetting file instance to " << inst << endl;
41 
42  instance() = inst;
43  Allocator::setInstance(inst);
44  surfZones_.instance() = inst;
45 
46  setWriteOption(wOpt);
47 }
48 
49 
51 {
52  writeOpt(wOpt);
54  surfZones_.writeOpt(wOpt);
55 }
56 
57 
59 {
60  DebugInFunction << "Updating mesh based on saved data." << endl;
61 
62  // Find point and face instances
63  fileName pointsInst(time().findInstance(meshDir(), "points"));
64  fileName facesInst(time().findInstance(meshDir(), "faces"));
65 
67  << "Points instance: old = " << pointsInstance()
68  << " new = " << pointsInst << nl
69  << "Faces instance: old = " << facesInstance()
70  << " new = " << facesInst << endl;
71 
72  if (facesInst != facesInstance())
73  {
74  // Topological change
75  DebugInfo
76  << "Topological change" << endl;
77 
78  clearOut();
79 
80  // Set instance to new instance.
81  // Note points instance can differ from faces instance.
82  setInstance(facesInst);
83  storedIOPoints().instance() = pointsInst;
84 
85  storedIOPoints() = pointIOField
86  (
87  IOobject
88  (
89  "points",
90  pointsInst,
91  meshSubDir,
92  *this,
95  false
96  )
97  );
98 
99  storedFaces() = faceCompactIOList
100  (
101  IOobject
102  (
103  "faces",
104  facesInst,
105  meshSubDir,
106  *this,
109  false
110  )
111  );
112 
113  // Reset the surface zones
114  surfZoneIOList newZones
115  (
116  IOobject
117  (
118  "surfZones",
119  facesInst,
120  meshSubDir,
121  *this,
124  false
125  )
126  );
127 
128  // Check that zone types and names are unchanged
129  bool zonesChanged = false;
130 
131  if (surfZones_.size() != newZones.size())
132  {
133  zonesChanged = true;
134  }
135  else
136  {
137  forAll(surfZones_, zoneI)
138  {
139  if (surfZones_[zoneI].name() != newZones[zoneI].name())
140  {
141  zonesChanged = true;
142  break;
143  }
144  }
145  }
146 
147  surfZones_.transfer(newZones);
148 
149  if (zonesChanged)
150  {
152  << "Unexpected consequences. Proceed with care." << endl;
153 
155  }
156  else
157  {
158  return surfMesh::TOPO_CHANGE;
159  }
160  }
161  else if (pointsInst != pointsInstance())
162  {
163  // Points moved
164  DebugInfo << "Point motion" << endl;
165 
166  clearOut();
167  storedIOPoints().instance() = pointsInst;
168 
169  storedIOPoints() = pointIOField
170  (
171  IOobject
172  (
173  "points",
174  pointsInst,
175  meshSubDir,
176  *this,
179  false
180  )
181  );
182 
183  return surfMesh::POINTS_MOVED;
184  }
185  else
186  {
187  DebugInfo << "No change" << endl;
188  }
189 
190  return surfMesh::UNCHANGED;
191 }
192 
193 
195 (
196  IOstreamOption streamOpt,
197  const bool valid
198 ) const
199 {
200  bool ok = Allocator::writeObject(streamOpt, valid);
201 
202  if (ok)
203  {
204  surfZones_.writeObject(streamOpt, valid);
205  }
206 
207  return ok;
208 }
209 
210 
211 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::surfMesh::readUpdateState
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: surfMesh.H:76
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::surfMesh::writeObject
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write all components using given format, version and compression.
Definition: surfMeshIO.C:195
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::IOobject::writeOpt
writeOption writeOpt() const noexcept
The write option.
Definition: IOobjectI.H:179
Foam::surfMesh::TOPO_PATCH_CHANGE
Definition: surfMesh.H:81
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::IOobject::writeOption
writeOption
Enumeration defining the write options.
Definition: IOobject.H:192
Foam::surfZoneIOList
IOobject for a surfZoneList.
Definition: surfZoneIOList.H:53
Foam::surfMesh::readUpdate
virtual readUpdateState readUpdate()
Update mesh based on the files saved in time directories.
Definition: surfMeshIO.C:58
Foam::pointIOField
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:44
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:388
Foam::surfMesh::setInstance
void setInstance(const fileName &inst, IOobject::writeOption wOpt=IOobject::AUTO_WRITE)
Set the instance for mesh files.
Definition: surfMeshIO.C:35
Foam::IOobject::READ_IF_PRESENT
Definition: IOobject.H:187
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::surfMesh::TOPO_CHANGE
Definition: surfMesh.H:80
Foam::surfMesh::UNCHANGED
Definition: surfMesh.H:78
Foam::Detail::MeshedSurfaceIOAllocator::setWriteOption
void setWriteOption(IOobject::writeOption wOpt)
Adjust the write option for all components.
Definition: MeshedSurfaceIOAllocator.C:87
surfMesh.H
Time.H
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:382
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::faceCompactIOList
CompactIOList< face, label > faceCompactIOList
Definition: faceIOList.H:45
Foam::surfMesh::POINTS_MOVED
Definition: surfMesh.H:79
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::surfMesh::setWriteOption
void setWriteOption(IOobject::writeOption wOpt)
Adjust the write option for all components.
Definition: surfMeshIO.C:50
Foam::IOobject::MUST_READ
Definition: IOobject.H:185