#include #include #include #include PetscErrorCode subdivide_triangle(PetscReal v1[2],PetscReal v2[2],PetscReal v3[3],PetscInt depth,PetscInt max,PetscReal xi[],PetscInt *np) { PetscReal v12[2],v23[2],v31[2]; PetscInt i; PetscErrorCode ierr; PetscFunctionBegin; if (depth == max) { PetscReal cx[2]; //printf("centroid \n"); cx[0] = (v1[0] + v2[0] + v3[0])/3.0; cx[1] = (v1[1] + v2[1] + v3[1])/3.0; xi[2*(*np)+0] = cx[0]; xi[2*(*np)+1] = cx[1]; (*np)++; PetscFunctionReturn(0); } /* calculate midpoints of each side */ for (i = 0; i < 2; i++) { v12[i] = (v1[i]+v2[i])/2.0; v23[i] = (v2[i]+v3[i])/2.0; v31[i] = (v3[i]+v1[i])/2.0; } /* recursively subdivide new triangles */ ierr = subdivide_triangle(v1,v12,v31,depth+1,max,xi,np);CHKERRQ(ierr); ierr = subdivide_triangle(v2,v23,v12,depth+1,max,xi,np);CHKERRQ(ierr); ierr = subdivide_triangle(v3,v31,v23,depth+1,max,xi,np);CHKERRQ(ierr); ierr = subdivide_triangle(v12,v23,v31,depth+1,max,xi,np);CHKERRQ(ierr); PetscFunctionReturn(0); } PetscErrorCode private_DMSwarmInsertPointsUsingCellDM_PLEX2D_SubDivide(DM dm,DM dmc,PetscInt nsub) { PetscErrorCode ierr; const PetscInt dim = 2; PetscInt q,npoints_q,e,nel,npe,pcnt,ps,pe,d,k,depth; PetscReal *xi; PetscReal **basis; Vec coorlocal; PetscSection coordSection; PetscScalar *elcoor = NULL; PetscReal *swarm_coor; PetscInt *swarm_cellid; PetscReal v1[2],v2[2],v3[2]; PetscFunctionBegin; npoints_q = 1; for (d=0; dcell, 1->edge, 2->vert */ ierr = DMPlexGetHeightStratum(dmc,0,&ps,&pe);CHKERRQ(ierr); nel = pe - ps; ierr = DMSwarmSetLocalSizes(dm,npoints_q*nel,-1);CHKERRQ(ierr); ierr = DMSwarmGetField(dm,DMSwarmPICField_coor,NULL,NULL,(void**)&swarm_coor);CHKERRQ(ierr); ierr = DMSwarmGetField(dm,DMSwarmPICField_cellid,NULL,NULL,(void**)&swarm_cellid);CHKERRQ(ierr); ierr = DMGetCoordinatesLocal(dmc,&coorlocal);CHKERRQ(ierr); ierr = DMGetCoordinateSection(dmc,&coordSection);CHKERRQ(ierr); pcnt = 0; for (e=0; ecell, 1->edge, 2->vert */ ierr = DMPlexGetHeightStratum(dmc,0,&ps,&pe);CHKERRQ(ierr); nel = pe - ps; ierr = DMSwarmSetLocalSizes(dm,npoints_q*nel,-1);CHKERRQ(ierr); ierr = DMSwarmGetField(dm,DMSwarmPICField_coor,NULL,NULL,(void**)&swarm_coor);CHKERRQ(ierr); ierr = DMSwarmGetField(dm,DMSwarmPICField_cellid,NULL,NULL,(void**)&swarm_cellid);CHKERRQ(ierr); ierr = DMGetCoordinatesLocal(dmc,&coorlocal);CHKERRQ(ierr); ierr = DMGetCoordinateSection(dmc,&coordSection);CHKERRQ(ierr); pcnt = 0; for (e=0; e