hypermesh二次开发tcl程序集

1、快速创建RBE蜘蛛

1.1、用set存放主从节点号,计算节点对应圆柱面内的节点号,存入相应的set

#source node_find.tcl
#for {set i 0} {$i<3} {incr i} {
#	puts $i
#}

#nodes in cylinder find::
set nodeIdSource [hm_getvalue sets name=set_s dataname=ids]
set nodeNumSource [llength $nodeIdSource]
for {set i 0} {$i<$nodeNumSource} {incr i} {
	set nodeIdi [lindex $nodeIdSource $i]
	set x [hm_getvalue nodes id=$nodeIdi dataname=x]
	set y [hm_getvalue nodes id=$nodeIdi dataname=y]
	set z [hm_getvalue nodes id=$nodeIdi dataname=z]
	set nodeSource($i,0) $x
	set nodeSource($i,1) $y
	set nodeSource($i,2) $z
	set nodeSource($i,3) $nodeIdi
}
set r 12.0
set listv {0 0 1}
set listL {-10.0 10.0}
set v(0) [lindex $listv 0]
set v(1) [lindex $listv 1]
set v(2) [lindex $listv 2]
set L(0) [lindex $listL 0]
set L(1) [lindex $listL 1]
set nodeId [hm_getvalue sets name=set_1 dataname=ids]
set nodeNum [llength $nodeId]
for {set i 0} {$i<$nodeNum} {incr i} {
	set nodeIdi [lindex $nodeId $i]
	set x0 [hm_getvalue nodes id=$nodeIdi dataname=x]
	set y0 [hm_getvalue nodes id=$nodeIdi dataname=y]
	set z0 [hm_getvalue nodes id=$nodeIdi dataname=z]
	#set node($i,0) $x0
	#set node($i,1) $y0
	#set node($i,2) $z0
	#set node($i,3) $nodeIdi
	set nodeIdFind {}
	for {set j 0} {$j<$nodeNumSource} {incr j} {
		set x $nodeSource($j,0)
		set y $nodeSource($j,1)
		set z $nodeSource($j,2)
		set x [expr $x-$x0]
		set y [expr $y-$y0]
		set z [expr $z-$z0]
		set NodeID $nodeSource($j,3)
		set La [expr $x*$v(0)+$y*$v(1)+$z*$v(2)]
		set Ra [expr sqrt($x**2+$y**2+$z**2-$La**2)]
		if {$La>=$L(0) & $La<=$L(1) & $Ra<=$r} {
			lappend nodeIdFind $NodeID
		}
	}
	eval *createmark nodes 1 $nodeIdFind;#eval is very important,or only one node is marked!!!
	*entitysetcreate set_1_$i nodes 1 
}

1.2、自动创建RBE2

#source rigid_create.tcl
#for {set i 0} {$i<3} {incr i} {
#	puts $i
#}

set nodeId [hm_getvalue sets name=set_1 dataname=ids]
set nodeNum [llength $nodeId]
#set nodeIdFind {}
for {set i 0} {$i<$nodeNum} {incr i} {
	set nodeIdi [lindex $nodeId $i]
	set nodeIdLink [hm_getvalue sets name=set_1_$i dataname=ids]
	#eval is very important,or only one node is marked!!!:
	eval *createmark nodes 2 $nodeIdLink
	eval *rigidlink $nodeIdi 2 123456
}

2、tcl读写csv文件

#source read_csv.tcl
#for {set i 0} {$i<3} {incr i} {
#	puts $i
#}

#read_csv::
set csvFile C:/Users/li/Documents/nodes.csv
set csv [open $csvFile]
set data [split [read $csv] '\n']
close $csv

#data 2 array aData::
set dataNum [llength $data]
incr dataNum -1
for {set i 0} {$i<$dataNum} {incr i} {
	set datai [split [lindex $data $i] ',']
	set dataiNum [llength $datai]
	for {set j 0} {$j<$dataiNum} {incr j} {
		set aData($i,$j) [lindex $datai $j]
		#puts $aData($i,$j)
	}
}
#parray aData #print array

