Merge branch 'feature-noise-writeFile' into 'develop'

ENH: noiseModels - replaced graph usage by writeFile

See merge request Development/openfoam!562
This commit is contained in:
Mark OLESEN
2022-10-04 13:50:32 +00:00
25 changed files with 405 additions and 194 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -127,7 +127,7 @@ int main(int argc, char *argv[])
IOdictionary dict(dictIO);
autoPtr<noiseModel> model(noiseModel::New(dict));
autoPtr<noiseModel> model(noiseModel::New(dict, runTime));
model->calculate();
Info<< nl << "End\n" << endl;

View File

@ -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]);
}

View File

@ -76,7 +76,44 @@ Foam::fileName Foam::functionObjects::writeFile::baseTimeDir() const
}
Foam::autoPtr<Foam::OFstream> Foam::functionObjects::writeFile::createFile
Foam::fileName Foam::functionObjects::writeFile::filePath
(
const fileName& fName
) const
{
return baseFileDir()/prefix_/fName;
}
Foam::autoPtr<Foam::OFstream> Foam::functionObjects::writeFile::newFile
(
const fileName& fName
) const
{
autoPtr<OFstream> osPtr;
if (Pstream::master() && writeToFile_)
{
fileName outputDir(filePath(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 +158,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 +172,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 +238,7 @@ Foam::functionObjects::writeFile::writeFile
if (writeToFile_)
{
filePtr_ = createFile(fileName_);
filePtr_ = newFileAtStartTime(fileName_);
}
}

View File

@ -137,15 +137,22 @@ protected:
//- Return the base directory for the current time value
fileName baseTimeDir() const;
//- Return the full path for the supplied file name
fileName filePath(const fileName& fName) 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 +168,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

View File

@ -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))

View File

@ -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()

View File

@ -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);

View File

@ -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,

View File

@ -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_());
}

View File

@ -206,7 +206,7 @@ void Foam::functionObjects::forceCoeffs::createIntegratedDataFile()
{
if (!coeffFilePtr_.valid())
{
coeffFilePtr_ = createFile("coefficient");
coeffFilePtr_ = newFileAtStartTime("coefficient");
writeIntegratedDataFileHeader("Coefficients", coeffFilePtr_());
}
}

View File

@ -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_());
}
}

View File

@ -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");
}
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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());

View File

