/*@ DMDAGetAO - Gets the application ordering context for a distributed array. Collective on DMDA Input Parameter: . da - the distributed array Output Parameters: . ao - the application ordering context for DMDAs Level: intermediate Notes: In this case, the AO maps to the natural grid ordering that would be used for the DMDA if only 1 processor were employed (ordering most rapidly in the x-direction, then y, then z). Multiple degrees of freedom are numbered for each node (rather than 1 component for the whole grid, then the next component, etc.) .keywords: distributed array, get, global, indices, local-to-global .seealso: DMDACreate2d(), DMDASetAOType(), DMDAGetGhostCorners(), DMDAGetCorners(), DMDALocalToGlocal() DMGlobalToLocalBegin(), DMGlobalToLocalEnd(), DMLocalToLocalBegin(), DMLocalToLocalEnd(), DMDAGetOwnershipRanges(), AO, AOPetscToApplication(), AOApplicationToPetsc() @*/ PetscErrorCode DMDAGetAO(DM da,AO *ao) { DM_DA *dd; PetscBool isdmda; PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(da,DM_CLASSID,1); PetscValidPointer(ao,2); ierr = PetscObjectTypeCompare((PetscObject)da,DMDA,&isdmda);CHKERRQ(ierr); if (!isdmda) SETERRQ(PetscObjectComm((PetscObject)da),PETSC_ERR_SUP,"Requires a DMDA as input"); /* now we can safely dereference */ dd = (DM_DA*)da->data; /* Build the natural ordering to PETSc ordering mappings. */ if (!dd->ao) { IS ispetsc,isnatural; PetscErrorCode ierr; PetscInt Nlocal; ierr = DMDAGetNatural_Private(da,&Nlocal,&isnatural);CHKERRQ(ierr); ierr = ISCreateStride(PetscObjectComm((PetscObject)da),Nlocal,dd->base,1,&ispetsc);CHKERRQ(ierr); ierr = AOCreate(PetscObjectComm((PetscObject)da),&dd->ao);CHKERRQ(ierr); ierr = AOSetIS(dd->ao,isnatural,ispetsc);CHKERRQ(ierr); ierr = AOSetType(dd->ao,dd->aotype);CHKERRQ(ierr); ierr = PetscLogObjectParent((PetscObject)da,(PetscObject)dd->ao);CHKERRQ(ierr); ierr = ISDestroy(&ispetsc);CHKERRQ(ierr); ierr = ISDestroy(&isnatural);CHKERRQ(ierr); } *ao = dd->ao; PetscFunctionReturn(0); }
/*@ DMDAGetAO - Gets the application ordering context for a distributed array. Collective on DMDA Input Parameter: . da - the distributed array Output Parameters: . ao - the application ordering context for DMDAs Level: intermediate Notes: In this case, the AO maps to the natural grid ordering that would be used for the DMDA if only 1 processor were employed (ordering most rapidly in the x-direction, then y, then z). Multiple degrees of freedom are numbered for each node (rather than 1 component for the whole grid, then the next component, etc.) .keywords: distributed array, get, global, indices, local-to-global .seealso: DMDACreate2d(), DMDAGetGhostCorners(), DMDAGetCorners(), DMDALocalToGlocal() DMGlobalToLocalBegin(), DMGlobalToLocalEnd(), DMDALocalToLocalBegin(), DMDALocalToLocalEnd(), DMDAGetGlobalIndices(), DMDAGetOwnershipRanges(), AO, AOPetscToApplication(), AOApplicationToPetsc() @*/ PetscErrorCode DMDAGetAO(DM da,AO *ao) { DM_DA *dd = (DM_DA*)da->data; PetscFunctionBegin; PetscValidHeaderSpecific(da,DM_CLASSID,1); PetscValidPointer(ao,2); /* Build the natural ordering to PETSc ordering mappings. */ if (!dd->ao) { IS ispetsc,isnatural; PetscErrorCode ierr; PetscInt Nlocal; ierr = DMDAGetNatural_Private(da,&Nlocal,&isnatural);CHKERRQ(ierr); ierr = ISCreateStride(PetscObjectComm((PetscObject)da),Nlocal,dd->base,1,&ispetsc);CHKERRQ(ierr); ierr = AOCreateBasicIS(isnatural,ispetsc,&dd->ao);CHKERRQ(ierr); ierr = PetscLogObjectParent(da,dd->ao);CHKERRQ(ierr); ierr = ISDestroy(&ispetsc);CHKERRQ(ierr); ierr = ISDestroy(&isnatural);CHKERRQ(ierr); } *ao = dd->ao; PetscFunctionReturn(0); }
/* DMDAGlobalToNatural_Create - Create the global to natural scatter object Collective on DMDA Input Parameter: . da - the distributed array context Level: developer Notes: This is an internal routine called by DMDAGlobalToNatural() to create the scatter context. .keywords: distributed array, global to local, begin .seealso: DMDAGlobalToNaturalBegin(), DMDAGlobalToNaturalEnd(), DMLocalToGlobalBegin(), DMDACreate2d(), DMGlobalToLocalBegin(), DMGlobalToLocalEnd(), DMDACreateNaturalVector() */ PetscErrorCode DMDAGlobalToNatural_Create(DM da) { PetscErrorCode ierr; PetscInt m,start,Nlocal; IS from,to; Vec global; DM_DA *dd = (DM_DA*)da->data; PetscFunctionBegin; PetscValidHeaderSpecific(da,DM_CLASSID,1); if (!dd->natural) SETERRQ(((PetscObject)da)->comm,PETSC_ERR_ORDER,"Natural layout vector not yet created; cannot scatter into it"); /* create the scatter context */ ierr = VecGetLocalSize(dd->natural,&m);CHKERRQ(ierr); ierr = VecGetOwnershipRange(dd->natural,&start,PETSC_NULL);CHKERRQ(ierr); ierr = DMDAGetNatural_Private(da,&Nlocal,&to);CHKERRQ(ierr); if (Nlocal != m) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Internal error: Nlocal %D local vector size %D",Nlocal,m); ierr = ISCreateStride(((PetscObject)da)->comm,m,start,1,&from);CHKERRQ(ierr); ierr = VecCreateMPIWithArray(((PetscObject)da)->comm,dd->w,dd->Nlocal,PETSC_DETERMINE,0,&global); ierr = VecScatterCreate(global,from,dd->natural,to,&dd->gton);CHKERRQ(ierr); ierr = VecDestroy(&global);CHKERRQ(ierr); ierr = ISDestroy(&from);CHKERRQ(ierr); ierr = ISDestroy(&to);CHKERRQ(ierr); PetscFunctionReturn(0); }