PetscErrorCode DMDAGetElements(DM dm,PetscInt *nel,PetscInt *nen,const PetscInt *e[]) { DM_DA *da = (DM_DA*)dm->data; PetscErrorCode ierr; PetscFunctionBegin; if (da->dim==-1) { *nel = 0; *nen = 0; *e = PETSC_NULL; } else if (da->dim==1) { ierr = DMDAGetElements_1D(dm,nel,nen,e);CHKERRQ(ierr); } else if (da->dim==2) { ierr = DMDAGetElements_2D(dm,nel,nen,e);CHKERRQ(ierr); } else if (da->dim==3) { ierr = DMDAGetElements_3D(dm,nel,nen,e);CHKERRQ(ierr); } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"DMDA dimension not 1, 2, or 3, it is %D\n",da->dim); PetscFunctionReturn(0); }
/*@C DMDAGetElements - Gets an array containing the indices (in local coordinates) of all the local elements Not Collective Input Parameter: . dm - the DM object Output Parameters: + nel - number of local elements . nen - number of element nodes - e - the local indices of the elements' vertices Level: intermediate Notes: Call DMDARestoreElements() once you have finished accessing the elements. Each process uniquely owns a subset of the elements. That is no element is owned by two or more processes. If on each process you integrate over its owned elements and use ADD_VALUES in Vec/MatSetValuesLocal() then you'll obtain the correct result. .seealso: DMDAElementType, DMDASetElementType(), VecSetValuesLocal(), MatSetValuesLocal(), DMGlobalToLocalBegin(), DMLocalToGlobalBegin() @*/ PetscErrorCode DMDAGetElements(DM dm,PetscInt *nel,PetscInt *nen,const PetscInt *e[]) { PetscInt dim; PetscErrorCode ierr; DM_DA *dd = (DM_DA*)dm->data; PetscFunctionBegin; if (dd->stencil_type == DMDA_STENCIL_STAR) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"DMDAGetElement() requires you use a stencil type of DMDA_STENCIL_BOX"); ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); if (dim==-1) { *nel = 0; *nen = 0; *e = NULL; } else if (dim==1) { ierr = DMDAGetElements_1D(dm,nel,nen,e);CHKERRQ(ierr); } else if (dim==2) { ierr = DMDAGetElements_2D(dm,nel,nen,e);CHKERRQ(ierr); } else if (dim==3) { ierr = DMDAGetElements_3D(dm,nel,nen,e);CHKERRQ(ierr); } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"DMDA dimension not 1, 2, or 3, it is %D\n",dim); PetscFunctionReturn(0); }