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

Updating WHOC/HERCULES communication to fix logging issue. #33

Merged
merged 7 commits into from
Mar 28, 2024
Merged
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
31 changes: 14 additions & 17 deletions tests/controller_library_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}

Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -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}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions tests/interface_library_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}

Expand Down Expand Up @@ -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"]
)
4 changes: 3 additions & 1 deletion whoc/interfaces/hercules_wind_battery_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading