FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/Time.H>
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
32 {
33  if (debug or true)
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 
87  storedIOPoints() = pointIOField
88  (
89  IOobject
90  (
91  "points",
92  pointsInst,
93  meshSubDir,
94  *this,
97  false
98  )
99  );
100 
101  storedFaces() = faceIOList
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 
177  storedIOPoints() = pointIOField
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 // ************************ vim: set sw=4 sts=4 et: ************************ //