How to get Mass/Area/Volume of a Comp in a macro

Altair Forum User
Altair Forum User
Altair Employee
edited September 2022 in Community Q&A

Hi everybody,

does anyone how to get the area / mass / volume of a component in a macro?

I'm searching for anything like:

' set area [hm_getcomparea $comp] '

or structural / non-structural mass or volume of this component.

I need it especially for Nastran models, but it would be great to have a solver-independet way (for at least: area, volume and total mass).

Can anybody help me?

Thank you...

Answers

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited January 2008

    try the following code

    proc calculateAreaOfComp {compNameId} {# computes the area of the surfaces in a componentset areaOfSurfaces 0.0*createmark surfaces 1 'by comp name' $compNameIdset surfaceList [hm_getmark surfaces 1]*clearmark surfaces 1foreach iSurface $surfaceList {    set areaOfSurfaces [expr ($areaOfSurfaces + [hm_getareaofsurface surface $iSurface]) ]	    }return $areaOfSurfaces}
  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited January 2008

    for the volume

    proc calculatevolumeOfComp {compNameId} {# computes the vol of solids in a componentset volumeOfSolids 0.0*createmark solids 1 'by comp name' $compNameIdset solidList [hm_getmark solids 1]*clearmark solids 1foreach iSolid $solidList {   set volumeOfSolids [expr ($volumeOfSolids + [hm_getvolumeofsolid solids $iSolid]) ]   }return $volumeOfSolids}
  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited January 2008

    Hi Cesar,

    thank you for your help.

    It's almost what I needed...

    But I'm searching for a way to get the informations of meshed components.

    e.g. after importing a Nastran-Input-Deck (-> there is no geometry, just mesh)

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited January 2008

    After you import the nastran deck, you could run a script to create surfaces from the mesh and place them in the proper collector. or manually create the surfaces with 'FE to surface'.

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited January 2008

    Good Idea, but I don't thick this way works on a whole BIW with > 300 PSHELL properties and

    > 500.000 elements in less then 8 hours (on a fast machine)...

    In 'Tool -> mass calc' is the fuction I'm searching for.

    The values of this function should be my new variables, but I don't find a command like:

    [hm_getareaofsurface ...] for a single element or a comp.

    I've got a complete runable model with all porperties and materials and I just would like to know the area of the elements of a certain component.

    Maybe anyone of Altair knows a way how get this information in same time as using 'mass calc' in a macro.

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited January 2008

    some posted this command to search the hypermesh api, you could search for the word 'mass' or 'area'.

    lsearch -all -inline $g_base(coreProcs) *mass*

    .......

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited January 2008

    try the following code, it will create the a surface from the fe model. for a 250k element (aprox. 100 components) frame model, it took less than one hour to generate the surfaces from the mesh.

    proc createSurfacesFromComp {} {  set compNameList [hm_complist name]  foreach compName $compNameList {     *createmark elems 1 'by comp name' $compName # some code is needed here for just selecting 2d elements. if other type of elements are present, there may be an error.     *createmark elems 2     *fetosurfs 1 2 123 1200 0.1 0  }}

    some code is needed to avoid an error if mark No1 does not contain any 2d element. I think should not contain any other type of elements, just 2d elements.

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited January 2008

    If you want to get the area of existing mesh, you can sum up the area of individual elements on a component by component basis. Each element area is already an attribute stored for each element.

    *createmark elems 1 'by comp' comp1set comp_el_list [hm_getmark elems 1] set comp1_area 0foreach id $comp_el_list {  set el_area [hm_getentityvalue elements $id 'area' 0]  set comp_1area [expr $comp_1area + $el_area]				      }

    This way you won't need to generate the geometric surfaces. There is also a 'volume' entity for solid elements.

    These are not solver specific, and would work on mesh from any source. I would also recommend looking at the 'masscalc' or 'components' in the hminstalldir/templates/summary directories for some other examples, although these are in template language, not tcl.

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited January 2008

    GREAT!!!

    Exact what I was looking for!

    This small code works fine and fast...

    Thanks a lot

  • FaForno
    FaForno Altair Community Member
    edited September 2022

    Dear All,

    If I have a list of component to get the total area on surface, how can I adapt this script?

    (names of components are fixed)

    Can someone help me, please?

     

    Thanks a lot in advance,

    Fabio