Skip to content

Commit

Permalink
Update examples and associated files
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhar-abbas committed Nov 21, 2019
1 parent 569f955 commit d5ca9b3
Show file tree
Hide file tree
Showing 13 changed files with 515 additions and 341 deletions.
165 changes: 165 additions & 0 deletions Examples/Cp_Ct_Cq.Ex03.txt

Large diffs are not rendered by default.

162 changes: 84 additions & 78 deletions Examples/DISCON.IN

Large diffs are not rendered by default.

90 changes: 40 additions & 50 deletions Examples/Example_07.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,49 @@
# Example_07
# Load gain schedules, write_paramter input file, plot gains

#%%
import numpy as np
from scipy import interpolate
import yaml

from WTC_toolbox import controller as wtc_controller
from WTC_toolbox import turbine as wtc_turbine
from WTC_toolbox import sim as wtc_sim
import os

# Ensure propper working directory
os.chdir('/Users/nabbas/Documents/WindEnergyToolbox/WTC_toolbox/examples')

# parameter filename
parameter_filename = 'NREL5MW.yaml' # Name of .yaml input file for the specific turbine

# Load input file contents, put them in some dictionaries to keep things cleaner
# ----------- Example_07 --------------
# Load saved turbine, tune controller, plot minimum pitch schedule
# -------------------------------------
#
# In this example:
# - Load a yaml file
# - Load a turbien from openfast
# - Tune a controller
# - Plot minimum pitch schedule


# Python modules
import matplotlib.pyplot as plt
import yaml
# ROSCO toolbox modules
from ROSCO_toolbox import controller as wtc_controller
from ROSCO_toolbox import turbine as wtc_turbine
from ROSCO_toolbox import sim as wtc_sim
from ROSCO_toolbox import utilities as wtc_utilities

# Load yaml file
parameter_filename = 'NREL5MW_example.yaml'
inps = yaml.safe_load(open(parameter_filename))
path_params = inps['path_params']
turbine_params = inps['turbine_params']
controller_params = inps['controller_params']
path_params = inps['path_params']
turbine_params = inps['turbine_params']
controller_params = inps['controller_params']

# Ensure minimum generator speed at 50 rpm (for example's sake), turn on peak shaving and cp-maximizing min pitch
controller_params['vs_minspd'] = 50
controller_params['PS_Mode'] = 3

# Initialiize turbine, controller, and file processing classes
# Instantiate turbine, controller, and file processing classes
turbine = wtc_turbine.Turbine(turbine_params)
controller = wtc_controller.Controller(controller_params)
file_processing = wtc_controller.FileProcessing()

# Fast input file and Cp surface text file
FAST_InputFile = '5MW_Land.fst'
FAST_directory = '/Users/nabbas/Documents/TurbineModels/NREL_5MW/5MW_Land'
txt_filename = 'Cp_Ct_Cq.txt'
file_processing = wtc_utilities.FileProcessing()

# Load turbine data from OpenFAST and rotor performance text file
turbine.load_from_fast(path_params['FAST_InputFile'],path_params['FAST_directory'],dev_branch=True,rot_source='txt',txt_filename=path_params['rotor_performance_filename'])

# Load controller
# Tune controller
controller.tune_controller(turbine)

# Write parameter input file
param_file = 'DISCON_TEST.IN'
file_processing.write_param_file(param_file,turbine,controller,new_file=True)

# Plot
import matplotlib.pyplot as pl

pl.figure(0)
pl.plot(controller.v[len(controller.vs_gain_schedule.Kp):], controller.pc_gain_schedule.Kp)
pl.xlabel('Wind Speed')
pl.ylabel('Proportional Gain')

pl.figure(1)
pl.plot(controller.v[len(controller.vs_gain_schedule.Ki):], controller.pc_gain_schedule.Ki)
pl.xlabel('Wind Speed')
pl.ylabel('Integral Gain')

pl.show()

# Plot minimum pitch schedule
plt.plot(controller.v, controller.pitch_op,label='Steady State Operation')
plt.plot(controller.v, controller.ps_min_bld_pitch, label='Minimum Pitch Schedule')
plt.legend()
plt.xlabel('Wind speed (m/s)')
plt.ylabel('Blade pitch (rad)')
plt.show()
6 changes: 3 additions & 3 deletions Examples/NREL5MW_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ------------------------------ OpenFAST PATH DEFINITIONS ------------------------------
path_params:
FAST_InputFile: '5MW_Land.fst' # Name of *.fst file
FAST_directory: '../5MW_Land/' # Main OpenFAST model directory, where the *.fst lives
FAST_directory: '../Test_Cases/5MW_Land/' # Main OpenFAST model directory, where the *.fst lives
# FAST_directory: '/Users/nabbas/Documents/WindEnergyToolbox/WTC_toolbox/Test_Cases/5MW_Land' # Main OpenFAST model directory, where the *.fst is
# Optional
rotor_performance_filename: 'Cp_Ct_Cq.NREL5MW.txt' # Filename for rotor performance text file (if it has been generated by ccblade already)
Expand Down Expand Up @@ -33,7 +33,7 @@ controller_params:
Y_ControlMode: 0 # Yaw control mode {0: no yaw control, 1: yaw rate control, 2: yaw-by-IPC}
SS_Mode: 1 # Setpoint Smoother mode {0: no setpoint smoothing, 1: introduce setpoint smoothing}
WE_Mode: 2 # Wind speed estimator mode {0: One-second low pass filtered hub height wind speed, 1: Immersion and Invariance Estimator (Ortega et al.)}
PS_Mode: 20 # Pitch saturation mode {0: no pitch saturation, 1: peak shaving, 2: Cp-maximizing pitch saturation, 3: peak shaving and Cp-maximizing pitch saturation}
PS_Mode: 0 # Pitch saturation mode {0: no pitch saturation, 1: peak shaving, 2: Cp-maximizing pitch saturation, 3: peak shaving and Cp-maximizing pitch saturation}
SD_Mode: 0 # Shutdown mode {0: no shutdown procedure, 1: pitch to max pitch at shutdown}
# Controller parameters
zeta_pc: 0.7 # Pitch controller desired damping ratio [-]
Expand All @@ -43,7 +43,7 @@ controller_params:
# Optional - these can be defined, but do not need to be
max_pitch: # None # Maximum pitch angle [rad], {default = 90 degrees}
min_pitch: # None # Minimum pitch angle [rad], {default = 0 degrees}
pc_minspd: # None # Minimum rotor speed [rad/s], {default = 0 rad/s}
vs_minspd: # None # Minimum rotor speed [rad/s], {default = 0 rad/s}
ss_cornerfreq: # None # First order low-pass filter cornering frequency for setpoint smoother [rad/s]
ss_vsgain: # None # Torque controller setpoint smoother gain bias percentage [%, <= 1 ], {default = 100%}
ss_pcgain: # None # Pitch controller setpoint smoother gain bias percentage [%, <= 1 ], {default = 0.1%}
Expand Down
12 changes: 10 additions & 2 deletions Examples/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Examples
We offer some example scripts to showcase the functionalities of the ROSCO toolbox. Enjoy!
We offer some example scripts to showcase the functionalities of the ROSCO toolbox. This offers a non-inclusive overview of some of the primary functionalities of the ROSCO toolbox. Enjoy!

- Example 1: Load and save a turbine model. Calculates rotor performance metrics, prints some basic turbine data, and saves the turbine.
Examples:
1. Load and save a turbine model. Prints some basic turbine data, and saves the turbine.
2. Load a turbine model from saved pickle, make a Cp surface plot.
3. Run CCblade, save a rotor performance text file.
4. Load a turbine model and tune the controller.
5. Run and plot a simple simple step wind simulation.
6. Load a turbine, tune a controller, run an OpenFAST simulation.
7. Load saved turbine, tune controller, plot minimum pitch schedule.
8. Plot some OpenFAST output data.
10 changes: 3 additions & 7 deletions Examples/example_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,22 @@
# In this example:
# - Read .yaml input file
# - Load an openfast turbine model
# - Run CCBlade to find the rotor performance properties
# - Read text file with rotor performance properties
# - Print some basic turbine properties
# - Save the turbine as a picklle
#
# Note: Uses the NREL 5MW included in the Test Cases and is a part of the OpenFAST distribution

