Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #include "ReadFields.H"
00027 #include <OpenFOAM/HashSet.H>
00028 #include <OpenFOAM/Pstream.H>
00029 #include <OpenFOAM/IOobjectList.H>
00030 
00031 
00032 
00033 
00034 
00035 template<class GeoField, class Mesh>
00036 Foam::wordList Foam::ReadFields
00037 (
00038     const Mesh& mesh,
00039     const IOobjectList& objects,
00040     PtrList<GeoField>& fields,
00041     const bool syncPar
00042 )
00043 {
00044     
00045     IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName));
00046 
00047     wordList masterNames(fieldObjects.names());
00048 
00049     if (syncPar && Pstream::parRun())
00050     {
00051         
00052         const wordList localNames(masterNames);
00053         Pstream::scatter(masterNames);
00054 
00055         HashSet<word> localNamesSet(localNames);
00056 
00057         forAll(masterNames, i)
00058         {
00059             const word& masterFld = masterNames[i];
00060 
00061             HashSet<word>::iterator iter = localNamesSet.find(masterFld);
00062 
00063             if (iter == localNamesSet.end())
00064             {
00065                 FatalErrorIn
00066                 (
00067                     "ReadFields<class GeoField, class Mesh>"
00068                     "(const Mesh&, const IOobjectList&, PtrList<GeoField>&"
00069                     ", const bool)"
00070                 )   << "Fields not synchronised across processors." << endl
00071                     << "Master has fields " << masterNames
00072                     << "  processor " << Pstream::myProcNo()
00073                     << " has fields " << localNames << exit(FatalError);
00074             }
00075             else
00076             {
00077                 localNamesSet.erase(iter);
00078             }
00079         }
00080 
00081         forAllConstIter(HashSet<word>, localNamesSet, iter)
00082         {
00083             FatalErrorIn
00084             (
00085                 "ReadFields<class GeoField, class Mesh>"
00086                 "(const Mesh&, const IOobjectList&, PtrList<GeoField>&"
00087                 ", const bool)"
00088             )   << "Fields not synchronised across processors." << endl
00089                 << "Master has fields " << masterNames
00090                 << "  processor " << Pstream::myProcNo()
00091                 << " has fields " << localNames << exit(FatalError);
00092         }
00093     }
00094 
00095 
00096     fields.setSize(masterNames.size());
00097 
00098     
00099 
00100     forAll(masterNames, i)
00101     {
00102         Info<< "Reading " << GeoField::typeName << ' ' << masterNames[i]
00103             << endl;
00104 
00105         const IOobject& io = *fieldObjects[masterNames[i]];
00106 
00107         fields.set
00108         (
00109             i,
00110             new GeoField
00111             (
00112                 IOobject
00113                 (
00114                     io.name(),
00115                     io.instance(),
00116                     io.local(),
00117                     io.db(),
00118                     IOobject::MUST_READ,
00119                     IOobject::AUTO_WRITE,
00120                     io.registerObject()
00121                 ),
00122                 mesh
00123             )
00124         );
00125     }
00126     return masterNames;    
00127 }
00128 
00129 
00130