Skip to content

Commit

Permalink
Squashed 'ROSCO/' changes from a70d374e..75bc214f
Browse files Browse the repository at this point in the history
75bc214f Add MHK example
b5d91323 Update FAST reader/writer
e2dba122 Select density based on main Fst file
426e567d Select airfoil by reynolds_ref in turbine params
37279a53 Merge remote-tracking branch 'upstream/develop' into develop
e3b7db77 ROSCO v2.8.0 (WISDEM#237)
79426f79 Increment version number
339ad539 Tidy example output
585e2c8b Open loop platform control (WISDEM#236)
de15e52d Various bug fixes (WISDEM#233)
5a7046f7 Active Wake Control (WISDEM#230)
1ccc1b36 Platform control and Optional Inputs (WISDEM#227)
41f2c001 Set minimum Python version to 3.8
a7d33035 Merge remote-tracking branch 'upstream/main' into develop
42525a98 V270 prep (WISDEM#218)
a1cf97bb Rename examples (WISDEM#215)
3155b63d Add script for updating DISCON versions (WISDEM#214)
e554c1da IPC Saturation Fix [RAAW] (WISDEM#210)
be28641f Allow PA_Mode 1 (WISDEM#213)
05d7b3b9 Compatibility with Numpy v1.24 (WISDEM#208)
9d27a333 OpenFAST v3.3.0 (WISDEM#202)
5ad1d410 Doc fix (WISDEM#200)
827b2814 Update sim.py (WISDEM#196)
602332ea Various Bug Fixes (WISDEM#188)
9384f030 Added feature to read AeroDyn 14 files also for the case without tower influence. (WISDEM#177)
decd6947 Various Bug Fixes (WISDEM#167)
2efac848 Adding pitch actuator fault (WISDEM#163)

git-subtree-dir: ROSCO
git-subtree-split: 75bc214f29bae2761f28ce4327b52c5a59580a13
  • Loading branch information
dzalkind committed Apr 18, 2023
1 parent 44d5844 commit 76b84e2
Show file tree
Hide file tree
Showing 137 changed files with 19,411 additions and 2,141 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Examples/*.p

# Exclude testing results
ROSCO_testing/results/
ROSCO_testing/testing

# Simulink/Matlab temp files
*.slxc
Expand Down
2 changes: 1 addition & 1 deletion Examples/01_turbine_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
----------- Example_01 --------------
----------- 01_turbine_model --------------
Load and save a turbine model
-------------------------------------
In this example:
Expand Down
2 changes: 1 addition & 1 deletion Examples/02_ccblade.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
----------- Example_03 --------------
----------- 02_ccblade --------------
Run CCblade, save a rotor performance text file
-------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Examples/03_tune_controller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
----------- Example_04 --------------
----------- 03_tune_controller --------------
Load a turbine model and tune the controller
-------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Examples/04_simple_sim.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
----------- Example_05 --------------
----------- 04_simple_sim --------------
Run and plot a simple simple step wind simulation
-------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Examples/05_openfast_sim.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
----------- Example_06 --------------
----------- 05_openfast_sim --------------
Load a turbine, tune a controller, run OpenFAST simulation
-------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Examples/06_peak_shaving.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
----------- Example_07 --------------
----------- 06_peak_shavings --------------
Load saved turbine, tune controller, plot minimum pitch schedule
-------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Examples/07_openfast_outputs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
----------- Example_08 --------------
----------- 07_openfast_outputss --------------
Plot some OpenFAST output data
-------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Examples/08_run_turbsim.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
----------- Example_09 --------------
----------- 08_run_turbsim --------------
Run TurbSim to create wind field binary
-------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Examples/09_distributed_aero.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
----------- Example_10 --------------
----------- 09_distributed_aero --------------
Tune a controller for distributed aerodynamic control
-------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Examples/10_linear_params.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
----------- Example_11 --------------
----------- 10_linear_params --------------
Load a turbine, tune a controller, export linear model
-------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Examples/11_robust_tuning.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
----------- Example_12 --------------
----------- 11_robust_tuning --------------
Controller tuning to satisfy a robustness criteria
-------------------------------------
NOTE: This example necessitates the mbc3 through either pyFAST or WEIS
Expand Down
153 changes: 53 additions & 100 deletions Examples/12_tune_ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,105 +14,58 @@
import matplotlib.pyplot as plt

# ROSCO toolbox modules
from ROSCO_toolbox import controller as ROSCO_controller
from ROSCO_toolbox import turbine as ROSCO_turbine
from ROSCO_toolbox.utilities import DISCON_dict
from ROSCO_toolbox.ofTools.fast_io import output_processing
from ROSCO_toolbox.inputs.validation import load_rosco_yaml
from ROSCO_toolbox.ofTools.case_gen.CaseLibrary import set_channels
from ROSCO_toolbox.ofTools.case_gen.runFAST_pywrapper import runFAST_pywrapper_batch
from ROSCO_toolbox.ofTools.case_gen.CaseGen_General import CaseGen_General



this_dir = os.path.dirname(os.path.abspath(__file__))
rosco_dir = os.path.dirname(this_dir)
example_out_dir = os.path.join(this_dir,'examples_out')
example_name = '12_ipc_sim'
run_dir = os.path.join(example_out_dir, example_name)

# Load yaml file (Open Loop Case)
parameter_filename = os.path.join(rosco_dir,'Tune_Cases/BAR.yaml')

inps = load_rosco_yaml(parameter_filename)
path_params = inps['path_params']
turbine_params = inps['turbine_params']
controller_params = inps['controller_params']

# Turn flaps off and IPC on
controller_params['Flp_Mode'] = 0
controller_params['IPC_ControlMode'] = 1

# Instantiate turbine, and controller
turbine = ROSCO_turbine.Turbine(turbine_params)
controller = ROSCO_controller.Controller(controller_params)

# Load turbine data from OpenFAST and rotor performance text file
turbine.load_from_fast(
path_params['FAST_InputFile'],
os.path.join(this_dir, path_params['FAST_directory'])
)
# Tune controller
controller.tune_controller(turbine)

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

case_inputs = {}
case_inputs[('ServoDyn','DLL_FileName')] = {'vals': [rosco_dll], 'group': 0}
case_inputs[('ServoDyn','Ptch_Cntrl')] = {'vals': [1], 'group': 0}

# Apply all discon variables as case inputs
discon_vt = DISCON_dict(
turbine,
controller,
txt_filename=os.path.join(this_dir,path_params['FAST_directory'],path_params['rotor_performance_filename'])
)

for discon_input in discon_vt:
case_inputs[('DISCON_in',discon_input)] = {'vals': [discon_vt[discon_input]], 'group': 0}

# Generate cases
if not os.path.exists(run_dir):
os.makedirs(run_dir)

case_list, case_name_list = CaseGen_General(case_inputs, dir_matrix=run_dir, namebase='ipc_example')
channels = set_channels()
channels['BldPitch2'] = True
channels['BldPitch3'] = True

# Run FAST cases
fastBatch = runFAST_pywrapper_batch()

fastBatch.FAST_directory = os.path.realpath(os.path.join(rosco_dir,'Tune_Cases',path_params['FAST_directory']))
fastBatch.FAST_InputFile = path_params['FAST_InputFile']
fastBatch.channels = channels
fastBatch.FAST_runDirectory = run_dir
fastBatch.case_list = case_list
fastBatch.case_name_list = case_name_list
fastBatch.debug_level = 2
fastBatch.FAST_exe = 'openfast'

fastBatch.run_serial()


# # Define Plot cases
cases = {}
cases['Baseline'] = ['Wind1VelX', ('BldPitch1', 'BldPitch2', 'BldPitch3'), 'RootMyc1', 'RotSpeed']

out_file = os.path.join(example_out_dir,example_name,'ipc_example_0.outb')
op = output_processing.output_processing()
fastout = op.load_fast_out(out_file, tmin=0)
fig, ax = op.plot_fast_out(cases=cases,showplot=False)
if False:
plt.show()
else:
fig[0].savefig(os.path.join(example_out_dir,'13_ipc_FAST_Out.png'))


from ROSCO_toolbox.ofTools.case_gen.run_FAST import run_FAST_ROSCO
from ROSCO_toolbox.ofTools.case_gen import CaseLibrary as cl

def main():
this_dir = os.path.dirname(os.path.abspath(__file__))
rosco_dir = os.path.dirname(this_dir)
example_out_dir = os.path.join(this_dir,'examples_out')
example_name = '12_ipc_sim'
run_dir = os.path.join(example_out_dir, example_name)

# Load yaml file (Open Loop Case)
parameter_filename = os.path.join(rosco_dir,'Tune_Cases/NREL2p8.yaml')

case_inputs = {}
case_inputs[('ServoDyn','Ptch_Cntrl')] = {'vals': [1], 'group': 0}
case_inputs[('DISCON_in','IPC_SatMode')] = {'vals': [0,1,2,3], 'group': 1}



# simulation set up
r = run_FAST_ROSCO()
r.tuning_yaml = parameter_filename
r.wind_case_fcn = cl.ramp # single step wind input
r.wind_case_opts = {
'U_start': 11, # from 10 to 15 m/s
'U_end': 9,
't_start': 100,
't_end': 400,
'both_dir': True,
'vert_shear': 0.2
}
r.case_inputs = case_inputs
r.save_dir = run_dir
r.rosco_dir = rosco_dir
r.n_cores = 4
r.run_FAST()


# # Define Plot cases
cases = {}
cases['Baseline'] = ['Wind1VelX', 'BldPitch1', 'RootMyc1', 'RotSpeed']

out_files = [os.path.join(example_out_dir,example_name,f'NREL2p8/ramp/base/NREL2p8_{i_case}.outb') for i_case in range(4)]
op = output_processing.output_processing()
fastout = op.load_fast_out(out_files, tmin=0)
fig, ax = op.plot_fast_out(cases=cases,showplot=False)
if False:
plt.show()
else:
fig[0].savefig(os.path.join(example_out_dir,'12_ipc_FAST_Out.png'))

if __name__=="__main__":
main()

Loading

0 comments on commit 76b84e2

Please sign in to comment.