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-------------------------------------------------------------------------------
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 "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
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 (
88 (
89 "points",
90 pointsInst,
91 meshSubDir,
92 *this,
95 false
96 )
97 );
98
99 storedFaces() = faceCompactIOList
100 (
102 (
103 "faces",
104 facesInst,
105 meshSubDir,
106 *this,
109 false
110 )
111 );
112
113 // Reset the surface zones
114 surfZoneIOList newZones
115 (
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 {
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 (
172 (
173 "points",
174 pointsInst,
175 meshSubDir,
176 *this,
179 false
180 )
181 );
182
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// ************************************************************************* //
void setInstance(const fileName &inst)
Set the instance for mesh files.
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
The IOstreamOption is a simple container for options an IOstream can normally have.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A class for handling file names.
Definition: fileName.H:76
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: surfMesh.H:77
@ TOPO_PATCH_CHANGE
Definition: surfMesh.H:81
virtual readUpdateState readUpdate()
Update mesh based on the files saved in time directories.
Definition: surfMeshIO.C:58
void setInstance(const fileName &inst, IOobject::writeOption wOpt=IOobject::AUTO_WRITE)
Set the instance for mesh files.
Definition: surfMeshIO.C:35
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write all components using given format, version and compression.
Definition: surfMeshIO.C:195
void setWriteOption(IOobject::writeOption wOpt)
Adjust the write option for all components.
Definition: surfMeshIO.C:50
IOobject for a surfZoneList.
#define DebugInfo
Report an information message using Foam::Info.
#define WarningInFunction
Report a warning using Foam::Warning.
#define DebugInFunction
Report an information message using Foam::Info.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:44
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