Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop OpenFAST for Simulink simulation when trim solution has been found. #930

Merged
merged 7 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions glue-codes/simulink/src/FAST_SFunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,26 @@ static int nTurbines = 1;
static int
checkError(SimStruct *S){

if (ErrStat >= AbortErrLev){
ssPrintf("\n");
ssSetErrorStatus(S, ErrMsg);
mdlTerminate(S); // terminate on error (in case Simulink doesn't do so itself)
return 1;
}
else if (ErrStat >= ErrID_Warn){
ssPrintf("\n");
ssWarning(S, ErrMsg);
}
else if (ErrStat != ErrID_None){
ssPrintf("\n%s\n", ErrMsg);
}
return 0;
if (ErrStat >= AbortErrLev) {
ssPrintf("\n");
if (ErrStat > ErrID_Fatal) { // in case we've reached a trim solution
ssPrintf("%s\n", ErrMsg);
}
else {
ssSetErrorStatus(S, ErrMsg);
}
mdlTerminate(S); // terminate on error (in case Simulink doesn't do so itself)
return 1;
}
else if (ErrStat >= ErrID_Warn) {
ssPrintf("\n");
ssWarning(S, ErrMsg);
}
else if (ErrStat != ErrID_None) {
ssPrintf("\n");
ssPrintf("%s\n", ErrMsg);
}
return 0;

}

Expand Down
5 changes: 5 additions & 0 deletions modules/openfast-library/src/FAST_Library.f90
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ subroutine FAST_Update(iTurb, NumInputs_c, NumOutputs_c, InputAry, OutputAry, Er
ErrMsg = TRIM(ErrMsg)//NewLine//TRIM(ErrMsg2)
end if

! NOTE: if there is ever more than one turbine, this logic will need to be revisited
IF ( Turbine(iTurb)%m_FAST%Lin%FoundSteady) THEN
ErrStat = ErrID_Fatal + 1 ! it's not really "fatal", but we do want to end prematurely; FAST_SFunc.c will look to see that it's larger than AbortErrLev
ErrMsg = TRIM(ErrMsg)//NewLine//"Ending because steady-state trim solution was successfully found."
END IF

! set the outputs for external code here...
! return y_FAST%ChannelNames
Expand Down
2 changes: 1 addition & 1 deletion modules/openfast-library/src/FAST_Subs.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6269,7 +6269,7 @@ SUBROUTINE ExitThisProgram( p_FAST, y_FAST, m_FAST, ED, BD, SrvD, AD14, AD, IfW,
ErrorLevel = ErrLevel_in

! for debugging, let's output the meshes and all of their fields
IF ( ErrorLevel >= AbortErrLev .AND. p_FAST%WrVTK > VTK_None) THEN
IF ( ErrorLevel >= AbortErrLev .AND. p_FAST%WrVTK > VTK_None .and. .not. m_FAST%Lin%FoundSteady) THEN
p_FAST%VTK_OutFileRoot = trim(p_FAST%VTK_OutFileRoot)//'.DebugError'
p_FAST%VTK_fields = .true.
CALL WrVTK_AllMeshes(p_FAST, y_FAST, MeshMapData, ED, BD, AD, IfW, OpFM, HD, SD, ExtPtfm, SrvD, MAPp, FEAM, MD, Orca, IceF, IceD)
Expand Down