mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: writeFile - enable file creation at a specified time. Fixes #1096
This commit is contained in:
@ -84,18 +84,18 @@ 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 time
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
autoPtr<OFstream> osPtr;
|
autoPtr<OFstream> osPtr;
|
||||||
|
|
||||||
if (Pstream::master() && writeToFile_)
|
if (Pstream::master() && writeToFile_)
|
||||||
{
|
{
|
||||||
const scalar startTime = fileObr_.time().startTime().value();
|
const scalar userTime = fileObr_.time().timeToUserTime(time);
|
||||||
const scalar userStartTime = fileObr_.time().timeToUserTime(startTime);
|
const word timeName = Time::timeName(userTime);
|
||||||
const word startTimeName = Time::timeName(userStartTime);
|
|
||||||
|
|
||||||
fileName outputDir(baseFileDir()/prefix_/startTimeName);
|
fileName outputDir(baseFileDir()/prefix_/timeName);
|
||||||
|
|
||||||
mkDir(outputDir);
|
mkDir(outputDir);
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ Foam::autoPtr<Foam::OFstream> Foam::functionObjects::writeFile::createFile
|
|||||||
IFstream is(outputDir/(fName + ".dat"));
|
IFstream is(outputDir/(fName + ".dat"));
|
||||||
if (is.good())
|
if (is.good())
|
||||||
{
|
{
|
||||||
fName = fName + "_" + startTimeName;
|
fName = fName + "_" + timeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
osPtr.reset(new OFstream(outputDir/(fName + ".dat")));
|
osPtr.reset(new OFstream(outputDir/(fName + ".dat")));
|
||||||
@ -123,6 +123,16 @@ Foam::autoPtr<Foam::OFstream> Foam::functionObjects::writeFile::createFile
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::autoPtr<Foam::OFstream> Foam::functionObjects::writeFile::createFile
|
||||||
|
(
|
||||||
|
const word& name
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return createFile(name, startTime_);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::functionObjects::writeFile::resetFile(const word& fileName)
|
void Foam::functionObjects::writeFile::resetFile(const word& fileName)
|
||||||
{
|
{
|
||||||
fileName_ = fileName;
|
fileName_ = fileName;
|
||||||
@ -153,7 +163,8 @@ Foam::functionObjects::writeFile::writeFile
|
|||||||
filePtr_(),
|
filePtr_(),
|
||||||
writePrecision_(IOstream::defaultPrecision()),
|
writePrecision_(IOstream::defaultPrecision()),
|
||||||
writeToFile_(true),
|
writeToFile_(true),
|
||||||
writtenHeader_(false)
|
writtenHeader_(false),
|
||||||
|
startTime_(obr.time().startTime().value())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -171,7 +182,8 @@ Foam::functionObjects::writeFile::writeFile
|
|||||||
filePtr_(),
|
filePtr_(),
|
||||||
writePrecision_(IOstream::defaultPrecision()),
|
writePrecision_(IOstream::defaultPrecision()),
|
||||||
writeToFile_(true),
|
writeToFile_(true),
|
||||||
writtenHeader_(false)
|
writtenHeader_(false),
|
||||||
|
startTime_(obr.time().startTime().value())
|
||||||
{
|
{
|
||||||
read(dict);
|
read(dict);
|
||||||
|
|
||||||
@ -182,12 +194,6 @@ Foam::functionObjects::writeFile::writeFile
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
Foam::functionObjects::writeFile::~writeFile()
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
bool Foam::functionObjects::writeFile::read(const dictionary& dict)
|
bool Foam::functionObjects::writeFile::read(const dictionary& dict)
|
||||||
|
|||||||
@ -3,7 +3,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) 2012-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -82,6 +82,9 @@ protected:
|
|||||||
//- Flag to identify whether the header has been written
|
//- Flag to identify whether the header has been written
|
||||||
bool writtenHeader_;
|
bool writtenHeader_;
|
||||||
|
|
||||||
|
//- Start time value
|
||||||
|
scalar startTime_;
|
||||||
|
|
||||||
|
|
||||||
// Protected Member Functions
|
// Protected Member Functions
|
||||||
|
|
||||||
@ -94,8 +97,18 @@ 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
|
||||||
|
virtual autoPtr<OFstream> createFile
|
||||||
|
(
|
||||||
|
const word& name,
|
||||||
|
const scalar time
|
||||||
|
) const;
|
||||||
|
|
||||||
//- Return an autoPtr to a new file
|
//- Return an autoPtr to a new file
|
||||||
virtual autoPtr<OFstream> createFile(const word& name) const;
|
virtual autoPtr<OFstream> createFile
|
||||||
|
(
|
||||||
|
const word& name
|
||||||
|
) const;
|
||||||
|
|
||||||
//- Reset internal file pointer to new file with new name
|
//- Reset internal file pointer to new file with new name
|
||||||
virtual void resetFile(const word& name);
|
virtual void resetFile(const word& name);
|
||||||
@ -142,7 +155,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//- Destructor
|
//- Destructor
|
||||||
virtual ~writeFile();
|
virtual ~writeFile() = default;
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|||||||
Reference in New Issue
Block a user