initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / surfMesh / surfMesh / surfMeshIO.C
blobc74b1c693eb5ae9fae13f00ca9948801da540707
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "surfMesh.H"
28 #include "Time.H"
30 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
32 void Foam::surfMesh::setInstance(const fileName& inst)
34     if (debug or true)
35     {
36         Info<< "void surfMesh::setInstance(const fileName& inst) : "
37             << "Resetting file instance to " << inst << endl;
38     }
40     instance() = inst;
42     storedIOPoints().writeOpt() = IOobject::AUTO_WRITE;
43     storedIOPoints().instance() = inst;
45     storedIOFaces().writeOpt() = IOobject::AUTO_WRITE;
46     storedIOFaces().instance() = inst;
48     storedIOZones().writeOpt() = IOobject::AUTO_WRITE;
49     storedIOZones().instance() = inst;
53 Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate()
55     if (debug)
56     {
57         Info<< "surfMesh::readUpdateState surfMesh::readUpdate() : "
58             << "Updating mesh based on saved data." << endl;
59     }
61     // Find point and face instances
62     fileName pointsInst(time().findInstance(meshDir(), "points"));
63     fileName facesInst(time().findInstance(meshDir(), "faces"));
65     if (debug)
66     {
67         Info<< "Points instance: old = " << pointsInstance()
68             << " new = " << pointsInst << nl
69             << "Faces instance: old = " << facesInstance()
70             << " new = " << facesInst << endl;
71     }
73     if (facesInst != facesInstance())
74     {
75         // Topological change
76         if (debug)
77         {
78             Info << "Topological change" << endl;
79         }
81         clearOut();
83         // Set instance to new instance.
84         // Note points instance can differ from faces instance.
85         setInstance(facesInst);
86         storedIOPoints().instance() = pointsInst;
88         storedIOPoints() = pointIOField
89         (
90             IOobject
91             (
92                 "points",
93                 pointsInst,
94                 meshSubDir,
95                 *this,
96                 IOobject::MUST_READ,
97                 IOobject::NO_WRITE,
98                 false
99             )
100         );
102         storedFaces() = faceIOList
103         (
104             IOobject
105             (
106                 "faces",
107                 facesInst,
108                 meshSubDir,
109                 *this,
110                 IOobject::MUST_READ,
111                 IOobject::NO_WRITE,
112                 false
113             )
114         );
116         // Reset the surface zones
117         surfZoneIOList newZones
118         (
119             IOobject
120             (
121                 "surfZones",
122                 facesInst,
123                 meshSubDir,
124                 *this,
125                 IOobject::MUST_READ,
126                 IOobject::NO_WRITE,
127                 false
128             )
129         );
131         // Check that zone types and names are unchanged
132         bool zonesChanged = false;
134         surfZoneList& zones = this->storedIOZones();
135         if (zones.size() != newZones.size())
136         {
137             zonesChanged = true;
138         }
139         else
140         {
141             forAll(zones, zoneI)
142             {
143                 if (zones[zoneI].name() != newZones[zoneI].name())
144                 {
145                     zonesChanged = true;
146                     break;
147                 }
148             }
149         }
151         zones.transfer(newZones);
153         if (zonesChanged)
154         {
155             WarningIn("surfMesh::readUpdateState surfMesh::readUpdate()")
156                 << "Number of zones has changed.  This may have "
157                 << "unexpected consequences.  Proceed with care." << endl;
159             return surfMesh::TOPO_PATCH_CHANGE;
160         }
161         else
162         {
163             return surfMesh::TOPO_CHANGE;
164         }
166     }
167     else if (pointsInst != pointsInstance())
168     {
169         // Points moved
170         if (debug)
171         {
172             Info << "Point motion" << endl;
173         }
175         clearGeom();
176         storedIOPoints().instance() = pointsInst;
178         storedIOPoints() = pointIOField
179         (
180             IOobject
181             (
182                 "points",
183                 pointsInst,
184                 meshSubDir,
185                 *this,
186                 IOobject::MUST_READ,
187                 IOobject::NO_WRITE,
188                 false
189             )
190         );
192         return surfMesh::POINTS_MOVED;
193     }
194     else
195     {
196         if (debug)
197         {
198             Info << "No change" << endl;
199         }
200     }
202     return surfMesh::UNCHANGED;
206 // ************************************************************************* //