# Python Modules
import yaml
import os
# ROSCO Modules
from ROSCO_toolbox import turbine as wtc_turbine
from ROSCO_toolbox import controller as wtc_controller
from ROSCO_toolbox import sim as wtc_sim

# Point to yaml and openfast file
# Load yaml file
parameter_filename = '../Tune_Cases/NREL5MW.yaml'
inps = yaml.safe_load(open(parameter_filename))
path_params = inps['path_params']
turbine_params = inps['turbine_params']
controller_params = inps['controller_params']

# Load turbine data from openfast model
turbine = wtc_turbine.Turbine(turbine_params)
Expand All @@ -33,4 +29,4 @@
print(turbine)

# Save the turbine model
turbine.save('saved_turbine.p')
turbine.save('NREL5MW_saved.p')
53 changes: 17 additions & 36 deletions Examples/example_02.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,24 @@
# Example_04
# Load a turbine model from saved pickle, make a quick cp plot


from WTC_toolbox import turbine as wtc_turbine
from WTC_toolbox import controller as wtc_controller
from WTC_toolbox import sim as wtc_sim
import numpy as np
# ----------- Example_02 --------------
# Load a turbine model from saved pickle, make a quick cp plot
# -------------------------------------
#
# In this example:
# - Load a turbine from a saved pickle
# - Plot Cp Surface

# Python modules
import matplotlib.pyplot as plt
# ROSCO toolbox modules
from ROSCO_toolbox import turbine as wtc_turbine

# Initialiize a turbine class
turbine = wtc_turbine.Turbine()

# Load quick from python
# turbine.load('saved_turbine.p')

# ## Or Load the turbine model from a FAST input folder
FAST_InputFile = '5MW_Land.fst'
FAST_directory = '/Users/nabbas/Documents/TurbineModels/NREL_5MW/5MW_Land'
txt_filename = 'Cp_Ct_Cq.txt'
drivetrain_inertia = 40469564.444
turbine.load_from_fast(FAST_InputFile,FAST_directory,drivetrain_inertia=drivetrain_inertia,dev_branch=True,rot_source=None,txt_filename='Cp_Ct_Cq.txt')

# Sweep TSR and fix pitch in two positions
fixed_rpm = 10. # RPM
fixed_pitch = 0.

tsr = np.arange(1,15,0.1)
# Initialize a turbine class -- Don't need to instantiate!
turbine = wtc_turbine.Turbine

# cp_0 = np.array([turbine.cp_interp(t,0) for t in tsr])
# cp_3 = np.array([turbine.cp_interp(t,3) for t in tsr])
cp_0 = np.array([turbine.Cp.interp_surface(0,t) for t in tsr])
cp_3 = np.array([turbine.Cp.interp_surface(np.deg2rad(3),t) for t in tsr])
# Load quick from python pickle
turbine = turbine.load('NREL5MW_saved.p')

# plot rotor performance
print('Plotting Cp data')
fig, ax = plt.subplots()
ax.plot(tsr,cp_0,label='Pitch=0')
ax.plot(tsr,cp_3,label='Pitch=3')
ax.set_xlabel('TSR')
ax.set_ylabel('Cp')
ax.grid(True)
ax.legend()
turbine.Cp.plot_performance(turbine.Cp_table, turbine.pitch_initial_rad, turbine.TSR_initial)
plt.show()
37 changes: 32 additions & 5 deletions Examples/example_03.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
# Example_03
# Load controller parameter file, make some changes and save as new file
# ----------- Example_03 --------------
# Run CCblade, save a rotor performance text file
# -------------------------------------
#
# In this example:
# - Read .yaml input file
# - Load an openfast turbine model
# - Run ccblade to get rotor performance properties
# - Write a text file with rotor performance properties

