static char help[] = "Tests DMSwarm with DMShell\n\n"; #include #include #include #include #include #include PetscErrorCode _DMLocatePoints_DMDARegular_IS(DM dm,Vec pos,IS *iscell) { PetscInt p,n,bs,npoints,si,sj,milocal,mjlocal,mx,my; DM dmregular; PetscInt *cellidx; const PetscScalar *coor; PetscReal dx,dy; PetscMPIInt rank; PetscFunctionBegin; PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD,&rank)); PetscCall(VecGetLocalSize(pos,&n)); PetscCall(VecGetBlockSize(pos,&bs)); npoints = n/bs; PetscCall(PetscMalloc1(npoints,&cellidx)); PetscCall(DMGetApplicationContext(dm,&dmregular)); PetscCall(DMDAGetCorners(dmregular,&si,&sj,NULL,&milocal,&mjlocal,NULL)); PetscCall(DMDAGetInfo(dmregular,NULL,&mx,&my,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)); dx = 2.0/((PetscReal)mx); dy = 2.0/((PetscReal)my); PetscCall(VecGetArrayRead(pos,&coor)); for (p=0; p= sj) && (mj < sj + mjlocal)) { if ((mi >= si) && (mi < si + milocal)) { cellidx[p] = (mi-si) + (mj-sj) * milocal; } } if (coorx < -1.0) cellidx[p] = DMLOCATEPOINT_POINT_NOT_FOUND; if (coorx > 1.0) cellidx[p] = DMLOCATEPOINT_POINT_NOT_FOUND; if (coory < -1.0) cellidx[p] = DMLOCATEPOINT_POINT_NOT_FOUND; if (coory > 1.0) cellidx[p] = DMLOCATEPOINT_POINT_NOT_FOUND; } PetscCall(VecRestoreArrayRead(pos,&coor)); PetscCall(ISCreateGeneral(PETSC_COMM_SELF,npoints,cellidx,PETSC_OWN_POINTER,iscell)); PetscFunctionReturn(0); } PetscErrorCode DMLocatePoints_DMDARegular(DM dm,Vec pos,DMPointLocationType ltype, PetscSF cellSF) { IS iscell; PetscSFNode *cells; PetscInt p,bs,npoints,nfound; const PetscInt *boxCells; PetscFunctionBegin; PetscCall(_DMLocatePoints_DMDARegular_IS(dm,pos,&iscell)); PetscCall(VecGetLocalSize(pos,&npoints)); PetscCall(VecGetBlockSize(pos,&bs)); npoints = npoints / bs; PetscCall(PetscMalloc1(npoints, &cells)); PetscCall(ISGetIndices(iscell, &boxCells)); for (p=0; pops->locatepoints = DMLocatePoints_DMDARegular; dmcell->ops->getneighbors = DMGetNeighbors_DMDARegular; /* Create the swarm */ PetscCall(DMCreate(PETSC_COMM_WORLD,&dms)); PetscCall(DMSetType(dms,DMSWARM)); PetscCall(DMSetDimension(dms,2)); PetscCall(PetscObjectSetName((PetscObject) dms, "Particles")); PetscCall(DMSwarmSetType(dms,DMSWARM_PIC)); PetscCall(DMSwarmSetCellDM(dms,dmcell)); PetscCall(DMSwarmRegisterPetscDatatypeField(dms,"itag",1,PETSC_INT)); PetscCall(DMSwarmFinalizeFieldRegister(dms)); { PetscInt si,sj,milocal,mjlocal; const PetscScalar *LA_coors; Vec coors; PetscInt cnt; PetscCall(DMDAGetCorners(dmregular,&si,&sj,NULL,&milocal,&mjlocal,NULL)); PetscCall(DMGetCoordinates(dmregular,&coors)); PetscCall(VecGetArrayRead(coors,&LA_coors)); PetscCall(DMSwarmSetLocalSizes(dms,milocal*mjlocal,4)); PetscCall(DMSwarmGetLocalSize(dms,&nlocal)); PetscCall(DMSwarmGetField(dms,DMSwarmPICField_coor,&bs,NULL,(void**)&array)); cnt = 0; PetscCall(PetscRandomCreate(PETSC_COMM_SELF,&rand)); PetscCall(PetscRandomSetInterval(rand,-1.0,1.0)); for (p=0; p