Get a Connectivity List for all the Elements on a Model - How to?
Hello everyone,
I was wondering if there is a way to export a .txt file with the connectivity of all the elements on a model.
For example:
My model is made of CQUAD4 elements only.
The ideal output would be a list like this:
ELEMENT_ID,CONNECTION_1,CONNECTION_2,CONNECTION_3,CONNECTION_4
With CONNECTION_X being:
CONNECTION_1 - Element connected to G1-G2
CONNECTION_2 - Element connected to G2-G3
CONNECTION_3 - Element connected to G3-G4
CONNECTION_4 - Element connected to G4-G1
If there was no element connected, CONNECTION_X would be 0 (for example)
I've tried to assemble this connectivity matrix based on the bulk data exported by Hypermesh using MATLAB(it's the only language I'm comfortable with) using the CQUAD entry to go element by element and then search the whole list to find which element is connected to each side.
But since the elements on Hypermesh don't have the same orientation, the whole process doesn't finish..
Can anyone help me with this?
Thank you very much!
Answers
-
Hi,
It's increadible that you are comfortable with matlab but cannot do it by matlab-a very powerful software.
The tcl code is like this
*createmark elems 1 'by config' quad4
set ids [hm_getvalue elems mark=1 dataname=id]
set nodes [hm_getvalue elems mark=1 dataname=nodes]
set elems {}
set conns {}
foreach id $ids {n1 n2 n3 n4} [join $nodes] {
set i 0
foreach edge [list '$n1 $n2' '$n2 $n3' '$n3 $n4' '$n4 $n1' '$n2 $n1' '$n3 $n2' '$n4 $n3' '$n1 $n4'] conn {1 2 3 4 1 2 3 4} {
if {[dict exists $elems $edge]]} {
set e_c [dict get $elems $edge]
eval dict lappend conns $id $conn [set ids_ [dict keys $e_c]]
foreach id_ $ids_ {
dict lappend conns $id_ [dict get $e_c $id_] $id
}
}
if {[incr i]<5} {dict lappend elems $edge $id $conn}
}
}
set buf ''
foreach {id c_ids} $conns {
foreach conn {1 2 3 4} {
if {[dict exists $c_ids $con]} {
append buf $id,[dict get $c_ids $conn]
} else {
append buf $id,0
}
}
append buf \n
}
puts $buf
0 -
Hi @tinh,
Thank you very much for your answer!
The model I have is big qs (almost 400 000 elements) and the way I programmed it right now (probably not the best one) I'm running out of RAM before I finish the calculations..
I'll try your code and get back to you!
Thank you so much!
PS - How can I learn how to write TCL scripts?
0 -
-
Please change:
if {[dict exists $elems $edge]]} {
to:
if {[dict exists $elems $edge]} {
0 -
Thanks @Q.Nguyen-Dai
@goncalop please change 'puts $buf' by:
set fpt [open conns.txt w]
puts $fpt $buf
close $fpt
Because output 400k lines will hang hypermesh
0 -
Hello @Q.Nguyen-Dai, @tinh
I just did what you guys said and now the code reads like this:
*createmark elems 1 'by config' quad4
set ids [hm_getvalue elems mark=1 dataname=id]
set nodes [hm_getvalue elems mark=1 dataname=nodes]
set elems {}
set conns {}
foreach id $ids {n1 n2 n3 n4} [join $nodes] {
set i 0
foreach edge
- conn {1 2 3 4 1 2 3 4} {
if {[dict exists $elems $edge]} {
set e_c [dict get $elems $edge]
eval dict lappend conns $id $conn [set ids_ [dict keys $e_c]]
foreach id_ $ids_ {
dict lappend conns $id_ [dict get $e_c $id_] $id
}
}
if {[incr i]<5} {dict lappend elems $edge $id $conn}
}
}
set buf ''
foreach {id c_ids} $conns {
foreach conn {1 2 3 4} {
if {[dict exists $c_ids $con]} {
append buf $id,[dict get $c_ids $conn]
} else {
append buf $id,0
}
}
append buf \n
}
set fpt [open conns.txt w]
puts $fpt $buf
close $fpt
After copying this to a text file, changing the extension etc and running from hypermesh, I get this:
<?xml version="1.0" encoding="UTF-8"?>
Any idea?
Thank you very much!
0 -
Altair Forum User said:
if {[dict exists $c_ids $con]} {
change to:
if {[dict exists $c_ids $conn]} {
0 -
Thank you! I guess it worked now since It did not give me any error message.
Where can i find the output file?
0 -
Altair Forum User said:
Thank you! I guess it worked now since It did not give me any error message.
Where can i find the output file?
current working directory....
0 -
Altair Forum User said:
current working directory....
I searched the folder where I have the .tcl file and the folder where I have my model:
<?xml version="1.0" encoding="UTF-8"?>
here ^
But I can't find any conns.txt file..
Is it possible that Hypermesh is still writing the file?
Thank you!
0 -
Go to View -> Click on 'Command Window'
You will see one command line below panels in Hm...
Just type -> pwd
hit enter...
you will get current working directory..
please find the file there...
Regards,
PD
0 -
Yeah, I would never find it... Sorry..
But I just found the file and it's perfect!
Thank you so much guys!
0