diff --git a/src/randomProcesses/windowModels/Hanning/Hanning.C b/src/randomProcesses/windowModels/Hanning/Hanning.C new file mode 100644 index 0000000000000000000000000000000000000000..19a48258ac4ffa8962aaaf8d8d89d83fd26101b1 --- /dev/null +++ b/src/randomProcesses/windowModels/Hanning/Hanning.C @@ -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 + +// ************************************************************************* // diff --git a/src/randomProcesses/windowModels/Hanning/Hanning.H b/src/randomProcesses/windowModels/Hanning/Hanning.H new file mode 100644 index 0000000000000000000000000000000000000000..8a0ca618ed62ab74c9c66ddb0532a581fadfc60c --- /dev/null +++ b/src/randomProcesses/windowModels/Hanning/Hanning.H @@ -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 + +// ************************************************************************* //