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 
86  (
87  IOobject
88  (
89  "points",
90  pointsInst,
91  meshSubDir,
92  *this,
95  false
96  )
97  );
98 
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 
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 // ************************************************************************* //
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: surfMesh.C:305
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
const word & name() const
Return name.
Definition: IOobject.H:315
faceCompactIOList & storedIOFaces()
Non-const access to the faces.
A class for handling file names.
Definition: fileName.H:79
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: surfMesh.H:72
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:42
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
const fileName & pointsInstance() const
Return the current instance directory for points.
Definition: surfMesh.C:299
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
faceList & storedFaces()
Non-const access to the faces.
Definition: surfMesh.H:102
void clearGeom()
Clear geometry.
Definition: surfMeshClear.C:48
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
pointIOField & storedIOPoints()
Non-const access to the points.
void setInstance(const fileName &)
Set the instance for mesh files.
Definition: surfMeshIO.C:31
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in.
Definition: surfMeshIO.C:51
CompactIOList< face, label > faceCompactIOList
Definition: faceIOList.H:44
static word meshSubDir
Return the mesh sub-directory name (normally "surfMesh")
Definition: surfMesh.H:137
surfZoneIOList & storedIOZones()
Non-const access to the zones.
IOobject for a surfZoneList.
void clearOut()
Clear all geometry and addressing unnecessary for CFD.
Definition: surfMeshClear.C:70
static const char nl
Definition: Ostream.H:260
const Time & time() const
Return time.
writeOption writeOpt() const
Definition: IOobject.H:375
#define WarningInFunction
Report a warning using Foam::Warning.
messageStream Info
fileName & instance() const
Return the instance directory, constant, system, <time> etc.
Definition: IOobject.C:355
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
Definition: surfMesh.C:293
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
#define InfoInFunction
Report an information message using Foam::Info.