Commit 5e3643ca authored by famen's avatar famen
Browse files

Init call from HAWC2 to Bladed style controller implemented

parent cc5abcf7
Pipeline #22811 passed with stage
in 4 minutes and 50 seconds
......@@ -23,7 +23,7 @@ module bladed_controller_hawc2
character*256 :: filename=''
character*256 :: infile =''
character*256 :: outfile=''
character*256 :: outfile='out.txt'
character*256 :: func_name=''
real(4),dimension(100) :: avrSWAP=0.0 ! The swap array, used to pass data to, and receive data from, the DLL controller.
integer(c_int) :: is_shutdown
......@@ -208,40 +208,34 @@ subroutine update_discon_dll(array1, array2) bind(c, name='update_discon_dll')
equivalence (avcMSG, cMessage)
equivalence (avcOutName, cOutName)
iStatus = nint(array1(1))
aviFail = 0
! Convert c character arrays to Fortran CHARACTER strings:
!cOutName = transfer(avcOUTNAME(1:len(cOutName)),cOutName)
!i = index(cOutName, C_NULL_CHAR) - 1 ! Find the c NULL character at the end of cOutName, if it has then remove it
!if (i>0) cOutName = cOutName(1:i)
!
!cInFile = transfer(avcINFILE(1:len(cInFile)),cInFile)
!i = index(cInFile, C_NULL_CHAR) - 1 ! Find the c NULL character at the end of cInFile, if it has then remove it
!if (i>0) cInFile = cInFile(1:i)
! If iStatus = 0 means OpenFAST/Bladed running at time = 0.00,
! The DTUWEC starts to run at the second time step, eg., time = delta_t
! Therefore, the iStatus should be bigger than 0
!--------------------------------------------------------------------------------------------
! Required inputs:
!--------------------------------------------------------------------------------------------
! Required inputs array1 must contains the following channels from HAWC2:
! 1: status
! 2: time[s]
! 3: rotor speed [rad/s]
! 4: blade 1 pitch angle [rad]
! 5: blade 2 pitch angle [rad]
! 6: blade 3 pitch angle [rad]
! 7: Shaft moment [kNm]
! 8: flap moment, blade 1 [kNm]
! 9: flap moment, blade 2 [kNm]
! 10: flap moment, blade 3 [kNm]
! 11: rotor azimuth angle [rad]
! 12: tower top fore-aft acceleration [m/s^2]
! 13: nacelle nodding acceleration [rad/s^2]
! 7: shaft moment [kNm] / Elec. power from generator servo dll [w]
! 8: rotor azimuth angle [rad]
! 9: floater platform transform displacement x [m]
! 10: floater platform transform displacement y [m]
! 11: floater platform transform displacement z [m]
! 12: floater platform rotation displacement x [rad]
! 13: floater platform rotation displacement y [rad]
! 14: floater platform rotation displacement z [rad]
! 15: floater platform transform velocity x [m/s]
! 16: floater platform transform velocity y [m/s]
! 17: floater platform transform velocity z [m/s]
! 18: floater platform rotation velocity x [rad/s]
! 19: floater platform rotation velocity y [rad/s]
! 20: floater platform rotation velocity z [rad/s]
! 21: floater platform transform acceleration x [m/s^2]
! 22: floater platform transform acceleration y [m/s^2]
! 23: floater platform transform acceleration z [m/s^2]
! 24: floater platform rotation acceleration x [rad/s^2]
! 25: floater platform rotation acceleration y [rad/s^2]
! 26: floater platform rotation acceleration z [rad/s^2]
!--------------------------------------------------------------------------------------------
! Provided outputs:
! 1: generator torque [Nm]
......@@ -251,86 +245,109 @@ subroutine update_discon_dll(array1, array2) bind(c, name='update_discon_dll')
! 5: Mechanical power [kW]
! 6: Electrical power [kW]
!--------------------------------------------------------------------------------------------
! Required avrSWAP channels 1-2-3-4-15-20-21-33-34-49-50-51-60-62-63-64
discon_dll%avrSWAP(1) = iStatus !status
discon_dll%avrSWAP(2) = array1(2) !time[s]
discon_dll%avrSWAP(3) = discon_dll%time_step !time step in simulation [s]
discon_dll%avrSWAP(4) = array1(4) !blade 1 pitch angle [rad]
! discon_dll%avrSWAP(10)=0.d0 ! 0=pitch position actuator, 1=pitch rate actuator
! discon_dll%avrSWAP(14) = array1(8) * 1000.d0 * array1(3) ! measured shaft power [W]
discon_dll%avrSWAP(15) = array1(7) * 1000.d0 * array1(3) * discon_dll%efficiency! measured electrical power [W]
discon_dll%avrSWAP(20) = array1(3) * discon_dll%gear_ratio !generator speed [rad/s]
discon_dll%avrSWAP(21) = array1(3) !rotor speed [rad/s]
! If iStatus = 0 means HAWC2 is running at first time step and first iteration;
! If iStatus = 1 means HAWC2 is running the rest of the simulation;
! If iStatus =-1 means HAWC2 is running the last time stepthe simulation;
iStatus = nint(array1(1))
! First set the aviFail to 0
aviFail = 0
discon_dll%avrSWAP(1) = iStatus ! HAWC2 status
discon_dll%avrSWAP(2) = array1(2) ! time[s]
discon_dll%avrSWAP(3) = discon_dll%time_step ! time step in simulation [s]
discon_dll%avrSWAP(4) = array1(4) ! blade 1 pitch angle [rad]
! discon_dll%avrSWAP(10)=0.d0 ! 0=pitch position actuator, 1=pitch rate actuator
! discon_dll%avrSWAP(15) = -array1(7) * 1000.d0 * array1(3) * discon_dll%efficiency! measured electrical power [W]
discon_dll%avrSWAP(15) = array1(7) ! measured electrical power [W]
discon_dll%avrSWAP(20) = array1(3) * discon_dll%gear_ratio ! generator speed [rad/s]
discon_dll%avrSWAP(21) = array1(3) ! rotor speed [rad/s]
! discon_dll%avrSWAP(23)=array1(8) * 1000.d0 * discon_dll%gearratio ! measured generator torque [Nm]
! not active discon_dll%avrSWAP(24) ! measured yaw error [rad]
! discon_dll%avrSWAP(24) ! measured yaw error [rad]
! discon_dll%avrSWAP(27)=array1(7) !Hub wind speed [m/s]
! discon_dll%avrSWAP(28)=0.d0 ! 0=collective pitch 1=individual pitch
! discon_dll%avrSWAP(30)=array1( 9)*1000.d0 ! flap moment, blade 1 [Nm]
! discon_dll%avrSWAP(31)=array1(10)*1000.d0 ! flap moment, blade 2 [Nm]
! discon_dll%avrSWAP(32)=array1(11)*1000.d0 ! flap moment, blade 3 [Nm]
discon_dll%avrSWAP(33) = array1(5) ! blade 2 pitch angle [rad]
discon_dll%avrSWAP(34) = array1(6) ! blade 3 pitch angle [rad]
discon_dll%avrSWAP(49) = size(avcMSG)-1
discon_dll%avrSWAP(50) = len(trim(discon_dll%infile))
if(iStatus == 0) then
cInFile=trim(discon_dll%Infile)
call fp_discon(discon_dll%avrSWAP,aviFail,accInFile,avcOutName,avcMSG)
endif
discon_dll%avrSWAP(51) = len(trim(discon_dll%outfile))
if(iStatus == 0) then
cOutName=trim(discon_dll%Outfile)
endif
! discon_dll%avrSWAP(53)=array1(13) ! tower top fore-aft acceleration [m/s^2]
discon_dll%avrSWAP(60) = array1(12) ! rotor azimuth angle [rad]
discon_dll%avrSWAP(62) = discon_dll%max_num_of_value_logging ! Max. number of values which can be returned for logging
discon_dll%avrSWAP(63) = discon_dll%start_elem_record_logging ! Record number for start of logging output
discon_dll%avrSWAP(64) = discon_dll%max_str_length_logging ! Max. no. of characters which can be returned in "OUTNAME"
! discon_dll%avrSWAP(83)=array1(14) ! nacelle nodding acceleration [rad/s^2]
! ------------------------------------------------------------------------------------
! Floating turbine part
! ------------------------------------------------------------------------------------
! floater motion
discon_dll%avrSWAP(66)=0.d0 ! PtfmTDxi
discon_dll%avrSWAP(67)=0.d0 ! PtfmTDyi
discon_dll%avrSWAP(68)=0.d0 ! PtfmTDzi
discon_dll%avrSWAP(69)=0.d0 ! PtfmRDxi
discon_dll%avrSWAP(70)=0.d0 ! PtfmRDyi
discon_dll%avrSWAP(71)=0.d0 ! PtfmRDzi
! floater velocity
discon_dll%avrSWAP(72)=0.d0 ! PtfmTVxi
discon_dll%avrSWAP(73)=0.d0 ! PtfmTVyi
discon_dll%avrSWAP(74)=0.d0 ! PtfmTVzi
discon_dll%avrSWAP(75)=0.d0 ! PtfmRVxi
discon_dll%avrSWAP(76)=0.d0 ! PtfmRVyi
discon_dll%avrSWAP(77)=0.d0 ! PtfmRVzi
! floater acceleration
discon_dll%avrSWAP(78)=0.d0 ! PtfmTAxi
discon_dll%avrSWAP(79)=0.d0 ! PtfmTAyi
discon_dll%avrSWAP(80)=0.d0 ! PtfmTAzi
discon_dll%avrSWAP(81)=0.d0 ! PtfmRAxi
discon_dll%avrSWAP(82)=0.d0 ! PtfmRAyi
discon_dll%avrSWAP(83)=0.d0 ! PtfmRAzi
if (aviFail == 0) then
continue ! call was succesfull
elseif (aviFAIL > 0) then
write (0,*) '*** WARNING *** In external dll. Warning message from discon:'
write (0,*) trim(cMessage)
else
write (0,*) '*** ERROR *** In external dll. Error message from discon:'
write (0,*) trim(cMessage)
stop
endif
if (( iStatus == 0 ) .and. ( aviFail >= 0 ) ) then
write (0,*) '*** INFO *** In external dll: Calling to DISCON dll at FIRST timestep is successful!'
stop
endif
discon_dll%avrSWAP(33) = array1(5) ! blade 2 pitch angle [rad]
discon_dll%avrSWAP(34) = array1(6) ! blade 3 pitch angle [rad]
discon_dll%avrSWAP(49) = size(avcMSG)-1
discon_dll%avrSWAP(50) = len(trim(discon_dll%infile))
if(iStatus == 0) then
! Ending with NULL character to make a proper C-String needed by bladed style discon interface
cInFile=trim(discon_dll%infile)//char(0)
discon_dll%avrSWAP(51) = len(trim(discon_dll%outfile)) ! Length of the output file name
! Ending with NULL character to make a proper C-String needed by bladed style discon interface
cOutName=trim(discon_dll%outfile)//char(0)
write(6,'(A)') 'First call to DISCON function.'
write(6,'(A)') 'Controller input parameter file: '// trim(cInFile)
call fp_discon(discon_dll%avrSWAP,aviFail,accInFile,avcOutName,avcMSG)
write(6,'(A)') 'Controller input parameter file: '// trim(cInFile) //' Openned successfully.'
write(6,'(A)') 'Controller output file: '//trim(cOutName)
write(6,'(A,I2)') trim(discon_dll%filename)//': aviFAIL = ', aviFail
! write(6,'(A)') trim(discon_dll%filename)//': ' // trim(cMessage)
endif
discon_dll%avrSWAP(60) = array1(8) ! Rotor azimuth angle [rad]
discon_dll%avrSWAP(62) = discon_dll%max_num_of_value_logging ! Max. number of values which can be returned for logging
discon_dll%avrSWAP(63) = discon_dll%start_elem_record_logging ! Record number for start of logging output
discon_dll%avrSWAP(64) = discon_dll%max_str_length_logging ! Max. no. of characters which can be returned in "OUTNAME"
! discon_dll%avrSWAP(53)=array1(13) ! tower top fore-aft acceleration [m/s^2]
! discon_dll%avrSWAP(83)=array1(14) ! nacelle nodding acceleration [rad/s^2]
! ------------------------------------------------------------------------------------
! floating turbine part
! ------------------------------------------------------------------------------------
! floater displacement
discon_dll%avrSWAP(66)=array1(9) ! PtfmTDxi
discon_dll%avrSWAP(67)=array1(10) ! PtfmTDyi
discon_dll%avrSWAP(68)=array1(11) ! PtfmTDzi
discon_dll%avrSWAP(69)=array1(12) ! PtfmRDxi
discon_dll%avrSWAP(70)=array1(13) ! PtfmRDyi
discon_dll%avrSWAP(71)=array1(14) ! PtfmRDzi
! floater velocity
discon_dll%avrSWAP(72)=array1(15) ! PtfmTVxi
discon_dll%avrSWAP(73)=array1(16) ! PtfmTVyi
discon_dll%avrSWAP(74)=array1(17) ! PtfmTVzi
discon_dll%avrSWAP(75)=array1(18) ! PtfmRVxi
discon_dll%avrSWAP(76)=array1(19) ! PtfmRVyi
discon_dll%avrSWAP(77)=array1(20) ! PtfmRVzi
! floater acceleration
discon_dll%avrSWAP(78)=array1(21) ! PtfmTAxi
discon_dll%avrSWAP(79)=array1(22) ! PtfmTAyi
discon_dll%avrSWAP(80)=array1(23) ! PtfmTAzi
discon_dll%avrSWAP(81)=array1(24) ! PtfmRAxi
discon_dll%avrSWAP(82)=array1(25) ! PtfmRAyi
discon_dll%avrSWAP(83)=array1(26) ! PtfmRAzi
if (aviFail == 0) then
continue ! call was succesfull
elseif (aviFAIL > 0) then
write (6,'(A)') '*** WARNING *** In external dll. Warning message from discon:'
write (6,'(A)') trim(cMessage)
else
write (6,'(A)') '*** ERROR *** In external dll. Error message from discon:'
write (6,'(A)') trim(cMessage)
stop
endif
if (( iStatus == 0 ) .and. ( aviFail >= 0 ) ) then
write (0,*) '*** INFO *** In external dll: Calling to DISCON dll at FIRST timestep is successful!'
stop
endif
array2 = 0.0
return
end subroutine update_discon_dll
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment