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 -------------------------------------------------------------------------------
10 License
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 
32 namespace Foam
33 {
36 }
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
42 :
44  overlapPercent_(dict.get<scalar>("overlapPercent")),
45  nOverlapSamples_(floor(overlapPercent_/scalar(100)*nSamples)),
46  nWindow_(dict.getOrDefault("nWindow", -1))
47 {}
48 
49 
50 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
51 
52 Foam::label Foam::windowModel::nSamples() const
53 {
54  return size();
55 }
56 
57 
58 Foam::scalar Foam::windowModel::overlapPercent() const
59 {
60  return overlapPercent_;
61 }
62 
63 
64 Foam::label Foam::windowModel::nOverlapSamples() const
65 {
66  return nOverlapSamples_;
67 }
68 
69 
70 Foam::label Foam::windowModel::nWindow() const
71 {
72  return nWindow_;
73 }
74 
75 
76 Foam::label Foam::windowModel::nWindowsTotal(label nSamplesTotal) const
77 {
78  const label nSamples = this->nSamples();
79 
80  return floor((nSamplesTotal - nSamples)/(nSamples - nOverlapSamples_)) + 1;
81 }
82 
83 
84 Foam::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 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
dictionary dict
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
label validate(label n)
Validate that the window is applicable to the data set size, and.
Definition: windowModel.C:77
label nWindowsTotal(label nSamplesTotal) const
Return the total number of windows for a given number of samples.
Definition: windowModel.C:69
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
label nWindow() const
Return the number of windows.
Definition: windowModel.C:63
const label nSamples(pdfDictionary.get< label >("nSamples"))
windowModel(const dictionary &dict, const label nSamples)
Construct from dictionary.
Definition: windowModel.C:34
Base class for windowing models.
Definition: windowModel.H:48
label nSamples() const
Return the number of samples in the window.
Definition: windowModel.C:45
scalar overlapPercent() const
Return the overlap percent.
Definition: windowModel.C:51
label size() const noexcept
The number of elements in the container.
Definition: UList.H:671
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
defineTypeNameAndDebug(combustionModel, 0)
label nOverlapSamples() const
Return number of overlap samples per window.
Definition: windowModel.C:57
messageStream Info
Information stream (stdout output on master, null elsewhere)
Namespace for OpenFOAM.