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");
|
||||
baseDir = baseDir.expand()/"postProcessing"/"noise";
|
||||
word datasetName("input" + Foam::name(dataseti));
|
||||
baseDir =
|
||||
baseDir.expand()
|
||||
/"postProcessing"
|
||||
/"noise"
|
||||
/outputPrefix_
|
||||
/type()
|
||||
/datasetName;
|
||||
|
||||
return baseDir;
|
||||
}
|
||||
|
||||
@ -133,6 +141,7 @@ Foam::noiseModel::noiseModel(const dictionary& dict, const bool readFields)
|
||||
startTime_(0),
|
||||
windowModelPtr_(),
|
||||
graphFormat_("raw"),
|
||||
outputPrefix_(),
|
||||
writePrmsf_(true),
|
||||
writeSPL_(true),
|
||||
writePSD_(true),
|
||||
@ -169,6 +178,7 @@ bool Foam::noiseModel::read(const dictionary& dict)
|
||||
}
|
||||
dict.readIfPresent("startTime", startTime_);
|
||||
dict.readIfPresent("graphFormat", graphFormat_);
|
||||
dict.readIfPresent("outputPrefix", outputPrefix_);
|
||||
|
||||
// Check number of samples - must be a power of 2 for our FFT
|
||||
bool powerOf2 = ((nSamples_ != 0) && !(nSamples_ & (nSamples_ - 1)));
|
||||
|
||||
@ -36,6 +36,8 @@ Description
|
||||
fu 25;
|
||||
startTime 0;
|
||||
|
||||
outputPrefix "test1";
|
||||
|
||||
// Optional write options dictionary
|
||||
writeOptions
|
||||
{
|
||||
@ -49,18 +51,19 @@ Description
|
||||
|
||||
where
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
rhoRef | Reference density | no | 1
|
||||
N | Number of samples in sampling window | no | 65536 (2^16)
|
||||
fl | Lower frequency bounds | no | 25
|
||||
fu | Upper frequency bounds | no | 10000
|
||||
startTime | Start time | no | 0
|
||||
graphFormat | Graph format | no | raw
|
||||
writePrmsf | Write Prmsf data | no | yes
|
||||
writeSPL | Write SPL data | no | yes
|
||||
writePSD | Write PSD data | no | yes
|
||||
writePSDf | Write PSDf data | no | yes
|
||||
writeOctaves| Write octaves data | no | yes
|
||||
Property | Description | Required | Default value
|
||||
rhoRef | Reference density | no | 1
|
||||
N | Number of samples in sampling window | no | 65536 (2^16)
|
||||
fl | Lower frequency bounds | no | 25
|
||||
fu | Upper frequency bounds | no | 10000
|
||||
startTime | Start time | no | 0
|
||||
outputPrefix | Prefix applied to output files| no | ''
|
||||
graphFormat | Graph format | no | raw
|
||||
writePrmsf | Write Prmsf data | no | yes
|
||||
writeSPL | Write SPL data | no | yes
|
||||
writePSD | Write PSD data | no | yes
|
||||
writePSDf | Write PSDf data | no | yes
|
||||
writeOctaves | Write octaves data | no | yes
|
||||
\endtable
|
||||
|
||||
Note
|
||||
@ -138,6 +141,9 @@ protected:
|
||||
|
||||
// Write options
|
||||
|
||||
//- Output file prefix, default = ''
|
||||
fileName outputPrefix_;
|
||||
|
||||
//- Write Prmsf; default = yes
|
||||
bool writePrmsf_;
|
||||
|
||||
@ -178,7 +184,7 @@ protected:
|
||||
) const;
|
||||
|
||||
//- Return the base output directory
|
||||
fileName baseFileDir() const;
|
||||
fileName baseFileDir(const label dataseti) const;
|
||||
|
||||
|
||||
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;
|
||||
|
||||
@ -86,7 +90,7 @@ void pointNoise::processData(const Function1Types::CSV<scalar>& data)
|
||||
windowModelPtr_->validate(t.size());
|
||||
const windowModel& win = windowModelPtr_();
|
||||
const scalar deltaf = 1.0/(deltaT*win.nSamples());
|
||||
fileName outDir(baseFileDir()/typeName/fNameBase);
|
||||
fileName outDir(baseFileDir(dataseti)/fNameBase);
|
||||
|
||||
// Create the fft
|
||||
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 * * * * * * * * * * * * * * //
|
||||
|
||||
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)
|
||||
{
|
||||
if (noiseModel::read(dict))
|
||||
|
||||
@ -117,7 +117,11 @@ protected:
|
||||
) const;
|
||||
|
||||
//- Process the CSV data
|
||||
void processData(const Function1Types::CSV<scalar>& data);
|
||||
void processData
|
||||
(
|
||||
const label dataseti,
|
||||
const Function1Types::CSV<scalar>& data
|
||||
);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
@ -226,8 +226,8 @@ void surfaceNoise::readSurfaceData
|
||||
|
||||
Foam::scalar surfaceNoise::writeSurfaceData
|
||||
(
|
||||
const fileName& outDirBase,
|
||||
const word& fName,
|
||||
const word& groupName,
|
||||
const word& title,
|
||||
const scalar freq,
|
||||
const scalarField& data,
|
||||
@ -237,7 +237,7 @@ Foam::scalar surfaceNoise::writeSurfaceData
|
||||
{
|
||||
Info<< " processing " << title << " for frequency " << freq << endl;
|
||||
|
||||
fileName outDir(baseFileDir()/groupName/Foam::name(freq));
|
||||
const fileName outDir(outDirBase/Foam::name(freq));
|
||||
|
||||
if (Pstream::parRun())
|
||||
{
|
||||
@ -463,9 +463,9 @@ bool surfaceNoise::read(const dictionary& dict)
|
||||
|
||||
void surfaceNoise::calculate()
|
||||
{
|
||||
forAll(inputFileNames_, i)
|
||||
forAll(inputFileNames_, filei)
|
||||
{
|
||||
fileName fName = inputFileNames_[i];
|
||||
fileName fName = inputFileNames_[filei];
|
||||
fName.expand();
|
||||
|
||||
if (!fName.isAbsolute())
|
||||
@ -591,7 +591,7 @@ void surfaceNoise::calculate()
|
||||
const word& fNameBase = fName.name(true);
|
||||
|
||||
// Output directory for graphs
|
||||
fileName outDir(baseFileDir()/typeName/fNameBase);
|
||||
fileName outDirBase(baseFileDir(filei)/fNameBase);
|
||||
|
||||
const scalar deltaf = 1.0/(deltaT_*win.nSamples());
|
||||
Info<< "Writing fft surface data";
|
||||
@ -606,6 +606,8 @@ void surfaceNoise::calculate()
|
||||
}
|
||||
|
||||
{
|
||||
fileName outDir(outDirBase/"fft");
|
||||
|
||||
// Determine frequency range of interest
|
||||
// Note: freqencies have fixed interval, and are in the range
|
||||
// 0 to fftWriteInterval_*(n-1)*deltaf
|
||||
@ -629,12 +631,12 @@ void surfaceNoise::calculate()
|
||||
{
|
||||
label freqI = (i + f0)*fftWriteInterval_;
|
||||
fOut[i] = freq1[freqI];
|
||||
const word gName = "fft";
|
||||
|
||||
|
||||
PrmsfAve[i] = writeSurfaceData
|
||||
(
|
||||
outDir,
|
||||
fNameBase,
|
||||
gName,
|
||||
"Prmsf",
|
||||
freq1[freqI],
|
||||
surfPrmsf[i + f0],
|
||||
@ -644,8 +646,8 @@ void surfaceNoise::calculate()
|
||||
|
||||
PSDfAve[i] = writeSurfaceData
|
||||
(
|
||||
outDir,
|
||||
fNameBase,
|
||||
gName,
|
||||
"PSDf",
|
||||
freq1[freqI],
|
||||
surfPSDf[i + f0],
|
||||
@ -654,8 +656,8 @@ void surfaceNoise::calculate()
|
||||
);
|
||||
writeSurfaceData
|
||||
(
|
||||
outDir,
|
||||
fNameBase,
|
||||
gName,
|
||||
"PSD",
|
||||
freq1[freqI],
|
||||
noiseFFT::PSD(surfPSDf[i + f0]),
|
||||
@ -664,8 +666,8 @@ void surfaceNoise::calculate()
|
||||
);
|
||||
writeSurfaceData
|
||||
(
|
||||
outDir,
|
||||
fNameBase,
|
||||
gName,
|
||||
"SPL",
|
||||
freq1[freqI],
|
||||
noiseFFT::SPL(surfPSDf[i + f0]*deltaf),
|
||||
@ -719,16 +721,17 @@ void surfaceNoise::calculate()
|
||||
|
||||
Info<< "Writing one-third octave surface data" << endl;
|
||||
{
|
||||
fileName outDir(outDirBase/"oneThirdOctave");
|
||||
|
||||
scalarField PSDfAve(surfPSD13f.size(), 0);
|
||||
scalarField Prms13f2Ave(surfPSD13f.size(), 0);
|
||||
|
||||
forAll(surfPSD13f, i)
|
||||
{
|
||||
const word gName = "oneThirdOctave";
|
||||
PSDfAve[i] = writeSurfaceData
|
||||
(
|
||||
outDir,
|
||||
fNameBase,
|
||||
gName,
|
||||
"PSD13f",
|
||||
octave13FreqCentre[i],
|
||||
surfPSD13f[i],
|
||||
@ -737,8 +740,8 @@ void surfaceNoise::calculate()
|
||||
);
|
||||
writeSurfaceData
|
||||
(
|
||||
outDir,
|
||||
fNameBase,
|
||||
gName,
|
||||
"PSD13",
|
||||
octave13FreqCentre[i],
|
||||
noiseFFT::PSD(surfPSD13f[i]),
|
||||
@ -747,8 +750,8 @@ void surfaceNoise::calculate()
|
||||
);
|
||||
writeSurfaceData
|
||||
(
|
||||
outDir,
|
||||
fNameBase,
|
||||
gName,
|
||||
"SPL13",
|
||||
octave13FreqCentre[i],
|
||||
noiseFFT::SPL(surfPrms13f2[i]),
|
||||
|
||||
@ -183,8 +183,8 @@ protected:
|
||||
// Returns the area average value
|
||||
scalar writeSurfaceData
|
||||
(
|
||||
const fileName& outDirBase,
|
||||
const word& fName,
|
||||
const word& groupName,
|
||||
const word& title,
|
||||
const scalar freq,
|
||||
const scalarField& data,
|
||||
|
||||
Reference in New Issue
Block a user