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-2020 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\*---------------------------------------------------------------------------*/
27
28#include "windowModel.H"
29
30// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31
32namespace Foam
33{
36}
37
38
39// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40
42:
44 nOverlapSamples_(0),
45 nWindow_(dict.getOrDefault("nWindow", -1))
46{
47 nOverlapSamples_ = floor
48 (
49 dict.get<scalar>("overlapPercent")/scalar(100)*nSamples
50 );
51}
52
53
54// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
55
56Foam::label Foam::windowModel::nSamples() const
57{
58 return size();
59}
60
61
62Foam::label Foam::windowModel::nWindow() const
63{
64 return nWindow_;
65}
66
67
68Foam::label Foam::windowModel::nWindowsTotal(label nSamplesTotal) const
69{
70 const label nSamples = this->nSamples();
71
72 return floor((nSamplesTotal - nSamples)/(nSamples - nOverlapSamples_)) + 1;
73}
74
75
76Foam::label Foam::windowModel::validate(const label nSamplesTotal)
77{
78 label nSamples = this->nSamples();
79
80 if (nSamplesTotal < nSamples)
81 {
83 << "Block size N = " << nSamples
84 << " is larger than total number of data points = " << nSamplesTotal
85 << exit(FatalError);
86 }
87
88 const label nWindowAvailable = nWindowsTotal(nSamplesTotal);
89
90 if (nWindow_ == -1)
91 {
92 nWindow_ = nWindowAvailable;
93 }
94
95 if (nWindow_ > nWindowAvailable)
96 {
98 << "Number of data points calculated with " << nWindow_
99 << " windows greater than the total number of data points"
100 << nl
101 << " Block size, N = " << nSamples << nl
102 << " Total number of data points = " << nSamplesTotal << nl
103 << " Maximum number of windows = " << nWindowAvailable << nl
104 << " Requested number of windows = " << nWindow_
105 << exit(FatalError);
106 }
107
108 const label nRequiredSamples =
109 nWindow_*nSamples - (nWindow_ - 1)*nOverlapSamples_;
110
111 Info<< "Windowing:" << nl
112 << " Total samples : " << nSamplesTotal << nl
113 << " Samples per window : " << nSamples << nl
114 << " Number of windows : " << nWindow_ << nl
115 << " Overlap size : " << nOverlapSamples_ << nl
116 << " Required number of samples : " << nRequiredSamples
117 << endl;
118
119 return nRequiredSamples;
120}
121
122
123// ************************************************************************* //
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
virtual void validate()
Validate the turbulence fields after construction.
Definition: kkLOmega.C:597
Base class for windowing models.
Definition: windowModel.H:55
label nWindow() const
Return the number of windows.
Definition: windowModel.C:62
label nWindowsTotal(label nSamplesTotal) const
Return the total number of windows for a given number of samples.
Definition: windowModel.C:68
label nSamples() const
Return the number of samples in the window.
Definition: windowModel.C:56
label nOverlapSamples_
Number of overlap samples per window.
Definition: windowModel.H:62
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
dictionary dict
const label nSamples(pdfDictionary.get< label >("nSamples"))