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

Add baseline supervisory hybrid plant controller #36

Merged
merged 31 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
795ba83
Skeleton hybrid supervisory controller.
misi9170 May 7, 2024
42e4994
passthrough controllers for solar and battery.
misi9170 May 7, 2024
5b02526
hybrid interface added; bugfixes.
misi9170 May 7, 2024
b6324df
print statements, bug fixes.
misi9170 May 7, 2024
761346f
Solar now runs as expected, with some mods on hercules.
misi9170 May 7, 2024
b173cf1
Add example files.
misi9170 May 7, 2024
5d58a19
Ruff.
misi9170 May 7, 2024
ca3b10e
Add other necessary measurements for supervisory control.
misi9170 May 7, 2024
295ef7a
Add interface test.
misi9170 May 13, 2024
1e50219
Full tests for interface; basic test for contorller.
misi9170 May 13, 2024
7492e1b
Get reference in supervisory_control stand in.
misi9170 May 13, 2024
f65ae8c
Fix copy-paste error.
misi9170 May 13, 2024
537ffd9
Add documentation.
misi9170 May 13, 2024
40da443
Add simple hybrid controller
genevievestarke May 14, 2024
e25722a
Updating basic hybrid controller
genevievestarke May 16, 2024
2a4bc1c
Fix Ruff formatting
genevievestarke May 16, 2024
cbcd6af
Fix Ruff lines that are too long
genevievestarke May 16, 2024
d8ca92f
Fix Ruff take 3
genevievestarke May 16, 2024
3c377f0
Removing farm capacity definition from WHOC
genevievestarke May 16, 2024
eef9d2d
Fixing bug for when SOC is maxed out
genevievestarke May 16, 2024
a767a53
Merge pull request #1 from genevievestarke/feature/simple_hybrid_cont…
misi9170 Jun 12, 2024
4b41285
Remove rate setpoint from interface and instead pass directly to inst…
misi9170 Jun 12, 2024
f27dc41
Rename skeleton controller to baseline.
misi9170 Jun 12, 2024
84113c6
Update baseline controller description
genevievestarke Jun 12, 2024
71a80a9
Adding working hybrid plant example
genevievestarke Jul 15, 2024
593817c
Fixing ruff call from update
genevievestarke Jul 16, 2024
f1c8612
Fix ruff formatting
genevievestarke Jul 16, 2024
fc2c100
Clean up output notebook
genevievestarke Jul 24, 2024
74fbbeb
Add headings to example.
misi9170 Jul 25, 2024
73aab54
Import sorting.
misi9170 Jul 25, 2024
d91c41e
Update controller description
genevievestarke Jul 26, 2024
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
970 changes: 970 additions & 0 deletions examples/simple_hybrid_plant/100MW_1axis_pvsamv1.json

Large diffs are not rendered by default.

163 changes: 163 additions & 0 deletions examples/simple_hybrid_plant/amr_input.inp
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨#
# SIMULATION STOP #
#.......................................#
time.stop_time = 100.0 # Max (simulated) time to evolve
time.max_step = -1 # Max number of time steps

#¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨#
# TIME STEP COMPUTATION #
#.......................................#
time.fixed_dt = 0.5 # Use this constant dt if > 0
time.cfl = 0.95 # CFL factor

#¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨#
# INPUT AND OUTPUT #
#.......................................#
time.plot_interval = 3600 # Steps between plot files
time.checkpoint_interval = 3600 # Steps between checkpoint files
io.restart_file = "/projects/ssc/amr_precursors/b_abl_neutral_lowTI_redo/chk14400"

#¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨#
# PHYSICS #
#.......................................#
incflo.gravity = 0. 0. -9.81 # Gravitational force (3D)
incflo.density = 1.0 # Reference density

incflo.use_godunov = 1
incflo.godunov_type = weno_z
incflo.diffusion_type = 1
transport.viscosity = 1.0e-5
transport.laminar_prandtl = 0.7
transport.turbulent_prandtl = 0.3333
turbulence.model = OneEqKsgsM84

