许可优化
产品
解决方案
服务支持
关于
软件库
当前位置:服务支持 >  软件文章 >  Python+Lsprepost:Dyna Shell Part缝合与延伸技巧

Python+Lsprepost:Dyna Shell Part缝合与延伸技巧

阅读数 6
点赞 0
article_banner

一、问题描述

将如下的shell缝合在一起

lsdyna模型的示意图

二、准备工作

所需材料为:

  • dyna模型k文件 (默认已有)
  • 缝合代码(见下面的python代码)
  • 左右节点编号文件

左右节点编号的获取操作为,打开Lsprepost-EleTol-Ident选项卡,设置选择方式为ByEdge,勾选Prop(即传播),选择Ang为45(即传播角度)。

设置完成后,点击要缝合部件的左右两边,即可在lsprepost的显示窗口,获得如下结果:

将上述结果以如下形式,形成左右节点编号文件,方便后续代码进行读取。

三、缝合结果如下

四、python代码文件

import numpy as np
from base_Kfile_func.NodeFunc import Excute_commandlines_byLsprepost

def read_id_from_txt(txt_path):
    with open(txt_path,'r')as f:
        list0 = []
        # 一直读取
        line = f.readline()
        while(line != ''):
            if 'edge-begin' in line: # 开始读取
                list1 = []
                line = f.readline()
                while('edge-end' not in line):
                    id = int(line.split('ID= ')[1].split(',')[0])
                    xyz = line.split('xyz= ')[1].split('\n')[0].split(',')
                    list1.append([id,float(xyz[0]),float(xyz[1]),float(xyz[2])])
                    line = f.readline()
                list0.append(list1)
            line = f.readline()
    return np.array(list0)[:,:,0].astype(np.int)

def Extending_id(idsets,starting_Nid,repeat):
    mid = np.arange(idsets.shape[1]*repeat).reshape(repeat,-1) + starting_Nid
    return np.insert(idsets,1,mid,axis=0)

def command_node_generate(idset,xyz):
    command = []
    for i in range(1,idset.shape[0]):
        temp = ['genselect target node ','genselect transfer 0 ',]
        for j in range(idset.shape[1]):
            temp += ['genselect node add node %d/0 '%idset[0,j],]
        temp += ['translate_model %s %s %s copy 0 '%(round(xyz[0]*i,4),round(xyz[1]*i,4),round(xyz[2]*i,4)),
                 'translate_model accept 0 465736 %d '%idset[i,0],'genselect clear ']
        command += temp
    return command

def command_element_generate(idset,element_pid,starting_Eid=500000):
    command = []
    for i in range(idset.shape[0]-1):
        for j in range(idset.shape[1]-1):
            temp = 'elemedit createelem new shell {0:d} {1:d} {2:d} {3:d} {4:d} {5:d} '.\
                format(starting_Eid,element_pid,idset[i,j],idset[i+1,j],idset[i+1,j+1],idset[i,j+1])
            starting_Eid += 1
            command.append(temp)
    return command

def RepeatSewingFunc(kfile_path,nodeid_path,target_path,xyz,repeat=14,starting_Nid=98881000,element_pid=195,starting_Eid=500000): # 这是 节点重复 + 缝合
    idsets = read_id_from_txt(nodeid_path)
    extended_idsets = Extending_id(idsets,starting_Nid,repeat)
    command_node = command_node_generate(extended_idsets[:-1], xyz)
    command_element = command_element_generate(extended_idsets,element_pid,starting_Eid)
    Excute_commandlines_byLsprepost(kfile_path,command_node+command_element,target_path=target_path,nographics=True)

def sewingFunc(kfile_path,nodeid_path,target_path,element_pid=195,starting_Eid=500000): # 这是单纯的缝合
    idsets = read_id_from_txt(nodeid_path)
    command_element = command_element_generate(idsets,element_pid,starting_Eid)
    Excute_commandlines_byLsprepost(kfile_path,command_element,target_path=target_path,nographics=False)




if __name__ == '__main__':
    # 参考
    # kfile_path = r'https://www.gofarlic.com\SoftwareFiles\PychramFiles\Program\2-CarTracker-Experiment1\Code\Data_Track_Extend\temp.k'
    # target_path = r'https://www.gofarlic.com\SoftwareFiles\PychramFiles\Program\2-CarTracker-Experiment1\Code\Data_Track_Extend\Base_600_550_v3.k'
    # nodeid_path = r'https://www.gofarlic.com\SoftwareFiles\PychramFiles\Program\2-CarTracker-Experiment1\Code\Data_Track_Extend\node_id.txt'
    # # RepeatSewingFunc(kfile_path, nodeid_path, target_path,xyz=(-3.5714,0,0), repeat=14)
    # sewingFunc(kfile_path, nodeid_path, target_path)

    kfile_path = r'https://www.gofarlic.com\SoftwareFiles\PychramFiles\Program\2-CarTracker-Experiment1\Code\Data_Track_Extend\temp.k'
    target_path = r'https://www.gofarlic.com\SoftwareFiles\PychramFiles\Program\2-CarTracker-Experiment1\Code\Data_Track_Extend\Base_600_550_v3.k'
    nodeid_path = r'https://www.gofarlic.com\SoftwareFiles\PychramFiles\Program\2-CarTracker-Experiment1\Code\Data_Track_Extend\node_id.txt'
    # RepeatSewingFunc(kfile_path, nodeid_path, target_path,xyz=(-3.5714,0,0), repeat=14)
    sewingFunc(kfile_path, nodeid_path, target_path)


免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删
相关文章
QR Code
微信扫一扫,欢迎咨询~

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 155-2731-8020
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

手机不正确

公司不为空