Commit 5863c94b authored by Andrew Heather's avatar Andrew Heather
Browse files

Merge branch 'issue-1556-fo-header-writing' into 'develop'

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

See merge request !360
parents d44babcc 1b45599b
......@@ -161,6 +161,7 @@ Foam::functionObjects::writeFile::writeFile(const writeFile& wf)
filePtr_(),
writePrecision_(wf.writePrecision_),
writeToFile_(wf.writeToFile_),
updateHeader_(wf.updateHeader_),
writtenHeader_(wf.writtenHeader_),
useUserTime_(wf.useUserTime_),
startTime_(wf.startTime_)
......@@ -180,6 +181,7 @@ Foam::functionObjects::writeFile::writeFile
fileName_(name),
filePtr_(),
writePrecision_(IOstream::defaultPrecision()),
updateHeader_(true),
writeToFile_(writeToFile),
writtenHeader_(false),
useUserTime_(true),
......@@ -214,6 +216,9 @@ bool Foam::functionObjects::writeFile::read(const dictionary& dict)
writePrecision_ =
dict.getOrDefault("writePrecision", IOstream::defaultPrecision());
updateHeader_ =
dict.lookupOrDefault("updateHeader", updateHeader_);
// Only write on master
writeToFile_ =
Pstream::master() && dict.getOrDefault("writeToFile", writeToFile_);
......@@ -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
{
return writePrecision_ + addChars;
......
......@@ -82,6 +82,10 @@ protected:
//- Flag to enable/disable writing to file
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
bool writtenHeader_;
......@@ -175,6 +179,9 @@ public:
//- Flag to allow writing to file
virtual bool writeToFile() const;
//- Flag to allow writing the header
virtual bool canWriteHeader() const;
//- Return width of character stream output
virtual label charWidth() const;
......
......@@ -543,9 +543,9 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::update()
void Foam::functionObjects::fieldValues::surfaceFieldValue::writeFileHeader
(
Ostream& os
) const
)
{
if (operation_ != opNone)
if (canWriteHeader() && (operation_ != opNone))
{
writeCommented(os, "Region type : ");
os << regionTypeNames_[regionType_] << " " << regionName_ << endl;
......@@ -575,6 +575,8 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::writeFileHeader
os << endl;
}
writtenHeader_ = true;
}
......
......@@ -529,7 +529,7 @@ protected:
//- Output file header information
virtual void writeFileHeader(Ostream& os) const;
virtual void writeFileHeader(Ostream& os);
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