Skip to content

Commit

Permalink
Added autodocumentation template for all examples
Browse files Browse the repository at this point in the history
  • Loading branch information
abhineet-gupta committed Aug 10, 2024
1 parent 541fe81 commit df133ee
Show file tree
Hide file tree
Showing 28 changed files with 1,022 additions and 1,014 deletions.
85 changes: 46 additions & 39 deletions Examples/02_ccblade.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,53 @@
'''
----------- 02_ccblade --------------
Run CCblade, save a rotor performance text file
-------------------------------------
"""
02_ccblade
--------------
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
'''
* 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 os
# ROSCO toolbox modules
from rosco.toolbox import turbine as ROSCO_turbine
from rosco.toolbox.utilities import write_rotor_performance
from rosco.toolbox.inputs.validation import load_rosco_yaml
# 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
this_dir = os.path.dirname(os.path.abspath(__file__))
tune_dir = os.path.join(this_dir,'Tune_Cases')
parameter_filename = os.path.join(tune_dir,'NREL5MW.yaml')
inps = load_rosco_yaml(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'],
os.path.join(tune_dir,path_params['FAST_directory']),
rot_source='cc-blade',
txt_filename=None)

# Write rotor performance text file
txt_filename = os.path.join(example_out_dir,'02_Cp_Ct_Cq.Ex03.txt')
write_rotor_performance(turbine,txt_filename=txt_filename)

def main():
# 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
this_dir = os.path.dirname(os.path.abspath(__file__))
tune_dir = os.path.join(this_dir,'Tune_Cases')
parameter_filename = os.path.join(tune_dir,'NREL5MW.yaml')
inps = load_rosco_yaml(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'],
os.path.join(tune_dir,path_params['FAST_directory']),
rot_source='cc-blade',
txt_filename=None)

# Write rotor performance text file
txt_filename = os.path.join(example_out_dir,'02_Cp_Ct_Cq.Ex03.txt')
write_rotor_performance(turbine,txt_filename=txt_filename)

if __name__ == "__main__":
main()

118 changes: 61 additions & 57 deletions Examples/03_tune_controller.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
'''
----------- 03_tune_controller --------------
"""
03_tune_controller
------------------
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
'''
* 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 os
Expand All @@ -19,62 +20,65 @@
from rosco.toolbox.utilities import write_DISCON
from rosco.toolbox.inputs.validation import load_rosco_yaml

def main():
# Load yaml file
this_dir = os.path.dirname(os.path.abspath(__file__))
tune_dir = os.path.join(this_dir,'Tune_Cases')
parameter_filename = os.path.join(tune_dir,'NREL5MW.yaml')
inps = load_rosco_yaml(parameter_filename)
path_params = inps['path_params']
turbine_params = inps['turbine_params']
controller_params = inps['controller_params']

# Load yaml file
this_dir = os.path.dirname(os.path.abspath(__file__))
tune_dir = os.path.join(this_dir,'Tune_Cases')
parameter_filename = os.path.join(tune_dir,'NREL5MW.yaml')
inps = load_rosco_yaml(parameter_filename)
path_params = inps['path_params']
turbine_params = inps['turbine_params']
controller_params = inps['controller_params']
# Instantiate turbine, controller, and file processing classes
turbine = ROSCO_turbine.Turbine(turbine_params)
controller = ROSCO_controller.Controller(controller_params)

# Instantiate turbine, controller, and file processing classes
turbine = ROSCO_turbine.Turbine(turbine_params)
controller = ROSCO_controller.Controller(controller_params)
# Load turbine data from OpenFAST and rotor performance text file
cp_filename = os.path.join(tune_dir,path_params['rotor_performance_filename'])
turbine.load_from_fast(
path_params['FAST_InputFile'],
os.path.join(tune_dir,path_params['FAST_directory']),
rot_source='txt',txt_filename= cp_filename
)

# Load turbine data from OpenFAST and rotor performance text file
cp_filename = os.path.join(tune_dir,path_params['rotor_performance_filename'])
turbine.load_from_fast(
path_params['FAST_InputFile'],
os.path.join(tune_dir,path_params['FAST_directory']),
rot_source='txt',txt_filename= cp_filename
)
# Tune controller
controller.tune_controller(turbine)

# Tune controller
controller.tune_controller(turbine)
# Write parameter input file
param_file = os.path.join(this_dir,'DISCON.IN')
write_DISCON(turbine,controller,
param_file=param_file,
txt_filename=cp_filename
)

# Write parameter input file
param_file = os.path.join(this_dir,'DISCON.IN')
write_DISCON(turbine,controller,
param_file=param_file,
txt_filename=cp_filename
)
# Plot gain schedule
fig, ax = plt.subplots(2,2,constrained_layout=True,sharex=True)
ax = ax.flatten()
ax[0].plot(controller.v[len(controller.v_below_rated)+1:], controller.omega_pc_U)
ax[0].set_ylabel('omega_pc')

# Plot gain schedule
fig, ax = plt.subplots(2,2,constrained_layout=True,sharex=True)
ax = ax.flatten()
ax[0].plot(controller.v[len(controller.v_below_rated)+1:], controller.omega_pc_U)
ax[0].set_ylabel('omega_pc')
ax[1].plot(controller.v[len(controller.v_below_rated)+1:], controller.zeta_pc_U)
ax[1].set_ylabel('zeta_pc')

ax[1].plot(controller.v[len(controller.v_below_rated)+1:], controller.zeta_pc_U)
ax[1].set_ylabel('zeta_pc')
ax[2].plot(controller.v[len(controller.v_below_rated)+1:], controller.pc_gain_schedule.Kp)
ax[2].set_xlabel('Wind Speed')
ax[2].set_ylabel('Proportional Gain')

ax[2].plot(controller.v[len(controller.v_below_rated)+1:], controller.pc_gain_schedule.Kp)
ax[2].set_xlabel('Wind Speed')
ax[2].set_ylabel('Proportional Gain')
ax[3].plot(controller.v[len(controller.v_below_rated)+1:], controller.pc_gain_schedule.Ki)
ax[3].set_xlabel('Wind Speed')
ax[3].set_ylabel('Integral Gain')

ax[3].plot(controller.v[len(controller.v_below_rated)+1:], controller.pc_gain_schedule.Ki)
ax[3].set_xlabel('Wind Speed')
ax[3].set_ylabel('Integral Gain')
plt.suptitle('Pitch Controller Gains')

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)

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,'03_GainSched.png'))

if False:
plt.show()
else:
plt.savefig(os.path.join(example_out_dir,'03_GainSched.png'))
if __name__ == "__main__":
main()
Loading

0 comments on commit df133ee

Please sign in to comment.