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

reconstructPar.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 Application
00026     reconstructPar
00027 
00028 Description
00029     Reconstructs a mesh and fields of a case that is decomposed for parallel
00030     execution of OpenFOAM.
00031 
00032 \*---------------------------------------------------------------------------*/
00033 
00034 #include "argList.H"
00035 #include "timeSelector.H"
00036 
00037 #include "fvCFD.H"
00038 #include "IOobjectList.H"
00039 #include "processorMeshes.H"
00040 #include "fvFieldReconstructor.H"
00041 #include "pointFieldReconstructor.H"
00042 #include "reconstructLagrangian.H"
00043 
00044 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00045 
00046 int main(int argc, char *argv[])
00047 {
00048     // enable -constant ... if someone really wants it
00049     // enable -zeroTime to prevent accidentally trashing the initial fields
00050     timeSelector::addOptions(true, true);
00051     argList::noParallel();
00052 #   include "addRegionOption.H"
00053     argList::validOptions.insert("fields", "\"(list of fields)\"");
00054     argList::validOptions.insert("noLagrangian", "");
00055 
00056 #   include "setRootCase.H"
00057 #   include "createTime.H"
00058 
00059     HashSet<word> selectedFields;
00060     if (args.optionFound("fields"))
00061     {
00062         args.optionLookup("fields")() >> selectedFields;
00063     }
00064 
00065     bool noLagrangian = args.optionFound("noLagrangian");
00066 
00067     // determine the processor count directly
00068     label nProcs = 0;
00069     while (isDir(args.path()/(word("processor") + name(nProcs))))
00070     {
00071         ++nProcs;
00072     }
00073 
00074     if (!nProcs)
00075     {
00076         FatalErrorIn(args.executable())
00077             << "No processor* directories found"
00078             << exit(FatalError);
00079     }
00080 
00081     // Create the processor databases
00082     PtrList<Time> databases(nProcs);
00083 
00084     forAll (databases, procI)
00085     {
00086         databases.set
00087         (
00088             procI,
00089             new Time
00090             (
00091                 Time::controlDictName,
00092                 args.rootPath(),
00093                 args.caseName()/fileName(word("processor") + name(procI))
00094             )
00095         );
00096     }
00097 
00098     // use the times list from the master processor
00099     // and select a subset based on the command-line options
00100     instantList timeDirs = timeSelector::select
00101     (
00102         databases[0].times(),
00103         args
00104     );
00105 
00106     if (timeDirs.empty())
00107     {
00108         FatalErrorIn(args.executable())
00109             << "No times selected"
00110             << exit(FatalError);
00111     }
00112 
00113 #   include "createNamedMesh.H"
00114     fileName regionPrefix = "";
00115     if (regionName != fvMesh::defaultRegion)
00116     {
00117         regionPrefix = regionName;
00118     }
00119 
00120     // Set all times on processor meshes equal to reconstructed mesh
00121     forAll (databases, procI)
00122     {
00123         databases[procI].setTime(runTime.timeName(), runTime.timeIndex());
00124     }
00125 
00126     // Read all meshes and addressing to reconstructed mesh
00127     processorMeshes procMeshes(databases, regionName);
00128 
00129 
00130     // check face addressing for meshes that have been decomposed
00131     // with a very old foam version
00132 #   include "checkFaceAddressingComp.H"
00133 
00134     // Loop over all times
00135     forAll (timeDirs, timeI)
00136     {
00137         // Set time for global database
00138         runTime.setTime(timeDirs[timeI], timeI);
00139 
00140         Info << "Time = " << runTime.timeName() << endl << endl;
00141 
00142         // Set time for all databases
00143         forAll (databases, procI)
00144         {
00145             databases[procI].setTime(timeDirs[timeI], timeI);
00146         }
00147 
00148         // Check if any new meshes need to be read.
00149         fvMesh::readUpdateState meshStat = mesh.readUpdate();
00150 
00151         fvMesh::readUpdateState procStat = procMeshes.readUpdate();
00152 
00153         if (procStat == fvMesh::POINTS_MOVED)
00154         {
00155             // Reconstruct the points for moving mesh cases and write them out
00156             procMeshes.reconstructPoints(mesh);
00157         }
00158         else if (meshStat != procStat)
00159         {
00160             WarningIn(args.executable())
00161                 << "readUpdate for the reconstructed mesh:" << meshStat << nl
00162                 << "readUpdate for the processor meshes  :" << procStat << nl
00163                 << "These should be equal or your addressing"
00164                 << " might be incorrect."
00165                 << " Please check your time directories for any "
00166                 << "mesh directories." << endl;
00167         }
00168 
00169 
00170         // Get list of objects from processor0 database
00171         IOobjectList objects(procMeshes.meshes()[0], databases[0].timeName());
00172 
00173 
00174         // If there are any FV fields, reconstruct them
00175 
00176         if
00177         (
00178             objects.lookupClass(volScalarField::typeName).size()
00179          || objects.lookupClass(volVectorField::typeName).size()
00180          || objects.lookupClass(volSphericalTensorField::typeName).size()
00181          || objects.lookupClass(volSymmTensorField::typeName).size()
00182          || objects.lookupClass(volTensorField::typeName).size()
00183          || objects.lookupClass(surfaceScalarField::typeName).size()
00184         )
00185         {
00186             Info << "Reconstructing FV fields" << nl << endl;
00187 
00188             fvFieldReconstructor fvReconstructor
00189             (
00190                 mesh,
00191                 procMeshes.meshes(),
00192                 procMeshes.faceProcAddressing(),
00193                 procMeshes.cellProcAddressing(),
00194                 procMeshes.boundaryProcAddressing()
00195             );
00196 
00197             fvReconstructor.reconstructFvVolumeFields<scalar>
00198             (
00199                 objects,
00200                 selectedFields
00201             );
00202             fvReconstructor.reconstructFvVolumeFields<vector>
00203             (
00204                 objects,
00205                 selectedFields
00206             );
00207             fvReconstructor.reconstructFvVolumeFields<sphericalTensor>
00208             (
00209                 objects,
00210                 selectedFields
00211             );
00212             fvReconstructor.reconstructFvVolumeFields<symmTensor>
00213             (
00214                 objects,
00215                 selectedFields
00216             );
00217             fvReconstructor.reconstructFvVolumeFields<tensor>
00218             (
00219                 objects,
00220                 selectedFields
00221             );
00222 
00223             fvReconstructor.reconstructFvSurfaceFields<scalar>
00224             (
00225                 objects,
00226                 selectedFields
00227             );
00228         }
00229         else
00230         {
00231             Info << "No FV fields" << nl << endl;
00232         }
00233 
00234 
00235         // If there are any point fields, reconstruct them
00236         if
00237         (
00238             objects.lookupClass(pointScalarField::typeName).size()
00239          || objects.lookupClass(pointVectorField::typeName).size()
00240          || objects.lookupClass(pointSphericalTensorField::typeName).size()
00241          || objects.lookupClass(pointSymmTensorField::typeName).size()
00242          || objects.lookupClass(pointTensorField::typeName).size()
00243         )
00244         {
00245             Info << "Reconstructing point fields" << nl << endl;
00246 
00247             pointMesh pMesh(mesh);
00248             PtrList<pointMesh> pMeshes(procMeshes.meshes().size());
00249 
00250             forAll (pMeshes, procI)
00251             {
00252                 pMeshes.set(procI, new pointMesh(procMeshes.meshes()[procI]));
00253             }
00254 
00255             pointFieldReconstructor pointReconstructor
00256             (
00257                 pMesh,
00258                 pMeshes,
00259                 procMeshes.pointProcAddressing(),
00260                 procMeshes.boundaryProcAddressing()
00261             );
00262 
00263             pointReconstructor.reconstructFields<scalar>(objects);
00264             pointReconstructor.reconstructFields<vector>(objects);
00265             pointReconstructor.reconstructFields<sphericalTensor>(objects);
00266             pointReconstructor.reconstructFields<symmTensor>(objects);
00267             pointReconstructor.reconstructFields<tensor>(objects);
00268         }
00269         else
00270         {
00271             Info << "No point fields" << nl << endl;
00272         }
00273 
00274 
00275         // If there are any clouds, reconstruct them.
00276         // The problem is that a cloud of size zero will not get written so
00277         // in pass 1 we determine the cloud names and per cloud name the
00278         // fields. Note that the fields are stored as IOobjectList from
00279         // the first processor that has them. They are in pass2 only used
00280         // for name and type (scalar, vector etc).
00281 
00282         if (!noLagrangian)
00283         {
00284             HashTable<IOobjectList> cloudObjects;
00285 
00286             forAll (databases, procI)
00287             {
00288                 fileNameList cloudDirs
00289                 (
00290                     readDir
00291                     (
00292                         databases[procI].timePath()/regionPrefix/cloud::prefix,
00293                         fileName::DIRECTORY
00294                     )
00295                 );
00296 
00297                 forAll (cloudDirs, i)
00298                 {
00299                     // Check if we already have cloud objects for this cloudname
00300                     HashTable<IOobjectList>::const_iterator iter =
00301                         cloudObjects.find(cloudDirs[i]);
00302 
00303                     if (iter == cloudObjects.end())
00304                     {
00305                         // Do local scan for valid cloud objects
00306                         IOobjectList sprayObjs
00307                         (
00308                             procMeshes.meshes()[procI],
00309                             databases[procI].timeName(),
00310                             cloud::prefix/cloudDirs[i]
00311                         );
00312 
00313                         IOobject* positionsPtr = sprayObjs.lookup("positions");
00314 
00315                         if (positionsPtr)
00316                         {
00317                             cloudObjects.insert(cloudDirs[i], sprayObjs);
00318                         }
00319                     }
00320                 }
00321             }
00322 
00323 
00324             if (cloudObjects.size())
00325             {
00326                 // Pass2: reconstruct the cloud
00327                 forAllConstIter(HashTable<IOobjectList>, cloudObjects, iter)
00328                 {
00329                     const word cloudName = string::validate<word>(iter.key());
00330 
00331                     // Objects (on arbitrary processor)
00332                     const IOobjectList& sprayObjs = iter();
00333 
00334                     Info<< "Reconstructing lagrangian fields for cloud "
00335                         << cloudName << nl << endl;
00336 
00337                     reconstructLagrangianPositions
00338                     (
00339                         mesh,
00340                         cloudName,
00341                         procMeshes.meshes(),
00342                         procMeshes.faceProcAddressing(),
00343                         procMeshes.cellProcAddressing()
00344                     );
00345                     reconstructLagrangianFields<label>
00346                     (
00347                         cloudName,
00348                         mesh,
00349                         procMeshes.meshes(),
00350                         sprayObjs
00351                     );
00352                     reconstructLagrangianFields<scalar>
00353                     (
00354                         cloudName,
00355                         mesh,
00356                         procMeshes.meshes(),
00357                         sprayObjs
00358                     );
00359                     reconstructLagrangianFields<vector>
00360                     (
00361                         cloudName,
00362                         mesh,
00363                         procMeshes.meshes(),
00364                         sprayObjs
00365                     );
00366                     reconstructLagrangianFields<sphericalTensor>
00367                     (
00368                         cloudName,
00369                         mesh,
00370                         procMeshes.meshes(),
00371                         sprayObjs
00372                     );
00373                     reconstructLagrangianFields<symmTensor>
00374                     (
00375                         cloudName,
00376                         mesh,
00377                         procMeshes.meshes(),
00378                         sprayObjs
00379                     );
00380                     reconstructLagrangianFields<tensor>
00381                     (
00382                         cloudName,
00383                         mesh,
00384                         procMeshes.meshes(),
00385                         sprayObjs
00386                     );
00387                 }
00388             }
00389             else
00390             {
00391                 Info << "No lagrangian fields" << nl << endl;
00392             }
00393         }
00394 
00395         // If there are any "uniform" directories copy them from
00396         // the master processor
00397 
00398         fileName uniformDir0 = databases[0].timePath()/"uniform";
00399         if (isDir(uniformDir0))
00400         {
00401             cp(uniformDir0, runTime.timePath());
00402         }
00403     }
00404 
00405     Info<< "End.\n" << endl;
00406 
00407     return 0;
00408 }
00409 
00410 
00411 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd