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: #undef __FUNCT__
 22: int myfunction(void *ctx,int n,PetscScalar *xy,PetscScalar *u)
 23: {
 24:   int i;

 27:   for (i=0; i<n; i++) {
 28:     u[2*i] = xy[2*i];
 29:     u[2*i+1] = xy[2*i+1];
 30:   }
 31:   return(0);
 32: }

 34: #undef __FUNCT__
 36: int main(int argc,char **argv)
 37: {
 38:   Vec        u,xy;
 39:   DA         da;
 40:   int        ierr, m = 10, n = 10, dof = 2;
 41:   PF         pf;

 43:   PetscInitialize(&argc,&argv,(char*)0,help);
 44: 
 45:   DACreate2d(PETSC_COMM_WORLD,DA_NONPERIODIC,DA_STENCIL_BOX,m,n,PETSC_DECIDE,PETSC_DECIDE,dof,1,0,0,&da);
 46:   DASetUniformCoordinates(da,0.0,1.0,0.0,1.0,0.0,1.0);
 47:   DACreateGlobalVector(da,&u);
 48:   DAGetCoordinates(da,&xy);

 50:   DACreatePF(da,&pf);
 51:   PFSet(pf,myfunction,0,0,0,0);
 52:   PFSetFromOptions(pf);

 54:   PFApplyVec(pf,xy,u);

 56:   VecView(u,PETSC_VIEWER_DRAW_WORLD);

 58:   /* 
 59:      Free work space.  All PETSc objects should be destroyed when they
 60:      are no longer needed.
 61:   */
 62:   PFDestroy(pf);
 63:   DADestroy(da);
 64:   PetscFinalize();
 65:   return 0;
 66: }
 67: