Skip to content

Commit

Permalink
Merge pull request WISDEM#37 from NREL/develop
Browse files Browse the repository at this point in the history
Update Main
  • Loading branch information
nikhar-abbas authored Mar 10, 2021
2 parents 9f2cf6a + 53343d1 commit 8ac261d
Show file tree
Hide file tree
Showing 311 changed files with 44,410 additions and 214,805 deletions.
13 changes: 10 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ _build
*.out
*.outb
*.dbg
*.vtp

# Fortran files
# ROSCO files
*.85
*.i90
*local*

# Binaries
*.dylib
Expand All @@ -46,7 +49,11 @@ examples/cp_ct_cq_lut.p
Examples/DISCON.IN
Examples/*.p

# Matlab Stuff
Matlab_Toolbox/*.slxc
# Exclude testing results
ROSCO_testing/results/

# Simulink/Matlab temp files
*.slxc
*.autosave
*.mat

3 changes: 2 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "ROSCO"]
path = ROSCO
url = https://github.com/NREL/ROSCO.git
url = https://github.com/NREL/ROSCO
branch = main
1 change: 1 addition & 0 deletions Examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Cp_Ct_Cq.*.txt
*.p
examples_out/
165 changes: 0 additions & 165 deletions Examples/Cp_Ct_Cq.Ex03.txt

This file was deleted.

54 changes: 27 additions & 27 deletions Examples/DISCON.IN

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Examples/NREL5MW_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# Turbine: NREL 5MW Reference Wind Turbine
# ------------------------------ OpenFAST PATH DEFINITIONS ------------------------------
path_params:
FAST_InputFile: '5MW_Land_DLL_WTurb.fst' # Name of *.fst file
FAST_directory: '../Test_Cases/5MW_Land_DLL_WTurb' # Main OpenFAST model directory, where the *.fst lives
FAST_InputFile: 'NREL-5MW.fst' # Name of *.fst file
FAST_directory: '../Test_Cases/NREL-5MW' # Main OpenFAST model directory, where the *.fst lives
# 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
Binary file removed Examples/NREL5MW_saved.p
Binary file not shown.
3 changes: 2 additions & 1 deletion Examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ Examples:
7. Load saved turbine, tune controller, plot minimum pitch schedule.
8. Plot some OpenFAST output data.
9. Run turbsim to compile binary.
10. Tune a controller for distributed aerodynamic control.
10. Tune a controller for distributed aerodynamic control.
11. Generate simplified linear models, save the parameters to a file.
96 changes: 43 additions & 53 deletions Examples/ROSCO_walkthrough.ipynb

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions Examples/example_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,33 @@
'''

# Python Modules
import yaml
import yaml, os
# ROSCO Modules
from ROSCO_toolbox import turbine as ROSCO_turbine

# Load yaml file
parameter_filename = 'NREL5MW_example.yaml'
this_dir = os.path.dirname(os.path.abspath(__file__))
parameter_filename = os.path.join(this_dir,'NREL5MW_example.yaml')
inps = yaml.safe_load(open(parameter_filename))
path_params = inps['path_params']
turbine_params = inps['turbine_params']

# Load turbine data from openfast model
turbine = ROSCO_turbine.Turbine(turbine_params)
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'])

turbine.load_from_fast(
path_params['FAST_InputFile'],
os.path.join(this_dir,path_params['FAST_directory']),
dev_branch=True,
rot_source='txt',txt_filename=os.path.join(this_dir,path_params['rotor_performance_filename'])
)

# Print some basic turbine info
print(turbine)

# Save the turbine model
turbine.save('NREL5MW_saved.p')
example_out_dir = os.path.join(this_dir,'examples_out')
if not os.path.isdir(example_out_dir):
os.makedirs(example_out_dir)

turbine.save(os.path.join(example_out_dir,'01_NREL5MW_saved.p'))
17 changes: 14 additions & 3 deletions Examples/example_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,29 @@
'''

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

this_dir = os.path.dirname(os.path.abspath(__file__))
example_out_dir = os.path.join(this_dir,'examples_out')
if not os.path.isdir(example_out_dir):
os.makedirs(example_out_dir)

# Initialize a turbine class -- Don't need to instantiate!
turbine = ROSCO_turbine.Turbine

# Load quick from python pickle
turbine = turbine.load('NREL5MW_saved.p')
turbine = turbine.load(os.path.join(example_out_dir,'01_NREL5MW_saved.p'))

# plot rotor performance
print('Plotting Cp data')
turbine.Cp.plot_performance(turbine.Cp_table, turbine.pitch_initial_rad, turbine.TSR_initial)
plt.show()
turbine.Cp.plot_performance()



if False:
plt.show()
else:
plt.savefig(os.path.join(example_out_dir,'02_NREL5MW_Cp.png'))
23 changes: 16 additions & 7 deletions Examples/example_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,35 @@
- Write a text file with rotor performance properties
'''
# Python modules
import yaml
import yaml, os
# ROSCO toolbox modules
from ROSCO_toolbox import turbine as ROSCO_turbine
from ROSCO_toolbox import utilities as ROSCO_utilities
from ROSCO_toolbox.utilities import write_rotor_performance
# Initialize parameter dictionaries
turbine_params = {}
control_params = {}

this_dir = os.path.dirname(os.path.abspath(__file__))
example_out_dir = os.path.join(this_dir,'examples_out')
if not os.path.isdir(example_out_dir):
os.makedirs(example_out_dir)

# Load yaml file
parameter_filename = '../Tune_Cases/NREL5MW.yaml'
parameter_filename = os.path.join(this_dir,'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']

# Load turbine data from openfast model
turbine = ROSCO_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)
turbine.load_from_fast(
path_params['FAST_InputFile'],
os.path.join(this_dir,path_params['FAST_directory']),
dev_branch=True,
rot_source='cc-blade',
txt_filename=None)

# Write rotor performance text file
txt_filename = 'Cp_Ct_Cq.Ex03.txt'
file_processing = ROSCO_utilities.FileProcessing()
file_processing.write_rotor_performance(turbine,txt_filename=txt_filename)
txt_filename = os.path.join(example_out_dir,'03_Cp_Ct_Cq.Ex03.txt')
write_rotor_performance(turbine,txt_filename=txt_filename)
43 changes: 28 additions & 15 deletions Examples/example_04.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
'''
# Python modules
import matplotlib.pyplot as plt
import yaml
import yaml, os
# ROSCO toolbox modules
from ROSCO_toolbox import controller as ROSCO_controller
from ROSCO_toolbox import turbine as ROSCO_turbine
from ROSCO_toolbox import sim as ROSCO_sim
from ROSCO_toolbox import utilities as ROSCO_utilities
from ROSCO_toolbox.utilities import write_DISCON

# Load yaml file
parameter_filename = 'NREL5MW_example.yaml'
this_dir = os.path.dirname(os.path.abspath(__file__))
parameter_filename = os.path.join(this_dir,'NREL5MW_example.yaml')
inps = yaml.safe_load(open(parameter_filename))
path_params = inps['path_params']
turbine_params = inps['turbine_params']
Expand All @@ -29,27 +30,39 @@
# Instantiate turbine, controller, and file processing classes
turbine = ROSCO_turbine.Turbine(turbine_params)
controller = ROSCO_controller.Controller(controller_params)
file_processing = ROSCO_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'])
turbine.load_from_fast(
path_params['FAST_InputFile'],
os.path.join(this_dir,path_params['FAST_directory']),
dev_branch=True,
rot_source='txt',txt_filename=os.path.join(this_dir,path_params['rotor_performance_filename'])
)

# Tune controller
controller.tune_controller(turbine)

# Write parameter input file
param_file = 'DISCON.IN'
file_processing.write_DISCON(turbine,controller,param_file=param_file, txt_filename=path_params['rotor_performance_filename'])
write_DISCON(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')
fig, ax = plt.subplots(1,2,constrained_layout=True)
ax[0].plot(controller.v[len(controller.v_below_rated)+1:], controller.pc_gain_schedule.Kp)
ax[0].set_xlabel('Wind Speed')
ax[0].set_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')
ax[1].plot(controller.v[len(controller.v_below_rated)+1:], controller.pc_gain_schedule.Ki)
ax[1].set_xlabel('Wind Speed')
ax[1].set_ylabel('Integral Gain')

plt.show()
plt.suptitle('Pitch Controller Gains')

example_out_dir = os.path.join(this_dir,'examples_out')
if not os.path.isdir(example_out_dir):
os.makedirs(example_out_dir)

if False:
plt.show()
else:
plt.savefig(os.path.join(example_out_dir,'04_GainSched.png'))
31 changes: 22 additions & 9 deletions Examples/example_05.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,37 @@
Notes - You will need to have a compiled controller in ROSCO, and
properly point to it in the `lib_name` variable.
- The complex nature of the wind speed estimators implemented in ROSCO
make using them for simulations is known to cause problems for
the simple simulator. We suggesting using WE_Mode = 0 in DISCON.IN.
- Using wind speed estimators in this simple simulation is
known to cause problems. We suggesting using WE_Mode = 0 in DISCON.IN.
'''
# Python modules
import matplotlib.pyplot as plt
import numpy as np
import yaml
import yaml, os, platform
# ROSCO toolbox modules
from ROSCO_toolbox import controller as ROSCO_controller
from ROSCO_toolbox import turbine as ROSCO_turbine
from ROSCO_toolbox import sim as ROSCO_sim
from ROSCO_toolbox import utilities as ROSCO_utilities
from ROSCO_toolbox import control_interface as ROSCO_ci

# Specify controller dynamic library path and name
lib_name = '../ROSCO/build/libdiscon.dylib'
param_filename = 'DISCON.IN'
this_dir = os.path.dirname(os.path.abspath(__file__))
example_out_dir = os.path.join(this_dir,'examples_out')
if not os.path.isdir(example_out_dir):
os.makedirs(example_out_dir)

if platform.system() == 'Windows':
lib_name = os.path.join(this_dir, '../ROSCO/build/libdiscon.dll')
elif platform.system() == 'Darwin':
lib_name = os.path.join(this_dir, '../ROSCO/build/libdiscon.dylib')
else:
lib_name = os.path.join(this_dir, '../ROSCO/build/libdiscon.so')

param_filename = os.path.join(this_dir,'DISCON.IN')

# Load turbine model from saved pickle
turbine = ROSCO_turbine.Turbine
turbine = turbine.load('NREL5MW_saved.p')
turbine = turbine.load(os.path.join(example_out_dir,'01_NREL5MW_saved.p'))

# Load controller library
controller_int = ROSCO_ci.ControllerInterface(lib_name,param_filename=param_filename)
Expand All @@ -51,5 +60,9 @@

# Run simulator and plot results
sim.sim_ws_series(t,ws,rotor_rpm_init=4)
plt.show()

if False:
plt.show()
else:
plt.savefig(os.path.join(example_out_dir,'05_NREL5MW_SimpSim.png'))

21 changes: 13 additions & 8 deletions Examples/example_06.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
'''
# Python Modules
import yaml
import os
# ROSCO toolbox modules
from ROSCO_toolbox import controller as ROSCO_controller
from ROSCO_toolbox import turbine as ROSCO_turbine
from ROSCO_toolbox.utilities import write_DISCON, run_openfast
from ROSCO_toolbox import sim as ROSCO_sim
from ROSCO_toolbox import utilities as ROSCO_utilities

this_dir = os.path.dirname(os.path.abspath(__file__))

# Load yaml file
parameter_filename = 'NREL5MW_example.yaml'
parameter_filename = os.path.join(os.path.dirname(this_dir), 'Tune_Cases', 'IEA15MW.yaml')
inps = yaml.safe_load(open(parameter_filename))
path_params = inps['path_params']
turbine_params = inps['turbine_params']
Expand All @@ -28,22 +31,24 @@
# Instantiate turbine, controller, and file processing classes
turbine = ROSCO_turbine.Turbine(turbine_params)
controller = ROSCO_controller.Controller(controller_params)
file_processing = ROSCO_utilities.FileProcessing()
fast_io = ROSCO_utilities.FAST_IO()

# 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'])
turbine.load_from_fast(path_params['FAST_InputFile'], \
os.path.join(this_dir,path_params['FAST_directory']), \
dev_branch=True,rot_source='txt',\
txt_filename=os.path.join(this_dir,path_params['FAST_directory'],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_DISCON(turbine,controller,param_file=param_file, txt_filename=path_params['rotor_performance_filename'])
param_file = os.path.join(this_dir,'DISCON.IN') # This must be named DISCON.IN to be seen by the compiled controller binary.
write_DISCON(turbine,controller,param_file=param_file, txt_filename=path_params['rotor_performance_filename'])

# Run OpenFAST
# --- May need to change fastcall if you use a non-standard command to call openfast
fast_io.run_openfast(path_params['FAST_directory'], fastcall='openfast_dev', fastfile=path_params['FAST_InputFile'],chdir=True)
fastcall = 'openfast'
run_openfast(path_params['FAST_directory'], fastcall=fastcall, fastfile=path_params['FAST_InputFile'], chdir=True)



Expand Down
Loading

0 comments on commit 8ac261d

Please sign in to comment.