将如下的shell缝合在一起
所需材料为:
左右节点编号的获取操作为,打开Lsprepost-EleTol-Ident选项卡,设置选择方式为ByEdge,勾选Prop(即传播),选择Ang为45(即传播角度)。
设置完成后,点击要缝合部件的左右两边,即可在lsprepost的显示窗口,获得如下结果:
将上述结果以如下形式,形成左右节点编号文件,方便后续代码进行读取。
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)