Documentation 6b54b78464
Loading...
Searching...
No Matches
CWindowingTools.hpp
Go to the documentation of this file.
1/*!
2 * \file signal_processing_toolbox.hpp
3 * \brief Header file for the signal processing toolbox.
4 * \author S. Schotthöfer
5 * \version 8.5.0 "Harrier"
6 *
7 * SU2 Project Website: https://su2code.github.io
8 *
9 * The SU2 Project is maintained by the SU2 Foundation
10 * (http://su2foundation.org)
11 *
12 * Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)
13 *
14 * SU2 is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * SU2 is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with SU2. If not, see <http://www.gnu.org/licenses/>.
26 */
27
28#pragma once
29
30#include <vector>
31#include <limits>
32#include "../../../../Common/include/option_structure.hpp"
33
35public:
36 /*! \brief Returns the value of a windowing function given by windowId at time-step curTimeIter with given time-frame endTimeIter (i.e. endTimeIter=nTimeIter, if one starts windowing at time t =0.)
37 * \param windowId - enum specifing the used window
38 * \param curTimeIter - Current time iteration of the solver
39 * \param endTimeIter - Number of time steps to average over
40 * \return Value of the window-weight-function at time curTimeIter with time-frame endTimeIter
41 */
42 static su2double GetWndWeight(WINDOW_FUNCTION windowId, unsigned long curTimeIter, unsigned long endTimeIter);
43
44protected:
45 // Long time windows
46 /*! \brief Returns the value of the Hann-window function at time-step curTimeIter with given end-time endTimeIter.
47 * \param curTimeIter - Current time iteration of the solver
48 * \param endTimeIter - Number of time steps to average over
49 * \return Value of the window-weight-function at time curTimeIter with end-time endTimeIter
50 */
51 static su2double HannWindow(unsigned long curTimeIter, unsigned long endTimeIter);
52
53 /*! \brief Returns the value of the Hann-Square-window function at time-step i with given end-time endTimeIter.
54 * \param curTimeIter - Current time iteration of the solver
55 * \param endTimeIter - Number of time steps to average over
56 * \return Value of the window-weight-function at time curTimeIter with end-time endTimeIter
57 */
58 static su2double HannSquaredWindow(unsigned long curTimeIter, unsigned long endTimeIter);
59
60 /*! \brief Returns the value of the Bump-window function at time-step i with given end-time endTimeIter.
61 * \param curTimeIter - Current time iteration of the solver
62 * \param endTimeIter - Number of time steps to average over
63 * \return Value of the window-weight-function at time curTimeIter with end-time endTimeIter
64 */
65 static su2double BumpWindow(unsigned long curTimeIter, unsigned long endTimeIter);
66};
67
69private:
70 su2double val = 0.0; /*!< \brief Value of the windowed-time average (of the instantaneous output) from starting time to the current time iteration. */
71 su2double cachedSum = 0.0; /*!< \brief Cached sum of windowWeight*value over all previous iterations. */
72 std::vector<su2double> values; /*!< \brief Vector of instantatneous output values from starting time to the current time iteration.*/
73 unsigned long lastTimeIter = std::numeric_limits<unsigned long>::max();
74 const WINDOW_FUNCTION windowingFunctionId; /*!< \brief ID of the windowing function to use.*/
75
76 public:
77
78 /*!
79 * \brief Creates a new CWindowedAverage with the specified windowing function
80 */
81 inline explicit CWindowedAverage(WINDOW_FUNCTION windowId) : windowingFunctionId(windowId) {
82 if (windowId==WINDOW_FUNCTION::SQUARE) {
83 values.push_back(0.);
84 }
85 }
86
87 /*!
88 * \brief Returns the value of windowed-time average (of the instantaneous output) from starting time to the current time iteration
89 */
90 inline su2double GetVal() const { return val; }
91
92 /*!
93 *\brief Resets the value of windowed-time average (of the instantaneous output) from starting time to the current time iteration to 0.
94 */
95 inline void Reset() {
96 val = 0.0;
97 values.clear();
98 cachedSum = 0.0;
99 lastTimeIter = std::numeric_limits<unsigned long>::max();
100 }
101
102 /*!
103 * \brief Adds the instantaneous output of the current iteration to the values-vector, if the current iteration is greater or equal to the starting iteration.
104 * \param valIn - value of the instantaneous output, that should be added
105 * \param currentIter - current time Iteration
106 * \param startIter - iteration to start the windowed-time average.
107 */
108 void AddValue(su2double valIn, unsigned long curTimeIter,unsigned long startIter = 0);
109
110private:
111 /*!
112 * \brief Caches the weighted sums from a previous time-step for later re-use
113 * \param windowWidth - Total width of the window, over which the samples were weighted during the previous timestep
114 */
115 su2double UpdateCachedSum(unsigned long windowWidth) const;
116};
Definition CWindowingTools.hpp:68
void AddValue(su2double valIn, unsigned long curTimeIter, unsigned long startIter=0)
Adds the instantaneous output of the current iteration to the values-vector, if the current iteration...
Definition CWindowingTools.cpp:69
void Reset()
Resets the value of windowed-time average (of the instantaneous output) from starting time to the cur...
Definition CWindowingTools.hpp:95
CWindowedAverage(WINDOW_FUNCTION windowId)
Creates a new CWindowedAverage with the specified windowing function.
Definition CWindowingTools.hpp:81
su2double GetVal() const
Returns the value of windowed-time average (of the instantaneous output) from starting time to the cu...
Definition CWindowingTools.hpp:90
Definition CWindowingTools.hpp:34
static su2double BumpWindow(unsigned long curTimeIter, unsigned long endTimeIter)
Returns the value of the Bump-window function at time-step i with given end-time endTimeIter.
Definition CWindowingTools.cpp:58
static su2double GetWndWeight(WINDOW_FUNCTION windowId, unsigned long curTimeIter, unsigned long endTimeIter)
Returns the value of a windowing function given by windowId at time-step curTimeIter with given time-...
Definition CWindowingTools.cpp:32
static su2double HannSquaredWindow(unsigned long curTimeIter, unsigned long endTimeIter)
Returns the value of the Hann-Square-window function at time-step i with given end-time endTimeIter.
Definition CWindowingTools.cpp:50
static su2double HannWindow(unsigned long curTimeIter, unsigned long endTimeIter)
Returns the value of the Hann-window function at time-step curTimeIter with given end-time endTimeIte...
Definition CWindowingTools.cpp:42
passivedouble su2double
Definition code_config.hpp:181
WINDOW_FUNCTION
Types of window (weight) functions for cost functional.
Definition option_structure.hpp:1634
@ SQUARE
No weight function (order 1)