mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: functionObjects - updated writing to file
This commit is contained in:
@ -31,9 +31,18 @@ License
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::word Foam::functionObjectFile::outputPrefix = "postProcessing";
|
||||
Foam::label Foam::functionObjectFile::addChars = 7;
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjectFile::initStream(Ostream& os) const
|
||||
{
|
||||
os.setf(ios_base::scientific, ios_base::floatfield);
|
||||
// os.precision(IOstream::defaultPrecision());
|
||||
os.width(charWidth());
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName Foam::functionObjectFile::baseFileDir() const
|
||||
{
|
||||
fileName baseDir = obr_.time().path();
|
||||
@ -96,6 +105,8 @@ void Foam::functionObjectFile::createFiles()
|
||||
|
||||
filePtrs_.set(i, new OFstream(outputDir/(fName + ".dat")));
|
||||
|
||||
initStream(filePtrs_[i]);
|
||||
|
||||
writeFileHeader(i);
|
||||
|
||||
i++;
|
||||
@ -149,7 +160,7 @@ void Foam::functionObjectFile::resetName(const word& name)
|
||||
|
||||
Foam::Omanip<int> Foam::functionObjectFile::valueWidth(const label offset) const
|
||||
{
|
||||
return setw(IOstream::defaultPrecision() + 7 + offset);
|
||||
return setw(IOstream::defaultPrecision() + addChars + offset);
|
||||
}
|
||||
|
||||
|
||||
@ -295,4 +306,42 @@ Foam::OFstream& Foam::functionObjectFile::file(const label i)
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::functionObjectFile::charWidth() const
|
||||
{
|
||||
return IOstream::defaultPrecision() + addChars;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjectFile::writeCommented
|
||||
(
|
||||
Ostream& os,
|
||||
const string& str
|
||||
) const
|
||||
{
|
||||
os << setw(1) << "#" << setw(1) << ' '
|
||||
<< setw(charWidth() - 2) << str.c_str();
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjectFile::writeTabbed
|
||||
(
|
||||
Ostream& os,
|
||||
const string& str
|
||||
) const
|
||||
{
|
||||
os << tab << setw(charWidth()) << str.c_str();
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjectFile::writeHeader
|
||||
(
|
||||
Ostream& os,
|
||||
const string& str
|
||||
) const
|
||||
{
|
||||
os << setw(1) << "#" << setw(1) << ' '
|
||||
<< setf(ios_base::left) << setw(charWidth() - 2) << str.c_str() << nl;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -78,6 +78,9 @@ protected:
|
||||
|
||||
// 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;
|
||||
|
||||
@ -114,6 +117,9 @@ public:
|
||||
//- Folder prefix
|
||||
static const word outputPrefix;
|
||||
|
||||
//- Additional characters for writing
|
||||
static label addChars;
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
@ -154,13 +160,38 @@ public:
|
||||
//- Return file 'i'
|
||||
OFstream& file(const label i);
|
||||
|
||||
//- Write a formatted value to stream
|
||||
template<class Type>
|
||||
const char* writeValue
|
||||
//- Write a commented string to stream
|
||||
void writeCommented
|
||||
(
|
||||
const Type& value,
|
||||
const label offset = 0
|
||||
Ostream& os,
|
||||
const string& str
|
||||
) const;
|
||||
|
||||
//- Write a tabbed string to stream
|
||||
void writeTabbed
|
||||
(
|
||||
Ostream& os,
|
||||
const string& str
|
||||
) const;
|
||||
|
||||
//- Write a commented header to stream
|
||||
void writeHeader
|
||||
(
|
||||
Ostream& os,
|
||||
const string& str
|
||||
) const;
|
||||
|
||||
//- Write a (commented) header property and value pair
|
||||
template<class Type>
|
||||
void writeHeaderValue
|
||||
(
|
||||
Ostream& os,
|
||||
const string& property,
|
||||
const Type& value
|
||||
) const;
|
||||
|
||||
//- Return width of character stream output
|
||||
label charWidth() const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user