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-2022 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;
44  surfZones_.instance() = inst;
45 
46  setWriteOption(wOpt);
47 }
48 
49 
51 {
52  writeOpt(wOpt);
53  Allocator::setWriteOption(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,
96  )
97  );
98 
99  storedFaces() = faceCompactIOList
100  (
101  IOobject
102  (
103  "faces",
104  facesInst,
105  meshSubDir,
106  *this,
110  )
111  );
112 
113  // Reset the surface zones
114  surfZoneIOList newZones
115  (
116  IOobject
117  (
118  "surfZones",
119  facesInst,
120  meshSubDir,
121  *this,
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,
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 writeOnProc
198 ) const
199 {
200  bool ok = Allocator::writeObject(streamOpt, writeOnProc);
201 
202  if (ok)
203  {
204  surfZones_.writeObject(streamOpt, writeOnProc);
205  }
206 
207  return ok;
208 }
209 
210 
211 // ************************************************************************* //
writeOption
Enumeration defining write preferences.
A class for handling file names.
Definition: fileName.H:72
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: surfMesh.H:75
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:38
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Ignore writing from objectRegistry::writeObject()
void setInstance(const fileName &inst)
Set the instance for mesh files.
virtual readUpdateState readUpdate()
Update mesh based on the files saved in time directories.
Definition: surfMeshIO.C:51
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
CompactIOList< face, label > faceCompactIOList
Compact IO for a List of face.
Definition: faceIOList.H:35
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
#define DebugInFunction
Report an information message using Foam::Info.
IOobject for a surfZoneList.
#define DebugInfo
Report an information message using Foam::Info.
const fileName & instance() const noexcept
Read access to instance path component.
Definition: IOobjectI.H:266
void setInstance(const fileName &inst, IOobjectOption::writeOption wOpt=IOobjectOption::AUTO_WRITE)
Set the instance for mesh files.
Definition: surfMeshIO.C:28
#define WarningInFunction
Report a warning using Foam::Warning.
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write all components using given format, version and compression.
Definition: surfMeshIO.C:188
Reading is optional [identical to READ_IF_PRESENT].
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Do not request registration (bool: false)
void setWriteOption(IOobjectOption::writeOption wOpt)
Adjust the write option for all components.
Definition: surfMeshIO.C:43