FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "surfMesh.H"
00027 #include <OpenFOAM/Time.H>
00028 
00029 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00030 
00031 void Foam::surfMesh::setInstance(const fileName& inst)
00032 {
00033     if (debug or true)
00034     {
00035         Info<< "void surfMesh::setInstance(const fileName& inst) : "
00036             << "Resetting file instance to " << inst << endl;
00037     }
00038 
00039     instance() = inst;
00040 
00041     storedIOPoints().writeOpt() = IOobject::AUTO_WRITE;
00042     storedIOPoints().instance() = inst;
00043 
00044     storedIOFaces().writeOpt() = IOobject::AUTO_WRITE;
00045     storedIOFaces().instance() = inst;
00046 
00047     storedIOZones().writeOpt() = IOobject::AUTO_WRITE;
00048     storedIOZones().instance() = inst;
00049 }
00050 
00051 
00052 Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate()
00053 {
00054     if (debug)
00055     {
00056         Info<< "surfMesh::readUpdateState surfMesh::readUpdate() : "
00057             << "Updating mesh based on saved data." << endl;
00058     }
00059 
00060     // Find point and face instances
00061     fileName pointsInst(time().findInstance(meshDir(), "points"));
00062     fileName facesInst(time().findInstance(meshDir(), "faces"));
00063 
00064     if (debug)
00065     {
00066         Info<< "Points instance: old = " << pointsInstance()
00067             << " new = " << pointsInst << nl
00068             << "Faces instance: old = " << facesInstance()
00069             << " new = " << facesInst << endl;
00070     }
00071 
00072     if (facesInst != facesInstance())
00073     {
00074         // Topological change
00075         if (debug)
00076         {
00077             Info << "Topological change" << endl;
00078         }
00079 
00080         clearOut();
00081 
00082         // Set instance to new instance.
00083         // Note points instance can differ from faces instance.
00084         setInstance(facesInst);
00085         storedIOPoints().instance() = pointsInst;
00086 
00087         storedIOPoints() = pointIOField
00088         (
00089             IOobject
00090             (
00091                 "points",
00092                 pointsInst,
00093                 meshSubDir,
00094                 *this,
00095                 IOobject::MUST_READ,
00096                 IOobject::NO_WRITE,
00097                 false
00098             )
00099         );
00100 
00101         storedFaces() = faceIOList
00102         (
00103             IOobject
00104             (
00105                 "faces",
00106                 facesInst,
00107                 meshSubDir,
00108                 *this,
00109                 IOobject::MUST_READ,
00110                 IOobject::NO_WRITE,
00111                 false
00112             )
00113         );
00114 
00115         // Reset the surface zones
00116         surfZoneIOList newZones
00117         (
00118             IOobject
00119             (
00120                 "surfZones",
00121                 facesInst,
00122                 meshSubDir,
00123                 *this,
00124                 IOobject::MUST_READ,
00125                 IOobject::NO_WRITE,
00126                 false
00127             )
00128         );
00129 
00130         // Check that zone types and names are unchanged
00131         bool zonesChanged = false;
00132 
00133         surfZoneList& zones = this->storedIOZones();
00134         if (zones.size() != newZones.size())
00135         {
00136             zonesChanged = true;
00137         }
00138         else
00139         {
00140             forAll(zones, zoneI)
00141             {
00142                 if (zones[zoneI].name() != newZones[zoneI].name())
00143                 {
00144                     zonesChanged = true;
00145                     break;
00146                 }
00147             }
00148         }
00149 
00150         zones.transfer(newZones);
00151 
00152         if (zonesChanged)
00153         {
00154             WarningIn("surfMesh::readUpdateState surfMesh::readUpdate()")
00155                 << "Number of zones has changed.  This may have "
00156                 << "unexpected consequences.  Proceed with care." << endl;
00157 
00158             return surfMesh::TOPO_PATCH_CHANGE;
00159         }
00160         else
00161         {
00162             return surfMesh::TOPO_CHANGE;
00163         }
00164 
00165     }
00166     else if (pointsInst != pointsInstance())
00167     {
00168         // Points moved
00169         if (debug)
00170         {
00171             Info << "Point motion" << endl;
00172         }
00173 
00174         clearGeom();
00175         storedIOPoints().instance() = pointsInst;
00176 
00177         storedIOPoints() = pointIOField
00178         (
00179             IOobject
00180             (
00181                 "points",
00182                 pointsInst,
00183                 meshSubDir,
00184                 *this,
00185                 IOobject::MUST_READ,
00186                 IOobject::NO_WRITE,
00187                 false
00188             )
00189         );
00190 
00191         return surfMesh::POINTS_MOVED;
00192     }
00193     else
00194     {
00195         if (debug)
00196         {
00197             Info << "No change" << endl;
00198         }
00199     }
00200 
00201     return surfMesh::UNCHANGED;
00202 }
00203 
00204 
00205 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines