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-2015 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 
44  storedIOFaces().writeOpt() = IOobject::AUTO_WRITE;
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() = faceCompactIOList
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  {
155  << "unexpected consequences. Proceed with care." << endl;
156 
158  }
159  else
160  {
161  return surfMesh::TOPO_CHANGE;
162  }
163 
164  }
165  else if (pointsInst != pointsInstance())
166  {
167  // Points moved
168  if (debug)
169  {
170  Info<< "Point motion" << endl;
171  }
172 
173  clearGeom();
174  storedIOPoints().instance() = pointsInst;
175 
176  storedIOPoints() = pointIOField
177  (
178  IOobject
179  (
180  "points",
181  pointsInst,
182  meshSubDir,
183  *this,
186  false
187  )
188  );
189 
190  return surfMesh::POINTS_MOVED;
191  }
192  else
193  {
194  if (debug)
195  {
196  Info<< "No change" << endl;
197  }
198  }
199 
200  return surfMesh::UNCHANGED;
201 }
202 
203 
204 // ************************************************************************* //
Foam::surfMesh::readUpdateState
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: surfMesh.H:72
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::MeshedSurfaceIOAllocator::storedIOZones
surfZoneIOList & storedIOZones()
Non-const access to the zones.
Definition: MeshedSurfaceIOAllocator.H:125
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::IOobject::AUTO_WRITE
@ AUTO_WRITE
Definition: IOobject.H:117
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::List::transfer
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::IOobject::instance
const fileName & instance() const
Definition: IOobject.H:350
Foam::IOobject::writeOpt
writeOption writeOpt() const
Definition: IOobject.H:327
Foam::MeshedSurfaceIOAllocator::storedIOPoints
pointIOField & storedIOPoints()
Non-const access to the points.
Definition: MeshedSurfaceIOAllocator.H:113
Foam::surfMesh::TOPO_PATCH_CHANGE
@ TOPO_PATCH_CHANGE
Definition: surfMesh.H:77
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
Foam::surfZoneIOList
IOobject for a surfZoneList.
Definition: surfZoneIOList.H:53
Foam::surfMesh::readUpdate
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in.
Definition: surfMeshIO.C:52
Foam::pointIOField
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:42
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::surfMesh::setInstance
void setInstance(const fileName &)
Set the instance for mesh files.
Definition: surfMeshIO.C:31
Foam::surfMesh::TOPO_CHANGE
@ TOPO_CHANGE
Definition: surfMesh.H:76
Foam::surfMesh::UNCHANGED
@ UNCHANGED
Definition: surfMesh.H:74
surfMesh.H
Foam::MeshedSurfaceIOAllocator::storedIOFaces
faceCompactIOList & storedIOFaces()
Non-const access to the faces.
Definition: MeshedSurfaceIOAllocator.H:119
Foam::List
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
Foam::faceCompactIOList
CompactIOList< face, label > faceCompactIOList
Definition: faceIOList.H:43
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::surfMesh::POINTS_MOVED
@ POINTS_MOVED
Definition: surfMesh.H:75
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47