Actual source code: ex19.c
petsc-3.6.1 2015-08-06
2: static char help[] = "Tests DMDA with variable multiple degrees of freedom per node.\n\n";
4: /*
5: This code only compiles with gcc, since it is not ANSI C
6: */
8: #include <petscdm.h>
9: #include <petscdmda.h>
11: PetscErrorCode doit(DM da,Vec global)
12: {
14: PetscInt i,j,k,M,N,dof;
16: DMDAGetInfo(da,0,&M,&N,0,0,0,0,&dof,0,0,0,0,0);
17: {
18: struct {PetscScalar inside[dof];} **mystruct;
19: DMDAVecGetArrayRead(da,global,(void*) &mystruct);
20: for (i=0; i<N; i++) {
21: for (j=0; j<M; j++) {
22: for (k=0; k<dof; k++) {
23: PetscPrintf(PETSC_COMM_WORLD,"%D %D %g\n",i,j,(double)mystruct[i][j].inside[0]);
25: mystruct[i][j].inside[1] = 2.1;
26: }
27: }
28: }
29: DMDAVecRestoreArrayRead(da,global,(void*) &mystruct);
30: }
31: return(0);
32: }
36: int main(int argc,char **argv)
37: {
38: PetscInt dof = 2,M = 3,N = 3,m = PETSC_DECIDE,n = PETSC_DECIDE;
40: DM da;
41: Vec global,local;
43: PetscInitialize(&argc,&argv,(char*)0,help);
45: PetscOptionsGetInt(0,"-dof",&dof,0);
46: /* Create distributed array and get vectors */
47: DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE,DMDA_STENCIL_BOX,
48: M,N,m,n,dof,1,NULL,NULL,&da);
49: DMCreateGlobalVector(da,&global);
50: DMCreateLocalVector(da,&local);
52: doit(da,global);
55: VecView(global,0);
57: /* Free memory */
58: VecDestroy(&local);
59: VecDestroy(&global);
60: DMDestroy(&da);
61: PetscFinalize();
62: return 0;
63: }