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

processorMeshes.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 "processorMeshes.H"
00027 #include <OpenFOAM/Time.H>
00028 #include <OpenFOAM/primitiveMesh.H>
00029 
00030 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00031 
00032 void Foam::processorMeshes::read()
00033 {
00034     forAll (databases_, procI)
00035     {
00036         meshes_.set
00037         (
00038             procI,
00039             new fvMesh
00040             (
00041                 IOobject
00042                 (
00043                     meshName_,
00044                     databases_[procI].timeName(),
00045                     databases_[procI]
00046                 )
00047             )
00048         );
00049 
00050         pointProcAddressing_.set
00051         (
00052             procI,
00053             new labelIOList
00054             (
00055                 IOobject
00056                 (
00057                     "pointProcAddressing",
00058                     meshes_[procI].facesInstance(),
00059                     meshes_[procI].meshSubDir,
00060                     meshes_[procI],
00061                     IOobject::MUST_READ,
00062                     IOobject::NO_WRITE
00063                 )
00064             )
00065         );
00066 
00067         faceProcAddressing_.set
00068         (
00069             procI,
00070             new labelIOList
00071             (
00072                 IOobject
00073                 (
00074                     "faceProcAddressing",
00075                     meshes_[procI].facesInstance(),
00076                     meshes_[procI].meshSubDir,
00077                     meshes_[procI],
00078                     IOobject::MUST_READ,
00079                     IOobject::NO_WRITE
00080                 )
00081             )
00082         );
00083 
00084         cellProcAddressing_.set
00085         (
00086             procI,
00087             new labelIOList
00088             (
00089                 IOobject
00090                 (
00091                     "cellProcAddressing",
00092                     meshes_[procI].facesInstance(),
00093                     meshes_[procI].meshSubDir,
00094                     meshes_[procI],
00095                     IOobject::MUST_READ,
00096                     IOobject::NO_WRITE
00097                 )
00098             )
00099         );
00100 
00101         boundaryProcAddressing_.set
00102         (
00103             procI,
00104             new labelIOList
00105             (
00106                 IOobject
00107                 (
00108                     "boundaryProcAddressing",
00109                     meshes_[procI].facesInstance(),
00110                     meshes_[procI].meshSubDir,
00111                     meshes_[procI],
00112                     IOobject::MUST_READ,
00113                     IOobject::NO_WRITE
00114                 )
00115             )
00116         );
00117     }
00118 }
00119 
00120 
00121 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00122 
00123 Foam::processorMeshes::processorMeshes
00124 (
00125     PtrList<Time>& databases,
00126     const word& meshName
00127 )
00128 :
00129     databases_(databases),
00130     meshName_(meshName),
00131     meshes_(databases.size()),
00132     pointProcAddressing_(databases.size()),
00133     faceProcAddressing_(databases.size()),
00134     cellProcAddressing_(databases.size()),
00135     boundaryProcAddressing_(databases.size())
00136 {
00137     read();
00138 }
00139 
00140 
00141 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00142 
00143 Foam::fvMesh::readUpdateState Foam::processorMeshes::readUpdate()
00144 {
00145     fvMesh::readUpdateState stat = fvMesh::UNCHANGED;
00146 
00147     forAll (databases_, procI)
00148     {
00149         // Check if any new meshes need to be read.
00150         fvMesh::readUpdateState procStat = meshes_[procI].readUpdate();
00151 
00152         /*
00153         if (procStat != fvMesh::UNCHANGED)
00154         {
00155             Info<< "Processor " << procI
00156                 << " at time " << databases_[procI].timeName()
00157                 << " detected mesh change " << procStat
00158                 << endl;
00159         }
00160         */
00161 
00162         // Combine into overall mesh change status
00163         if (stat == fvMesh::UNCHANGED)
00164         {
00165             stat = procStat;
00166         }
00167         else
00168         {
00169             if (stat != procStat)
00170             {
00171                 FatalErrorIn("processorMeshes::readUpdate()")
00172                     << "Processor " << procI
00173                     << " has a different polyMesh at time "
00174                     << databases_[procI].timeName()
00175                     << " compared to any previous processors." << nl
00176                     << "Please check time " << databases_[procI].timeName()
00177                     << " directories on all processors for consistent"
00178                     << " mesh files."
00179                     << exit(FatalError);
00180             }
00181         }
00182     }
00183 
00184     if
00185     (
00186         stat == fvMesh::TOPO_CHANGE
00187      || stat == fvMesh::TOPO_PATCH_CHANGE
00188     )
00189     {
00190         // Reread all meshes and addresssing
00191         read();
00192     }
00193     return stat;
00194 }
00195 
00196 
00197 void Foam::processorMeshes::reconstructPoints(fvMesh& mesh)
00198 {
00199     // Read the field for all the processors
00200     PtrList<pointIOField> procsPoints(meshes_.size());
00201 
00202     forAll (meshes_, procI)
00203     {
00204         procsPoints.set
00205         (
00206             procI,
00207             new pointIOField
00208             (
00209                 IOobject
00210                 (
00211                     "points",
00212                     meshes_[procI].time().timeName(),
00213                     polyMesh::meshSubDir,
00214                     meshes_[procI],
00215                     IOobject::MUST_READ,
00216                     IOobject::NO_WRITE
00217                 )
00218             )
00219         );
00220     }
00221 
00222     // Create the new points
00223     vectorField newPoints(mesh.nPoints());
00224 
00225     forAll (meshes_, procI)
00226     {
00227         const vectorField& procPoints = procsPoints[procI];
00228 
00229         // Set the cell values in the reconstructed field
00230 
00231         const labelList& pointProcAddressingI = pointProcAddressing_[procI];
00232 
00233         if (pointProcAddressingI.size() != procPoints.size())
00234         {
00235             FatalErrorIn("processorMeshes")
00236                 << "problem :"
00237                 << " pointProcAddressingI:" << pointProcAddressingI.size()
00238                 << " procPoints:" << procPoints.size()
00239                 << abort(FatalError);
00240         }
00241 
00242         forAll(pointProcAddressingI, pointI)
00243         {
00244             newPoints[pointProcAddressingI[pointI]] = procPoints[pointI];
00245         }
00246     }
00247 
00248     mesh.movePoints(newPoints);
00249     mesh.write();
00250 }
00251 
00252 
00253 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines