Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 52ce7e6

Browse files
committed
Converters: update of hawc2ToBeamDyn (template optional, interp with pandalib and curvilinear interp optional)"
1 parent 7fa23ef commit 52ce7e6

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

pyFAST/converters/examples/Main_Hawc2ToBeamDyn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def main():
3131
BDMainTemplate = os.path.join(MyDir,'../../../data/templates/BeamDyn.dat') # readonly, template file to write main BD file
3232
BD_mainfile = '_NREL5MW_BeamDyn_Created.dat' # Name of BeamDyn file to be writen
3333
BD_bladefile = '_NREL5MW_BeamDyn_Blade_Created.dat' # Name of BeamDyn blade file to be written
34-
fig = bd.htcToBeamDyn(H2_htcfile, 'blade1', BD_bladefile, BD_mainfile, BDMainTemplate, Mu=Mu, poly_exp=[2,3,4,5,6], ref_axis='c2def', bPlot=True)
34+
fig = bd.htcToBeamDyn(H2_htcfile, 'blade1', BD_bladefile, BD_mainfile, BDMainTemplate, Mu=Mu, poly_exp=[2,3,4,5,6], ref_axis='c2def', bPlot=True, interpCurvilinear=False)
3535

3636
return BD_mainfile, BD_bladefile
3737

pyFAST/converters/hawc2ToBeamDyn.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import os
55
from pyFAST.input_output.hawc2_htc_file import HAWC2HTCFile
66
from pyFAST.input_output.csv_file import CSVFile
7-
from pyFAST.input_output.fast_input_file import FASTInputFile
7+
from pyFAST.input_output.fast_input_file import FASTInputFile, BDFile
8+
9+
from pyFAST.tools.pandalib import pd_interp1
810

911

1012
from .beam import *
@@ -78,7 +80,7 @@ def mypolyfit(x,y,exponents=[0,1,2,3]):
7880

