forked from WISDEM/WEIS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update examples and associated files
- Loading branch information
1 parent
569f955
commit d5ca9b3
Showing
13 changed files
with
515 additions
and
341 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.