问题背景:风机荷载的时序文件经雨流计数后,生成马尔科夫矩阵。得到若干个不同方向的循环荷载及循环次数。通常情况下,工况非常繁杂,多达数百个,在SACS软件里采用手工定义的方式效率非常低下,并且容易出错。
本文采用python语言,将整理好的载荷谱直接生成SACS能识别的荷载文件。
整理后的载荷谱格式如下,本代码仅支持excel文件后缀格式.xls,不支持.xlsx。如有需要读者可自行修改。
软件打包界面如下:
p
python源代码:
import tkinter
import xlrd
from tkinter import *
from tkinter.filedialog import askopenfilename
from tkinter.messagebox import showinfo
frameT = Tk()
frameT.geometry('500x200+400+200')
frameT.title('疲劳载荷谱生成SACS文本')
frame = Frame(frameT)
frame.pack(padx=10, pady=10) # 设置外边距
frame1 = Frame(frameT)
frame1.pack(padx=10, pady=10)
v1 = StringVar()
ent = Entry(frame, width=50, textvariable=v1).pack(fill=X, side=LEFT) # x方向填充,靠左
def fileopen():
file_sql = askopenfilename()
if file_sql:
v1.set(file_sql)
# excel(.xls)文件转换为字典数组
def get_data(dir_case, sheetnum):
data = xlrd.open_workbook(dir_case)
table = data.sheets()[sheetnum]
nor = table.nrows
nol = table.ncols
dict = {}
for i in range(1, nor):
for j in range(nol):
title = table.cell_value(0, j)
value = table.cell_value(i, j)
# print value
dict[title] = value
yield dict
# 生成载荷谱文件按钮
def match():
for i in get_data(v1.get(), 0):
case = i['工况']
casestr = str(int(case))
load_case = str(int(i['循环荷载']))
if len(str(i['循环次数']))>10:
num_cycles=str(int(i['循环次数']))
else:
num_cycles=str(i['循环次数'])
direction=i['荷载方向']
# 动力放大系数
amp='1'
# 工况名 循环次数 动力放大系数 应力叠加方法
strlist = 'FTCASE' + casestr.ljust(4) + num_cycles.ljust(10) + amp.ljust(10) + 'STD'
strlist2 = 'FTCOMB' + ' ' + casestr.ljust(3) + amp.ljust(7)
with open('ftginp.joint', "a") as f:
f.write('\n' + strlist)
f.write('\n' + strlist2)
strlist3 = 'LOADCN' + casestr.ljust(4)
if direction == 'FX':
strlist4 = 'LOAD' + ' ' + 'WNOD' + ' ' * 5 + load_case.ljust(7) + ' ' * 37 + 'GLOB JOIN' + ' ' * 3 + 'FAT'
elif direction == 'FY':
strlist4 = 'LOAD' + ' ' * 3 + 'WNOD' + ' ' * 5 + ' ' * 7 + load_case.ljust(
7) + ' ' * 30 + 'GLOB JOIN' + ' ' * 3 + 'FAT'
elif direction == 'FZ':
strlist4 = 'LOAD' + ' ' * 3 + 'WNOD' + ' ' * 5 + ' ' * 14 + load_case.ljust(
7) + ' ' * 23 + 'GLOB JOIN' + ' ' * 3 + 'FAT'
elif direction == 'MX':
strlist4 = 'LOAD' + ' ' * 3 + 'WNOD' + ' ' * 5 + ' ' * 21 + load_case.ljust(
7) + ' ' * 16 + 'GLOB JOIN' + ' ' * 3 + 'FAT'
elif direction == 'MY':
strlist4 = 'LOAD' + ' ' * 3 + 'WNOD' + ' ' * 5 + ' ' * 29 + load_case.ljust(
7) + ' ' * 8 + 'GLOB JOIN' + ' ' * 3 + 'FAT'
elif direction == 'MZ':
strlist4 = 'LOAD' + ' ' * 3 + 'WNOD' + ' ' * 5 + ' ' * 36 + load_case.ljust(
7) + ' ' + 'GLOB JOIN' + ' ' * 3 + 'FAT'
with open('seainp.fatigue', "a") as m:
m.write('\n' + strlist3)
m.write('\n' + strlist4)
pass
btn = Button(frame, width=20, text='疲劳谱文件', font=("宋体", 14), command=fileopen).pack(fil=X, padx=10)
ext = Button(frame1, width=10, text='运行', font=("宋体", 14), command=match).pack(fill=X, side=LEFT)
etb = Button(frame1, width=10, text='退出', font=("宋体", 14), command=frameT.quit).pack(fill=Y, padx=10)
frameT.mainloop()
生成的SACS疲劳载荷文件
SACS荷载文件显示