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

Commit 56f4a44

Browse files
committed
IO: update of FAST reader for SubDyn
1 parent a44afc0 commit 56f4a44

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

pyFAST/input_output/fast_input_file.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class BrokenFormatError(Exception): pass
1616
TABTYPE_NUM_WITH_HEADERCOM = 2
1717
TABTYPE_NUM_NO_HEADER = 4
1818
TABTYPE_NUM_BEAMDYN = 5
19+
TABTYPE_NUM_SUBDYNOUT = 7
1920
TABTYPE_MIX_WITH_HEADER = 6
2021
TABTYPE_FIL = 3
2122
TABTYPE_FMT = 9999 # TODO
@@ -345,7 +346,7 @@ def _read(self):
345346
NUMTAB_FROM_LAB_VARNAME = ['AFCoeff' , 'TMDspProp' , 'MemberProp' , 'Members' , 'MemberOuts' , 'MemberOuts' , 'SectionProp' ,'LineTypes' ,'ConnectionProp' ,'LineProp' ]
346347
NUMTAB_FROM_LAB_NHEADER = [2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ]
347348
NUMTAB_FROM_LAB_NOFFSET = [0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ]
348-
NUMTAB_FROM_LAB_TYPE = ['num' , 'num' , 'num' , 'mix' , 'num' , 'num' , 'num' ,'mix' ,'mix' ,'mix' ]
349+
NUMTAB_FROM_LAB_TYPE = ['num' , 'num' , 'num' , 'mix' , 'num' , 'sdout' , 'num' ,'mix' ,'mix' ,'mix' ]
349350
# SubDyn
350351
NUMTAB_FROM_LAB_DETECT += ['GuyanDampSize' , 'YoungE' , 'YoungE' , 'EA' , 'MatDens' ]
351352
NUMTAB_FROM_LAB_DIM_VAR += [6 , 'NPropSets', 'NXPropSets', 'NCablePropSets' , 'NRigidPropSets']
@@ -592,6 +593,8 @@ def _read(self):
592593
else:
593594
if tab_type=='num':
594595
d['tabType'] = TABTYPE_NUM_WITH_HEADER
596+
elif tab_type=='sdout':
597+
d['tabType'] = TABTYPE_NUM_SUBDYNOUT
595598
else:
596599
d['tabType'] = TABTYPE_MIX_WITH_HEADER
597600
if isinstance(d['tabDimVar'],int):
@@ -679,6 +682,16 @@ def toStringVLD(val,lab,descr):
679682
lab='{:13s}'.format(lab)
680683
return val+' '+lab+' - '+descr.strip().strip('-').strip()+'\n'
681684

685+
def toStringIntFloatStr(x):
686+
try:
687+
if int(x)==x:
688+
s='{:15.0f}'.format(x)
689+
else:
690+
s='{:15.8e}'.format(x)
691+
except:
692+
s=x
693+
return s
694+
682695
def beamdyn_section_mat_tostring(x,K,M):
683696
def mat_tostring(M,fmt='24.16e'):
684697
return '\n'.join([' '+' '.join(['{:24.16E}'.format(m) for m in M[i,:]]) for i in range(np.size(M,1))])
@@ -725,7 +738,7 @@ def mat_tostring(M,fmt='24.16e'):
725738
s+='{}'.format(' '.join(['{:15s}'.format(s) for s in d['tabUnits']]))
726739
if np.size(d['value'],0) > 0 :
727740
s+='\n'
728-
s+='\n'.join('\t'.join('{}'.format(x) for x in y) for y in d['value'])
741+
s+='\n'.join('\t'.join(toStringIntFloatStr(x) for x in y) for y in d['value'])
729742
elif d['tabType']==TABTYPE_NUM_WITH_HEADERCOM:
730743
s+='! {}\n'.format(' '.join(['{:15s}'.format(s) for s in d['tabColumnNames']]))
731744
s+='! {}\n'.format(' '.join(['{:15s}'.format(s) for s in d['tabUnits']]))
@@ -748,6 +761,11 @@ def mat_tostring(M,fmt='24.16e'):
748761
K = data['K'][i]
749762
M = data['M'][i]
750763
s += beamdyn_section_mat_tostring(x,K,M)
764+
elif d['tabType']==TABTYPE_NUM_SUBDYNOUT:
765+
data = d['value']
766+
s+='{}\n'.format(' '.join(['{:15s}'.format(s) for s in d['tabColumnNames']]))
767+
s+='{}\n'.format(' '.join(['{:15s}'.format(s) for s in d['tabUnits']]))
768+
s+='\n'.join('\t'.join('{:15.0f}'.format(x) for x in y) for y in data)
751769
else:
752770
raise Exception('Unknown table type for variable {}'.format(d))
753771
if i<len(self.data)-1:
@@ -1263,6 +1281,13 @@ def parseFASTNumTable(filename,lines,n,iStart,nHeaders=2,tableType='num',nOffset
12631281
# If all values are float, we convert to float
12641282
if all([strIsFloat(x) for x in Tab.ravel()]):
12651283
Tab=Tab.astype(float)
1284+
elif tableType=='sdout':
1285+
header = lines[0]
1286+
units = lines[1]
1287+
Tab=[]
1288+
for i in range(nHeaders+nOffset,n+nHeaders+nOffset):
1289+
l = cleanAfterChar(lines[i].lower(),'!')
1290+
Tab.append( np.array(l.split()).astype(int))
12661291
else:
12671292
raise Exception('Unknown table type')
12681293

0 commit comments

Comments
 (0)