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 -------------------------------------------------------------------------------
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 \*---------------------------------------------------------------------------*/
27 
28 #include "Hanning.H"
30 #include "mathematicalConstants.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace 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 
95 bool Hanning::symmetric() const
96 {
97  return symmetric_;
98 }
99 
100 
101 bool Hanning::extended() const
102 {
103  return extended_;
104 }
105 
106 
107 Foam::scalar Hanning::alpha() const
108 {
109  return alpha_;
110 }
111 
112 
113 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
114 
115 } // End namespace windowModels
116 } // End namespace Foam
117 
118 // ************************************************************************* //
Hanning.H
mathematicalConstants.H
Foam::windowModels::Hanning::alpha
scalar alpha() const
Return the window coefficient.
Definition: Hanning.C:107
Foam::windowModels::Hanning::Hanning
Hanning(const dictionary &dict, const label nSamples)
Construct from dictionary.
Definition: Hanning.C:47
Foam::sumSqr
outerProduct1< Type >::type sumSqr(const UList< Type > &f)
Definition: FieldFunctions.C:505
Foam::windowModels::defineTypeNameAndDebug
defineTypeNameAndDebug(Hanning, 0)
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::Field< scalar >
Foam::windowModels::Hanning::symmetric
bool symmetric() const
Return the symmetric flag.
Definition: Hanning.C:95
Foam::constant::mathematical::twoPi
constexpr scalar twoPi(2 *M_PI)
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::windowModels::Hanning::extended_
bool extended_
Extended switch.
Definition: Hanning.H:97
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::windowModels::Hanning::alpha_
scalar alpha_
Window coefficient, default = 0.5.
Definition: Hanning.H:100
Foam::windowModels::Hanning::symmetric_
bool symmetric_
Symmetric switch.
Definition: Hanning.H:94
nSamples
const label nSamples(pdfDictionary.get< label >("nSamples"))
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::windowModels::addToRunTimeSelectionTable
addToRunTimeSelectionTable(windowModel, Hanning, dictionary)
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:144
Foam::sum
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:327
bool
bool
Definition: EEqn.H:20
Foam::windowModel::nSamples
label nSamples() const
Return the number of samples in the window.
Definition: windowModel.C:56
Foam::PtrListOps::get
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
Foam::windowModel
Base class for windowing models.
Definition: windowModel.H:52
Foam::windowModels::Hanning
Hanning window.
Definition: Hanning.H:84
Foam::windowModels::Hanning::extended
bool extended() const
Return the extended flag.
Definition: Hanning.C:101
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:265