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; }
MRegion_ptr MRs_Join(MRegion_ptr r1, MRegion_ptr r2, MFace_ptr f) { int i, j, nrf1, nrf2, gdim, gid, *rfdir2; MFace_ptr *rf2, fcmn=f; Mesh_ptr mesh; List_ptr rfaces2; mesh = MF_Mesh(r1); gid = MF_GEntID(r1); if (mesh != MF_Mesh(r2)) { MSTK_Report("MRs_Join","Regions not from same mesh",MSTK_ERROR); return 0; } else if (gid != MR_GEntID(r2)) { MSTK_Report("MRs_Join","Regions not from same geometric entity",MSTK_ERROR); return 0; } rfaces2 = MR_Faces(r2); nrf2 = List_Num_Entries(rfaces2); if (fcmn) { if (!MR_UsesEntity(r1,fcmn,MFACE)) { MSTK_Report("MRs_Join","Cannot find common face in region",MSTK_ERROR); return 0; } } else { /* find the common face */ List_ptr rfaces1 = MR_Faces(r1); int idx = 0; MFace_ptr rf; while ((rf = List_Next_Entry(rfaces2,&idx))) { if (List_Contains(rfaces1,rf)) { fcmn = rf; break; } } List_Delete(rfaces1); } rf2 = (MFace_ptr) malloc(nrf2*sizeof(MFace_ptr)); rfdir2 = (int *) malloc(nrf2*sizeof(int)); int found; for (i = 0, j = 0, found = 0; i < nrf2; i++) { MFace_ptr rface = List_Entry(rfaces2,i); if (rface == fcmn) found = 1; else { rf2[j] = rface; rfdir2[j] = MR_FaceDir_i(r2,i); j++; } } List_Delete(rfaces2); if (!found) { MSTK_Report("MRs_Join","Cannot find common face in region",MSTK_ERROR); return 0; } MR_Delete(r2,0); MR_Replace_Faces(r1,1,&fcmn,nrf2-1,rf2,rfdir2); MF_Delete(fcmn,0); free(rf2); free(rfdir2); return r1; }