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

AD: Support UserProp linearization #612

Closed
Closed
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
48 changes: 43 additions & 5 deletions modules/aerodyn/src/AeroDyn.f90
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,8 @@ subroutine SetParameters( InitInp, InputFileData, p, ErrStat, ErrMsg )

p%CompAA = InputFileData%CompAA

! p%numBlades = InitInp%numBlades ! this was set earlier because it was necessary
! NOTE: In the following we use InputFileData%BladeProps(1)%NumBlNds as the number of aero nodes on EACH blade,
! but if AD changes this, then it must be handled in the Glue-code linearization code, too (and elsewhere?) !
p%NumBlNds = InputFileData%BladeProps(1)%NumBlNds
if (p%TwrPotent == TwrPotent_none .and. .not. p%TwrShadow .and. .not. p%TwrAero) then
p%NumTwrNds = 0
Expand Down Expand Up @@ -4164,7 +4165,15 @@ SUBROUTINE AD_GetOP( t, u, p, x, xd, z, OtherState, y, m, ErrStat, ErrMsg, u_op,
index = index + 1
end do
end do

do k=1,p%NumBlades
do j = 1, size(u%UserProp,1) ! Number of nodes for a blade
u_op(index) = u%UserProp(j,k)
index = index + 1
end do
end do


END IF

IF ( PRESENT( y_op ) ) THEN
Expand Down Expand Up @@ -4459,7 +4468,8 @@ SUBROUTINE Init_Jacobian_u( InputFileData, p, u, InitOut, ErrStat, ErrMsg)
nu = u%TowerMotion%NNodes * 9 & ! 3 Translation Displacements + 3 orientations + 3 Translation velocities at each node
+ u%hubMotion%NNodes * 9 & ! 3 Translation Displacements + 3 orientations + 3 Rotation velocities at each node
+ size( u%InflowOnBlade) &
+ size( u%InflowOnTower)
+ size( u%InflowOnTower) &
+ size( u%UserProp)

do i=1,p%NumBlades
nu = nu + u%BladeMotion(i)%NNodes * 15 & ! 3 Translation Displacements + 3 orientations + 3 Translation velocities + 3 Rotation velocities + 3 TranslationAcc at each node
Expand Down Expand Up @@ -4587,7 +4597,16 @@ SUBROUTINE Init_Jacobian_u( InputFileData, p, u, InitOut, ErrStat, ErrMsg)
end do !j
end do !i

!Module/Mesh/Field: u%UserProp(:,:) = 23,24,25;

do k=1,size(u%UserProp,2) ! p%NumBlades
do i=1,size(u%UserProp,1) ! numNodes
p%Jac_u_indx(index,1) = 22 + k
p%Jac_u_indx(index,2) = 1 !component index: this is a scalar, so 1, but is never used
p%Jac_u_indx(index,3) = i !Node: i
index = index + 1
end do !i
end do !k
!......................................
! default perturbations, p%du:
!......................................
Expand Down Expand Up @@ -4625,7 +4644,11 @@ SUBROUTINE Init_Jacobian_u( InputFileData, p, u, InitOut, ErrStat, ErrMsg)
do k=1,p%NumBlades
p%du(24 + k) = perturb_b(k) ! u%InflowOnBlade(:,:,k) = 24 + k
end do
p%du(28) = perturb_t ! u%InflowOnTower(:,:) = 22
p%du(28) = perturb_t ! u%InflowOnTower(:,:) = 28
do k=1,p%NumBlades
p%du(28+k) = perturb ! u%UserProp(:,:) = 29,30,31
end do



!.....................
Expand All @@ -4641,7 +4664,10 @@ SUBROUTINE Init_Jacobian_u( InputFileData, p, u, InitOut, ErrStat, ErrMsg)

InitOut%IsLoad_u = .false. ! None of AeroDyn's inputs are loads
InitOut%RotFrame_u = .false.

do k=0,p%NumBlades*p%NumBlNds-1
InitOut%RotFrame_u(nu - k ) = .true. ! UserProp(:,:)
end do

index = 1
FieldMask = .false.
FieldMask(MASKID_TRANSLATIONDISP) = .true.
Expand Down Expand Up @@ -4684,6 +4710,13 @@ SUBROUTINE Init_Jacobian_u( InputFileData, p, u, InitOut, ErrStat, ErrMsg)
index = index + 1
end do
end do

do k=1,p%NumBlades
do i=1,p%NumBlNds
InitOut%LinNames_u(index) = 'User defined control property for blade '//trim(num2lstr(k))//', node '//trim(num2lstr(i))//', -'
index = index + 1
end do
end do

END SUBROUTINE Init_Jacobian_u
!----------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -4901,7 +4934,12 @@ SUBROUTINE Perturb_u( p, n, perturb_sign, u, du )

CASE (28) !Module/Mesh/Field: u%InflowOnTower(:,:) = 28;
u%InflowOnTower(fieldIndx,node) = u%InflowOnTower(fieldIndx,node) + du * perturb_sign

CASE (29) !Module/Mesh/Field: u%UserProp(:,1) = 29;
u%UserProp(node,1) = u%UserProp(node,1) + du * perturb_sign
CASE (30) !Module/Mesh/Field: u%UserProp(:,2) = 30;
u%UserProp(node,2) = u%UserProp(node,2) + du * perturb_sign
CASE (31) !Module/Mesh/Field: u%UserProp(:,3) = 31;
u%UserProp(node,3) = u%UserProp(node,3) + du * perturb_sign
END SELECT

END SUBROUTINE Perturb_u
Expand Down
19 changes: 14 additions & 5 deletions modules/openfast-library/src/FAST_Lin.f90
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ MODULE FAST_Linear
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!----------------------------------------------------------------------------------------------------------------------------------
!> Routine that initializes some variables for linearization.
SUBROUTINE Init_Lin(p_FAST, y_FAST, m_FAST, AD, ED, NumBl, ErrStat, ErrMsg)
SUBROUTINE Init_Lin(p_FAST, y_FAST, m_FAST, AD, ED, NumBl, NumBlNodes, ErrStat, ErrMsg)

TYPE(FAST_ParameterType), INTENT(INOUT) :: p_FAST !< Parameters for the glue code
TYPE(FAST_OutputFileType),INTENT(INOUT) :: y_FAST !< Output variables for the glue code
TYPE(FAST_MiscVarType), INTENT(INOUT) :: m_FAST !< Miscellaneous variables
TYPE(AeroDyn_Data), INTENT(IN ) :: AD !< AeroDyn data
TYPE(ElastoDyn_Data), INTENT(IN ) :: ED !< ElastoDyn data
INTEGER(IntKi), INTENT(IN ) :: NumBl !< Number of blades (for index into ED input array)
INTEGER(IntKi), INTENT(IN ) :: NumBl !< Number of blades (for index into ED,AD input array)
INTEGER(IntKi), INTENT(IN ) :: NumBlNodes !< Number of blade nodes (for index into AD input array)

INTEGER(IntKi), INTENT( OUT) :: ErrStat !< Error status of the operation
CHARACTER(*), INTENT( OUT) :: ErrMsg !< Error message if ErrStat /= ErrID_None
Expand Down Expand Up @@ -153,7 +154,7 @@ SUBROUTINE Init_Lin(p_FAST, y_FAST, m_FAST, AD, ED, NumBl, ErrStat, ErrMsg)
! ...................................
! determine which of the module inputs/outputs are written to file
! ...................................
call Init_Lin_InputOutput(p_FAST, y_FAST, NumBl, ErrStat2, ErrMsg2)
call Init_Lin_InputOutput(p_FAST, y_FAST, NumBl, NumBlNodes, ErrStat2, ErrMsg2)
call SetErrStat(errStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)

! ...................................
Expand Down Expand Up @@ -419,11 +420,12 @@ SUBROUTINE Init_Lin_IfW( p_FAST, y_FAST, u_AD )
END SUBROUTINE Init_Lin_IfW
!----------------------------------------------------------------------------------------------------------------------------------
!> Routine that initializes some use_u and use_y, which determine which, if any, inputs and outputs are output in the linearization file.
SUBROUTINE Init_Lin_InputOutput(p_FAST, y_FAST, NumBl, ErrStat, ErrMsg)
SUBROUTINE Init_Lin_InputOutput(p_FAST, y_FAST, NumBl, NumBlNodes, ErrStat, ErrMsg)

TYPE(FAST_ParameterType), INTENT(INOUT) :: p_FAST !< Parameters for the glue code
TYPE(FAST_OutputFileType),INTENT(INOUT) :: y_FAST !< Output variables for the glue code
INTEGER(IntKi), INTENT(IN ) :: NumBl !< Number of blades (for index into ED input array)
INTEGER(IntKi), INTENT(IN ) :: NumBl !< Number of blades (for index into ED,AD input array)
INTEGER(IntKi), INTENT(IN ) :: NumBlNodes !< Number of blades nodes (for index into AD input array)

INTEGER(IntKi), INTENT( OUT) :: ErrStat !< Error status of the operation
CHARACTER(*), INTENT( OUT) :: ErrMsg !< Error message if ErrStat /= ErrID_None
Expand Down Expand Up @@ -476,6 +478,13 @@ SUBROUTINE Init_Lin_InputOutput(p_FAST, y_FAST, NumBl, ErrStat, ErrMsg)
end do
end do

! AD standard inputs: UserProp(NumBlNodes,NumBl)
! LIN-TODO Add these Userprop values
if (p_FAST%CompAero == MODULE_AD) then
do j=1,NumBl*NumBlNodes
y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%use_u(y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%SizeLin(LIN_INPUT_COL)+1-j) = .true.
end do
end if
! ED standard inputs: BlPitchCom, YawMom, GenTrq, extended input (collective pitch)
do j=1,NumBl+3
y_FAST%Lin%Modules(MODULE_ED)%Instance(1)%use_u(y_FAST%Lin%Modules(MODULE_ED)%Instance(1)%SizeLin(LIN_INPUT_COL)+1-j) = .true.
Expand Down
8 changes: 7 additions & 1 deletion modules/openfast-library/src/FAST_Subs.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,13 @@ SUBROUTINE FAST_InitializeAll( t_initial, p_FAST, y_FAST, m_FAST, ED, BD, SrvD,
! Initialize for linearization:
! -------------------------------------------------------------------------
if ( p_FAST%Linearize ) then
call Init_Lin(p_FAST, y_FAST, m_FAST, AD, ED, Init%OutData_ED%NumBl, ErrStat2, ErrMsg2)
! NOTE: In the following call, we use Init%OutData_AD%BladeProps(1)%NumBlNds as the number of aero nodes on EACH blade, which
! is consistent with the current AD implementation, but if AD changes this, then it must be handled here, too!
if (p_FAST%CompAero == MODULE_AD) then
call Init_Lin(p_FAST, y_FAST, m_FAST, AD, ED, Init%OutData_ED%NumBl, Init%OutData_AD%BladeProps(1)%NumBlNds, ErrStat2, ErrMsg2)
else
call Init_Lin(p_FAST, y_FAST, m_FAST, AD, ED, Init%OutData_ED%NumBl, -1, ErrStat2, ErrMsg2)
endif
call SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)

if (ErrStat >= AbortErrLev) then
Expand Down