Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into f/docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhar-abbas committed Feb 26, 2021
2 parents d1ba1f1 + 0e17b73 commit 97b36e5
Show file tree
Hide file tree
Showing 40 changed files with 610 additions and 375 deletions.
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/
93 changes: 0 additions & 93 deletions Examples/Cp_Ct_Cq.Ex03.txt

This file was deleted.

102 changes: 51 additions & 51 deletions Examples/DISCON.IN

Large diffs are not rendered by default.

Binary file removed Examples/NREL5MW_saved.p
Binary file not shown.
13 changes: 9 additions & 4 deletions Examples/example_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from ROSCO_toolbox import turbine as ROSCO_turbine

# Load yaml file
parameter_filename = os.path.join(os.path.dirname(__file__),'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 @@ -28,13 +29,17 @@

turbine.load_from_fast(
path_params['FAST_InputFile'],
os.path.join(os.path.dirname(__file__),path_params['FAST_directory']),
os.path.join(this_dir,path_params['FAST_directory']),
dev_branch=True,
rot_source='txt',txt_filename=os.path.join(os.path.dirname(__file__),path_params['rotor_performance_filename'])
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(os.path.join(os.path.dirname(__file__),'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'))
14 changes: 12 additions & 2 deletions Examples/example_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@
# 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(os.path.join(os.path.dirname(__file__),'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()
plt.show()



if False:
plt.show()
else:
plt.savefig(os.path.join(example_out_dir,'02_NREL5MW_Cp.png'))
11 changes: 8 additions & 3 deletions Examples/example_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
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 = os.path.join(os.path.dirname(__file__),'NREL5MW_example.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']
Expand All @@ -29,11 +34,11 @@
turbine = ROSCO_turbine.Turbine(turbine_params)
turbine.load_from_fast(
path_params['FAST_InputFile'],
os.path.join(os.path.dirname(__file__),path_params['FAST_directory']),
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 = os.path.join(os.path.dirname(__file__),'Cp_Ct_Cq.Ex03.txt')
txt_filename = os.path.join(example_out_dir,'03_Cp_Ct_Cq.Ex03.txt')
write_rotor_performance(turbine,txt_filename=txt_filename)
21 changes: 15 additions & 6 deletions Examples/example_04.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
from ROSCO_toolbox.utilities import write_DISCON

# Load yaml file
parameter_filename = os.path.join(os.path.dirname(__file__),'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 @@ -33,9 +34,9 @@
# Load turbine data from OpenFAST and rotor performance text file
turbine.load_from_fast(
path_params['FAST_InputFile'],
os.path.join(os.path.dirname(__file__),path_params['FAST_directory']),
os.path.join(this_dir,path_params['FAST_directory']),
dev_branch=True,
rot_source='txt',txt_filename=os.path.join(os.path.dirname(__file__),path_params['rotor_performance_filename'])
rot_source='txt',txt_filename=os.path.join(this_dir,path_params['rotor_performance_filename'])
)

# Tune controller
Expand All @@ -47,13 +48,21 @@

# Plot gain schedule
fig, ax = plt.subplots(1,2,constrained_layout=True)
ax[0].plot(controller.v[len(controller.vs_gain_schedule.Kp):], controller.pc_gain_schedule.Kp)
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')

ax[1].plot(controller.v[len(controller.vs_gain_schedule.Ki):], controller.pc_gain_schedule.Ki)
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.suptitle('Pitch Controller Gains')
plt.show()

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'))
29 changes: 21 additions & 8 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, os
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 control_interface as ROSCO_ci

# Specify controller dynamic library path and name
this_dir = os.path.dirname(__file__)
lib_name = os.path.join(this_dir,'../ROSCO/build/libdiscon.dylib')
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(os.path.join(this_dir,'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'))

12 changes: 8 additions & 4 deletions Examples/example_06.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
from ROSCO_toolbox.utilities import write_DISCON, run_openfast
from ROSCO_toolbox import sim as ROSCO_sim

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

# Load yaml file
parameter_filename = os.path.join(this_dir,'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 @@ -33,7 +33,10 @@
controller = ROSCO_controller.Controller(controller_params)

# 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)
Expand All @@ -44,7 +47,8 @@

# Run OpenFAST
# --- May need to change fastcall if you use a non-standard command to call openfast
run_openfast(path_params['FAST_directory'], fastcall='openfast_sdev', 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
9 changes: 8 additions & 1 deletion Examples/example_07.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
from ROSCO_toolbox import sim as ROSCO_sim

this_dir = os.path.dirname(__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 = os.path.join(this_dir,'NREL5MW_example.yaml')
Expand Down Expand Up @@ -47,4 +50,8 @@
plt.legend()
plt.xlabel('Wind speed (m/s)')
plt.ylabel('Blade pitch (rad)')
plt.show()

if False:
plt.show()
else:
plt.savefig(os.path.join(example_out_dir,'07_MinPitch.png'))
17 changes: 13 additions & 4 deletions Examples/example_08.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
from ROSCO_toolbox.ofTools.fast_io import output_processing
import os

this_dir = os.path.dirname(__file__)
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)

# Define openfast output filenames
filenames = ["../Test_Cases/NREL-5MW/NREL-5MW.outb"]
filenames = ["../Test_Cases/IEA-15-240-RWT-UMaineSemi/IEA-15-240-RWT-UMaineSemi.outb"]
# ---- Note: Could load and plot multiple cases, textfiles, and binaries...
# filenames = ["../Test_Cases/NREL-5MW/NREL-5MW.outb",
# "../Test_Cases/NREL-5MW/NREL-5MW_ex8.outb"]
Expand All @@ -33,7 +36,9 @@
# --- Comment,uncomment, create, and change these as desired...
cases = {}
cases['Baseline'] = ['Wind1VelX', 'BldPitch1', 'GenTq', 'RotSpeed']
cases['Rotor'] = ['BldPitch1', 'GenTq', 'GenPwr']
# cases['Rotor'] = ['BldPitch1', 'GenTq', 'GenPwr']
# cases['Platform Motion'] = ['PtfmSurge', 'PtfmSway', 'PtfmHeave', 'PtfmPitch','PtfmRoll','PtfmYaw']


# Instantiate fast_IO
fast_out = output_processing.output_processing()
Expand All @@ -43,4 +48,8 @@

# Load and plot
fastout = fast_out.load_fast_out(filenames, tmin=10)
fast_out.plot_fast_out(cases=cases)
fast_out.plot_fast_out(cases=cases,showplot=False)

plt.savefig(os.path.join(example_out_dir,'08_IEA-15MW_Semi_Out.png'))


4 changes: 2 additions & 2 deletions Examples/example_09.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
from ROSCO_toolbox.utilities import run_openfast
import os

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

# Define openfast output filenames
wind_directory = os.path.join(this_dir,'../Test_Cases/Wind/')
turbsim_infile = '90m_12mps_twr.inp'

run_openfast(wind_directory, fastcall='turbsim_sdev', fastfile=turbsim_infile, chdir=False)
run_openfast(wind_directory, fastcall='turbsim', fastfile=turbsim_infile, chdir=False)

6 changes: 3 additions & 3 deletions Examples/example_10.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
from ROSCO_toolbox import turbine as ROSCO_turbine
from ROSCO_toolbox import controller as ROSCO_controller

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

# Load yaml file
parameter_filename = os.path.join(rt_dir,'Tune_Cases/BAR.yaml')
parameter_filename = os.path.join(os.path.dirname(this_dir),'Tune_Cases/BAR.yaml')
inps = yaml.safe_load(open(parameter_filename))
path_params = inps['path_params']
turbine_params = inps['turbine_params']
Expand All @@ -34,7 +34,7 @@
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(rt_dir,path_params['FAST_directory']),dev_branch=True)
os.path.join(this_dir,path_params['FAST_directory']),dev_branch=True)

# Tune controller
controller = ROSCO_controller.Controller(controller_params)
Expand Down
7 changes: 6 additions & 1 deletion Examples/example_11.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
controller_params = inps['controller_params']

# Linear file output
linmod_filename = 'IEA15MW_LinMod.dat'
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)

linmod_filename = os.path.join(example_out_dir,'11_IEA15MW_LinMod.dat')

# Instantiate turbine, controller, and file processing classes
turbine = ROSCO_turbine.Turbine(turbine_params)
Expand Down
Loading

0 comments on commit 97b36e5

Please sign in to comment.