Input file writing¶
HTCFile¶
Quickstart¶
The HTCFile class allows you to open, modify, save htc files and run HAWC2 simulations
In [1]:
from wetb import hawc2
from wetb.hawc2 import HTCFile
from wetb.hawc2.tests.test_files import tfp
htc = HTCFile(tfp + "htcfiles/DTU_10MW_RWT.htc")
htc.wind.wsp=11
print (htc)
htc.save("tmp/tmp.htc")
# htc.simulate('<path_to_hawc2>/hawc2mb.exe')
;DTU_10MW_RWT, version 9, 25-09-2017, mhha
;
begin simulation;
time_stop 1000;
solvertype 1; (newmark)
on_no_convergence continue;
convergence_limits 1000 1 1e-07;
logfile ./log/DTU_10MW_RWT_ver09.log;
begin newmark;
deltat 0.01;
end newmark;
end simulation;
;
;----------------------------------------------------------------------------------------------------------------------------------------------------------------
begin new_htc_structure;
; beam_output_file_name ./log/DTU_10MW_RWT_beam.dat; Optional - Calculated beam properties of the bodies are written to file
; body_output_file_name ./log/DTU_10MW_RWT_body.dat; Optional - Body initial position and orientation are written to file
; body_eigenanalysis_file_name ./eig/DTU_10MW_RWT_body_eigen.dat;
; structure_eigenanalysis_file_name ./eig/DTU_10MW_RWT_strc_eigen.dat ;
;-------------------------------------------------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------------------------------------------------
begin main_body; tower 115m
name tower;
type timoschenko;
nbodies 1;
node_distribution c2_def;
damping_posdef 0 0 0 0.00412 0.00412 0.00045; Mx My Mz Kx Ky Kz , M´s raises overall level, K´s raises high freguency level "tuned by Larh"
begin timoschenko_input;
filename ./data/DTU_10MW_RWT_Tower_st.dat;
set 1 1;
end timoschenko_input;
begin c2_def; Definition of centerline (main_body coordinates)
nsec 11;
sec 1 0 0 0 0; x,y,z,twist
sec 2 0 0 -11.5 0;
sec 3 0 0 -23 0;
sec 4 0 0 -34.5 0;
sec 5 0 0 -46 0;
sec 6 0 0 -57.5 0;
sec 7 0 0 -69 0;
sec 8 0 0 -80.5 0;
sec 9 0 0 -92 0;
sec 10 0 0 -103.5 0;
sec 11 0 0 -115.63 0;
end c2_def;
end main_body;
;
begin main_body;
name towertop;
type timoschenko;
nbodies 1;
node_distribution c2_def;
damping_posdef 0 0 0 0.007 0.007 0.007; "changed by Larh"
concentrated_mass 2 0 2.687 0.30061 446040 4106000 410600 4106000; Nacelle mass and inertia "corrected by Anyd 25/4/13"
begin timoschenko_input;
filename ./data/DTU_10MW_RWT_Towertop_st.dat;
set 1 2;
end timoschenko_input;
begin c2_def; Definition of centerline (main_body coordinates)
nsec 2;
sec 1 0 0 0 0; x,y,z,twist
sec 2 0 0 -2.75 0;
end c2_def;
end main_body;
;
begin main_body;
name shaft;
type timoschenko;
nbodies 1;
node_distribution c2_def;
damping_posdef 0 0 0 0.000465 0.000465 0.003983; "tuned by Anyd 23/5/13 to 31.45 log decr. damping for free free with stiff rotor and tower"
concentrated_mass 1 0 0 0 0 0 0 3751000; generator equivalent slow shaft "re_tuned by Anyd 20/2/13"
concentrated_mass 5 0 0 0 105520 0 0 325700; hub mass and inertia; "re_tuned by Anyd 20/2/13"
begin timoschenko_input;
filename ./data/DTU_10MW_RWT_Shaft_st.dat;
set 1 1;
end timoschenko_input;
begin c2_def; Definition of centerline (main_body coordinates)
nsec 5;
sec 1 0 0 0 0; Tower top x,y,z,twist
sec 2 0 0 1.5 0;
sec 3 0 0 3 0;
sec 4 0 0 4.4 0; Main bearing
sec 5 0 0 7.1 0; Rotor centre
end c2_def;
end main_body;
;
begin main_body;
name hub1;
type timoschenko;
nbodies 1;
node_distribution c2_def;
damping_posdef 0 0 0 3e-06 3e-06 2e-05; "changed by Larh"
begin timoschenko_input;
filename ./data/DTU_10MW_RWT_Hub_st.dat;
set 1 2;
end timoschenko_input;
begin c2_def; Definition of centerline (main_body coordinates)
nsec 2;
sec 1 0 0 0 0; x,y,z,twist
sec 2 0 0 2.8 0;
end c2_def;
end main_body;
;
begin main_body;
name hub2;
copy_main_body hub1;
end main_body;
;
begin main_body;
name hub3;
copy_main_body hub1;
end main_body;
;
begin main_body;
name blade1;
type timoschenko;
nbodies 10;
node_distribution c2_def;
damping_posdef 0 0 0 0.00153 0.00255 0.00033; " 3% damping tuned by tkim 23/03/13 unable to fit 3rd and higher mode"
begin timoschenko_input;
filename ./data/DTU_10MW_RWT_Blade_st.dat;
set 1 1; set subset
end timoschenko_input;
begin c2_def; Definition of centerline (main_body coordinates)
nsec 27;
sec 1 0 7.006e-05 4.44089e-16 -14.5;
sec 2 -2.06477e-05 -0.0122119 3 -14.5;
sec 3 -0.0072881 -0.0249251 6 -14.4851;
sec 4 -0.0189235 -0.0273351 7.00004 -14.461;
sec 5 -0.0541282 -0.0282163 8.70051 -14.3388;
sec 6 -0.126633 -0.021321 10.402 -14.0201;
sec 7 -0.225666 -0.0128378 12.2046 -13.3904;
sec 8 -0.288563 -0.00770659 13.2065 -12.9371;
sec 9 -0.399194 -0.00488317 15.01 -11.9445;
sec 10 -0.576634 -0.0180296 18.2151 -9.98243;
sec 11 -0.707136 -0.0501772 21.4178 -8.45147;
sec 12 -0.791081 -0.0941228 24.6189 -7.46417;
sec 13 -0.837195 -0.14888 27.8193 -6.72916;
sec 14 -0.853948 -0.214514 31.0194 -6.08842;
sec 15 -0.849367 -0.290618 34.2197 -5.49322;
sec 16 -0.79392 -0.462574 40.2204 -4.39222;
sec 17 -0.716284 -0.688437 46.6217 -3.09315;
sec 18 -0.634358 -0.960017 53.0232 -1.75629;
sec 19 -0.553179 -1.28424 59.4245 -0.50065;
sec 20 -0.475422 -1.66402 65.8255 0.601964;
sec 21 -0.40318 -2.10743 72.2261 1.5556;
sec 22 -0.330085 -2.6563 79.0266 2.51935;
sec 23 -0.31014 -2.78882 80.5267 2.7295;
sec 24 -0.286719 -2.92517 82.0271 2.93201;
sec 25 -0.255823 -3.06577 83.5274 3.11874;
sec 26 -0.207891 -3.20952 85.0277 3.28847;
sec 27 -0.089894 -3.33685 86.3655 3.42796;
end c2_def;
end main_body;
;
begin main_body;
name blade2;
copy_main_body blade1;
end main_body;
;
begin main_body;
name blade3;
copy_main_body blade1;
end main_body;
;-------------------------------------------------------------------------------------------------------------------------------
;
begin orientation;
begin base;
body tower;
inipos 0 0 0; initial position of node 1
body_eulerang 0 0 0;
end base;
;
begin relative;
body1 tower last;
body2 towertop 1;
body2_eulerang 0 0 0;
end relative;
;
begin relative;
body1 towertop last;
body2 shaft 1;
body2_eulerang 90 0 0;
body2_eulerang 5 0 0; 5 deg tilt angle
mbdy2_ini_rotvec_d1 0 0 -1 0.2; mbdy2_ini_rotvec_d1 0.0 0.0 -1.0 [init_wr];
end relative;
;
begin relative;
body1 shaft last;
body2 hub1 1;
body2_eulerang -90 0 0;
body2_eulerang 0 180 0;
body2_eulerang 2.5 0 0; 2.5deg cone angle
end relative;
;
begin relative;
body1 shaft last;
body2 hub2 1;
body2_eulerang -90 0 0;
body2_eulerang 0 60 0;
body2_eulerang 2.5 0 0; 2.5deg cone angle
end relative;
;
begin relative;
body1 shaft last;
body2 hub3 1;
body2_eulerang -90 0 0;
body2_eulerang 0 -60 0;
body2_eulerang 2.5 0 0; 2.5deg cone angle
end relative;
;
begin relative;
body1 hub1 last;
body2 blade1 1;
body2_eulerang 0 0 0;
end relative;
;
begin relative;
body1 hub2 last;
body2 blade2 1;
body2_eulerang 0 0 0;
end relative;
;
begin relative;
body1 hub3 last;
body2 blade3 1;
body2_eulerang 0 0 0;
end relative;
;
end orientation;
;-------------------------------------------------------------------------------------------------------------------------------
begin constraint;
;
begin fix0; fixed to ground in translation and rotation of node 1
body tower;
end fix0;
;
begin fix1;
body1 tower last;
body2 towertop 1;
end fix1;
;
begin bearing1; free bearing
name shaft_rot;
body1 towertop last;
body2 shaft 1;
bearing_vector 2 0 0 -1; x=coo (0=global.1=body1.2=body2) vector in body2 coordinates where the free rotation is present
end bearing1;
;
begin fix1;
body1 shaft last;
body2 hub1 1;
end fix1;
;
begin fix1;
body1 shaft last;
body2 hub2 1;
end fix1;
;
begin fix1;
body1 shaft last;
body2 hub3 1;
end fix1;
;
begin bearing2;
name pitch1;
body1 hub1 last;
body2 blade1 1;
bearing_vector 2 0 0 -1;
end bearing2;
;
begin bearing2;
name pitch2;
body1 hub2 last;
body2 blade2 1;
bearing_vector 2 0 0 -1;
end bearing2;
;
begin bearing2;
name pitch3;
body1 hub3 last;
body2 blade3 1;
bearing_vector 2 0 0 -1;
end bearing2;
end constraint;
;
end new_htc_structure;
;----------------------------------------------------------------------------------------------------------------------------------------------------------------
begin wind;
density 1.225;
wsp 11;
tint 0;
horizontal_input 1;
windfield_rotations 0 0 0; yaw, tilt, rotation
center_pos0 0 0 -119; hub heigth
shear_format 1 0.2;
turb_format 0; 0=none, 1=mann,2=flex
tower_shadow_method 0; 0=none, 1=potential flow, 2=jet
scale_time_start 0;
wind_ramp_factor 0 40 0.6 1;
; Steps ;
wind_ramp_abs 140 141 0 1; wsp. after the step: 5.0
wind_ramp_abs 181 182 0 1; wsp. after the step: 6.0
wind_ramp_abs 222 223 0 1; wsp. after the step: 7.0
wind_ramp_abs 263 264 0 1; wsp. after the step: 8.0
wind_ramp_abs 304 305 0 1; wsp. after the step: 9.0
wind_ramp_abs 345 346 0 1; wsp. after the step: 10.0
wind_ramp_abs 386 387 0 1; wsp. after the step: 11.0
wind_ramp_abs 427 428 0 1; wsp. after the step: 12.0
wind_ramp_abs 468 469 0 1; wsp. after the step: 13.0
wind_ramp_abs 509 510 0 1; wsp. after the step: 14.0
wind_ramp_abs 550 551 0 1; wsp. after the step: 15.0
wind_ramp_abs 591 592 0 1; wsp. after the step: 16.0
wind_ramp_abs 632 633 0 1; wsp. after the step: 17.0
wind_ramp_abs 673 674 0 1; wsp. after the step: 18.0
wind_ramp_abs 714 715 0 1; wsp. after the step: 19.0
wind_ramp_abs 755 756 0 1; wsp. after the step: 20.0
wind_ramp_abs 796 797 0 1; wsp. after the step: 21.0
wind_ramp_abs 837 838 0 1; wsp. after the step: 22.0
wind_ramp_abs 878 879 0 1; wsp. after the step: 23.0
wind_ramp_abs 919 920 0 1; wsp. after the step: 24.0
wind_ramp_abs 960 961 0 1; wsp. after the step: 25.0
;
begin tower_shadow_potential_2;
tower_mbdy_link tower;
nsec 2;
radius 0 4.15;
radius 115.63 2.75;
end tower_shadow_potential_2;
end wind;
;
begin aerodrag;
begin aerodrag_element;
mbdy_name tower;
aerodrag_sections uniform 10;
nsec 2;
sec 0 0.6 8.3; tower bottom
sec 115.63 0.6 5.5; tower top
end aerodrag_element;
;
begin aerodrag_element; Nacelle drag side
mbdy_name shaft;
aerodrag_sections uniform 2;
nsec 2;
sec 0 0.8 10;
sec 7.01 0.8 10;
end aerodrag_element;
end aerodrag;
;
begin aero;
nblades 3;
hub_vec shaft -3; rotor rotation vector (normally shaft composant directed from pressure to sustion side)
link 1 mbdy_c2_def blade1;
link 2 mbdy_c2_def blade2;
link 3 mbdy_c2_def blade3;
ae_filename ./data/DTU_10MW_RWT_ae.dat;
pc_filename ./data/DTU_10MW_RWT_pc.dat;
induction_method 1; 0=none, 1=normal
aerocalc_method 1; 0=ingen aerodynamic, 1=med aerodynamic
aerosections 50; def. 50
ae_sets 1 1 1;
tiploss_method 1; 0=none, 1=prandtl
dynstall_method 2; 0=none, 1=stig øye method,2=mhh method
;
end aero;
;-------------------------------------------------------------------------------------------------
begin dll;
;
begin type2_dll;
name dtu_we_controller;
filename ./control/dtu_we_controller.dll;
dll_subroutine_init init_regulation_advanced;
dll_subroutine_update update_regulation;
arraysizes_init 100 1;
arraysizes_update 100 100;
begin init;
; Overall parameters
constant 1 10000; Rated power [kW]
constant 2 0.628; Minimum rotor (LSS) speed [rad/s]
constant 3 1.005; Rated rotor (LSS) speed [rad/s]
constant 4 15600000; Maximum allowable generator torque [Nm]
constant 5 100; Minimum pitch angle, theta_min [deg],
; if |theta_min|>90, then a table of <wsp,theta_min> is read ;
; from a file named 'wptable.n', where n=int(theta_min)
constant 6 82; Maximum pitch angle [deg]
constant 7 10; Maximum pitch velocity operation [deg/s]
constant 8 0.4; Frequency of generator speed filter [Hz]
constant 9 0.7; Damping ratio of speed filter [-]
constant 10 1.8; Frequency of free-free DT torsion mode [Hz], if zero no notch filter used
; Partial load control parameters
constant 11 13013100; Optimal Cp tracking K factor [Nm/(rad/s)^2], ;
; Qg=K*Omega^2, K=eta*0.5*rho*A*Cp_opt*R^3/lambda_opt^3
constant 12 68345600; Proportional gain of torque controller [Nm/(rad/s)]
constant 13 15336700; Integral gain of torque controller [Nm/rad]
constant 14 0; Differential gain of torque controller [Nm/(rad/s^2)]
; Full load control parameters
constant 15 1; Generator control switch [1=constant power, 2=constant torque]
constant 16 1.06713; Proportional gain of pitch controller [rad/(rad/s)]
constant 17 0.242445; Integral gain of pitch controller [rad/rad]
constant 18 0; Differential gain of pitch controller [rad/(rad/s^2)]
constant 19 4e-09; Proportional power error gain [rad/W]
constant 20 4e-09; Integral power error gain [rad/(Ws)]
constant 21 11.4; Coefficient of linear term in aerodynamic gain scheduling, KK1 [deg]
constant 22 402.9; Coefficient of quadratic term in aerodynamic gain scheduling, KK2 [deg^2] &
; (if zero, KK1 = pitch angle at double gain)
constant 23 1.3; Relative speed for double nonlinear gain [-]
; Cut-in simulation parameters
constant 24 -1; Cut-in time [s], no cut-in is simulated if zero or negative
constant 25 1; Time delay for soft start of torque [1/1P]
; Cut-out simulation parameters
constant 26 -1; Shut-down time [s], no shut-down is simulated if zero or negative
constant 27 5; Time of linear torque cut-out during a generator assisted stop [s]
constant 28 1; Stop type [1=normal, 2=emergency]
constant 29 1; Time delay for pitch stop after shut-down signal [s]
constant 30 3; Maximum pitch velocity during initial period of stop [deg/s]
constant 31 3; Time period of initial pitch stop phase [s] (maintains pitch speed specified in constant 30)
constant 32 4; Maximum pitch velocity during final phase of stop [deg/s]
; Expert parameters (keep default values unless otherwise given)
constant 33 2; Time for the maximum torque rate = Maximum allowable generator torque/(constant 33 + 0.01s) [s]
constant 34 2; Upper angle above lowest minimum pitch angle for switch [deg], if equal then hard switch
constant 35 95; Percentage of the rated speed when the torque limits are fully opened [%]
constant 36 2; Time constant of 1st order filter on wind speed used for minimum pitch [1/1P]
constant 37 1; Time constant of 1st order filter on pitch angle used for gain scheduling [1/1P]
; Drivetrain damper
constant 38 0; Proportional gain of active DT damper [Nm/(rad/s)], requires frequency in input 10
; Over speed
constant 39 25; Overspeed percentage before initiating turbine controller alarm (shut-down) [%]
; Additional non-linear pitch control term (not used when all zero)
constant 40 0; Rotor speed error scaling factor [rad/s]
constant 41 0; Rotor acceleration error scaling factor [rad/s^2]
constant 42 0; Pitch rate gain [rad/s]
; Storm control command
constant 43 28; Wind speed 'Vstorm' above which derating of rotor speed is used [m/s]
constant 44 28; Cut-out wind speed (only used for derating of rotor speed in storm) [m/s]
; Safety system parameters
constant 45 30; Overspeed percentage before initiating safety system alarm (shut-down) [%]
constant 46 1.5; Max low-pass filtered tower top acceleration level [m/s^2]
; Turbine parameter
constant 47 178; Nominal rotor diameter [m]
; Parameters for rotor inertia reduction in variable speed region
constant 48 0; Proportional gain on rotor acceleration in variable speed region [Nm/(rad/s^2)] (not used when zero)
; Parameters for alternative partial load controller with PI regulated TSR tracking
constant 49 7.8; Optimal tip speed ratio [-] (only used when K=constant 11 = 0 otherwise Qg=K*Omega^2 is used)
; Parameters for adding aerodynamic drivetrain damping on gain scheduling
constant 50 0; Aerodynamic DT damping coefficient at the operational point of zero pitch angle [Nm/(rad/s)] (not used when zero)
constant 51 0; Coefficient of linear term in aerodynamic DT damping scheduling, KK1 [deg]
constant 52 0; Coefficient of quadratic term in aerodynamic DT damping scheduling, KK2 [deg^2]
; Torque exclusion zone
constant 53 0; Exclusion zone: Lower speed limit [rad/s] (Default 0 used if zero)
constant 54 0; Exclusion zone: Generator torque at lower limit [Nm] (Default 0 used if zero)
constant 55 0; Exclusion zone: Upper speed limit [rad/s] (if =< 0 then exclusion zone functionality is inactive)
constant 56 0; Exclusion zone: Generator torque at upper limit [Nm] (Default 0 used if zero)
constant 57 0; Time constant of reference switching at exclusion zone [s] (Default 0 used if zero)
; DT torsion mode damper
constant 58 0; Frequency of notch filter [Hz] (Default 10 x input 10 used if zero)
constant 59 0; Damping of BP filter [-] (Default 0.02 used if zero)
constant 60 0; Damping of notch filter [-] (Default 0.01 used if zero)
constant 61 0; Phase lag of damper [s] => max 40*dt (Default 0 used if zero)
; Fore-aft Tower mode damper
constant 62 0; Frequency of BP filter [Hz] (Default 10 used if zero)\\
constant 63 0; Frequency of notch fiter [Hz] (Default 10 used if zero)\\
constant 64 0; Damping of BP filter [-] (Default 0.02 used if zero)\\
constant 65 0; Damping of notch filter [-] (Default 0.01 used if zero)\\
constant 66 0; Gain of damper [-] (Default 0 used if zero)\\
constant 67 0; Phase lag of damper [s] => max 40*dt (Default 0 used if zero)\\
constant 68 0; Time constant of 1st order filter on PWR used for fore-aft Tower mode damper GS [Hz] (Default 10 used if zero)
constant 69 0; Lower PWR limit used for fore-aft Tower mode damper GS [-] (Default 0 used if zero)
constant 70 0; Upper PWR limit used for fore-aft Tower mode damper GS [-] (Default 0 used if zero)
; Side-to-side Tower mode filter
constant 71 0; Frequency of Tower side-to-sede notch filter [Hz] (Default 100 used if zero)
constant 72 0; Damping of notch filter [-] (Default 0.01 used if zero)
constant 73 0; Max low-pass filtered tower top acceleration level before initiating safety system alarm (shut-down) [m/s^2] (Default 1.1 x input 46 used if zero)
constant 74 0; Time constant of 1st order filter on tower top acceleration [1/1P] (Default 1 used if zero)
; Pitch deviation monitor parameters
constant 75 1005020; Parameters for pitch deviation monitoring. The format is 1,nnn,mmm
; where 'nnn' [s] is the period of the moving average and 'mmm' is threshold of the deviation [0.1 deg] (functionality is inactive if value $<$ 1,000,000)
; Gear ratio
constant 76 0; Gear ratio used for the calculation of the LSS rotational speeds and the HSS generator torque reference [-] (Default 1 if zero)
end init;
;
begin output;
general time; [s]
constraint bearing1 shaft_rot 1 only 2; Drivetrain speed [rad/s]
constraint bearing2 pitch1 1 only 1; [rad]
constraint bearing2 pitch2 1 only 1; [rad]
constraint bearing2 pitch3 1 only 1; [rad]
wind free_wind 1 0 0 -119; Global coordinates at hub height
dll inpvec 2 2; Elec. power from generator servo .dll
dll inpvec 2 8; Grid state flag from generator servo .dll
mbdy state acc towertop 1 1 global only 1; Tower top x-acceleration [m/s^2]
mbdy state acc towertop 1 1 global only 2; Tower top y-acceleration [m/s^2]
end output;
end type2_dll;
;
begin type2_dll;
name generator_servo;
filename ./control/generator_servo.dll;
dll_subroutine_init init_generator_servo;
dll_subroutine_update update_generator_servo;
arraysizes_init 100 1;
arraysizes_update 100 100;
begin init;
constant 1 20; Frequency of 2nd order servo model of generator-converter system [Hz]
constant 2 0.9; Damping ratio 2nd order servo model of generator-converter system [-]
constant 3 15600000; Maximum allowable LSS torque (pull-out torque) [Nm]
constant 4 0.94; Generator efficiency [-]
constant 5 1; Gearratio [-]
constant 6 0; Time for half value in softstart of torque [s]
constant 7 -1; Time for grid loss [s] (never if lower than zero)
end init;
;
begin output;
general time; Time [s]
dll inpvec 1 1; Electrical torque reference [Nm]
constraint bearing1 shaft_rot 1 only 2; Generator LSS speed [rad/s]
mbdy momentvec shaft 1 1 shaft only 3; Shaft moment [kNm] (Qshaft)
end output;
;
begin actions;
mbdy moment_int shaft 1 -3 shaft towertop 2; Generator LSS torque [Nm]
end actions;
end type2_dll;
;
begin type2_dll;
name mech_brake;
filename ./control/mech_brake.dll;
dll_subroutine_init init_mech_brake;
dll_subroutine_update update_mech_brake;
arraysizes_init 100 1;
arraysizes_update 100 100;
begin init;
constant 1 9360000; Fully deployed maximum brake torque [Nm] (0.6*max torque)
constant 2 100; Parameter alpha used in Q = tanh(omega*alpha), typically 1e2/Omega_nom
constant 3 0.5; Delay time for before brake starts to deploy [s]
constant 4 0.6; Time for brake to become fully deployed [s]
end init;
;
begin output;
general time; Time [s]
constraint bearing1 shaft_rot 1 only 2; Generator LSS speed [rad/s]
dll inpvec 1 25; Command to deploy mechanical disc brake [0,1]
end output;
;
begin actions;
mbdy moment_int shaft 1 -3 shaft towertop 2; Brake LSS torque [Nm]
end actions;
end type2_dll;
;
begin type2_dll;
name servo_with_limits;
filename ./control/servo_with_limits.dll;
dll_subroutine_init init_servo_with_limits;
dll_subroutine_update update_servo_with_limits;
arraysizes_init 100 1;
arraysizes_update 100 100;
begin init;
constant 1 3; Number of blades [-]
constant 2 1; Frequency of 2nd order servo model of pitch system [Hz]
constant 3 0.7; Damping ratio 2nd order servo model of pitch system [-]
constant 4 10; Max. pitch speed [deg/s]
constant 5 15; Max. pitch acceleration [deg/s^2]
constant 6 -5; Min. pitch angle [deg]
constant 7 90; Max. pitch angle [deg]
constant 8 -1; Time for pitch runaway [s]
constant 9 -1; Time for stuck blade 1 [s]
constant 10 0; Angle of stuck blade 1 [deg] (if > 90 deg then blade is stuck at instantaneous angle)
end init;
begin output;
general time; Time [s]
dll inpvec 1 2; Pitch1 demand angle [rad]
dll inpvec 1 3; Pitch2 demand angle [rad]
dll inpvec 1 4; Pitch3 demand angle [rad]
dll inpvec 1 26; Flag for emergency pitch stop [0=off/1=on]
end output;
;
begin actions;
constraint bearing2 angle pitch1; Angle pitch1 bearing [rad]
constraint bearing2 angle pitch2; Angle pitch2 bearing [rad]
constraint bearing2 angle pitch3; Angle pitch3 bearing [rad]
end actions;
end type2_dll;
;
; --- DLL for tower-blade tip distance -- ;
;-------------------------------------------
begin type2_dll;
name towerclearance_mblade;
filename ./control/towerclearance_mblade.dll;
dll_subroutine_init initialize;
dll_subroutine_update update;
arraysizes_init 3 1;
arraysizes_update 15 6;
begin init; Variables passed into initialization function
constant 1 4.15; Tower radius at tower bottom [m]
constant 2 2.75; Tower radius at tower top [m]
constant 3 3; Number of points to check [-]
end init;
begin output; Variables passed into update function
mbdy state pos tower 1 0 global; [1,2,3] global coordinates of tower base
mbdy state pos tower 10 1 global; [4,5,6] global coordinates of tower top
mbdy state pos blade1 26 1 global; [7,8,9] global coordinates of point 1 (blade 1 tip)
mbdy state pos blade2 26 1 global; [10,11,12] global coordinates of point 2 (blade 2 tip)
mbdy state pos blade3 26 1 global; [13,14,15] global coordinates of point 3 (blade 3 tip)
end output;
end type2_dll;
;
end dll;
;----------------------------------------------------------------------------------------------------------------------------------------------------------------
;
begin output;
filename ./res/DTU_10MW_RWT_ver09;
data_format hawc_binary;
buffer 1;
;
general time;
constraint bearing1 shaft_rot 2; angle and angle velocity
constraint bearing2 pitch1 5; angle and angle velocity
constraint bearing2 pitch2 5; angle and angle velocity
constraint bearing2 pitch3 5; angle and angle velocity
aero omega;
aero torque;
aero power;
aero thrust;
wind free_wind 1 0 0 -119; local wind at fixed position: coo (1=global,2=non-rotation rotor coo.), pos x, pos y, pos z
; Moments:
mbdy momentvec tower 1 1 tower # tower base;
mbdy momentvec tower 10 2 tower # tower yaw bearing;
mbdy momentvec shaft 4 1 shaft # main bearing;
mbdy momentvec blade1 2 2 blade1 # blade 1 root;
mbdy momentvec blade2 2 2 blade2 # blade 2 root;
mbdy momentvec blade3 2 2 blade3 # blade 3 root;
mbdy momentvec blade1 13 1 local # blade 1 50% local e coo;
mbdy momentvec blade2 13 1 local # blade 2 50% local e coo;
mbdy momentvec blade3 13 1 local # blade 3 50% local e coo;
; Displacements and accellerations
mbdy state pos tower 10 1 global only 1 # Tower top FA displ;
mbdy state pos tower 10 1 global only 2 # Tower top SS displ;
mbdy state acc tower 10 1 global only 1 # Tower top FA acc;
mbdy state acc tower 10 1 global only 2 # Tower top SS acc;
;
mbdy state pos blade1 26 1 blade1 # blade 1 tip pos;
mbdy state pos blade2 26 1 blade2 # blade 2 tip pos;
mbdy state pos blade3 26 1 blade3 # blade 3 tip pos;
mbdy state pos blade1 26 1 global # gl blade 1 tip pos;
; - Monitor Aerodynamics - ;
aero windspeed 3 1 1 72.5;
aero alfa 1 72.5;
aero alfa 2 72.5;
aero alfa 3 72.5;
aero cl 1 72.5;
aero cl 2 72.5;
aero cl 3 72.5;
aero cd 1 72.5;
aero cd 2 72.5;
aero cd 3 72.5;
; DLL outputs and into HAWC2
dll inpvec 1 1 # Generator torque reference [Nm];
dll inpvec 1 2 # Pitch angle reference of blade 1 [rad];
dll inpvec 1 3 # Pitch angle reference of blade 2 [rad];
dll inpvec 1 4 # Pitch angle reference of blade 3 [rad];
dll inpvec 1 5 # Power reference [W];
dll inpvec 1 6 # Filtered wind speed [m/s];
dll inpvec 1 7 # Filtered rotor speed [rad/s];
dll inpvec 1 8 # Filtered rotor speed error for torque [rad/s];
dll inpvec 1 9 # Bandpass filtered rotor speed [rad/s];
dll inpvec 1 10 # Proportional term of torque contr. [Nm];
dll inpvec 1 11 # Integral term of torque controller [Nm];
dll inpvec 1 12 # Minimum limit of torque [Nm];
dll inpvec 1 13 # Maximum limit of torque [Nm];
dll inpvec 1 14 # Torque limit switch based on pitch [-];
dll inpvec 1 15 # Filtered rotor speed error for pitch [rad/s];
dll inpvec 1 16 # Power error for pitch [W];
dll inpvec 1 17 # Proportional term of pitch controller [rad];
dll inpvec 1 18 # Integral term of pitch controller [rad];
dll inpvec 1 19 # Minimum limit of pitch [rad];
dll inpvec 1 20 # Maximum limit of pitch [rad];
dll inpvec 1 21 # Torque reference from DT dammper [Nm];
dll inpvec 1 22 # Status signal [-];
dll inpvec 1 23 # Total added pitch rate [rad/s];
dll inpvec 1 24 # Filtered Mean pitch for gain sch [rad];
dll inpvec 1 25 # Flag for mechnical brake [0=off/1=on];
dll inpvec 1 26 # Flag for emergency pitch stop [0=off/1=on];
dll inpvec 1 27 # LP filtered acceleration level [m/s^2];
dll inpvec 1 31 # Monitored average of reference pitch [rad];
dll inpvec 1 32 # Monitored ave. of actual pitch (blade 1) [rad];
; Input from generator model
dll inpvec 2 1 # Mgen LSS [Nm];
dll inpvec 2 2 # Pelec [W];
dll inpvec 2 3 # Mframe [Nm];
dll inpvec 2 4 # Mgen HSS [Nm];
dll inpvec 2 8 # Grid flag [0=run/1=stop];
; Input from mechanical brake
dll inpvec 3 1 # Brake torque [Nm];
; Input from pitch servo
dll inpvec 4 1 # pitch 1 [rad];
dll inpvec 4 2 # pitch 2 [rad];
dll inpvec 4 3 # pitch 3 [rad];
; Check tower clearence
dll inpvec 5 1 # Bltip tow min d [m];
end output;
;
exit;
Load htc files¶
HTCFile
takes the htc-filename and optionally the modelpath as
input.
The modelpath
is the path from where HAWC2 should be run, i.e. the
the origion for relative data file paths in the htc file. If not
specified (default) the modelpath
is autodetected if possible.
In [2]:
htc = HTCFile(filename=tfp+"htcfiles/DTU_10MW_RWT.htc",
modelpath=None # modelpath autodetected
)
print (htc.modelpath)
C:/mmpe/programming/python/WindEnergyToolbox/wetb/hawc2/tests/test_files/
Access htc contents¶
Access elements(lines and sections) in the htc file via dot or string notation
In [3]:
wsp = htc.wind.wsp # dot notation
print (wsp)
convergence_limits = htc['simulation.convergence_limits'] # string notation with dot
print (convergence_limits)
wsp 4;
convergence_limits 1000 1 1e-07;
you can also store a (sub)section in a varble and access subelements from that
In [4]:
wind = htc.wind
print (wind.wsp)
wsp 4;
Values of a line are obtained by
In [5]:
print (wsp[0])
print (htc.simulation.convergence_limits[:])
4
[1000, 1, 1e-07]
In case there is more than one element with the same name, e.g. main_body sections in new_htc_structure:
In [6]:
htc.new_htc_structure.keys()
Out[6]:
['main_body',
'main_body__2',
'main_body__3',
'main_body__4',
'main_body__5',
'main_body__6',
'main_body__7',
'main_body__8',
'main_body__9',
'orientation',
'constraint']
Then the right element can be access by adding __x
(where x is the
section number). The first element can be accessed without __x
or
with __1
In [7]:
htc.new_htc_structure.main_body__1 == htc.new_htc_structure.main_body
Out[7]:
True
Another way to access these elements are:
In [8]:
htc.new_htc_structure.get_subsection_by_name('shaft')
htc.new_htc_structure.main_body(name='shaft')
Out[8]:
<wetb.hawc2.htc_contents.HTCSection at 0x1ff94e5eb50>
HTC Section¶
In [9]:
section = htc.new_htc_structure.main_body__3.c2_def
print(section.section_name)
print(section.keys())
print(section.parent.section_name)
print(section.parent.location())
print()
print(section)
c2_def
['nsec', 'sec', 'sec__2', 'sec__3', 'sec__4', 'sec__5']
main_body
DTU_10MW_RWT.htc/new_htc_structure/main_body__3
begin c2_def; Definition of centerline (main_body coordinates)
nsec 5;
sec 1 0 0 0 0; Tower top x,y,z,twist
sec 2 0 0 1.5 0;
sec 3 0 0 3 0;
sec 4 0 0 4.4 0; Main bearing
sec 5 0 0 7.1 0; Rotor centre
end c2_def;
HTC Line¶
In [10]:
line = htc.new_htc_structure.main_body__3.c2_def.sec__4
print(line.values) # print all values in line
print(line.values[3]) # print value 4 (zero-indexed)
print(line.comments) # print comments
print()
print(line) # print line
[4, 0, 0, 4.4, 0]
4.4
Main bearing
sec 4 0 0 4.4 0; Main bearing
Output sensor¶
In [11]:
print (htc.output.sensors[3])
print (htc.output.sensors[3].type)
print (htc.output.sensors[3].sensor)
print (htc.output.sensors[3].values)
print (htc.output.sensors[3].comments)
constraint bearing2 pitch2 5; angle and angle velocity
constraint
bearing2
['pitch2', 5]
angle and angle velocity
Add htc contents¶
Add htc line¶
In [12]:
htc.simulation.my_line = "value1", 2
htc.simulation.my_line.comments = "MyComment"
print (htc.simulation)
begin simulation;
time_stop 1000;
solvertype 1; (newmark)
on_no_convergence continue;
convergence_limits 1000 1 1e-07;
logfile ./log/DTU_10MW_RWT_ver09.log;
begin newmark;
deltat 0.01;
end newmark;
my_line value1 2; MyComment
end simulation;
;
;----------------------------------------------------------------------------------------------------------------------------------------------------------------
In case there is already one line with the same key, then you need to
use the add_line
function
In [13]:
htc.simulation.add_line(name="my_line",
values=["value1", 2],
comments="MyComment for second my_line" #defaults to ""
)
print (htc.simulation)
begin simulation;
time_stop 1000;
solvertype 1; (newmark)
on_no_convergence continue;
convergence_limits 1000 1 1e-07;
logfile ./log/DTU_10MW_RWT_ver09.log;
begin newmark;
deltat 0.01;
end newmark;
my_line value1 2; MyComment
my_line value1 2; MyComment for second my_line
end simulation;
;
;----------------------------------------------------------------------------------------------------------------------------------------------------------------
Add htc section¶
In [14]:
my_section = htc.simulation.add_section(section_name="my_section",
members={"Line1":1, "line2":[21,22,23]},
allow_duplicate=False,
line3=[31,32])
print (htc.simulation)
begin simulation;
time_stop 1000;
solvertype 1; (newmark)
on_no_convergence continue;
convergence_limits 1000 1 1e-07;
logfile ./log/DTU_10MW_RWT_ver09.log;
begin newmark;
deltat 0.01;
end newmark;
my_line value1 2; MyComment
my_line value1 2; MyComment for second my_line
begin my_section;
line3 31 32;
Line1 1;
line2 21 22 23;
end my_section;
end simulation;
;
;----------------------------------------------------------------------------------------------------------------------------------------------------------------
If allow_duplicate
is False
and a section with the same name
already exists, then add_section
has no effect
In [15]:
my_section = htc.simulation.add_section(section_name="my_section",
allow_duplicate=False,
line4=4)
print (htc.simulation)
begin simulation;
time_stop 1000;
solvertype 1; (newmark)
on_no_convergence continue;
convergence_limits 1000 1 1e-07;
logfile ./log/DTU_10MW_RWT_ver09.log;
begin newmark;
deltat 0.01;
end newmark;
my_line value1 2; MyComment
my_line value1 2; MyComment for second my_line
begin my_section;
line3 31 32;
Line1 1;
line2 21 22 23;
end my_section;
end simulation;
;
;----------------------------------------------------------------------------------------------------------------------------------------------------------------
Add output sensor¶
In [16]:
htc.output.add_sensor('sensor_type', 'sensor_name', ['arg1', 2], comment = "MySensor", nr=3)
print (htc.output)
begin output;
filename ./res/DTU_10MW_RWT_ver09;
data_format hawc_binary;
buffer 1;
;
general time;
constraint bearing1 shaft_rot 2; angle and angle velocity
constraint bearing2 pitch1 5; angle and angle velocity
sensor_type sensor_name arg1 2; MySensor
constraint bearing2 pitch2 5; angle and angle velocity
constraint bearing2 pitch3 5; angle and angle velocity
aero omega;
aero torque;
aero power;
aero thrust;
wind free_wind 1 0 0 -119; local wind at fixed position: coo (1=global,2=non-rotation rotor coo.), pos x, pos y, pos z
; Moments:
mbdy momentvec tower 1 1 tower # tower base;
mbdy momentvec tower 10 2 tower # tower yaw bearing;
mbdy momentvec shaft 4 1 shaft # main bearing;
mbdy momentvec blade1 2 2 blade1 # blade 1 root;
mbdy momentvec blade2 2 2 blade2 # blade 2 root;
mbdy momentvec blade3 2 2 blade3 # blade 3 root;
mbdy momentvec blade1 13 1 local # blade 1 50% local e coo;
mbdy momentvec blade2 13 1 local # blade 2 50% local e coo;
mbdy momentvec blade3 13 1 local # blade 3 50% local e coo;
; Displacements and accellerations
mbdy state pos tower 10 1 global only 1 # Tower top FA displ;
mbdy state pos tower 10 1 global only 2 # Tower top SS displ;
mbdy state acc tower 10 1 global only 1 # Tower top FA acc;
mbdy state acc tower 10 1 global only 2 # Tower top SS acc;
;
mbdy state pos blade1 26 1 blade1 # blade 1 tip pos;
mbdy state pos blade2 26 1 blade2 # blade 2 tip pos;
mbdy state pos blade3 26 1 blade3 # blade 3 tip pos;
mbdy state pos blade1 26 1 global # gl blade 1 tip pos;
; - Monitor Aerodynamics - ;
aero windspeed 3 1 1 72.5;
aero alfa 1 72.5;
aero alfa 2 72.5;
aero alfa 3 72.5;
aero cl 1 72.5;
aero cl 2 72.5;
aero cl 3 72.5;
aero cd 1 72.5;
aero cd 2 72.5;
aero cd 3 72.5;
; DLL outputs and into HAWC2
dll inpvec 1 1 # Generator torque reference [Nm];
dll inpvec 1 2 # Pitch angle reference of blade 1 [rad];
dll inpvec 1 3 # Pitch angle reference of blade 2 [rad];
dll inpvec 1 4 # Pitch angle reference of blade 3 [rad];
dll inpvec 1 5 # Power reference [W];
dll inpvec 1 6 # Filtered wind speed [m/s];
dll inpvec 1 7 # Filtered rotor speed [rad/s];
dll inpvec 1 8 # Filtered rotor speed error for torque [rad/s];
dll inpvec 1 9 # Bandpass filtered rotor speed [rad/s];
dll inpvec 1 10 # Proportional term of torque contr. [Nm];
dll inpvec 1 11 # Integral term of torque controller [Nm];
dll inpvec 1 12 # Minimum limit of torque [Nm];
dll inpvec 1 13 # Maximum limit of torque [Nm];
dll inpvec 1 14 # Torque limit switch based on pitch [-];
dll inpvec 1 15 # Filtered rotor speed error for pitch [rad/s];
dll inpvec 1 16 # Power error for pitch [W];
dll inpvec 1 17 # Proportional term of pitch controller [rad];
dll inpvec 1 18 # Integral term of pitch controller [rad];
dll inpvec 1 19 # Minimum limit of pitch [rad];
dll inpvec 1 20 # Maximum limit of pitch [rad];
dll inpvec 1 21 # Torque reference from DT dammper [Nm];
dll inpvec 1 22 # Status signal [-];
dll inpvec 1 23 # Total added pitch rate [rad/s];
dll inpvec 1 24 # Filtered Mean pitch for gain sch [rad];
dll inpvec 1 25 # Flag for mechnical brake [0=off/1=on];
dll inpvec 1 26 # Flag for emergency pitch stop [0=off/1=on];
dll inpvec 1 27 # LP filtered acceleration level [m/s^2];
dll inpvec 1 31 # Monitored average of reference pitch [rad];
dll inpvec 1 32 # Monitored ave. of actual pitch (blade 1) [rad];
; Input from generator model
dll inpvec 2 1 # Mgen LSS [Nm];
dll inpvec 2 2 # Pelec [W];
dll inpvec 2 3 # Mframe [Nm];
dll inpvec 2 4 # Mgen HSS [Nm];
dll inpvec 2 8 # Grid flag [0=run/1=stop];
; Input from mechanical brake
dll inpvec 3 1 # Brake torque [Nm];
; Input from pitch servo
dll inpvec 4 1 # pitch 1 [rad];
dll inpvec 4 2 # pitch 2 [rad];
dll inpvec 4 3 # pitch 3 [rad];
; Check tower clearence
dll inpvec 5 1 # Bltip tow min d [m];
end output;
;
Modify htc contents¶
In [18]:
htc.wind.wsp = 12 # set single value element
print (htc.wind.wsp)
c2def = htc.new_htc_structure.main_body__3.c2_def
c2def.section_name = "c2_def_new"
c2def.sec__4 = 1,2,3,4 # set element with four values
c2def.sec__4[3] = 9
print (c2def)
wsp 12;
begin c2_def_new; Definition of centerline (main_body coordinates)
nsec 5;
sec 1 0 0 0 0; Tower top x,y,z,twist
sec 2 0 0 1.5 0;
sec 3 0 0 3 0;
sec 1 2 3 9; Main bearing
sec 5 0 0 7.1 0; Rotor centre
end c2_def_new;
Note, that you cannot change modify values of the current line, e.g.
line = htc.new_htc_structure.main_body__3.c2_def.sec__4
line = 1,2,3,4
as it will overwrite the variable line
with the tuple (1,2,3,4)
instead of updating the values
Delete¶
Sections and lines are deleted by calling their delete
method
In [44]:
htc.simulation.my_line.delete() # second my_line (my_line__2) remains
htc.simulation.my_section.delete()
print (htc.simulation)
begin simulation;
time_stop 1000;
solvertype 1; (newmark)
on_no_convergence continue;
convergence_limits 1000 1 1e-07;
logfile ./log/DTU_10MW_RWT_ver09.log;
begin newmark;
deltat 0.01;
end newmark;
my_line value1 2; MyComment for second my_line
end simulation;
;
;----------------------------------------------------------------------------------------------------------------------------------------------------------------
HTC functions¶
set_name()¶
The set_name
function sets the filename, as well as the
log filename
animation filename
visualization filename
output filename (only first output section)
In [45]:
htc.set_name(name="new_name", subfolder='my_folder')
print (htc.filename)
print (htc.simulation.logfile)
print (htc.output.filename)
c:/mmpe/programming/python/windenergytoolbox/wetb/hawc2/tests/test_files/htc/my_folder/new_name.htc
logfile ./log/my_folder/new_name.log;
filename ./res/my_folder/new_name;
set_time()¶
The set_time(start=None, stop=None, step=None)
function sets the
start, stop and step time if specified:
In [46]:
htc.set_time(10,20,.1)
print (htc.simulation.time_stop)
print (htc.simulation.newmark.deltat)
print (htc.wind.scale_time_start)
print (htc.output.time)
time_stop 20;
deltat 0.1;
scale_time_start 10;
time 10 20;
simulate()¶
The simulate(exe)
function saves the htc file, performs the
simulation using the specified exe (HAWC2), raises an error if the
simulation fails and returns the console output and log
stdout, log = htc.simulate("<path_to_hawc2>\hawc2mb.exe")
Parameter study¶
HTC files for parameter studies, can be generated by a loop that updates the desired values of the htc and saves the result:
In [49]:
from wetb.hawc2 import HTCFile
from wetb.hawc2.tests.test_files import tfp
htc = HTCFile(tfp + "htcfiles/DTU_10MW_RWT.htc")
for wsp in [4,6,8]:
htc.wind.wsp = wsp
htc.set_name("case_wsp%d"%wsp)
htc.save()
HAWC2InputWriter¶
An easier way for more complicate studies is to use the HAWC2InputWriter which takes a case as input (see Case list generation)
A case is dictionary of (key,value)-pairs. Keys can be:
Htc address, e.g. wind.wsp
Function name, e.g.
wsp
in which casevalue
is passed to theset_wsp
ofHAWC2InputWriter
(which you must implement)A tag that is replaced by
value
Note, all three types can be combined
First we create the htc file that we want the parameter study to be based on
In [50]:
%%writefile "tmp/base.htc"
begin simulation;
time_stop 600;
logfile log.txt
end simulation;
;
begin wind;
wsp 10;
end wind;
exit;
Writing tmp/base.htc
htc address¶
For (key-value) cases where the keys are htc addresses, we just need a
HAWC2InputWriter
In [51]:
from wetb.hawc2 import HTCFile
from wetb.hawc2 import HAWC2InputWriter
h2writer = HAWC2InputWriter(base_htc_file='tmp/base.htc')
that allow us to make a case like this
In [53]:
h2writer('tmp/my_case.htc', **{'wind.wsp':12, 'simulation.logfile': "my_case.log"})
In [55]:
print (HTCFile('tmp/my_case.htc'))
begin simulation;
time_stop 600;
logfile my_case.log;
end simulation;
;
begin wind;
wsp 12;
end wind;
exit;
Function name¶
For (key-value) cases where the keys are function names, a subclass of
HAWC2InputWriter
with the required functions must be implemented:
In [56]:
class MyInputWriter(HAWC2InputWriter):
def set_wsp(self, htc, wsp, **_):
htc.wind.wsp = wsp
bs = self.begin_step
for i, o in enumerate([0,50],1):
htc.wind.add_line("wind_ramp_abs", [bs+o, bs+o+1, 0, 1], "wsp. after the step: %d.0"%(wsp+i))
# ...
def set_log(self, htc, log, **_):
if log:
htc.simulation.logfile = log
else:
htc.simulation.logfile.delete()
This approach enables
Multiple values, e.g. wind speed, turbulence grid size, wind ramp etc., can be set by one (key,value)-pair
Lines or sections can be deleted
Use of constants (specified when creating the writer)
Modification of e.g. aerodynamic, profile or structural data files
In [57]:
h2writer = MyInputWriter(base_htc_file='tmp/base.htc',
begin_step=100, # constant need in the implemented functions (specify as many as you want)
)
h2writer('tmp/my_case.htc', wsp=12, log=None, sensor_y=[10,20])
In [58]:
print (HTCFile('tmp/my_case.htc'))
begin simulation;
time_stop 600;
end simulation;
;
begin wind;
wsp 12;
wind_ramp_abs 100 101 0 1; wsp. after the step: 13.0
wind_ramp_abs 150 151 0 1; wsp. after the step: 14.0
end wind;
exit;
Tags¶
The tag options offers template rendering via the jinja templating language. Jinja templates allows:
variable substitution,
wsp {{wsp}}
conditionals
{% if logfilename %}
logfile {{logfilename}}
{% endif %}
loops
{%- for y in sensor_y %}
wind free_wind 1 0.0 {{ y }} -119;
{%- endfor %}
let us make a new template.htc
In [60]:
%%writefile "tmp/template.htc"
begin simulation;
time_stop 600;
{% if logfilename %}
logfile {{logfilename}}
{% endif %}
end simulation;
;
begin wind;
wsp {{wsp}};
{%- for i in range(2) %}
wind_ramp_abs {{begin_step+i*50}} {{begin_step+i*50+1}} 0 1; wsp. after the step: {{wsp+i+1}}
{%- endfor %}
end wind;
exit;
Writing tmp/template.htc
In [61]:
h2writer = HAWC2InputWriter(base_htc_file='tmp/template.htc')
h2writer('tmp/my_case.htc', wsp=12, log=None, begin_step=100)
In [62]:
print (HTCFile('tmp/my_case.htc'))
begin simulation;
time_stop 600;
end simulation;
;
begin wind;
wsp 12;
wind_ramp_abs 100 101 0 1; wsp. after the step: 13
wind_ramp_abs 150 151 0 1; wsp. after the step: 14
end wind;
exit;
Case list generation¶
The HAWC2InputWriter
can also handle a list of cases.
These cases can be defined in a Pandas DataFrame or an excel sheet
Note, case lists must contain a Name
column
Pandas Dataframe¶
In [63]:
import pandas as pd
df = pd.DataFrame({'Name':['case10', 'case12'], 'wsp':[10,12], 'log':['','log.txt']})
df
Out[63]:
Name | wsp | log | |
---|---|---|---|
0 | case10 | 10 | |
1 | case12 | 12 | log.txt |
In [64]:
h2writer = MyInputWriter(base_htc_file='tmp/base.htc',
begin_step=100, # constant need in the implemented functions (specify as many as you want)
)
h2writer.from_pandas(df)
h2writer.write_all(out_dir="tmp")
Generating 2 htc files in directory: tmp
In [65]:
print(HTCFile('tmp/case10.htc'))
begin simulation;
time_stop 600;
end simulation;
;
begin wind;
wsp 10;
wind_ramp_abs 100 101 0 1; wsp. after the step: 11.0
wind_ramp_abs 150 151 0 1; wsp. after the step: 12.0
end wind;
exit;
In [66]:
print(HTCFile('tmp/case12.htc'))
begin simulation;
time_stop 600;
logfile log.txt;
end simulation;
;
begin wind;
wsp 12;
wind_ramp_abs 100 101 0 1; wsp. after the step: 13.0
wind_ramp_abs 150 151 0 1; wsp. after the step: 14.0
end wind;
exit;
Excel¶
Saving previous dataframe as Excel spreadsheet
In [69]:
df.to_excel('tmp/caselist.xlsx', index=False)
which can be opened and modified in Excel
In [70]:
# uncomment to open in excel
# %system "tmp/caselist.xlsx"
Loading case list from (modifyed) excel sheet and write htc files
In [71]:
h2writer.from_excel('tmp/caselist.xlsx')
h2writer.contents
h2writer.write_all('tmp')
Generating 2 htc files in directory: tmp
Design Load Basis (DLB)¶
The DTU_IEC64100_1_Ref_DLB
can make a case list covering a subset of
the full DLB as defined in IEC64100-1(2005).
Note, some DLCs are missing.
Some interpretation are made see Hansen, M. H., Thomsen, K., Natarajan, A., & Barlas, A. (2015). Design Load Basis for onshore turbines - Revision 00. DTU Wind Energy. DTU Wind Energy E, No. 0074(EN)
In [72]:
from wetb.dlb.iec64100_1 import DTU_IEC64100_1_Ref_DLB, DLB, DLC
dlb = DTU_IEC64100_1_Ref_DLB(iec_wt_class='1A', #IEC wind turbine class
Vin=4, # cut-in wind speed
Vout=25, # cut-out wind speed
Vr=8, # rated wind speed
D=180, # Rotor diameter
z_hub=110 # hub height
)
DLB definition¶
You can work with a DLB on an definition level
In [73]:
dlb.dlcs
Out[73]:
Name | Description | WSP | Wdir | Turb | Seeds | Shear | Gust | Fault | Time | |
---|---|---|---|---|---|---|---|---|---|---|
DLC12 | DLC12 | Normal production | Vin:2:Vout | -10/0/10 | NTM | 6.0 | NWP | None | None | 600 |
DLC13 | DLC13 | Normal production with high turbulence | Vin:2:Vout | -10/0/10 | ETM | 6.0 | NWP | None | None | 600 |
DLC14 | DLC14 | Normal production with gust and direction change | Vr/Vr+2/Vr-2 | 0 | NoTurb | NaN | NWP | ECD | None | 100 |
DLC15 | DLC15 | Normal production with extreme wind shear | Vin:2:Vout | 0 | NoTurb | NaN | EWS | None | None | 100 |
DLC21 | DLC21 | Loss of electical network | Vin:2:Vout | -10/0/10 | NTM | 4.0 | NWP | None | GridLoss10 | 100 |
DLC22y | DLC22y | Abnormal yaw error | Vin:2:Vout | 15:15:345 | NTM | 1.0 | NWP | None | None | 600 |
In [74]:
dlb.variables
Out[74]:
Name | Value | Description | |
---|---|---|---|
Vin | Vin | 4 | Cut-in wind speed |
Vout | Vout | 25 | Cut-out wind speed |
Vr | Vr | 8 | Rated wind speed |
D | D | 180 | Rotor diameter |
z_hub | z_hub | 110 | Hub height |
Vstep | Vstep | 2 | Wind speed distribution step |
iec_wt_class | iec_wt_class | 1A | IEC wind turbine class, e.g. 1A |
Edit DLB definition¶
dlb.dlcs
is a Pandas DataFrame that you can edit in python
In [75]:
dlb.dlcs.loc['DLC12','Seeds'] = 1
dlb.dlcs
Out[75]:
Name | Description | WSP | Wdir | Turb | Seeds | Shear | Gust | Fault | Time | |
---|---|---|---|---|---|---|---|---|---|---|
DLC12 | DLC12 | Normal production | Vin:2:Vout | -10/0/10 | NTM | 1.0 | NWP | None | None | 600 |
DLC13 | DLC13 | Normal production with high turbulence | Vin:2:Vout | -10/0/10 | ETM | 6.0 | NWP | None | None | 600 |
DLC14 | DLC14 | Normal production with gust and direction change | Vr/Vr+2/Vr-2 | 0 | NoTurb | NaN | NWP | ECD | None | 100 |
DLC15 | DLC15 | Normal production with extreme wind shear | Vin:2:Vout | 0 | NoTurb | NaN | EWS | None | None | 100 |
DLC21 | DLC21 | Loss of electical network | Vin:2:Vout | -10/0/10 | NTM | 4.0 | NWP | None | GridLoss10 | 100 |
DLC22y | DLC22y | Abnormal yaw error | Vin:2:Vout | 15:15:345 | NTM | 1.0 | NWP | None | None | 600 |
dlb.variables
is a Pandas DataFrame that you can edit in python
In [76]:
dlb.variables.loc['Vin','Value'] = 8
dlb.variables.loc['Vout', 'value']=10
dlb.variables
Out[76]:
Name | Value | Description | value | |
---|---|---|---|---|
Vin | Vin | 8 | Cut-in wind speed | NaN |
Vout | Vout | 25 | Cut-out wind speed | 10.0 |
Vr | Vr | 8 | Rated wind speed | NaN |
D | D | 180 | Rotor diameter | NaN |
z_hub | z_hub | 110 | Hub height | NaN |
Vstep | Vstep | 2 | Wind speed distribution step | NaN |
iec_wt_class | iec_wt_class | 1A | IEC wind turbine class, e.g. 1A | NaN |
Edit DLB definition in Excel¶
You can also save the DLB definition and variables as an Excel workbook
In [78]:
dlb.to_excel('tmp/overview.xlsx')
open, edit and save in Excel
In [7]:
# uncomment to open file in excel
# %system "tmp/overview.xlsx"
and load the modified DLB
In [79]:
dlb = DLB.from_excel('tmp/overview.xlsx')
dlb.dlcs
Out[79]:
Name | Description | WSP | Wdir | Turb | Seeds | Shear | Gust | Fault | Time | |
---|---|---|---|---|---|---|---|---|---|---|
DLC12 | DLC12 | Normal production | Vin:2:Vout | -10/0/10 | NTM | 1.0 | NWP | NaN | NaN | 600 |
DLC13 | DLC13 | Normal production with high turbulence | Vin:2:Vout | -10/0/10 | ETM | 6.0 | NWP | NaN | NaN | 600 |
DLC14 | DLC14 | Normal production with gust and direction change | Vr/Vr+2/Vr-2 | 0 | NoTurb | NaN | NWP | ECD | NaN | 100 |
DLC15 | DLC15 | Normal production with extreme wind shear | Vin:2:Vout | 0 | NoTurb | NaN | EWS | NaN | NaN | 100 |
DLC21 | DLC21 | Loss of electical network | Vin:2:Vout | -10/0/10 | NTM | 4.0 | NWP | NaN | GridLoss10 | 100 |
DLC22y | DLC22y | Abnormal yaw error | Vin:2:Vout | 15:15:345 | NTM | 1.0 | NWP | NaN | NaN | 600 |
DLC cases¶
You can generate a Pandas DataFrame with all cases of all DLCs
In [80]:
dlb.to_pandas()
Out[80]:
DLC | Name | Folder | V_hub | wdir | simulation_time | ti | seed | shear | Gust | Fault | |
---|---|---|---|---|---|---|---|---|---|---|---|
0 | DLC12 | DLC12_wsp08_wdir350_s1001 | DLC12 | 8.0 | -10.0 | 600 | 0.232000 | 1001 | {'type': 'NWP', 'profile': ('power', 0.2)} | NaN | NaN |
1 | DLC12 | DLC12_wsp08_wdir000_s1001 | DLC12 | 8.0 | 0.0 | 600 | 0.232000 | 1001 | {'type': 'NWP', 'profile': ('power', 0.2)} | NaN | NaN |
2 | DLC12 | DLC12_wsp08_wdir010_s1001 | DLC12 | 8.0 | 10.0 | 600 | 0.232000 | 1001 | {'type': 'NWP', 'profile': ('power', 0.2)} | NaN | NaN |
3 | DLC12 | DLC12_wsp10_wdir350_s1101 | DLC12 | 10.0 | -10.0 | 600 | 0.209600 | 1101 | {'type': 'NWP', 'profile': ('power', 0.2)} | NaN | NaN |
4 | DLC12 | DLC12_wsp10_wdir000_s1101 | DLC12 | 10.0 | 0.0 | 600 | 0.209600 | 1101 | {'type': 'NWP', 'profile': ('power', 0.2)} | NaN | NaN |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
225 | DLC22y | DLC22y_wsp26_wdir285_s1901 | DLC22y | 26.0 | 285.0 | 600 | 0.154462 | 1901 | {'type': 'NWP', 'profile': ('power', 0.2)} | NaN | NaN |
226 | DLC22y | DLC22y_wsp26_wdir300_s1901 | DLC22y | 26.0 | 300.0 | 600 | 0.154462 | 1901 | {'type': 'NWP', 'profile': ('power', 0.2)} | NaN | NaN |
227 | DLC22y | DLC22y_wsp26_wdir315_s1901 | DLC22y | 26.0 | 315.0 | 600 | 0.154462 | 1901 | {'type': 'NWP', 'profile': ('power', 0.2)} | NaN | NaN |
228 | DLC22y | DLC22y_wsp26_wdir330_s1901 | DLC22y | 26.0 | 330.0 | 600 | 0.154462 | 1901 | {'type': 'NWP', 'profile': ('power', 0.2)} | NaN | NaN |
229 | DLC22y | DLC22y_wsp26_wdir345_s1901 | DLC22y | 26.0 | 345.0 | 600 | 0.154462 | 1901 | {'type': 'NWP', 'profile': ('power', 0.2)} | NaN | NaN |
603 rows × 11 columns
or the cases of a single DLC
In [81]:
dlb['DLC14']
Out[81]:
DLC | Name | Folder | V_hub | wdir | simulation_time | seed | shear | Gust | |
---|---|---|---|---|---|---|---|---|---|
0 | DLC14 | DLC14_wsp06_wdir000 | DLC14 | 6.0 | 0.0 | 100 | None | {'type': 'NWP', 'profile': ('power', 0.2)} | {'type': 'ECD', 'V_cg': 15, 'theta_cg': 120.0,... |
1 | DLC14 | DLC14_wsp08_wdir000 | DLC14 | 8.0 | 0.0 | 100 | None | {'type': 'NWP', 'profile': ('power', 0.2)} | {'type': 'ECD', 'V_cg': 15, 'theta_cg': 90.0, ... |
2 | DLC14 | DLC14_wsp10_wdir000 | DLC14 | 10.0 | 0.0 | 100 | None | {'type': 'NWP', 'profile': ('power', 0.2)} | {'type': 'ECD', 'V_cg': 15, 'theta_cg': 72.0, ... |
Edit DLC cases¶
The dlc cases returned by dlb.dlcs[<dlc>]
is a Pandas DataFrame that
you can edit in python
!!! Note, editing dlc cases will not influence the DLB
In [82]:
dlc14_ed = dlb['DLC14']
dlc14_ed.loc[0,'V_hub'] = 4
dlc14_ed
Out[82]:
DLC | Name | Folder | V_hub | wdir | simulation_time | seed | shear | Gust | |
---|---|---|---|---|---|---|---|---|---|
0 | DLC14 | DLC14_wsp06_wdir000 | DLC14 | 4.0 | 0.0 | 100 | None | {'type': 'NWP', 'profile': ('power', 0.2)} | {'type': 'ECD', 'V_cg': 15, 'theta_cg': 120.0,... |
1 | DLC14 | DLC14_wsp08_wdir000 | DLC14 | 8.0 | 0.0 | 100 | None | {'type': 'NWP', 'profile': ('power', 0.2)} | {'type': 'ECD', 'V_cg': 15, 'theta_cg': 90.0, ... |
2 | DLC14 | DLC14_wsp10_wdir000 | DLC14 | 10.0 | 0.0 | 100 | None | {'type': 'NWP', 'profile': ('power', 0.2)} | {'type': 'ECD', 'V_cg': 15, 'theta_cg': 72.0, ... |
Edit DLC cases in Excel¶
You can also save the DLC case list as an Excel spreadsheet
In [83]:
dlc14_ed.to_excel('tmp/dlc14_ed.xlsx')
and open and edit the cases in Excel
In [84]:
# uncomment to open file in excel
# %system "tmp/dlc14_ed.xlsx"
The modified cases can be loaded by the input writer, see below
Write DLB/DLC cases as HAWC2 input files¶
Load into HAWC2_IEC_DLC_Writer¶
To write the HTC files correponding to the DLB cases, you need the
HAWC2_IEC_DLC_Writer
and a base htc file
In [85]:
from wetb.hawc2.tests.test_files import tfp
from wetb.dlb.hawc2_iec_dlc_writer import HAWC2_IEC_DLC_Writer
path = tfp + '/simulation_setup/DTU10MWRef6.0/'
writer = HAWC2_IEC_DLC_Writer(path + 'htc/DTU_10MW_RWT.htc', diameter=180)
Load all cases into the writer
In [86]:
writer.from_pandas(dlb)
writer.contents
Out[86]:
DLC | Name | Folder | V_hub | wdir | simulation_time | ti | seed | shear | Gust | Fault | |
---|---|---|---|---|---|---|---|---|---|---|---|
0 | DLC12 | DLC12_wsp08_wdir350_s1001 | DLC12 | 8.0 | -10.0 | 600 | 0.232000 | 1001 | {'type': 'NWP', 'profile': ('power', 0.2)} | NaN | NaN |
1 | DLC12 | DLC12_wsp08_wdir000_s1001 | DLC12 | 8.0 | 0.0 | 600 | 0.232000 | 1001 | {'type': 'NWP', 'profile': ('power', 0.2)} | NaN | NaN |
2 | DLC12 | DLC12_wsp08_wdir010_s1001 | DLC12 | 8.0 | 10.0 | 600 | 0.232000 | 1001 | {'type': 'NWP', 'profile': ('power', 0.2)} | NaN | NaN |
3 | DLC12 | DLC12_wsp10_wdir350_s1101 | DLC12 | 10.0 | -10.0 | 600 | 0.209600 | 1101 | {'type': 'NWP', 'profile': ('power', 0.2)} | NaN | NaN |
4 | DLC12 | DLC12_wsp10_wdir000_s1101 | DLC12 | 10.0 | 0.0 | 600 | 0.209600 | 1101 | {'type': 'NWP', 'profile': ('power', 0.2)} | NaN | NaN |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
225 | DLC22y | DLC22y_wsp26_wdir285_s1901 | DLC22y | 26.0 | 285.0 | 600 | 0.154462 | 1901 | {'type': 'NWP', 'profile': ('power', 0.2)} | NaN | NaN |
226 | DLC22y | DLC22y_wsp26_wdir300_s1901 | DLC22y | 26.0 | 300.0 | 600 | 0.154462 | 1901 | {'type': 'NWP', 'profile': ('power', 0.2)} | NaN | NaN |
227 | DLC22y | DLC22y_wsp26_wdir315_s1901 | DLC22y | 26.0 | 315.0 | 600 | 0.154462 | 1901 | {'type': 'NWP', 'profile': ('power', 0.2)} | NaN | NaN |
228 | DLC22y | DLC22y_wsp26_wdir330_s1901 | DLC22y | 26.0 | 330.0 | 600 | 0.154462 | 1901 | {'type': 'NWP', 'profile': ('power', 0.2)} | NaN | NaN |
229 | DLC22y | DLC22y_wsp26_wdir345_s1901 | DLC22y | 26.0 | 345.0 | 600 | 0.154462 | 1901 | {'type': 'NWP', 'profile': ('power', 0.2)} | NaN | NaN |
603 rows × 11 columns
Load a single DLC
In [87]:
writer.from_pandas(dlb['DLC14'])
writer.contents
Out[87]:
DLC | Name | Folder | V_hub | wdir | simulation_time | seed | shear | Gust | |
---|---|---|---|---|---|---|---|---|---|
0 | DLC14 | DLC14_wsp06_wdir000 | DLC14 | 6.0 | 0.0 | 100 | None | {'type': 'NWP', 'profile': ('power', 0.2)} | {'type': 'ECD', 'V_cg': 15, 'theta_cg': 120.0,... |
1 | DLC14 | DLC14_wsp08_wdir000 | DLC14 | 8.0 | 0.0 | 100 | None | {'type': 'NWP', 'profile': ('power', 0.2)} | {'type': 'ECD', 'V_cg': 15, 'theta_cg': 90.0, ... |
2 | DLC14 | DLC14_wsp10_wdir000 | DLC14 | 10.0 | 0.0 | 100 | None | {'type': 'NWP', 'profile': ('power', 0.2)} | {'type': 'ECD', 'V_cg': 15, 'theta_cg': 72.0, ... |
Load the modified DLC
In [88]:
writer.from_pandas(dlc14_ed)
writer.contents
Out[88]:
DLC | Name | Folder | V_hub | wdir | simulation_time | seed | shear | Gust | |
---|---|---|---|---|---|---|---|---|---|
0 | DLC14 | DLC14_wsp06_wdir000 | DLC14 | 4.0 | 0.0 | 100 | None | {'type': 'NWP', 'profile': ('power', 0.2)} | {'type': 'ECD', 'V_cg': 15, 'theta_cg': 120.0,... |
1 | DLC14 | DLC14_wsp08_wdir000 | DLC14 | 8.0 | 0.0 | 100 | None | {'type': 'NWP', 'profile': ('power', 0.2)} | {'type': 'ECD', 'V_cg': 15, 'theta_cg': 90.0, ... |
2 | DLC14 | DLC14_wsp10_wdir000 | DLC14 | 10.0 | 0.0 | 100 | None | {'type': 'NWP', 'profile': ('power', 0.2)} | {'type': 'ECD', 'V_cg': 15, 'theta_cg': 72.0, ... |
Load the DLC from the (modified) excel file
In [89]:
writer.from_excel('tmp/dlc14_ed.xlsx')
writer.contents
Out[89]:
DLC | Name | Folder | V_hub | wdir | simulation_time | seed | shear | Gust | |
---|---|---|---|---|---|---|---|---|---|
0 | DLC14 | DLC14_wsp06_wdir000 | DLC14 | 4 | 0 | 100 | {'type': 'NWP', 'profile': ('power', 0.2)} | {'type': 'ECD', 'V_cg': 15, 'theta_cg': 120.0,... | |
1 | DLC14 | DLC14_wsp08_wdir000 | DLC14 | 8 | 0 | 100 | {'type': 'NWP', 'profile': ('power', 0.2)} | {'type': 'ECD', 'V_cg': 15, 'theta_cg': 90.0, ... | |
2 | DLC14 | DLC14_wsp10_wdir000 | DLC14 | 10 | 0 | 100 | {'type': 'NWP', 'profile': ('power', 0.2)} | {'type': 'ECD', 'V_cg': 15, 'theta_cg': 72.0, ... |
Write files¶
In [90]:
writer.write_all(out_dir='tmp')
Generating 3 htc files in directory: tmp
In [91]:
%ls "tmp/DLC14"
Volume in drive C is Windows
Volume Serial Number is 1AB2-743B
Directory of c:\mmpe\programming\python\WindEnergyToolbox\notebooks\hawc2\tmp\DLC14
29-04-2020 14:56 <DIR> .
29-04-2020 14:56 <DIR> ..
29-04-2020 14:56 28,439 DLC14_wsp06_wdir000.htc
29-04-2020 14:56 28,438 DLC14_wsp08_wdir000.htc
29-04-2020 14:56 28,439 DLC14_wsp10_wdir000.htc
3 File(s) 85,316 bytes
2 Dir(s) 56,159,342,592 bytes free