mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
STYLE: simplify the writeFile constructor
This commit is contained in:
committed by
Andrew Heather
parent
2ca4792734
commit
c8df98cc2a
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
| Copyright (C) 2012-2018 OpenFOAM Foundation
|
| Copyright (C) 2012-2018 OpenFOAM Foundation
|
||||||
@ -82,18 +82,19 @@ Foam::fileName Foam::functionObjects::writeFile::baseTimeDir() const
|
|||||||
Foam::autoPtr<Foam::OFstream> Foam::functionObjects::writeFile::createFile
|
Foam::autoPtr<Foam::OFstream> Foam::functionObjects::writeFile::createFile
|
||||||
(
|
(
|
||||||
const word& name,
|
const word& name,
|
||||||
const scalar time0
|
scalar timeValue
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
autoPtr<OFstream> osPtr;
|
autoPtr<OFstream> osPtr;
|
||||||
|
|
||||||
if (Pstream::master() && writeToFile_)
|
if (Pstream::master() && writeToFile_)
|
||||||
{
|
{
|
||||||
const scalar time = useUserTime_ ?
|
if (useUserTime_)
|
||||||
fileObr_.time().timeToUserTime(time0)
|
{
|
||||||
: time0;
|
timeValue = fileObr_.time().timeToUserTime(timeValue);
|
||||||
|
}
|
||||||
|
|
||||||
const word timeName = Time::timeName(time);
|
const word timeName = Time::timeName(timeValue);
|
||||||
|
|
||||||
fileName outputDir(baseFileDir()/prefix_/timeName);
|
fileName outputDir(baseFileDir()/prefix_/timeName);
|
||||||
|
|
||||||
@ -154,12 +155,13 @@ Foam::Omanip<int> Foam::functionObjects::writeFile::valueWidth
|
|||||||
Foam::functionObjects::writeFile::writeFile
|
Foam::functionObjects::writeFile::writeFile
|
||||||
(
|
(
|
||||||
const objectRegistry& obr,
|
const objectRegistry& obr,
|
||||||
const word& prefix
|
const word& prefix,
|
||||||
|
const word& file
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
fileObr_(obr),
|
fileObr_(obr),
|
||||||
prefix_(prefix),
|
prefix_(prefix),
|
||||||
fileName_("undefined"),
|
fileName_(file),
|
||||||
filePtr_(),
|
filePtr_(),
|
||||||
writePrecision_(IOstream::defaultPrecision()),
|
writePrecision_(IOstream::defaultPrecision()),
|
||||||
writeToFile_(true),
|
writeToFile_(true),
|
||||||
@ -173,19 +175,11 @@ Foam::functionObjects::writeFile::writeFile
|
|||||||
(
|
(
|
||||||
const objectRegistry& obr,
|
const objectRegistry& obr,
|
||||||
const word& prefix,
|
const word& prefix,
|
||||||
const word& fileName,
|
const word& file,
|
||||||
const dictionary& dict
|
const dictionary& dict
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
fileObr_(obr),
|
writeFile(obr, prefix, file)
|
||||||
prefix_(prefix),
|
|
||||||
fileName_(fileName),
|
|
||||||
filePtr_(),
|
|
||||||
writePrecision_(IOstream::defaultPrecision()),
|
|
||||||
writeToFile_(true),
|
|
||||||
writtenHeader_(false),
|
|
||||||
useUserTime_(true),
|
|
||||||
startTime_(obr.time().startTime().value())
|
|
||||||
{
|
{
|
||||||
read(dict);
|
read(dict);
|
||||||
|
|
||||||
@ -203,9 +197,9 @@ bool Foam::functionObjects::writeFile::read(const dictionary& dict)
|
|||||||
writePrecision_ =
|
writePrecision_ =
|
||||||
dict.lookupOrDefault("writePrecision", IOstream::defaultPrecision());
|
dict.lookupOrDefault("writePrecision", IOstream::defaultPrecision());
|
||||||
|
|
||||||
// Only write on master process
|
// Only write on master
|
||||||
writeToFile_ = dict.lookupOrDefault("writeToFile", true);
|
writeToFile_ =
|
||||||
writeToFile_ = writeToFile_ && Pstream::master();
|
Pstream::master() && dict.lookupOrDefault("writeToFile", true);
|
||||||
|
|
||||||
// Use user time, e.g. CA deg in preference to seconds
|
// Use user time, e.g. CA deg in preference to seconds
|
||||||
useUserTime_ = dict.lookupOrDefault("useUserTime", true);
|
useUserTime_ = dict.lookupOrDefault("useUserTime", true);
|
||||||
@ -224,7 +218,7 @@ Foam::OFstream& Foam::functionObjects::writeFile::file()
|
|||||||
if (!filePtr_.valid())
|
if (!filePtr_.valid())
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "File pointer not allocated";
|
<< "File pointer not allocated\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return *filePtr_;
|
return *filePtr_;
|
||||||
@ -282,11 +276,14 @@ void Foam::functionObjects::writeFile::writeHeader
|
|||||||
|
|
||||||
void Foam::functionObjects::writeFile::writeTime(Ostream& os) const
|
void Foam::functionObjects::writeFile::writeTime(Ostream& os) const
|
||||||
{
|
{
|
||||||
scalar timeNow = useUserTime_ ?
|
const scalar timeValue =
|
||||||
fileObr_.time().timeOutputValue()
|
(
|
||||||
: fileObr_.time().value();
|
useUserTime_
|
||||||
|
? fileObr_.time().timeOutputValue()
|
||||||
|
: fileObr_.time().value()
|
||||||
|
);
|
||||||
|
|
||||||
os << setw(charWidth()) << Time::timeName(timeNow);
|
os << setw(charWidth()) << Time::timeName(timeValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
| Copyright (C) 2012-2016 OpenFOAM Foundation
|
| Copyright (C) 2012-2016 OpenFOAM Foundation
|
||||||
@ -103,14 +103,14 @@ protected:
|
|||||||
//- Return the base directory for the current time value
|
//- Return the base directory for the current time value
|
||||||
fileName baseTimeDir() const;
|
fileName baseTimeDir() const;
|
||||||
|
|
||||||
//- Return an autoPtr to a new file for a given time
|
//- Return autoPtr to a new file for a given time
|
||||||
virtual autoPtr<OFstream> createFile
|
virtual autoPtr<OFstream> createFile
|
||||||
(
|
(
|
||||||
const word& name,
|
const word& name,
|
||||||
const scalar time
|
scalar timeValue
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Return an autoPtr to a new file
|
//- Return autoPtr to a new file using the simulation start time
|
||||||
virtual autoPtr<OFstream> createFile
|
virtual autoPtr<OFstream> createFile
|
||||||
(
|
(
|
||||||
const word& name
|
const word& name
|
||||||
@ -138,20 +138,21 @@ public:
|
|||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from objectRegistry and prefix
|
//- Construct from objectRegistry, prefix, fileName
|
||||||
writeFile
|
|
||||||
(
|
|
||||||
const objectRegistry& obr,
|
|
||||||
const word& prefix
|
|
||||||
);
|
|
||||||
|
|
||||||
//- Construct from objectRegistry and prefix, and read options
|
|
||||||
// from dictionary
|
|
||||||
writeFile
|
writeFile
|
||||||
(
|
(
|
||||||
const objectRegistry& obr,
|
const objectRegistry& obr,
|
||||||
const word& prefix,
|
const word& prefix,
|
||||||
const word& fileName,
|
const word& file = "undefined"
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Construct from objectRegistry, prefix, fileName
|
||||||
|
//- and read options from dictionary
|
||||||
|
writeFile
|
||||||
|
(
|
||||||
|
const objectRegistry& obr,
|
||||||
|
const word& prefix,
|
||||||
|
const word& file,
|
||||||
const dictionary& dict
|
const dictionary& dict
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user