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 | Copyright (C) 2011 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  Info<< "void surfMesh::setInstance(const fileName& inst) : "
36  << "Resetting file instance to " << inst << endl;
37  }
38 
39  instance() = inst;
40 
42  storedIOPoints().instance() = inst;
43 
45  storedIOFaces().instance() = inst;
46 
48  storedIOZones().instance() = inst;
49 }
50 
51 
53 {
54  if (debug)
55  {
56  Info<< "surfMesh::readUpdateState surfMesh::readUpdate() : "
57  << "Updating mesh based on saved data." << endl;
58  }
59 
60  // Find point and face instances
61  fileName pointsInst(time().findInstance(meshDir(), "points"));
62  fileName facesInst(time().findInstance(meshDir(), "faces"));
63 
64  if (debug)
65  {
66  Info<< "Points instance: old = " << pointsInstance()
67  << " new = " << pointsInst << nl
68  << "Faces instance: old = " << facesInstance()
69  << " new = " << facesInst << endl;
70  }
71 
72  if (facesInst != facesInstance())
73  {
74  // Topological change
75  if (debug)
76  {
77  Info<< "Topological change" << endl;
78  }
79 
80  clearOut();
81 
82  // Set instance to new instance.
83  // Note points instance can differ from faces instance.
84  setInstance(facesInst);
85  storedIOPoints().instance() = pointsInst;
86 
88  (
89  IOobject
90  (
91  "points",
92  pointsInst,
93  meshSubDir,
94  *this,
97  false
98  )
99  );
100 
102  (
103  IOobject
104  (
105  "faces",
106  facesInst,
107  meshSubDir,
108  *this,
111  false
112  )
113  );
114 
115  // Reset the surface zones
116  surfZoneIOList newZones
117  (
118  IOobject
119  (
120  "surfZones",
121  facesInst,
122  meshSubDir,
123  *this,
126  false
127  )
128  );
129 
130  // Check that zone types and names are unchanged
131  bool zonesChanged = false;
132 
133  surfZoneList& zones = this->storedIOZones();
134  if (zones.size() != newZones.size())
135  {
136  zonesChanged = true;
137  }
138  else
139  {
140  forAll(zones, zoneI)
141  {
142  if (zones[zoneI].name() != newZones[zoneI].name())
143  {
144  zonesChanged = true;
145  break;
146  }
147  }
148  }
149 
150  zones.transfer(newZones);
151 
152  if (zonesChanged)
153  {
154  WarningIn("surfMesh::readUpdateState surfMesh::readUpdate()")
155  << "Number of zones has changed. This may have "
156  << "unexpected consequences. Proceed with care." << endl;
157 
159  }
160  else
161  {
162  return surfMesh::TOPO_CHANGE;
163  }
164 
165  }
166  else if (pointsInst != pointsInstance())
167  {
168  // Points moved
169  if (debug)
170  {
171  Info<< "Point motion" << endl;
172  }
173 
174  clearGeom();
175  storedIOPoints().instance() = pointsInst;
176 
178  (
179  IOobject
180  (
181  "points",
182  pointsInst,
183  meshSubDir,
184  *this,
187  false
188  )
189  );
190 
191  return surfMesh::POINTS_MOVED;
192  }
193  else
194  {
195  if (debug)
196  {
197  Info<< "No change" << endl;
198  }
199  }
200 
201  return surfMesh::UNCHANGED;
202 }
203 
204 
205 // ************************************************************************* //
surfZoneIOList & storedIOZones()
Non-const access to the zones.
void clearOut()
Clear all geometry and addressing unnecessary for CFD.
Definition: surfMeshClear.C:76
IOobject for a surfZoneList.
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:390
void setInstance(const fileName &)
Set the instance for mesh files.
Definition: surfMeshIO.C:31
void clearGeom()
Clear geometry.
Definition: surfMeshClear.C:50
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
const fileName & instance() const
Definition: IOobject.H:337
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:42
messageStream Info
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
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
#define WarningIn(functionName)
Report a warning using Foam::Warning.
#define forAll(list, i)
Definition: UList.H:421
writeOption writeOpt() const
Definition: IOobject.H:314
const word & name() const
Return name.
Definition: IOobject.H:260
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: surfMesh.C:321
A class for handling file names.
Definition: fileName.H:69
pointIOField & storedIOPoints()
Non-const access to the points.
const Time & time() const
Return time.
CompactIOList< face, label > faceCompactIOList
Definition: faceIOList.H:43
const fileName & pointsInstance() const
Return the current instance directory for points.
Definition: surfMesh.C:315
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: surfMesh.H:72
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in.
Definition: surfMeshIO.C:52
faceCompactIOList & storedIOFaces()
Non-const access to the faces.
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
Definition: surfMesh.C:309
static word meshSubDir
Return the mesh sub-directory name (normally "surfMesh")
Definition: surfMesh.H:152
faceList & storedFaces()
Non-const access to the faces.
Definition: surfMesh.H:117