7981
def htcToBeamDyn(HTCFile, bodyname, BDBldFileOut, BDMainFileOut=None, BDMainTemplate=None, Mu = 1.0e-03,
8082
ref_axis='c2def-polyfit', poly_exp=[2,3,4,5], zref=None, Label='', bPlot=False,
81-
bNoOffset=False, bNoPreSweep=False, nRootZeros=0, bCGOnMeanLine=False): # Experimental options
83+
bNoOffset=False, bNoPreSweep=False, nRootZeros=0, bCGOnMeanLine=False, interpCurvilinear=True): # Experimental options
8284
"""
8385
Writes BeamDyn inputs files from a HAWC2 htc file and the blade body name
8486
INPUTS:
@@ -92,14 +94,17 @@ def htcToBeamDyn(HTCFile, bodyname, BDBldFileOut, BDMainFileOut=None, BDMainTemp
9294
H2MeanLine = dfs[bodyname+'_c2']
9395
H2Structure = dfs[bodyname+'_st']
9496
H2MeanLine = H2MeanLine[['x_[m]','y_[m]','z_[m]','twist_[deg]']] # Changing order
97+
if len(Label)==0:
98+
Label='Converted by hawc2ToBeamDyn.py from {}'.format(HTCFile)
99+
95100

96101
return hawc2ToBeamDyn(H2MeanLine, H2Structure, BDBldFileOut, BDMainFileOut=BDMainFileOut, BDMainTemplate=BDMainTemplate, Mu=Mu,
97102
ref_axis=ref_axis, poly_exp=poly_exp, zref=zref, Label=Label, bPlot=bPlot,
98-
bNoOffset=bNoOffset, bNoPreSweep=bNoPreSweep, nRootZeros=nRootZeros, bCGOnMeanLine=bCGOnMeanLine)
103+
bNoOffset=bNoOffset, bNoPreSweep=bNoPreSweep, nRootZeros=nRootZeros, bCGOnMeanLine=bCGOnMeanLine, interpCurvilinear=interpCurvilinear)
99104

100105
def hawc2ToBeamDyn(H2MeanLine, H2Structure, BDBldFileOut, BDMainFileOut=None, BDMainTemplate=None, Mu = 1.0e-03,
101106
ref_axis='c2def-polyfit', poly_exp=[2,3,4,5], zref=None, Label='', bPlot=False,
102-
bNoOffset=False, bNoPreSweep=False, nRootZeros=0, bCGOnMeanLine=False): # Experimental options
107+
bNoOffset=False, bNoPreSweep=False, nRootZeros=0, bCGOnMeanLine=False, interpCurvilinear=True): # Experimental options
103108
"""
104109
Writes BeamDyn inputs files from two csv files derived from "Hawc2" inputs
105110
@@ -164,8 +169,11 @@ def hawc2ToBeamDyn(H2MeanLine, H2Structure, BDBldFileOut, BDMainFileOut=None, BD
164169
twist = - c2def['twist_[deg]'].values # initial_twist [deg] Hawc2 angle is positive around z, unlike the "twist"
165170

166171
# --- Compute r_ref, curvilinear position of keypoints (for st file)
167-
dr= np.sqrt((x_O_h2[1:]-x_O_h2[0:-1])**2 +(y_O_h2[1:]-y_O_h2[0:-1])**2 +(z_O_h2[1:]-z_O_h2[0:-1])**2)
168-
r_ref = np.concatenate(([0],np.cumsum(dr)))
172+
if interpCurvilinear:
173+
dr= np.sqrt((x_O_h2[1:]-x_O_h2[0:-1])**2 +(y_O_h2[1:]-y_O_h2[0:-1])**2 +(z_O_h2[1:]-z_O_h2[0:-1])**2)
174+
r_ref = np.concatenate(([0],np.cumsum(dr)))
175+
else:
176+
r_ref = np.abs(z_O_h2)
169177

170178

171179
# --- BeamDyn ref axis
@@ -220,13 +228,10 @@ def hawc2ToBeamDyn(H2MeanLine, H2Structure, BDBldFileOut, BDMainFileOut=None, BD
220228
# For the equations below to be generic we force the column names
221229
hwc_in.columns=['r_[m]','m_[kg/m]','x_cg_[m]','y_cg_[m]','ri_x_[m]','ri_y_[m]','x_sh_[m]','y_sh_[m]','E_[N/m^2]','G_[N/m^2]','I_x_[m^4]','I_y_[m^4]','I_p_[m^4]','k_x_[-]','k_y_[-]','A_[m^2]','pitch_[deg]','x_e_[m]','y_e_[m]']
222230
# --- Interpolating to match c2def positions
223-
hwc = pd.DataFrame(columns=hwc_in.columns)
224-
r_old = hwc_in['r_[m]'].values
225-
for c in hwc.columns:
226-
hwc[c] = np.interp(r_ref, r_old, hwc_in[c])
227-
if r_old[-1]<r_ref[-1]:
228-
# NOTE: interp won't do extrap , small hack here...
229-
hwc['r_[m]'].values[-1] = r_ref[-1]
231+
hwc = pd_interp1(r_ref, 'r_[m]', hwc_in)
232+
#if r_old[-1]<r_ref[-1]:
233+
# # NOTE: interp won't do extrap , small hack here...
234+
# hwc['r_[m]'].values[-1] = r_ref[-1]
230235

231236
# --- Safety check
232237
if len(hwc)!=len(c2def):
@@ -295,12 +300,14 @@ def hawc2ToBeamDyn(H2MeanLine, H2Structure, BDBldFileOut, BDMainFileOut=None, BD
295300
#np.savetxt(BDBldFileOut.replace('.dat','offsets.txt'), M, delimiter=',',header='z_[m], xoff_[m], yoff_[m]')
296301

297302
# --- Writing BeamDyn main file based on template file
298-
if BDMainTemplate is not None and BDMainFileOut is not None:
299-
BD=FASTInputFile(BDMainTemplate)
303+
if BDMainFileOut is not None:
304+
if BDMainTemplate is not None:
305+
BD=FASTInputFile(BDMainTemplate)
306+
else:
307+
BD=BDFile(BDMainTemplate)
300308
#print(BD.keys())
301309
BD.data[1]['value']=Label
302310
BD['MemberGeom'] = np.column_stack((x_O,y_O,z_O,twist))
303-
BD['kp_total'] = len(x_O)
304311
BD['BldFile'] = '"'+os.path.basename(BDBldFileOut)+'"'
305312
BD.data[BD.getID('kp_total')+1]['value']= '1 {}'.format(len(x_O))
306313

0 commit comments

Comments
 (0)