Skip to content

Commit 0e68137

Browse files
committed
Update iTurb indexing in FAST_Library.f90 FSI CFD funcs (See Issue #2096 and PR #2121)
1 parent 2303ded commit 0e68137

File tree

1 file changed

+45
-20
lines changed

1 file changed

+45
-20
lines changed

modules/openfast-library/src/FAST_Library.f90

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -855,15 +855,19 @@ subroutine FAST_CFD_Solution0(iTurb_c, ErrStat_c, ErrMsg_c) BIND (C, NAME='FAST_
855855

856856
end subroutine FAST_CFD_Solution0
857857
!==================================================================================================================================
858-
subroutine FAST_CFD_InitIOarrays_SubStep(iTurb, ErrStat_c, ErrMsg_c) BIND (C, NAME='FAST_CFD_InitIOarrays_SubStep')
858+
subroutine FAST_CFD_InitIOarrays_SubStep(iTurb_c, ErrStat_c, ErrMsg_c) BIND (C, NAME='FAST_CFD_InitIOarrays_SubStep')
859859
!DEC$ ATTRIBUTES DLLEXPORT::FAST_CFD_InitIOarrays_SubStep
860860
IMPLICIT NONE
861861
#ifndef IMPLICIT_DLLEXPORT
862862
!GCC$ ATTRIBUTES DLLEXPORT :: FAST_CFD_InitIOarrays_SubStep
863863
#endif
864-
INTEGER(C_INT), INTENT(IN ) :: iTurb ! Turbine number
864+
INTEGER(C_INT), INTENT(IN ) :: iTurb_c ! Turbine number
865865
INTEGER(C_INT), INTENT( OUT) :: ErrStat_c
866866
CHARACTER(KIND=C_CHAR), INTENT( OUT) :: ErrMsg_c(IntfStrLen)
867+
integer(IntKi) :: iTurb ! turbine number: Fortran indexing (starts at 1 for first turbine)
868+
869+
! transfer turbine index number from C to Fortran indexing (0 to 1 start)
870+
iTurb = int(iTurb_c,IntKi) + 1
867871

868872
call FAST_InitIOarrays_SubStep_T(t_initial, Turbine(iTurb), ErrStat, ErrMsg )
869873

@@ -1159,22 +1163,25 @@ subroutine FAST_CFD_Prework(iTurb_c, ErrStat_c, ErrMsg_c) BIND (C, NAME='FAST_CF
11591163

11601164
end subroutine FAST_CFD_Prework
11611165
!==================================================================================================================================
1162-
subroutine FAST_CFD_UpdateStates(iTurb, ErrStat_c, ErrMsg_c) BIND (C, NAME='FAST_CFD_UpdateStates')
1166+
subroutine FAST_CFD_UpdateStates(iTurb_c, ErrStat_c, ErrMsg_c) BIND (C, NAME='FAST_CFD_UpdateStates')
11631167
!DEC$ ATTRIBUTES DLLEXPORT::FAST_CFD_UpdateStates
11641168
IMPLICIT NONE
11651169
#ifndef IMPLICIT_DLLEXPORT
11661170
!GCC$ ATTRIBUTES DLLEXPORT :: FAST_CFD_UpdateStates
11671171
#endif
1168-
INTEGER(C_INT), INTENT(IN ) :: iTurb ! Turbine number
1172+
INTEGER(C_INT), INTENT(IN ) :: iTurb_c ! Turbine number
11691173
INTEGER(C_INT), INTENT( OUT) :: ErrStat_c
11701174
CHARACTER(KIND=C_CHAR), INTENT( OUT) :: ErrMsg_c(IntfStrLen)
1175+
integer(IntKi) :: iTurb ! turbine number: Fortran indexing (starts at 1 for first turbine)
11711176

1177+
! transfer turbine index number from C to Fortran indexing (0 to 1 start)
1178+
iTurb = int(iTurb_c,IntKi) + 1
11721179

11731180
IF ( n_t_global > Turbine(iTurb)%p_FAST%n_TMax_m1 ) THEN !finish
11741181

11751182
! we can't continue because we might over-step some arrays that are allocated to the size of the simulation
11761183

1177-
if (iTurb .eq. (NumTurbines-1) ) then
1184+
if (iTurb == NumTurbines ) then
11781185
IF (n_t_global == Turbine(iTurb)%p_FAST%n_TMax_m1 + 1) THEN ! we call update an extra time in Simulink, which we can ignore until the time shift with outputs is solved
11791186
n_t_global = n_t_global + 1
11801187
ErrStat_c = ErrID_None
@@ -1198,22 +1205,25 @@ subroutine FAST_CFD_UpdateStates(iTurb, ErrStat_c, ErrMsg_c) BIND (C, NAME='FAST
11981205

11991206
end subroutine FAST_CFD_UpdateStates
12001207
!==================================================================================================================================
1201-
subroutine FAST_CFD_AdvanceToNextTimeStep(iTurb, ErrStat_c, ErrMsg_c) BIND (C, NAME='FAST_CFD_AdvanceToNextTimeStep')
1208+
subroutine FAST_CFD_AdvanceToNextTimeStep(iTurb_c, ErrStat_c, ErrMsg_c) BIND (C, NAME='FAST_CFD_AdvanceToNextTimeStep')
12021209
!DEC$ ATTRIBUTES DLLEXPORT::FAST_CFD_AdvanceToNextTimeStep
12031210
IMPLICIT NONE
12041211
#ifndef IMPLICIT_DLLEXPORT
12051212
!GCC$ ATTRIBUTES DLLEXPORT :: FAST_CFD_AdvanceToNextTimeStep
12061213
#endif
1207-
INTEGER(C_INT), INTENT(IN ) :: iTurb ! Turbine number
1214+
INTEGER(C_INT), INTENT(IN ) :: iTurb_c ! Turbine number
12081215
INTEGER(C_INT), INTENT( OUT) :: ErrStat_c
12091216
CHARACTER(KIND=C_CHAR), INTENT( OUT) :: ErrMsg_c(IntfStrLen)
1217+
integer(IntKi) :: iTurb ! turbine number: Fortran indexing (starts at 1 for first turbine)
12101218

1219+
! transfer turbine index number from C to Fortran indexing (0 to 1 start)
1220+
iTurb = int(iTurb_c,IntKi) + 1
12111221

12121222
IF ( n_t_global > Turbine(iTurb)%p_FAST%n_TMax_m1 ) THEN !finish
12131223

12141224
! we can't continue because we might over-step some arrays that are allocated to the size of the simulation
12151225

1216-
if (iTurb .eq. (NumTurbines-1) ) then
1226+
if (iTurb == NumTurbines ) then
12171227
IF (n_t_global == Turbine(iTurb)%p_FAST%n_TMax_m1 + 1) THEN ! we call update an extra time in Simulink, which we can ignore until the time shift with outputs is solved
12181228
n_t_global = n_t_global + 1
12191229
ErrStat_c = ErrID_None
@@ -1234,7 +1244,7 @@ subroutine FAST_CFD_AdvanceToNextTimeStep(iTurb, ErrStat_c, ErrMsg_c) BIND (C, N
12341244
! CALL SC_SetInputs(Turbine(iTurb)%p_FAST, Turbine(iTurb)%SrvD%y, Turbine(iTurb)%SC, ErrStat, ErrMsg)
12351245
! end if
12361246

1237-
if (iTurb .eq. (NumTurbines-1) ) then
1247+
if (iTurb == NumTurbines ) then
12381248
n_t_global = n_t_global + 1
12391249
end if
12401250

@@ -1246,36 +1256,43 @@ subroutine FAST_CFD_AdvanceToNextTimeStep(iTurb, ErrStat_c, ErrMsg_c) BIND (C, N
12461256

12471257
end subroutine FAST_CFD_AdvanceToNextTimeStep
12481258
!==================================================================================================================================
1249-
subroutine FAST_CFD_WriteOutput(iTurb, ErrStat_c, ErrMsg_c) BIND (C, NAME='FAST_CFD_WriteOutput')
1259+
subroutine FAST_CFD_WriteOutput(iTurb_c, ErrStat_c, ErrMsg_c) BIND (C, NAME='FAST_CFD_WriteOutput')
12501260
!DEC$ ATTRIBUTES DLLEXPORT::FAST_CFD_WriteOutput
12511261
IMPLICIT NONE
12521262
#ifndef IMPLICIT_DLLEXPORT
12531263
!GCC$ ATTRIBUTES DLLEXPORT :: FAST_CFD_WriteOutput
12541264
#endif
1255-
INTEGER(C_INT), INTENT(IN ) :: iTurb ! Turbine number
1265+
INTEGER(C_INT), INTENT(IN ) :: iTurb_c ! Turbine number
12561266
INTEGER(C_INT), INTENT( OUT) :: ErrStat_c
12571267
CHARACTER(KIND=C_CHAR), INTENT( OUT) :: ErrMsg_c(IntfStrLen)
1268+
integer(IntKi) :: iTurb ! turbine number: Fortran indexing (starts at 1 for first turbine)
1269+
1270+
! transfer turbine index number from C to Fortran indexing (0 to 1 start)
1271+
iTurb = int(iTurb_c,IntKi) + 1
12581272

12591273
CALL FAST_WriteOutput_T( t_initial, n_t_global, Turbine(iTurb), ErrStat, ErrMsg )
12601274

12611275
end subroutine FAST_CFD_WriteOutput
12621276
!==================================================================================================================================
1263-
subroutine FAST_CFD_Step(iTurb, ErrStat_c, ErrMsg_c) BIND (C, NAME='FAST_CFD_Step')
1277+
subroutine FAST_CFD_Step(iTurb_c, ErrStat_c, ErrMsg_c) BIND (C, NAME='FAST_CFD_Step')
12641278
IMPLICIT NONE
12651279
#ifndef IMPLICIT_DLLEXPORT
12661280
!DEC$ ATTRIBUTES DLLEXPORT :: FAST_CFD_Step
12671281
!GCC$ ATTRIBUTES DLLEXPORT :: FAST_CFD_Step
12681282
#endif
1269-
INTEGER(C_INT), INTENT(IN ) :: iTurb ! Turbine number
1283+
INTEGER(C_INT), INTENT(IN ) :: iTurb_c ! Turbine number
12701284
INTEGER(C_INT), INTENT( OUT) :: ErrStat_c
12711285
CHARACTER(KIND=C_CHAR), INTENT( OUT) :: ErrMsg_c(IntfStrLen)
1286+
integer(IntKi) :: iTurb ! turbine number: Fortran indexing (starts at 1 for first turbine)
12721287

1288+
! transfer turbine index number from C to Fortran indexing (0 to 1 start)
1289+
iTurb = int(iTurb_c,IntKi) + 1
12731290

12741291
IF ( n_t_global > Turbine(iTurb)%p_FAST%n_TMax_m1 ) THEN !finish
12751292

12761293
! we can't continue because we might over-step some arrays that are allocated to the size of the simulation
12771294

1278-
if (iTurb .eq. (NumTurbines-1) ) then
1295+
if (iTurb == NumTurbines ) then
12791296
IF (n_t_global == Turbine(iTurb)%p_FAST%n_TMax_m1 + 1) THEN ! we call update an extra time in Simulink, which we can ignore until the time shift with outputs is solved
12801297
n_t_global = n_t_global + 1
12811298
ErrStat_c = ErrID_None
@@ -1292,7 +1309,7 @@ subroutine FAST_CFD_Step(iTurb, ErrStat_c, ErrMsg_c) BIND (C, NAME='FAST_CFD_Ste
12921309

12931310
CALL FAST_Solution_T( t_initial, n_t_global, Turbine(iTurb), ErrStat, ErrMsg )
12941311

1295-
if (iTurb .eq. (NumTurbines-1) ) then
1312+
if (iTurb == NumTurbines ) then
12961313
n_t_global = n_t_global + 1
12971314
end if
12981315

@@ -1304,20 +1321,24 @@ subroutine FAST_CFD_Step(iTurb, ErrStat_c, ErrMsg_c) BIND (C, NAME='FAST_CFD_Ste
13041321

13051322
end subroutine FAST_CFD_Step
13061323
!==================================================================================================================================
1307-
subroutine FAST_CFD_Reset_SubStep(iTurb, n_timesteps, ErrStat_c, ErrMsg_c) BIND (C, NAME='FAST_CFD_Reset_SubStep')
1324+
subroutine FAST_CFD_Reset_SubStep(iTurb_c, n_timesteps, ErrStat_c, ErrMsg_c) BIND (C, NAME='FAST_CFD_Reset_SubStep')
13081325
IMPLICIT NONE
13091326
#ifndef IMPLICIT_DLLEXPORT
13101327
!DEC$ ATTRIBUTES DLLEXPORT :: FAST_CFD_Reset_SubStep
13111328
!GCC$ ATTRIBUTES DLLEXPORT :: FAST_CFD_Reset_SubStep
13121329
#endif
1313-
INTEGER(C_INT), INTENT(IN ) :: iTurb ! Turbine number
1330+
INTEGER(C_INT), INTENT(IN ) :: iTurb_c ! Turbine number
13141331
INTEGER(C_INT), INTENT(IN ) :: n_timesteps ! Number of time steps to go back
13151332
INTEGER(C_INT), INTENT( OUT) :: ErrStat_c
13161333
CHARACTER(KIND=C_CHAR), INTENT( OUT) :: ErrMsg_c(IntfStrLen)
1334+
integer(IntKi) :: iTurb ! turbine number: Fortran indexing (starts at 1 for first turbine)
1335+
1336+
! transfer turbine index number from C to Fortran indexing (0 to 1 start)
1337+
iTurb = int(iTurb_c,IntKi) + 1
13171338

13181339
CALL FAST_Reset_SubStep_T(t_initial, n_t_global-n_timesteps, n_timesteps, Turbine(iTurb), ErrStat, ErrMsg )
13191340

1320-
if (iTurb .eq. (NumTurbines-1) ) then
1341+
if (iTurb == NumTurbines ) then
13211342
n_t_global = n_t_global - n_timesteps
13221343
end if
13231344

@@ -1328,16 +1349,20 @@ subroutine FAST_CFD_Reset_SubStep(iTurb, n_timesteps, ErrStat_c, ErrMsg_c) BIND
13281349

13291350
end subroutine FAST_CFD_Reset_SubStep
13301351
!==================================================================================================================================
1331-
subroutine FAST_CFD_Store_SubStep(iTurb, n_t_global, ErrStat_c, ErrMsg_c) BIND (C, NAME='FAST_CFD_Store_SubStep')
1352+
subroutine FAST_CFD_Store_SubStep(iTurb_c, n_t_global, ErrStat_c, ErrMsg_c) BIND (C, NAME='FAST_CFD_Store_SubStep')
13321353
IMPLICIT NONE
13331354
#ifndef IMPLICIT_DLLEXPORT
13341355
!DEC$ ATTRIBUTES DLLEXPORT :: FAST_CFD_Store_SubStep
13351356
!GCC$ ATTRIBUTES DLLEXPORT :: FAST_CFD_Store_SubStep
13361357
#endif
1337-
INTEGER(C_INT), INTENT(IN ) :: iTurb ! Turbine number
1358+
INTEGER(C_INT), INTENT(IN ) :: iTurb_c ! Turbine number
13381359
INTEGER(C_INT), INTENT(IN ) :: n_t_global !< loop counter
13391360
INTEGER(C_INT), INTENT( OUT) :: ErrStat_c
13401361
CHARACTER(KIND=C_CHAR), INTENT( OUT) :: ErrMsg_c(IntfStrLen)
1362+
integer(IntKi) :: iTurb ! turbine number: Fortran indexing (starts at 1 for first turbine)
1363+
1364+
! transfer turbine index number from C to Fortran indexing (0 to 1 start)
1365+
iTurb = int(iTurb_c,IntKi) + 1
13411366

13421367
CALL FAST_Store_SubStep_T(t_initial, n_t_global, Turbine(iTurb), ErrStat, ErrMsg )
13431368

0 commit comments

Comments
 (0)