From ff99949ea822278055912253ca38224107dafbcb Mon Sep 17 00:00:00 2001 From: Nikhar Abbas Date: Wed, 18 Dec 2019 13:02:25 -0700 Subject: [PATCH 1/3] Read input filename - initial commit --- src/DISCON.F90 | 2 +- src/Filters.f90 | 12 +++++++++--- src/Functions.f90 | 6 +++--- src/ReadSetParameters.f90 | 23 +++++++++++++++++------ 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/DISCON.F90 b/src/DISCON.F90 index f74fd126..8912f1a2 100644 --- a/src/DISCON.F90 +++ b/src/DISCON.F90 @@ -59,7 +59,7 @@ SUBROUTINE DISCON(avrSWAP, aviFAIL, accINFILE, avcOUTNAME, avcMSG) BIND (C, NAME !------------------------------------------------------------------------------------------------------------------------------ ! Read avrSWAP array into derived types/variables CALL ReadAvrSWAP(avrSWAP, LocalVar) -CALL SetParameters(avrSWAP, aviFAIL, ErrMsg, SIZE(avcMSG), CntrPar, LocalVar, objInst, PerfData) +CALL SetParameters(avrSWAP, aviFAIL, accINFILE, ErrMsg, SIZE(avcMSG), CntrPar, LocalVar, objInst, PerfData) CALL PreFilterMeasuredSignals(CntrPar, LocalVar, objInst) IF ((LocalVar%iStatus >= 0) .AND. (aviFAIL >= 0)) THEN ! Only compute control calculations if no error has occurred and we are not on the last time step diff --git a/src/Filters.f90 b/src/Filters.f90 index 6d41703d..c8cb0919 100644 --- a/src/Filters.f90 +++ b/src/Filters.f90 @@ -27,7 +27,9 @@ MODULE Filters CONTAINS !------------------------------------------------------------------------------------------------------------------------------- REAL FUNCTION LPFilter(InputSignal, DT, CornerFreq, iStatus, reset, inst) - ! Discrete time Low-Pass Filter + ! Discrete time Low-Pass Filter of the form: + ! H(z) = (b1z + b0) / (a1*z + a0) + ! REAL(4), INTENT(IN) :: InputSignal REAL(4), INTENT(IN) :: DT ! time step [s] REAL(4), INTENT(IN) :: CornerFreq ! corner frequency [rad/s] @@ -36,13 +38,17 @@ REAL FUNCTION LPFilter(InputSignal, DT, CornerFreq, iStatus, reset, inst) LOGICAL(4), INTENT(IN) :: reset ! Reset the filter to the input signal ! Local + REAL(4), SAVE :: a1 ! Denominator coefficient 1 + REAL(4), SAVE :: a0 ! Denominator coefficient 0 + REAL(4), SAVE :: b1 ! Numerator coefficient 1 + REAL(4), SAVE :: b0 ! Numerator coefficient 0 REAL(4), DIMENSION(99), SAVE :: InputSignalLast ! Input signal the last time this filter was called. Supports 99 separate instances. REAL(4), DIMENSION(99), SAVE :: OutputSignalLast ! Output signal the last time this filter was called. Supports 99 separate instances. ! Initialization - - IF ((iStatus == 0) .OR. reset) THEN + IF ((iStatus == 0) .OR. reset) THEN + ! a1 = OutputSignalLast(inst) = InputSignal InputSignalLast(inst) = InputSignal ENDIF diff --git a/src/Functions.f90 b/src/Functions.f90 index bf5bf92d..988b865c 100644 --- a/src/Functions.f90 +++ b/src/Functions.f90 @@ -416,8 +416,8 @@ SUBROUTINE Debug(LocalVar, CntrPar, avrSWAP, RootName, size_avcOUTNAME) IF (CntrPar%LoggingLevel > 0) THEN !OPEN(unit=UnDb, FILE=TRIM(RootName)//'.dbg', STATUS='NEW') OPEN(unit=UnDb, FILE='DEBUG.dbg') - WRITE (UnDb,'(A)') ' Time ' //Tab//' WE_TowerTop ' //Tab//' WE_Vw ' //Tab//' SS_DelOmega ' - WRITE (UnDb,'(A)') ' (sec) ' //Tab//'(m/s) ' //Tab//'(rad) ' + WRITE (UnDb,'(A)') ' Time ' //Tab//' WE_TowerTop ' //Tab//' WE_Vw ' //Tab//' GenSpeedF ' + WRITE (UnDb,'(A)') ' (sec) ' //Tab//'(m/s) ' //Tab//'(m/s) ' //Tab//'(rad/s) ' !WRITE (UnDb,'(A)') ' LocalVar%Time ' //Tab//'LocalVar%PC_PitComT ' //Tab//'LocalVar%PC_SpdErr ' //Tab//'LocalVar%PC_KP ' //Tab//'LocalVar%PC_KI ' //Tab//'LocalVar%Y_M ' //Tab//'LocalVar%rootMOOP(1) '//Tab//'VS_RtPwr '//Tab//'LocalVar%GenTq' !WRITE (UnDb,'(A)') ' (sec) ' //Tab//'(rad) ' //Tab//'(rad/s) '//Tab//'(-) ' //Tab//'(-) ' //Tab//'(rad) ' //Tab//'(?) ' //Tab//'(W) '//Tab//'(Nm) ' END IF @@ -440,7 +440,7 @@ SUBROUTINE Debug(LocalVar, CntrPar, avrSWAP, RootName, size_avcOUTNAME) ! Output debugging information if requested: IF (CntrPar%LoggingLevel > 0) THEN - WRITE (UnDb,FmtDat) LocalVar%Time, LocalVar%TestType, LocalVar%WE_Vw, LocalVar%SS_DelOmegaF + WRITE (UnDb,FmtDat) LocalVar%Time, LocalVar%TestType, LocalVar%WE_Vw, LocalVar%GenSpeedF END IF IF (CntrPar%LoggingLevel > 1) THEN diff --git a/src/ReadSetParameters.f90 b/src/ReadSetParameters.f90 index d42b0484..f0140df5 100644 --- a/src/ReadSetParameters.f90 +++ b/src/ReadSetParameters.f90 @@ -31,13 +31,24 @@ MODULE ReadSetParameters CONTAINS ! ----------------------------------------------------------------------------------- ! Read all constant control parameters from DISCON.IN parameter file - SUBROUTINE ReadControlParameterFileSub(CntrPar) + SUBROUTINE ReadControlParameterFileSub(CntrPar, accINFILE, accINFILE_size)!, accINFILE_size) + USE ROSCO_Types, ONLY : ControlParameters + INTEGER(4) :: accINFILE_size + CHARACTER(KIND=C_CHAR), INTENT(IN) :: accINFILE(89) + CHARACTER(89) :: DISCON_IN INTEGER(4), PARAMETER :: UnControllerParameters = 89 TYPE(ControlParameters), INTENT(INOUT) :: CntrPar + ! CHARACTER(KIND=C_CHAR) :: DISCON_IN(LEN(TRIM(accINFILE))) - OPEN(unit=UnControllerParameters, file='DISCON.IN', status='old', action='read') + ! OPEN(unit=UnControllerParameters, file='/Users/nabbas/Documents/TurbineModels/NREL_5MW/5MW_Land/./DISCON.IN', status='old', action='read') + ! print *, 'accINFILE: ', accINFILE + ! DISCON_IN = TRIM(accINFILE) + ! accINFILE = "DISCON.IN" + DISCON_IN = TRANSFER(accINFILE,' ') + print *, DISCON_IN + OPEN(unit=UnControllerParameters, FILE=trim(DISCON_IN), status='old', action='read') !----------------------- HEADER ------------------------ READ(UnControllerParameters, *) @@ -467,7 +478,7 @@ SUBROUTINE Assert(LocalVar, CntrPar, avrSWAP, aviFAIL, ErrMsg, size_avcMSG) END SUBROUTINE Assert ! ----------------------------------------------------------------------------------- ! Define parameters for control actions - SUBROUTINE SetParameters(avrSWAP, aviFAIL, ErrMsg, size_avcMSG, CntrPar, LocalVar, objInst, PerfData) + SUBROUTINE SetParameters(avrSWAP, aviFAIL, accINFILE, ErrMsg, size_avcMSG, CntrPar, LocalVar, objInst, PerfData) USE ROSCO_Types, ONLY : ControlParameters, LocalVariables, ObjectInstances, PerformanceData INTEGER(4), INTENT(IN) :: size_avcMSG @@ -475,9 +486,10 @@ SUBROUTINE SetParameters(avrSWAP, aviFAIL, ErrMsg, size_avcMSG, CntrPar, LocalVa TYPE(LocalVariables), INTENT(INOUT) :: LocalVar TYPE(ObjectInstances), INTENT(INOUT) :: objInst TYPE(PerformanceData), INTENT(INOUT) :: PerfData - + REAL(C_FLOAT), INTENT(INOUT) :: avrSWAP(*) ! The swap array, used to pass data to, and receive data from, the DLL controller. INTEGER(C_INT), INTENT(OUT) :: aviFAIL ! A flag used to indicate the success of this DLL call set as follows: 0 if the DLL call was successful, >0 if the DLL call was successful but cMessage should be issued as a warning messsage, <0 if the DLL call was unsuccessful or for any other reason the simulation is to be stopped at this point with cMessage as the error message. + CHARACTER(KIND=C_CHAR), INTENT(IN) :: accINFILE(NINT(avrSWAP(50))) ! The name of the parameter input file CHARACTER(size_avcMSG-1), INTENT(OUT) :: ErrMsg ! a Fortran version of the C string argument (not considered an array here) [subtract 1 for the C null-character] INTEGER(4) :: K ! Index used for looping through blades. @@ -523,8 +535,7 @@ SUBROUTINE SetParameters(avrSWAP, aviFAIL, ErrMsg, size_avcMSG, CntrPar, LocalVa 'Visit our GitHub-page to contribute to this project: '//NEW_LINE('A')// & 'https://github.com/NREL/ROSCO '//NEW_LINE('A')// & '------------------------------------------------------------------------------' - - CALL ReadControlParameterFileSub(CntrPar) + CALL ReadControlParameterFileSub(CntrPar, accINFILE, NINT(avrSWAP(50))) IF (CntrPar%WE_Mode > 0) THEN CALL READCpFile(CntrPar,PerfData) From 461f6ec111e4bde45842f70c485c0c757b447874 Mon Sep 17 00:00:00 2001 From: Nikhar Abbas Date: Wed, 18 Dec 2019 13:10:33 -0700 Subject: [PATCH 2/3] Update to read file --- src/ReadSetParameters.f90 | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/ReadSetParameters.f90 b/src/ReadSetParameters.f90 index f0140df5..2946da4a 100644 --- a/src/ReadSetParameters.f90 +++ b/src/ReadSetParameters.f90 @@ -32,23 +32,20 @@ MODULE ReadSetParameters ! ----------------------------------------------------------------------------------- ! Read all constant control parameters from DISCON.IN parameter file SUBROUTINE ReadControlParameterFileSub(CntrPar, accINFILE, accINFILE_size)!, accINFILE_size) - + USE, INTRINSIC :: ISO_C_Binding USE ROSCO_Types, ONLY : ControlParameters INTEGER(4) :: accINFILE_size - CHARACTER(KIND=C_CHAR), INTENT(IN) :: accINFILE(89) - CHARACTER(89) :: DISCON_IN + CHARACTER, DIMENSION(accINFILE_size), INTENT(IN) :: accINFILE INTEGER(4), PARAMETER :: UnControllerParameters = 89 TYPE(ControlParameters), INTENT(INOUT) :: CntrPar ! CHARACTER(KIND=C_CHAR) :: DISCON_IN(LEN(TRIM(accINFILE))) ! OPEN(unit=UnControllerParameters, file='/Users/nabbas/Documents/TurbineModels/NREL_5MW/5MW_Land/./DISCON.IN', status='old', action='read') - ! print *, 'accINFILE: ', accINFILE + print *, 'accINFILE: ', accINFILE ! DISCON_IN = TRIM(accINFILE) ! accINFILE = "DISCON.IN" - DISCON_IN = TRANSFER(accINFILE,' ') - print *, DISCON_IN - OPEN(unit=UnControllerParameters, FILE=trim(DISCON_IN), status='old', action='read') + OPEN(unit=UnControllerParameters, file=accINFILE, status='old', action='read') !----------------------- HEADER ------------------------ READ(UnControllerParameters, *) From 6e51b263f996db8d58d39757055151786798acd4 Mon Sep 17 00:00:00 2001 From: Nikhar Abbas Date: Wed, 18 Dec 2019 13:56:43 -0700 Subject: [PATCH 3/3] Load ServoDyn-defined DISCON input file --- src/ReadSetParameters.f90 | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/ReadSetParameters.f90 b/src/ReadSetParameters.f90 index 2946da4a..2db294b7 100644 --- a/src/ReadSetParameters.f90 +++ b/src/ReadSetParameters.f90 @@ -35,17 +35,13 @@ SUBROUTINE ReadControlParameterFileSub(CntrPar, accINFILE, accINFILE_size)!, acc USE, INTRINSIC :: ISO_C_Binding USE ROSCO_Types, ONLY : ControlParameters - INTEGER(4) :: accINFILE_size - CHARACTER, DIMENSION(accINFILE_size), INTENT(IN) :: accINFILE - INTEGER(4), PARAMETER :: UnControllerParameters = 89 - TYPE(ControlParameters), INTENT(INOUT) :: CntrPar - ! CHARACTER(KIND=C_CHAR) :: DISCON_IN(LEN(TRIM(accINFILE))) - - ! OPEN(unit=UnControllerParameters, file='/Users/nabbas/Documents/TurbineModels/NREL_5MW/5MW_Land/./DISCON.IN', status='old', action='read') - print *, 'accINFILE: ', accINFILE - ! DISCON_IN = TRIM(accINFILE) - ! accINFILE = "DISCON.IN" - OPEN(unit=UnControllerParameters, file=accINFILE, status='old', action='read') + INTEGER(4) :: accINFILE_size ! size of DISCON input filename + CHARACTER(accINFILE_size), INTENT(IN) :: accINFILE(accINFILE_size) ! DISCON input filename + INTEGER(4), PARAMETER :: UnControllerParameters = 89 ! Unit number to open file + TYPE(ControlParameters), INTENT(INOUT) :: CntrPar ! Control parameter type + + + OPEN(unit=UnControllerParameters, file=accINFILE(1), status='old', action='read') !----------------------- HEADER ------------------------ READ(UnControllerParameters, *)