5 import medcoupling as mc
11 from salome.geom import geomBuilder
13 geompy = geomBuilder.New()
15 import SMESH, SALOMEDS
16 from salome.smesh import smeshBuilder
18 smesh = smeshBuilder.New()
20 def create_dual_mesh(mesh_ior, output_file, adapt_to_shape=True, mesh_name="MESH"):
21 """ Create a dual of the mesh in input_file into output_file
24 mesh_ior (string): corba Id of the Tetrahedron mesh
25 output_file (string): dual mesh file
27 # Import mesh from file
28 # mesh = salome.orb.string_to_object(salome.salome_study.myStudy.FindObjectID(mesh_id).GetIOR())
29 mesh = salome.orb.string_to_object(mesh_ior)
31 raise Exception("Could not find mesh using id: ", mesh_ior)
33 shape = mesh.GetShapeToMesh()
35 # We got a meshProxy so we need to convert pointer to MEDCoupling
36 int_ptr = mesh.ExportMEDCoupling(True, True)
37 dab = mc.FromPyIntPtrToDataArrayByte(int_ptr)
38 tetras = mc.MEDFileMesh.New(dab)[0]
39 # End of SMESH -> MEDCoupling part for dualmesh
41 tetras = mc.MEDCoupling1SGTUMesh(tetras)
42 polyh = tetras.computeDualMesh()
43 skin = tetras.buildUnstructured().computeSkin()
44 skin_polyh = polyh.buildUnstructured().computeSkin()
45 allNodesOnSkinPolyh = skin_polyh.computeFetchedNodeIds()
46 allNodesOnSkin = skin.computeFetchedNodeIds()
47 ptsAdded = allNodesOnSkinPolyh.buildSubstraction(allNodesOnSkin)
48 ptsAddedMesh = mc.MEDCouplingUMesh.Build0DMeshFromCoords( skin_polyh.getCoords()[ptsAdded] )
51 ptsAddedCoo = ptsAddedMesh.getCoords()
52 ptsAddedCooModified = ptsAddedCoo[:]
54 # We need the geometry for that
55 # TODO : Loop on faces identify points associated to which face
56 faces = geompy.ExtractShapes(shape, geompy.ShapeType["FACE"], True)
57 #assert( len(faces) == 1 )
58 ## projection des points ajoutés par le dual sur la surface
59 #for i,tup in enumerate(ptsAddedCooModified):
60 # vertex = geompy.MakeVertex(*tuple(tup))
61 # prj = geompy.MakeProjection(vertex, faces)
62 # newCoor = geompy.PointCoordinates( prj )
63 # ptsAddedCooModified[i] = newCoor
64 ## assign coordinates with projected ones
65 #polyh.getCoords()[ptsAdded] = ptsAddedCooModified
67 print("Writing dual mesh in ", output_file)
68 polyh.setName(mesh_name)
69 polyh.write(output_file)