52 const scalar deltaf = 1.0/(
N*deltaT);
91 scalar fTest = 15.625;
93 const scalar fRatio =
pow(2, 1.0/octave);
94 const scalar fRatioL2C =
pow(2, 0.5/octave);
116 if (bandIDs.insert(i))
119 fc.
append(fTest*fRatioL2C);
130 fBandIDs = bandIDs.sortedToc();
151 planInfo_.active =
true;
152 planInfo_.windowSize = windowSize;
153 planInfo_.in.
setSize(windowSize);
154 planInfo_.out.
setSize(windowSize);
162 planInfo_.out.
data(),
164 windowSize <= 8192 ? FFTW_MEASURE : FFTW_ESTIMATE
169 planInfo_.active =
false;
178 if (planInfo_.active)
180 planInfo_.active =
false;
181 fftw_destroy_plan(planInfo_.plan);
207 <<
"Cannot read file " << pFileName
213 scalar dummyt, dummyp;
215 for (label i = 0; i < skip; ++i)
219 if (!pFile.good() || pFile.eof())
222 <<
"Number of points in file " << pFileName
223 <<
" is less than the number to be skipped = " << skip
231 scalar t = 0,
T0 = 0, T1 = 0;
235 while (!(pFile >> t).eof())
247 deltaT_ = (T1 -
T0)/pData.size();
280 if (planInfo_.active)
283 if (pn.
size() != planInfo_.windowSize)
286 <<
"Expected pressure data to have " << planInfo_.windowSize
287 <<
" values, but received " << pn.
size() <<
" values"
291 List<double>& in = planInfo_.in;
292 const List<double>& out = planInfo_.out;
299 ::fftw_execute(planInfo_.plan);
301 const label
n = planInfo_.windowSize;
302 const label nBy2 =
n/2;
304 auto& result = tresult.ref();
309 for (label i = 1; i <= nBy2; ++i)
311 const auto re = out[i];
312 const auto im = out[
n - i];
313 result[i] =
sqrt(re*re + im*im);
326 const label nWindow = window.
nWindow();
330 for (label windowI = 0; windowI < nWindow; ++windowI)
332 meanPf += Pf(window.
apply<scalar>(*
this, windowI));
335 meanPf /= scalar(nWindow);
337 scalar deltaf = 1.0/(
N*deltaT_);
358 const label nWindow = window.
nWindow();
361 for (label windowI = 0; windowI < nWindow; ++windowI)
363 RMSMeanPf +=
sqr(Pf(window.
apply<scalar>(*
this, windowI)));
366 RMSMeanPf =
sqrt(RMSMeanPf/scalar(nWindow))/scalar(
N);
368 scalar deltaf = 1.0/(
N*deltaT_);
389 const label nWindow = window.
nWindow();
393 for (label windowI = 0; windowI < nWindow; ++windowI)
395 psd +=
sqr(Pf(window.
apply<scalar>(*
this, windowI)));
398 scalar deltaf = 1.0/(
N*deltaT_);
399 scalar fs = 1.0/deltaT_;
400 psd /= scalar(nWindow)*fs*
N;
450 if (freqBandIDs.
size() < 2)
453 <<
"Octave frequency bands are not defined "
454 <<
"- skipping octaves calculation"
473 for (label bandI = 0; bandI < freqBandIDs.
size() - 1; ++bandI)
475 label fb0 = freqBandIDs[bandI];
476 label fb1 = freqBandIDs[bandI+1];
479 if (fb0 == fb1)
continue;
481 for (label freqI = fb0; freqI < fb1; ++freqI)
484 label f1 =
f[freqI + 1];
485 scalar dataAve = 0.5*(data[freqI] + data[freqI + 1]);
486 octData[bandI] += dataAve*(f1 - f0);
503 return p0*
pow(10.0, db/20.0);
512 return p0*
pow(10.0, db/20.0);
const uniformDimensionedVectorField & g
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
void pop_back(label n=1)
Reduce size by 1 or more elements. Can be called on an empty list.
void append(const T &val)
Copy append an element to the end of this list.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Input from file stream as an ISstream, normally using std::ifstream for the actual input.
bool good() const noexcept
True if next operation might succeed.
bool eof() const noexcept
True if end of input seen.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
void setSize(label n)
Alias for resize().
T & first()
Access first element of the list, position [0].
void size(const label n)
Older name for setAddressableSize.
T & last()
Access last element of the list, position [size()-1].
static tmp< complexField > realTransform1D(const scalarField &field)
Transform real-value data.
A class for handling file names.
Class to create, store and output qgraph files.
const scalarField & y() const
const scalarField & x() const
graph meanPf(const windowModel &window) const
Return the multi-window mean fft of the complete pressure data [Pa].
static tmp< scalarField > frequencies(const label N, const scalar deltaT)
Return the FFT frequencies.
static tmp< scalarField > SPL(const scalarField &Prms2)
Return the SPL [dB].
static scalar p0
Reference pressure.
void setData(scalarList &data)
Set the pressure data.
static void octaveBandInfo(const scalarField &f, const scalar fLower, const scalar fUpper, const scalar octave, labelList &fBandIDs, scalarField &fCentre)
Return a list of the frequency indices wrt f field that.
graph pt() const
Return the graph of pressure as a function of time.
graph octaves(const graph &g, const labelUList &freqBandIDs) const
Generate octave data.
static tmp< scalarField > PSD(const scalarField &PSDf)
Return the PSD [dB/Hz].
~noiseFFT()
Destructor. Cleanup/destroy plan.
graph PSDf(const windowModel &window) const
Return the multi-window PSD (power spectral density) of the complete.
scalar dbToPa(const scalar db) const
Convert the db into Pa.
graph RMSmeanPf(const windowModel &window) const
Return the multi-window RMS mean fft of the complete pressure.
tmp< scalarField > Pf(const tmp< scalarField > &pn) const
Return the fft of the given pressure data.
noiseFFT(const scalar deltaT, const label windowSize=-1)
Construct from pressure field.
A class for managing temporary objects.
void clear() const noexcept
If object pointer points to valid object: delete object and set pointer to nullptr.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Base class for windowing models.
label nWindow() const
Return the number of windows.
tmp< Field< Type > > apply(const Field< Type > &fld, const label windowI) const
Return the windowed data.
label nSamples() const
Return the number of samples in the window.
const volScalarField & p0
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define WarningInFunction
Report a warning using Foam::Warning.
const dimensionedScalar re
Classical electron radius: default SI units: [m].
Different types of constants.
List< label > labelList
A List of labels.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
dimensionedScalar log10(const dimensionedScalar &ds)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
errorManip< error > abort(error &err)
static constexpr const zero Zero
Global zero (0).
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
errorManipArg< error, int > exit(error &err, const int errNo=1)
UList< label > labelUList
A UList of labels.
List< scalar > scalarList
List of scalar.
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &f1, const label comm)
#define forAll(list, i)
Loop across all elements in list.
const Vector< label > N(dict.get< Vector< label > >("N"))