mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Refactored function objects to make use of new base class
This commit is contained in:
@ -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_)
|
||||
|
||||
@ -214,7 +214,7 @@ protected:
|
||||
) const;
|
||||
|
||||
//- Output file header information
|
||||
virtual void writeFileHeader();
|
||||
virtual void writeFileHeader(const label i);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
@ -195,7 +195,7 @@ bool Foam::fieldValues::cellSource::writeValues(const word& fieldName)
|
||||
}
|
||||
|
||||
|
||||
outputFilePtr_()<< tab << result;
|
||||
file()<< tab << result;
|
||||
|
||||
if (log_)
|
||||
{
|
||||
|
||||
@ -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_)
|
||||
|
||||
@ -296,7 +296,7 @@ protected:
|
||||
) const;
|
||||
|
||||
//- Output file header information
|
||||
virtual void writeFileHeader();
|
||||
virtual void writeFileHeader(const label i);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
@ -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_)
|
||||
{
|
||||
|
||||
@ -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_))
|
||||
|
||||
@ -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
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user