Commit 8be6a272 authored by Jenni Rinker's avatar Jenni Rinker
Browse files

first upload of functions

parent 959f0728
"""Utilities for htc file maniopulation
"""
from wetb.hawc2 import HTCFile
# default values for DTU 10 MW
_DEF_KWARGS = dict(rate_pow=10_000, cut_in=4, cut_out=25, n_wsp=22, pitch_f=100,
pitch_z=0.7, gen_min=299.85, gen_max=479.56567, gbr=50, pitch_min=0,
opt_lambda=7.5, gen_eff=0.94, p1_f=0.05, p1_z=0.7, p2_f=0.06,
p2_z=0.7, gs=2, constant_power=1, tstart=100, dt=40)
def turb_to_hs2(orig_htc, new_htc, **kwargs):
"""Convert DTU 10 MW HAWC2 file to a HAWCStab2 file"""
kw = {**_DEF_KWARGS, **kwargs} # model params
htc = HTCFile(orig_htc)
# delete useless hawc2 blocks
del htc.simulation
del htc.dll
del htc.output
del htc.wind.tower_shadow_potential_2 # hawcstab2 can't handle this subblock
del htc.wind.mann # don't want hs2 to generate turbulence
del htc.aerodrag # can't handle this either
htc.wind.turb_format = 0
htc.wind.tower_shadow_method = 0
# add hawcstab2 block
hs2 = htc.add_section('hawcstab2')
# structure
hs2.add_line('; define structure', [])
sb = hs2.add_section('ground_fixed_substructure') # fixed to ground
sb.main_body = ['tower']
sb.add_line('main_body', ['towertop'])
sb.add_line('main_body', ['connector'])
sb = hs2.add_section('rotating_axissym_substructure') # rotating with rotor
sb.main_body = ['shaft']
sb = hs2.add_section('rotating_threebladed_substructure') # three-bladed sutbstruct.
sb.main_body = ['hub1']
sb.add_line('main_body', ['blade1'])
sb.second_order_actuator = ['pitch1', kw['pitch_f'], kw['pitch_z']]
hs2.operational_data_filename = ['./data/operation.dat']
# operational data
hs2.add_line('; inputs for finding optimal operational data', [])
sb = hs2.add_section('operational_data')
sb.add_line('windspeed', [kw['cut_in'], kw['cut_out'], kw['n_wsp']],
comments='cut-in [m/s], cut-out [m/s], points [-]')
sb.add_line('genspeed', [kw['gen_min'], kw['gen_max']], comments='[rpm]')
sb.add_line('gearratio', [kw['gbr']], comments='[-]')
sb.add_line('minpitch', [kw['pitch_min']], comments='[deg]')
sb.add_line('opt_lambda', [kw['opt_lambda']], comments='[-]')
sb.add_line('maxpow', [kw['rate_pow']/kw['gen_eff']], comments='[kW]')
sb.add_line('prvs_turbine', [1], comments='[-]')
sb.add_line('include_torsiondeform', [1], comments='[-]')
# controller
hs2.add_line('; define controller couplings', [])
sb = hs2.add_section('controller')
sb.add_section('input')
sb.input.add_line('constraint', ['bearing1', 'shaft_rot'])
sb.input.add_line('constraint', ['bearing2', 'pitch1', 'collective'])
sb.add_section('output')
sb.output.add_line('constraint', ['bearing1', 'shaft_rot', 1, 'only', 2])
sb.output.add_line('constraint', ['bearing2', 'pitch1', 1, 'only', 1, 'collective'])
# controller tuning
hs2.add_line('; inputs for controller tuning', [])
sb = hs2.add_section('controller_tuning') # controller tuning block
sb.partial_load = [kw['p1_f'], kw['p1_z']]
sb.partial_load.comments = 'fn [hz], zeta [-]'
sb.full_load = [kw['p2_f'], kw['p2_z']]
sb.full_load.comments = 'fn [hz], zeta [-]'
sb.gain_scheduling = [kw['gs']]
sb.gain_scheduling.comments = '1 linear, 2 quadratic'
sb.constant_power = [kw['constant_power']]
sb.constant_power.comments = '0 constant torque, 1 constant power at full load'
# HAWC2S commands
hs2.add_line('; HAWC2S commands (uncomment as needed)', [])
line = hs2.add_line(';compute_optimal_pitch_angle', ['use_operational_data'])
line = hs2.add_line(';compute_steady_states', ['bladedeform', 'tipcorrect',
'induction', 'nogradients'])
line.comments = 'compute steady states using hawcstab2 (need for other commands)'
line = hs2.add_line(';save_power', [])
line.comments = 'save steady-state values to input_htc_file.pwr'
line = hs2.add_line(';compute_controller_input', [])
line.comments = 'tune controller parameters'
# save the new file
htc.save(new_htc)
def turb_to_step(orig_htc, new_htc, **kwargs):
"""Convert base file to a step wind"""
kw = {**_DEF_KWARGS, **kwargs} # model params
htc = HTCFile(orig_htc)
wsp = range(kw['cut_in'], kw['cut_out']+1)
# set simulation time and file names
time_stop = (len(wsp) - 1)*(kw['dt'] + 1) + kw['tstart'] + kw['dt']
htc.simulation.time_stop = time_stop
htc.simulation.logfile = './log/IEA_15MW_RWT_step.log'
htc.output.filename = './res/IEA_15MW_RWT_step'
# add the step wind
del htc.wind.mann # remove mann block
htc.wind.shear_format = [3, 0.0] # no shear
htc.wind.turb_format = 0
htc.wind.tower_shadow_method = 0
htc.wind.add_line(';', [])
htc.wind.add_line(';', ['step-wind for testing controller tuning'])
htc.wind.wsp = wsp[0] # set first wsp
for i, u in enumerate(wsp[1:]):
t0 = (i + 1)*kw['dt'] + i + kw['tstart']
tend = t0 + 1
line = htc.wind.add_line('wind_ramp_abs', [t0, tend, 0, wsp[i+1]-wsp[i]])
line.comments = f'wsp. after the step: {u:.1f}'
# update the simulation time
htc.output.time = [kw['tstart'], time_stop]
# save the new file
htc.save(new_htc)
# -*- coding: utf-8 -*-
"""Setup file for refutils
"""
from setuptools import setup
setup(name='refutils',
version='0.1',
description='Utilities for HAWC reference models',
url='https://gitlab.windenergy.dtu.dk/hawc-reference-models/reference-utilities',
author='Jenni Rinker',
author_email='rink@dtu.dk',
license='MIT',
packages=['refutils', # top-level package
],
install_requires=[#'wetb', # wind energy toolbox (pip installation currently broken)
],
zip_safe=False)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment