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