Skip to content

Commit

Permalink
Merge commit '381ae2862ee58d9684ef5c69270eef4956ce1813' into weis
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhar-abbas committed Apr 12, 2021
2 parents d748c9f + 381ae28 commit c87da84
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 34 deletions.
19 changes: 19 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Description and Purpose

## Type of change
What types of change is it?
_Select the appropriate type(s) that describe this PR_

- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (non-backwards-compatible fix or feature)
- [ ] Code style update (formatting, renaming)
- [ ] Refactoring (no functional changes, no API changes)
- [ ] Documentation update
- [ ] Maintenance update
- [ ] Other (please describe)

## Github issues addressed, if one exists

## Examples/Testing, if applicable

106 changes: 106 additions & 0 deletions .github/workflows/CI_rosco-toolbox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: CI_rosco-toolbox

# We run CI on push commits on all branches
on: [push, pull_request]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
name: Build (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: ["ubuntu-latest", "macOS-latest", "windows-latest"]
python-version: ["3.8"]
defaults:
run:
shell: bash -l {0}

steps:
- name: Checkout repository and submodules
uses: actions/checkout@v2
with:
submodules: recursive

- name: Setup environment
uses: conda-incubator/setup-miniconda@v2
with:
miniconda-version: "latest"
channels: conda-forge, general
auto-update-conda: true
python-version: 3.8
environment-file: environment.yml


# Install dependencies of ROSCO toolbox
- name: Add dependencies ubuntu specific
if: false == contains( matrix.os, 'windows')
run: |
conda install -y compilers
conda install -y wisdem
- name: Add dependencies windows specific
if: true == contains( matrix.os, 'windows')
run: |
conda install -y m2w64-toolchain libpython
conda install -y wisdem
# Install ROSCO toolbox
- name: Install ROSCO toolbox
run: |
python setup.py develop --compile-rosco
run_examples:
name: Run Examples
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: ["ubuntu-latest"] #, "macOS-latest"]
python-version: ["3.8"]
defaults:
run:
shell: bash -l {0}

steps:
- name: Checkout repository and submodules
uses: actions/checkout@v2
with:
submodules: recursive

- name: Setup environment
uses: conda-incubator/setup-miniconda@v2
with:
miniconda-version: "latest"
channels: conda-forge, general
auto-update-conda: true
python-version: 3.8
environment-file: environment.yml


# Install dependencies of ROSCO toolbox
- name: Add dependencies ubuntu specific
if: false == contains( matrix.os, 'windows')
run: |
conda install -y compilers
conda install -y wisdem
# Install ROSCO toolbox
- name: Install ROSCO toolbox
run: |
python setup.py develop --compile-rosco
# Install OpenFAST
- name: Install OpenFAST
run: |
conda install openfast
# Run examples
- name: Run examples
run: |
cd Examples
python run_examples.py
11 changes: 6 additions & 5 deletions Examples/example_07.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@
controller.tune_controller(turbine)

# 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)')
fig, ax = plt.subplots(1,1)
ax.plot(controller.v, controller.pitch_op,label='Steady State Operation')
ax.plot(controller.v, controller.ps_min_bld_pitch, label='Minimum Pitch Schedule')
ax.legend()
ax.set_xlabel('Wind speed (m/s)')
ax.set_ylabel('Blade pitch (rad)')

if False:
plt.show()
Expand Down
9 changes: 3 additions & 6 deletions Examples/example_09.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
wind_directory = os.path.join(this_dir,'../Test_Cases/Wind/')
turbsim_infile = '90m_12mps_twr.inp'

run_openfast(
wind_directory,
fastcall='/Users/dzalkind/Tools/WEIS-1/build/temp.macosx-10.9-x86_64-3.8_rosco_openfast/modules/turbsim/turbsim',
fastfile=turbsim_infile,
chdir=False
)
run_openfast(wind_directory, fastcall='turbsim',
fastfile=os.path.join(wind_directory, turbsim_infile), chdir=False)

print('test')
4 changes: 3 additions & 1 deletion Examples/run_examples.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import unittest
import sys
from time import time
import importlib

Expand Down Expand Up @@ -100,4 +101,5 @@ def suite():


if __name__ == "__main__":
unittest.TextTestRunner().run(suite())
result = unittest.TextTestRunner().run(suite())
sys.exit(not result.wasSuccessful())
9 changes: 5 additions & 4 deletions ROSCO_toolbox/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ def tune_controller(self, turbine):
TSR_rated = rated_rotor_speed*R/turbine.v_rated # TSR at rated

# separate wind speeds by operation regions
v_below_rated = np.linspace(turbine.v_min,turbine.v_rated, num=30) # below rated
v_above_rated = np.linspace(turbine.v_rated,turbine.v_max, num=30)[1:] # above rated
v_below_rated = np.linspace(turbine.v_min,turbine.v_rated, num=30)[:-1] # below rated
v_above_rated = np.linspace(turbine.v_rated,turbine.v_max, num=30) # above rated
v = np.concatenate((v_below_rated, v_above_rated))

# separate TSRs by operations regions
Expand Down Expand Up @@ -189,7 +189,8 @@ def tune_controller(self, turbine):
# Find pitch angle as a function of expected operating CP for each TSR
Cp_TSR = np.ndarray.flatten(turbine.Cp.interp_surface(turbine.pitch_initial_rad, TSR_op[i])) # all Cp values for a given tsr
Cp_op[i] = np.clip(Cp_op[i], np.min(Cp_TSR), np.max(Cp_TSR)) # saturate Cp values to be on Cp surface
f_cp_pitch = interpolate.interp1d(Cp_TSR,pitch_initial_rad) # interpolate function for Cp(tsr) values
Cp_maxidx = Cp_TSR.argmax() # Find maximum Cp value for this TSR
f_cp_pitch = interpolate.interp1d(Cp_TSR[Cp_maxidx:],pitch_initial_rad[Cp_maxidx:]) # interpolate function for Cp(tsr) values
# expected operation blade pitch values
if v[i] <= turbine.v_rated and isinstance(self.min_pitch, float): # Below rated & defined min_pitch
pitch_op[i] = min(self.min_pitch, f_cp_pitch(Cp_op[i]))
Expand Down Expand Up @@ -479,7 +480,7 @@ def peak_shaving(self,controller, turbine):
else:
Ct_max[i] = np.minimum( np.max(Ct_tsr), Ct_max[i])
# Define minimum pitch angle
f_pitch_min = interpolate.interp1d(Ct_tsr, turbine.pitch_initial_rad, kind='cubic', bounds_error=False, fill_value=(turbine.pitch_initial_rad[0],turbine.pitch_initial_rad[-1]))
f_pitch_min = interpolate.interp1d(Ct_tsr, turbine.pitch_initial_rad, kind='linear', bounds_error=False, fill_value=(turbine.pitch_initial_rad[0],turbine.pitch_initial_rad[-1]))
pitch_min[i] = max(controller.min_pitch, f_pitch_min(Ct_max[i]))

controller.ps_min_bld_pitch = pitch_min
Expand Down
23 changes: 8 additions & 15 deletions ROSCO_toolbox/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
from matplotlib import transforms
from itertools import takewhile, product
import struct
import subprocess
import ROSCO_toolbox

from ROSCO_toolbox.ofTools.util import spectral
# Some useful constants
now = datetime.datetime.now()
pi = np.pi
Expand Down Expand Up @@ -455,7 +455,7 @@ def DISCON_dict(turbine, controller, txt_filename=None):
return DISCON_dict


def run_openfast(fast_dir,fastcall='openfast',fastfile=None,chdir=False):
def run_openfast(fast_dir, fastcall='openfast', fastfile=None, chdir=True):
'''
Runs a openfast openfast simulation.
Expand Down Expand Up @@ -483,18 +483,11 @@ def run_openfast(fast_dir,fastcall='openfast',fastfile=None,chdir=False):
print('Using {} to run OpenFAST simulation'.format(fastfile))

if chdir: # Change cwd before calling OpenFAST -- note: This is an artifact of needing to call OpenFAST from the same directory as DISCON.IN
# save starting file path
original_path = os.getcwd()
# change path, run OpenFAST
os.chdir(fast_dir)
print('Running OpenFAST simulation for {} through the ROSCO toolbox...'.format(fastfile))
os.system('{} {}'.format(fastcall, os.path.join(fastfile)))
print('OpenFAST simulation complete. ')
# return to original path
os.chdir(original_path)
cwd = fast_dir
else:
# Run OpenFAST
print('Running OpenFAST simulation for {} through the ROSCO toolbox...'.format(fastfile))
os.system('{} {}'.format(fastcall, os.path.join(fast_dir,fastfile)))
print('OpenFAST simulation complete. ')
cwd = None

print('Running OpenFAST simulation for {} through the ROSCO toolbox...'.format(fastfile))
# os.system('{} {}'.format(fastcall, os.path.join(fastfile)))
subprocess.run([fastcall, os.path.join(fastfile)], check=True, cwd=cwd)
print('OpenFAST simulation complete.')
2 changes: 1 addition & 1 deletion Test_Cases/BAR_10/BAR_10_ServoDyn.dat
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ False CompNTMD - Compute nacelle tuned mass damper {true/fal
False CompTTMD - Compute tower tuned mass damper {true/false} (flag)
"b.dat" TTMDfile - Name of the file for tower tuned mass damper (quoted string) [unused when CompTTMD is false]
---------------------- BLADED INTERFACE ---------------------------------------- [used only with Bladed Interface]
"../../ROSCO/install/lib/libdiscon.dylib" DLL_FileName - Name/location of the dynamic library {.dll [Windows] or .so [Linux]} in the Bladed-DLL format (-) [used only with Bladed Interface]
"../../ROSCO/install/lib/libdiscon.so" DLL_FileName - Name/location of the dynamic library {.dll [Windows] or .so [Linux]} in the Bladed-DLL format (-) [used only with Bladed Interface]
"BAR_10_DISCON.IN" DLL_InFile - Name of input file sent to the DLL (-) [used only with Bladed Interface]
"DISCON" DLL_ProcName - Name of procedure in DLL to be called (-) [case sensitive; used only with DLL Interface]
"default" DLL_DT - Communication interval for dynamic library (s) (or "default") [used only with Bladed Interface]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ False CompNTMD - Compute nacelle tuned mass damper {true/fal
False CompTTMD - Compute tower tuned mass damper {true/false} (flag)
"unused" TTMDfile - Name of the file for tower tuned mass damper (quoted string) [unused when CompTTMD is false]
---------------------- BLADED INTERFACE ---------------------------------------- [used only with Bladed Interface]
"../../ROSCO/install/lib/libdiscon.dylib" DLL_FileName - Name/location of the dynamic library {.dll [Windows] or .so [Linux]} in the Bladed-DLL format (-) [used only with Bladed Interface]
"../../ROSCO/install/lib/libdiscon.so" DLL_FileName - Name/location of the dynamic library {.dll [Windows] or .so [Linux]} in the Bladed-DLL format (-) [used only with Bladed Interface]
"ServoData/DISCON-UMaineSemi.IN" DLL_InFile - Name of input file sent to the DLL (-) [used only with Bladed Interface]
"DISCON" DLL_ProcName - Name of procedure in DLL to be called (-) [case sensitive; used only with DLL Interface]
"default" DLL_DT - Communication interval for dynamic library (s) (or "default") [used only with Bladed Interface]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ False CompNTMD - Compute nacelle tuned mass damper {true/false} (fla
False CompTTMD - Compute tower tuned mass damper {true/false} (flag)
"../5MW_Baseline/NRELOffshrBsline5MW_ServoDyn_TMD.dat" TTMDfile - Name of the file for tower tuned mass damper (quoted string) [unused when CompTTMD is false]
---------------------- BLADED INTERFACE ---------------------------------------- [used only with Bladed Interface]
"../../ROSCO/install/lib/libdiscon.dylib" DLL_FileName - Name/location of the dynamic library {.dll [Windows] or .so [Linux]} in the Bladed-DLL format (-) [used only with Bladed Interface]
"../../ROSCO/install/lib/libdiscon.so" DLL_FileName - Name/location of the dynamic library {.dll [Windows] or .so [Linux]} in the Bladed-DLL format (-) [used only with Bladed Interface]
"DISCON.IN" DLL_InFile - Name of input file sent to the DLL (-) [used only with Bladed Interface]
"DISCON" DLL_ProcName - Name of procedure in DLL to be called (-) [case sensitive; used only with DLL Interface]
"default" DLL_DT - Communication interval for dynamic library (s) (or "default") [used only with Bladed Interface]
Expand Down
11 changes: 11 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
channels:
- conda-forge
- defaults

dependencies:
- matplotlib
- numpy
- pytest
- scipy
- pyYAML
- pandas

0 comments on commit c87da84

Please sign in to comment.