ReadFields.C
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
00027 #include "ReadFields.H"
00028 #include "HashSet.H"
00029 #include "Pstream.H"
00030 #include "IOobjectList.H"
00031
00032
00033
00034
00035
00036 template<class GeoField, class Mesh>
00037 Foam::wordList Foam::ReadFields
00038 (
00039 const Mesh& mesh,
00040 const IOobjectList& objects,
00041 PtrList<GeoField>& fields,
00042 const bool syncPar
00043 )
00044 {
00045
00046 IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName));
00047
00048 wordList masterNames(fieldObjects.names());
00049
00050 if (syncPar && Pstream::parRun())
00051 {
00052
00053 const wordList localNames(masterNames);
00054 Pstream::scatter(masterNames);
00055
00056 HashSet<word> localNamesSet(localNames);
00057
00058 forAll(masterNames, i)
00059 {
00060 const word& masterFld = masterNames[i];
00061
00062 HashSet<word>::iterator iter = localNamesSet.find(masterFld);
00063
00064 if (iter == localNamesSet.end())
00065 {
00066 FatalErrorIn
00067 (
00068 "ReadFields<class GeoField, class Mesh>"
00069 "(const Mesh&, const IOobjectList&, PtrList<GeoField>&"
00070 ", const bool)"
00071 ) << "Fields not synchronised across processors." << endl
00072 << "Master has fields " << masterNames
00073 << " processor " << Pstream::myProcNo()
00074 << " has fields " << localNames << exit(FatalError);
00075 }
00076 else
00077 {
00078 localNamesSet.erase(iter);
00079 }
00080 }
00081
00082 forAllConstIter(HashSet<word>, localNamesSet, iter)
00083 {
00084 FatalErrorIn
00085 (
00086 "ReadFields<class GeoField, class Mesh>"
00087 "(const Mesh&, const IOobjectList&, PtrList<GeoField>&"
00088 ", const bool)"
00089 ) << "Fields not synchronised across processors." << endl
00090 << "Master has fields " << masterNames
00091 << " processor " << Pstream::myProcNo()
00092 << " has fields " << localNames << exit(FatalError);
00093 }
00094 }
00095
00096
00097 fields.setSize(masterNames.size());
00098
00099
00100
00101 forAll(masterNames, i)
00102 {
00103 Info<< "Reading " << GeoField::typeName << ' ' << masterNames[i]
00104 << endl;
00105
00106 const IOobject& io = *fieldObjects[masterNames[i]];
00107
00108 fields.set
00109 (
00110 i,
00111 new GeoField
00112 (
00113 IOobject
00114 (
00115 io.name(),
00116 io.instance(),
00117 io.local(),
00118 io.db(),
00119 IOobject::MUST_READ,
00120 IOobject::AUTO_WRITE,
00121 io.registerObject()
00122 ),
00123 mesh
00124 )
00125 );
00126 }
00127 return masterNames;
00128 }
00129
00130
00131
Copyright © 2000-2009 OpenCFD Ltd