ENH: writeFile - add newFile function
ENH: writeFile - renamed createFile functions
to newFileAtTime and newFileAtStartTime
This commit is contained in:
committed by
Mark OLESEN
parent
c59b6db3c4
commit
f87f0040b8
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2012-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2016 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -43,7 +43,7 @@ void Foam::functionObjects::logFiles::createFiles()
|
||||
{
|
||||
if (!filePtrs_.set(i))
|
||||
{
|
||||
filePtrs_.set(i, createFile(names_[i]));
|
||||
filePtrs_.set(i, newFileAtStartTime(names_[i]));
|
||||
|
||||
initStream(filePtrs_[i]);
|
||||
}
|
||||
|
||||
@ -76,7 +76,35 @@ Foam::fileName Foam::functionObjects::writeFile::baseTimeDir() const
|
||||
}
|
||||
|
||||
|
||||
Foam::autoPtr<Foam::OFstream> Foam::functionObjects::writeFile::createFile
|
||||
Foam::autoPtr<Foam::OFstream> Foam::functionObjects::writeFile::newFile
|
||||
(
|
||||
const fileName& fName
|
||||
) const
|
||||
{
|
||||
autoPtr<OFstream> osPtr;
|
||||
|
||||
if (Pstream::master() && writeToFile_)
|
||||
{
|
||||
fileName outputDir(baseFileDir()/prefix_/fName.path());
|
||||
|
||||
mkDir(outputDir);
|
||||
|
||||
osPtr.reset(new OFstream(outputDir/(fName.name() + ".dat")));
|
||||
|
||||
if (!osPtr->good())
|
||||
{
|
||||
FatalIOErrorInFunction(osPtr()) << "Cannot open file"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
initStream(osPtr());
|
||||
}
|
||||
|
||||
return osPtr;
|
||||
}
|
||||
|
||||
|
||||
Foam::autoPtr<Foam::OFstream> Foam::functionObjects::writeFile::newFileAtTime
|
||||
(
|
||||
const word& name,
|
||||
scalar timeValue
|
||||
@ -121,12 +149,13 @@ Foam::autoPtr<Foam::OFstream> Foam::functionObjects::writeFile::createFile
|
||||
}
|
||||
|
||||
|
||||
Foam::autoPtr<Foam::OFstream> Foam::functionObjects::writeFile::createFile
|
||||
Foam::autoPtr<Foam::OFstream>
|
||||
Foam::functionObjects::writeFile::newFileAtStartTime
|
||||
(
|
||||
const word& name
|
||||
) const
|
||||
{
|
||||
return createFile(name, startTime_);
|
||||
return newFileAtTime(name, startTime_);
|
||||
|
||||
}
|
||||
|
||||
@ -134,7 +163,7 @@ Foam::autoPtr<Foam::OFstream> Foam::functionObjects::writeFile::createFile
|
||||
void Foam::functionObjects::writeFile::resetFile(const word& fileName)
|
||||
{
|
||||
fileName_ = fileName;
|
||||
filePtr_ = createFile(fileName_);
|
||||
filePtr_ = newFileAtStartTime(fileName_);
|
||||
}
|
||||
|
||||
|
||||
@ -200,7 +229,7 @@ Foam::functionObjects::writeFile::writeFile
|
||||
|
||||
if (writeToFile_)
|
||||
{
|
||||
filePtr_ = createFile(fileName_);
|
||||
filePtr_ = newFileAtStartTime(fileName_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -137,15 +137,19 @@ protected:
|
||||
//- Return the base directory for the current time value
|
||||
fileName baseTimeDir() const;
|
||||
|
||||
//- Return autoPtr to a new file using file name
|
||||
// Note: no check for if the file already exists
|
||||
virtual autoPtr<OFstream> newFile(const fileName& fName) const;
|
||||
|
||||
//- Return autoPtr to a new file for a given time
|
||||
virtual autoPtr<OFstream> createFile
|
||||
virtual autoPtr<OFstream> newFileAtTime
|
||||
(
|
||||
const word& name,
|
||||
scalar timeValue
|
||||
) const;
|
||||
|
||||
//- Return autoPtr to a new file using the simulation start time
|
||||
virtual autoPtr<OFstream> createFile
|
||||
virtual autoPtr<OFstream> newFileAtStartTime
|
||||
(
|
||||
const word& name
|
||||
) const;
|
||||
@ -161,6 +165,35 @@ protected:
|
||||
void operator=(const writeFile&) = delete;
|
||||
|
||||
|
||||
// Housekeeping
|
||||
|
||||
//- Deprecated(2022-09) Return autoPtr to a new file for a given time
|
||||
//
|
||||
// \deprecated(2022-09) - use newFileAtTime function
|
||||
FOAM_DEPRECATED_FOR(2022-09, "newFileAtTime function")
|
||||
virtual autoPtr<OFstream> createFile
|
||||
(
|
||||
const word& name,
|
||||
scalar timeValue
|
||||
) const
|
||||
{
|
||||
return newFileAtTime(name, timeValue);
|
||||
}
|
||||
|
||||
//- Deprecated(2022-09) Return autoPtr to a new file
|
||||
//- using the simulation start time
|
||||
//
|
||||
// \deprecated(2022-09) - use newFileAtStartTime function
|
||||
FOAM_DEPRECATED_FOR(2022-09, "newFileAtStartTime function")
|
||||
virtual autoPtr<OFstream> createFile
|
||||
(
|
||||
const word& name
|
||||
) const
|
||||
{
|
||||
return newFileAtStartTime(name);
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Additional characters for writing
|
||||
|
||||
Reference in New Issue
Block a user