ENH: Refactored function objects to make use of new base class

This commit is contained in:
andy
2012-10-15 17:59:38 +01:00
parent d8321469e9
commit 72d49281ce
27 changed files with 225 additions and 612 deletions

View File

@ -34,53 +34,9 @@ defineTypeNameAndDebug(Foam::cloudInfo, 0);
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::cloudInfo::makeFiles()
void Foam::cloudInfo::writeFileHeader(const label i)
{
if (debug)
{
Info<< "Creating cloudInfo output files." << endl;
}
outputFilePtr_.clear();
outputFilePtr_.setSize(cloudSet_.size());
if (Pstream::master())
{
label i = 0;
forAllConstIter(wordHashSet, cloudSet_, iter)
{
const word& cloudName = iter.key();
fileName cloudInfoDir(obr_.time().path());
word timeName = Foam::name(obr_.time().startTime().value());
if (Pstream::parRun())
{
// Put in undecomposed case (Note: gives problems for
// distributed data running)
cloudInfoDir = cloudInfoDir/".."/name_/timeName;
}
else
{
cloudInfoDir = cloudInfoDir/name_/timeName;
}
// Create directory if does not exist
mkDir(cloudInfoDir);
// Open new files at start up
outputFilePtr_.set
(
i,
new OFstream(cloudInfoDir/(cloudName + ".dat"))
);
// Add headers
outputFilePtr_[i]
<< "# Time" << tab << "nParcels" << tab << "mass" << endl;
i++;
}
}
file(i) << "# Time" << tab << "nParcels" << tab << "mass" << endl;
}
@ -94,11 +50,10 @@ Foam::cloudInfo::cloudInfo
const bool loadFromFiles
)
:
functionObjectFile(obr, name),
name_(name),
obr_(obr),
active_(true),
cloudSet_(),
outputFilePtr_()
active_(true)
{
read(dict);
}
@ -116,19 +71,17 @@ void Foam::cloudInfo::read(const dictionary& dict)
{
if (active_)
{
cloudSet_.insert(wordList(dict.lookup("clouds")));
functionObjectFile::resetNames(dict.lookup("clouds"));
Info<< type() << ": ";
if (cloudSet_.size())
if (names_.size())
{
Info<< "applying to clouds:" << nl;
forAllConstIter(wordHashSet, cloudSet_, iter)
forAllConstIter(wordHashSet, names_, iter)
{
Info<< " " << iter.key() << nl;
}
Info<< endl;
makeFiles();
}
else
{
@ -154,8 +107,10 @@ void Foam::cloudInfo::write()
{
if (active_)
{
functionObjectFile::write();
label i = 0;
forAllConstIter(wordHashSet, cloudSet_, iter)
forAllConstIter(wordHashSet, names_, iter)
{
const word& cloudName = iter.key();
@ -168,7 +123,7 @@ void Foam::cloudInfo::write()
if (Pstream::master())
{
outputFilePtr_[i]
file(i)
<< obr_.time().value() << token::TAB
<< nParcels << token::TAB
<< massInSystem << endl;

View File

@ -72,7 +72,7 @@ SourceFiles
#ifndef cloudInfo_H
#define cloudInfo_H
#include "OFstream.H"
#include "functionObjectFile.H"
#include "PtrList.H"
#include "pointFieldFwd.H"
#include "volFields.H"
@ -93,6 +93,8 @@ class mapPolyMesh;
\*---------------------------------------------------------------------------*/
class cloudInfo
:
public functionObjectFile
{
protected:
@ -101,22 +103,17 @@ protected:
//- Name of this set of cloudInfo object
word name_;
//- Reference to the database
const objectRegistry& obr_;
//- on/off switch
bool active_;
//- Clouds to process
wordHashSet cloudSet_;
//- Output file pointers
PtrList<OFstream> outputFilePtr_;
// Protected Member Functions
//- If the output file has not been created create it
void makeFiles();
//- File header information
virtual void writeFileHeader(const label i);
//- Disallow default bitwise copy construct
cloudInfo(const cloudInfo&);