From cbfa9f685e8cf200a2fb649a8f519985373d667b Mon Sep 17 00:00:00 2001 From: Andrew Heather <> Date: Tue, 23 Mar 2021 18:09:57 +0000 Subject: [PATCH] ENH: noiseModels - added feedback for the case that frequency range is empty --- .../noise/noiseModels/noiseModel/noiseModel.C | 35 ++++++++++++++++--- .../noise/noiseModels/noiseModel/noiseModel.H | 6 +++- .../noise/noiseModels/pointNoise/pointNoise.C | 2 +- .../noiseModels/surfaceNoise/surfaceNoise.C | 2 +- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/randomProcesses/noise/noiseModels/noiseModel/noiseModel.C b/src/randomProcesses/noise/noiseModels/noiseModel/noiseModel.C index efc36e33463..3bce2b6f0af 100644 --- a/src/randomProcesses/noise/noiseModels/noiseModel/noiseModel.C +++ b/src/randomProcesses/noise/noiseModels/noiseModel/noiseModel.C @@ -237,7 +237,8 @@ Foam::fileName Foam::noiseModel::baseFileDir(const label dataseti) const Foam::tmp<Foam::scalarField> Foam::noiseModel::uniformFrequencies ( - const scalar deltaT + const scalar deltaT, + const bool check ) const { const auto& window = windowModelPtr_(); @@ -247,9 +248,24 @@ Foam::tmp<Foam::scalarField> Foam::noiseModel::uniformFrequencies auto& f = tf.ref(); const scalar deltaf = 1.0/(N*deltaT); + + label nFreq = 0; forAll(f, i) { f[i] = i*deltaf; + + if (f[i] > fLower_ && f[i] < fUpper_) + { + ++nFreq; + } + } + + if (check && nFreq == 0) + { + WarningInFunction + << "No frequencies found in range " + << fLower_ << " to " << fUpper_ + << endl; } return tf; @@ -263,8 +279,6 @@ Foam::tmp<Foam::scalarField> Foam::noiseModel::octaves const labelUList& freqBandIDs ) const { - auto toctData = tmp<scalarField>::New(freqBandIDs.size() - 1, Zero); - if (freqBandIDs.size() < 2) { WarningInFunction @@ -272,11 +286,13 @@ Foam::tmp<Foam::scalarField> Foam::noiseModel::octaves << "- skipping octaves calculation" << endl; - return toctData; + return tmp<scalarField>::New(); } + auto toctData = tmp<scalarField>::New(freqBandIDs.size() - 1, Zero); auto& octData = toctData.ref(); + bitSet bandUsed(freqBandIDs.size() - 1); for (label bandI = 0; bandI < freqBandIDs.size() - 1; ++bandI) { label fb0 = freqBandIDs[bandI]; @@ -290,9 +306,20 @@ Foam::tmp<Foam::scalarField> Foam::noiseModel::octaves label f1 = f[freqI + 1]; scalar dataAve = 0.5*(data[freqI] + data[freqI + 1]); octData[bandI] += dataAve*(f1 - f0); + + bandUsed.set(bandI); } } + bandUsed.flip(); + labelList bandUnused = bandUsed.sortedToc(); + if (bandUnused.size()) + { + WarningInFunction + << "Empty bands found: " << bandUnused.size() << " of " + << bandUsed.size() << endl; + } + return toctData; } diff --git a/src/randomProcesses/noise/noiseModels/noiseModel/noiseModel.H b/src/randomProcesses/noise/noiseModels/noiseModel/noiseModel.H index 380ec389d26..af26b9ba953 100644 --- a/src/randomProcesses/noise/noiseModels/noiseModel/noiseModel.H +++ b/src/randomProcesses/noise/noiseModels/noiseModel/noiseModel.H @@ -246,7 +246,11 @@ protected: //- Create a field of equally spaced frequencies for the current set of //- data - assumes a constant time step - tmp<scalarField> uniformFrequencies(const scalar deltaT) const; + tmp<scalarField> uniformFrequencies + ( + const scalar deltaT, + const bool check + ) const; //- Return a list of the frequency indices wrt f field that correspond //- to the bands limits for a given octave diff --git a/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.C b/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.C index 8606462f1ee..5be43857cb2 100644 --- a/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.C +++ b/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.C @@ -109,7 +109,7 @@ void pointNoise::processData // Narrow band data // ---------------- - scalarField f(uniformFrequencies(deltaT)); + scalarField f(uniformFrequencies(deltaT, true)); // RMS pressure [Pa] if (writePrmsf_) diff --git a/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C b/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C index ea227417c4b..845a7de3e5d 100644 --- a/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C +++ b/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C @@ -515,7 +515,7 @@ void surfaceNoise::calculate() Info<< "Creating noise FFTs" << endl; - const scalarField freq1(uniformFrequencies(deltaT_)); + const scalarField freq1(uniformFrequencies(deltaT_, true)); // Reset desired frequency range if outside actual frequency range fLower_ = min(fLower_, max(freq1)); -- GitLab