Actual source code: ex1.c

  1: /*$Id: ex1.c,v 1.9 2001/03/23 23:25:53 balay 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,Scalar *xy,Scalar *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);

 49:   PFApplyVec(pf,xy,u);

 51:   VecView(u,PETSC_VIEWER_DRAW_WORLD);

 53:   /* 
 54:      Free work space.  All PETSc objects should be destroyed when they
 55:      are no longer needed.
 56:   */
 57:   PFDestroy(pf);
 58:   DADestroy(da);
 59:   PetscFinalize();
 60:   return 0;
 61: }
 62: