Skip to content

Commit 3bd4b61

Browse files
authored
Fixed a potential issue for calcMeanStates. (#620)
1 parent 0fe5c96 commit 3bd4b61

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/adjoint/DASolver/DASolver.C

+13-1
Original file line numberDiff line numberDiff line change
@@ -9686,9 +9686,11 @@ void DASolver::assignMeanStatesToStates()
96869686
/*
96879687
Description:
96889688
Assigned the calculated meanStates to the primal states and update intermediate vars
9689+
NOTE: if meanStatesCalculated_ == 0, we will not assignMeanStatesToStates at the end of the primal.
9690+
meanStatesCalculated_ is assigned to 1 if timeIndex >= startTimeIndex in DASolver::calcMeanStates
96899691
*/
96909692

9691-
if (!useMeanStates_)
9693+
if (!useMeanStates_ || !meanStatesCalculated_)
96929694
{
96939695
return;
96949696
}
@@ -9729,6 +9731,9 @@ void DASolver::assignMeanStatesToStates()
97299731

97309732
// update state BC and intermedate vars
97319733
this->updateStateBoundaryConditions();
9734+
9735+
// after the meanStates is assigned to states, reset meanStatesCalculated_ for the next primal solution.
9736+
meanStatesCalculated_ = 0;
97329737
}
97339738

97349739
void DASolver::calcMeanStates()
@@ -9809,6 +9814,13 @@ void DASolver::calcMeanStates()
98099814
}
98109815
}
98119816
}
9817+
9818+
// if we have caluclate mean states, i.e., timeIndex >= startTimeIndex, set meanStatesCalculated_ = 1
9819+
// this is to avoid setting a large startTime but the flow somehow converge before the startTime is
9820+
// triggered. In this case, the meanStates is never calculated and will return the wrong results
9821+
// if meanStatesCalculated_ == 0, we will not assignMeanStatesToStates at the end of the primal
9822+
// check DASolver::assignMeanStatesToStates
9823+
meanStatesCalculated_ = 1;
98129824
}
98139825
}
98149826

src/adjoint/DASolver/DASolver.H

+2
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ protected:
209209
label useMeanStates_ = 0;
210210
/// if the meanStates is used, what is the step-averaging start
211211
scalar meanStateStart_ = 0.5;
212+
/// whether we have calculated the meanStates, if not (flow converge before meanStateStart_), we will not use meanStates
213+
label meanStatesCalculated_ = 0;
212214

213215
/// step-averaged scalar states
214216
PtrList<volScalarField> meanVolScalarStates_;

0 commit comments

Comments
 (0)