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 "regIOobject.H"
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 Foam::Istream& Foam::regIOobject::readStream()
38 Info<< "regIOobject::readStream() : "
39 << "reading object " << name()
40 << " from file " << objectPath()
44 if (readOpt() == NO_READ)
46 FatalErrorIn("regIOobject::readStream()")
47 << "NO_READ specified for read-constructor of object " << name()
48 << " of class " << headerClassName()
52 // Construct object stream and read header if not already constructed
57 if (watchIndex_ != -1)
59 // File is being watched. Read exact file that is being watched.
60 objPath = time().getFile(watchIndex_);
64 // Search intelligently for file
71 "regIOobject::readStream()",
76 ) << "cannot find file"
77 << exit(FatalIOError);
81 if (!(isPtr_ = objectStream(objPath)))
85 "regIOobject::readStream()",
90 ) << "cannot open file"
91 << exit(FatalIOError);
93 else if (!readHeader(*isPtr_))
95 FatalIOErrorIn("regIOobject::readStream()", *isPtr_)
96 << "problem while reading header for object " << name()
97 << exit(FatalIOError);
101 // Mark as uptodate if read succesfully
102 if (watchIndex_ != -1)
104 time().setUnmodified(watchIndex_);
111 Foam::Istream& Foam::regIOobject::readStream(const word& expectName)
115 Info<< "regIOobject::readStream(const word&) : "
116 << "reading object " << name()
117 << " from file " << objectPath()
121 // Construct IFstream if not already constructed
126 // Check the className of the regIOobject
127 // dictionary is an allowable name in case the actual class
128 // instantiated is a dictionary
132 && headerClassName() != expectName
133 && headerClassName() != "dictionary"
136 FatalIOErrorIn("regIOobject::readStream(const word&)", *isPtr_)
137 << "unexpected class name " << headerClassName()
138 << " expected " << expectName << endl
139 << " while reading object " << name()
140 << exit(FatalIOError);
148 void Foam::regIOobject::close()
152 Info<< "regIOobject::close() : "
153 << "finished reading " << filePath()
165 bool Foam::regIOobject::readData(Istream&)
171 bool Foam::regIOobject::read()
173 // Note: cannot do anything in readStream itself since this is used by
174 // e.g. GeometricField.
177 regIOobject::fileModificationChecking == timeStampMaster
178 || regIOobject::fileModificationChecking == inotifyMaster;
181 if (Pstream::master() || !masterOnly)
185 Pout<< "regIOobject::read() : "
186 << "reading object " << name()
187 << " from file " << endl;
189 ok = readData(readStream(type()));
193 if (masterOnly && Pstream::parRun())
195 // Scatter master data using communication scheme
197 const List<Pstream::commsStruct>& comms =
199 (Pstream::nProcs() < Pstream::nProcsSimpleSum)
200 ? Pstream::linearCommunication()
201 : Pstream::treeCommunication()
204 // Master reads headerclassname from file. Make sure this gets
205 // transfered as well as contents.
206 Pstream::scatter(comms, const_cast<word&>(headerClassName()));
207 Pstream::scatter(comms, note());
210 // Get my communication order
211 const Pstream::commsStruct& myComm = comms[Pstream::myProcNo()];
214 if (myComm.above() != -1)
218 Pout<< "regIOobject::read() : "
219 << "reading object " << name()
220 << " from processor " << myComm.above()
224 // Note: use ASCII for now - binary IO of dictionaries is
225 // not currently supported
233 ok = readData(fromAbove);
236 // Send to my downstairs neighbours
237 forAll(myComm.below(), belowI)
242 myComm.below()[belowI],
254 bool Foam::regIOobject::modified() const
256 if (watchIndex_ != -1)
258 return time().getState(watchIndex_) != fileMonitor::UNMODIFIED;
267 bool Foam::regIOobject::readIfModified()
269 if (watchIndex_ != -1)
273 const fileName& fName = time().getFile(watchIndex_);
274 Info<< "regIOobject::readIfModified() : " << nl
275 << " Re-reading object " << name()
276 << " from file " << fName << endl;
291 // ************************************************************************* //