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

@ -62,14 +62,13 @@ Foam::fieldMinMax::fieldMinMax
const bool loadFromFiles
)
:
functionObjectFile(obr, name, typeName),
name_(name),
obr_(obr),
active_(true),
write_(true),
log_(false),
mode_(mdMag),
fieldSet_(),
fieldMinMaxFilePtr_(NULL)
fieldSet_()
{
// Check if the available mesh is an fvMesh otherise deactivate
if (!isA<fvMesh>(obr_))
@ -99,7 +98,6 @@ void Foam::fieldMinMax::read(const dictionary& dict)
{
if (active_)
{
write_ = dict.lookupOrDefault<Switch>("write", true);
log_ = dict.lookupOrDefault<Switch>("log", false);
mode_ = modeTypeNames_[dict.lookupOrDefault<word>("mode", "magnitude")];
@ -108,72 +106,25 @@ void Foam::fieldMinMax::read(const dictionary& dict)
}
void Foam::fieldMinMax::makeFile()
void Foam::fieldMinMax::writeFileHeader(const label i)
{
// Create the fieldMinMax file if not already created
if (fieldMinMaxFilePtr_.empty())
file()
<< "# Time" << token::TAB << "field" << token::TAB
<< "min" << token::TAB << "position(min)";
if (Pstream::parRun())
{
if (debug)
{
Info<< "Creating fieldMinMax file." << endl;
}
// File update
if (Pstream::master())
{
fileName fieldMinMaxDir;
if (Pstream::parRun())
{
// Put in undecomposed case (Note: gives problems for
// distributed data running)
fieldMinMaxDir =
obr_.time().path()/".."/name_/obr_.time().timeName();
}
else
{
fieldMinMaxDir =
obr_.time().path()/name_/obr_.time().timeName();
}
// Create directory if does not exist.
mkDir(fieldMinMaxDir);
// Open new file at start up
fieldMinMaxFilePtr_.reset
(
new OFstream(fieldMinMaxDir/(type() + ".dat"))
);
// Add headers to output data
writeFileHeader();
}
file() << token::TAB << "proc";
}
}
file() << token::TAB << "max" << token::TAB << "position(max)";
void Foam::fieldMinMax::writeFileHeader()
{
if (fieldMinMaxFilePtr_.valid())
if (Pstream::parRun())
{
fieldMinMaxFilePtr_()
<< "# Time" << token::TAB << "field" << token::TAB
<< "min" << token::TAB << "position(min)";
if (Pstream::parRun())
{
fieldMinMaxFilePtr_() << token::TAB << "proc";
}
fieldMinMaxFilePtr_()
<< token::TAB << "max" << token::TAB << "position(max)";
if (Pstream::parRun())
{
fieldMinMaxFilePtr_() << token::TAB << "proc";
}
fieldMinMaxFilePtr_() << endl;
file() << token::TAB << "proc";
}
file() << endl;
}
@ -193,11 +144,7 @@ void Foam::fieldMinMax::write()
{
if (active_)
{
// Create the fieldMinMax file if not already created
if (write_)
{
makeFile();
}
functionObjectFile::write();
if (log_)
{

View File

@ -76,6 +76,7 @@ SourceFiles
#ifndef fieldMinMax_H
#define fieldMinMax_H
#include "functionObjectFile.H"
#include "primitiveFieldsFwd.H"
#include "volFieldsFwd.H"
#include "HashSet.H"
@ -99,6 +100,8 @@ class mapPolyMesh;
\*---------------------------------------------------------------------------*/
class fieldMinMax
:
public functionObjectFile
{
public:
@ -115,8 +118,8 @@ protected:
//- Mode type names
static const NamedEnum<modeType, 2> modeTypeNames_;
//- Name of this set of field min/max.
// Also used as the name of the output directory.
//- Name of this set of field min/max
// Also used as the name of the output directory
word name_;
const objectRegistry& obr_;
@ -124,9 +127,6 @@ protected:
//- on/off switch
bool active_;
//- Switch to enable/disable writing to file
Switch write_;
//- Switch to send output to Info as well
Switch log_;
@ -136,15 +136,9 @@ protected:
//- Fields to assess min/max
wordList fieldSet_;
//- Min/max file ptr
autoPtr<OFstream> fieldMinMaxFilePtr_;
// Private Member Functions
//- If the output file has not been created create it
void makeFile();
//- Disallow default bitwise copy construct
fieldMinMax(const fieldMinMax&);
@ -152,7 +146,7 @@ protected:
void operator=(const fieldMinMax&);
//- Output file header information
virtual void writeFileHeader();
virtual void writeFileHeader(const label i);
public:

View File

@ -83,29 +83,25 @@ void Foam::fieldMinMax::calcMinMaxFields
scalar maxValue = maxVs[maxI];
const vector& maxC = maxCs[maxI];
if (write_)
file()
<< obr_.time().value() << token::TAB
<< fieldName << token::TAB
<< minValue << token::TAB << minC;
if (Pstream::parRun())
{
fieldMinMaxFilePtr_()
<< obr_.time().value() << token::TAB
<< fieldName << token::TAB
<< minValue << token::TAB << minC;
if (Pstream::parRun())
{
fieldMinMaxFilePtr_() << token::TAB << minI;
}
fieldMinMaxFilePtr_()
<< token::TAB << maxValue << token::TAB << maxC;
if (Pstream::parRun())
{
fieldMinMaxFilePtr_() << token::TAB << maxI;
}
fieldMinMaxFilePtr_() << endl;
file() << token::TAB << minI;
}
file() << token::TAB << maxValue << token::TAB << maxC;
if (Pstream::parRun())
{
file() << token::TAB << maxI;
}
file() << endl;
if (log_)
{
Info<< " min(mag(" << fieldName << ")) = "
@ -163,29 +159,25 @@ void Foam::fieldMinMax::calcMinMaxFields
Type maxValue = maxVs[maxI];
const vector& maxC = maxCs[maxI];
if (write_)
file()
<< obr_.time().value() << token::TAB
<< fieldName << token::TAB
<< minValue << token::TAB << minC;
if (Pstream::parRun())
{
fieldMinMaxFilePtr_()
<< obr_.time().value() << token::TAB
<< fieldName << token::TAB
<< minValue << token::TAB << minC;
if (Pstream::parRun())
{
fieldMinMaxFilePtr_() << token::TAB << minI;
}
fieldMinMaxFilePtr_()
<< token::TAB << maxValue << token::TAB << maxC;
if (Pstream::parRun())
{
fieldMinMaxFilePtr_() << token::TAB << maxI;
}
fieldMinMaxFilePtr_() << endl;
file() << token::TAB << minI;
}
file() << token::TAB << maxValue << token::TAB << maxC;
if (Pstream::parRun())
{
file() << token::TAB << maxI;
}
file() << endl;
if (log_)
{
Info<< " min(" << fieldName << ") = "