control structure

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

hi,

In a macro I written I have 3 for loop nested.

the 1st one iterates for up to 3000 times .so my execution time is long.

Is there any way to reduce time.

 

Thanks and regards,

Mahes

Answers

  • tinh
    tinh Altair Community Member
    edited August 2017

    Show us your script please.

    If you just say looping 3000 times is so long then answer is looping 3 times only! 

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited August 2017

    Show us your script please.

    If you just say looping 3000 times is so long then answer is looping 3 times only! 

    hm_markclear nodes 1
    hm_createmark nodes 1 'by set' slide5
    set nodelist [hm_getmark nodes 1]
    set setupdate $nodelist
    foreach node $nodelist {
     hm_markclear nodes 1
     hm_createmark nodes 1 $node

     
     set temp [hm_getmark nodes 1]
     hm_markclear nodes 1
     foreach nid $temp {
      set flg [lsearch $nodelist $nid]
      if {$flg >-1} {
       *nodemarkbypath $node $nid 1
       set ls [hm_getmark nodes 1]
       if { [llength $ls]<4 } {
       foreach n $ls {
        
        if { [lsearch $setupdate $n] == -1} {
         
         lappend setupdate $n }
       } }
      }
     }
     
     
     unset temp
     lreplace $nodelist 0 0
          }

  • tinh
    tinh Altair Community Member
    edited August 2017

    Hi Mahes . What do you want to do?

    You have a set of nodes need to be updated

    You search for adjacent nodes of it

    Then if between it and its adjacents existing less than 4 nodes then you add those to the set.

    If you perform in 2d model, between each node and its adjacent node, there is nothing! What do you want to do with adjacent nodes?

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited August 2017

    Hi Mahes . What do you want to do?

    You have a set of nodes need to be updated

    You search for adjacent nodes of it

    Then if between it and its adjacents existing less than 4 nodes then you add those to the set.

    If you perform in 2d model, between each node and its adjacent node, there is nothing! What do you want to do with adjacent nodes?

    hi tinh,

    I have a model built of both hex and shell elements.

    we create some nodal sets.

    in those sets from primary nodes I need to fetch the mid nodes and update the set.

    This one is a part of my macro.

    elements are second order.

    2nd line of code mark nodes by sets.

    those sets only has primary nodes.

     

    Thanks,

    Mahes

  • tinh
    tinh Altair Community Member
    edited August 2017

    I understand

    From primary nodes, you want to add to the set only mid nodes nearby them, don't you?

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited August 2017

    I understand

    From primary nodes, you want to add to the set only mid nodes nearby them, don't you?

    hi tinh,

    yes .

    final set includes both primary and mid nodes.

    is there any other logic other than this.

     

    Thanks,

    Mahes

     

  • tinh
    tinh Altair Community Member
    edited August 2017

    Ok

    Do you need to add mid nodes those are inside solid comps? Or only on outer face of solid comps?

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited August 2017

    Ok

    Do you need to add mid nodes those are inside solid comps? Or only on outer face of solid comps?

    hi tinh,

    No.

    wat I want to do is...

    I will do  the mesh the model which has only 1st order elements.

    from that I will create nodal sets.

    after that I will change all elements to second order.

    By running the macro I will update the set which has the midnodes too.

     

    <?xml version="1.0" encoding="UTF-8"?>1.jpg

    <?xml version="1.0" encoding="UTF-8"?>2.jpg

  • tinh
    tinh Altair Community Member
    edited August 2017

    Ok, look like you want to add only mid nodes on outer face of solid

    Can't you switch to 2nd then create sets?

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited August 2017

    Ok, look like you want to add only mid nodes on outer face of solid

    Can't you switch to 2nd then create sets?

    hi tinh,

    Usually for me updates for mesh will come often.

    each time when I want to edit mesh I have to change it to first order.

    So I have do sets again.

     

  • tinh
    tinh Altair Community Member
    edited August 2017

    Why dont you create set after all updates?

    Somehow you should take the least effort of machine and man also

    Try arrange your work flow with fewer actions

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited August 2017

    Why dont you create set after all updates?

    Somehow you should take the least effort of machine and man also

    Try arrange your work flow with fewer actions

    Hi tinh,

    You are correct.This wat we taught.

    That's a must thing so have to be done .

     

     

  • tinh
    tinh Altair Community Member
    edited August 2017

    :D/emoticons/default_biggrin.png' srcset='/emoticons/biggrin@2x.png 2x' title=':D' width='20' /> I can write a code that helps to select such mid nodes. But I think if you describe detailly your script aim, I can give another strategy that doesn't need to select mid nodes, shorter and faster,...

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited August 2017

    hi tinh,

    I have done with code using entity info of node id in element edges.

    Thanks for the suggestion.

     

     

    thanks,

    mahes