noiseFFT.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2015 OpenFOAM Foundation
9 Copyright (C) 2016-2017 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::noiseFFT
29
30Description
31 Performs FFT of pressure field to generate noise data.
32
33 General functionality:
34 - Pf: fft of the pressure data
35 - meanPf: multi-window mean fft
36 - RMSmeanPf: multi-window RMS mean fft
37 - PSDf: multi-window power spectral density (PSD) in frequency domain
38 - PSD: power spectral density in dB/Hz
39 - SPL: sound pressure level in dB
40
41 Octave-based data:
42 - PSD spectrum
43 - SPL spectrum
44
45SourceFiles
46 noiseFFT.C
47
48SeeAlso
49 windowModel.H
50
51\*---------------------------------------------------------------------------*/
52
53#ifndef noiseFFT_H
54#define noiseFFT_H
55
56#include "scalarField.H"
57#include "graph.H"
58#include "windowModel.H"
59#include <fftw3.h>
60
61// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62
63namespace Foam
64{
65
66/*---------------------------------------------------------------------------*\
67 Class noiseFFT Declaration
68\*---------------------------------------------------------------------------*/
70class noiseFFT
71:
72 public scalarField
73{
74 //- FFTW planner information.
75 // Storage as double for use directly with FFTW.
76 struct planInfo
77 {
78 bool active;
79 label windowSize;
80 List<double> in;
81 List<double> out;
82 fftw_plan plan;
83 };
84
85 //- Octave band information
86 struct octaveBandInfo
87 {
88 label octave;
89
90 // IDs of bin boundaries in pressure data
91 labelList binIDs;
92
93 // Centre frequencies for each bin
94 scalarField centreFreq;
95 };
96
97
98 // Private data
99
100 //- Time spacing of the raw data (uniform)
101 scalar deltaT_;
102
103 //- Plan information for FFTW
104 mutable planInfo planInfo_;
105
106
107public:
108
109 //- Reference pressure
110 static scalar p0;
111
112 //- Construct from pressure field
113 noiseFFT(const scalar deltaT, const label windowSize = -1);
114
115 //- Destructor. Cleanup/destroy plan
116 ~noiseFFT();
117
118
119 // Member Functions
120
121 //- Return the FFT frequencies
123 (
124 const label N,
125 const scalar deltaT
126 );
127
128 //- Return the PSD [dB/Hz]
129 // Input PSD in [Pa^2/Hz]
130 static tmp<scalarField> PSD(const scalarField& PSDf);
131
132 //- Return the SPL [dB]
133 // Input P(rms)^2 in [Pa^2]
134 static tmp<scalarField> SPL(const scalarField& Prms2);
135
136 //- Return a list of the frequency indices wrt f field that
137 // correspond to the bands limits for a given octave
138 static void octaveBandInfo
139 (
140 const scalarField& f,
141 const scalar fLower,
142 const scalar fUpper,
143 const scalar octave,
144 labelList& fBandIDs,
145 scalarField& fCentre
146 );
147
148 //- Set the pressure data
149 //- \note transfers storage to *this
150 void setData(scalarList& data);
151
152 //- Set the pressure data by reading from file with an optional offset
153 void setData(const fileName& pFileName, const label skip = 0);
154
155
156 //- Return the graph of pressure as a function of time
157 graph pt() const;
158
159 //- Return the fft of the given pressure data
160 tmp<scalarField> Pf(const tmp<scalarField>& pn) const;
161
162 //- Return the multi-window mean fft of the complete pressure data [Pa]
163 graph meanPf(const windowModel& window) const;
164
165 //- Return the multi-window RMS mean fft of the complete pressure
166 // data [Pa]
167 graph RMSmeanPf(const windowModel& window) const;
168
169 //- Return the multi-window PSD (power spectral density) of the complete
170 // pressure data [Pa^2/Hz]
171 graph PSDf(const windowModel& window) const;
172
173 //- Return the PSD [dB/Hz]
174 // Takes PSD in [Pa^2/Hz]
175 graph PSD(const graph& gPSDf) const;
176
177 //- Generate octave data
179 (
180 const graph& g,
181 const labelUList& freqBandIDs
182 ) const;
183
184 //- Convert the db into Pa
185 scalar dbToPa(const scalar db) const;
186
187 //- Convert the db-field into Pa
189};
190
191
192// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193
194} // End namespace Foam
195
196// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197
198#endif
199
200// ************************************************************************* //
const uniformDimensionedVectorField & g
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
Database for solution data, solver performance and other reduced data.
Definition: data.H:58
A class for handling file names.
Definition: fileName.H:76
Class to create, store and output qgraph files.
Definition: graph.H:62
Performs FFT of pressure field to generate noise data.
Definition: noiseFFT.H:72
graph meanPf(const windowModel &window) const
Return the multi-window mean fft of the complete pressure data [Pa].
Definition: noiseFFT.C:323
static tmp< scalarField > frequencies(const label N, const scalar deltaT)
Return the FFT frequencies.
Definition: noiseFFT.C:44
static tmp< scalarField > SPL(const scalarField &Prms2)
Return the SPL [dB].
Definition: noiseFFT.C:68
static scalar p0
Reference pressure.
Definition: noiseFFT.H:109
void setData(scalarList &data)
Definition: noiseFFT.C:189
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.
Definition: noiseFFT.C:75
graph pt() const
Return the graph of pressure as a function of time.
Definition: noiseFFT.C:256
graph octaves(const graph &g, const labelUList &freqBandIDs) const
Generate octave data.
Definition: noiseFFT.C:445
static tmp< scalarField > PSD(const scalarField &PSDf)
Return the PSD [dB/Hz].
Definition: noiseFFT.C:62
~noiseFFT()
Destructor. Cleanup/destroy plan.
Definition: noiseFFT.C:176
graph PSDf(const windowModel &window) const
Return the multi-window PSD (power spectral density) of the complete.
Definition: noiseFFT.C:386
scalar dbToPa(const scalar db) const
Convert the db into Pa.
Definition: noiseFFT.C:501
graph RMSmeanPf(const windowModel &window) const
Return the multi-window RMS mean fft of the complete pressure.
Definition: noiseFFT.C:355
tmp< scalarField > Pf(const tmp< scalarField > &pn) const
Return the fft of the given pressure data.
Definition: noiseFFT.C:276
A class for managing temporary objects.
Definition: tmp.H:65
Base class for windowing models.
Definition: windowModel.H:55
Namespace for OpenFOAM.
labelList f(nPoints)
const Vector< label > N(dict.get< Vector< label > >("N"))