2 .. _python_testMEDCouplingNumPy_solution:
4 Playing with NumPy and SciPy
5 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 import MEDCoupling as mc
16 # Checking NumPy binding
17 assert(mc.MEDCouplingHasNumPyBindings())
18 # Playing with conversion and shared data
19 arr = mc.DataArrayDouble(12)
21 nparr = arr.toNumPyArray()
22 print nparr.__repr__()
25 print nparr.__repr__()
28 import gc; gc.collect() # Make sure the object has been deleted
29 print nparr.__repr__()
30 arr2 = mc.DataArrayDouble(nparr)
33 print nparr.__repr__()
36 f = open("toto.data","w+b")
37 a = np.memmap(f,dtype='float64',mode='w+',offset=0,shape=nparr.shape)
41 f2 = open("toto.data","r+b")
42 b = np.memmap(f2,dtype='float64',mode='r',offset=0,shape=(12,))
45 b = np.memmap(f2,dtype='float64',mode='r',offset=0,shape=(12,))
50 assert(mc.MEDCouplingHasSciPyBindings())
51 c1 = mc.MEDCouplingCMesh()
52 arr1 = mc.DataArrayDouble(7)
54 c1.setCoords(arr1,arr1,arr1)
55 c2 = mc.MEDCouplingCMesh()
56 arr2 = mc.DataArrayDouble(9)
59 c2.setCoords(arr2,arr2,arr2)
60 c1 = c1.buildUnstructured()
61 c2 = c2.buildUnstructured()
62 c2.translate([6.,0.,0.])
63 c = mc.MEDCouplingUMesh.MergeUMeshes([c1,c2])
65 skinAndNCFaces = c.computeSkin()
66 skinAndNCFaces.zipCoords()
67 # Isolating non conform cells
68 from MEDCouplingRemapper import MEDCouplingRemapper
69 rem = MEDCouplingRemapper()
70 rem.setMaxDistance3DSurfIntersect(1e-12)
71 rem.setMinDotBtwPlane3DSurfIntersect(0.99)
72 rem.prepare(skinAndNCFaces,skinAndNCFaces,"P0P0")
73 mat = rem.getCrudeCSRMatrix()
74 indptr = mc.DataArrayInt(mat.indptr)
75 indptr2 = indptr.deltaShiftIndex()
76 cellIdsOfSkin = indptr2.findIdsEqual(1)
77 skin = skinAndNCFaces[cellIdsOfSkin]
78 skin.writeVTK("skin.vtu")