Newer
Older
df_stats1=None, df_stats2=None,
iplot_legend=0, legloc='best'):
"""
Compare blade distribution aerodynamics of two HAWC2 cases.
"""
tors1 = fname_1.split('_aero_at_tstop')[0]
res1 = self.load_h2(fname_1, h2_df_stats=df_stats1, fname_h2_tors=tors1)
tors2 = fname_2.split('_aero_at_tstop')[0]
res2 = self.load_h2(fname_2, h2_df_stats=df_stats2, fname_h2_tors=tors2)
results = [res1.h2_aero[n0+1:], res2.h2_aero[n0+1:]]
fig, axes = self.distribution(results, labels, title, self.dist_channels,
x_ax='pos_z', xlabel='Z-coordinate [m]',

David Verelst
committed
nrows=self.dist_nrows,
ncols=self.dist_ncols,
size=self.dist_size,
iplot_legend=iplot_legend, legloc=legloc)
def hs_blade_distribution(self, fname_1, fname_2, title, labels, n0=0,
iplot_legend=0, legloc='best'):
res1 = self.load_hs(fname_1)
res2 = self.load_hs(fname_2)
results = [res1.hs_aero[n0:], res2.hs_aero[n0:]]
# channels = ['pos_x', 'pos_y', 'AoA', 'inflow_angle', 'Cl', 'Cd',
# 'vrel', 'ax_ind_vel']
fig, axes = self.distribution(results, labels, title, self.dist_channels,
x_ax='pos_z', xlabel='Z-coordinate [m]',

David Verelst
committed
nrows=self.dist_nrows,
ncols=self.dist_ncols,
size=self.dist_size,
iplot_legend=iplot_legend, legloc=legloc)
return fig, axes
def blade_distribution(self, fname_h2, fname_hs2, title, n0=0,
h2_df_stats=None, fname_h2_tors=None,
iplot_legend=0, legloc='best'):
"""Compare aerodynamics, blade deflections between HAWC2 and HAWCStab2.
This is based on HAWCSTab2 *.ind files, and an HAWC2 output_at_time
output file.

David Verelst
committed
Parameters
----------
fname_h2
fname_hs2
title
n0 : int, default=0
Number of nodes to ignore at the blade root section

David Verelst
committed
results = MappingsH2HS2(self.config)
results.blade_distribution(fname_h2, fname_hs2, h2_df_stats=h2_df_stats,
fname_h2_tors=fname_h2_tors)

David Verelst
committed
self.units = results.units
res = [results.h2_aero[n0+1:-1], results.hs_aero[n0:]]
# channels = ['pos_x', 'pos_y', 'AoA', 'inflow_angle', 'Cl', 'Cd',
# 'vrel', 'ax_ind_vel']
labels = ['HAWC2', 'HAWCStab2']
fig, axes = self.distribution(res, labels, title, self.dist_channels,
x_ax='pos_z', xlabel='Z-coordinate [m]',

David Verelst
committed
nrows=self.dist_nrows,
ncols=self.dist_ncols,
size=self.dist_size,
iplot_legend=iplot_legend, legloc=legloc)
def blade_distribution2(self, fname_h2, fname_hs2, title, n0=0,
iplot_legend=0, legloc='best'):
"""Compare aerodynamics, blade deflections between HAWC2 and HAWCStab2.
This is based on HAWCSTab2 *.ind files, and an HAWC2 output_at_time
output file.
"""

David Verelst
committed
results = MappingsH2HS2(self.config)
results.blade_distribution(fname_h2, fname_hs2)
res = [results.h2_aero[n0+1:-1], results.hs_aero[n0:]]
channels = ['pos_x', 'pos_y', 'torsion', 'inflow_angle',
'Cl', 'Cd', 'vrel', 'AoA',
'F_x', 'F_y', 'M', 'ax_ind_vel', 'torsion']
labels = ['HAWC2', 'HAWCStab2']
fig, axes = self.distribution(res, labels, title, channels,
x_ax='pos_z', xlabel='Z-coordinate [m]',
nrows=3, ncols=4, size=(16, 12),
iplot_legend=iplot_legend, legloc=legloc)
return fig, axes
def powercurve(self, h2_df_stats, fname_hs, title, size=(8.6, 4)):

David Verelst
committed
results = MappingsH2HS2(self.config)
results.powercurve(h2_df_stats, fname_hs)
fig, axes = self.new_fig(title=title, nrows=1, ncols=2, size=size)
wind_h2 = results.pwr_h2_mean['windspeed'].values
wind_hs = results.pwr_hs['windspeed'].values

David Verelst
committed
# POWER ---------------------------------------------------------------
ax.set_ylabel('Power [kW]')
ax.set_xlabel('Wind speed [m/s]')

David Verelst
committed
keys = ['P_aero', 'P_mech']
lss = [self.h2ls, '--', ':']
# HAWC2
for key, ls in zip(keys, lss):
# it is possible the mechanical power has not been calculated
if key not in results.pwr_h2_mean:
continue
label = 'HAWC2 %s' % (key.replace('_', '$_{') + '}$')
yerr = results.pwr_h2_std[key].values
c = self.h2c
ax.errorbar(wind_h2, results.pwr_h2_mean[key].values, color=c, ls=ls,
label=label, alpha=0.9, yerr=yerr, marker=self.h2ms)

David Verelst
committed
key = 'P_aero'
ax.plot(wind_hs, results.pwr_hs[key].values, label='HAWCStab2',
alpha=0.7, color=self.hsc, ls=self.hsls, marker=self.hsms)

David Verelst
committed
# errors on the right axes
axr = ax.twinx()
assert np.allclose(wind_h2, wind_hs)
qq1 = results.pwr_h2_mean[key].values
qq2 = results.pwr_hs[key].values

David Verelst
committed
err = qq1 - qq2
axr.plot(wind_hs, err, color=self.errc, ls=self.errls, alpha=0.6,

David Verelst
committed
label=self.errlab + ' P$_{aero}$')
ax.set_xlim([wind_h2.min(), wind_h2.max()])

David Verelst
committed
# legends
lines, labels = ax.get_legend_handles_labels()
linesr, labelsr = axr.get_legend_handles_labels()
leg = axr.legend(lines + linesr, labels + labelsr, loc='lower right')
leg.get_frame().set_alpha(0.5)
# THRUST --------------------------------------------------------------
ax.set_ylabel('Thrust [kN]')
ax.set_xlabel('Wind speed [m/s]')
keys = ['T_aero', 'T_shafttip']
lss = [self.h2ls, '--', ':']
# HAWC2
for key, ls in zip(keys, lss):
label = 'HAWC2 %s' % (key.replace('_', '$_{') + '}$')

David Verelst
committed
yerr = results.pwr_h2_std[key].values

David Verelst
committed
ax.errorbar(wind_h2, results.pwr_h2_mean[key].values, color=c, ls=ls,
label=label, alpha=0.9, yerr=yerr, marker=self.h2ms)
# HAWCStab2

David Verelst
committed
ax.plot(wind_hs, results.pwr_hs['T_aero'].values, color=self.hsc, alpha=0.7,
label='HAWCStab2 T$_{aero}$', marker=self.hsms, ls=self.hsls)

David Verelst
committed
# errors on the right axes
axr = ax.twinx()
qq1 = results.pwr_h2_mean['T_aero'].values
qq2 = results.pwr_hs['T_aero'].values

David Verelst
committed
err = qq1 - qq2
axr.plot(wind_hs, err, color=self.errc, ls=self.errls, alpha=0.6,

David Verelst
committed
label=self.errlab + ' T$_{aero}$')
ax.set_xlim([wind_h2.min(), wind_h2.max()])
ax.set_xlabel('Wind speed [m/s]')

David Verelst
committed
# legends
lines, labels = ax.get_legend_handles_labels()
linesr, labelsr = axr.get_legend_handles_labels()
leg = axr.legend(lines + linesr, labels + labelsr, loc='lower right')
leg.get_frame().set_alpha(0.5)
axes = self.set_axes_label_grid(axes, setlegend=False)
return fig, axes
def h2_powercurve(self, h2_df_stats1, h2_df_stats2, title, labels,
size=(8.6,4)):

David Verelst
committed
res1 = MappingsH2HS2(self.config)
res1._powercurve_h2(h2_df_stats1)
wind1 = res1.pwr_h2_mean['windspeed'].values

David Verelst
committed
res2 = MappingsH2HS2(self.config)
res2._powercurve_h2(h2_df_stats2)
wind2 = res2.pwr_h2_mean['windspeed'].values
fig, axes = self.new_fig(title=title, nrows=1, ncols=2, size=size)
# POWER
ax = axes[0]
key = 'P_aero'
# HAWC2

David Verelst
committed
yerr1 = res1.pwr_h2_std[key].values
ax.errorbar(wind1, res1.pwr_h2_mean[key].values, color=self.h2c, yerr=yerr1,
marker=self.h2ms, ls=self.h2ls, label=labels[0], alpha=0.9)
yerr2 = res2.pwr_h2_std[key]

David Verelst
committed
ax.errorbar(wind2, res2.pwr_h2_mean[key].values, color=self.hsc, yerr=yerr2,
marker=self.hsms, ls=self.hsls, label=labels[1], alpha=0.7)
ax.set_ylabel('Power [kW]')
ax.set_xlabel('Wind speed [m/s]')
# relative errors on the right axes
axr = ax.twinx()
assert np.allclose(wind1, wind2)
qq1 = res1.pwr_h2_mean[key].values
qq2 = res2.pwr_h2_mean[key].values
err = np.abs(1.0 - qq1 / qq2)*100.0
axr.plot(wind1, err, color=self.errc, ls=self.errls, alpha=0.6,
label=self.errlab)
# THRUST
ax = axes[1]
keys = ['T_aero', 'T_shafttip']
lss = [self.h2ls, '--', ':']
for key, ls in zip(keys, lss):
label = '%s %s' % (labels[0], key.replace('_', '$_{') + '}$')

David Verelst
committed
yerr = res1.pwr_h2_std[key].values

David Verelst
committed
ax.errorbar(wind1, res1.pwr_h2_mean[key].values, color=c, ls=ls,
label=label, alpha=0.9, yerr=yerr, marker=self.h2ms)
for key, ls in zip(keys, lss):
label = '%s %s' % (labels[1], key.replace('_', '$_{') + '}$')

David Verelst
committed
yerr = res2.pwr_h2_std[key].values

David Verelst
committed
ax.errorbar(wind2, res2.pwr_h2_mean[key].values, color=c, ls=ls,
label=label, alpha=0.9, yerr=yerr, marker=self.hsms)
# relative errors on the right axes
axr = ax.twinx()
qq1 = res1.pwr_h2_mean['T_aero'].values
qq2 = res2.pwr_h2_mean['T_aero'].values
err = np.abs(1.0 - (qq1 / qq2))*100.0
axr.plot(wind1, err, color=self.errc, ls=self.errls, alpha=0.6,
label=self.errlab)
ax.set_ylabel('Thrust [kN]')
ax.set_xlabel('Wind speed [m/s]')
axes = self.set_axes_label_grid(axes, setlegend=True)
# # use axr for the legend
# lines = ax.lines + axr.lines
# labels = [l.get_label() for l in lines]
# leg = axr.legend(lines, labels, loc='best')
# leg.get_frame().set_alpha(0.5)
return fig, axes
def hs_powercurve(self, fname1, fname2, title, labels, size=(8.6, 4)):

David Verelst
committed
res1 = MappingsH2HS2(self.config)
res1._powercurve_hs2(fname1)
wind1 = res1.pwr_hs['windspeed'].values

David Verelst
committed
res2 = MappingsH2HS2(self.config)
res2._powercurve_hs2(fname2)
wind2 = res2.pwr_hs['windspeed'].values
fig, axes = self.new_fig(title=title, nrows=1, ncols=2, size=size)
# POWER
ax = axes[0]
key = 'P_aero'

David Verelst
committed
ax.plot(wind1, res1.pwr_hs['P_aero'].values, label=labels[0],
alpha=0.9, color=self.h2c, ls=self.h2ls, marker=self.h2ms)

David Verelst
committed
ax.plot(wind2, res2.pwr_hs['P_aero'].values, label=labels[1],
alpha=0.7, color=self.hsc, ls=self.hsls, marker=self.hsms)
ax.set_ylabel('Power [kW]')
ax.set_xlabel('Wind speed [m/s]')
# relative errors on the right axes
axr = ax.twinx()
assert np.allclose(wind1, wind2)
qq1 = res1.pwr_hs[key].values
qq2 = res2.pwr_hs[key].values
err = np.abs(1.0 - qq1 / qq2)*100.0
axr.plot(wind1, err, color=self.errc, ls=self.errls, alpha=0.6,
label=self.errlab)
# axr.set_ylim([])
# THRUST
ax = axes[1]

David Verelst
committed
ax.plot(wind1, res1.pwr_hs['T_aero'].values, color=self.h2c, alpha=0.9,
label=labels[0], marker=self.h2ms, ls=self.h2ls)

David Verelst
committed
ax.plot(wind2, res2.pwr_hs['T_aero'].values, color=self.hsc, alpha=0.7,
label=labels[1], marker=self.hsms, ls=self.hsls)
# relative errors on the right axes
axr = ax.twinx()
qq1 = res1.pwr_hs['T_aero'].values
qq2 = res2.pwr_hs['T_aero'].values
err = np.abs(1.0 - (qq1 / qq2))*100.0
axr.plot(wind1, err, color=self.errc, ls=self.errls, alpha=0.6,
label=self.errlab)
ax.set_ylabel('Thrust [kN]')
ax.set_xlabel('Wind speed [m/s]')
axes = self.set_axes_label_grid(axes, setlegend=True)
# # use axr for the legend
# lines = ax.lines + axr.lines
# labels = [l.get_label() for l in lines]
# leg = axr.legend(lines, labels, loc='best')
# leg.get_frame().set_alpha(0.5)
return fig, axes
if __name__ == '__main__':
dummy = None