mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -135,7 +135,7 @@ bool Foam::functionObjects::Curle::read(const dictionary& dict)
|
||||
rawFilePtrs_.set
|
||||
(
|
||||
filei,
|
||||
createFile("observer" + Foam::name(filei))
|
||||
newFileAtStartTime("observer" + Foam::name(filei))
|
||||
);
|
||||
|
||||
if (rawFilePtrs_.set(filei))
|
||||
|
||||
@ -742,7 +742,7 @@ void Foam::DMDModels::STDMD::writeToFile(const word& fileName) const
|
||||
// Write objects of dynamics
|
||||
{
|
||||
autoPtr<OFstream> osPtr =
|
||||
createFile
|
||||
newFileAtTime
|
||||
(
|
||||
fileName + "_" + fieldName_,
|
||||
mesh_.time().timeOutputValue()
|
||||
|
||||
@ -190,7 +190,7 @@ bool Foam::binModel::read(const dictionary& dict)
|
||||
filePtrs_.setSize(fieldNames_.size());
|
||||
forAll(filePtrs_, i)
|
||||
{
|
||||
filePtrs_.set(i, createFile(fieldNames_[i] + "Bin"));
|
||||
filePtrs_.set(i, newFileAtStartTime(fieldNames_[i] + "Bin"));
|
||||
}
|
||||
|
||||
setCoordinateSystem(dict);
|
||||
|
||||
@ -910,7 +910,7 @@ bool Foam::functionObjects::fluxSummary::update()
|
||||
forAll(filePtrs_, zonei)
|
||||
{
|
||||
const word& zoneName = zoneNames_[zonei];
|
||||
filePtrs_.set(zonei, createFile(zoneName));
|
||||
filePtrs_.set(zonei, newFileAtStartTime(zoneName));
|
||||
writeFileHeader
|
||||
(
|
||||
zoneName,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2016-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -36,19 +36,19 @@ createFileNames()
|
||||
{
|
||||
if (writeToFile() && !prodFilePtr_)
|
||||
{
|
||||
prodFilePtr_ = createFile("production");
|
||||
prodFilePtr_ = newFileAtStartTime("production");
|
||||
writeHeader(prodFilePtr_(), "production");
|
||||
writeFileHeader(prodFilePtr_());
|
||||
|
||||
consFilePtr_ = createFile("consumption");
|
||||
consFilePtr_ = newFileAtStartTime("consumption");
|
||||
writeHeader(consFilePtr_(), "consumption");
|
||||
writeFileHeader(consFilePtr_());
|
||||
|
||||
prodIntFilePtr_ = createFile("productionInt");
|
||||
prodIntFilePtr_ = newFileAtStartTime("productionInt");
|
||||
writeHeader(prodIntFilePtr_(), "productionInt");
|
||||
writeFileHeader(prodIntFilePtr_());
|
||||
|
||||
consIntFilePtr_ = createFile("consumptionInt");
|
||||
consIntFilePtr_ = newFileAtStartTime("consumptionInt");
|
||||
writeHeader(consIntFilePtr_(), "consumptionInt");
|
||||
writeFileHeader(consIntFilePtr_());
|
||||
}
|
||||
|
||||
@ -206,7 +206,7 @@ void Foam::functionObjects::forceCoeffs::createIntegratedDataFile()
|
||||
{
|
||||
if (!coeffFilePtr_.valid())
|
||||
{
|
||||
coeffFilePtr_ = createFile("coefficient");
|
||||
coeffFilePtr_ = newFileAtStartTime("coefficient");
|
||||
writeIntegratedDataFileHeader("Coefficients", coeffFilePtr_());
|
||||
}
|
||||
}
|
||||
|
||||
@ -386,13 +386,13 @@ void Foam::functionObjects::forces::createIntegratedDataFiles()
|
||||
{
|
||||
if (!forceFilePtr_.valid())
|
||||
{
|
||||
forceFilePtr_ = createFile("force");
|
||||
forceFilePtr_ = newFileAtStartTime("force");
|
||||
writeIntegratedDataFileHeader("Force", forceFilePtr_());
|
||||
}
|
||||
|
||||
if (!momentFilePtr_.valid())
|
||||
{
|
||||
momentFilePtr_ = createFile("moment");
|
||||
momentFilePtr_ = newFileAtStartTime("moment");
|
||||
writeIntegratedDataFileHeader("Moment", momentFilePtr_());
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,7 +181,8 @@ void Foam::functionObjects::propellerInfo::createFiles()
|
||||
|
||||
if (writePropellerPerformance_ && !propellerPerformanceFilePtr_)
|
||||
{
|
||||
propellerPerformanceFilePtr_ = createFile("propellerPerformance");
|
||||
propellerPerformanceFilePtr_ =
|
||||
newFileAtStartTime("propellerPerformance");
|
||||
auto& os = propellerPerformanceFilePtr_();
|
||||
|
||||
writeHeader(os, "Propeller performance");
|
||||
@ -203,8 +204,9 @@ void Foam::functionObjects::propellerInfo::createFiles()
|
||||
|
||||
if (writeWakeFields_)
|
||||
{
|
||||
if (!wakeFilePtr_) wakeFilePtr_ = createFile("wake");
|
||||
if (!axialWakeFilePtr_) axialWakeFilePtr_ = createFile("axialWake");
|
||||
if (!wakeFilePtr_) wakeFilePtr_ = newFileAtStartTime("wake");
|
||||
if (!axialWakeFilePtr_) axialWakeFilePtr_ =
|
||||
newFileAtStartTime("axialWake");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017-2019 OpenFOAM Foundation
|
||||
Copyright (C) 2019-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -378,7 +378,7 @@ Foam::functionObjects::sizeDistribution::sizeDistribution
|
||||
{
|
||||
read(dict);
|
||||
resetFile(name);
|
||||
createFile(name);
|
||||
newFileAtStartTime(name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -105,7 +105,7 @@ void Foam::functionObjects::energySpectrum::calcAndWriteSpectrum
|
||||
E /= kappaNorm;
|
||||
|
||||
Log << "Writing spectrum" << endl;
|
||||
autoPtr<OFstream> osPtr = createFile(name(), time_.value());
|
||||
autoPtr<OFstream> osPtr = newFileAtTime(name(), time_.value());
|
||||
OFstream& os = osPtr.ref();
|
||||
writeFileHeader(os);
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2021 OpenCFD Ltd.
|
||||
Copyright (C) 2021-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -209,7 +209,7 @@ Foam::FaceInteraction<CloudType>::FaceInteraction
|
||||
filePtrs_.set
|
||||
(
|
||||
nZone,
|
||||
this->createFile(modelName + '_' + zoneName)
|
||||
this->newFileAtStartTime(modelName + '_' + zoneName)
|
||||
);
|
||||
|
||||
writeHeaderValue(filePtrs_[nZone], "Source", type());
|
||||
|
||||
@ -351,7 +351,11 @@ template<class CloudType>
|
||||
void Foam::ParticleZoneInfo<CloudType>::write()
|
||||
{
|
||||
autoPtr<OFstream> osPtr =
|
||||
this->createFile("particles", this->owner().time().timeOutputValue());
|
||||
this->newFileAtTime
|
||||
(
|
||||
"particles",
|
||||
this->owner().time().timeOutputValue()
|
||||
);
|
||||
|
||||
if (Pstream::parRun())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user