Commit 4a301e94 authored by Henry Weller's avatar Henry Weller
Browse files

functionObjects: Separated writeFile and logFiles (previously writeFiles) from regionFunctionObject

Now the functionality to write single graph files or log files (vs time)
may be used in the creation of any form of functionObject, not just
those relating to a mesh region.
parent 65207e29
......@@ -81,7 +81,6 @@ See also
#include "noiseFFT.H"
#include "argList.H"
#include "Time.H"
#include "writeFiles.H"
#include "CSV.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -222,7 +222,7 @@ $(dll)/codedBase/codedBase.C
db/functionObjects/functionObject/functionObject.C
db/functionObjects/functionObjectList/functionObjectList.C
db/functionObjects/writeFile/writeFile.C
db/functionObjects/writeFiles/writeFiles.C
db/functionObjects/logFiles/logFiles.C
db/functionObjects/timeControl/timeControl.C
db/functionObjects/timeControl/timeControlFunctionObject.C
db/functionObjects/regionFunctionObject/regionFunctionObject.C
......
......@@ -23,18 +23,18 @@ License
\*---------------------------------------------------------------------------*/
#include "writeFiles.H"
#include "logFiles.H"
#include "Time.H"
#include "IFstream.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::functionObjects::writeFiles::createFiles()
void Foam::functionObjects::logFiles::createFiles()
{
if (Pstream::master())
{
const word startTimeName =
obr_.time().timeName(obr_.time().startTime().value());
fileObr_.time().timeName(fileObr_.time().startTime().value());
forAll(names_, i)
{
......@@ -49,7 +49,7 @@ void Foam::functionObjects::writeFiles::createFiles()
IFstream is(outputDir/(fName + ".dat"));
if (is.good())
{
fName = fName + "_" + obr_.time().timeName();
fName = fName + "_" + fileObr_.time().timeName();
}
filePtrs_.set(i, new OFstream(outputDir/(fName + ".dat")));
......@@ -57,14 +57,13 @@ void Foam::functionObjects::writeFiles::createFiles()
initStream(filePtrs_[i]);
writeFileHeader(i);
}
}
}
}
void Foam::functionObjects::writeFiles::resetNames(const wordList& names)
void Foam::functionObjects::logFiles::resetNames(const wordList& names)
{
names_.clear();
names_.append(names);
......@@ -77,7 +76,7 @@ void Foam::functionObjects::writeFiles::resetNames(const wordList& names)
}
void Foam::functionObjects::writeFiles::resetName(const word& name)
void Foam::functionObjects::logFiles::resetName(const word& name)
{
names_.clear();
names_.append(name);
......@@ -92,29 +91,13 @@ void Foam::functionObjects::writeFiles::resetName(const word& name)
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::writeFiles::writeFiles
(
const word& name,
const Time& time,
const dictionary& dict,
const word& prefix
)
:
writeFile(name, time, dict, prefix),
names_(),
filePtrs_()
{}
Foam::functionObjects::writeFiles::writeFiles
Foam::functionObjects::logFiles::logFiles
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const word& prefix
)
:
writeFile(name, obr, dict, prefix),
writeFile(obr, prefix),
names_(),
filePtrs_()
{}
......@@ -122,19 +105,19 @@ Foam::functionObjects::writeFiles::writeFiles
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::writeFiles::~writeFiles()
Foam::functionObjects::logFiles::~logFiles()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::wordList& Foam::functionObjects::writeFiles::names() const
const Foam::wordList& Foam::functionObjects::logFiles::names() const
{
return names_;
}
Foam::OFstream& Foam::functionObjects::writeFiles::file()
Foam::OFstream& Foam::functionObjects::logFiles::file()
{
if (!Pstream::master())
{
......@@ -161,7 +144,7 @@ Foam::OFstream& Foam::functionObjects::writeFiles::file()
}
Foam::PtrList<Foam::OFstream>& Foam::functionObjects::writeFiles::files()
Foam::PtrList<Foam::OFstream>& Foam::functionObjects::logFiles::files()
{
if (!Pstream::master())
{
......@@ -174,7 +157,7 @@ Foam::PtrList<Foam::OFstream>& Foam::functionObjects::writeFiles::files()
}
Foam::OFstream& Foam::functionObjects::writeFiles::file(const label i)
Foam::OFstream& Foam::functionObjects::logFiles::file(const label i)
{
if (!Pstream::master())
{
......@@ -194,7 +177,7 @@ Foam::OFstream& Foam::functionObjects::writeFiles::file(const label i)
}
bool Foam::functionObjects::writeFiles::write()
bool Foam::functionObjects::logFiles::write()
{
createFiles();
......
......@@ -22,22 +22,23 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::functionObjects::writeFiles
Foam::functionObjects::logFiles
Description
functionObject base class for writing files
functionObject base class for creating, maintaining and writing log
files e.g. integrated of averaged field data vs time.
See also
Foam::functionObject
Foam::OutputFilterFunctionObject
Foam::functionObjects::writeFile
SourceFiles
functionObjectFiles.C
logFiles.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_writeFiles_H
#define functionObjects_writeFiles_H
#ifndef functionObjects_logFiles_H
#define functionObjects_logFiles_H
#include "writeFile.H"
#include "OFstream.H"
......@@ -51,14 +52,17 @@ namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class writeFiles Declaration
Class logFiles Declaration
\*---------------------------------------------------------------------------*/
class writeFiles
class logFiles
:
public writeFile
{
// Private data
protected:
// Protected data
//- File names
wordList names_;
......@@ -67,8 +71,6 @@ class writeFiles
PtrList<OFstream> filePtrs_;
protected:
// Protected Member Functions
//- Create the output file
......@@ -80,38 +82,35 @@ protected:
//- Reset the list of names to a single name entry
virtual void resetName(const word& name);
//- File header information
virtual void writeFileHeader(const label i = 0) = 0;
private:
// Private Member Functions
//- Disallow default bitwise copy construct
writeFiles(const writeFiles&);
logFiles(const logFiles&);
//- Disallow default bitwise assignment
void operator=(const writeFiles&);
void operator=(const logFiles&);
public:
// Constructors
//- Construct from name, Time, dictionary and prefix
writeFiles
//- Construct from objectRegistry and prefix
logFiles
(
const word& name,
const Time& time,
const dictionary& dict,
const word& prefix
);
//- Construct from name, objectRegistry, dictionary and prefix
writeFiles
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const word& prefix
);
//- Destructor
virtual ~writeFiles();
virtual ~logFiles();
// Member Functions
......@@ -119,12 +118,12 @@ public:
//- Return const access to the names
const wordList& names() const;
//- Return access to the file (if only 1)
OFstream& file();
//- Return access to the files
PtrList<OFstream>& files();
//- Return access to the file (if only 1)
OFstream& file();
//- Return file 'i'
OFstream& file(const label i);
......
......@@ -26,7 +26,6 @@ License
#include "writeFile.H"
#include "Time.H"
#include "polyMesh.H"
#include "IOmanip.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -49,7 +48,7 @@ void Foam::functionObjects::writeFile::initStream(Ostream& os) const
Foam::fileName Foam::functionObjects::writeFile::baseFileDir() const
{
fileName baseDir = obr_.time().path();
fileName baseDir = fileObr_.time().path();
if (Pstream::parRun())
{
......@@ -63,9 +62,9 @@ Foam::fileName Foam::functionObjects::writeFile::baseFileDir() const
}
// Append mesh name if not default region
if (isA<polyMesh>(obr_))
if (isA<polyMesh>(fileObr_))
{
const polyMesh& mesh = refCast<const polyMesh>(obr_);
const polyMesh& mesh = refCast<const polyMesh>(fileObr_);
if (mesh.name() != polyMesh::defaultRegion)
{
baseDir = baseDir/mesh.name();
......@@ -78,14 +77,10 @@ Foam::fileName Foam::functionObjects::writeFile::baseFileDir() const
Foam::fileName Foam::functionObjects::writeFile::baseTimeDir() const
{
return baseFileDir()/prefix_/obr_.time().timeName();
return baseFileDir()/prefix_/fileObr_.time().timeName();
}
void Foam::functionObjects::writeFile::writeFileHeader(const label i)
{}
Foam::Omanip<int> Foam::functionObjects::writeFile::valueWidth
(
const label offset
......@@ -99,26 +94,11 @@ Foam::Omanip<int> Foam::functionObjects::writeFile::valueWidth
Foam::functionObjects::writeFile::writeFile
(
const word& name,
const Time& runTime,
const dictionary& dict,
const word& prefix
)
:
regionFunctionObject(name, runTime, dict),
prefix_(prefix)
{}
Foam::functionObjects::writeFile::writeFile
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const word& prefix
)
:
regionFunctionObject(name, obr, dict),
fileObr_(obr),
prefix_(prefix)
{}
......@@ -171,7 +151,7 @@ void Foam::functionObjects::writeFile::writeHeader
void Foam::functionObjects::writeFile::writeTime(Ostream& os) const
{
os << setw(charWidth()) << obr_.time().timeName();
os << setw(charWidth()) << fileObr_.time().timeName();
}
......
......@@ -28,19 +28,18 @@ Description
functionObject base class for writing single files
See also
Foam::regionFunctionObject
Foam::functionObject
Foam::functionObjects::logFiles
SourceFiles
functionObjectFile.C
writeFile.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_writeFile_H
#define functionObjects_writeFile_H
#include "regionFunctionObject.H"
#include "Time.H"
#include "objectRegistry.H"
#include "IOmanip.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -55,34 +54,22 @@ namespace functionObjects
\*---------------------------------------------------------------------------*/
class writeFile
:
public regionFunctionObject
{
protected:
// Protected data
//- Reference to the region objectRegistry
const objectRegistry& fileObr_;
//- Prefix
const word prefix_;
// Protected Member Functions
//- Initialise the output stream for writing
virtual void initStream(Ostream& os) const;
//- Return the base directory for output
virtual fileName baseFileDir() const;
private:
//- Return the base directory for the current time value
virtual fileName baseTimeDir() const;
//- File header information
virtual void writeFileHeader(const label i = 0);
//- Return the value width when writing to stream with optional offset
virtual Omanip<int> valueWidth(const label offset = 0) const;
// Private Member Functions
//- Disallow default bitwise copy construct
writeFile(const writeFile&);
......@@ -102,31 +89,32 @@ public:
// Constructors
//- Construct from name, Time, dictionary and prefix
writeFile
(
const word& name,
const Time& t,
const dictionary& dict,
const word& prefix
);
//- Construct from name, objectRegistry, dictionary and prefix
//- Construct from objectRegistry and prefix
writeFile
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const word& prefix
);
//- Destructor
virtual ~writeFile();
~writeFile();
// Member Functions
//- Initialise the output stream for writing
void initStream(Ostream& os) const;
//- Return the base directory for output
fileName baseFileDir() const;
//- Return the base directory for the current time value
fileName baseTimeDir() const;
//- Return the value width when writing to stream with optional offset
Omanip<int> valueWidth(const label offset = 0) const;
//- Write a commented string to stream
void writeCommented(Ostream& os, const string& str) const;
......
......@@ -103,7 +103,8 @@ Foam::functionObjects::fieldMinMax::fieldMinMax
const dictionary& dict
)
:
writeFiles(name, runTime, dict, name),
regionFunctionObject(name, runTime, dict),
logFiles(obr_, name),
location_(true),
mode_(mdMag),
fieldSet_()
......@@ -129,7 +130,7 @@ Foam::functionObjects::fieldMinMax::~fieldMinMax()
bool Foam::functionObjects::fieldMinMax::read(const dictionary& dict)
{
writeFiles::read(dict);
regionFunctionObject::read(dict);
location_ = dict.lookupOrDefault<Switch>("location", true);
......@@ -148,7 +149,7 @@ bool Foam::functionObjects::fieldMinMax::execute()
bool Foam::functionObjects::fieldMinMax::write()
{
writeFiles::write();
logFiles::write();
if (!location_) writeTime(file());
Log << type() << " " << name() << " write:" << nl;
......
......@@ -67,8 +67,8 @@ Usage
Output data is written to the file \<timeDir\>/fieldMinMax.dat
See also
Foam::functionObject
Foam::functionObjects::writeFiles
Foam::functionObjects::regionFunctionObject
Foam::functionObjects::logFiles
SourceFiles
fieldMinMax.C
......@@ -78,7 +78,8 @@ SourceFiles
#ifndef functionObjects_fieldMinMax_H
#define functionObjects_fieldMinMax_H
#include "writeFiles.H"
#include "regionFunctionObject.H"
#include "logFiles.H"
#include "vector.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -94,7 +95,8 @@ namespace functionObjects
class fieldMinMax
:
public writeFiles
public regionFunctionObject,
public logFiles
{
public:
......
......@@ -49,7 +49,8 @@ Foam::functionObjects::fieldValue::fieldValue
const word& valueType
)
:
writeFiles(name, runTime, dict, name),
regionFunctionObject(name, runTime, dict),
logFiles(obr_, name),
dict_(dict),
regionName_(word::null),
resultDict_(fileName("name"), dictionary::null)
......@@ -67,7 +68,8 @@ Foam::functionObjects::fieldValue::fieldValue
const word& valueType
)
:
writeFiles(name, obr, dict, name),
regionFunctionObject(name, obr, dict),
logFiles(obr_, name),
dict_(dict),
regionName_(word::null),
resultDict_(fileName("name"), dictionary::null)
......@@ -88,7 +90,7 @@ Foam::functionObjects::fieldValue::~fieldValue()
bool Foam::functionObjects::fieldValue::read(const dictionary& dict)
{
dict_ = dict;
writeFiles::read(dict);
regionFunctionObject::read(dict);
dict.lookup("fields") >> fields_;
dict.lookup("writeFields") >> writeFields_;
......@@ -105,7 +107,7 @@ bool Foam::functionObjects::fieldValue::execute()
bool Foam::functionObjects::fieldValue::write()
{
writeFiles::write();
logFiles::write();
Log << type() << " " << name() << " write:" << nl;
......
......@@ -30,6 +30,11 @@ Group
Description
Base class for field value -based function objects.
See also
Foam::functionObject
Foam::functionObjects::regionFunctionObject
Foam::functionObjects::logFiles
SourceFiles
fieldValue.C
......@@ -38,7 +43,8 @@ SourceFiles
#ifndef functionObjects_fieldValue_H
#define functionObjects_fieldValue_H
#include "writeFiles.H"
#include "regionFunctionObject.H"
#include "logFiles.H"
#include "Switch.H"
#include "Field.H"
......@@ -59,7 +65,8 @@ namespace functionObjects
class fieldValue
:
public writeFiles
public regionFunctionObject,
public logFiles
{
protected:
......
......@@ -106,7 +106,8 @@ Foam::functionObjects::fieldValues::fieldValueDelta::fieldValueDelta
const dictionary& dict
)
:
writeFiles(name, runTime, dict, name),
regionFunctionObject(name, runTime, dict),
logFiles(obr_, name),
operation_(opSubtract),
region1Ptr_(nullptr),
region2Ptr_(nullptr)
......@@ -135,7 +136,7 @@ bool Foam::functionObjects::fieldValues::fieldValueDelta::read
const dictionary& dict
)
{
writeFiles::read(dict);
regionFunctionObject::read(dict);
region1Ptr_.reset
(
......@@ -166,7 +167,7 @@ bool Foam::functionObjects::fieldValues::fieldValueDelta::read