@ -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())
{

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015-2021 OpenCFD Ltd.
Copyright (C) 2015-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -243,16 +243,58 @@ Foam::fileName Foam::noiseModel::baseFileDir(const label dataseti) const
{
return
(
argList::envGlobalPath()
/ functionObject::outputPrefix
/ "noise"
/ outputPrefix_
outputPrefix_
/ type()
/ ("input" + Foam::name(dataseti))
);
}
void Foam::noiseModel::writeFileHeader
(
Ostream& os,
const string& x,
const string& y,
const List<Tuple2<string, token>>& headerValues
) const
{
writeHeader(os, x + " vs " + y);
writeHeaderValue(os, "Lower frequency", fLower_);
writeHeaderValue(os, "Upper frequency", fUpper_);
writeHeaderValue(os, "Window model", windowModelPtr_->type());
writeHeaderValue(os, "Window number", windowModelPtr_->nWindow());
writeHeaderValue(os, "Window samples", windowModelPtr_->nSamples());
writeHeaderValue(os, "Window overlap %", windowModelPtr_->overlapPercent());
writeHeaderValue(os, "dBRef", dBRef_);
for (const auto& hv : headerValues)
{
writeHeaderValue(os, hv.first(), hv.second());
}
writeCommented(os, x.substr(0, x.find(' ')));
writeTabbed(os, y.substr(0, y.find(' ')));
os << nl;
}
void Foam::noiseModel::writeFreqDataToFile
(
Ostream& os,
const scalarField& f,
const scalarField& fx
) const
{
forAll(f, i)
{
if (f[i] >= fLower_ && f[i] <= fUpper_)
{
os << f[i] << tab << fx[i] << nl;
}
}
}
Foam::tmp<Foam::scalarField> Foam::noiseModel::uniformFrequencies
(
const scalar deltaT,
@ -563,8 +605,15 @@ Foam::scalar Foam::noiseModel::gainD(const scalar f) const
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::noiseModel::noiseModel(const dictionary& dict, const bool readFields)
Foam::noiseModel::noiseModel
(
const dictionary& dict,
const objectRegistry& obr,
const word& name,
const bool readFields
)
:
functionObjects::writeFile(obr, "noise"),
dict_(dict),
rhoRef_(1),
nSamples_(65536),
@ -572,7 +621,6 @@ Foam::noiseModel::noiseModel(const dictionary& dict, const bool readFields)
fUpper_(10000),
startTime_(0),
windowModelPtr_(),
graphFormat_("raw"),
SPLweighting_(weightingType::none),
dBRef_(2e-5),
minPressure_(-0.5*VGREAT),
@ -603,12 +651,16 @@ Foam::noiseModel::noiseModel(const dictionary& dict, const bool readFields)
bool Foam::noiseModel::read(const dictionary& dict)
{
if (!functionObjects::writeFile::read(dict))
{
return false;
}
dict.readIfPresent("rhoRef", rhoRef_);
dict.readIfPresent("N", nSamples_);
dict.readIfPresent("fl", fLower_);
dict.readIfPresent("fu", fUpper_);
dict.readIfPresent("startTime", startTime_);
dict.readIfPresent("graphFormat", graphFormat_);
dict.readIfPresent("minPressure", minPressure_);
dict.readIfPresent("maxPressure", maxPressure_);
dict.readIfPresent("outputPrefix", outputPrefix_);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015-2021 OpenCFD Ltd.
Copyright (C) 2015-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -64,7 +64,6 @@ Description
outputPrefix | Prefix applied to output files| no | ''
SPLweighting | Weighting: dBA, dBB, dBC, DBD | no | none
dBRef | Reference for dB calculation | no | 2e-5
graphFormat | Graph format | no | raw
writePrmsf | Write Prmsf data | no | yes
writeSPL | Write SPL data | no | yes
writePSD | Write PSD data | no | yes
@ -80,13 +79,14 @@ SourceFiles
#ifndef noiseModel_H
#define noiseModel_H
#include "writeFile.H"
#include "dictionary.H"
#include "scalarList.H"
#include "instantList.H"
#include "windowModel.H"
#include "Enum.H"
#include "Tuple2.H"
#include "runTimeSelectionTables.H"
#include "graph.H"
#include <fftw3.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -99,6 +99,8 @@ namespace Foam
\*---------------------------------------------------------------------------*/
class noiseModel
:
public functionObjects::writeFile
{
public:
@ -173,9 +175,6 @@ protected:
//- Window model
autoPtr<windowModel> windowModelPtr_;
//- Graph format
word graphFormat_;
//- Weighting
weightingType SPLweighting_;
@ -252,6 +251,23 @@ protected:
//- Return the base output directory
fileName baseFileDir(const label dataseti) const;
//- Write output file header
void writeFileHeader
(
Ostream& os,
const string& x,
const string& y,
const List<Tuple2<string, token>>& headerValues = {}
) const;
// Write frequency-based data to file
void writeFreqDataToFile
(
Ostream& os,
const scalarField& f,
const scalarField& fx
) const;
//- Create a field of equally spaced frequencies for the current set of
//- data - assumes a constant time step
tmp<scalarField> uniformFrequencies
@ -334,16 +350,27 @@ public:
noiseModel,
dictionary,
(
const dictionary& dict
const dictionary& dict,
const objectRegistry& obr
),
(dict)
(dict, obr)
);
//- Selector
static autoPtr<noiseModel> New(const dictionary& dict);
static autoPtr<noiseModel> New
(
const dictionary& dict,
const objectRegistry& obr
);
//- Constructor
noiseModel(const dictionary& dict, const bool readFields = true);
noiseModel
(
const dictionary& dict,
const objectRegistry& obr,
const word& name,
const bool readFields = true
);
//- Destructor
virtual ~noiseModel() = default;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -29,7 +29,11 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::autoPtr<Foam::noiseModel> Foam::noiseModel::New(const dictionary& dict)
Foam::autoPtr<Foam::noiseModel> Foam::noiseModel::New
(
const dictionary& dict,
const objectRegistry& obr
)
{
const word modelType(dict.get<word>("noiseModel"));
@ -48,7 +52,10 @@ Foam::autoPtr<Foam::noiseModel> Foam::noiseModel::New(const dictionary& dict)
) << exit(FatalIOError);
}
return autoPtr<noiseModel>(ctorPtr(dict.subDict(modelType + "Coeffs")));
return autoPtr<noiseModel>
(
ctorPtr(dict.subDict(modelType + "Coeffs"), obr)
);
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015-2021 OpenCFD Ltd.
Copyright (C) 2015-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -113,19 +113,13 @@ void pointNoise::processData
// RMS pressure [Pa]
if (writePrmsf_)
{
graph g
(
"Prms(f)",
"f [Hz]",
"Prms(f) [Pa]",
f,
RMSmeanPf(p)
);
auto filePtr = newFile(outDir/"Prms_f");
auto& os = filePtr();
g.setXRange(fLower_, fUpper_);
Info<< " Writing " << os.name() << endl;
Info<< " Creating graph for " << g.title() << endl;
g.write(outDir, graph::wordify(g.title()), graphFormat_);
writeFileHeader(os, "f [Hz]", "Prms(f) [Pa]");
writeFreqDataToFile(os, f, RMSmeanPf(p));
}
// PSD [Pa^2/Hz]
@ -133,55 +127,42 @@ void pointNoise::processData
if (writePSDf_)
{
graph g
(
"PSD(f)",
"f [Hz]",
"PSD(f) [PaPa_Hz]",
f,
PSDf
);
auto filePtr = newFile(outDir/"PSD_f");
auto& os = filePtr();
g.setXRange(fLower_, fUpper_);
Info<< " Writing " << os.name() << endl;
Info<< " Creating graph for " << g.title() << endl;
g.write(outDir, graph::wordify(g.title()), graphFormat_);
writeFileHeader(os, "f [Hz]", "PSD(f) [PaPa_Hz]");
writeFreqDataToFile(os, f, PSDf);
}
// PSD [dB/Hz]
if (writePSD_)
{
graph g
(
"PSD_dB_Hz(f)",
"f [Hz]",
"PSD(f) [dB_Hz]",
f,
PSD(PSDf)
);
auto filePtr = newFile(outDir/"PSD_dB_Hz_f");
auto& os = filePtr();
g.setXRange(fLower_, fUpper_);
Info<< " Writing " << os.name() << endl;
Info<< " Creating graph for " << g.title() << endl;
g.write(outDir, graph::wordify(g.title()), graphFormat_);
writeFileHeader(os, "f [Hz]", "PSD(f) [dB_Hz]");
writeFreqDataToFile(os, f, PSD(PSDf));
}
// SPL [dB]
if (writeSPL_)
{
graph g
auto filePtr = newFile(outDir/"SPL_dB_f");
auto& os = filePtr();
Info<< " Writing " << os.name() << endl;
writeFileHeader
(
"SPL_dB(f)",
os,
"f [Hz]",
"SPL(f) [" + weightingTypeNames_[SPLweighting_] + "]",
f,
SPL(PSDf*deltaf, f)
"SPL(f) [" + weightingTypeNames_[SPLweighting_] + "]"
);
g.setXRange(fLower_, fUpper_);
Info<< " Creating graph for " << g.title() << endl;
g.write(outDir, graph::wordify(g.title()), graphFormat_);
writeFreqDataToFile(os, f, SPL(PSDf*deltaf, f));
}
if (writeOctaves_)
@ -205,26 +186,38 @@ void pointNoise::processData
// Integrated PSD = P(rms)^2 [Pa^2]
scalarField Prms13f(octaves(PSDf, f, octave13BandIDs));
graph g
auto filePtr = newFile(outDir/"SPL13_dB_fm");
auto& os = filePtr();
Info<< " Writing " << os.name() << endl;
writeFileHeader
(
"SPL13_dB(fm)",
os,
"fm [Hz]",
"SPL(fm) [" + weightingTypeNames_[SPLweighting_] + "]",
"SPL(fm) [" + weightingTypeNames_[SPLweighting_] + "]"
);
writeFreqDataToFile
(
os,
octave13FreqCentre,
SPL(Prms13f, octave13FreqCentre)
);
Info<< " Creating graph for " << g.title() << endl;
g.write(outDir, graph::wordify(g.title()), graphFormat_);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
pointNoise::pointNoise(const dictionary& dict, const bool readFields)
pointNoise::pointNoise
(
const dictionary& dict,
const objectRegistry& obr,
const word& name,
const bool readFields
)
:
noiseModel(dict, false)
noiseModel(dict, obr, name, false)
{
if (readFields)
{

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015-2016 OpenCFD Ltd.
Copyright (C) 2015-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -62,8 +62,6 @@ Description
separator " ";
mergeSeparators yes;
graphFormat raw;
\endverbatim
SourceFiles
@ -129,7 +127,13 @@ public:
TypeName("pointNoise");
//- Constructor
pointNoise(const dictionary& dict, const bool readFields = true);
pointNoise
(
const dictionary& dict,
const objectRegistry& obr,
const word& name = typeName,
const bool readFields = true
);
//- Destructor
virtual ~pointNoise() = default;

View File

@ -29,7 +29,6 @@ License
#include "surfaceReader.H"
#include "surfaceWriter.H"
#include "argList.H"
#include "graph.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -441,9 +440,15 @@ scalar surfaceNoise::surfaceAverage
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
surfaceNoise::surfaceNoise(const dictionary& dict, const bool readFields)
surfaceNoise::surfaceNoise
(
const dictionary& dict,
const objectRegistry& obr,
const word& name,
const bool readFields
)
:
noiseModel(dict, false),
noiseModel(dict, obr, name, false),
inputFileNames_(),
pName_("p"),
pIndex_(0),
@ -648,7 +653,7 @@ void surfaceNoise::calculate()
const word fNameBase = fName.nameLessExt();
// Output directory for graphs
// Output directory
fileName outDirBase(baseFileDir(filei)/fNameBase);
const scalar deltaf = 1.0/(deltaT_*win.nSamples());
@ -663,8 +668,28 @@ void surfaceNoise::calculate()
<< endl;
}
// Common output information
// Note: hard-coded to read mesh from first time index
scalar surfArea = 0;
label surfSize = 0;
if (Pstream::master())
{
const meshedSurface& surf = readerPtr_->geometry(0);
surfArea = sum(surf.magSf());
surfSize = surf.size();
}
Pstream::broadcast(surfArea);
Pstream::broadcast(surfSize);
List<Tuple2<string, token>> commonInfo =
{
{"Area average", token(word(Switch::name(areaAverage_)))},
{"Area sum", token(surfArea)},
{"Number of faces", token(surfSize)}
};
{
fileName outDir(outDirBase/"fft");
fileName outSurfDir(filePath(outDir));
// Determine frequency range of interest
// Note: frequencies have fixed interval, and are in the range
@ -693,7 +718,7 @@ void surfaceNoise::calculate()
PrmsfAve[i] = writeSurfaceData
(
outDir,
outSurfDir,
fNameBase,
"Prmsf",
freq1[freqI],
@ -704,7 +729,7 @@ void surfaceNoise::calculate()
PSDfAve[i] = writeSurfaceData
(
outDir,
outSurfDir,
fNameBase,
"PSDf",
freq1[freqI],
@ -714,7 +739,7 @@ void surfaceNoise::calculate()
);
writeSurfaceData
(
outDir,
outSurfDir,
fNameBase,
"PSD",
freq1[freqI],
@ -724,7 +749,7 @@ void surfaceNoise::calculate()
);
writeSurfaceData
(
outDir,
outSurfDir,
fNameBase,
"SPL",
freq1[freqI],
@ -737,65 +762,60 @@ void surfaceNoise::calculate()
if (Pstream::master())
{
graph Prmsfg
(
"Average Prms(f)",
"f [Hz]",
"P(f) [Pa]",
fOut,
PrmsfAve
);
Prmsfg.write
(
outDir,
graph::wordify(Prmsfg.title()),
graphFormat_
);
{
auto filePtr = newFile(outDir/"Average_Prms_f");
auto& os = filePtr();
graph PSDfg
(
"Average PSD_f(f)",
"f [Hz]",
"PSD(f) [PaPa_Hz]",
fOut,
PSDfAve
);
PSDfg.write
(
outDir,
graph::wordify(PSDfg.title()),
graphFormat_
);
Info<< " Writing " << os.name() << endl;
graph PSDg
(
"Average PSD_dB_Hz(f)",
"f [Hz]",
"PSD(f) [dB_Hz]",
fOut,
PSD(PSDfAve)
);
PSDg.write
(
outDir,
graph::wordify(PSDg.title()),
graphFormat_
);
writeFileHeader(os, "f [Hz]", "P(f) [Pa]", commonInfo);
writeFreqDataToFile(os, fOut, PrmsfAve);
}
{
auto filePtr = newFile(outDir/"Average_PSD_f_f");
auto& os = filePtr();
graph SPLg
(
"Average SPL_dB(f)",
"f [Hz]",
"SPL(f) [dB]",
fOut,
SPL(PSDfAve*deltaf, fOut)
);
SPLg.write
(
outDir,
graph::wordify(SPLg.title()),
graphFormat_
);
Info<< " Writing " << os.name() << endl;
writeFileHeader
(
os,
"f [Hz]",
"PSD(f) [PaPa_Hz]",
commonInfo
);
writeFreqDataToFile(os, fOut, PSDfAve);
}
{
auto filePtr = newFile(outDir/"Average_PSD_dB_Hz_f");
auto& os = filePtr();
Info<< " Writing " << os.name() << endl;
writeFileHeader
(
os,
"f [Hz]",
"PSD(f) [dB_Hz]",
commonInfo
);
writeFreqDataToFile(os, fOut, PSD(PSDfAve));
}
{
auto filePtr = newFile(outDir/"Average_SPL_dB_f");
auto& os = filePtr();
Info<< " Writing " << os.name() << endl;
writeFileHeader
(
os,
"f [Hz]",
"SPL(f) [dB]",
commonInfo
);
writeFreqDataToFile(os, fOut, SPL(PSDfAve*deltaf, fOut));
}
}
}
@ -803,6 +823,7 @@ void surfaceNoise::calculate()
Info<< "Writing one-third octave surface data" << endl;
{
fileName outDir(outDirBase/"oneThirdOctave");
fileName outSurfDir(filePath(outDir));
scalarField PSDfAve(surfPrms13f.size(), Zero);
scalarField Prms13fAve(surfPrms13f.size(), Zero);
@ -811,7 +832,7 @@ void surfaceNoise::calculate()
{
writeSurfaceData
(
outDir,
outSurfDir,
fNameBase,
"SPL13",
octave13FreqCentre[i],
@ -826,20 +847,24 @@ void surfaceNoise::calculate()
if (Pstream::master())
{
graph SPL13g
auto filePtr = newFile(outDir/"Average_SPL13_dB_fm");
auto& os = filePtr();
Info<< " Writing " << os.name() << endl;
writeFileHeader
(
"Average SPL13_dB(fm)",
os,
"fm [Hz]",
"SPL(fm) [dB]",
commonInfo
);
writeFreqDataToFile
(
os,
octave13FreqCentre,
SPL(Prms13fAve, octave13FreqCentre)
);
SPL13g.write
(
outDir,
graph::wordify(SPL13g.title()),
graphFormat_
);
}
}
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015-2021 OpenCFD Ltd.
Copyright (C) 2015-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -216,7 +216,13 @@ public:
//- Constructor
explicit surfaceNoise(const dictionary& dict, const bool readFields=true);
surfaceNoise
(
const dictionary& dict,
const objectRegistry& obr,
const word& name = typeName,
const bool readFields = true
);
//- Destructor
virtual ~surfaceNoise() = default;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015-2020 OpenCFD Ltd.
Copyright (C) 2015-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -41,14 +41,10 @@ namespace Foam
Foam::windowModel::windowModel(const dictionary& dict, const label nSamples)
:
scalarField(nSamples),
nOverlapSamples_(0),
overlapPercent_(dict.get<scalar>("overlapPercent")),
nOverlapSamples_(floor(overlapPercent_/scalar(100)*nSamples)),
nWindow_(dict.getOrDefault("nWindow", -1))
{
nOverlapSamples_ = floor
(
dict.get<scalar>("overlapPercent")/scalar(100)*nSamples
);
}
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -59,6 +55,18 @@ Foam::label Foam::windowModel::nSamples() const
}
Foam::scalar Foam::windowModel::overlapPercent() const
{
return overlapPercent_;
}
Foam::label Foam::windowModel::nOverlapSamples() const
{
return nOverlapSamples_;
}
Foam::label Foam::windowModel::nWindow() const
{
return nWindow_;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2018 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -59,6 +59,9 @@ protected:
// Protected Data
//- Overlap percent
scalar overlapPercent_;
//- Number of overlap samples per window
label nOverlapSamples_;
@ -108,6 +111,12 @@ public:
//- Return the number of samples in the window
label nSamples() const;
//- Return the overlap percent
scalar overlapPercent() const;
//- Return number of overlap samples per window
label nOverlapSamples() const;
//- Return the number of windows
label nWindow() const;