Added support to writing dictionaries to log on read and re-read.

This commit is contained in:
Henry
2011-07-20 14:27:02 +01:00
parent 6b92b781b6
commit 3ba236115d
5 changed files with 121 additions and 99 deletions

View File

@ -37,6 +37,7 @@ InfoSwitches
{ {
writePrecision 6; writePrecision 6;
writeJobInfo 0; writeJobInfo 0;
writeDictionaries 0;
// Allow case-supplied C++ code (#codeStream, codedFixedValue) // Allow case-supplied C++ code (#codeStream, codedFixedValue)
allowSystemOperations 0; allowSystemOperations 0;

View File

@ -21,12 +21,6 @@ License
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
IOdictionary is derived from dictionary and IOobject to give the
dictionary automatic IO functionality via the objectRegistry. To facilitate
IO, IOdictioanry is provided with a constructor from IOobject and writeData
and write functions.
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "IOdictionary.H" #include "IOdictionary.H"
@ -37,84 +31,10 @@ Description
defineTypeNameAndDebug(Foam::IOdictionary, 0); defineTypeNameAndDebug(Foam::IOdictionary, 0);
bool Foam::IOdictionary::writeDictionaries
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // (
Foam::debug::infoSwitch("writeDictionaries", 0)
// Parallel aware reading, using non-virtual type information (typeName instead );
// of type()) because of use in constructor.
void Foam::IOdictionary::readFile(const bool masterOnly)
{
if (Pstream::master() || !masterOnly)
{
if (debug)
{
Pout<< "IOdictionary : Reading " << objectPath()
<< " from file " << endl;
}
readStream(typeName) >> *this;
close();
}
if (masterOnly && Pstream::parRun())
{
// Scatter master data using communication scheme
const List<Pstream::commsStruct>& comms =
(
(Pstream::nProcs() < Pstream::nProcsSimpleSum)
? Pstream::linearCommunication()
: Pstream::treeCommunication()
);
// Master reads headerclassname from file. Make sure this gets
// transfered as well as contents.
Pstream::scatter(comms, const_cast<word&>(headerClassName()));
Pstream::scatter(comms, note());
// Get my communication order
const Pstream::commsStruct& myComm = comms[Pstream::myProcNo()];
// Reveive from up
if (myComm.above() != -1)
{
if (debug)
{
Pout<< "IOdictionary : Reading " << objectPath()
<< " from processor " << myComm.above() << endl;
}
// Note: use ASCII for now - binary IO of dictionaries is
// not currently supported
IPstream fromAbove
(
Pstream::scheduled,
myComm.above(),
0,
IOstream::ASCII
);
IOdictionary::readData(fromAbove);
}
// Send to my downstairs neighbours
forAll(myComm.below(), belowI)
{
if (debug)
{
Pout<< "IOdictionary : Sending " << objectPath()
<< " to processor " << myComm.below()[belowI] << endl;
}
OPstream toBelow
(
Pstream::scheduled,
myComm.below()[belowI],
0,
Pstream::msgType(),
IOstream::ASCII
);
IOdictionary::writeData(toBelow);
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

View File

@ -25,10 +25,10 @@ Class
Foam::IOdictionary Foam::IOdictionary
Description Description
IOdictionary is derived from dictionary and IOobject to give the IOdictionary is derived from dictionary and IOobject to give the dictionary
dictionary automatic IO functionality via the objectRegistry. To facilitate automatic IO functionality via the objectRegistry. To facilitate IO,
IO, IOdictioanry is provided with a constructor from IOobject and writeData IOdictioanry is provided with a constructor from IOobject and writeData and
and write functions. write functions.
SourceFiles SourceFiles
IOdictionary.C IOdictionary.C
@ -56,12 +56,17 @@ class IOdictionary
public regIOobject, public regIOobject,
public dictionary public dictionary
{ {
// Private data
static bool writeDictionaries;
// Private Member Functions // Private Member Functions
//- read dictionary from file //- Read dictionary from file
void readFile(const bool); void readFile(const bool);
public: public:
TypeName("dictionary"); TypeName("dictionary");

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -21,21 +21,116 @@ License
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
IOdictionary is derived from dictionary and IOobject to give the
dictionary automatic IO functionality via the objectRegistry. To facilitate
IO, IOdictioanry is provided with a constructor from IOobject and writeData
and write functions.
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "IOdictionary.H" #include "IOdictionary.H"
#include "Pstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// Parallel aware reading, using non-virtual type information (typeName instead
// of type()) because of use in constructor.
void Foam::IOdictionary::readFile(const bool masterOnly)
{
if (Pstream::master() || !masterOnly)
{
if (debug)
{
Pout<< "IOdictionary : Reading " << objectPath()
<< " from file " << endl;
}
readStream(typeName) >> *this;
close();
if (writeDictionaries && Pstream::master())
{
Sout<< nl
<< "--- IOdictionary " << name()
<< ' ' << objectPath() << ":" << nl;
writeHeader(Sout);
writeData(Sout);
Sout<< "--- End of IOdictionary " << name() << nl << endl;
}
}
if (masterOnly && Pstream::parRun())
{
// Scatter master data using communication scheme
const List<Pstream::commsStruct>& comms =
(
(Pstream::nProcs() < Pstream::nProcsSimpleSum)
? Pstream::linearCommunication()
: Pstream::treeCommunication()
);
// Master reads headerclassname from file. Make sure this gets
// transfered as well as contents.
Pstream::scatter(comms, const_cast<word&>(headerClassName()));
Pstream::scatter(comms, note());
// Get my communication order
const Pstream::commsStruct& myComm = comms[Pstream::myProcNo()];
// Reveive from up
if (myComm.above() != -1)
{
if (debug)
{
Pout<< "IOdictionary : Reading " << objectPath()
<< " from processor " << myComm.above() << endl;
}
// Note: use ASCII for now - binary IO of dictionaries is
// not currently supported
IPstream fromAbove
(
Pstream::scheduled,
myComm.above(),
0,
IOstream::ASCII
);
IOdictionary::readData(fromAbove);
}
// Send to my downstairs neighbours
forAll(myComm.below(), belowI)
{
if (debug)
{
Pout<< "IOdictionary : Sending " << objectPath()
<< " to processor " << myComm.below()[belowI] << endl;
}
OPstream toBelow
(
Pstream::scheduled,
myComm.below()[belowI],
0,
Pstream::msgType(),
IOstream::ASCII
);
IOdictionary::writeData(toBelow);
}
}
}
// * * * * * * * * * * * * * * * Members Functions * * * * * * * * * * * * * //
bool Foam::IOdictionary::readData(Istream& is) bool Foam::IOdictionary::readData(Istream& is)
{ {
is >> *this; is >> *this;
if (writeDictionaries && Pstream::master() && !is.bad())
{
Sout<< nl
<< "--- IOdictionary " << name()
<< ' ' << objectPath() << ":" << nl;
writeHeader(Sout);
writeData(Sout);
Sout<< "--- End of IOdictionary " << name() << nl << endl;
}
return !is.bad(); return !is.bad();
} }
@ -46,4 +141,5 @@ bool Foam::IOdictionary::writeData(Ostream& os) const
return os.good(); return os.good();
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -98,7 +98,7 @@ Foam::Istream& Foam::regIOobject::readStream()
} }
} }
// Mark as uptodate if read succesfully // Mark as uptodate if read successfully
if (watchIndex_ != -1) if (watchIndex_ != -1)
{ {
time().setUnmodified(watchIndex_); time().setUnmodified(watchIndex_);
@ -173,7 +173,7 @@ bool Foam::regIOobject::read()
// Note: cannot do anything in readStream itself since this is used by // Note: cannot do anything in readStream itself since this is used by
// e.g. GeometricField. // e.g. GeometricField.
bool masterOnly = bool masterOnly =
regIOobject::fileModificationChecking == timeStampMaster regIOobject::fileModificationChecking == timeStampMaster
|| regIOobject::fileModificationChecking == inotifyMaster; || regIOobject::fileModificationChecking == inotifyMaster;