forked from OpenFAST/python-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfast_input_deck.py
More file actions
134 lines (119 loc) · 5.09 KB
/
fast_input_deck.py
File metadata and controls
134 lines (119 loc) · 5.09 KB
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
import os
import numpy as np
import re
import pandas as pd
from .fast_input_file import FASTInputFile
__all__ = ['FASTInputDeck']
# --------------------------------------------------------------------------------}
# --- Full FAST input deck
# --------------------------------------------------------------------------------{
class FASTInputDeck(object):
"""Container for input files that make up a FAST input deck"""
def __init__(self,fstfile,readlist=['ED','AD'],silent=True):
"""Read FAST master file and read inputs for FAST modules that
are used
"""
# Backward compatibility:
readlist= [rd.replace('Aero', 'AD') for rd in readlist]
self.filename = fstfile
self.modeldir = os.path.split(fstfile)[0]
self.inputfiles = {}
# read master file
self.fst = FASTInputFile(fstfile)
print('Read',fstfile)
self.Attributes=['fst']
def sub_read(file_obj,store_obj,expected_keys,names):
""" read sub files from object """
for key,name in zip(expected_keys,names):
# NOTE: fast input files are relative to their module file
modeldir = os.path.split(file_obj.filename)[0]
try:
keyval=file_obj[key]
except:
print('Key not found',key)
continue
if type(keyval) is list:
setattr(store_obj, name, [])
bFileList = True
else:
bFileList = False
keyval=[keyval]
for i,keyv in enumerate(keyval):
fpath = os.path.join(modeldir, os.path.normpath(keyv.strip('"').replace('\\','/')))
if os.path.isfile(fpath):
self.inputfiles[name] = fpath
modinput = FASTInputFile(fpath)
try:
modinput = FASTInputFile(fpath)
except:
print('Problem reading',fpath)
else:
if bFileList:
getattr(store_obj,name).append(modinput)
if not silent:
print('Read',fpath,'as{}[{}]'.format(name,i))
else:
setattr(store_obj, name, modinput)
if not silent:
print('Read',fpath,'as',name)
self.Attributes.append(name)
else:
if not silent:
print('Not a file:',fpath)
FST_Keys= self.fst.keys()
filekeys = [ key for key in FST_Keys if key.endswith('File') ]
names = [key[:-4] for key in filekeys]
sub_read(self.fst,self,filekeys,names)
# BD
if 'BD' in readlist:
try:
if self.fst['CompElast']==2:
filekeys = ['BDBldFile(1)']
names = ['BD']
sub_read(self.fst,self,filekeys,names)
except:
pass
if 'InterpOrder' in FST_Keys:
self.version='OF2'
if self.fst['CompAero'] == 1:
self.ADversion='AD14'
elif self.fst['CompAero'] == 2:
self.ADversion='AD15'
else:
self.ADversion='Unknown'
elif 'TipRad' in FST_Keys:
self.version='F7'
else:
self.version='Unknown'
if hasattr(self,'Aero'):
self.AD=self.Aero
delattr(self,'Aero')
self.Attributes = [at.replace('Aero', 'AD') for at in self.Attributes]
if hasattr(self,'ED') and 'ED' in readlist:
filekeys = ['BldFile(1)' , 'BldFile(2)' , 'BldFile(3)' , 'TwrFile']
names = ['Bld1' , 'Bld2' , 'Bld3' , 'Twr']
sub_read(self.ED,self.ED,filekeys,names)
if hasattr(self,'AD') and 'AD' in readlist:
if 'WakeMod' in self.AD.keys():
self.ADversion='AD15'
# NOTE airfoils are not read
filekeys = ['ADBlFile(1)' , 'ADBlFile(2)' , 'ADBlFile(3)', 'AFNames']
names = ['Bld1' , 'Bld2' , 'Bld3' , 'AF']
sub_read(self.AD,self.AD,filekeys,names)
else:
self.ADversion='AD14'
if self.version=='F7':
filekeysAD14 = [ key for key in ['BldFile(1)','BldFile(2)','BldFile(3)'] if key in FST_Keys ]
names = ['Bld1' , 'Bld2' , 'Bld3' ]
sub_read(self.fst,self,filekeysAD14,names)
def __repr__(self):
s='<weio.FastInputDeck object>'+'\n'
s+='filename : '+self.filename+'\n'
s+='version : '+self.version+'\n'
s+='AD version : '+self.ADversion+'\n'
s+='available attributes: '+','.join(self.Attributes)
s+='\n'
return s
if __name__ == "__main__":
fst=FASTInputDeck('NREL5MW.fst')
print(fst)