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

polyMeshIO.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 "polyMesh.H"
00027 #include <OpenFOAM/Time.H>
00028 #include <OpenFOAM/cellIOList.H>
00029 
00030 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00031 
00032 void Foam::polyMesh::setInstance(const fileName& inst)
00033 {
00034     if (debug)
00035     {
00036         Info<< "void polyMesh::setInstance(const fileName& inst) : "
00037             << "Resetting file instance to " << inst << endl;
00038     }
00039 
00040     points_.writeOpt() = IOobject::AUTO_WRITE;
00041     points_.instance() = inst;
00042 
00043     faces_.writeOpt() = IOobject::AUTO_WRITE;
00044     faces_.instance() = inst;
00045 
00046     owner_.writeOpt() = IOobject::AUTO_WRITE;
00047     owner_.instance() = inst;
00048 
00049     neighbour_.writeOpt() = IOobject::AUTO_WRITE;
00050     neighbour_.instance() = inst;
00051 
00052     boundary_.writeOpt() = IOobject::AUTO_WRITE;
00053     boundary_.instance() = inst;
00054 
00055     pointZones_.writeOpt() = IOobject::AUTO_WRITE;
00056     pointZones_.instance() = inst;
00057 
00058     faceZones_.writeOpt() = IOobject::AUTO_WRITE;
00059     faceZones_.instance() = inst;
00060 
00061     cellZones_.writeOpt() = IOobject::AUTO_WRITE;
00062     cellZones_.instance() = inst;
00063 }
00064 
00065 
00066 Foam::polyMesh::readUpdateState Foam::polyMesh::readUpdate()
00067 {
00068     if (debug)
00069     {
00070         Info<< "polyMesh::readUpdateState polyMesh::readUpdate() : "
00071             << "Updating mesh based on saved data." << endl;
00072     }
00073 
00074     // Find the point and cell instance
00075     fileName pointsInst(time().findInstance(meshDir(), "points"));
00076     fileName facesInst(time().findInstance(meshDir(), "faces"));
00077 
00078     if (debug)
00079     {
00080         Info<< "Faces instance: old = " << facesInstance()
00081             << " new = " << facesInst << nl
00082             << "Points instance: old = " << pointsInstance()
00083             << " new = " << pointsInst << endl;
00084     }
00085 
00086     if (facesInst != facesInstance())
00087     {
00088         // Topological change
00089         if (debug)
00090         {
00091             Info << "Topological change" << endl;
00092         }
00093 
00094         clearOut();
00095 
00096         // Set instance to new instance. Note that points instance can differ
00097         // from from faces instance.
00098         setInstance(facesInst);
00099         points_.instance() = pointsInst;
00100 
00101         points_ = pointIOField
00102         (
00103             IOobject
00104             (
00105                 "points",
00106                 pointsInst,
00107                 meshSubDir,
00108                 *this,
00109                 IOobject::MUST_READ,
00110                 IOobject::NO_WRITE,
00111                 false
00112             )
00113         );
00114 
00115         faces_ = faceIOList
00116         (
00117             IOobject
00118             (
00119                 "faces",
00120                 facesInst,
00121                 meshSubDir,
00122                 *this,
00123                 IOobject::MUST_READ,
00124                 IOobject::NO_WRITE,
00125                 false
00126             )
00127         );
00128 
00129         owner_ = labelIOList
00130         (
00131             IOobject
00132             (
00133                 "owner",
00134                 facesInst,
00135                 meshSubDir,
00136                 *this,
00137                 IOobject::READ_IF_PRESENT,
00138                 IOobject::NO_WRITE,
00139                 false
00140             )
00141         );
00142 
00143         neighbour_ = labelIOList
00144         (
00145             IOobject
00146             (
00147                 "neighbour",
00148                 facesInst,
00149                 meshSubDir,
00150                 *this,
00151                 IOobject::READ_IF_PRESENT,
00152                 IOobject::NO_WRITE,
00153                 false
00154             )
00155         );
00156 
00157         // Reset the boundary patches
00158         polyBoundaryMesh newBoundary
00159         (
00160             IOobject
00161             (
00162                 "boundary",
00163                 facesInst,
00164                 meshSubDir,
00165                 *this,
00166                 IOobject::MUST_READ,
00167                 IOobject::NO_WRITE,
00168                 false
00169             ),
00170             *this
00171         );
00172 
00173         // Check that patch types and names are unchanged
00174         bool boundaryChanged = false;
00175 
00176         if (newBoundary.size() != boundary_.size())
00177         {
00178             boundaryChanged = true;
00179         }
00180         else
00181         {
00182             wordList newTypes = newBoundary.types();
00183             wordList newNames = newBoundary.names();
00184 
00185             wordList oldTypes = boundary_.types();
00186             wordList oldNames = boundary_.names();
00187 
00188             forAll (oldTypes, patchI)
00189             {
00190                 if
00191                 (
00192                     oldTypes[patchI] != newTypes[patchI]
00193                  || oldNames[patchI] != newNames[patchI]
00194                 )
00195                 {
00196                     boundaryChanged = true;
00197                     break;
00198                 }
00199             }
00200         }
00201 
00202         if (boundaryChanged)
00203         {
00204             WarningIn("polyMesh::readUpdateState polyMesh::readUpdate()")
00205                 << "Number of patches has changed.  This may have "
00206                 << "unexpected consequences.  Proceed with care." << endl;
00207 
00208             boundary_.clear();
00209             boundary_.setSize(newBoundary.size());
00210 
00211             forAll (newBoundary, patchI)
00212             {
00213                 boundary_.set(patchI, newBoundary[patchI].clone(boundary_));
00214             }
00215         }
00216         else
00217         {
00218             forAll (boundary_, patchI)
00219             {
00220                 boundary_[patchI] = polyPatch
00221                 (
00222                     newBoundary[patchI].name(),
00223                     newBoundary[patchI].size(),
00224                     newBoundary[patchI].start(),
00225                     patchI,
00226                     boundary_
00227                 );
00228             }
00229         }
00230 
00231 
00232         // Boundary is set so can use initMesh now (uses boundary_ to
00233         // determine internal and active faces)
00234 
00235         if (exists(owner_.objectPath()))
00236         {
00237             initMesh();
00238         }
00239         else
00240         {
00241             cellIOList cells
00242             (
00243                 IOobject
00244                 (
00245                     "cells",
00246                     facesInst,
00247                     meshSubDir,
00248                     *this,
00249                     IOobject::MUST_READ,
00250                     IOobject::NO_WRITE,
00251                     false
00252                 )
00253             );
00254 
00255             // Recalculate the owner/neighbour addressing and reset the
00256             // primitiveMesh
00257             initMesh(cells);
00258         }
00259 
00260 
00261         // Even if number of patches stayed same still recalculate boundary
00262         // data.
00263 
00264         // Calculate topology for the patches (processor-processor comms etc.)
00265         boundary_.updateMesh();
00266 
00267         // Calculate the geometry for the patches (transformation tensors etc.)
00268         boundary_.calcGeometry();
00269 
00270         // Derived info
00271         bounds_ = boundBox(points_);
00272         geometricD_ = Vector<label>::zero;
00273         solutionD_ = Vector<label>::zero;
00274 
00275         // Zones
00276         pointZoneMesh newPointZones
00277         (
00278             IOobject
00279             (
00280                 "pointZones",
00281                 facesInst,
00282                 meshSubDir,
00283                 *this,
00284                 IOobject::READ_IF_PRESENT,
00285                 IOobject::NO_WRITE,
00286                 false
00287             ),
00288             *this
00289         );
00290 
00291         label oldSize = pointZones_.size();
00292 
00293         if (newPointZones.size() <= pointZones_.size())
00294         {
00295             pointZones_.setSize(newPointZones.size());
00296         }
00297 
00298         // Reset existing ones
00299         forAll (pointZones_, czI)
00300         {
00301             pointZones_[czI] = newPointZones[czI];
00302         }
00303 
00304         // Extend with extra ones
00305         pointZones_.setSize(newPointZones.size());
00306 
00307         for (label czI = oldSize; czI < newPointZones.size(); czI++)
00308         {
00309             pointZones_.set(czI, newPointZones[czI].clone(pointZones_));
00310         }
00311 
00312 
00313         faceZoneMesh newFaceZones
00314         (
00315             IOobject
00316             (
00317                 "faceZones",
00318                 facesInst,
00319                 meshSubDir,
00320                 *this,
00321                 IOobject::READ_IF_PRESENT,
00322                 IOobject::NO_WRITE,
00323                 false
00324             ),
00325             *this
00326         );
00327 
00328         oldSize = faceZones_.size();
00329 
00330         if (newFaceZones.size() <= faceZones_.size())
00331         {
00332             faceZones_.setSize(newFaceZones.size());
00333         }
00334 
00335         // Reset existing ones
00336         forAll (faceZones_, fzI)
00337         {
00338             faceZones_[fzI].resetAddressing
00339             (
00340                 newFaceZones[fzI],
00341                 newFaceZones[fzI].flipMap()
00342             );
00343         }
00344 
00345         // Extend with extra ones
00346         faceZones_.setSize(newFaceZones.size());
00347 
00348         for (label fzI = oldSize; fzI < newFaceZones.size(); fzI++)
00349         {
00350             faceZones_.set(fzI, newFaceZones[fzI].clone(faceZones_));
00351         }
00352 
00353 
00354         cellZoneMesh newCellZones
00355         (
00356             IOobject
00357             (
00358                 "cellZones",
00359                 facesInst,
00360                 meshSubDir,
00361                 *this,
00362                 IOobject::READ_IF_PRESENT,
00363                 IOobject::NO_WRITE,
00364                 false
00365             ),
00366             *this
00367         );
00368 
00369         oldSize = cellZones_.size();
00370 
00371         if (newCellZones.size() <= cellZones_.size())
00372         {
00373             cellZones_.setSize(newCellZones.size());
00374         }
00375 
00376         // Reset existing ones
00377         forAll (cellZones_, czI)
00378         {
00379             cellZones_[czI] = newCellZones[czI];
00380         }
00381 
00382         // Extend with extra ones
00383         cellZones_.setSize(newCellZones.size());
00384 
00385         for (label czI = oldSize; czI < newCellZones.size(); czI++)
00386         {
00387             cellZones_.set(czI, newCellZones[czI].clone(cellZones_));
00388         }
00389 
00390 
00391         if (boundaryChanged)
00392         {
00393             return polyMesh::TOPO_PATCH_CHANGE;
00394         }
00395         else
00396         {
00397             return polyMesh::TOPO_CHANGE;
00398         }
00399     }
00400     else if (pointsInst != pointsInstance())
00401     {
00402         // Points moved
00403         if (debug)
00404         {
00405             Info << "Point motion" << endl;
00406         }
00407 
00408         clearGeom();
00409 
00410         points_.instance() = pointsInst;
00411 
00412         points_ = pointIOField
00413         (
00414             IOobject
00415             (
00416                 "points",
00417                 pointsInst,
00418                 meshSubDir,
00419                 *this,
00420                 IOobject::MUST_READ,
00421                 IOobject::NO_WRITE,
00422                 false
00423             )
00424         );
00425 
00426         // Derived info
00427         bounds_ = boundBox(points_);
00428 
00429         // Rotation can cause direction vector to change
00430         geometricD_ = Vector<label>::zero;
00431         solutionD_ = Vector<label>::zero;
00432         
00433         return polyMesh::POINTS_MOVED;
00434     }
00435     else
00436     {
00437         if (debug)
00438         {
00439             Info << "No change" << endl;
00440         }
00441 
00442         return polyMesh::UNCHANGED;
00443     }
00444 }
00445 
00446 
00447 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines