Actual source code: ex19.c
2: static char help[] = "Tests DA 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 petscda.h
10: PetscErrorCode doit(DA da,Vec global)
11: {
13: PetscInt i,j,k,M,N,dof;
15: DAGetInfo(da,0,&M,&N,0,0,0,0,&dof,0,0,0);
16: {
17: struct {PetscScalar inside[dof];} **mystruct;
18: DAVecGetArray(da,global,(void*) &mystruct);
19: for ( i=0; i<N; i++) {
20: for ( j=0; j<M; j++) {
21: for ( k=0; k<dof; k++) {
22: PetscPrintf(PETSC_COMM_WORLD,"%d %d %G\n",i,j,mystruct[i][j].inside[0]);
23: mystruct[i][j].inside[1] = 2.1;
24: }
25: }
26: }
27: DAVecRestoreArray(da,global,(void*) &mystruct);
28: }
29: return(0);
30: }
34: int main(int argc,char **argv)
35: {
36: PetscInt dof = 2,M = 3,N = 3,m = PETSC_DECIDE,n = PETSC_DECIDE;
38: DA da;
39: Vec global,local;
40:
41: PetscInitialize(&argc,&argv,(char*)0,help);
43: PetscOptionsGetInt(0,"-dof",&dof,0);
44: /* Create distributed array and get vectors */
45: DACreate2d(PETSC_COMM_WORLD,DA_NONPERIODIC,DA_STENCIL_BOX,
46: M,N,m,n,dof,1,PETSC_NULL,PETSC_NULL,&da);
47: DACreateGlobalVector(da,&global);
48: DACreateLocalVector(da,&local);
50: doit(da,global);
53: VecView(global,0);
55: /* Free memory */
56: VecDestroy(local);
57: VecDestroy(global);
58: DADestroy(da);
59: PetscFinalize();
60: return 0;
61: }
62: