Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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
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
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,
96 )
97 );
98
99 storedFaces() = faceCompactIOList
100 (
102 (
103 "faces",
104 facesInst,
105 meshSubDir,
106 *this,
110 )
111 );
112
113 // Reset the surface zones
114 surfZoneIOList newZones
115 (
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 {
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,
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 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// ************************************************************************* //
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write using stream options.
pointIOField & storedIOPoints() noexcept
Non-const access to the points.
void setInstance(const fileName &inst)
Set the instance for mesh files.
void setWriteOption(IOobjectOption::writeOption wOpt)
Adjust the write option for all components.
@ NO_REGISTER
Do not request registration (bool: false).
writeOption writeOpt() const noexcept
Get the write option.
@ MUST_READ
Reading required.
@ LAZY_READ
Reading is optional [identical to READ_IF_PRESENT].
writeOption
Enumeration defining write preferences.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
const fileName & instance() const noexcept
Read access to instance path component.
Definition IOobjectI.H:289
A simple container for options an IOstream can normally have.
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A class for handling file names.
Definition fileName.H:75
const Time & time() const noexcept
Return time registry.
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write all components using given format, version and compression.
Definition surfMeshIO.C:188
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition surfMesh.C:431
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir).
Definition surfMesh.C:419
faceList & storedFaces()
Non-const access to the faces.
Definition surfMesh.H:129
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition surfMesh.H:79
virtual readUpdateState readUpdate()
Update mesh based on the files saved in time directories.
Definition surfMeshIO.C:51
const fileName & pointsInstance() const
Return the current instance directory for points.
Definition surfMesh.C:425
void setInstance(const fileName &inst, IOobjectOption::writeOption wOpt=IOobjectOption::AUTO_WRITE)
Set the instance for mesh files.
Definition surfMeshIO.C:28
static word meshSubDir
Return the mesh sub-directory name (normally "surfMesh").
Definition surfMesh.H:171
void clearOut()
Clear all geometry and addressing unnecessary for CFD.
void setWriteOption(IOobjectOption::writeOption wOpt)
Adjust the write option for all components.
Definition surfMeshIO.C:43
IOobject for a surfZoneList.
auto & name
#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.
CompactIOList< face > faceCompactIOList
Compact IO for a List of face.
Definition faceIOList.H:35
vectorIOField pointIOField
pointIOField is a vectorIOField.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299