mainpyFormex - Support: sr #108202, encode, decode: in arraytools?

 
 

sr #108202: encode, decode: in arraytools?

Submitter:  gianluca de santis <gianlucadesi>
Submitted:  Mon 10 Dec 2012 04:15:03 PM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Privacy:  Public
Assigned to:  None Open/Closed:  Open
Operating System:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 10 Dec 2012 06:32:36 PM UTC, comment #2: 

The same result can be obtained using testDuplicate. E.g., replace the code

cod, mag=encode(H.elems,permutations=True, return_magic=True)
mult, uniq = multiplicity(cod)
order = uniqueOrdered(cod, return_index=False, return_inverse=True)
orderedmult = mult[order[1]]
print("Elements with multiplicity 3: ",where(orderedmult==3)[0])
# [ 2  3  4  5  6  7  8 10 12 13 18 19 21 22 37 40 41 52 53 56 57]


ind,ok = H.elems.testDuplicate()
cs = ok.cumsum()-1
mult, uniq = multiplicity(cs)
sel = where(mult==3)[0]
print("Elements with multiplicity 3: ",ind[in1d(cs,sel)])
# [ 2 10 37  5 18 52  6 19 53  3 12 40  4 13 41  7 21 56  8 22 57]

Sorting the last result would yield the same result as the first.

So I think the encode,decode are unneeded.
But maybe we should add an option to testDuplicate to return (some of) this information, because I agree that it is not obvious to find this solution (esp. the cumsum and in1d tricks).

E.g. an option return_multiplicity=True could return an extra dict with multiplicities as keys and a list of elements as value.
And an option return_multiplicity=[2,3,5] could return only the specified multiplicities.



Benedict Verhegghe <bverheg>
Group administrator
Mon 10 Dec 2012 04:15:03 PM UTC, comment #1: 

This item has been reassigned from the project pyFormex task tracker to your tracker.

The original report is still available at task #12341

Following are the information included in the original report:

[field #0]                  Item ID: 12341
[field #1]                 Group ID: 10866
[field #2]              Open/Closed: Open
[field #3]                 Severity: 3 - Normal
[field #4]                  Privacy: Public
[field #9]                 Category: None
[field #10]             Submitted by: gianlucadesi
[field #11]              Assigned to: bverheg
[field #12]             Submitted on: Mon 10 Dec 2012 04:27:22 PM CET
[field #13]                  Summary: encode, decode: in arraytools?
[field #14]      Original Submission: Should encode/decode be re-introduced in pyFormex? Maybe in arraytools.py?
Or are there some other functions which may reproduce the same array functionality of decode/encode (not necessarily on a connectivity table)?

I would suggest to re-introduce encode (and enmagic2), decode (and demagic2) and move them to arraytools. 

The example below shows something that can be done with encode: in a mesh with repeated elements, find the elements that are repeated N times. NB: to be able to run it, you need to uncomment the encode function in connectivity.py lines 1052-1123.


#build basic blocks
from elements import Hex8
h0=Mesh(Hex8).toFormex()
#change order of nodes to make it more difficult to find multiple rows
h1=Formex([h0.points()[[1, 5, 6, 2, 0, 4, 7, 3]]], eltype='hex8')
draw(h0)
drawNumbers(h0.coords)
draw(h1.translate([2., 2., 2]), color='red')
drawNumbers(h1.translate([2., 2., 2]).coords, color='red')

clear()
H4=h0.replic(4, 1, 0).replic(4, 1, 1).replic(4, 1, 2).toMesh()
H3=h1.replic(3, 1, 0).replic(3, 1, 1).replic(3, 1, 2).toMesh()
H2=h0.replic(2, 1, 0).replic(2, 1, 1).replic(2, 1, 2).toMesh()
H1=h1.replic(1, 1, 0).replic(1, 1, 1).replic(1, 1, 2).toMesh()

H=Mesh.concatenate([H1, H2, H3, H4]).compact().renumber().setProp(0)
smooth()
draw(H, mode='wireframe')
perspective(False)
#find elems which are repeated N times
N=3
cod, mag=encode(H.elems,permutations=True, return_magic=True)
mult, uniq = multiplicity(cod)
order = uniqueOrdered(cod, return_index=False, return_inverse=True)
orderedmult = mult[order[1]]
draw(H.select(orderedmult==N), mode='smoothwire', color='red')
lights(True)

exit()

[field #16]               Item Group: None
[field #17]                   Status: None
[field #18]        Component Version: None
[field #19]         Operating System: None
[field #20]          Reproducibility: None
[field #21]               Size (loc): None
[field #22]            Fixed Release: None
[field #23]          Planned Release: None
[field #24]                   Effort: 0.00
[field #28]                 Priority: 5 - Normal
[field #29]          Should Start On: Mon 10 Dec 2012 01:00:00 AM CET
[field #30]    Should be Finished on: Mon 10 Dec 2012 01:00:00 AM CET
[field #31]         Percent Complete: 0%
[field #33]                  Release: None
[field #58]     Custom Select Box #1: None
[field #59]     Custom Select Box #2: None
[field #60]     Custom Select Box #3: None
[field #61]     Custom Select Box #4: None
[field #62]     Custom Select Box #5: None
[field #63]     Custom Select Box #6: None
[field #64]     Custom Select Box #7: None
[field #65]     Custom Select Box #8: None
[field #66]     Custom Select Box #9: None
[field #67]    Custom Select Box #10: None

Benedict Verhegghe <bverheg>
Group administrator
Mon 10 Dec 2012 04:15:03 PM UTC, original submission:  

Should encode/decode be re-introduced in pyFormex? Maybe in arraytools.py?
Or are there some other functions which may reproduce the same array functionality of decode/encode (not necessarily on a connectivity table)?

I would suggest to re-introduce encode (and enmagic2), decode (and demagic2) and move them to arraytools. 

The example below shows something that can be done with encode: in a mesh with repeated elements, find the elements that are repeated N times. NB: to be able to run it, you need to uncomment the encode function in connectivity.py lines 1052-1123.


#build basic blocks
from elements import Hex8
h0=Mesh(Hex8).toFormex()
#change order of nodes to make it more difficult to find multiple rows
h1=Formex([h0.points()[[1, 5, 6, 2, 0, 4, 7, 3]]], eltype='hex8')
draw(h0)
drawNumbers(h0.coords)
draw(h1.translate([2., 2., 2]), color='red')
drawNumbers(h1.translate([2., 2., 2]).coords, color='red')

clear()
H4=h0.replic(4, 1, 0).replic(4, 1, 1).replic(4, 1, 2).toMesh()
H3=h1.replic(3, 1, 0).replic(3, 1, 1).replic(3, 1, 2).toMesh()
H2=h0.replic(2, 1, 0).replic(2, 1, 1).replic(2, 1, 2).toMesh()
H1=h1.replic(1, 1, 0).replic(1, 1, 1).replic(1, 1, 2).toMesh()

H=Mesh.concatenate([H1, H2, H3, H4]).compact().renumber().setProp(0)
smooth()
draw(H, mode='wireframe')
perspective(False)
#find elems which are repeated N times
N=3
cod, mag=encode(H.elems,permutations=True, return_magic=True)
mult, uniq = multiplicity(cod)
order = uniqueOrdered(cod, return_index=False, return_inverse=True)
orderedmult = mult[order[1]]
draw(H.select(orderedmult==N), mode='smoothwire', color='red')
lights(True)

exit()

gianluca de santis <gianlucadesi>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bverheg (Posted a comment)
  • -email is unavailable- added by gianlucadesi (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-12-10 bverheg Reassign itempyFormex, task #12341 pyFormex, sr #108202

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code