forked from OpenFAST/openfast_toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flex_blade_file.py
139 lines (126 loc) · 6.26 KB
/
flex_blade_file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import numpy as np
import pandas as pd
import os
try:
from .file import File, WrongFormatError, BrokenFormatError
except:
File = dict
class WrongFormatError(Exception): pass
class BrokenFormatError(Exception): pass
class FLEXBladeFile(File):
@staticmethod
def defaultExtensions():
return ['.bld','.bla','.00X'] #'.001 etc..'
@staticmethod
def formatName():
return 'FLEX blade file'
def _read(self):
headers_all = ['r_[m]','EIFlap_[Nm2]','EIEdge_[Nm2]','GKt_[Nm2]','Mass_[kg/m]','Jxx_[kg.m]','PreBendFlap_[m]','PreBendEdge_[m]'\
,'Str.Twist_[deg]','PhiOut_[deg]','Ycog_[m]','Yshc_[m]','CalcOutput_[0/1]'\
,'Chord_[m]','AeroTwist_[deg]','RelThickness_[%]','AeroCenter_[m]','AeroTorsion_[0/1]','ProfileSet_[#]']
with open(self.filename, 'r', errors="surrogateescape") as f:
try:
firstline = f.readline().strip()
nSections = int(f.readline().strip().split()[0])
except:
raise WrongFormatError('Unable to read first two lines of blade file')
try:
self.version=int(firstline[1:4])
except:
self.version=0
# --- Different handling depending on version
if self.version==0:
# Version 0 struct has no GKt
# Version 0 aero has no profile set, no TorsionAero
nColsStruct = 8
nColsAero = 5
struct_headers = ['r_[m]','EIFlap_[Nm2]','EIEdge_[Nm2]','Mass_[kg/m]','Str.Twist_[deg]','CalcOutput_[0/1]','PreBendFlap_[m]','PreBendEdge_[m]']
aero_headers = ['X_BladeRoot_[m]','Chord_[m]','AeroTwist_[deg]','RelThickness_[%]','AeroCenter_[m]']
elif self.version==1:
# Version 1 struct has GKt
# Version 1 aero has no profile set
nColsStruct = 8
nColsAero = 6
struct_headers = ['r_[m]','EIFlap_[Nm2]','EIEdge_[Nm2]','Mass_[kg/m]','Str.Twist_[deg]','CalcOutput_[0/1]','PreBendFlap_[m]','PreBendEdge_[m]']
aero_headers = ['X_BladeRoot_[m]','Chord_[m]','AeroTwist_[deg]','RelThickness_[%]','AeroCenter_[m]','AeroTorsion_[0/1]']
elif self.version==2:
nColsStruct = 9
nColsAero = 7
struct_headers = ['r_[m]','EIFlap_[Nm2]','EIEdge_[Nm2]','Mass_[kg/m]','Str.Twist_[deg]','CalcOutput_[0/1]','PreBendFlap_[m]','PreBendEdge_[m]','GKt_[Nm2]']
aero_headers = ['X_BladeRoot_[m]','Chord_[m]','AeroTwist_[deg]','RelThickness_[%]','AeroCenter_[m]','AeroTorsion_[0/1]','ProfileSet_[#]']
elif self.version==3:
nColsStruct = 13
nColsAero = 7
struct_headers = ['r_[m]','EIFlap_[Nm2]','EIEdge_[Nm2]','GKt_[Nm2]','Mass_[kg/m]','Jxx_[kg.m]','PreBendFlap_[m]','PreBendEdge_[m]','Str.Twist_[deg]','PhiOut_[deg]','Ycog_[m]','Yshc_[m]','CalcOutput_[0/1]']
aero_headers = ['X_BladeRoot_[m]','Chord_[m]','AeroTwist_[deg]','RelThickness_[%]','AeroCenter_[m]','AeroTorsion_[0/1]','ProfileSet_[#]']
else:
raise BrokenFormatError('Blade format not implemented')
struct = np.zeros((nSections,nColsStruct))
aero = np.zeros((nSections,nColsAero))
# --- Structural data
try:
for iSec in range(nSections):
vals=f.readline().split()
#if len(vals)>=nColsStruct:
struct[iSec,:]=np.array(vals[0:nColsStruct]).astype(float)
#elif self.version==1:
# # version 1 has either 8 or 9 columns
# nColsStruct=nColsStruct-1
# struct_headers=struct_headers[0:-1]
# struct =struct[:,:-1]
# struct[iSec,:]=np.array(vals[0:nColsStruct]).astype(float)
except:
raise WrongFormatError('Unable to read structural data')
try:
self.BetaC = float(f.readline().strip().split()[0])
if self.version==3:
f.readline()
self.FlapDamping = [float(v) for v in f.readline().strip().split(';')[0].split()]
self.EdgeDamping = [float(v) for v in f.readline().strip().split(';')[0].split()]
self.TorsDamping = [float(v) for v in f.readline().strip().split(';')[0].split()]
f.readline()
f.readline()
else:
Damping = [float(v) for v in f.readline().strip().split()[0:4]]
self.FlapDamping = Damping[0:2]
self.EdgeDamping = Damping[2:4]
self.TorsDamping = []
except:
raise
raise WrongFormatError('Unable to read damping data')
# --- Aero
try:
for iSec in range(nSections):
vals=f.readline().split()[0:nColsAero]
aero[iSec,:]=np.array(vals).astype(float)
except:
raise WrongFormatError('Unable to read aerodynamic data')
self.ProfileFile=f.readline().strip()
# --- Concatenating aero and structural data
self._cols = struct_headers+aero_headers[1:]
data = np.column_stack((struct,aero[:,1:]))
dataMiss=pd.DataFrame(data=data, columns=self._cols)
self._nColsStruct=nColsStruct # to remember where to split
# --- Making sure all columns are present, irrespectively of version
self.data=pd.DataFrame(data=[], columns=headers_all)
for c in self._cols:
self.data[c]=dataMiss[c]
# def toString(self):
# s=''
# if len(self.ProfileSets)>0:
# prefix='PROFILE SET '
# else:
# prefix=''
# for pset in self.ProfileSets:
# s+=pset.toString(prefix)
# return s
#
# def _write(self):
# with open(self.filename,'w') as f:
# f.write(self.toString)
#
def __repr__(self):
s ='Class FLEXBladeFile (attributes: data, BetaC, FlapDamping, EdgeDamping, ProfileFile)\n'
return s
def _toDataFrame(self):
return self.data