Get a Connectivity List for all the Elements on a Model - How to?

Altair Forum User
Altair Forum User
Altair Employee
edited October 2020 in Community Q&A

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:

 

image.png.00d7030345cef12b16e8b382ae69c1ec.png

 

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

  • tinh
    tinh Altair Community Member
    edited September 2018

    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

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited September 2018

    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?

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited September 2018

    <?xml version="1.0" encoding="UTF-8"?>image.thumb.png.78113f46c95201bc5b87d862a06d9635.png

     

    I get this error when I run it.

     

    Is there something I should be doing differently?

     

    I copied your code, pasted it to a text file that I saved with a .tcl extension and then I ran it from hypermesh

  • Q.Nguyen-Dai
    Q.Nguyen-Dai Altair Community Member
    edited September 2018

    Please change:

             if {[dict exists $elems $edge]]} {

    to:

             if {[dict exists $elems $edge]} {

     

  • tinh
    tinh Altair Community Member
    edited September 2018

    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

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited September 2018

    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

    1.  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"?>image.thumb.png.87fbda2614df2d14255466ade179827a.png

     

    Any idea?

     

    Thank you very much!

  • Pandurang
    Pandurang Altair Community Member
    edited September 2018

     

     

     

     if {[dict exists $c_ids $con]} {

     

    change to:

     

     if {[dict exists $c_ids $conn]} {

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited September 2018

    @Pandurang,

     

    Thank you! I guess it worked now since It did not give me any error message.

     

    Where can i find the output file?

  • Pandurang
    Pandurang Altair Community Member
    edited September 2018

    @Pandurang,

     

    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....

     

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited September 2018

    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"?>image.thumb.png.23dfede6483de93f1d8e86e0f9bf3d2c.png

     

    here ^

     

    But I can't find any conns.txt file..

     

    Is it possible that Hypermesh is still writing the file?

     

    Thank you!

  • Pandurang
    Pandurang Altair Community Member
    edited September 2018

    image.png.dd0ade479069f991702f6a727656e642.png

     

    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

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited September 2018

    @Pandurang,

     

    Yeah, I would never find it... Sorry..

     

    But I just found the file and it's perfect!

     

    Thank you so much guys!

     

    @tinh  @Q.Nguyen-Dai  

     

    <?xml version="1.0" encoding="UTF-8"?>image.thumb.png.e21214784298fcd6efbc70ad914df32c.png