I have a group of elements selected, and I want to find a list of unique attributes for these elements; e.g., if there are a bunch of elements with either REAL 3 or 4, I want the list {3,4}. How can I do this?
There are a few approaches to solving this problem. -------------------------------------------------- Approach 1: Use vectors and vector operations -------------------------------------------------- (1) *VGET the element attributes (all_att) *VGET,all_att,ELEM,1,ATTR,MAT (2) *VGET the element select status (mask1) *VGET,mask,ELEM,1,ESEL (3) use mask1 to compress all_att to get a list of attributes for selected elements (sel_att) *VMASK,mask *VFUN,sel_att,COMP,all_mats (4) sort sel_att in ascending order (sorted_att) *VFUN,sorted_att,ASORT,sel_att *SET,all_att *SET,sel_att *SET,mask (5) define a new mask (mask2) the length of sorted_att, set the first entry to 1, then subtract sorted_att(1) from sorted_att(2) to identify changes in sorted_att; this effectively does entry(i)-entry(i-1) for all i>1 *VSCFUN,num_att,NUM,sorted_att *DIM,mask,ARRAY,num_att mask(1) = 1 *VOPER,mask(2),sorted_att(2),SUB,sorted_att(1) (6) use mask2 to compress sorted_att to get the desired list of unique element attributes (unique_att) *VMASK,mask *VFUN,unique_att,COMP,sorted_att *SET,sorted_att *SET,mask *STAT,unique_att(1) -------------------------------------------------- Approach 2: Use parameterized variable names -------------------------------------------------- (1) pick one element from the selected set (e.g., elnext(0)) (2) *GET the attribute that you are looking for (3) unselect all elements with that attribute (4) repeat until no elements in selected set This would require a loop with parameterized variable names (e.g., loop index "ii", then store attributes in "my_att%ii%"). -------------------------------------------------- Approach 3: Use the scatter vector operation -------------------------------------------------- The scatter operation of the *VOPER can be used to create a vector of the unique attributes as follows: (1) use *VGET to get an array of the desired attribute *VGET,atrib,ELEM,1,ATTR,MAT (2) get the maximum attribute value in the array *VSCFUN,mxat,MAX,atrib(1) (3) create an array to hold the values *DIM,scat,ARRAY,mxat (4) use the *VOPER command with scatter operation on attribute array !*VCUM,1 ! if you wanted the usage count of each attribute vale uncomment this line *VOPER,scat(1),atrib(1),SCAT,atrib(1) *STAT,scat(1) |
||
|