+logger.setLevel("WARNING")
+
+# prefix for groups with internal usage
+# i.e. used to transfer the faces and edges sub-shapes ids to the mesh
+__prefix = "____"
+
+def __getIdsGrpDualFromOrig(mc_mesh_file, grp_name, mesh2d, grp_level):
+ """ Identify the polygonal cells ids matching the original group on the
+ original mesh (before dual mesh)
+
+ Args:
+ mc_mesh_file (MEDFileMesh): mesh on which to read the group
+ grp_name (string): name of the group to read
+ mesh2d (MEDCouplingUMesh): mesh at lower level (-1 or -2) containing
+ faces or segments cells
+ grp_level (int): level on which to load the group (-1 or -2)
+
+ Returns:
+ id_grp_poly (DataArrayInt64): ids of cells mathcing the group. None if
+ the group has not been found.
+ nodes_added (DataArrayInt64): new nodes added on the dual mesh
+ """
+ try:
+ grp_tria = mc_mesh_file.getGroup(grp_level, grp_name)
+ except:
+ logger.debug("""No group found for %s at level %i.
+ It is normal behaviour for degenerated geom edge."""\
+ %(grp_name, grp_level))
+ return None, None
+ # Retrieve the nodes in group
+ orig_grp_nodes = grp_tria.computeFetchedNodeIds()
+ # Find all the cells lying on one of the nodes
+ id_grp_poly = mesh2d.getCellIdsLyingOnNodes(orig_grp_nodes, False)
+
+ grp_poly = mesh2d[id_grp_poly]
+ if grp_poly.getNumberOfCells() == 0:
+ logger.debug("""No poly cell found for %s at level %i."""\
+ %(grp_name, grp_level))
+ return None, None
+
+ # find the extra face cells, on the border of the group (lying on nodes,
+ # but outside the group)
+ id_poly_border = grp_poly.findCellIdsOnBoundary()
+
+ # ids of the cells in grp_poly
+ id_poly = mc.DataArrayInt64.New(grp_poly.getNumberOfCells(), 1)
+ id_poly.iota()
+
+ # cells that are really in the group
+ id_to_keep = id_poly.buildSubstraction(id_poly_border)
+
+ id_grp_poly = id_grp_poly[id_to_keep]
+
+ id_grp_poly.setName(grp_name.strip())
+
+ # get nodes added on this group
+ grp_poly = mesh2d[id_grp_poly]
+ grp_nodes_poly = grp_poly.computeFetchedNodeIds()
+ nodes_added = grp_nodes_poly.buildSubstraction(orig_grp_nodes)
+
+ return id_grp_poly, nodes_added
+
+def __projectNodeOnSubshape(nodes, subshape, coords):
+ """ Project nodes on a sub-shape (face or edge) and update the mesh
+ coordinates
+
+ Args:
+ nodes (DataArrayInt): nodes ids to project
+ subshape (GEOM object): face or edge on which to project the nodes
+ coords (DataArrayDouble): coordinates of the mesh to update. These
+ coordinates are modified inside this function.
+ """
+ for i in nodes:
+ x, y, z = coords[i].getValues()
+ vertex = geompy.MakeVertex(x, y, z)
+ try:
+ prj = geompy.MakeProjection(vertex, subshape)
+ except:
+ logger.warning("Projection failed for %.5f %.5f %.5f but we continue with next node"%(x, y, z))
+ continue
+ new_coor = geompy.PointCoordinates(prj)
+ # update its coordinates in the mesh
+ coords[i] = new_coor
+ pass
+
+def __deleteObj(theObj):
+ """ Delete object from a Study