From c05b87edea74e3493974646f3d041890f1ef0f8c Mon Sep 17 00:00:00 2001 From: andrew-platt Date: Thu, 23 Sep 2021 07:45:24 -0600 Subject: [PATCH] [BugFix] Fix segmentation fault in HD linearization Error in logic for creating the state names for linearization. --- modules/hydrodyn/src/HydroDyn.f90 | 49 +++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/modules/hydrodyn/src/HydroDyn.f90 b/modules/hydrodyn/src/HydroDyn.f90 index ca4cf13dd..e15ec0da7 100644 --- a/modules/hydrodyn/src/HydroDyn.f90 +++ b/modules/hydrodyn/src/HydroDyn.f90 @@ -3096,7 +3096,7 @@ SUBROUTINE HD_Init_Jacobian_x( p, InitOut, ErrStat, ErrMsg) ! local variables: INTEGER(IntKi) :: i, j, k, l, spdof, indx - CHARACTER(10) :: modLabels(2), dofLabels(6) + CHARACTER(10) :: dofLabels(6) ErrStat = ErrID_None ErrMsg = "" indx = 1 @@ -3135,36 +3135,53 @@ SUBROUTINE HD_Init_Jacobian_x( p, InitOut, ErrStat, ErrMsg) k=k+1 end do end do - - modLabels = (/'Exctn ','Rdtn '/) + + !---------------- + ! SS_Exctn states + dofLabels = (/'PtfmSg ','PtfmSw ','PtfmHv ','PtfmR ','PtfmP ','PtfmY '/) - do k = 1, 2 ! 1 = Excitation, 2 = Radiation + if (p%totalExctnStates>0) then do l=1,p%nWAMITObj - ! set linearization state names: do j = 1, 6 - - if (k == 1) then - spdof = p%WAMIT(l)%SS_Exctn%spdof(j) - else - spdof = p%WAMIT(l)%SS_Rdtn%spdof(j) + spdof = p%WAMIT(l)%SS_Exctn%spdof(j) + if ( p%NBodyMod == 1 ) then + do i = 1,spdof + InitOut%LinNames_x(indx) = 'Exctn'//trim(dofLabels(j))//trim(num2lstr(i)) + indx = indx + 1 + end do + else + do i = 1,spdof + InitOut%LinNames_x(indx) = 'B'//trim(num2lstr(l))//'Exctn'//trim(dofLabels(j))//trim(num2lstr(i)) + indx = indx + 1 + end do end if - + end do + end do + endif + + !---------------- + ! SS_Rdtn states + + if (p%totalRdtnStates>0) then + do l=1,p%nWAMITObj + ! set linearization state names: + do j = 1, 6 + spdof = p%WAMIT(l)%SS_Rdtn%spdof(j) if ( p%NBodyMod == 1 ) then do i = 1,spdof - InitOut%LinNames_x(indx) = trim(modLabels(k))//trim(dofLabels(j))//trim(num2lstr(i)) + InitOut%LinNames_x(indx) = 'Rdtn'//trim(dofLabels(j))//trim(num2lstr(i)) indx = indx + 1 end do else do i = 1,spdof - InitOut%LinNames_x(indx) = 'B'//trim(num2lstr(l))//trim(modLabels(k))//trim(dofLabels(j))//trim(num2lstr(i)) + InitOut%LinNames_x(indx) = 'B'//trim(num2lstr(l))//'Rdtn'//trim(dofLabels(j))//trim(num2lstr(i)) indx = indx + 1 end do end if - end do end do - end do + endif END SUBROUTINE HD_Init_Jacobian_x !---------------------------------------------------------------------------------------------------------------------------------- !> This routine initializes the array that maps rows/columns of the Jacobian to specific mesh fields. @@ -3553,7 +3570,7 @@ SUBROUTINE HD_Perturb_x( p, n, perturb_sign, x, dx ) else offset1 = p%totalExctnStates + 1 ! Find body index for rdtn states - do i=1,p%nWAMITObj + do i=1,p%nWAMITObj offset2 = offset1 + p%WAMIT(i)%SS_Exctn%numStates if ( n >= offset1 .and. n < offset2) then n2 = n - offset1 + 1