mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Added new structure for run-time selectable data windowing functions
This commit is contained in:
100
src/randomProcesses/windowModels/windowModel/windowModel.C
Normal file
100
src/randomProcesses/windowModels/windowModel/windowModel.C
Normal file
@ -0,0 +1,100 @@
|
||||
#include "windowModel.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(windowModel, 0);
|
||||
defineRunTimeSelectionTable(windowModel, dictionary);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::windowModel::windowModel(const dictionary& dict, const label nSamples)
|
||||
:
|
||||
scalarField(nSamples),
|
||||
nOverlapSamples_(0),
|
||||
nWindow_(dict.lookupOrDefault("nWindow", -1))
|
||||
{
|
||||
scalar prc = readScalar(dict.lookup("overlapPercent"));
|
||||
nOverlapSamples_ = floor(prc/scalar(100)*nSamples);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::windowModel::~windowModel()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::label Foam::windowModel::nSamples() const
|
||||
{
|
||||
return size();
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::windowModel::nWindow() const
|
||||
{
|
||||
return nWindow_;
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::windowModel::nWindowsTotal(label nSamplesTotal) const
|
||||
{
|
||||
const label nSamples = this->nSamples();
|
||||
|
||||
return floor((nSamplesTotal - nSamples)/(nSamples - nOverlapSamples_)) + 1;
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::windowModel::validate(const label nSamplesTotal)
|
||||
{
|
||||
label nSamples = this->nSamples();
|
||||
|
||||
if (nSamplesTotal < nSamples)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Block size N = " << nSamples
|
||||
<< " is larger than total number of data points = " << nSamplesTotal
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
label nWindowAvailable = nWindowsTotal(nSamplesTotal);
|
||||
|
||||
if (nWindow_ == -1)
|
||||
{
|
||||
nWindow_ = nWindowAvailable;
|
||||
}
|
||||
|
||||
if (nWindow_ > nWindowAvailable)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Number of data points calculated with " << nWindow_
|
||||
<< " windows greater than the total number of data points"
|
||||
<< nl
|
||||
<< " Block size, N = " << nSamples << nl
|
||||
<< " Total number of data points = " << nSamplesTotal << nl
|
||||
<< " Maximum number of windows = " << nWindowAvailable << nl
|
||||
<< " Requested number of windows = " << nWindow_
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
label nRequiredSamples =
|
||||
nWindow_*nSamples - (nWindow_ - 1)*nOverlapSamples_;
|
||||
|
||||
Info<< "Windowing:" << nl
|
||||
<< " Total samples : " << nSamplesTotal << nl
|
||||
<< " Samples per window : " << nSamples << nl
|
||||
<< " Number of windows : " << nWindow_ << nl
|
||||
<< " Overlap size : " << nOverlapSamples_ << nl
|
||||
<< " Required number of samples : " << nRequiredSamples
|
||||
<< endl;
|
||||
|
||||
return nRequiredSamples;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
143
src/randomProcesses/windowModels/windowModel/windowModel.H
Normal file
143
src/randomProcesses/windowModels/windowModel/windowModel.H
Normal file
@ -0,0 +1,143 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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::windowModel
|
||||
|
||||
Description
|
||||
Base class for windowing models
|
||||
|
||||
SourceFiles
|
||||
noiseFFT.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef windowModel_H
|
||||
#define windowModel_H
|
||||
|
||||
#include "autoPtr.H"
|
||||
#include "runTimeSelectionTables.H"
|
||||
#include "scalarField.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class windowModel Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class windowModel
|
||||
:
|
||||
public scalarField
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Data
|
||||
|
||||
//- Number of overlap samples per window
|
||||
label nOverlapSamples_;
|
||||
|
||||
//- Number of windows
|
||||
label nWindow_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("windowModel");
|
||||
|
||||
// Declare runtime constructor selection table
|
||||
declareRunTimeSelectionTable
|
||||
(
|
||||
autoPtr,
|
||||
windowModel,
|
||||
dictionary,
|
||||
(
|
||||
const dictionary& dict,
|
||||
const label nSamples
|
||||
),
|
||||
(dict, nSamples)
|
||||
);
|
||||
|
||||
|
||||
//- Construct from dictionary
|
||||
windowModel(const dictionary& dict, const label nSamples);
|
||||
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Return a reference to the selected window model
|
||||
static autoPtr<windowModel> New
|
||||
(
|
||||
const dictionary& dict,
|
||||
const label nSamples
|
||||
);
|
||||
|
||||
|
||||
//- Destuctor
|
||||
virtual ~windowModel();
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Return the number of samples in the window
|
||||
label nSamples() const;
|
||||
|
||||
//- Return the number of windows
|
||||
label nWindow() const;
|
||||
|
||||
//- Return the total number of windows for a given number of samples
|
||||
label nWindowsTotal(label nSamplesTotal) const;
|
||||
|
||||
//- Validate that the window is applicable to the data set size, and
|
||||
// return the number of required data points
|
||||
label validate(label n);
|
||||
|
||||
//- Return the windowed data
|
||||
template<class Type>
|
||||
tmp<Field<Type> > apply
|
||||
(
|
||||
const Field<Type>& fld,
|
||||
const label windowI
|
||||
) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "windowModelTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,63 @@
|
||||
#/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "windowModel.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::autoPtr<Foam::windowModel> Foam::windowModel::New
|
||||
(
|
||||
const dictionary& dict,
|
||||
const label nSamples
|
||||
)
|
||||
{
|
||||
const word modelType(dict.lookup("windowModel"));
|
||||
|
||||
Info<< "Selecting windowModel " << modelType << endl;
|
||||
|
||||
dictionaryConstructorTable::iterator cstrIter =
|
||||
dictionaryConstructorTablePtr_->find(modelType);
|
||||
|
||||
if (cstrIter == dictionaryConstructorTablePtr_->end())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"windowModel::New(const dictionary&, const label)"
|
||||
) << "Unknown windowModel type "
|
||||
<< modelType << nl << nl
|
||||
<< "Valid windowModel types are:" << nl
|
||||
<< dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return autoPtr<windowModel>
|
||||
(
|
||||
cstrIter()(dict.subDict(modelType + "Coeffs"), nSamples)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,84 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class Type>
|
||||
Foam::tmp<Foam::Field<Type> > Foam::windowModel::apply
|
||||
(
|
||||
const Field<Type>& fld,
|
||||
const label windowI
|
||||
) const
|
||||
{
|
||||
label nSamples = this->nSamples();
|
||||
|
||||
if (nSamples > fld.size())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"template<class Type> "
|
||||
"Foam::tmp<Foam::Field<Type> > Foam::windowModel::apply"
|
||||
"("
|
||||
"const Field<Type>&, "
|
||||
"const label"
|
||||
") const"
|
||||
)
|
||||
<< "Number of samples in sampling window is greater than the "
|
||||
<< "size of the input field" << nl
|
||||
<< " input field size = " << fld.size() << nl
|
||||
<< " window size = " << nSamples << nl
|
||||
<< " requested window index = " << windowI
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
|
||||
tmp<Field<Type> > tresult(new Field<Type>(nSamples, pTraits<Type>::zero));
|
||||
Field<Type>& result = tresult();
|
||||
|
||||
label nWindow = nWindowsTotal(fld.size());
|
||||
if (windowI >= nWindow)
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"template<class Type> "
|
||||
"Foam::tmp<Foam::Field<Type> > Foam::windowModel::apply"
|
||||
"("
|
||||
"const Field<Type>&, "
|
||||
"const label"
|
||||
") const"
|
||||
)
|
||||
<< "Requested window " << windowI << " outside of range. "
|
||||
<< "Number of available windows is " << nWindow
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
label windowOffset = windowI*(nSamples - nOverlapSamples_);
|
||||
|
||||
const scalarField& wf = *this;
|
||||
result = wf*SubField<Type>(fld, nSamples, windowOffset);
|
||||
|
||||
return tresult;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user