Skip to content

Commit

Permalink
Check for prior initialization of ROSCO (#401)
Browse files Browse the repository at this point in the history
* Add mpi_tools to rosco

* Check for prior initialization

* Check if ROSCO has already been initialized

* Add unit test for rosco initialization

* Run example 4

* Only publish on macos-latest

* Update install directory
  • Loading branch information
dzalkind authored Dec 11, 2024
1 parent e003136 commit 122c758
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 169 deletions.
3 changes: 3 additions & 0 deletions Examples/04_simple_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,6 @@ def main():
else:
plt.savefig(os.path.join(example_out_dir,'04_NREL5MW_SimpSim.png'))

if __name__=='__main__':
main()

2 changes: 1 addition & 1 deletion rosco/controller/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,5 @@ set(linuxDefault ${CMAKE_INSTALL_PREFIX} STREQUAL "/usr/local")
set(windowsDefault ${CMAKE_INSTALL_PREFIX} STREQUAL "C:\\Program Files (x86)")
if(${linuxDefault} OR ${windowsDefault})
message("TRUE")
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/../../")
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/../")
endif()
4 changes: 4 additions & 0 deletions rosco/controller/rosco_registry/rosco_types.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,10 @@ LocalVariables:
iStatus:
<<: *integer
description: Initialization status
AlreadyInitialized:
<<: *integer
description: Has ROSCO already been initialized (0-no, 1-yes)
equals: 0
Time:
<<: *real
description: Time [s]
Expand Down
4 changes: 2 additions & 2 deletions rosco/controller/rosco_registry/write_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def write_types(yfile):
for attype in reg[toptype].keys():
f90type = read_type(reg[toptype][attype])
atstr = check_size(reg[toptype], attype)
if reg[toptype][attype]['equals']:
atstr += ' = ' + reg[toptype][attype]['equals']
if reg[toptype][attype]['equals'] is not None:
atstr += ' = ' + str(reg[toptype][attype]['equals'])
file.write(' {:<25s} :: {:<25s} ! {}\n'.format(f90type, atstr, reg[toptype][attype]['description']))
file.write('END TYPE {}\n'.format(toptype))
file.write('\n')
Expand Down
6 changes: 4 additions & 2 deletions rosco/controller/src/DISCON.F90
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ SUBROUTINE DISCON(avrSWAP, aviFAIL, accINFILE, avcOUTNAME, avcMSG) BIND (C, NAME
END IF

! Read avrSWAP array into derived types/variables
CALL ReadAvrSWAP(avrSWAP, LocalVar, CntrPar)
CALL ReadAvrSWAP(avrSWAP, LocalVar, CntrPar, ErrVar)

! Set Control Parameters
CALL SetParameters(avrSWAP, accINFILE, SIZE(avcMSG), CntrPar, LocalVar, objInst, PerfData, RootName, ErrVar)
IF (ErrVar%aviFAIL >= 0) THEN
CALL SetParameters(avrSWAP, accINFILE, SIZE(avcMSG), CntrPar, LocalVar, objInst, PerfData, RootName, ErrVar)
ENDIF

! Call external controller, if desired
IF (CntrPar%Ext_Mode > 0 .AND. ErrVar%aviFAIL >= 0) THEN
Expand Down
324 changes: 164 additions & 160 deletions rosco/controller/src/ROSCO_IO.f90

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion rosco/controller/src/ROSCO_Types.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
! ROSCO Registry
! This file is automatically generated by write_registry.py using ROSCO v2.9.0
! This file is automatically generated by write_registry.py using ROSCO v2.9.4
! For any modification to the registry, please edit the rosco_types.yaml accordingly

MODULE ROSCO_Types
Expand Down Expand Up @@ -248,6 +248,7 @@ MODULE ROSCO_Types

TYPE, PUBLIC :: LocalVariables
INTEGER(IntKi) :: iStatus ! Initialization status
INTEGER(IntKi) :: AlreadyInitialized = 0 ! Has ROSCO already been initialized (0-no, 1-yes)
REAL(DbKi) :: Time ! Time [s]
REAL(DbKi) :: DT ! Time step [s]
LOGICAL :: WriteThisStep ! Write an output line this time step
Expand Down
16 changes: 13 additions & 3 deletions rosco/controller/src/ReadSetParameters.f90
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ MODULE ReadSetParameters
CONTAINS
! -----------------------------------------------------------------------------------
! Read avrSWAP array passed from ServoDyn
SUBROUTINE ReadAvrSWAP(avrSWAP, LocalVar, CntrPar)
SUBROUTINE ReadAvrSWAP(avrSWAP, LocalVar, CntrPar, ErrVar)
USE ROSCO_Types, ONLY : LocalVariables

REAL(ReKi), INTENT(INOUT) :: avrSWAP(*) ! The swap array, used to pass data to, and receive data from, the DLL controller.
TYPE(LocalVariables), INTENT(INOUT) :: LocalVar
TYPE(ControlParameters), INTENT(IN) :: CntrPar
TYPE(ErrorVariables), INTENT(INOUT) :: ErrVar

! Allocate Variables:
INTEGER(IntKi) :: K ! Index used for looping through blades.
Expand Down Expand Up @@ -79,9 +80,18 @@ SUBROUTINE ReadAvrSWAP(avrSWAP, LocalVar, CntrPar)

ENDIF

! GenTemp = avrSWAP(1026)

! WRITE(1000,*) LocalVar%GenSpeed*RPS2RPM, GenTemp
! Check that we haven't already loaded this dynamic library
IF (LocalVar%iStatus == 0) THEN
IF (LocalVar%AlreadyInitialized == 0) THEN
LocalVar%AlreadyInitialized = 1
ELSE
ErrVar%aviFAIL = -1
ErrVar%ErrMsg = 'ERROR: This ROSCO dynamic library has already been loaded.'
RETURN
ENDIF
ENDIF




Expand Down
34 changes: 34 additions & 0 deletions rosco/test/test_initialization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'''
Unit testing for ROSCO
Tests:
initialization
'''

import os
import unittest


# ROSCO toolbox modules
from rosco import discon_lib_path
from rosco.toolbox import control_interface as ROSCO_ci


class UnitTesting(unittest.TestCase):
def test_initialization(self):

this_dir = os.path.dirname(os.path.abspath(__file__))
param_filename = os.path.join(this_dir,'../../Examples/Test_Cases/IEA-15-240-RWT-UMaineSemi/DISCON-UMaineSemi.IN')


# Load controller library
ci_1 = ROSCO_ci.ControllerInterface(discon_lib_path,param_filename=param_filename,sim_name='sim1')

ci_2 = ROSCO_ci.ControllerInterface(discon_lib_path,param_filename=param_filename,sim_name='sim2')

# Check that the error is as expected
assert("b'ROSCO:ERROR: This ROSCO dynamic library has already been loaded" == str(ci_2.avcMSG.raw).split('.')[0])


if __name__ == "__main__":
unittest.main()

0 comments on commit 122c758

Please sign in to comment.