incflo.physics = ABL Actuator
ICNS.source_terms = BoussinesqBuoyancy CoriolisForcing ABLMeanBoussinesq ActuatorForcing
TKE.source_terms = KsgsM84Src
BoussinesqBuoyancy.reference_temperature = 300.0
CoriolisForcing.latitude = 41.3
ABLForcing.abl_forcing_height = 90
incflo.velocity = 6.928203230275509 4.0 0.0


# Atmospheric boundary layer
ABL.temperature_heights = 0.0 700.0 800.0 1280.0
ABL.temperature_values = 300.0 300.0 308.0 309.44
ABL.reference_temperature = 300.0
ABL.kappa = .40
ABL.surface_roughness_z0 = 1.0E-4
ABL.Uperiods = 25.0
ABL.Vperiods = 25.0
ABL.cutoff_height = 50.0
ABL.deltaU = 1.0
ABL.deltaV = 1.0
ABL.normal_direction = 2
ABL.perturb_ref_height = 50.0
ABL.perturb_temperature = false
ABL.perturb_velocity = true
ABL.stats_output_format = netcdf
ABL.stats_output_frequency = 1
ABL.surface_temp_flux = 0.00
ABL.wall_shear_stress_type = "Moeng"

ABL.bndry_file = "/projects/ssc/amr_precursors/b_abl_neutral_lowTI_redo/bndry_files"
ABL.bndry_io_mode = 1
ABL.bndry_planes = ylo xlo # I'm (Paul) adding this but not sure if I have to
ABL.bndry_var_names = velocity temperature tke


# Output boundary files
ABL.bndry_planes = ylo xlo
ABL.bndry_output_start_time = 7200.0
ABL.bndry_var_names = velocity temperature tke
ABL.bndry_output_format = native
ABL.stats_output_frequency = 1
ABL.stats_output_format = netcdf

# Whether to use helics
helics.activated = true
helics.broker_port = 32000

#¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨#
# ADAPTIVE MESH REFINEMENT #
#.......................................#
amr.n_cell = 512 512 128 # Grid cells at coarsest AMRlevel
amr.max_level = 0 # Max AMR level in hierarchy

#¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨#
# GEOMETRY #
#.......................................#
geometry.prob_lo = 0. 0. 0. # Lo corner coordinates
geometry.prob_hi = 5120. 5120. 1280. # Hi corner coordinates
geometry.is_periodic = 0 0 0
xlo.type = "mass_inflow"
xlo.density = 1.0
xlo.temperature = 0.0 # value required but ignored
xlo.tke = 0.0
xhi.type = "pressure_outflow"

ylo.type = "mass_inflow"
ylo.density = 1.0
ylo.temperature = 0.0
ylo.tke = 0.0
yhi.type = "pressure_outflow"

# Boundary conditions
zlo.type = "wall_model"
zlo.tke_type = "zero_gradient"

zhi.type = "slip_wall"
zhi.temperature_type = "fixed_gradient"
zhi.temperature = 0.003 # tracer is used to specify potential temperature gradient

#¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨#
# VERBOSITY #
#.......................................#
incflo.verbose = 0 # incflo_level



#¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨#
# SAMPLING #
#.......................................#
incflo.post_processing = samplingPlane samplingLine

samplingPlane.output_frequency = 600
samplingPlane.labels = z_plane
samplingPlane.fields = velocity temperature
samplingPlane.z_plane.type = PlaneSampler
samplingPlane.z_plane.axis1 = 5110 0.0 0.0
samplingPlane.z_plane.axis2 = 0.0 5110 0.0
samplingPlane.z_plane.origin = 5.0 5.0 0.0
samplingPlane.z_plane.num_points = 512 512
samplingPlane.z_plane.normal = 0.0 0.0 1.0
samplingPlane.z_plane.offsets = 5.0 85.0 155.0 255.0


samplingLine.output_frequency = 1
samplingLine.labels = z_line
samplingLine.fields = velocity temperature
samplingLine.z_line.type = LineSampler
samplingLine.z_line.num_points = 128
samplingLine.z_line.start = 5.0 5.0 5.0
samplingLine.z_line.end = 5.0 5.0 1275.0

#¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨#
# TURBINES #
#.......................................#

