OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

surfMeshIO.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "surfMesh.H"
00028 #include "Time.H"
00029 
00030 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00031 
00032 void Foam::surfMesh::setInstance(const fileName& inst)
00033 {
00034     if (debug or true)
00035     {
00036         Info<< "void surfMesh::setInstance(const fileName& inst) : "
00037             << "Resetting file instance to " << inst << endl;
00038     }
00039 
00040     instance() = inst;
00041 
00042     storedIOPoints().writeOpt() = IOobject::AUTO_WRITE;
00043     storedIOPoints().instance() = inst;
00044 
00045     storedIOFaces().writeOpt() = IOobject::AUTO_WRITE;
00046     storedIOFaces().instance() = inst;
00047 
00048     storedIOZones().writeOpt() = IOobject::AUTO_WRITE;
00049     storedIOZones().instance() = inst;
00050 }
00051 
00052 
00053 Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate()
00054 {
00055     if (debug)
00056     {
00057         Info<< "surfMesh::readUpdateState surfMesh::readUpdate() : "
00058             << "Updating mesh based on saved data." << endl;
00059     }
00060 
00061     // Find point and face instances
00062     fileName pointsInst(time().findInstance(meshDir(), "points"));
00063     fileName facesInst(time().findInstance(meshDir(), "faces"));
00064 
00065     if (debug)
00066     {
00067         Info<< "Points instance: old = " << pointsInstance()
00068             << " new = " << pointsInst << nl
00069             << "Faces instance: old = " << facesInstance()
00070             << " new = " << facesInst << endl;
00071     }
00072 
00073     if (facesInst != facesInstance())
00074     {
00075         // Topological change
00076         if (debug)
00077         {
00078             Info << "Topological change" << endl;
00079         }
00080 
00081         clearOut();
00082 
00083         // Set instance to new instance.
00084         // Note points instance can differ from faces instance.
00085         setInstance(facesInst);
00086         storedIOPoints().instance() = pointsInst;
00087 
00088         storedIOPoints() = pointIOField
00089         (
00090             IOobject
00091             (
00092                 "points",
00093                 pointsInst,
00094                 meshSubDir,
00095                 *this,
00096                 IOobject::MUST_READ,
00097                 IOobject::NO_WRITE,
00098                 false
00099             )
00100         );
00101 
00102         storedFaces() = faceIOList
00103         (
00104             IOobject
00105             (
00106                 "faces",
00107                 facesInst,
00108                 meshSubDir,
00109                 *this,
00110                 IOobject::MUST_READ,
00111                 IOobject::NO_WRITE,
00112                 false
00113             )
00114         );
00115 
00116         // Reset the surface zones
00117         surfZoneIOList newZones
00118         (
00119             IOobject
00120             (
00121                 "surfZones",
00122                 facesInst,
00123                 meshSubDir,
00124                 *this,
00125                 IOobject::MUST_READ,
00126                 IOobject::NO_WRITE,
00127                 false
00128             )
00129         );
00130 
00131         // Check that zone types and names are unchanged
00132         bool zonesChanged = false;
00133 
00134         surfZoneList& zones = this->storedIOZones();
00135         if (zones.size() != newZones.size())
00136         {
00137             zonesChanged = true;
00138         }
00139         else
00140         {
00141             forAll(zones, zoneI)
00142             {
00143                 if (zones[zoneI].name() != newZones[zoneI].name())
00144                 {
00145                     zonesChanged = true;
00146                     break;
00147                 }
00148             }
00149         }
00150 
00151         zones.transfer(newZones);
00152 
00153         if (zonesChanged)
00154         {
00155             WarningIn("surfMesh::readUpdateState surfMesh::readUpdate()")
00156                 << "Number of zones has changed.  This may have "
00157                 << "unexpected consequences.  Proceed with care." << endl;
00158 
00159             return surfMesh::TOPO_PATCH_CHANGE;
00160         }
00161         else
00162         {
00163             return surfMesh::TOPO_CHANGE;
00164         }
00165 
00166     }
00167     else if (pointsInst != pointsInstance())
00168     {
00169         // Points moved
00170         if (debug)
00171         {
00172             Info << "Point motion" << endl;
00173         }
00174 
00175         clearGeom();
00176         storedIOPoints().instance() = pointsInst;
00177 
00178         storedIOPoints() = pointIOField
00179         (
00180             IOobject
00181             (
00182                 "points",
00183                 pointsInst,
00184                 meshSubDir,
00185                 *this,
00186                 IOobject::MUST_READ,
00187                 IOobject::NO_WRITE,
00188                 false
00189             )
00190         );
00191 
00192         return surfMesh::POINTS_MOVED;
00193     }
00194     else
00195     {
00196         if (debug)
00197         {
00198             Info << "No change" << endl;
00199         }
00200     }
00201 
00202     return surfMesh::UNCHANGED;
00203 }
00204 
00205 
00206 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd