diff --git a/tests/controller_library_test.py b/tests/controller_library_test.py index f39505ec..1d28e11e 100644 --- a/tests/controller_library_test.py +++ b/tests/controller_library_test.py @@ -55,7 +55,7 @@ def send_controls(self): } } }, - "py_sims": {"test_battery": {"outputs": 10.0}}, + "py_sims": {"test_battery": {"outputs": 10.0}, "inputs": {}}, "external_signals": {"wind_power_reference": 1000.0}, } @@ -75,7 +75,7 @@ def test_controller_instantiation(): # def test_LookupBasedWakeSteeringController(): # test_interface = HerculesADInterface(test_hercules_dict) - + # # No lookup table passed; simply passes through wind direction to yaw angles # test_controller = LookupBasedWakeSteeringController( # interface=test_interface, @@ -99,7 +99,7 @@ def test_controller_instantiation(): # df_opt_test = pd.DataFrame(data={ # "wind_direction":[220.0, 320.0, 220.0, 320.0], # "wind_speed":[0.0, 0.0, 20.0, 20.0], -# "yaw_angles_opt":[test_offsets]*4, +# "yaw_angles_opt":[test_offsets]*4, # "turbulence_intensity":[0.06]*4 # }) # test_controller = LookupBasedWakeSteeringController( @@ -118,20 +118,19 @@ def test_controller_instantiation(): # ) # assert np.allclose(test_angles, wind_directions - test_offsets) -def test_WindBatteryController(): +def test_WindBatteryController(): test_interface = HerculesWindBatteryInterface(test_hercules_dict) test_controller = WindBatteryController(test_interface, test_hercules_dict) - # Check the low level methods behave as expected test_controller._receive_measurements(test_hercules_dict) wind_setpoints = test_controller.calc_wind_setpoints() - assert not wind_setpoints # wind setpoints should be empty + assert not wind_setpoints # wind setpoints should be empty battery_setpoints = test_controller.calc_battery_setpoints() - assert battery_setpoints["signal"] == -500 # battery setpoints should not be empty + assert battery_setpoints["signal"] == -500 # battery setpoints should not be empty test_controller.compute_controls() assert test_controller.setpoints_dict == {"wind": wind_setpoints, "battery": battery_setpoints} @@ -140,18 +139,18 @@ def test_WindBatteryController(): # We will need to change these cases when the wind_battery_controller has more general behavior test_hercules_dict["hercules_comms"]["amr_wind"]["test_farm"]["turbine_powers"] = [450, 450] hercules_dict_out = test_controller.step(test_hercules_dict) - assert hercules_dict_out["setpoints"]["battery"]["signal"] == 900 + assert hercules_dict_out["py_sims"]["inputs"]["battery_signal"] == 900 test_hercules_dict["hercules_comms"]["amr_wind"]["test_farm"]["turbine_powers"] = [550, 550] hercules_dict_out = test_controller.step(test_hercules_dict) - assert hercules_dict_out["setpoints"]["battery"]["signal"] == -500 + assert hercules_dict_out["py_sims"]["inputs"]["battery_signal"] == -500 + def test_WindFarmPowerDistributingController(): test_interface = HerculesADInterface(test_hercules_dict) test_controller = WindFarmPowerDistributingController( - interface=test_interface, - input_dict=test_hercules_dict + interface=test_interface, input_dict=test_hercules_dict ) # Default behavior when no power reference is given @@ -163,7 +162,7 @@ def test_WindFarmPowerDistributingController(): ) assert np.allclose( test_power_setpoints, - POWER_SETPOINT_DEFAULT/test_hercules_dict["controller"]["num_turbines"] + POWER_SETPOINT_DEFAULT / test_hercules_dict["controller"]["num_turbines"], ) # Test with power reference @@ -174,12 +173,12 @@ def test_WindFarmPowerDistributingController(): ) assert np.allclose(test_power_setpoints, 500) + def test_WindFarmPowerTrackingController(): test_interface = HerculesADInterface(test_hercules_dict) test_controller = WindFarmPowerTrackingController( - interface=test_interface, - input_dict=test_hercules_dict + interface=test_interface, input_dict=test_hercules_dict ) # Test no change to power setpoints if producing desired power @@ -215,9 +214,7 @@ def test_WindFarmPowerTrackingController(): # Test that more aggressive control leads to faster response test_controller = WindFarmPowerTrackingController( - interface=test_interface, - input_dict=test_hercules_dict, - proportional_gain=2 + interface=test_interface, input_dict=test_hercules_dict, proportional_gain=2 ) test_hercules_dict["hercules_comms"]["amr_wind"]["test_farm"]["turbine_powers"] = [600, 600] test_hercules_dict_out = test_controller.step(hercules_dict=test_hercules_dict) diff --git a/tests/interface_library_test.py b/tests/interface_library_test.py index a0bdf860..daea48ce 100644 --- a/tests/interface_library_test.py +++ b/tests/interface_library_test.py @@ -30,7 +30,7 @@ } } }, - "py_sims": {"test_battery": {"outputs": 10.0}}, + "py_sims": {"test_battery": {"outputs": 10.0}, "inputs": {}}, "external_signals": {"wind_power_reference": 1000.0}, } @@ -125,9 +125,12 @@ def test_HerculesWindBatteryInterface(): # check_controls is pass-through # Test send_controls() - controls_dict = {"test": 0} + controls_dict = {"battery": {"signal": 0}} test_hercules_dict_out = interface.send_controls( hercules_dict=test_hercules_dict, controls_dict=controls_dict ) - assert test_hercules_dict_out["setpoints"] == controls_dict + assert ( + test_hercules_dict_out["py_sims"]["inputs"]["battery_signal"] + == controls_dict["battery"]["signal"] + ) diff --git a/whoc/interfaces/hercules_wind_battery_interface.py b/whoc/interfaces/hercules_wind_battery_interface.py index c49b8ca6..e905e69f 100644 --- a/whoc/interfaces/hercules_wind_battery_interface.py +++ b/whoc/interfaces/hercules_wind_battery_interface.py @@ -45,5 +45,7 @@ def check_controls(self, controls_dict): return controls def send_controls(self, hercules_dict, controls_dict=None): - hercules_dict.update({"setpoints": controls_dict}) + hercules_dict["py_sims"]["inputs"].update( + {"battery_signal": controls_dict["battery"]["signal"]} + ) return hercules_dict