Actuator.type = UniformCtDisk
Actuator.UniformCtDisk.rotor_diameter = 126.0
Actuator.UniformCtDisk.hub_height = 90.0
Actuator.UniformCtDisk.thrust_coeff = 0.0 0.0 1.132034888 0.999470963 0.917697381 0.860849503 0.815371198 0.811614904 0.807939328 0.80443352 0.800993851 0.79768116 0.794529244 0.791495834 0.788560434 0.787217182 0.787127977 0.785839257 0.783812219 0.783568108 0.783328285 0.781194418 0.777292539 0.773464375 0.769690236 0.766001924 0.762348072 0.758760824 0.755242872 0.751792927 0.748434131 0.745113997 0.717806682 0.672204789 0.63831272 0.610176496 0.585456847 0.563222111 0.542912273 0.399312061 0.310517829 0.248633226 0.203543725 0.169616419 0.143478955 0.122938861 0.106515296 0.093026095 0.081648606 0.072197368 0.064388275 0.057782745 0.0 0.0
Actuator.UniformCtDisk.wind_speed = 0.0 2.9 3.0 4.0 5.0 6.0 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0 9.0 10.0 10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 11.0 11.1 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0 20.0 21.0 22.0 23.0 24.0 25.0 25.1 50.0
Actuator.UniformCtDisk.epsilon = 10.0
Actuator.UniformCtDisk.density = 1.225
Actuator.UniformCtDisk.diameters_to_sample = 1.0
Actuator.UniformCtDisk.num_points_r = 20
Actuator.UniformCtDisk.num_points_t = 5


Actuator.labels = T00 T01
Actuator.T00.base_position = 0.0 0.0 0.0
Actuator.T01.base_position = 1000.0 0.0 0.0
18 changes: 18 additions & 0 deletions examples/simple_hybrid_plant/bash_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Example bash for running things locally
# I just run these one at a t time

# A lot of modules and conda stuff
conda activate hercules

# Set the helics port to use:
export HELICS_PORT=32000

#make sure you use the same port number in the amr_input.inp and hercules_input_000.yaml files.

# Clear old log files for clarity
rm loghercules logfloris

# Set up the helics broker and run the open-loop control simulation
helics_broker -t zmq -f 2 --loglevel="debug" --local_port=$HELICS_PORT &
python3 hercules_runscript_windsolarstorage.py hercules_input_000.yaml >> loghercules 2>&1 &
python3 floris_runscript.py amr_input.inp >> logfloris 2>&1
14 changes: 14 additions & 0 deletions examples/simple_hybrid_plant/floris_runscript.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sys

from hercules.floris_standin import launch_floris

# Check that one command line argument was given
if len(sys.argv) < 2:
raise Exception("Usage: python floris_runscript.py <amr_input_file>")

# # Get the first command line argument
# This is the name of the file to read
amr_input_file = sys.argv[1]
print(f"Running FLORIS standin with input file: {amr_input_file}")

launch_floris(amr_input_file)
71 changes: 71 additions & 0 deletions examples/simple_hybrid_plant/hercules_input_000.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Input YAML for emy_python

# Name
name: example_000

###
# Describe this emulator setup
description: Hybrid wind, solar, and battery plant

dt: 0.5

hercules_comms:

amr_wind:

wind_farm_0:
type: amr_wind_local #options are amr_wind or amr_wind_local
amr_wind_input_file: amr_input.inp

helics:

config:
name: hercules # What is the purpose of this name
use_dash_frontend: False
KAFKA: False
KAFKA_topics: EMUV1py
helics:
# deltat: 1 # This will be assigned in software
subscription_topics: [status]
publication_topics: [control]
endpoints: []
helicsport : 32000
publication_interval: 1
endpoint_interval: 1
starttime: 0
stoptime: 100
Agent: ControlCenter

py_sims:

solar_farm_0: # The name of py_sim object 1

py_sim_type: SolarPySAM
weather_file_name: NonAnnualSimulation-sample_data-interpolated-daytime.csv
system_info_file_name: 100MW_1axis_pvsamv1.json
lat: 39.7442
lon: -105.1778
elev: 1829

