Skip to content

Commit dd9d9a6

Browse files
authored
Apply suggestions from code review
1 parent 2952441 commit dd9d9a6

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

SU2_CFD/src/output/tools/CWindowingTools.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void CWindowedAverage::addValue(su2double valIn, unsigned long curTimeIter,unsig
8484
values.back() = valIn;
8585
}
8686
// Update the windowed-average from the weighted sum of previous samples and the latest sample
87-
totalSum = cachedSum + valIn*GetWndWeight(windowingFunctionId, windowWidth, windowWidth);
87+
totalSum = cachedSum + valIn*GetWndWeight(windowingFunctionId, windowWidth-1, windowWidth-1);
8888
val = totalSum / static_cast<su2double>(windowWidth);
8989
}
9090

@@ -93,11 +93,11 @@ su2double CWindowedAverage::UpdateCachedSum(unsigned long windowWidth) const {
9393
// Handle square window
9494
if (windowingFunctionId == WINDOW_FUNCTION::SQUARE) return val * static_cast<su2double>(windowWidth);
9595
// Handle non-trivial windows
96-
// At this point new samples are not yet added. Therefore: values.size()=windowWidth-1
97-
for (unsigned long curTimeIter = 0; curTimeIter < values.size(); curTimeIter++) {
98-
// integrate over all but the last timestep-bin
99-
weightedSum += values[curTimeIter] * GetWndWeight(windowingFunctionId, curTimeIter, windowWidth);
100-
}
96+
// At this point new samples are not yet added. Therefore: values.size()=windowWidth-1
97+
for (unsigned long curTimeIter = 0; curTimeIter < values.size(); curTimeIter++) {
98+
// integrate over all but the last timestep-bin
99+
weightedSum += values[curTimeIter] * GetWndWeight(windowingFunctionId, curTimeIter, windowWidth);
100+
}
101101
return weightedSum;
102102
}
103103

UnitTests/SU2_CFD/windowing.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ struct CWindowingTest {
7171
};
7272

7373
TEST_CASE("BUMP", "[Windowing]") {
74-
su2double avg = 0;
75-
avg = CWindowingTest::calcAverage(WINDOW_FUNCTION::BUMP, 10, 0);
76-
CHECK(avg == Approx(1.1851).epsilon(0.001));
77-
avg = CWindowingTest::calcAverage(WINDOW_FUNCTION::BUMP, 100, 10);
78-
CHECK(avg == Approx(1.1883).epsilon(0.001));
74+
su2double avg = 0;
75+
avg = CWindowingTest::calcAverage(WINDOW_FUNCTION::BUMP, 10, 0);
76+
CHECK(avg == Approx(1.1851).epsilon(0.001));
77+
avg = CWindowingTest::calcAverage(WINDOW_FUNCTION::BUMP, 100, 10);
78+
CHECK(avg == Approx(1.1883).epsilon(0.001));
7979
}
8080

8181
TEST_CASE("HANN", "[Windowing]") {

0 commit comments

Comments
 (0)