# Python modules
import yaml
# ROSCO toolbox modules
from ROSCO_toolbox import turbine as wtc_turbine
from ROSCO_toolbox import utilities as wtc_utilities
# Initialize parameter dictionaries
turbine_params = {}
control_params = {}

from WTC_toolbox import turbine as wtc_turbine
from WTC_toolbox import controller as wtc_controller
from WTC_toolbox import sim as wtc_sim
# Load yaml file
parameter_filename = '../Tune_Cases/NREL5MW.yaml'
inps = yaml.safe_load(open(parameter_filename))
path_params = inps['path_params']
turbine_params = inps['turbine_params']
controller_params = inps['controller_params']

# Load turbine data from openfast model
turbine = wtc_turbine.Turbine(turbine_params)
turbine.load_from_fast(path_params['FAST_InputFile'],path_params['FAST_directory'],dev_branch=True,rot_source=None,txt_filename=None)

# Write rotor performance text file
txt_filename = 'Cp_Ct_Cq.Ex03.txt'
file_processing = wtc_utilities.FileProcessing()
file_processing.write_rotor_performance(turbine,txt_filename=txt_filename)
59 changes: 50 additions & 9 deletions Examples/example_04.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,54 @@
# Example_04
# Load a turbine model and use to tune the controller
# ----------- Example_04 --------------
# Load a turbine model and tune the controller
# -------------------------------------
#
# In this example:
# - Read a .yaml file
# - Load a turbine model from OpenFAST
# - Tune a controller
# - Write a controller input file
# - Plot gain schedule

# Python modules
import matplotlib.pyplot as plt
import yaml
# ROSCO toolbox modules
from ROSCO_toolbox import controller as wtc_controller
from ROSCO_toolbox import turbine as wtc_turbine
from ROSCO_toolbox import sim as wtc_sim
from ROSCO_toolbox import utilities as wtc_utilities

from WTC_toolbox import turbine as wtc_turbine
from WTC_toolbox import controller as wtc_controller
from WTC_toolbox import sim as wtc_sim
# Load yaml file
parameter_filename = '../Tune_Cases/NREL5MW.yaml'
inps = yaml.safe_load(open(parameter_filename))
path_params = inps['path_params']
turbine_params = inps['turbine_params']
controller_params = inps['controller_params']

# Initialiize a turbine class
turbine = wtc_turbine.Turbine()
# Instantiate turbine, controller, and file processing classes
turbine = wtc_turbine.Turbine(turbine_params)
controller = wtc_controller.Controller(controller_params)
file_processing = wtc_utilities.FileProcessing()

# Load quick from python
turbine.load('saved_turbine.p')
# Load turbine data from OpenFAST and rotor performance text file
turbine.load_from_fast(path_params['FAST_InputFile'],path_params['FAST_directory'],dev_branch=True,rot_source='txt',txt_filename=path_params['rotor_performance_filename'])

# Tune controller
controller.tune_controller(turbine)

# Write parameter input file
param_file = 'DISCON.IN' # This must be named DISCON.IN to be seen by the compiled controller binary.
file_processing.write_param_file(turbine,controller,param_file=param_file, txt_filename=path_params['rotor_performance_filename'])

# Plot gain schedule
plt.figure(0)
plt.plot(controller.v[len(controller.vs_gain_schedule.Kp):], controller.pc_gain_schedule.Kp)
plt.xlabel('Wind Speed')
plt.ylabel('Proportional Gain')

plt.figure(1)
plt.plot(controller.v[len(controller.vs_gain_schedule.Ki):], controller.pc_gain_schedule.Ki)
plt.xlabel('Wind Speed')
plt.ylabel('Integral Gain')

plt.show()
Loading

0 comments on commit d5ca9b3

Please sign in to comment.