# capacity: 100 # MW

initial_conditions:

power: 25 # MW
dni: 1000

battery_0: # The name of py_sim object 1

py_sim_type: LIB
size: 10 # MW size of the battery
energy_capacity: 40 # total capacity of the battery in MWh (4-hour 20 MW battery)
charge_rate: 20 # charge rate of the battery in MW
discharge_rate: 20 # discharge rate of the battery in MW
max_SOC: 0.9 # upper boundary on battery SOC
min_SOC: 0.1 # lower boundary on battery SOC

initial_conditions:
SOC: 0.5 # initial state of charge of the battery as fraction of total size

controller:
num_turbines: 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2021 NREL

# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

# See https://nrel.github.io/wind-hybrid-open-controller for documentation

import sys

from hercules.emulator import Emulator
from hercules.py_sims import PySims
from hercules.utilities import load_yaml
from whoc.controllers import (
BatteryPassthroughController,
HybridSupervisoryControllerSkeleton,
SolarPassthroughController,
WindFarmPowerTrackingController,
)
from whoc.interfaces.hercules_hybrid_actuator_disk_interface import HerculesHybridADInterface

input_dict = load_yaml(sys.argv[1])
input_dict["output_file"] = "hercules_output_hybrid.csv"

interface = HerculesHybridADInterface(input_dict)

print("Setting up controller.")
wind_controller = WindFarmPowerTrackingController(interface, input_dict)
solar_controller = SolarPassthroughController(interface, input_dict)
battery_controller = BatteryPassthroughController(interface, input_dict)
controller = HybridSupervisoryControllerSkeleton(
interface,
input_dict,
wind_controller=wind_controller,
solar_controller=solar_controller,
battery_controller=battery_controller
)

print("Establishing simulators.")
py_sims = PySims(input_dict)

emulator = Emulator(controller, py_sims, input_dict)
emulator.run_helics_setup()
emulator.enter_execution(function_targets=[], function_arguments=[[]])

print("Finished running open-loop controller.")
5 changes: 1 addition & 4 deletions tests/interface_library_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
# See https://nrel.github.io/wind-hybrid-open-controller for documentation

import pytest
from whoc.interfaces import (
HerculesADInterface,
HerculesWindBatteryInterface,
)
from whoc.interfaces import HerculesADInterface, HerculesWindBatteryInterface

test_hercules_dict = {
"dt": 1,
Expand Down
3 changes: 3 additions & 0 deletions whoc/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from whoc.controllers.battery_passthrough_controller import BatteryPassthroughController
from whoc.controllers.hybrid_supervisory_controller import HybridSupervisoryControllerSkeleton
from whoc.controllers.lookup_based_wake_steering_controller import LookupBasedWakeSteeringController
from whoc.controllers.solar_passthrough_controller import SolarPassthroughController
from whoc.controllers.wake_steering_rosco_standin import WakeSteeringROSCOStandin
from whoc.controllers.wind_battery_controller import WindBatteryController
from whoc.controllers.wind_farm_power_tracking_controller import (
Expand Down
28 changes: 28 additions & 0 deletions whoc/controllers/battery_passthrough_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2021 NREL

# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

# See https://nrel.github.io/wind-hybrid-open-controller for documentation


from whoc.controllers.controller_base import ControllerBase


class BatteryPassthroughController(ControllerBase):
"""
Simply passes power reference down to (single) battery.
"""
def __init__(self, interface, input_dict, verbose=True):
super().__init__(interface, verbose)

def compute_controls(self):
reference_power = self.measurements_dict["battery_power_reference"]
self.controls_dict["power_setpoint"] = reference_power
5 changes: 3 additions & 2 deletions whoc/controllers/controller_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ def __init__(self, interface, verbose=True):
# from servers.python_server import WHOC_python_server
# self._s = WHOC_python_server()

# Initialize controls to send
self.controls_dict = None
# Initialize measurements and controls to send
self.measurements_dict = {}
self.controls_dict = {}

def _receive_measurements(self, dict=None):
# May need to eventually loop here, depending on server set up.
Expand Down
Loading
Loading