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

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