Hanning.C
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) 2016-2020 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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\*---------------------------------------------------------------------------*/
27
28#include "Hanning.H"
31
32// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33
34namespace Foam
35{
36namespace windowModels
37{
38
39// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40
43
44
45// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46
48:
50 symmetric_(dict.get<bool>("symmetric")),
51 extended_(dict.get<bool>("extended")),
52 alpha_(dict.getOrDefault<scalar>("alpha", 0.5)) // Hamming = 0.54
53{
54 // Extend range if required
55 const label offset = extended_ ? 1 : 0;
56 const scalar m = nSamples - 1 + 2*offset;
57
59 forAll(t, i)
60 {
61 t[i] = i + offset;
62 }
63
64 scalarField& wf = *this;
66
67 // Reset second half of window if symmetric
68 if (symmetric_)
69 {
70 label midPointI = 0;
71 if (nSamples % 2 == 0)
72 {
73 midPointI = nSamples/2;
74 }
75 else
76 {
77 midPointI = (nSamples + 1)/2;
78 }
79
80 for (label i = 0; i < midPointI; i++)
81 {
82 wf[nSamples - i - 1] = wf[i];
83 }
84 }
85
86 const scalar sumSqr = sum(sqr(wf));
87
88 // Normalisation
89 wf *= sqrt(nSamples/sumSqr);
90}
91
92
93// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
94
96{
97 return symmetric_;
98}
99
100
102{
103 return extended_;
104}
105
106
107Foam::scalar Hanning::alpha() const
108{
109 return alpha_;
110}
111
112
113// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
114
115} // End namespace windowModels
116} // End namespace Foam
117
118// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Base class for windowing models.
Definition: windowModel.H:55
label nSamples() const
Return the number of samples in the window.
Definition: windowModel.C:56
Hanning window.
Definition: Hanning.H:87
bool symmetric() const
Return the symmetric flag.
Definition: Hanning.C:95
bool extended_
Extended switch.
Definition: Hanning.H:97
bool extended() const
Return the extended flag.
Definition: Hanning.C:101
bool symmetric_
Symmetric switch.
Definition: Hanning.H:94
scalar alpha_
Window coefficient, default = 0.5.
Definition: Hanning.H:100
scalar alpha() const
Return the window coefficient.
Definition: Hanning.C:107
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
bool
Definition: EEqn.H:20
constexpr scalar twoPi(2 *M_PI)
Namespace for OpenFOAM.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
dimensionedScalar sqrt(const dimensionedScalar &ds)
outerProduct1< Type >::type sumSqr(const UList< Type > &f)
dimensionedScalar cos(const dimensionedScalar &ds)
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
const label nSamples(pdfDictionary.get< label >("nSamples"))