surfaceNoise.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) 2015-2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::noiseModels::surfaceNoise
28 
29 Description
30  Perform noise analysis on surface-based pressure data.
31 
32  Input data is read from a dictionary, e.g.
33 
34  \verbatim
35  // Pressure reference
36  pRef 0;
37 
38  // Number of samples in sampling window, default = 2^16 (=65536)
39  N 4096;
40 
41  // Lower frequency bounds
42  fl 25;
43 
44  // Upper frequency bounds
45  fu 25;
46 
47  // Start time
48  startTime 0;
49 
50  windowModel <modelType>
51  <modelType>Coeffs
52  {
53  ...
54  }
55 
56  // Input file
57  file "postProcessing/faceSource1/surface/patch/patch.case";
58  //files ("postProcessing/faceSource1/surface/patch/patch.case");
59 
60  // Write interval for FFT data, default = 1
61  fftWriteInterval 100;
62 
63  // Area-weighted averaging switch, default = no (ensemble) for backwards
64  // compatibility
65  areaAverage yes;
66 
67  // Surface reader
68  reader ensight;
69 
70  // Surface writer
71  writer ensight; // none
72 
73  // Collate times for ensight output - ensures geometry is only written once
74  writeOptions
75  {
76  ensight
77  {
78  collateTimes true;
79  }
80 
81  // Write Prmsf; default = yes
82  writePrmsf no;
83 
84  // Write SPL; default = yes
85  writeSPL yes;
86 
87  // Write PSD; default = yes
88  writePSD yes;
89 
90  // Write PSDf; default = yes
91  writePSDf no;
92 
93  // Write writeOctaves; default = yes
94  writeOctaves yes;
95  }
96 
97  \endverbatim
98 
99  Communication Options
100  \table
101  Property | Description | Type | Req'd | Dflt
102  commsType | Communication type for send/receive field | word | no | scheduled
103  broadcast | (Experimental) broadcast all fields | bool | no | false
104  \endtable
105 
106 SourceFiles
107  surfaceNoise.C
108 
109 SeeAlso
110  noiseModel.H
111 
112 \*---------------------------------------------------------------------------*/
113 
114 #ifndef Foam_noiseModels_surfaceNoise_H
115 #define Foam_noiseModels_surfaceNoise_H
116 
117 #include "noiseModel.H"
118 #include "scalarField.H"
119 #include "UPstream.H"
120 
121 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
122 
123 namespace Foam
124 {
125 
126 // Forward Declarations
127 class globalIndex;
128 class surfaceReader;
129 class surfaceWriter;
130 
131 namespace noiseModels
132 {
133 
134 /*---------------------------------------------------------------------------*\
135  Class surfaceNoise Declaration
136 \*---------------------------------------------------------------------------*/
137 
138 class surfaceNoise
139 :
140  public noiseModel
141 {
142 protected:
143 
144  // Protected Data
145 
146  //- Input file names
147  List<fileName> inputFileNames_;
148 
149  //- Name of pressure field
150  word pName_;
152  //- Index of pressure field in reader field list
153  label pIndex_;
154 
155  //- Sample times
157 
158  //- Time step (constant)
159  scalar deltaT_;
160 
161  //- Start time index
163 
164  //- Global number of surface faces
165  label nFaces_;
166 
167  //- Frequency data output interval, default = 1
168  // nSamples/2 data points are returned from the FFT, which can
169  // result in a very large number of output files (1 per frequency)
170  label fftWriteInterval_;
171 
172  //- Apply area average; default = no (ensemble average) for backwards
173  //- compatibility
174  bool areaAverage_;
175 
176  //- Use broadcast to send entire field to sub-ranks
178 
179  //- Communication type (for sending/receiving fields)
181 
182  //- Reader type
184 
185  //- Pointer to the surface reader
188  //- Pointer to the surface writer
190 
191 
192  // Protected Member Functions
193 
194  //- Initialise
195  void initialise(const fileName& fName);
196 
197  //- Read surface data
198  void readSurfaceData
199  (
200  const globalIndex& procFaceAddr,
201  List<scalarField>& pData
202  );
203 
204  //- Calculate the area average value
205  scalar surfaceAverage
206  (
207  const scalarField& data,
208  const globalIndex& procFaceAddr
209  ) const;
210 
211  //- Write surface data to file
212  // Returns the area average value
213  scalar writeSurfaceData
214  (
215  const fileName& outDirBase,
216  const word& fName,
217  const word& title,
218  const scalar freq,
219  const scalarField& data,
220  const globalIndex& procFaceAddr,
221  const bool writeSurface
222  ) const;
223 
224 
225 public:
227  //- Runtime type information
228  TypeName("surfaceNoise");
229 
230 
231  //- Constructor
233  (
234  const dictionary& dict,
235  const objectRegistry& obr,
236  const word& name = typeName,
237  const bool readFields = true
238  );
239 
240  //- Destructor
241  virtual ~surfaceNoise() = default;
242 
243 
244  // Public Member Functions
245 
246  //- Read from dictionary
247  virtual bool read(const dictionary& dict);
248 
249  //- Calculate
250  virtual void calculate();
251 };
252 
253 
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 
256 } // End namespace noiseModels
257 } // End namespace Foam
258 
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 
261 #endif
262 
263 // ************************************************************************* //
label nFaces_
Global number of surface faces.
Definition: surfaceNoise.H:192
virtual void calculate()
Calculate.
Definition: surfaceNoise.C:528
dictionary dict
A class for handling file names.
Definition: fileName.H:72
commsTypes
Communications types.
Definition: UPstream.H:72
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
label startTimeIndex_
Start time index.
Definition: surfaceNoise.H:187
void initialise(const fileName &fName)
Initialise.
Definition: surfaceNoise.C:42
scalar surfaceAverage(const scalarField &data, const globalIndex &procFaceAddr) const
Calculate the area average value.
Definition: surfaceNoise.C:252
surfaceNoise(const dictionary &dict, const objectRegistry &obr, const word &name=typeName, const bool readFields=true)
Constructor.
Definition: surfaceNoise.C:428
autoPtr< surfaceWriter > writerPtr_
Pointer to the surface writer.
Definition: surfaceNoise.H:231
word pName_
Name of pressure field.
Definition: surfaceNoise.H:167
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:61
scalarList times_
Sample times.
Definition: surfaceNoise.H:177
scalar writeSurfaceData(const fileName &outDirBase, const word &fName, const word &title, const scalar freq, const scalarField &data, const globalIndex &procFaceAddr, const bool writeSurface) const
Write surface data to file.
Definition: surfaceNoise.C:315
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const NameMatchPredicate &selectedFields, DynamicList< regIOobject *> &storedObjects)
Read the selected GeometricFields of the templated type and store on the objectRegistry.
A class for handling words, derived from Foam::string.
Definition: word.H:63
List< fileName > inputFileNames_
Input file names.
Definition: surfaceNoise.H:162
bool useBroadcast_
Use broadcast to send entire field to sub-ranks.
Definition: surfaceNoise.H:211
virtual bool read(const dictionary &dict)
Read from dictionary.
Definition: surfaceNoise.C:460
TypeName("surfaceNoise")
Runtime type information.
autoPtr< surfaceReader > readerPtr_
Pointer to the surface reader.
Definition: surfaceNoise.H:226
bool areaAverage_
Apply area average; default = no (ensemble average) for backwards compatibility.
Definition: surfaceNoise.H:206
scalar deltaT_
Time step (constant)
Definition: surfaceNoise.H:182
UPstream::commsTypes commType_
Communication type (for sending/receiving fields)
Definition: surfaceNoise.H:216
label fftWriteInterval_
Frequency data output interval, default = 1.
Definition: surfaceNoise.H:200
void readSurfaceData(const globalIndex &procFaceAddr, List< scalarField > &pData)
Read surface data.
Definition: surfaceNoise.C:126
label pIndex_
Index of pressure field in reader field list.
Definition: surfaceNoise.H:172
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
virtual ~surfaceNoise()=default
Destructor.
Registry of regIOobjects.
Namespace for OpenFOAM.