Actual source code: ex51.c

petsc-3.5.4 2015-05-23
Report Typos and Errors
  1: static char help[] = "Tests DMDAVecGetArrayDOF()\n";
  2: #include <petscdm.h>
  3: #include <petscdmda.h>

  5: int main(int argc, char *argv[])
  6: {
  7:   DM             da, daX, daY;
  8:   DMDALocalInfo  info;
  9:   MPI_Comm       commX, commY;
 10:   Vec            basisX, basisY;
 11:   PetscScalar    **arrayX, **arrayY;
 12:   const PetscInt *lx, *ly;
 13:   PetscInt       M     = 3, N = 3;
 14:   PetscInt       p     = 1;
 15:   PetscInt       numGP = 3;
 16:   PetscInt       dof   = 2*(p+1)*numGP;
 17:   PetscMPIInt    rank, subsize, subrank;

 20:   PetscInitialize(&argc,&argv,0,help);
 21:   MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
 22:   /* Create 2D DMDA */
 23:   DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DMDA_STENCIL_STAR, M, N, PETSC_DECIDE, PETSC_DECIDE, 1, 1, NULL, NULL, &da);
 24:   /* Create 1D DMDAs along two directions */
 25:   DMDAGetOwnershipRanges(da, &lx, &ly, NULL);
 26:   DMDAGetLocalInfo(da, &info);
 27:   DMDAGetProcessorSubsets(da, DMDA_X, &commX);
 28:   DMDAGetProcessorSubsets(da, DMDA_Y, &commY);
 29:   MPI_Comm_size(commX, &subsize);
 30:   MPI_Comm_rank(commX, &subrank);
 31:   PetscPrintf(PETSC_COMM_SELF, "[%d]X subrank: %d subsize: %d\n", rank, subrank, subsize);
 32:   MPI_Comm_size(commY, &subsize);
 33:   MPI_Comm_rank(commY, &subrank);
 34:   PetscPrintf(PETSC_COMM_SELF, "[%d]Y subrank: %d subsize: %d\n", rank, subrank, subsize);
 35:   DMDACreate1d(commX, DM_BOUNDARY_NONE, M, dof, 1, lx, &daX);
 36:   DMDACreate1d(commY, DM_BOUNDARY_NONE, N, dof, 1, ly, &daY);
 37:   /* Create 1D vectors for basis functions */
 38:   DMGetGlobalVector(daX, &basisX);
 39:   DMGetGlobalVector(daY, &basisY);
 40:   /* Extract basis functions */
 41:   DMDAVecGetArrayDOF(daX, basisX, &arrayX);
 42:   DMDAVecGetArrayDOF(daY, basisY, &arrayY);
 43:   /*arrayX[i][ndof]; */
 44:   /*arrayY[j][ndof]; */
 45:   DMDAVecRestoreArrayDOF(daX, basisX, &arrayX);
 46:   DMDAVecRestoreArrayDOF(daY, basisY, &arrayY);
 47:   /* Return basis vectors */
 48:   DMRestoreGlobalVector(daX, &basisX);
 49:   DMRestoreGlobalVector(daY, &basisY);
 50:   /* Cleanup */
 51:   DMDestroy(&daX);
 52:   DMDestroy(&daY);
 53:   DMDestroy(&da);
 54:   PetscFinalize();
 55:   return 0;
 56: }