Loading...
Searching...
No Matches
windowModel.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) 2015-2022 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\*---------------------------------------------------------------------------*/
28#include "windowModel.H"
29
30// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31
32namespace Foam
33{
36}
37
38
39// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40
42:
44 overlapPercent_(dict.get<scalar>("overlapPercent")),
46 nWindow_(dict.getOrDefault("nWindow", -1))
47{}
48
49
50// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52Foam::label Foam::windowModel::nSamples() const
53{
54 return size();
55}
56
58Foam::scalar Foam::windowModel::overlapPercent() const
59{
60 return overlapPercent_;
61}
62
64Foam::label Foam::windowModel::nOverlapSamples() const
65{
66 return nOverlapSamples_;
67}
68
70Foam::label Foam::windowModel::nWindow() const
71{
72 return nWindow_;
73}
74
75
76Foam::label Foam::windowModel::nWindowsTotal(label nSamplesTotal) const
78 const label nSamples = this->nSamples();
79
80 return floor((nSamplesTotal - nSamples)/(nSamples - nOverlapSamples_)) + 1;
81}
82
83
84Foam::label Foam::windowModel::validate(const label nSamplesTotal)
85{
86 label nSamples = this->nSamples();
87
88 if (nSamplesTotal < nSamples)
89 {
91 << "Block size N = " << nSamples
92 << " is larger than total number of data points = " << nSamplesTotal
93 << exit(FatalError);
94 }
95
96 const label nWindowAvailable = nWindowsTotal(nSamplesTotal);
97
98 if (nWindow_ == -1)
99 {
100 nWindow_ = nWindowAvailable;
101 }
102
103 if (nWindow_ > nWindowAvailable)
104 {
106 << "Number of data points calculated with " << nWindow_
107 << " windows greater than the total number of data points"
108 << nl
109 << " Block size, N = " << nSamples << nl
110 << " Total number of data points = " << nSamplesTotal << nl
111 << " Maximum number of windows = " << nWindowAvailable << nl
112 << " Requested number of windows = " << nWindow_
113 << exit(FatalError);
114 }
115
116 const label nRequiredSamples =
117 nWindow_*nSamples - (nWindow_ - 1)*nOverlapSamples_;
118
119 Info<< "Windowing:" << nl
120 << " Total samples : " << nSamplesTotal << nl
121 << " Samples per window : " << nSamples << nl
122 << " Number of windows : " << nWindow_ << nl
123 << " Overlap size : " << nOverlapSamples_ << nl
124 << " Required number of samples : " << nRequiredSamples
125 << endl;
126
127 return nRequiredSamples;
128}
129
130
131// ************************************************************************* //
bool get(const label i) const
Definition UList.H:868
label size() const noexcept
Definition UList.H:706
void size(const label n)
Definition UList.H:118
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Base class for windowing models.
Definition windowModel.H:51
scalar overlapPercent() const
Return the overlap percent.
Definition windowModel.C:51
label nWindow() const
Return the number of windows.
Definition windowModel.C:63
label nWindowsTotal(label nSamplesTotal) const
Return the total number of windows for a given number of samples.
Definition windowModel.C:69
label nSamples() const
Return the number of samples in the window.
Definition windowModel.C:45
label nWindow_
Number of windows.
Definition windowModel.H:70
windowModel(const dictionary &dict, const label nSamples)
Construct from dictionary.
Definition windowModel.C:34
label validate(label n)
Validate that the window is applicable to the data set size, and.
Definition windowModel.C:77
label nOverlapSamples_
Number of overlap samples per window.
Definition windowModel.H:65
scalar overlapPercent_
Overlap percent.
Definition windowModel.H:60
label nOverlapSamples() const
Return number of overlap samples per window.
Definition windowModel.C:57
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere).
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
dictionary dict
const label nSamples(pdfDictionary.get< label >("nSamples"))