mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: noiseModels - replaced graph usage by writeFile
Header information now includes, e.g.
f [Hz] vs P(f) [Pa]
Lower frequency: 2.500000e+01
Upper frequency: 5.000000e+03
Window model: Hanning
Window number: 2
Window samples: 512
Window overlap %: 5.000000e+01
dBRef : 2.000000e-05
Area average: false
Area sum : 6.475194e-04
Number of faces: 473
Note: output files now have .dat extension
This commit is contained in:
committed by
Mark OLESEN
parent
f87f0040b8
commit
7c2311aae6
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2015 OpenFOAM Foundation
|
Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||||
Copyright (C) 2016-2021 OpenCFD Ltd.
|
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -127,7 +127,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
IOdictionary dict(dictIO);
|
IOdictionary dict(dictIO);
|
||||||
|
|
||||||
autoPtr<noiseModel> model(noiseModel::New(dict));
|
autoPtr<noiseModel> model(noiseModel::New(dict, runTime));
|
||||||
model->calculate();
|
model->calculate();
|
||||||
|
|
||||||
Info<< nl << "End\n" << endl;
|
Info<< nl << "End\n" << endl;
|
||||||
|
|||||||
@ -76,6 +76,15 @@ Foam::fileName Foam::functionObjects::writeFile::baseTimeDir() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::fileName Foam::functionObjects::writeFile::filePath
|
||||||
|
(
|
||||||
|
const fileName& fName
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return baseFileDir()/prefix_/fName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::autoPtr<Foam::OFstream> Foam::functionObjects::writeFile::newFile
|
Foam::autoPtr<Foam::OFstream> Foam::functionObjects::writeFile::newFile
|
||||||
(
|
(
|
||||||
const fileName& fName
|
const fileName& fName
|
||||||
@ -85,7 +94,7 @@ Foam::autoPtr<Foam::OFstream> Foam::functionObjects::writeFile::newFile
|
|||||||
|
|
||||||
if (Pstream::master() && writeToFile_)
|
if (Pstream::master() && writeToFile_)
|
||||||
{
|
{
|
||||||
fileName outputDir(baseFileDir()/prefix_/fName.path());
|
fileName outputDir(filePath(fName).path());
|
||||||
|
|
||||||
mkDir(outputDir);
|
mkDir(outputDir);
|
||||||
|
|
||||||
|
|||||||
@ -137,6 +137,9 @@ 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 the full path for the supplied file name
|
||||||
|
fileName filePath(const fileName& fName) const;
|
||||||
|
|
||||||
//- Return autoPtr to a new file using file name
|
//- Return autoPtr to a new file using file name
|
||||||
// Note: no check for if the file already exists
|
// Note: no check for if the file already exists
|
||||||
virtual autoPtr<OFstream> newFile(const fileName& fName) const;
|
virtual autoPtr<OFstream> newFile(const fileName& fName) const;
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2015-2021 OpenCFD Ltd.
|
Copyright (C) 2015-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -243,16 +243,58 @@ Foam::fileName Foam::noiseModel::baseFileDir(const label dataseti) const
|
|||||||
{
|
{
|
||||||
return
|
return
|
||||||
(
|
(
|
||||||
argList::envGlobalPath()
|
outputPrefix_
|
||||||
/ functionObject::outputPrefix
|
|
||||||
/ "noise"
|
|
||||||
/ outputPrefix_
|
|
||||||
/ type()
|
/ type()
|
||||||
/ ("input" + Foam::name(dataseti))
|
/ ("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
|
Foam::tmp<Foam::scalarField> Foam::noiseModel::uniformFrequencies
|
||||||
(
|
(
|
||||||
const scalar deltaT,
|
const scalar deltaT,
|
||||||
@ -563,8 +605,15 @@ Foam::scalar Foam::noiseModel::gainD(const scalar f) const
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * 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),
|
dict_(dict),
|
||||||
rhoRef_(1),
|
rhoRef_(1),
|
||||||
nSamples_(65536),
|
nSamples_(65536),
|
||||||
@ -572,7 +621,6 @@ Foam::noiseModel::noiseModel(const dictionary& dict, const bool readFields)
|
|||||||
fUpper_(10000),
|
fUpper_(10000),
|
||||||
startTime_(0),
|
startTime_(0),
|
||||||
windowModelPtr_(),
|
windowModelPtr_(),
|
||||||
graphFormat_("raw"),
|
|
||||||
SPLweighting_(weightingType::none),
|
SPLweighting_(weightingType::none),
|
||||||
dBRef_(2e-5),
|
dBRef_(2e-5),
|
||||||
minPressure_(-0.5*VGREAT),
|
minPressure_(-0.5*VGREAT),
|
||||||
@ -603,12 +651,16 @@ Foam::noiseModel::noiseModel(const dictionary& dict, const bool readFields)
|
|||||||
|
|
||||||
bool Foam::noiseModel::read(const dictionary& dict)
|
bool Foam::noiseModel::read(const dictionary& dict)
|
||||||
{
|
{
|
||||||
|
if (!functionObjects::writeFile::read(dict))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
dict.readIfPresent("rhoRef", rhoRef_);
|
dict.readIfPresent("rhoRef", rhoRef_);
|
||||||
dict.readIfPresent("N", nSamples_);
|
dict.readIfPresent("N", nSamples_);
|
||||||
dict.readIfPresent("fl", fLower_);
|
dict.readIfPresent("fl", fLower_);
|
||||||
dict.readIfPresent("fu", fUpper_);
|
dict.readIfPresent("fu", fUpper_);
|
||||||
dict.readIfPresent("startTime", startTime_);
|
dict.readIfPresent("startTime", startTime_);
|
||||||
dict.readIfPresent("graphFormat", graphFormat_);
|
|
||||||
dict.readIfPresent("minPressure", minPressure_);
|
dict.readIfPresent("minPressure", minPressure_);
|
||||||
dict.readIfPresent("maxPressure", maxPressure_);
|
dict.readIfPresent("maxPressure", maxPressure_);
|
||||||
dict.readIfPresent("outputPrefix", outputPrefix_);
|
dict.readIfPresent("outputPrefix", outputPrefix_);
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2015-2021 OpenCFD Ltd.
|
Copyright (C) 2015-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -64,7 +64,6 @@ Description
|
|||||||
outputPrefix | Prefix applied to output files| no | ''
|
outputPrefix | Prefix applied to output files| no | ''
|
||||||
SPLweighting | Weighting: dBA, dBB, dBC, DBD | no | none
|
SPLweighting | Weighting: dBA, dBB, dBC, DBD | no | none
|
||||||
dBRef | Reference for dB calculation | no | 2e-5
|
dBRef | Reference for dB calculation | no | 2e-5
|
||||||
graphFormat | Graph format | no | raw
|
|
||||||
writePrmsf | Write Prmsf data | no | yes
|
writePrmsf | Write Prmsf data | no | yes
|
||||||
writeSPL | Write SPL data | no | yes
|
writeSPL | Write SPL data | no | yes
|
||||||
writePSD | Write PSD data | no | yes
|
writePSD | Write PSD data | no | yes
|
||||||
@ -80,13 +79,14 @@ SourceFiles
|
|||||||
#ifndef noiseModel_H
|
#ifndef noiseModel_H
|
||||||
#define noiseModel_H
|
#define noiseModel_H
|
||||||
|
|
||||||
|
#include "writeFile.H"
|
||||||
#include "dictionary.H"
|
#include "dictionary.H"
|
||||||
#include "scalarList.H"
|
#include "scalarList.H"
|
||||||
#include "instantList.H"
|
#include "instantList.H"
|
||||||
#include "windowModel.H"
|
#include "windowModel.H"
|
||||||
#include "Enum.H"
|
#include "Enum.H"
|
||||||
|
#include "Tuple2.H"
|
||||||
#include "runTimeSelectionTables.H"
|
#include "runTimeSelectionTables.H"
|
||||||
#include "graph.H"
|
|
||||||
#include <fftw3.h>
|
#include <fftw3.h>
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
@ -99,6 +99,8 @@ namespace Foam
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
class noiseModel
|
class noiseModel
|
||||||
|
:
|
||||||
|
public functionObjects::writeFile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -173,9 +175,6 @@ protected:
|
|||||||
//- Window model
|
//- Window model
|
||||||
autoPtr<windowModel> windowModelPtr_;
|
autoPtr<windowModel> windowModelPtr_;
|
||||||
|
|
||||||
//- Graph format
|
|
||||||
word graphFormat_;
|
|
||||||
|
|
||||||
//- Weighting
|
//- Weighting
|
||||||
weightingType SPLweighting_;
|
weightingType SPLweighting_;
|
||||||
|
|
||||||
@ -252,6 +251,23 @@ protected:
|
|||||||
//- Return the base output directory
|
//- Return the base output directory
|
||||||
fileName baseFileDir(const label dataseti) const;
|
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
|
//- Create a field of equally spaced frequencies for the current set of
|
||||||
//- data - assumes a constant time step
|
//- data - assumes a constant time step
|
||||||
tmp<scalarField> uniformFrequencies
|
tmp<scalarField> uniformFrequencies
|
||||||
@ -334,16 +350,27 @@ public:
|
|||||||
noiseModel,
|
noiseModel,
|
||||||
dictionary,
|
dictionary,
|
||||||
(
|
(
|
||||||
const dictionary& dict
|
const dictionary& dict,
|
||||||
|
const objectRegistry& obr
|
||||||
),
|
),
|
||||||
(dict)
|
(dict, obr)
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Selector
|
//- Selector
|
||||||
static autoPtr<noiseModel> New(const dictionary& dict);
|
static autoPtr<noiseModel> New
|
||||||
|
(
|
||||||
|
const dictionary& dict,
|
||||||
|
const objectRegistry& obr
|
||||||
|
);
|
||||||
|
|
||||||
//- Constructor
|
//- Constructor
|
||||||
noiseModel(const dictionary& dict, const bool readFields = true);
|
noiseModel
|
||||||
|
(
|
||||||
|
const dictionary& dict,
|
||||||
|
const objectRegistry& obr,
|
||||||
|
const word& name,
|
||||||
|
const bool readFields = true
|
||||||
|
);
|
||||||
|
|
||||||
//- Destructor
|
//- Destructor
|
||||||
virtual ~noiseModel() = default;
|
virtual ~noiseModel() = default;
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2016-2021 OpenCFD Ltd.
|
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -29,7 +29,11 @@ License
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * 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"));
|
const word modelType(dict.get<word>("noiseModel"));
|
||||||
|
|
||||||
@ -48,7 +52,10 @@ Foam::autoPtr<Foam::noiseModel> Foam::noiseModel::New(const dictionary& dict)
|
|||||||
) << exit(FatalIOError);
|
) << exit(FatalIOError);
|
||||||
}
|
}
|
||||||
|
|
||||||
return autoPtr<noiseModel>(ctorPtr(dict.subDict(modelType + "Coeffs")));
|
return autoPtr<noiseModel>
|
||||||
|
(
|
||||||
|
ctorPtr(dict.subDict(modelType + "Coeffs"), obr)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2015-2021 OpenCFD Ltd.
|
Copyright (C) 2015-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -113,19 +113,13 @@ void pointNoise::processData
|
|||||||
// RMS pressure [Pa]
|
// RMS pressure [Pa]
|
||||||
if (writePrmsf_)
|
if (writePrmsf_)
|
||||||
{
|
{
|
||||||
graph g
|
auto filePtr = newFile(outDir/"Prms_f");
|
||||||
(
|
auto& os = filePtr();
|
||||||
"Prms(f)",
|
|
||||||
"f [Hz]",
|
|
||||||
"Prms(f) [Pa]",
|
|
||||||
f,
|
|
||||||
RMSmeanPf(p)
|
|
||||||
);
|
|
||||||
|
|
||||||
g.setXRange(fLower_, fUpper_);
|
Info<< " Writing " << os.name() << endl;
|
||||||
|
|
||||||
Info<< " Creating graph for " << g.title() << endl;
|
writeFileHeader(os, "f [Hz]", "Prms(f) [Pa]");
|
||||||
g.write(outDir, graph::wordify(g.title()), graphFormat_);
|
writeFreqDataToFile(os, f, RMSmeanPf(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
// PSD [Pa^2/Hz]
|
// PSD [Pa^2/Hz]
|
||||||
@ -133,55 +127,42 @@ void pointNoise::processData
|
|||||||
|
|
||||||
if (writePSDf_)
|
if (writePSDf_)
|
||||||
{
|
{
|
||||||
graph g
|
auto filePtr = newFile(outDir/"PSD_f");
|
||||||
(
|
auto& os = filePtr();
|
||||||
"PSD(f)",
|
|
||||||
"f [Hz]",
|
|
||||||
"PSD(f) [PaPa_Hz]",
|
|
||||||
f,
|
|
||||||
PSDf
|
|
||||||
);
|
|
||||||
|
|
||||||
g.setXRange(fLower_, fUpper_);
|
Info<< " Writing " << os.name() << endl;
|
||||||
|
|
||||||
Info<< " Creating graph for " << g.title() << endl;
|
writeFileHeader(os, "f [Hz]", "PSD(f) [PaPa_Hz]");
|
||||||
g.write(outDir, graph::wordify(g.title()), graphFormat_);
|
writeFreqDataToFile(os, f, PSDf);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PSD [dB/Hz]
|
// PSD [dB/Hz]
|
||||||
if (writePSD_)
|
if (writePSD_)
|
||||||
{
|
{
|
||||||
graph g
|
auto filePtr = newFile(outDir/"PSD_dB_Hz_f");
|
||||||
(
|
auto& os = filePtr();
|
||||||
"PSD_dB_Hz(f)",
|
|
||||||
"f [Hz]",
|
|
||||||
"PSD(f) [dB_Hz]",
|
|
||||||
f,
|
|
||||||
PSD(PSDf)
|
|
||||||
);
|
|
||||||
|
|
||||||
g.setXRange(fLower_, fUpper_);
|
Info<< " Writing " << os.name() << endl;
|
||||||
|
|
||||||
Info<< " Creating graph for " << g.title() << endl;
|
writeFileHeader(os, "f [Hz]", "PSD(f) [dB_Hz]");
|
||||||
g.write(outDir, graph::wordify(g.title()), graphFormat_);
|
writeFreqDataToFile(os, f, PSD(PSDf));
|
||||||
}
|
}
|
||||||
|
|
||||||
// SPL [dB]
|
// SPL [dB]
|
||||||
if (writeSPL_)
|
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]",
|
"f [Hz]",
|
||||||
"SPL(f) [" + weightingTypeNames_[SPLweighting_] + "]",
|
"SPL(f) [" + weightingTypeNames_[SPLweighting_] + "]"
|
||||||
f,
|
|
||||||
SPL(PSDf*deltaf, f)
|
|
||||||
);
|
);
|
||||||
|
writeFreqDataToFile(os, f, SPL(PSDf*deltaf, f));
|
||||||
g.setXRange(fLower_, fUpper_);
|
|
||||||
|
|
||||||
Info<< " Creating graph for " << g.title() << endl;
|
|
||||||
g.write(outDir, graph::wordify(g.title()), graphFormat_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (writeOctaves_)
|
if (writeOctaves_)
|
||||||
@ -205,26 +186,38 @@ void pointNoise::processData
|
|||||||
// Integrated PSD = P(rms)^2 [Pa^2]
|
// Integrated PSD = P(rms)^2 [Pa^2]
|
||||||
scalarField Prms13f(octaves(PSDf, f, octave13BandIDs));
|
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]",
|
"fm [Hz]",
|
||||||
"SPL(fm) [" + weightingTypeNames_[SPLweighting_] + "]",
|
"SPL(fm) [" + weightingTypeNames_[SPLweighting_] + "]"
|
||||||
|
);
|
||||||
|
writeFreqDataToFile
|
||||||
|
(
|
||||||
|
os,
|
||||||
octave13FreqCentre,
|
octave13FreqCentre,
|
||||||
SPL(Prms13f, octave13FreqCentre)
|
SPL(Prms13f, octave13FreqCentre)
|
||||||
);
|
);
|
||||||
|
|
||||||
Info<< " Creating graph for " << g.title() << endl;
|
|
||||||
g.write(outDir, graph::wordify(g.title()), graphFormat_);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * 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)
|
if (readFields)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2015-2016 OpenCFD Ltd.
|
Copyright (C) 2015-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -62,8 +62,6 @@ Description
|
|||||||
separator " ";
|
separator " ";
|
||||||
mergeSeparators yes;
|
mergeSeparators yes;
|
||||||
|
|
||||||
graphFormat raw;
|
|
||||||
|
|
||||||
\endverbatim
|
\endverbatim
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
@ -129,7 +127,13 @@ public:
|
|||||||
TypeName("pointNoise");
|
TypeName("pointNoise");
|
||||||
|
|
||||||
//- Constructor
|
//- 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
|
//- Destructor
|
||||||
virtual ~pointNoise() = default;
|
virtual ~pointNoise() = default;
|
||||||
|
|||||||
@ -29,7 +29,6 @@ License
|
|||||||
#include "surfaceReader.H"
|
#include "surfaceReader.H"
|
||||||
#include "surfaceWriter.H"
|
#include "surfaceWriter.H"
|
||||||
#include "argList.H"
|
#include "argList.H"
|
||||||
#include "graph.H"
|
|
||||||
#include "addToRunTimeSelectionTable.H"
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
@ -441,9 +440,15 @@ scalar surfaceNoise::surfaceAverage
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * 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_(),
|
inputFileNames_(),
|
||||||
pName_("p"),
|
pName_("p"),
|
||||||
pIndex_(0),
|
pIndex_(0),
|
||||||
@ -648,7 +653,7 @@ void surfaceNoise::calculate()
|
|||||||
|
|
||||||
const word fNameBase = fName.nameLessExt();
|
const word fNameBase = fName.nameLessExt();
|
||||||
|
|
||||||
// Output directory for graphs
|
// Output directory
|
||||||
fileName outDirBase(baseFileDir(filei)/fNameBase);
|
fileName outDirBase(baseFileDir(filei)/fNameBase);
|
||||||
|
|
||||||
const scalar deltaf = 1.0/(deltaT_*win.nSamples());
|
const scalar deltaf = 1.0/(deltaT_*win.nSamples());
|
||||||
@ -663,8 +668,28 @@ void surfaceNoise::calculate()
|
|||||||
<< endl;
|
<< 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 outDir(outDirBase/"fft");
|
||||||
|
fileName outSurfDir(filePath(outDir));
|
||||||
|
|
||||||
// Determine frequency range of interest
|
// Determine frequency range of interest
|
||||||
// Note: frequencies have fixed interval, and are in the range
|
// Note: frequencies have fixed interval, and are in the range
|
||||||
@ -693,7 +718,7 @@ void surfaceNoise::calculate()
|
|||||||
|
|
||||||
PrmsfAve[i] = writeSurfaceData
|
PrmsfAve[i] = writeSurfaceData
|
||||||
(
|
(
|
||||||
outDir,
|
outSurfDir,
|
||||||
fNameBase,
|
fNameBase,
|
||||||
"Prmsf",
|
"Prmsf",
|
||||||
freq1[freqI],
|
freq1[freqI],
|
||||||
@ -704,7 +729,7 @@ void surfaceNoise::calculate()
|
|||||||
|
|
||||||
PSDfAve[i] = writeSurfaceData
|
PSDfAve[i] = writeSurfaceData
|
||||||
(
|
(
|
||||||
outDir,
|
outSurfDir,
|
||||||
fNameBase,
|
fNameBase,
|
||||||
"PSDf",
|
"PSDf",
|
||||||
freq1[freqI],
|
freq1[freqI],
|
||||||
@ -714,7 +739,7 @@ void surfaceNoise::calculate()
|
|||||||
);
|
);
|
||||||
writeSurfaceData
|
writeSurfaceData
|
||||||
(
|
(
|
||||||
outDir,
|
outSurfDir,
|
||||||
fNameBase,
|
fNameBase,
|
||||||
"PSD",
|
"PSD",
|
||||||
freq1[freqI],
|
freq1[freqI],
|
||||||
@ -724,7 +749,7 @@ void surfaceNoise::calculate()
|
|||||||
);
|
);
|
||||||
writeSurfaceData
|
writeSurfaceData
|
||||||
(
|
(
|
||||||
outDir,
|
outSurfDir,
|
||||||
fNameBase,
|
fNameBase,
|
||||||
"SPL",
|
"SPL",
|
||||||
freq1[freqI],
|
freq1[freqI],
|
||||||
@ -737,65 +762,60 @@ void surfaceNoise::calculate()
|
|||||||
|
|
||||||
if (Pstream::master())
|
if (Pstream::master())
|
||||||
{
|
{
|
||||||
graph Prmsfg
|
{
|
||||||
(
|
auto filePtr = newFile(outDir/"Average_Prms_f");
|
||||||
"Average Prms(f)",
|
auto& os = filePtr();
|
||||||
"f [Hz]",
|
|
||||||
"P(f) [Pa]",
|
|
||||||
fOut,
|
|
||||||
PrmsfAve
|
|
||||||
);
|
|
||||||
Prmsfg.write
|
|
||||||
(
|
|
||||||
outDir,
|
|
||||||
graph::wordify(Prmsfg.title()),
|
|
||||||
graphFormat_
|
|
||||||
);
|
|
||||||
|
|
||||||
graph PSDfg
|
Info<< " Writing " << os.name() << endl;
|
||||||
(
|
|
||||||
"Average PSD_f(f)",
|
|
||||||
"f [Hz]",
|
|
||||||
"PSD(f) [PaPa_Hz]",
|
|
||||||
fOut,
|
|
||||||
PSDfAve
|
|
||||||
);
|
|
||||||
PSDfg.write
|
|
||||||
(
|
|
||||||
outDir,
|
|
||||||
graph::wordify(PSDfg.title()),
|
|
||||||
graphFormat_
|
|
||||||
);
|
|
||||||
|
|
||||||
graph PSDg
|
writeFileHeader(os, "f [Hz]", "P(f) [Pa]", commonInfo);
|
||||||
(
|
writeFreqDataToFile(os, fOut, PrmsfAve);
|
||||||
"Average PSD_dB_Hz(f)",
|
}
|
||||||
"f [Hz]",
|
{
|
||||||
"PSD(f) [dB_Hz]",
|
auto filePtr = newFile(outDir/"Average_PSD_f_f");
|
||||||
fOut,
|
auto& os = filePtr();
|
||||||
PSD(PSDfAve)
|
|
||||||
);
|
|
||||||
PSDg.write
|
|
||||||
(
|
|
||||||
outDir,
|
|
||||||
graph::wordify(PSDg.title()),
|
|
||||||
graphFormat_
|
|
||||||
);
|
|
||||||
|
|
||||||
graph SPLg
|
Info<< " Writing " << os.name() << endl;
|
||||||
(
|
|
||||||
"Average SPL_dB(f)",
|
writeFileHeader
|
||||||
"f [Hz]",
|
(
|
||||||
"SPL(f) [dB]",
|
os,
|
||||||
fOut,
|
"f [Hz]",
|
||||||
SPL(PSDfAve*deltaf, fOut)
|
"PSD(f) [PaPa_Hz]",
|
||||||
);
|
commonInfo
|
||||||
SPLg.write
|
);
|
||||||
(
|
writeFreqDataToFile(os, fOut, PSDfAve);
|
||||||
outDir,
|
}
|
||||||
graph::wordify(SPLg.title()),
|
{
|
||||||
graphFormat_
|
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;
|
Info<< "Writing one-third octave surface data" << endl;
|
||||||
{
|
{
|
||||||
fileName outDir(outDirBase/"oneThirdOctave");
|
fileName outDir(outDirBase/"oneThirdOctave");
|
||||||
|
fileName outSurfDir(filePath(outDir));
|
||||||
|
|
||||||
scalarField PSDfAve(surfPrms13f.size(), Zero);
|
scalarField PSDfAve(surfPrms13f.size(), Zero);
|
||||||
scalarField Prms13fAve(surfPrms13f.size(), Zero);
|
scalarField Prms13fAve(surfPrms13f.size(), Zero);
|
||||||
@ -811,7 +832,7 @@ void surfaceNoise::calculate()
|
|||||||
{
|
{
|
||||||
writeSurfaceData
|
writeSurfaceData
|
||||||
(
|
(
|
||||||
outDir,
|
outSurfDir,
|
||||||
fNameBase,
|
fNameBase,
|
||||||
"SPL13",
|
"SPL13",
|
||||||
octave13FreqCentre[i],
|
octave13FreqCentre[i],
|
||||||
@ -826,20 +847,24 @@ void surfaceNoise::calculate()
|
|||||||
|
|
||||||
if (Pstream::master())
|
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]",
|
"fm [Hz]",
|
||||||
"SPL(fm) [dB]",
|
"SPL(fm) [dB]",
|
||||||
|
commonInfo
|
||||||
|
);
|
||||||
|
writeFreqDataToFile
|
||||||
|
(
|
||||||
|
os,
|
||||||
octave13FreqCentre,
|
octave13FreqCentre,
|
||||||
SPL(Prms13fAve, octave13FreqCentre)
|
SPL(Prms13fAve, octave13FreqCentre)
|
||||||
);
|
);
|
||||||
SPL13g.write
|
|
||||||
(
|
|
||||||
outDir,
|
|
||||||
graph::wordify(SPL13g.title()),
|
|
||||||
graphFormat_
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2015-2021 OpenCFD Ltd.
|
Copyright (C) 2015-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -216,7 +216,13 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//- Constructor
|
//- 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
|
//- Destructor
|
||||||
virtual ~surfaceNoise() = default;
|
virtual ~surfaceNoise() = default;
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2015-2020 OpenCFD Ltd.
|
Copyright (C) 2015-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -41,14 +41,10 @@ namespace Foam
|
|||||||
Foam::windowModel::windowModel(const dictionary& dict, const label nSamples)
|
Foam::windowModel::windowModel(const dictionary& dict, const label nSamples)
|
||||||
:
|
:
|
||||||
scalarField(nSamples),
|
scalarField(nSamples),
|
||||||
nOverlapSamples_(0),
|
overlapPercent_(dict.get<scalar>("overlapPercent")),
|
||||||
|
nOverlapSamples_(floor(overlapPercent_/scalar(100)*nSamples)),
|
||||||
nWindow_(dict.getOrDefault("nWindow", -1))
|
nWindow_(dict.getOrDefault("nWindow", -1))
|
||||||
{
|
{}
|
||||||
nOverlapSamples_ = floor
|
|
||||||
(
|
|
||||||
dict.get<scalar>("overlapPercent")/scalar(100)*nSamples
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * 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
|
Foam::label Foam::windowModel::nWindow() const
|
||||||
{
|
{
|
||||||
return nWindow_;
|
return nWindow_;
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2016-2018 OpenCFD Ltd.
|
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -59,6 +59,9 @@ protected:
|
|||||||
|
|
||||||
// Protected Data
|
// Protected Data
|
||||||
|
|
||||||
|
//- Overlap percent
|
||||||
|
scalar overlapPercent_;
|
||||||
|
|
||||||
//- Number of overlap samples per window
|
//- Number of overlap samples per window
|
||||||
label nOverlapSamples_;
|
label nOverlapSamples_;
|
||||||
|
|
||||||
@ -108,6 +111,12 @@ public:
|
|||||||
//- Return the number of samples in the window
|
//- Return the number of samples in the window
|
||||||
label nSamples() const;
|
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
|
//- Return the number of windows
|
||||||
label nWindow() const;
|
label nWindow() const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user