mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Added new Hanning window model
This commit is contained in:
122
src/randomProcesses/windowModels/Hanning/Hanning.C
Normal file
122
src/randomProcesses/windowModels/Hanning/Hanning.C
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "Hanning.H"
|
||||||
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
#include "mathematicalConstants.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace windowModels
|
||||||
|
{
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
defineTypeNameAndDebug(Hanning, 0);
|
||||||
|
addToRunTimeSelectionTable(windowModel, Hanning, dictionary);
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Hanning::Hanning(const dictionary& dict, const label nSamples)
|
||||||
|
:
|
||||||
|
windowModel(dict, nSamples),
|
||||||
|
symmetric_(readBool(dict.lookup("symmetric"))),
|
||||||
|
extended_(readBool(dict.lookup("extended"))),
|
||||||
|
alpha_(dict.lookupOrDefault("alpha", 0.5))
|
||||||
|
{
|
||||||
|
// Extend range if required
|
||||||
|
label offset = extended_ ? 1 : 0;
|
||||||
|
scalar m = nSamples - 1 + 2*offset;
|
||||||
|
|
||||||
|
scalarField t(nSamples);
|
||||||
|
forAll(t, i)
|
||||||
|
{
|
||||||
|
t[i] = i + offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
scalarField& wf = *this;
|
||||||
|
wf = (1 - alpha_)*cos(constant::mathematical::twoPi*t/m);
|
||||||
|
|
||||||
|
// Reset second half of window if symmetric
|
||||||
|
if (symmetric_)
|
||||||
|
{
|
||||||
|
label midPointI = 0;
|
||||||
|
if (nSamples % 2 == 0)
|
||||||
|
{
|
||||||
|
midPointI = nSamples/2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
midPointI = (nSamples + 1)/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (label i = 0; i < midPointI; i++)
|
||||||
|
{
|
||||||
|
wf[nSamples - i - 1] = wf[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scalar sumSqr = sum(sqr(wf));
|
||||||
|
|
||||||
|
// Normalisation (if required)
|
||||||
|
wf *= sqrt(nSamples/sumSqr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Hanning::~Hanning()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
bool Hanning::symmetric() const
|
||||||
|
{
|
||||||
|
return symmetric_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Hanning::extended() const
|
||||||
|
{
|
||||||
|
return extended_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::scalar Hanning::alpha() const
|
||||||
|
{
|
||||||
|
return alpha_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace windowModels
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
125
src/randomProcesses/windowModels/Hanning/Hanning.H
Normal file
125
src/randomProcesses/windowModels/Hanning/Hanning.H
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::windowModels::Hanning
|
||||||
|
|
||||||
|
Description
|
||||||
|
Hanning window
|
||||||
|
|
||||||
|
The window is described by the function
|
||||||
|
\f[
|
||||||
|
wf = (1 - \alpha) cos(2 \pi t/m);
|
||||||
|
\f]
|
||||||
|
|
||||||
|
Where:
|
||||||
|
\vartable
|
||||||
|
\alpha | Coefficient with a default value of 0.5
|
||||||
|
t | time
|
||||||
|
m | window width
|
||||||
|
\endvartable
|
||||||
|
|
||||||
|
The window can be further manipulated by the controls:
|
||||||
|
- \c symmetric: force the window to be symmetric
|
||||||
|
- \c extended: extend the window by 1 element at start and end to produce
|
||||||
|
non-zero values at the start and end positions. Note: window is
|
||||||
|
normalised to preserve energy content
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
Hanning.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef Hanning_H
|
||||||
|
#define Hanning_H
|
||||||
|
|
||||||
|
#include "autoPtr.H"
|
||||||
|
#include "runTimeSelectionTables.H"
|
||||||
|
#include "windowModel.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace windowModels
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class Hanning Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class Hanning
|
||||||
|
:
|
||||||
|
public windowModel
|
||||||
|
{
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Protected Member Data
|
||||||
|
|
||||||
|
//- Symmetric switch
|
||||||
|
bool symmetric_;
|
||||||
|
|
||||||
|
//- Extended switch
|
||||||
|
bool extended_;
|
||||||
|
|
||||||
|
//- Window coefficient, default = 0.5
|
||||||
|
scalar alpha_;
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//- Runtime type information
|
||||||
|
TypeName("Hanning");
|
||||||
|
|
||||||
|
|
||||||
|
//- Construct from dictionary
|
||||||
|
Hanning(const dictionary& dict, const label nSamples);
|
||||||
|
|
||||||
|
//- Destuctor
|
||||||
|
virtual ~Hanning();
|
||||||
|
|
||||||
|
|
||||||
|
// Public Member Functions
|
||||||
|
|
||||||
|
//- Return the symmetric flag
|
||||||
|
bool symmetric() const;
|
||||||
|
|
||||||
|
//- Return the extended flag
|
||||||
|
bool extended() const;
|
||||||
|
|
||||||
|
//- Return the window coefficient
|
||||||
|
scalar alpha() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace windowModels
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
Reference in New Issue
Block a user