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;
writeJobInfo 0;
writeDictionaries 0;
// Allow case-supplied C++ code (#codeStream, codedFixedValue)
allowSystemOperations 0;

View File

@ -21,12 +21,6 @@ License
You should have received a copy of the GNU General Public License
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"
@ -37,84 +31,10 @@ Description
defineTypeNameAndDebug(Foam::IOdictionary, 0);
// * * * * * * * * * * * * * 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 (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);
}
}
}
bool Foam::IOdictionary::writeDictionaries
(
Foam::debug::infoSwitch("writeDictionaries", 0)
);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

View File

@ -25,10 +25,10 @@ Class
Foam::IOdictionary
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.
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.
SourceFiles
IOdictionary.C
@ -56,12 +56,17 @@ class IOdictionary
public regIOobject,
public dictionary
{
// Private data
static bool writeDictionaries;
// Private Member Functions
//- read dictionary from file
//- Read dictionary from file
void readFile(const bool);
public:
TypeName("dictionary");

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -21,21 +21,116 @@ License
You should have received a copy of the GNU General Public License
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 "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)
{
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();
}
@ -46,4 +141,5 @@ bool Foam::IOdictionary::writeData(Ostream& os) const
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)
{
time().setUnmodified(watchIndex_);
@ -173,7 +173,7 @@ bool Foam::regIOobject::read()
// Note: cannot do anything in readStream itself since this is used by
// e.g. GeometricField.
bool masterOnly =
bool masterOnly =
regIOobject::fileModificationChecking == timeStampMaster
|| regIOobject::fileModificationChecking == inotifyMaster;