Actual source code: ex19.c
1: /*$Id: ex1.c,v 1.49 2001/08/07 03:04:42 balay Exp $*/
3: static char help[] = "Tests DA with variable multiple degrees of freedom per node.\n\n";
5: /*
6: This code only compiles with gcc, since it is not ANSI C
7: */
9: #include petscda.h
10: #include petscsys.h
12: int doit(DA da,Vec global)
13: {
14: int ierr,i,j,k,M,N,dof;
16: DAGetInfo(da,0,&M,&N,0,0,0,0,&dof,0,0,0);
17: {
18: struct {PetscScalar inside[dof];} **mystruct;
19: DAVecGetArray(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: printf("%d %d %g\n",i,j,mystruct[i][j].inside[0]);
24: mystruct[i][j].inside[1] = 2.1;
25: }
26: }
27: }
28: DAVecRestoreArray(da,global,(void*) &mystruct);
29: }
30: return(0);
31: }
35: int main(int argc,char **argv)
36: {
37: int i,j,k,dof = 2, rank,M = 3,N = 3,m = PETSC_DECIDE,n = PETSC_DECIDE,ierr;
38: DA da;
39: PetscScalar value;
40: Vec global,local;
41:
42: PetscInitialize(&argc,&argv,(char*)0,help);
44: PetscOptionsGetInt(0,"-dof",&dof,0);
45: /* Create distributed array and get vectors */
46: DACreate2d(PETSC_COMM_WORLD,DA_NONPERIODIC,DA_STENCIL_BOX,
47: M,N,m,n,dof,1,PETSC_NULL,PETSC_NULL,&da);
48: DACreateGlobalVector(da,&global);
49: DACreateLocalVector(da,&local);
51: doit(da,global);
54: VecView(global,0);
56: /* Free memory */
57: VecDestroy(local);
58: VecDestroy(global);
59: DADestroy(da);
60: PetscFinalize();
61: return 0;
62: }
63: