1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "ReadFields.H"
29 #include "IOobjectList.H"
31 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
33 // Read all fields of type. Returns names of fields read. Guarantees all
34 // processors to read fields in same order.
35 template<class GeoField, class Mesh>
36 Foam::wordList Foam::ReadFields
39 const IOobjectList& objects,
40 PtrList<GeoField>& fields,
44 // Search list of objects for wanted type
45 IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName));
47 wordList masterNames(fieldObjects.names());
49 if (syncPar && Pstream::parRun())
51 // Check that I have the same fields as the master
52 const wordList localNames(masterNames);
53 Pstream::scatter(masterNames);
55 HashSet<word> localNamesSet(localNames);
57 forAll(masterNames, i)
59 const word& masterFld = masterNames[i];
61 HashSet<word>::iterator iter = localNamesSet.find(masterFld);
63 if (iter == localNamesSet.end())
67 "ReadFields<class GeoField, class Mesh>"
68 "(const Mesh&, const IOobjectList&, PtrList<GeoField>&"
70 ) << "Fields not synchronised across processors." << endl
71 << "Master has fields " << masterNames
72 << " processor " << Pstream::myProcNo()
73 << " has fields " << localNames << exit(FatalError);
77 localNamesSet.erase(iter);
81 forAllConstIter(HashSet<word>, localNamesSet, iter)
85 "ReadFields<class GeoField, class Mesh>"
86 "(const Mesh&, const IOobjectList&, PtrList<GeoField>&"
88 ) << "Fields not synchronised across processors." << endl
89 << "Master has fields " << masterNames
90 << " processor " << Pstream::myProcNo()
91 << " has fields " << localNames << exit(FatalError);
96 fields.setSize(masterNames.size());
98 // Make sure to read in masterNames order.
100 forAll(masterNames, i)
102 Info<< "Reading " << GeoField::typeName << ' ' << masterNames[i]
105 const IOobject& io = *fieldObjects[masterNames[i]];
119 IOobject::AUTO_WRITE,
130 // ************************************************************************* //