From 316bb6e13909351b3068e21b9dd9d57c42e0814f Mon Sep 17 00:00:00 2001 From: andrew-platt Date: Thu, 1 Apr 2021 18:56:46 -0600 Subject: [PATCH 1/2] [BugFix] unallocated AD%y%Rotors when AD14 is used with cpp interface The FillOutputAry_T routine tried to pass Turbine(iTurb)%AD%y%Rotors(1) to FillOutputAry, but the AD%y%Rotors was not allocated for cases where AD15 was not used. The logic within FillOutputAry and the variables passed into it have been modified accordingly. NOTE: this set of routines is only called from the FAST_Library, so this issue would only appear with the cpp interface when AD14 is used (I only know of one Simulink example case that this would affect) --- modules/openfast-library/src/FAST_Library.f90 | 2 +- modules/openfast-library/src/FAST_Subs.f90 | 30 ++++++++----------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/modules/openfast-library/src/FAST_Library.f90 b/modules/openfast-library/src/FAST_Library.f90 index bc6c0af131..144ab5a93c 100644 --- a/modules/openfast-library/src/FAST_Library.f90 +++ b/modules/openfast-library/src/FAST_Library.f90 @@ -214,7 +214,7 @@ subroutine FAST_Start(iTurb, NumInputs_c, NumOutputs_c, InputAry, OutputAry, Err OutputAry(1) = Turbine(iTurb)%m_FAST%t_global OutputAry(2:NumOutputs_c) = Outputs - CALL FAST_Linearize_T(t_initial, 0, Turbine(iTurb), ErrStat, ErrMsg) + CALL FAST_Linearize_T(t_initial, 0, Turbine(iTurb), ErrStat2, ErrMsg2) if (ErrStat2 /= ErrID_None) then ErrStat = max(ErrStat,ErrStat2) ErrMsg = TRIM(ErrMsg)//NewLine//TRIM(ErrMsg2) diff --git a/modules/openfast-library/src/FAST_Subs.f90 b/modules/openfast-library/src/FAST_Subs.f90 index e0742e33d5..c5b63286b6 100644 --- a/modules/openfast-library/src/FAST_Subs.f90 +++ b/modules/openfast-library/src/FAST_Subs.f90 @@ -4762,15 +4762,9 @@ SUBROUTINE WriteOutputToFile(n_t_global, t_global, p_FAST, y_FAST, ED, BD, AD14, IF ( y_FAST%WriteThisStep ) THEN ! Generate glue-code output file - if (allocated(AD%y%rotors)) then CALL WrOutputLine( t_global, p_FAST, y_FAST, IfW%y%WriteOutput, OpFM%y%WriteOutput, ED%y%WriteOutput, & - AD%y%rotors(1)%WriteOutput, SrvD%y%WriteOutput, HD%y%WriteOutput, SD%y%WriteOutput, ExtPtfm%y%WriteOutput, MAPp%y%WriteOutput, & + AD%y, SrvD%y%WriteOutput, HD%y%WriteOutput, SD%y%WriteOutput, ExtPtfm%y%WriteOutput, MAPp%y%WriteOutput, & FEAM%y%WriteOutput, MD%y%WriteOutput, Orca%y%WriteOutput, IceF%y%WriteOutput, IceD%y, BD%y, ErrStat, ErrMsg ) - else - CALL WrOutputLine( t_global, p_FAST, y_FAST, IfW%y%WriteOutput, OpFM%y%WriteOutput, ED%y%WriteOutput, & - (/0.0_ReKi/), SrvD%y%WriteOutput, HD%y%WriteOutput, SD%y%WriteOutput, ExtPtfm%y%WriteOutput, MAPp%y%WriteOutput, & - FEAM%y%WriteOutput, MD%y%WriteOutput, Orca%y%WriteOutput, IceF%y%WriteOutput, IceD%y, BD%y, ErrStat, ErrMsg ) - endif ENDIF @@ -4785,7 +4779,7 @@ SUBROUTINE WriteOutputToFile(n_t_global, t_global, p_FAST, y_FAST, ED, BD, AD14, END SUBROUTINE WriteOutputToFile !---------------------------------------------------------------------------------------------------------------------------------- !> This routine writes the module output to the primary output file(s). -SUBROUTINE WrOutputLine( t, p_FAST, y_FAST, IfWOutput, OpFMOutput, EDOutput, ADOutput, SrvDOutput, HDOutput, SDOutput, ExtPtfmOutput,& +SUBROUTINE WrOutputLine( t, p_FAST, y_FAST, IfWOutput, OpFMOutput, EDOutput, y_AD, SrvDOutput, HDOutput, SDOutput, ExtPtfmOutput,& MAPOutput, FEAMOutput, MDOutput, OrcaOutput, IceFOutput, y_IceD, y_BD, ErrStat, ErrMsg) IMPLICIT NONE @@ -4799,7 +4793,7 @@ SUBROUTINE WrOutputLine( t, p_FAST, y_FAST, IfWOutput, OpFMOutput, EDOutput, ADO REAL(ReKi), INTENT(IN) :: IfWOutput (:) !< InflowWind WriteOutput values REAL(ReKi), INTENT(IN) :: OpFMOutput (:) !< OpenFOAM WriteOutput values REAL(ReKi), INTENT(IN) :: EDOutput (:) !< ElastoDyn WriteOutput values - REAL(ReKi), INTENT(IN) :: ADOutput (:) !< AeroDyn WriteOutput values + TYPE(AD_OutputType), INTENT(IN) :: y_AD !< AeroDyn outputs (WriteOutput values are subset of allocated Rotors) REAL(ReKi), INTENT(IN) :: SrvDOutput (:) !< ServoDyn WriteOutput values REAL(ReKi), INTENT(IN) :: HDOutput (:) !< HydroDyn WriteOutput values REAL(ReKi), INTENT(IN) :: SDOutput (:) !< SubDyn WriteOutput values @@ -4825,7 +4819,7 @@ SUBROUTINE WrOutputLine( t, p_FAST, y_FAST, IfWOutput, OpFMOutput, EDOutput, ADO ErrStat = ErrID_None ErrMsg = '' - CALL FillOutputAry(p_FAST, y_FAST, IfWOutput, OpFMOutput, EDOutput, ADOutput, SrvDOutput, HDOutput, SDOutput, ExtPtfmOutput, & + CALL FillOutputAry(p_FAST, y_FAST, IfWOutput, OpFMOutput, EDOutput, y_AD, SrvDOutput, HDOutput, SDOutput, ExtPtfmOutput, & MAPOutput, FEAMOutput, MDOutput, OrcaOutput, IceFOutput, y_IceD, y_BD, OutputAry) IF (p_FAST%WrTxtOutFile) THEN @@ -4885,7 +4879,7 @@ SUBROUTINE FillOutputAry_T(Turbine, Outputs) CALL FillOutputAry(Turbine%p_FAST, Turbine%y_FAST, Turbine%IfW%y%WriteOutput, Turbine%OpFM%y%WriteOutput, & - Turbine%ED%y%WriteOutput, Turbine%AD%y%rotors(1)%WriteOutput, Turbine%SrvD%y%WriteOutput, & + Turbine%ED%y%WriteOutput, Turbine%AD%y, Turbine%SrvD%y%WriteOutput, & Turbine%HD%y%WriteOutput, Turbine%SD%y%WriteOutput, Turbine%ExtPtfm%y%WriteOutput, Turbine%MAP%y%WriteOutput, & Turbine%FEAM%y%WriteOutput, Turbine%MD%y%WriteOutput, Turbine%Orca%y%WriteOutput, & Turbine%IceF%y%WriteOutput, Turbine%IceD%y, Turbine%BD%y, Outputs) @@ -4894,7 +4888,7 @@ END SUBROUTINE FillOutputAry_T !---------------------------------------------------------------------------------------------------------------------------------- !> This routine concatenates all of the WriteOutput values from the module Output into one array to be written to the FAST !! output file. -SUBROUTINE FillOutputAry(p_FAST, y_FAST, IfWOutput, OpFMOutput, EDOutput, ADOutput, SrvDOutput, HDOutput, SDOutput, ExtPtfmOutput, & +SUBROUTINE FillOutputAry(p_FAST, y_FAST, IfWOutput, OpFMOutput, EDOutput, y_AD, SrvDOutput, HDOutput, SDOutput, ExtPtfmOutput, & MAPOutput, FEAMOutput, MDOutput, OrcaOutput, IceFOutput, y_IceD, y_BD, OutputAry) TYPE(FAST_ParameterType), INTENT(IN) :: p_FAST !< Glue-code simulation parameters @@ -4903,7 +4897,7 @@ SUBROUTINE FillOutputAry(p_FAST, y_FAST, IfWOutput, OpFMOutput, EDOutput, ADOutp REAL(ReKi), INTENT(IN) :: IfWOutput (:) !< InflowWind WriteOutput values REAL(ReKi), INTENT(IN) :: OpFMOutput (:) !< OpenFOAM WriteOutput values REAL(ReKi), INTENT(IN) :: EDOutput (:) !< ElastoDyn WriteOutput values - REAL(ReKi), INTENT(IN) :: ADOutput (:) !< AeroDyn WriteOutput values + TYPE(AD_OutputType), INTENT(IN) :: y_AD !< AeroDyn outputs (WriteOutput values are subset of allocated Rotors) REAL(ReKi), INTENT(IN) :: SrvDOutput (:) !< ServoDyn WriteOutput values REAL(ReKi), INTENT(IN) :: HDOutput (:) !< HydroDyn WriteOutput values REAL(ReKi), INTENT(IN) :: SDOutput (:) !< SubDyn WriteOutput values @@ -4959,10 +4953,12 @@ SUBROUTINE FillOutputAry(p_FAST, y_FAST, IfWOutput, OpFMOutput, EDOutput, ADOutp END IF IF ( y_FAST%numOuts(Module_AD) > 0 ) THEN - indxLast = indxNext + SIZE(ADOutput) - 1 - OutputAry(indxNext:indxLast) = ADOutput - indxNext = IndxLast + 1 - END IF + do i=1,SIZE(y_AD%Rotors) + indxLast = indxNext + SIZE(y_AD%Rotors(i)%WriteOutput) - 1 + OutputAry(indxNext:indxLast) = y_AD%Rotors(i)%WriteOutput + indxNext = IndxLast + 1 + end do + END IF IF ( y_FAST%numOuts(Module_SrvD) > 0 ) THEN indxLast = indxNext + SIZE(SrvDOutput) - 1 From 85971f0a5aeb64addb28e2acac5e730acf0440e0 Mon Sep 17 00:00:00 2001 From: andrew-platt Date: Mon, 12 Apr 2021 15:50:29 -0600 Subject: [PATCH 2/2] FastLib: check allocation of y_AD%Rotors(i)%WriteOutput in output writing loop --- modules/openfast-library/src/FAST_Subs.f90 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/openfast-library/src/FAST_Subs.f90 b/modules/openfast-library/src/FAST_Subs.f90 index c5b63286b6..4fa00deb5f 100644 --- a/modules/openfast-library/src/FAST_Subs.f90 +++ b/modules/openfast-library/src/FAST_Subs.f90 @@ -4954,9 +4954,11 @@ SUBROUTINE FillOutputAry(p_FAST, y_FAST, IfWOutput, OpFMOutput, EDOutput, y_AD, IF ( y_FAST%numOuts(Module_AD) > 0 ) THEN do i=1,SIZE(y_AD%Rotors) - indxLast = indxNext + SIZE(y_AD%Rotors(i)%WriteOutput) - 1 - OutputAry(indxNext:indxLast) = y_AD%Rotors(i)%WriteOutput - indxNext = IndxLast + 1 + if (allocated(y_AD%Rotors(i)%WriteOutput)) then + indxLast = indxNext + SIZE(y_AD%Rotors(i)%WriteOutput) - 1 + OutputAry(indxNext:indxLast) = y_AD%Rotors(i)%WriteOutput + indxNext = IndxLast + 1 + endif end do END IF