Actual source code: ex1.c
1: /*$Id: ex1.c,v 1.11 2001/08/06 21:19:10 bsmith Exp $*/
3: /* Program usage: mpirun ex1 [-help] [all PETSc options] */
5: static char help[] = "Demonstrates various vector routines.nn";
7: /*T
8: Concepts: mathematical functions
9: Processors: n
10: T*/
12: /*
13: Include "petscpf.h" so that we can use pf functions and "petscda.h" so
14: we can use the PETSc distributed arrays
15: */
17: #include petscpf.h
18: #include petscda.h
20: int myfunction(void *ctx,int n,PetscScalar *xy,PetscScalar *u)
21: {
22: int i;
25: for (i=0; i<n; i++) {
26: u[2*i] = xy[2*i];
27: u[2*i+1] = xy[2*i+1];
28: }
29: return(0);
30: }
32: int main(int argc,char **argv)
33: {
34: Vec u,xy;
35: DA da;
36: int ierr, m = 10, n = 10, dof = 2;
37: PF pf;
39: PetscInitialize(&argc,&argv,(char*)0,help);
40:
41: DACreate2d(PETSC_COMM_WORLD,DA_NONPERIODIC,DA_STENCIL_BOX,m,n,PETSC_DECIDE,PETSC_DECIDE,dof,1,0,0,&da);
42: DASetUniformCoordinates(da,0.0,1.0,0.0,1.0,0.0,1.0);
43: DACreateGlobalVector(da,&u);
44: DAGetCoordinates(da,&xy);
46: DACreatePF(da,&pf);
47: PFSet(pf,myfunction,0,0,0,0);
48: PFSetFromOptions(pf);
50: PFApplyVec(pf,xy,u);
52: VecView(u,PETSC_VIEWER_DRAW_WORLD);
54: /*
55: Free work space. All PETSc objects should be destroyed when they
56: are no longer needed.
57: */
58: PFDestroy(pf);
59: DADestroy(da);
60: PetscFinalize();
61: return 0;
62: }
63: