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

This commit is contained in:
Andrew Heather
2020-01-21 15:10:29 +00:00
committed by Andrew Heather
parent d44babcc78
commit 1b45599b26
4 changed files with 23 additions and 3 deletions

View File

@ -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
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)
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
} }
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;

View File

@ -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:
//- 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;

View File

@ -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
os << endl; os << endl;
} }
writtenHeader_ = true;
} }

View File

@ -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: