Skip to content

Commit

Permalink
Fixed a potential issue for calcMeanStates. (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
friedenhe authored Apr 7, 2024
1 parent 0fe5c96 commit 3bd4b61
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/adjoint/DASolver/DASolver.C
Original file line number Diff line number Diff line change
Expand Up @@ -9686,9 +9686,11 @@ void DASolver::assignMeanStatesToStates()
/*
Description:
Assigned the calculated meanStates to the primal states and update intermediate vars
NOTE: if meanStatesCalculated_ == 0, we will not assignMeanStatesToStates at the end of the primal.
meanStatesCalculated_ is assigned to 1 if timeIndex >= startTimeIndex in DASolver::calcMeanStates
*/

if (!useMeanStates_)
if (!useMeanStates_ || !meanStatesCalculated_)
{
return;
}
Expand Down Expand Up @@ -9729,6 +9731,9 @@ void DASolver::assignMeanStatesToStates()

// update state BC and intermedate vars
this->updateStateBoundaryConditions();

// after the meanStates is assigned to states, reset meanStatesCalculated_ for the next primal solution.
meanStatesCalculated_ = 0;
}

void DASolver::calcMeanStates()
Expand Down Expand Up @@ -9809,6 +9814,13 @@ void DASolver::calcMeanStates()
}
}
}

// if we have caluclate mean states, i.e., timeIndex >= startTimeIndex, set meanStatesCalculated_ = 1
// this is to avoid setting a large startTime but the flow somehow converge before the startTime is
// triggered. In this case, the meanStates is never calculated and will return the wrong results
// if meanStatesCalculated_ == 0, we will not assignMeanStatesToStates at the end of the primal
// check DASolver::assignMeanStatesToStates
meanStatesCalculated_ = 1;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/adjoint/DASolver/DASolver.H
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ protected:
label useMeanStates_ = 0;
/// if the meanStates is used, what is the step-averaging start
scalar meanStateStart_ = 0.5;
/// whether we have calculated the meanStates, if not (flow converge before meanStateStart_), we will not use meanStates
label meanStatesCalculated_ = 0;

/// step-averaged scalar states
PtrList<volScalarField> meanVolScalarStates_;
Expand Down

0 comments on commit 3bd4b61

Please sign in to comment.