Commit 1b45599b authored by Andrew Heather's avatar Andrew Heather Committed by Andrew Heather
Browse files

ENH: enable user to control re-writing of function object output file headers. See #1556

parent d44babcc
...@@ -161,6 +161,7 @@ Foam::functionObjects::writeFile::writeFile(const writeFile& wf) ...@@ -161,6 +161,7 @@ Foam::functionObjects::writeFile::writeFile(const writeFile& wf)
filePtr_(), filePtr_(),
writePrecision_(wf.writePrecision_), writePrecision_(wf.writePrecision_),
writeToFile_(wf.writeToFile_), writeToFile_(wf.writeToFile_),
updateHeader_(wf.updateHeader_),
writtenHeader_(wf.writtenHeader_), writtenHeader_(wf.writtenHeader_),
useUserTime_(wf.useUserTime_), useUserTime_(wf.useUserTime_),
startTime_(wf.startTime_) startTime_(wf.startTime_)
...@@ -180,6 +181,7 @@ Foam::functionObjects::writeFile::writeFile ...@@ -180,6 +181,7 @@ Foam::functionObjects::writeFile::writeFile
fileName_(name), fileName_(name),
filePtr_(), filePtr_(),
writePrecision_(IOstream::defaultPrecision()), writePrecision_(IOstream::defaultPrecision()),
updateHeader_(true),
writeToFile_(writeToFile), writeToFile_(writeToFile),
writtenHeader_(false), writtenHeader_(false),
useUserTime_(true), useUserTime_(true),
...@@ -214,6 +216,9 @@ bool Foam::functionObjects::writeFile::read(const dictionary& dict) ...@@ -214,6 +216,9 @@ bool Foam::functionObjects::writeFile::read(const dictionary& dict)
writePrecision_ = writePrecision_ =
dict.getOrDefault("writePrecision", IOstream::defaultPrecision()); dict.getOrDefault("writePrecision", IOstream::defaultPrecision());
updateHeader_ =
dict.lookupOrDefault("updateHeader", updateHeader_);
// Only write on master // Only write on master
writeToFile_ = writeToFile_ =
Pstream::master() && dict.getOrDefault("writeToFile", writeToFile_); Pstream::master() && dict.getOrDefault("writeToFile", writeToFile_);
...@@ -248,6 +253,12 @@ bool Foam::functionObjects::writeFile::writeToFile() const ...@@ -248,6 +253,12 @@ bool Foam::functionObjects::writeFile::writeToFile() const
} }
bool Foam::functionObjects::writeFile::canWriteHeader() const
{
return writeToFile_ && (updateHeader_ || !writtenHeader_);
}
Foam::label Foam::functionObjects::writeFile::charWidth() const Foam::label Foam::functionObjects::writeFile::charWidth() const
{ {
return writePrecision_ + addChars; return writePrecision_ + addChars;
......
...@@ -82,6 +82,10 @@ protected: ...@@ -82,6 +82,10 @@ protected:
//- Flag to enable/disable writing to file //- Flag to enable/disable writing to file
bool writeToFile_; bool writeToFile_;
//- Flag to update the header, e.g. on mesh changes.
//- Default is true.
bool updateHeader_;
//- Flag to identify whether the header has been written //- Flag to identify whether the header has been written
bool writtenHeader_; bool writtenHeader_;
...@@ -175,6 +179,9 @@ public: ...@@ -175,6 +179,9 @@ public:
//- Flag to allow writing to file //- Flag to allow writing to file
virtual bool writeToFile() const; virtual bool writeToFile() const;
//- Flag to allow writing the header
virtual bool canWriteHeader() const;
//- Return width of character stream output //- Return width of character stream output
virtual label charWidth() const; virtual label charWidth() const;
......
...@@ -543,9 +543,9 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::update() ...@@ -543,9 +543,9 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::update()
void Foam::functionObjects::fieldValues::surfaceFieldValue::writeFileHeader void Foam::functionObjects::fieldValues::surfaceFieldValue::writeFileHeader
( (
Ostream& os Ostream& os
) const )
{ {
if (operation_ != opNone) if (canWriteHeader() && (operation_ != opNone))
{ {
writeCommented(os, "Region type : "); writeCommented(os, "Region type : ");
os << regionTypeNames_[regionType_] << " " << regionName_ << endl; os << regionTypeNames_[regionType_] << " " << regionName_ << endl;
...@@ -575,6 +575,8 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::writeFileHeader ...@@ -575,6 +575,8 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::writeFileHeader
os << endl; os << endl;
} }
writtenHeader_ = true;
} }
......
...@@ -529,7 +529,7 @@ protected: ...@@ -529,7 +529,7 @@ protected:
//- Output file header information //- Output file header information
virtual void writeFileHeader(Ostream& os) const; virtual void writeFileHeader(Ostream& os);
public: public:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment