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 << ") = "

View File

@ -153,24 +153,21 @@ void Foam::fieldValues::cellSource::initialise(const dictionary& dict)
}
void Foam::fieldValues::cellSource::writeFileHeader()
void Foam::fieldValues::cellSource::writeFileHeader(const label i)
{
if (outputFilePtr_.valid())
file()
<< "# Source : " << sourceTypeNames_[source_] << " "
<< sourceName_ << nl << "# Cells : " << nCells_ << nl
<< "# Time" << tab << "sum(V)";
forAll(fields_, i)
{
outputFilePtr_()
<< "# Source : " << sourceTypeNames_[source_] << " "
<< sourceName_ << nl << "# Cells : " << nCells_ << nl
<< "# Time" << tab << "sum(V)";
forAll(fields_, i)
{
outputFilePtr_()
<< tab << operationTypeNames_[operation_]
<< "(" << fields_[i] << ")";
}
outputFilePtr_() << endl;
file()
<< tab << operationTypeNames_[operation_]
<< "(" << fields_[i] << ")";
}
file() << endl;
}
@ -184,7 +181,7 @@ Foam::fieldValues::cellSource::cellSource
const bool loadFromFiles
)
:
fieldValue(name, obr, dict, loadFromFiles),
fieldValue(name, obr, dict, typeName, loadFromFiles),
source_(sourceTypeNames_.read(dict.lookup("source"))),
operation_(operationTypeNames_.read(dict.lookup("operation"))),
nCells_(0),
@ -223,7 +220,7 @@ void Foam::fieldValues::cellSource::write()
scalar totalVolume = gSum(filterField(mesh().V()));
if (Pstream::master())
{
outputFilePtr_() << obr_.time().value() << tab << totalVolume;
file() << obr_.time().value() << tab << totalVolume;
}
forAll(fields_, i)
@ -237,7 +234,7 @@ void Foam::fieldValues::cellSource::write()
if (Pstream::master())
{
outputFilePtr_()<< endl;
file()<< endl;
}
if (log_)

View File

@ -214,7 +214,7 @@ protected:
) const;
//- Output file header information
virtual void writeFileHeader();
virtual void writeFileHeader(const label i);
public:

View File

@ -195,7 +195,7 @@ bool Foam::fieldValues::cellSource::writeValues(const word& fieldName)
}
outputFilePtr_()<< tab << result;
file()<< tab << result;
if (log_)
{

View File

@ -472,24 +472,21 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
}
void Foam::fieldValues::faceSource::writeFileHeader()
void Foam::fieldValues::faceSource::writeFileHeader(const label i)
{
if (outputFilePtr_.valid())
file()
<< "# Source : " << sourceTypeNames_[source_] << " "
<< sourceName_ << nl << "# Faces : " << nFaces_ << nl
<< "# Time" << tab << "sum(magSf)";
forAll(fields_, i)
{
outputFilePtr_()
<< "# Source : " << sourceTypeNames_[source_] << " "
<< sourceName_ << nl << "# Faces : " << nFaces_ << nl
<< "# Time" << tab << "sum(magSf)";
forAll(fields_, i)
{
outputFilePtr_()
<< tab << operationTypeNames_[operation_]
<< "(" << fields_[i] << ")";
}
outputFilePtr_() << endl;
file()
<< tab << operationTypeNames_[operation_]
<< "(" << fields_[i] << ")";
}
file() << endl;
}
@ -532,7 +529,7 @@ Foam::fieldValues::faceSource::faceSource
const bool loadFromFiles
)
:
fieldValue(name, obr, dict, loadFromFiles),
fieldValue(name, obr, dict, typeName, loadFromFiles),
surfaceWriterPtr_(NULL),
source_(sourceTypeNames_.read(dict.lookup("source"))),
operation_(operationTypeNames_.read(dict.lookup("operation"))),
@ -586,7 +583,7 @@ void Foam::fieldValues::faceSource::write()
if (Pstream::master())
{
outputFilePtr_() << obr_.time().value() << tab << totalArea;
file() << obr_.time().value() << tab << totalArea;
}
forAll(fields_, i)
@ -600,7 +597,7 @@ void Foam::fieldValues::faceSource::write()
if (Pstream::master())
{
outputFilePtr_()<< endl;
file()<< endl;
}
if (log_)

View File

@ -296,7 +296,7 @@ protected:
) const;
//- Output file header information
virtual void writeFileHeader();
virtual void writeFileHeader(const label i);
public:

View File

