4
4
import os
5
5
from pyFAST .input_output .hawc2_htc_file import HAWC2HTCFile
6
6
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
8
10
9
11
10
12
from .beam import *
@@ -78,7 +80,7 @@ def mypolyfit(x,y,exponents=[0,1,2,3]):
78
80
79
81
def htcToBeamDyn (HTCFile , bodyname , BDBldFileOut , BDMainFileOut = None , BDMainTemplate = None , Mu = 1.0e-03 ,
80
82
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
82
84
"""
83
85
Writes BeamDyn inputs files from a HAWC2 htc file and the blade body name
84
86
INPUTS:
@@ -92,14 +94,17 @@ def htcToBeamDyn(HTCFile, bodyname, BDBldFileOut, BDMainFileOut=None, BDMainTemp
92
94
H2MeanLine = dfs [bodyname + '_c2' ]
93
95
H2Structure = dfs [bodyname + '_st' ]
94
96
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
+
95
100
96
101
return hawc2ToBeamDyn (H2MeanLine , H2Structure , BDBldFileOut , BDMainFileOut = BDMainFileOut , BDMainTemplate = BDMainTemplate , Mu = Mu ,
97
102
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 )
99
104
100
105
def hawc2ToBeamDyn (H2MeanLine , H2Structure , BDBldFileOut , BDMainFileOut = None , BDMainTemplate = None , Mu = 1.0e-03 ,
101
106
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
103
108
"""
104
109
Writes BeamDyn inputs files from two csv files derived from "Hawc2" inputs
105
110
@@ -164,8 +169,11 @@ def hawc2ToBeamDyn(H2MeanLine, H2Structure, BDBldFileOut, BDMainFileOut=None, BD
164
169
twist = - c2def ['twist_[deg]' ].values # initial_twist [deg] Hawc2 angle is positive around z, unlike the "twist"
165
170
166
171
# --- 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 )
169
177
170
178
171
179
# --- BeamDyn ref axis
@@ -220,13 +228,10 @@ def hawc2ToBeamDyn(H2MeanLine, H2Structure, BDBldFileOut, BDMainFileOut=None, BD
220
228
# For the equations below to be generic we force the column names
221
229
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]' ]
222
230
# --- 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]
230
235
231
236
# --- Safety check
232
237
if len (hwc )!= len (c2def ):
@@ -295,12 +300,14 @@ def hawc2ToBeamDyn(H2MeanLine, H2Structure, BDBldFileOut, BDMainFileOut=None, BD
295
300
#np.savetxt(BDBldFileOut.replace('.dat','offsets.txt'), M, delimiter=',',header='z_[m], xoff_[m], yoff_[m]')
296
301
297
302
# --- 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 )
300
308
#print(BD.keys())
301
309
BD .data [1 ]['value' ]= Label
302
310
BD ['MemberGeom' ] = np .column_stack ((x_O ,y_O ,z_O ,twist ))
303
- BD ['kp_total' ] = len (x_O )
304
311
BD ['BldFile' ] = '"' + os .path .basename (BDBldFileOut )+ '"'
305
312
BD .data [BD .getID ('kp_total' )+ 1 ]['value' ]= '1 {}' .format (len (x_O ))
306
313
0 commit comments