mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: noiseModels - re-worked output directories to avoid clashes. Fixes
Both point- and surfaceNoise utilities can operate on multiple input files. However, if the files had the same name, the output would be overwritten. To avoid this, the output files are now written to a sub-directory including the path '/input<input-file-index>/', e.g. postProcessing/noise/surfaceNoise/input0/nearWall/[fft|oneThirdOctave] An optional 'outputPrefix' can be included (defaults to empty), e.g. when set to 'test1': postProcessing/noise/test1/surfaceNoise/input0/nearWall/[fft|oneThirdOctave]
This commit is contained in:
@ -112,10 +112,18 @@ Foam::label Foam::noiseModel::findStartTimeIndex
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::fileName Foam::noiseModel::baseFileDir() const
|
Foam::fileName Foam::noiseModel::baseFileDir(const label dataseti) const
|
||||||
{
|
{
|
||||||
fileName baseDir("$FOAM_CASE");
|
fileName baseDir("$FOAM_CASE");
|
||||||
baseDir = baseDir.expand()/"postProcessing"/"noise";
|
word datasetName("input" + Foam::name(dataseti));
|
||||||
|
baseDir =
|
||||||
|
baseDir.expand()
|
||||||
|
/"postProcessing"
|
||||||
|
/"noise"
|
||||||
|
/outputPrefix_
|
||||||
|
/type()
|
||||||
|
/datasetName;
|
||||||
|
|
||||||
return baseDir;
|
return baseDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,6 +141,7 @@ Foam::noiseModel::noiseModel(const dictionary& dict, const bool readFields)
|
|||||||
startTime_(0),
|
startTime_(0),
|
||||||
windowModelPtr_(),
|
windowModelPtr_(),
|
||||||
graphFormat_("raw"),
|
graphFormat_("raw"),
|
||||||
|
outputPrefix_(),
|
||||||
writePrmsf_(true),
|
writePrmsf_(true),
|
||||||
writeSPL_(true),
|
writeSPL_(true),
|
||||||
writePSD_(true),
|
writePSD_(true),
|
||||||
@ -169,6 +178,7 @@ bool Foam::noiseModel::read(const dictionary& dict)
|
|||||||
}
|
}
|
||||||
dict.readIfPresent("startTime", startTime_);
|
dict.readIfPresent("startTime", startTime_);
|
||||||
dict.readIfPresent("graphFormat", graphFormat_);
|
dict.readIfPresent("graphFormat", graphFormat_);
|
||||||
|
dict.readIfPresent("outputPrefix", outputPrefix_);
|
||||||
|
|
||||||
// Check number of samples - must be a power of 2 for our FFT
|
// Check number of samples - must be a power of 2 for our FFT
|
||||||
bool powerOf2 = ((nSamples_ != 0) && !(nSamples_ & (nSamples_ - 1)));
|
bool powerOf2 = ((nSamples_ != 0) && !(nSamples_ & (nSamples_ - 1)));
|
||||||
|
|||||||
@ -36,6 +36,8 @@ Description
|
|||||||
fu 25;
|
fu 25;
|
||||||
startTime 0;
|
startTime 0;
|
||||||
|
|
||||||
|
outputPrefix "test1";
|
||||||
|
|
||||||
// Optional write options dictionary
|
// Optional write options dictionary
|
||||||
writeOptions
|
writeOptions
|
||||||
{
|
{
|
||||||
@ -55,12 +57,13 @@ Description
|
|||||||
fl | Lower frequency bounds | no | 25
|
fl | Lower frequency bounds | no | 25
|
||||||
fu | Upper frequency bounds | no | 10000
|
fu | Upper frequency bounds | no | 10000
|
||||||
startTime | Start time | no | 0
|
startTime | Start time | no | 0
|
||||||
|
outputPrefix | Prefix applied to output files| no | ''
|
||||||
graphFormat | Graph format | no | raw
|
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
|
||||||
writePSDf | Write PSDf data | no | yes
|
writePSDf | Write PSDf data | no | yes
|
||||||
writeOctaves| Write octaves data | no | yes
|
writeOctaves | Write octaves data | no | yes
|
||||||
\endtable
|
\endtable
|
||||||
|
|
||||||
Note
|
Note
|
||||||
@ -138,6 +141,9 @@ protected:
|
|||||||
|
|
||||||
// Write options
|
// Write options
|
||||||
|
|
||||||
|
//- Output file prefix, default = ''
|
||||||
|
fileName outputPrefix_;
|
||||||
|
|
||||||
//- Write Prmsf; default = yes
|
//- Write Prmsf; default = yes
|
||||||
bool writePrmsf_;
|
bool writePrmsf_;
|
||||||
|
|
||||||
@ -178,7 +184,7 @@ protected:
|
|||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Return the base output directory
|
//- Return the base output directory
|
||||||
fileName baseFileDir() const;
|
fileName baseFileDir(const label dataseti) const;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -66,7 +66,11 @@ void pointNoise::filterTimeData
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void pointNoise::processData(const Function1Types::CSV<scalar>& data)
|
void pointNoise::processData
|
||||||
|
(
|
||||||
|
const label dataseti,
|
||||||
|
const Function1Types::CSV<scalar>& data
|
||||||
|
)
|
||||||
{
|
{
|
||||||
Info<< "Reading data file " << data.fName() << endl;
|
Info<< "Reading data file " << data.fName() << endl;
|
||||||
|
|
||||||
@ -86,7 +90,7 @@ void pointNoise::processData(const Function1Types::CSV<scalar>& data)
|
|||||||
windowModelPtr_->validate(t.size());
|
windowModelPtr_->validate(t.size());
|
||||||
const windowModel& win = windowModelPtr_();
|
const windowModel& win = windowModelPtr_();
|
||||||
const scalar deltaf = 1.0/(deltaT*win.nSamples());
|
const scalar deltaf = 1.0/(deltaT*win.nSamples());
|
||||||
fileName outDir(baseFileDir()/typeName/fNameBase);
|
fileName outDir(baseFileDir(dataseti)/fNameBase);
|
||||||
|
|
||||||
// Create the fft
|
// Create the fft
|
||||||
noiseFFT nfft(deltaT, p);
|
noiseFFT nfft(deltaT, p);
|
||||||
@ -200,32 +204,6 @@ void pointNoise::processData(const Function1Types::CSV<scalar>& data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
void pointNoise::calculate()
|
|
||||||
{
|
|
||||||
// Point data only handled by master
|
|
||||||
if (!Pstream::master())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
forAll(inputFileNames_, i)
|
|
||||||
{
|
|
||||||
fileName fName = inputFileNames_[i];
|
|
||||||
fName.expand();
|
|
||||||
if (!fName.isAbsolute())
|
|
||||||
{
|
|
||||||
fName = "$FOAM_CASE"/fName;
|
|
||||||
}
|
|
||||||
fName.expand();
|
|
||||||
Function1Types::CSV<scalar> data("pressure", dict_, "Data", fName);
|
|
||||||
processData(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
pointNoise::pointNoise(const dictionary& dict, const bool readFields)
|
pointNoise::pointNoise(const dictionary& dict, const bool readFields)
|
||||||
@ -245,6 +223,32 @@ pointNoise::~pointNoise()
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
void pointNoise::calculate()
|
||||||
|
{
|
||||||
|
// Point data only handled by master
|
||||||
|
if (!Pstream::master())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
forAll(inputFileNames_, filei)
|
||||||
|
{
|
||||||
|
fileName fName = inputFileNames_[filei];
|
||||||
|
fName.expand();
|
||||||
|
if (!fName.isAbsolute())
|
||||||
|
{
|
||||||
|
fName = "$FOAM_CASE"/fName;
|
||||||
|
}
|
||||||
|
fName.expand();
|
||||||
|
Function1Types::CSV<scalar> data("pressure", dict_, "Data", fName);
|
||||||
|
processData(filei, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool pointNoise::read(const dictionary& dict)
|
bool pointNoise::read(const dictionary& dict)
|
||||||
{
|
{
|
||||||
if (noiseModel::read(dict))
|
if (noiseModel::read(dict))
|
||||||
|
|||||||
@ -117,7 +117,11 @@ protected:
|
|||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Process the CSV data
|
//- Process the CSV data
|
||||||
void processData(const Function1Types::CSV<scalar>& data);
|
void processData
|
||||||
|
(
|
||||||
|
const label dataseti,
|
||||||
|
const Function1Types::CSV<scalar>& data
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -226,8 +226,8 @@ void surfaceNoise::readSurfaceData
|
|||||||
|
|
||||||
Foam::scalar surfaceNoise::writeSurfaceData
|
Foam::scalar surfaceNoise::writeSurfaceData
|
||||||
(
|
(
|
||||||
|
const fileName& outDirBase,
|
||||||
const word& fName,
|
const word& fName,
|
||||||
const word& groupName,
|
|
||||||
const word& title,
|
const word& title,
|
||||||
const scalar freq,
|
const scalar freq,
|
||||||
const scalarField& data,
|
const scalarField& data,
|
||||||
@ -237,7 +237,7 @@ Foam::scalar surfaceNoise::writeSurfaceData
|
|||||||
{
|
{
|
||||||
Info<< " processing " << title << " for frequency " << freq << endl;
|
Info<< " processing " << title << " for frequency " << freq << endl;
|
||||||
|
|
||||||
fileName outDir(baseFileDir()/groupName/Foam::name(freq));
|
const fileName outDir(outDirBase/Foam::name(freq));
|
||||||
|
|
||||||
if (Pstream::parRun())
|
if (Pstream::parRun())
|
||||||
{
|
{
|
||||||
@ -463,9 +463,9 @@ bool surfaceNoise::read(const dictionary& dict)
|
|||||||
|
|
||||||
void surfaceNoise::calculate()
|
void surfaceNoise::calculate()
|
||||||
{
|
{
|
||||||
forAll(inputFileNames_, i)
|
forAll(inputFileNames_, filei)
|
||||||
{
|
{
|
||||||
fileName fName = inputFileNames_[i];
|
fileName fName = inputFileNames_[filei];
|
||||||
fName.expand();
|
fName.expand();
|
||||||
|
|
||||||
if (!fName.isAbsolute())
|
if (!fName.isAbsolute())
|
||||||
@ -591,7 +591,7 @@ void surfaceNoise::calculate()
|
|||||||
const word& fNameBase = fName.name(true);
|
const word& fNameBase = fName.name(true);
|
||||||
|
|
||||||
// Output directory for graphs
|
// Output directory for graphs
|
||||||
fileName outDir(baseFileDir()/typeName/fNameBase);
|
fileName outDirBase(baseFileDir(filei)/fNameBase);
|
||||||
|
|
||||||
const scalar deltaf = 1.0/(deltaT_*win.nSamples());
|
const scalar deltaf = 1.0/(deltaT_*win.nSamples());
|
||||||
Info<< "Writing fft surface data";
|
Info<< "Writing fft surface data";
|
||||||
@ -606,6 +606,8 @@ void surfaceNoise::calculate()
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
fileName outDir(outDirBase/"fft");
|
||||||
|
|
||||||
// Determine frequency range of interest
|
// Determine frequency range of interest
|
||||||
// Note: freqencies have fixed interval, and are in the range
|
// Note: freqencies have fixed interval, and are in the range
|
||||||
// 0 to fftWriteInterval_*(n-1)*deltaf
|
// 0 to fftWriteInterval_*(n-1)*deltaf
|
||||||
@ -629,12 +631,12 @@ void surfaceNoise::calculate()
|
|||||||
{
|
{
|
||||||
label freqI = (i + f0)*fftWriteInterval_;
|
label freqI = (i + f0)*fftWriteInterval_;
|
||||||
fOut[i] = freq1[freqI];
|
fOut[i] = freq1[freqI];
|
||||||
const word gName = "fft";
|
|
||||||
|
|
||||||
PrmsfAve[i] = writeSurfaceData
|
PrmsfAve[i] = writeSurfaceData
|
||||||
(
|
(
|
||||||
|
outDir,
|
||||||
fNameBase,
|
fNameBase,
|
||||||
gName,
|
|
||||||
"Prmsf",
|
"Prmsf",
|
||||||
freq1[freqI],
|
freq1[freqI],
|
||||||
surfPrmsf[i + f0],
|
surfPrmsf[i + f0],
|
||||||
@ -644,8 +646,8 @@ void surfaceNoise::calculate()
|
|||||||
|
|
||||||
PSDfAve[i] = writeSurfaceData
|
PSDfAve[i] = writeSurfaceData
|
||||||
(
|
(
|
||||||
|
outDir,
|
||||||
fNameBase,
|
fNameBase,
|
||||||
gName,
|
|
||||||
"PSDf",
|
"PSDf",
|
||||||
freq1[freqI],
|
freq1[freqI],
|
||||||
surfPSDf[i + f0],
|
surfPSDf[i + f0],
|
||||||
@ -654,8 +656,8 @@ void surfaceNoise::calculate()
|
|||||||
);
|
);
|
||||||
writeSurfaceData
|
writeSurfaceData
|
||||||
(
|
(
|
||||||
|
outDir,
|
||||||
fNameBase,
|
fNameBase,
|
||||||
gName,
|
|
||||||
"PSD",
|
"PSD",
|
||||||
freq1[freqI],
|
freq1[freqI],
|
||||||
noiseFFT::PSD(surfPSDf[i + f0]),
|
noiseFFT::PSD(surfPSDf[i + f0]),
|
||||||
@ -664,8 +666,8 @@ void surfaceNoise::calculate()
|
|||||||
);
|
);
|
||||||
writeSurfaceData
|
writeSurfaceData
|
||||||
(
|
(
|
||||||
|
outDir,
|
||||||
fNameBase,
|
fNameBase,
|
||||||
gName,
|
|
||||||
"SPL",
|
"SPL",
|
||||||
freq1[freqI],
|
freq1[freqI],
|
||||||
noiseFFT::SPL(surfPSDf[i + f0]*deltaf),
|
noiseFFT::SPL(surfPSDf[i + f0]*deltaf),
|
||||||
@ -719,16 +721,17 @@ void surfaceNoise::calculate()
|
|||||||
|
|
||||||
Info<< "Writing one-third octave surface data" << endl;
|
Info<< "Writing one-third octave surface data" << endl;
|
||||||
{
|
{
|
||||||
|
fileName outDir(outDirBase/"oneThirdOctave");
|
||||||
|
|
||||||
scalarField PSDfAve(surfPSD13f.size(), 0);
|
scalarField PSDfAve(surfPSD13f.size(), 0);
|
||||||
scalarField Prms13f2Ave(surfPSD13f.size(), 0);
|
scalarField Prms13f2Ave(surfPSD13f.size(), 0);
|
||||||
|
|
||||||
forAll(surfPSD13f, i)
|
forAll(surfPSD13f, i)
|
||||||
{
|
{
|
||||||
const word gName = "oneThirdOctave";
|
|
||||||
PSDfAve[i] = writeSurfaceData
|
PSDfAve[i] = writeSurfaceData
|
||||||
(
|
(
|
||||||
|
outDir,
|
||||||
fNameBase,
|
fNameBase,
|
||||||
gName,
|
|
||||||
"PSD13f",
|
"PSD13f",
|
||||||
octave13FreqCentre[i],
|
octave13FreqCentre[i],
|
||||||
surfPSD13f[i],
|
surfPSD13f[i],
|
||||||
@ -737,8 +740,8 @@ void surfaceNoise::calculate()
|
|||||||
);
|
);
|
||||||
writeSurfaceData
|
writeSurfaceData
|
||||||
(
|
(
|
||||||
|
outDir,
|
||||||
fNameBase,
|
fNameBase,
|
||||||
gName,
|
|
||||||
"PSD13",
|
"PSD13",
|
||||||
octave13FreqCentre[i],
|
octave13FreqCentre[i],
|
||||||
noiseFFT::PSD(surfPSD13f[i]),
|
noiseFFT::PSD(surfPSD13f[i]),
|
||||||
@ -747,8 +750,8 @@ void surfaceNoise::calculate()
|
|||||||
);
|
);
|
||||||
writeSurfaceData
|
writeSurfaceData
|
||||||
(
|
(
|
||||||
|
outDir,
|
||||||
fNameBase,
|
fNameBase,
|
||||||
gName,
|
|
||||||
"SPL13",
|
"SPL13",
|
||||||
octave13FreqCentre[i],
|
octave13FreqCentre[i],
|
||||||
noiseFFT::SPL(surfPrms13f2[i]),
|
noiseFFT::SPL(surfPrms13f2[i]),
|
||||||
|
|||||||
@ -183,8 +183,8 @@ protected:
|
|||||||
// Returns the area average value
|
// Returns the area average value
|
||||||
scalar writeSurfaceData
|
scalar writeSurfaceData
|
||||||
(
|
(
|
||||||
|
const fileName& outDirBase,
|
||||||
const word& fName,
|
const word& fName,
|
||||||
const word& groupName,
|
|
||||||
const word& title,
|
const word& title,
|
||||||
const scalar freq,
|
const scalar freq,
|
||||||
const scalarField& data,
|
const scalarField& data,
|
||||||
|
|||||||
Reference in New Issue
Block a user