@ -269,19 +269,8 @@ bool Foam::fieldValues::faceSource::writeValues(const word& fieldName)
combineMeshGeometry(faces, points);
}
fileName outputDir;
if (Pstream::parRun())
{
// Put in undecomposed case (Note: gives problems for
// distributed data running)
outputDir = obr_.time().path()/".."/name_;
}
else
{
outputDir = obr_.time().path()/name_;
}
outputDir = outputDir/"surface"/obr_.time().timeName();
fileName outputDir =
baseFileDir()/name_/"surface"/obr_.time().timeName();
surfaceWriterPtr_->write
(
@ -302,7 +291,7 @@ bool Foam::fieldValues::faceSource::writeValues(const word& fieldName)
{
Type result = processValues(values, Sf, weightField);
outputFilePtr_()<< tab << result;
file()<< tab << result;
if (log_)
{

View File

@ -49,48 +49,6 @@ void Foam::fieldValue::movePoints(const Field<point>&)
}
void Foam::fieldValue::makeFile()
{
// Create the output file if not already created
if (outputFilePtr_.empty())
{
if (debug)
{
Info<< "Creating output file." << endl;
}
// File update
if (Pstream::master())
{
fileName outputDir;
word startTimeName =
obr_.time().timeName(obr_.time().startTime().value());
if (Pstream::parRun())
{
// Put in undecomposed case (Note: gives problems for
// distributed data running)
outputDir =
obr_.time().path()/".."/name_/startTimeName;
}
else
{
outputDir = obr_.time().path()/name_/startTimeName;
}
// Create directory if does not exist
mkDir(outputDir);
// Open new file at start up
outputFilePtr_.reset(new OFstream(outputDir/(type() + ".dat")));
// Add headers to output data
writeFileHeader();
}
}
}
void Foam::fieldValue::read(const dictionary& dict)
{
if (active_)
@ -106,12 +64,12 @@ void Foam::fieldValue::write()
{
if (active_)
{
functionObjectFile::write();
if (log_)
{
Info<< type() << " " << name_ << " output:" << nl;
}
makeFile();
}
}
@ -123,17 +81,18 @@ Foam::fieldValue::fieldValue
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const word& valueType,
const bool loadFromFiles
)
:
functionObjectFile(obr, name, valueType),
name_(name),
obr_(obr),
active_(true),
log_(false),
sourceName_(dict.lookupOrDefault<word>("sourceName", "sampledSurface")),
fields_(dict.lookup("fields")),
valueOutput_(dict.lookup("valueOutput")),
outputFilePtr_(NULL)
valueOutput_(dict.lookup("valueOutput"))
{
// Only active if obr is an fvMesh
if (isA<fvMesh>(obr_))

View File

@ -38,6 +38,7 @@ SourceFiles
#ifndef fieldValue_H
#define fieldValue_H
#include "functionObjectFile.H"
#include "Switch.H"
#include "pointFieldFwd.H"
#include "OFstream.H"
@ -58,6 +59,8 @@ class mapPolyMesh;
\*---------------------------------------------------------------------------*/
class fieldValue
:
public functionObjectFile
{
protected:
@ -85,18 +88,9 @@ protected:
//- Output field values flag
Switch valueOutput_;
//- Output file pointer
autoPtr<OFstream> outputFilePtr_;
// Functions to be over-ridden from IOoutputFilter class
//- Make the output file
virtual void makeFile();
//- Write the output file header
virtual void writeFileHeader() = 0;
//- Update mesh
virtual void updateMesh(const mapPolyMesh&);
@ -116,6 +110,7 @@ public:
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const word& valueType,
const bool loadFromFiles = false
);

View File

@ -69,26 +69,19 @@ void Foam::regionSizeDistribution::writeGraph
const wordList valNames(1, valueName);
fileName outputPath;
if (Pstream::parRun())
{
outputPath = mesh.time().path()/".."/name_;
}
else
{
outputPath = mesh.time().path()/name_;
}
fileName outputPath = baseFileDir()/name_;
if (mesh.name() != fvMesh::defaultRegion)
{
outputPath = outputPath/mesh.name();
}
mkDir(outputPath/mesh.time().timeName());
outputPath = outputPath/mesh.time().timeName();
mkDir(outputPath);
OFstream str
(
outputPath
/ mesh.time().timeName()
/ formatterPtr_().getFileName(coords, valNames)
);
Info<< "Writing distribution of " << valueName << " to " << str.name()
@ -341,6 +334,7 @@ Foam::regionSizeDistribution::regionSizeDistribution
const bool loadFromFiles
)
:
functionObjectFile(obr, name, typeName),
name_(name),
obr_(obr),
active_(true),

View File

@ -98,6 +98,7 @@ SourceFiles
#ifndef regionSizeDistribution_H
#define regionSizeDistribution_H
#include "functionObjectFile.H"
#include "pointFieldFwd.H"
#include "writer.H"
#include "Map.H"
@ -121,6 +122,8 @@ class polyMesh;
\*---------------------------------------------------------------------------*/
class regionSizeDistribution
:
public functionObjectFile
{
// Private data