hm_getentityvalue uses too much physical memory

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

I am using the function hm_getentityvalue as follows,

 hm_getentityvalue elems 123 'cogx' 1

in order to get the x coordinates of all the elements in a particular hypermesh meshed model, and then I'm finding the minimum and maximum x-coordinates and the corresponding 2 elements that represent them while running through the elements in a foreach loop. However, this code seems to be using too much physical memory, almost a 6% jump after every iteration and eventually leads to 99% physical memory usage on my machine.

 

How could I avoid this ? And also, is there an easier way to find elements with minimum and maximum x/y/z coordinates in a model using tcl code but not by cycling through each element and checking its coordinates ?

 

Thanks,

Answers

  • Q.Nguyen-Dai
    Q.Nguyen-Dai Altair Community Member
    edited March 2017

    Maybe show us your code?

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited March 2017

    Maybe show us your code?

    Here it is,

     *createmark elems 1 displayed; set count 0; set minX 10000; set maxX 0; foreach elem [hm_getmark elems 1] { puts '[expr {double($count)/[hm_marklength elems 1]}]% done'; set x [hm_getentityvalue elems $elem 'cogx' 0]; if {$x < $minX} { 	set minX $x; } if {$x > $maxX} { 	set maxX $x; }                unset x; incr count; update; }

     

    After running this small bit of code in the HyperMesh tcl console, my Physical Memory jumped from 20% to 28% when I checked the Windows Task Manager. This is what I'd like to avoid and I'm not sure how best to optimize my code block.

     

    Edit : 

    I also tried using the hm_getmarkvalue command to get all values of cogx for all elements in one go, but this command takes a lot longer to run, and freezes up the GUI, however it does not use up any more physical memory. Any help in implementing this command while leaving the GUI unfrozen would also be appreciated.

  • Q.Nguyen-Dai
    Q.Nguyen-Dai Altair Community Member
    edited March 2017

    Try to delete two 'useless' lines  and you will see the difference :)/emoticons/default_smile.png' srcset='/emoticons/smile@2x.png 2x' title=':)' width='20' />

    <?xml version="1.0" encoding="UTF-8"?>Selection_019.png

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited March 2017

    Try to delete two 'useless' lines  and you will see the difference :)/emoticons/default_smile.png' srcset='/emoticons/smile@2x.png 2x' title=':)' width='20' />

    <?xml version="1.0" encoding="UTF-8"?>Selection_019.png

    @Q.Nguyen-Dai : I did try removing those lines and it makes no difference to the memory usage. I still see a 6% jump in Physical Memory usage before and after running this script. Removing those lines only results in the text not being printed on the tcl console's stdout.

  • Q.Nguyen-Dai
    Q.Nguyen-Dai Altair Community Member
    edited March 2017

    I do a test with about 12000 elements. By deleting these two lines, the script works 1000x faster :)/emoticons/default_smile.png' srcset='/emoticons/smile@2x.png 2x' title=':)' width='20' />

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited March 2017

    I do a test with about 12000 elements. By deleting these two lines, the script works 1000x faster :)/emoticons/default_smile.png' srcset='/emoticons/smile@2x.png 2x' title=':)' width='20' />

    @Q.Nguyen-Dai : The script does work faster, I agree. But that is not the issue I am facing. The script results in very high memory usage even though it works fast and that is what I am trying to avoid. Try opening up Windows Task Manager before you run the script, note the physical memory usage % and note it after the script has run. You'll see a sharp rise. 

     

    When I run it with about 60,000 elements my memory usage jumps 6% and it jumps 8% when I run it with 90,000 elements.

  • Q.Nguyen-Dai
    Q.Nguyen-Dai Altair Community Member
    edited March 2017

    How much memory do you have?

    When my script runs less than 2s, I don't care about used memory quantity, especially when I have more than 20G of RAM on my laptop :)/emoticons/default_smile.png' srcset='/emoticons/smile@2x.png 2x' title=':)' width='20' />

     

  • tinh
    tinh Altair Community Member
    edited March 2017

    Hi, 

    try another strategy

    *createmark elems 1 displayed

    lassign [hm_getboundingbox elems 1] minx miny minz maxx maxy maxz

    puts 'minx=$minx'

    puts 'maxx=$maxx'

     

    :rolleyes:/emoticons/default_rolleyes.gif' title=':rolleyes:' />

     

     

    sorry, it's lack some arguments, should be:

    hm_getboundingbox elems 1 0 0 0

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited March 2017

    How much memory do you have?

    When my script runs less than 2s, I don't care about used memory quantity, especially when I have more than 20G of RAM on my laptop :)/emoticons/default_smile.png' srcset='/emoticons/smile@2x.png 2x' title=':)' width='20' />

     

    @Q.Nguyen-Dai : I too have 16GB of RAM on my laptop, and my laptop eventually shuts down if I run this script too much. Which is why, I need to optimize it so that memory usage is not an issue.