surfMeshIO.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "surfMesh.H"
27 #include "Time.H"
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
32 {
33  if (debug)
34  {
35  InfoInFunction << "Resetting file instance to " << inst << endl;
36  }
37 
38  instance() = inst;
39 
41  storedIOPoints().instance() = inst;
42 
44  storedIOFaces().instance() = inst;
45 
47  storedIOZones().instance() = inst;
48 }
49 
50 
52 {
53  if (debug)
54  {
55  InfoInFunction << "Updating mesh based on saved data." << endl;
56  }
57 
58  // Find point and face instances
59  fileName pointsInst(time().findInstance(meshDir(), "points"));
60  fileName facesInst(time().findInstance(meshDir(), "faces"));
61 
62  if (debug)
63  {
64  Info<< "Points instance: old = " << pointsInstance()
65  << " new = " << pointsInst << nl
66  << "Faces instance: old = " << facesInstance()
67  << " new = " << facesInst << endl;
68  }
69 
70  if (facesInst != facesInstance())
71  {
72  // Topological change
73  if (debug)
74  {
75  Info<< "Topological change" << endl;
76  }
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  surfZoneList& zones = this->storedIOZones();
132  if (zones.size() != newZones.size())
133  {
134  zonesChanged = true;
135  }
136  else
137  {
138  forAll(zones, zoneI)
139  {
140  if (zones[zoneI].name() != newZones[zoneI].name())
141  {
142  zonesChanged = true;
143  break;
144  }
145  }
146  }
147 
148  zones.transfer(newZones);
149 
150  if (zonesChanged)
151  {
153  << "unexpected consequences. Proceed with care." << endl;
154 
156  }
157  else
158  {
159  return surfMesh::TOPO_CHANGE;
160  }
161 
162  }
163  else if (pointsInst != pointsInstance())
164  {
165  // Points moved
166  if (debug)
167  {
168  Info<< "Point motion" << endl;
169  }
170 
171  clearGeom();
172  storedIOPoints().instance() = pointsInst;
173 
174  storedIOPoints() = pointIOField
175  (
176  IOobject
177  (
178  "points",
179  pointsInst,
180  meshSubDir,
181  *this,
184  false
185  )
186  );
187 
188  return surfMesh::POINTS_MOVED;
189  }
190  else
191  {
192  if (debug)
193  {
194  Info<< "No change" << endl;
195  }
196  }
197 
198  return surfMesh::UNCHANGED;
199 }
200 
201 
202 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
writeOption writeOpt() const
Definition: IOobject.H:370
fileName & instance() const
Return the instance directory, constant, system, <time> etc.
Definition: IOobject.C:355
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
pointIOField & storedIOPoints()
Non-const access to the points.
faceCompactIOList & storedIOFaces()
Non-const access to the faces.
surfZoneIOList & storedIOZones()
Non-const access to the zones.
A class for handling file names.
Definition: fileName.H:82
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: surfMesh.H:73
@ TOPO_PATCH_CHANGE
Definition: surfMesh.H:77
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in.
Definition: surfMeshIO.C:51
void setInstance(const fileName &)
Set the instance for mesh files.
Definition: surfMeshIO.C:31
IOobject for a surfZoneList.
#define WarningInFunction
Report a warning using Foam::Warning.
#define InfoInFunction
Report an information message using Foam::Info.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
CompactIOList< face > faceCompactIOList
Definition: faceIOList.H:44
messageStream Info
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:42
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
static const char nl
Definition: Ostream.H:260