int MESH_Recv_Vertices(Mesh_ptr mesh, int fromrank, int nvertices, MSTK_Comm comm) { int i; MVertex_ptr v; MPI_Status status; MPI_Request request; char mesg[256], errorstr[256], funcname[256]="MESH_Recv_Vertices"; int errcode, len, nreq=0; int rank; MPI_Comm_rank(comm,&rank); /* allocate receive buffer */ int *list_vertex = (int *) malloc(3*nvertices*sizeof(int)); /* receive vertex info */ errcode = MPI_Irecv(list_vertex,3*nvertices,MPI_INT,fromrank,rank,comm, &request); if (errcode != MPI_SUCCESS) MSTK_Report(funcname,"Trouble receiving mesh vertex info",MSTK_FATAL); /* Create the vertices while waiting for the message to complete */ for (i = 0; i < nvertices; i++) v = MV_New(mesh); errcode = MPI_Wait(&request,MPI_STATUS_IGNORE); if (errcode != MPI_SUCCESS) MSTK_Report(funcname,"Trouble receiving mesh vertex info",MSTK_FATAL); for(i = 0; i < nvertices; i++) { v = MESH_Vertex(mesh,i); int gentdim = list_vertex[3*i] & 7; /* first 3 bits; 7 is 0...00111 */ int gentid = list_vertex[3*i] >> 3; /* All but the first 3 bits */ MV_Set_GEntDim(v,gentdim); MV_Set_GEntID(v,gentid); int ptype = list_vertex[3*i+1] & 3; /* first 2 bits; 3 is 0...00011 */ int on_par_bdry = list_vertex[3*i+1] & 4; /* 3rd bit; 4 is 0...00100 */ int masterparid = list_vertex[3*i+1] >> 3; /* All but the first 3 bits */ MV_Set_PType(v,ptype); if (on_par_bdry) MV_Flag_OnParBoundary(v); MV_Set_MasterParID(v,masterparid); MV_Set_GlobalID(v,list_vertex[3*i+2]); } free(list_vertex); return 1; }
int MESH_ConcatSubMesh_Face(Mesh_ptr mesh, int num, Mesh_ptr *submeshes) { int nfv, nfe, i, j, k, ival; MVertex_ptr mv, new_mv, sub_mv; MEdge_ptr me, new_me, sub_me; MFace_ptr new_mf, sub_mf; List_ptr mfverts, mfedges; int add_face, idx, global_id, iloc, *loc; double coor[3], rval; void *pval; Mesh_ptr submesh; List_ptr parbndry_verts = List_New(10); List_ptr parbndry_edges = List_New(10); MEdge_ptr *fedges = (MEdge_ptr *) malloc(MAXPV2*sizeof(MEdge_ptr)); int *fedirs = (int *) malloc(MAXPV2*sizeof(int)); MAttrib_ptr parbndryatt = MAttrib_New(mesh, "on_parbndry", INT, MVERTEX); /* collect edges and vertices on the partition boundary */ int num_parbndry_edges = 0; idx = 0; while ((me = MESH_Next_Edge(mesh,&idx))) if (ME_PType(me) != PINTERIOR) { List_Add(parbndry_edges,me); num_parbndry_edges++; } int num_parbndry_verts = 0; idx = 0; while ((mv = MESH_Next_Vertex(mesh,&idx))) if (MV_PType(mv) != PINTERIOR) { List_Add(parbndry_verts,mv); MEnt_Set_AttVal(mv, parbndryatt, 1, 0.0, NULL); num_parbndry_verts++; } /* sort based on global ID */ List_Sort(parbndry_edges,num_parbndry_edges,sizeof(MEdge_ptr),compareGlobalID); List_Sort(parbndry_verts,num_parbndry_verts,sizeof(MVertex_ptr),compareGlobalID); int *parbndry_vert_gids = (int *) malloc(num_parbndry_verts*sizeof(int)); int *parbndry_edge_gids = (int *) malloc(num_parbndry_edges*sizeof(int)); /* store them in array for binary search */ for (i = 0; i < num_parbndry_edges; i++) { me = List_Entry(parbndry_edges,i); parbndry_edge_gids[i] = ME_GlobalID(me); } for (i = 0; i < num_parbndry_verts; i++) { mv = List_Entry(parbndry_verts,i); parbndry_vert_gids[i] = MV_GlobalID(mv); } /* Make list of new edges and vertices which will be updated with each mesh that is concatenated */ int max_vnew = 0, max_enew = 0; for (i = 0; i < num; i++) { max_vnew += MESH_Num_Vertices(submeshes[i]); max_enew += MESH_Num_Edges(submeshes[i]); } int num_new_verts = 0, num_new_edges = 0; int *new_vert_gids = (int *) malloc(max_vnew*sizeof(int)); int *new_edge_gids = (int *) malloc(max_enew*sizeof(int)); List_ptr new_verts = List_New(max_vnew); List_ptr new_edges = List_New(max_enew); /* Now process each mesh and add a layer of ghost elements from each of them to the main partition */ for (i = 0; i < num; i++) { submesh = submeshes[i]; MAttrib_ptr vidatt = MAttrib_New(submesh, "tempvid", POINTER, MVERTEX); MAttrib_ptr eidatt = MAttrib_New(submesh, "tempeid", POINTER, MEDGE); idx = 0; while ((sub_mf = MESH_Next_Face(submesh, &idx))) { add_face = 0; /* Find matching vertices between the submesh and main mesh */ mfverts = MF_Vertices(sub_mf,1,0); nfv = List_Num_Entries(mfverts); for (j = 0; j < nfv; j++) { sub_mv = List_Entry(mfverts,j); /* Does the vertex have a known counterpart on the partition * boundary of the main mesh? */ MEnt_Get_AttVal(sub_mv, vidatt, &ival, &rval, &mv); if (mv) { int on_parbndry=0; MEnt_Get_AttVal(mv, parbndryatt, &on_parbndry, &rval, &pval); if (on_parbndry) add_face = 1; } else { /* Does the global ID of this vertex of the sub mesh face * match the global ID of a partition boundary vertex in * the main mesh? */ global_id = MV_GlobalID(sub_mv); loc = (int *) bsearch(&global_id, parbndry_vert_gids, num_parbndry_verts, sizeof(int), compareINT); if (loc) { /* found a match */ add_face = 1; iloc = loc - parbndry_vert_gids; mv = List_Entry(parbndry_verts,iloc); /* here set the ghost vertex property, only necessary when the input submeshes are not consistent */ if (MV_PType(mv) == PGHOST && MV_PType(sub_mv) != PGHOST) { MV_Set_GEntDim(mv,MV_GEntDim(sub_mv)); MV_Set_GEntID(mv,MV_GEntID(sub_mv)); } MEnt_Set_AttVal(sub_mv, vidatt, 0, 0.0, mv); } } } List_Delete(mfverts); /* Find matching edges between the submesh and main mesh */ mfedges = MF_Edges(sub_mf,1,0); nfe = List_Num_Entries(mfedges); for (j = 0; j < nfe; j++) { sub_me = List_Entry(mfedges,j); /* Does the edge have a known counterpart on the partition * boundary of the main mesh */ MEnt_Get_AttVal(sub_me, eidatt, &ival, &rval, &me); if (!me) { /* Does the global ID of this edge of the sub mesh face * match the global ID of a partition boundary edge in the * main mesh? */ global_id = ME_GlobalID(sub_me); loc = (int *) bsearch(&global_id, parbndry_edge_gids, num_parbndry_edges, sizeof(int), compareINT); if (loc) { iloc = loc - parbndry_edge_gids; me = List_Entry(parbndry_edges,iloc); /* here set the ghost edge property, only necessary when the input submeshes are not consistent */ if (ME_PType(me) == PGHOST && ME_PType(sub_me) != PGHOST) { ME_Set_GEntDim(me,ME_GEntDim(sub_me)); ME_Set_GEntID(me,ME_GEntID(sub_me)); } MEnt_Set_AttVal(sub_me, eidatt, 0, 0.0, me); } } } if (!add_face) { List_Delete(mfedges); continue; } new_mf = MF_New(mesh); /* add face */ MF_Set_GEntDim(new_mf,MF_GEntDim(sub_mf)); MF_Set_GEntID(new_mf,MF_GEntID(sub_mf)); MF_Set_PType(new_mf,PGHOST); MF_Set_MasterParID(new_mf,MF_MasterParID(sub_mf)); MF_Set_GlobalID(new_mf,MF_GlobalID(sub_mf)); nfe = List_Num_Entries(mfedges); for (j = 0; j < nfe; j++) { sub_me = List_Entry(mfedges,j); global_id = ME_GlobalID(sub_me); fedirs[j] = MF_EdgeDir_i(sub_mf,j) == 1 ? 1 : 0; new_me = NULL; MEnt_Get_AttVal(sub_me, eidatt, &ival, &rval, &new_me); if (!new_me) { /* search in the ghost layer if another edge with * this global ID has been added */ loc = (int *) bsearch(&global_id, new_edge_gids, num_new_edges, sizeof(int), compareINT); if (loc) { iloc = loc - new_edge_gids; new_me = List_Entry(new_edges, iloc); MEnt_Set_AttVal(sub_me, eidatt, 0, 0.0, new_me); } } if (new_me) { if (MV_GlobalID(ME_Vertex(new_me,0)) != MV_GlobalID(ME_Vertex(sub_me,0))) fedirs[j] = 1 - fedirs[j]; /* if the edge dir is not the same, reverse the edge dir */ } else { /* add a new edge to main mesh */ new_me = ME_New(mesh); ME_Set_GEntDim(new_me,ME_GEntDim(sub_me)); ME_Set_GEntID(new_me,ME_GEntID(sub_me)); ME_Set_PType(new_me,PGHOST); ME_Set_MasterParID(new_me,ME_MasterParID(sub_me)); ME_Set_GlobalID(new_me,ME_GlobalID(sub_me)); MEnt_Set_AttVal(sub_me, eidatt, 0, 0.0, new_me); List_Add(new_edges, new_me); for (k = 0; k < 2; k++) { sub_mv = ME_Vertex(sub_me,k); global_id = MV_GlobalID(sub_mv); new_mv = NULL; MEnt_Get_AttVal(sub_mv, vidatt, &ival, &rval, &new_mv); if (!new_mv) { /* search in the ghost layer if another vertex with * this global ID has been added */ loc = (int *) bsearch(&global_id, new_vert_gids, num_new_verts, sizeof(int), compareINT); if (loc) { iloc = loc - new_vert_gids; new_mv = List_Entry(new_verts, iloc); MEnt_Set_AttVal(sub_mv, vidatt, 0, 0.0, new_mv); } } if (!new_mv) { /* add a new vertex to main mesh */ new_mv = MV_New(mesh); MV_Set_GEntDim(new_mv,MV_GEntDim(sub_mv)); MV_Set_GEntID(new_mv,MV_GEntID(sub_mv)); MV_Set_PType(new_mv,PGHOST); MV_Set_MasterParID(new_mv,MV_MasterParID(sub_mv)); MV_Set_GlobalID(new_mv,MV_GlobalID(sub_mv)); MV_Coords(sub_mv,coor); MV_Set_Coords(new_mv,coor); MEnt_Set_AttVal(sub_mv, vidatt, 0, 0.0, new_mv); List_Add(new_verts, new_mv); } ME_Set_Vertex(new_me,k,new_mv); /* set edge-vertex */ } } fedges[j] = new_me; } MF_Set_Edges(new_mf,nfe,fedges,fedirs); /* set face-edge */ List_Delete(mfedges); } idx = 0; while ((sub_mv = MESH_Next_Vertex(submesh, &idx))) MEnt_Rem_AttVal(sub_mv, vidatt); MAttrib_Delete(vidatt); idx = 0; while ((sub_me = MESH_Next_Edge(submesh, &idx))) MEnt_Rem_AttVal(sub_me, eidatt); MAttrib_Delete(eidatt); /* Sort the added entity lists by GlobalID */ num_new_edges = List_Num_Entries(new_edges); List_Sort(new_edges, num_new_edges, sizeof(MEdge_ptr), compareGlobalID); for (j = 0; j < num_new_edges; j++) new_edge_gids[j] = ME_GlobalID(List_Entry(new_edges, j)); num_new_verts = List_Num_Entries(new_verts); List_Sort(new_verts, num_new_verts, sizeof(MVertex_ptr), compareGlobalID); for (j = 0; j < num_new_verts; j++) new_vert_gids[j] = MV_GlobalID(List_Entry(new_verts, j)); } idx = 0; while ((mv = List_Next_Entry(parbndry_verts, &idx))) MEnt_Rem_AttVal(mv, parbndryatt); MAttrib_Delete(parbndryatt); List_Delete(parbndry_edges); List_Delete(parbndry_verts); List_Delete(new_edges); List_Delete(new_verts); free(parbndry_vert_gids); free(parbndry_edge_gids); free(new_vert_gids); free(new_edge_gids); free(fedges); free(fedirs); return 1; }
int MESH_BuildEdgeClassfn(Mesh_ptr mesh, int use_geometry) { int i, j, k, idx, idx2, fnd, fnd2, geid, geid2, gdim; int ngedges, ngealloc, ngef, max_loc_gfids, *loc_gfids; int max_gedge_id; int nve, nbe, nef, nsub, *geids, **gefaceids; double PI=3.141592, cosang, COSSHARPANG; MVertex_ptr ev[2]; MEdge_ptr edge, subedge, adjedge; MFace_ptr eface; List_ptr efaces, vedges, vbedges, geedges, subedges; double rval; void *pval; COSSHARPANG = cos(5*PI/6); /* 165 degrees */ /* Verify that mesh edges on the boundary have classification information; if not, assign all edges to the same model edge */ ngedges = 0; ngealloc = 10; geids = (int *) malloc(ngealloc*sizeof(int)); /* model edge ids */ /* Number of model faces connected to edge followed by model face ids */ gefaceids = (int **) malloc(ngealloc*sizeof(int *)); /* Take stock of existing model edge information */ max_gedge_id = 0; idx = 0; while ((edge = MESH_Next_Edge(mesh,&idx))) { gdim = ME_GEntDim(edge); if (gdim != 1) continue; geid = ME_GEntID(edge); if (geid) { /* Has this model edge been encountered? If not, add it to list of model edges */ for (i = 0, fnd = 0; i < ngedges; i++) if (geids[i] == geid) { fnd = 1; break; } if (!fnd) { if (geid > max_gedge_id) max_gedge_id = geid; if (ngealloc == ngedges) { ngealloc *= 2; geids = (int *) realloc(geids,ngealloc*sizeof(int)); gefaceids = (int **)realloc(gefaceids,ngealloc*sizeof(int *)); } geids[ngedges] = geid; efaces = ME_Faces(edge); nef = List_Num_Entries(efaces); gefaceids[ngedges] = (int *) malloc((1+nef)*sizeof(int)); ngef = 0; for (i = 0; i < nef; i++) { eface = List_Entry(efaces,i); if (MF_GEntDim(eface) == 2) { gefaceids[ngedges][1+ngef] = MF_GEntID(eface); ngef++; } } gefaceids[ngedges][0] = ngef; ngedges++; List_Delete(efaces); } } } /* Build new model edge information based on adjacent model region info */ /* NOTE: The following cases involve some repetition and can be "cleverly" folded into a shorter piece of code, but then the method by which the individual cases are handled gets a littled obscured. So leave as is */ max_loc_gfids = 10; loc_gfids = (int *) malloc(max_loc_gfids*sizeof(int)); idx = 0; while ((edge = MESH_Next_Edge(mesh,&idx))) { gdim = ME_GEntDim(edge); geid = ME_GEntID(edge); /* Edge has no classification? Assign classification info */ /* Edge classified as face or interior edge? Verify */ efaces = ME_Faces(edge); nef = efaces ? List_Num_Entries(efaces) : 0; if (!nef) { /* Isolated edge (must be on model edge). Did we encounter such an edge before? */ ME_Set_GEntDim(edge,1); for (i = 0, fnd = 0; i < ngedges; i++) { if (gefaceids[i][0] == 0) { fnd = 1; break; } } if (fnd) ME_Set_GEntID(edge,geids[i]); else { max_gedge_id++; ME_Set_GEntID(edge,max_gedge_id); if (ngealloc == ngedges) { ngealloc *= 2; geids = (int *) realloc(geids,ngealloc*sizeof(int)); gefaceids = (int **) realloc(gefaceids,ngealloc*sizeof(int *)); } geids[ngedges] = max_gedge_id; gefaceids[ngedges] = malloc(1*sizeof(int *)); gefaceids[ngedges][0] = 0; } continue; /* nothing else to do */ } if (nef > max_loc_gfids) { loc_gfids = (int *) realloc(loc_gfids,nef*sizeof(int)); max_loc_gfids = nef; } ngef = 0; for (i = 0; i < nef; i++) { eface = List_Entry(efaces,i); if (MF_GEntDim(eface) == 2) { loc_gfids[ngef] = MF_GEntID(eface); ngef++; } } switch (ngef) { case 0: /* Interior edge - we took care of the case of the isolated edge b4 */ ME_Set_GEntDim(edge,3); eface = List_Entry(efaces,0); ME_Set_GEntID(edge,MF_GEntID(eface)); break; case 2: if (loc_gfids[0] == loc_gfids[1]) { if (gdim == 1) { /* Looks like during face classification, this was tagged as being a sharp edge. This means that it is a sharp edge on the interior of a model face (same model face on both sides) */ ME_Set_GEntDim(edge,1); /* Check if such an edge was encountered before */ for (i = 0, fnd = 0; i < ngedges; i++) { if (gefaceids[i][0] != 2) continue; if ((loc_gfids[0] == gefaceids[i][0]) && (gefaceids[i][0] == gefaceids[i][1])) { fnd = 1; break; } } if (fnd) ME_Set_GEntID(edge,geids[i]); else { max_gedge_id++; ME_Set_GEntID(edge,max_gedge_id); if (ngealloc == ngedges) { ngealloc *= 2; geids = (int *) realloc(geids,ngealloc*sizeof(int)); gefaceids = (int **) realloc(gefaceids,ngealloc*sizeof(int *)); } geids[ngedges] = max_gedge_id; gefaceids[ngedges] = malloc((1+ngef)*sizeof(int *)); gefaceids[ngedges][0] = ngef; for (i = 0; i < ngef; i++) gefaceids[ngedges][1+i] = loc_gfids[i]; ngedges++; } } else { /* edge must be on model face */ ME_Set_GEntDim(edge,2); ME_Set_GEntID(edge,loc_gfids[0]); } } else { /* edge is on model edge between two faces */ ME_Set_GEntDim(edge,1); /* Check if such an edge was encountered before */ for (i = 0, fnd = 0; i < ngedges; i++) { if (gefaceids[i][0] != 2) continue; if (((loc_gfids[0] == gefaceids[i][1]) && (loc_gfids[1] == gefaceids[i][2])) || ((loc_gfids[1] == gefaceids[i][1]) && (loc_gfids[0] == gefaceids[i][2]))) { fnd = 1; break; } } if (fnd) ME_Set_GEntID(edge,geids[i]); else { max_gedge_id++; ME_Set_GEntID(edge,max_gedge_id); if (ngealloc == ngedges) { ngealloc *= 2; geids = (int *) realloc(geids,ngealloc*sizeof(int)); gefaceids = (int **) realloc(gefaceids,ngealloc*sizeof(int *)); } geids[ngedges] = max_gedge_id; gefaceids[ngedges] = malloc((1+ngef)*sizeof(int *)); gefaceids[ngedges][0] = ngef; for (i = 0; i < ngef; i++) gefaceids[ngedges][1+i] = loc_gfids[i]; ngedges++; } } break; default: /* if ngef is 1, edge is on model edge of non-manifold model face if ngef is >= 3, edge is on model edge at junction of many model faces */ ME_Set_GEntDim(edge,1); /* Check if a previously encountered model edge has this combination of connected faces */ for (i = 0, fnd = 0; i < ngedges; i++) { if (ngef != gefaceids[i][0]) continue; /* number of connected model faces is different */ /* see if all the model faces of the current edge can be found in the i'th model edge's faces */ fnd2 = 0; for (j = 0; j < ngef; j++) { fnd2 = 0; for (k = 0; k < ngef; k++) { if (loc_gfids[j] == gefaceids[i][1+k]) { fnd2 = 1; break; } } /* Did not find loc_gfid[j] in the list gefaceids[i] */ if (!fnd2) break; } /* if a model face connected to this edge was not found in the model face list of the previously processed, then the two model edges are obviously different */ if (!fnd2) continue; else { fnd = 1; break; } } if (fnd) ME_Set_GEntID(edge,geids[i]); else { max_gedge_id++; ME_Set_GEntID(edge,max_gedge_id); if (ngealloc == ngedges) { ngealloc *= 2; geids = (int *) realloc(geids,ngealloc*sizeof(int)); gefaceids = (int **) realloc(gefaceids,ngealloc*sizeof(int *)); } geids[ngedges] = max_gedge_id; gefaceids[ngedges] = malloc((1+ngef)*sizeof(int *)); gefaceids[ngedges][0] = ngef; for (i = 0; i < ngef; i++) gefaceids[ngedges][1+i] = loc_gfids[i]; ngedges++; } break; } List_Delete(efaces); /* needed efaces in case 0 */ } free(loc_gfids); if (use_geometry == 1) { #ifdef MSTK_USE_MARKERS int processedmk = MSTK_GetMarker(); int submk = MSTK_GetMarker(); #else MAttrib_ptr processedatt = MAttrib_New(mesh, "processed", INT, MEDGE); MAttrib_ptr sublistatt = MAttrib_New(mesh, "sublist", INT, MEDGE); #endif /* Now assign model edge IDs based on whether a sharp set of edges enclose a set of edges */ for (i = 0; i < ngedges; i++) { /* Find all mesh edges with this model edge id */ geedges = List_New(10); idx = 0; while ((edge = MESH_Next_Edge(mesh,&idx))) { if (ME_GEntDim(edge) == 1 && ME_GEntID(edge) == geids[i]) List_Add(geedges,edge); } /* Process edges of this list and subdivide them into subedges */ /* The way we do that is 1) we put an unprocessed edge from the original list in a subedge list 2) we then add its neighboring edges to subedge list if they are of the same color (same model edge id) and do not have a sharp edge separating them from the current edge 3) we then process the next edge in the subedge list 4) we are done if we cannot find any more neighbors of edges in the subedge list to add to the subedge list 5) we then repeat steps 1 through 4 until we are left with no more edges to process from the original list */ nsub = 0; idx = 0; while ((edge = List_Next_Entry(geedges,&idx))) { int emarked; #ifdef MSTK_USE_MARKERS emarked = MEnt_IsMarked(edge,processedmk); #else MEnt_Get_AttVal(edge, processedatt, &emarked, &rval, &pval); #endif if (emarked) continue; /* Found a edge in geedges that has not been processed */ #ifdef MSTK_USE_MARKERS MEnt_Mark(edge,processedmk); #else MEnt_Set_AttVal(edge, processedatt, 1, 0.0, NULL); #endif subedges = List_New(10); List_Add(subedges,edge); #ifdef MSTK_USE_MARKERS MEnt_Mark(edge,submk); #else MEnt_Set_AttVal(edge, sublistatt, 1, 0.0, NULL); #endif idx2 = 0; while ((subedge = List_Next_Entry(subedges,&idx2))) { geid = ME_GEntID(subedge); ev[0] = ME_Vertex(subedge,0); ev[1] = ME_Vertex(subedge,1); for (j = 0; j < 2; j++) { vedges = MV_Edges(ev[j]); nve = List_Num_Entries(vedges); vbedges = List_New(nve); /* list of boundary edges cnctd 2 vert */ for (k = 0; k < nve; k++) { adjedge = List_Entry(vedges,k); if (ME_GEntDim(adjedge) == 1) List_Add(vbedges,adjedge); } nbe = List_Num_Entries(vbedges); if (nbe == 2) { /* we might be on a model vertex or on a model edge */ adjedge = List_Entry(vbedges,0); if (adjedge == subedge) adjedge = List_Entry(vbedges,1); geid2 = ME_GEntID(adjedge); if (geid == geid2) { /* The two edges are of the same ID. If the angle between them is not sharp they can be classified as being on the same subedge */ cosang = MEs_Angle(subedge,adjedge); if (cosang <= COSSHARPANG) { /* Add edge2 to subedge list unless its already there */ int adjemarked; #ifdef MSTK_USE_MARKERS adjemarked = MEnt_IsMarked(adjedge,submk); #else MEnt_Get_AttVal(adjedge, sublistatt, &adjemarked, &rval, &pval); #endif if (!adjemarked) { List_Add(subedges,adjedge); #ifdef MSTK_USE_MARKERS MEnt_Mark(adjedge,submk); #else MEnt_Set_AttVal(adjedge, sublistatt, 1, 0.0, NULL); #endif } } else { /* The two edges make a very sharp angle. We will consider the edge b/w them to be a model vertex */ /* Tag the edge as being on a model vertex (we don't know the model vertex ID as yet) and continue */ MV_Set_GEntDim(ev[j],0); MV_Set_GEntID(ev[j],0); } } else { /* we reached a model vertex */ /* Tag the edge as being on a model vertex (we don't know the model vertex ID as yet) and continue */ MV_Set_GEntDim(ev[j],0); MV_Set_GEntID(ev[j],0); } } else { /* we reached a a model vertex */ /* Tag the edge as being on a model vertex (we don't know the model vertex ID as yet) and continue */ ME_Set_GEntDim(ev[j],0); ME_Set_GEntID(ev[j],0); } List_Delete(vedges); List_Delete(vbedges); } /* Finished processing all neighbors of the edge */ } /* Now we have a list of edges which we believe constitutes a model edge by itself. If this is the first subedge (which means it could also be the entire model edge originally considered), leave the model edge tag as it is. If not, assign the edges in the subedge a new model edge ID */ if (nsub != 0) { max_gedge_id++; idx2 = 0; while ((subedge = List_Next_Entry(subedges,&idx2))) ME_Set_GEntID(subedge,max_gedge_id); } nsub++; /* Done with this subedge */ #ifdef MSTK_USE_MARKERS idx2 = 0; while ((subedge = List_Next_Entry(subedges,&idx2))) { MEnt_Mark(subedge,processedmk); MEnt_Unmark(subedge,submk); } #else idx2 = 0; while ((subedge = List_Next_Entry(subedges,&idx2))) { MEnt_Set_AttVal(subedge, processedatt, 1, 0.0, NULL); MEnt_Set_AttVal(subedge, sublistatt, 0, 0.0, NULL); } #endif List_Delete(subedges); } #ifdef MSTK_USE_MARKERS List_Unmark(geedges,processedmk); #else idx2 = 0; while ((edge = List_Next_Entry(geedges, &idx2))) MEnt_Set_AttVal(edge, processedatt, 1, 0.0, NULL); #endif List_Delete(geedges); } #ifdef MSTK_USE_MARKERS MSTK_FreeMarker(processedmk); MSTK_FreeMarker(submk); #else MAttrib_Delete(processedatt); MAttrib_Delete(sublistatt); #endif } /* if use_geometry == 1 */ free(geids); for (i = 0; i < ngedges; i++) free(gefaceids[i]); free(gefaceids); return 1; }
MVertex_ptr MF_Split(MFace_ptr fsplit, double *splitxyz) { Mesh_ptr mesh; MVertex_ptr vsplit, fv[3]; MEdge_ptr enew, *fedges0, *fedges1, fe; MFace_ptr fnew[MAXPV2]; MRegion_ptr fr; int gid, gdim, i, j, idx, nnew; int nfv, fnewdir[MAXPV2], rfdir; List_ptr fregs, fverts; gdim = MF_GEntDim(fsplit); gid = MF_GEntID(fsplit); /* Collect information */ mesh = MF_Mesh(fsplit); /* Regions connected to face */ fregs = MF_Regions(fsplit); /* Vertices of face */ fverts = MF_Vertices(fsplit,1,0); nfv = List_Num_Entries(fverts); /* Create the splitting vertex */ vsplit = MV_New(mesh); MV_Set_Coords(vsplit,splitxyz); MV_Set_GEntDim(vsplit,gdim); MV_Set_GEntID(vsplit,gid); /* Create the 'nfe' faces */ for (i = 0; i < nfv; i++) { fv[0] = vsplit; fv[1] = List_Entry(fverts,i); fv[2] = List_Entry(fverts,(i+1)%nfv); fnew[i] = MF_New(mesh); MF_Set_GEntDim(fnew[i],gdim); MF_Set_GEntID(fnew[i],gid); MF_Set_Vertices(fnew[i],3,fv); } List_Delete(fverts); nnew = nfv; if (fregs) { for (i = 0; i < List_Num_Entries(fregs); i++) { fr = List_Entry(fregs,i); rfdir = MR_FaceDir(fr,fsplit); for (j = 0; j < nnew; j++) fnewdir[j] = rfdir; MR_Replace_Faces(fr,1,&fsplit,nnew,fnew,fnewdir); } List_Delete(fregs); } MF_Delete(fsplit,0); return vsplit; }