#write_csv::
set wrFile [open nodes2.csv w]
puts $wrFile $aData(0,3),[expr $aData(0,3)+10000]
puts $wrFile $aData(1,3),[expr $aData(1,3)+10000]
puts $wrFile 4,5
close $wrFile

*createnode $aData(0,0) $aData(0,1) $aData(0,2) 0 0 0
*createnode $aData(1,0) $aData(1,1) $aData(1,2) 0 0 0
*createmark nodes 1 "all"
*numbersmark nodes 1 1 #show nodes number
*numbersmark nodes 1 0 #hide nodes number

*createmark nodes 1 2 1
*entitysetcreate "boy_R_nodes" nodes 1

set nodeId [hm_getvalue sets name=boy_R_nodes dataname=ids]
set nodeNum [llength $nodeId]
set wrFile [open nodes3.csv w]
for {set i 0} {$i<$nodeNum} {incr i} {
	set nodeIdi [lindex $nodeId $i]
	set x [hm_getvalue nodes id=$nodeIdi dataname=x]
	set y [hm_getvalue nodes id=$nodeIdi dataname=y]
	set z [hm_getvalue nodes id=$nodeIdi dataname=z]
	puts $wrFile $x,$y,$z,$nodeIdi
}
close $wrFile

*createmark nodes 1 200
*renumbersolverid nodes 1 2 1 0 0 0 0 0
*createmark nodes 1 100
*renumbersolverid nodes 1 1 1 0 0 0 0 0

for {set i 0} {$i<2} {incr i} {
	*createmark nodes 1 $aData($i,3)
	*renumbersolverid nodes 1 $aData($i,4) 1 0 0 0 0 0
}

3、将计算有问题的单元ID保存在set中

3.1、将计算有问题的单元ID拷贝到csv文件中

在这里插入图片描述

3.2、tcl程序

#source read_elements.tcl
#for {set i 0} {$i<3} {incr i} {
#	puts $i
#}

#read_csv::
set csvFile C:/Users/lijil/Documents/elements.csv
set csv [open $csvFile]
set data [split [read $csv] '\n']
close $csv

#data 2 array aData::
set dataNum [llength $data]
incr dataNum -1
for {set i 0} {$i<$dataNum} {incr i} {
	set datai [split [lindex $data $i] ',']
	set dataiNum [llength $datai]
	for {set j 0} {$j<$dataiNum} {incr j} {
		set aData($i,$j) [lindex $datai $j]
		#puts $aData($i,$j)
	}
}
#parray aData #print array

#*createmark nodes 1 2 1
#*entitysetcreate "boy_R_nodes" nodes 1
set elementsId {}
for {set i 0} {$i<$dataNum} {incr i} {
	lappend elementsId $aData($i,0)
}
eval *createmark elements 1 $elementsId
*entitysetcreate set_error elements 1 

4、手动选取部件,预览并输出材料的各项参数

4.1、用hypermesh的Matrix Browser查询材料的dataname关键字

在这里插入图片描述

4.2、tcl程序

#source material.tcl
#for {set i 0} {$i<3} {incr i} {
#	puts $i
#}

#components material find::
set csvFile C:/Users/lijil/Documents/material.csv
set wrFile [open $csvFile w]

#create markpanel to selecte components by hands:
*createmarkpanel components 1 'Select Components'
#review components selected:
*reviewentitybymark 1 0 1 0

set compList [hm_getmark components 1]
foreach comp $compList {
	set nameComp [hm_getvalue comps id=$comp dataname=name]
	#!!!comp has prop property,property has prop material,material has prop density...
	set material [hm_getvalue comps id=$comp dataname=property.materialid]
	set nameMaterial [hm_getvalue mats id=$material dataname=name]
	set density [hm_getvalue comps id=$comp dataname=property.material.Density]
	set young [hm_getvalue comps id=$comp dataname=property.material.Young]
	set poiss [hm_getvalue comps id=$comp dataname=property.material.Poiss]
	set mass [hm_getvalue comps id=$comp dataname=mass]
	set dataiNum [llength $datai]
	puts $wrFile $nameComp,$nameMaterial,$density,$young,$young,$poiss,$mass
}
close $wrFile
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值