1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "ReadFields.H"
30 #include "IOobjectList.H"
32 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
34 // Read all fields of type. Returns names of fields read. Guarantees all
35 // processors to read fields in same order.
36 template<class GeoField, class Mesh>
37 Foam::wordList Foam::ReadFields
40 const IOobjectList& objects,
41 PtrList<GeoField>& fields,
45 // Search list of objects for wanted type
46 IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName));
48 wordList masterNames(fieldObjects.names());
50 if (syncPar && Pstream::parRun())
52 // Check that I have the same fields as the master
53 const wordList localNames(masterNames);
54 Pstream::scatter(masterNames);
56 HashSet<word> localNamesSet(localNames);
58 forAll(masterNames, i)
60 const word& masterFld = masterNames[i];
62 HashSet<word>::iterator iter = localNamesSet.find(masterFld);
64 if (iter == localNamesSet.end())
68 "ReadFields<class GeoField, class Mesh>"
69 "(const Mesh&, const IOobjectList&, PtrList<GeoField>&"
71 ) << "Fields not synchronised across processors." << endl
72 << "Master has fields " << masterNames
73 << " processor " << Pstream::myProcNo()
74 << " has fields " << localNames << exit(FatalError);
78 localNamesSet.erase(iter);
82 forAllConstIter(HashSet<word>, localNamesSet, iter)
86 "ReadFields<class GeoField, class Mesh>"
87 "(const Mesh&, const IOobjectList&, PtrList<GeoField>&"
89 ) << "Fields not synchronised across processors." << endl
90 << "Master has fields " << masterNames
91 << " processor " << Pstream::myProcNo()
92 << " has fields " << localNames << exit(FatalError);
97 fields.setSize(masterNames.size());
99 // Make sure to read in masterNames order.
101 forAll(masterNames, i)
103 Info<< "Reading " << GeoField::typeName << ' ' << masterNames[i]
106 const IOobject& io = *fieldObjects[masterNames[i]];
120 IOobject::AUTO_WRITE,
131 // ************************************************************************* //