Actual source code: ex58.c

petsc-master 2016-09-25
Report Typos and Errors
  1: #include <petscsnes.h>
 2:  #include <petscdm.h>
 3:  #include <petscdmda.h>

  5: static const char help[] = "Parallel version of the minimum surface area problem in 2D using DMDA.\n\
  6:  It solves a system of nonlinear equations in mixed\n\
  7: complementarity form.This example is based on a\n\
  8: problem from the MINPACK-2 test suite.  Given a rectangular 2-D domain and\n\
  9: boundary values along the edges of the domain, the objective is to find the\n\
 10: surface with the minimal area that satisfies the boundary conditions.\n\
 11: This application solves this problem using complimentarity -- We are actually\n\
 12: solving the system  (grad f)_i >= 0, if x_i == l_i \n\
 13:                     (grad f)_i = 0, if l_i < x_i < u_i \n\
 14:                     (grad f)_i <= 0, if x_i == u_i  \n\
 15: where f is the function to be minimized. \n\
 16: \n\
 17: The command line options are:\n\
 18:   -da_grid_x <nx>, where <nx> = number of grid points in the 1st coordinate direction\n\
 19:   -da_grid_y <ny>, where <ny> = number of grid points in the 2nd coordinate direction\n\
 20:   -start <st>, where <st> =0 for zero vector, and an average of the boundary conditions otherwise\n\
 21:   -lb <value>, lower bound on the variables\n\
 22:   -ub <value>, upper bound on the variables\n\n";

 24: /*
 25:    User-defined application context - contains data needed by the
 26:    application-provided call-back routines, FormJacobian() and
 27:    FormFunction().
 28: */

 30: /*
 31:      This is a new version of the ../tests/ex8.c code

 33:      Run, for example, with the options ./ex58 -snes_vi_monitor -ksp_monitor -mg_levels_ksp_monitor -pc_type mg -pc_mg_levels 2 -pc_mg_galerkin pmat -ksp_type fgmres

 35:      Or to run with grid sequencing on the nonlinear problem (note that you do not need to provide the number of
 36:          multigrid levels, it will be determined automatically based on the number of refinements done)

 38:       ./ex58 -pc_type mg -ksp_monitor  -snes_view -pc_mg_galerkin pmat -snes_grid_sequence 3
 39:              -mg_levels_ksp_monitor -snes_vi_monitor -mg_levels_pc_type sor -pc_mg_type full


 42: */

 44: typedef struct {
 45:   PetscScalar *bottom, *top, *left, *right;
 46:   PetscScalar lb,ub;
 47: } AppCtx;


 50: /* -------- User-defined Routines --------- */

 52: extern PetscErrorCode FormBoundaryConditions(SNES,AppCtx**);
 53: extern PetscErrorCode DestroyBoundaryConditions(AppCtx**);
 54: extern PetscErrorCode ComputeInitialGuess(SNES, Vec,void*);
 55: extern PetscErrorCode FormGradient(SNES, Vec, Vec, void*);
 56: extern PetscErrorCode FormJacobian(SNES, Vec, Mat, Mat, void*);
 57: extern PetscErrorCode FormBounds(SNES,Vec,Vec);

 61: int main(int argc, char **argv)
 62: {
 64:   Vec            x,r;               /* solution and residual vectors */
 65:   SNES           snes;              /* nonlinear solver context */
 66:   Mat            J;                 /* Jacobian matrix */
 67:   DM             da;

 69:   PetscInitialize(&argc, &argv, (char*)0, help);if (ierr) return ierr;

 71:   /* Create distributed array to manage the 2d grid */
 72:   DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE,DMDA_STENCIL_BOX,4,4,PETSC_DECIDE,PETSC_DECIDE,1,1,NULL,NULL,&da);
 73:   DMSetFromOptions(da);
 74:   DMSetUp(da);

 76:   /* Extract global vectors from DMDA; */
 77:   DMCreateGlobalVector(da,&x);
 78:   VecDuplicate(x, &r);

 80:   DMSetMatType(da,MATAIJ);
 81:   DMCreateMatrix(da,&J);

 83:   /* Create nonlinear solver context */
 84:   SNESCreate(PETSC_COMM_WORLD,&snes);
 85:   SNESSetDM(snes,da);

 87:   /*  Set function evaluation and Jacobian evaluation  routines */
 88:   SNESSetFunction(snes,r,FormGradient,NULL);
 89:   SNESSetJacobian(snes,J,J,FormJacobian,NULL);

 91:   SNESSetComputeApplicationContext(snes,(PetscErrorCode (*)(SNES,void**))FormBoundaryConditions,(PetscErrorCode (*)(void**))DestroyBoundaryConditions);

 93:   SNESSetComputeInitialGuess(snes,ComputeInitialGuess,NULL);

 95:   SNESVISetComputeVariableBounds(snes,FormBounds);

 97:   SNESSetFromOptions(snes);

 99:   /* Solve the application */
100:   SNESSolve(snes,NULL,x);

102:   /* Free memory */
103:   VecDestroy(&x);
104:   VecDestroy(&r);
105:   MatDestroy(&J);
106:   SNESDestroy(&snes);

108:   /* Free user-created data structures */
109:   DMDestroy(&da);

111:   PetscFinalize();
112:   return ierr;
113: }

115: /* -------------------------------------------------------------------- */

119: /*  FormBounds - sets the upper and lower bounds

121:     Input Parameters:
122: .   snes  - the SNES context

124:     Output Parameters:
125: .   xl - lower bounds
126: .   xu - upper bounds
127: */
128: PetscErrorCode FormBounds(SNES snes, Vec xl, Vec xu)
129: {
131:   AppCtx         *ctx;

134:   SNESGetApplicationContext(snes,&ctx);
135:   VecSet(xl,ctx->lb);
136:   VecSet(xu,ctx->ub);
137:   return(0);
138: }

140: /* -------------------------------------------------------------------- */

144: /*  FormGradient - Evaluates gradient of f.

146:     Input Parameters:
147: .   snes  - the SNES context
148: .   X     - input vector
149: .   ptr   - optional user-defined context, as set by SNESSetFunction()

151:     Output Parameters:
152: .   G - vector containing the newly evaluated gradient
153: */
154: PetscErrorCode FormGradient(SNES snes, Vec X, Vec G, void *ptr)
155: {
156:   AppCtx      *user;
157:   int         ierr;
158:   PetscInt    i,j;
159:   PetscInt    mx, my;
160:   PetscScalar hx,hy, hydhx, hxdhy;
161:   PetscScalar f1,f2,f3,f4,f5,f6,d1,d2,d3,d4,d5,d6,d7,d8,xc,xl,xr,xt,xb,xlt,xrb;
162:   PetscScalar df1dxc,df2dxc,df3dxc,df4dxc,df5dxc,df6dxc;
163:   PetscScalar **g, **x;
164:   PetscInt    xs,xm,ys,ym;
165:   Vec         localX;
166:   DM          da;

169:   SNESGetDM(snes,&da);
170:   SNESGetApplicationContext(snes,(void**)&user);
171:   DMDAGetInfo(da,PETSC_IGNORE,&mx,&my,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE);
172:   hx   = 1.0/(mx+1);hy=1.0/(my+1); hydhx=hy/hx; hxdhy=hx/hy;

174:   VecSet(G,0.0);

176:   /* Get local vector */
177:   DMGetLocalVector(da,&localX);
178:   /* Get ghost points */
179:   DMGlobalToLocalBegin(da,X,INSERT_VALUES,localX);
180:   DMGlobalToLocalEnd(da,X,INSERT_VALUES,localX);
181:   /* Get pointer to local vector data */
182:   DMDAVecGetArray(da,localX, &x);
183:   DMDAVecGetArray(da,G, &g);

185:   DMDAGetCorners(da,&xs,&ys,NULL,&xm,&ym,NULL);
186:   /* Compute function over the locally owned part of the mesh */
187:   for (j=ys; j < ys+ym; j++) {
188:     for (i=xs; i< xs+xm; i++) {

190:       xc = x[j][i];
191:       xlt=xrb=xl=xr=xb=xt=xc;

193:       if (i==0) { /* left side */
194:         xl  = user->left[j+1];
195:         xlt = user->left[j+2];
196:       } else xl = x[j][i-1];

198:       if (j==0) { /* bottom side */
199:         xb  = user->bottom[i+1];
200:         xrb = user->bottom[i+2];
201:       } else xb = x[j-1][i];

203:       if (i+1 == mx) { /* right side */
204:         xr  = user->right[j+1];
205:         xrb = user->right[j];
206:       } else xr = x[j][i+1];

208:       if (j+1==0+my) { /* top side */
209:         xt  = user->top[i+1];
210:         xlt = user->top[i];
211:       } else xt = x[j+1][i];

213:       if (i>0 && j+1<my) xlt = x[j+1][i-1]; /* left top side */
214:       if (j>0 && i+1<mx) xrb = x[j-1][i+1]; /* right bottom */

216:       d1 = (xc-xl);
217:       d2 = (xc-xr);
218:       d3 = (xc-xt);
219:       d4 = (xc-xb);
220:       d5 = (xr-xrb);
221:       d6 = (xrb-xb);
222:       d7 = (xlt-xl);
223:       d8 = (xt-xlt);

225:       df1dxc = d1*hydhx;
226:       df2dxc = (d1*hydhx + d4*hxdhy);
227:       df3dxc = d3*hxdhy;
228:       df4dxc = (d2*hydhx + d3*hxdhy);
229:       df5dxc = d2*hydhx;
230:       df6dxc = d4*hxdhy;

232:       d1 /= hx;
233:       d2 /= hx;
234:       d3 /= hy;
235:       d4 /= hy;
236:       d5 /= hy;
237:       d6 /= hx;
238:       d7 /= hy;
239:       d8 /= hx;

241:       f1 = PetscSqrtScalar(1.0 + d1*d1 + d7*d7);
242:       f2 = PetscSqrtScalar(1.0 + d1*d1 + d4*d4);
243:       f3 = PetscSqrtScalar(1.0 + d3*d3 + d8*d8);
244:       f4 = PetscSqrtScalar(1.0 + d3*d3 + d2*d2);
245:       f5 = PetscSqrtScalar(1.0 + d2*d2 + d5*d5);
246:       f6 = PetscSqrtScalar(1.0 + d4*d4 + d6*d6);

248:       df1dxc /= f1;
249:       df2dxc /= f2;
250:       df3dxc /= f3;
251:       df4dxc /= f4;
252:       df5dxc /= f5;
253:       df6dxc /= f6;

255:       g[j][i] = (df1dxc+df2dxc+df3dxc+df4dxc+df5dxc+df6dxc)/2.0;

257:     }
258:   }

260:   /* Restore vectors */
261:   DMDAVecRestoreArray(da,localX, &x);
262:   DMDAVecRestoreArray(da,G, &g);
263:   DMRestoreLocalVector(da,&localX);
264:   PetscLogFlops(67*mx*my);
265:   return(0);
266: }

268: /* ------------------------------------------------------------------- */
271: /*
272:    FormJacobian - Evaluates Jacobian matrix.

274:    Input Parameters:
275: .  snes - SNES context
276: .  X    - input vector
277: .  ptr  - optional user-defined context, as set by SNESSetJacobian()

279:    Output Parameters:
280: .  tH    - Jacobian matrix

282: */
283: PetscErrorCode FormJacobian(SNES snes, Vec X, Mat H, Mat tHPre, void *ptr)
284: {
285:   AppCtx         *user;
287:   PetscInt       i,j,k;
288:   PetscInt       mx, my;
289:   MatStencil     row,col[7];
290:   PetscScalar    hx, hy, hydhx, hxdhy;
291:   PetscScalar    f1,f2,f3,f4,f5,f6,d1,d2,d3,d4,d5,d6,d7,d8,xc,xl,xr,xt,xb,xlt,xrb;
292:   PetscScalar    hl,hr,ht,hb,hc,htl,hbr;
293:   PetscScalar    **x, v[7];
294:   PetscBool      assembled;
295:   PetscInt       xs,xm,ys,ym;
296:   Vec            localX;
297:   DM             da;

300:   SNESGetDM(snes,&da);
301:   SNESGetApplicationContext(snes,(void**)&user);
302:   DMDAGetInfo(da,PETSC_IGNORE,&mx,&my,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE);
303:   hx   = 1.0/(mx+1); hy=1.0/(my+1); hydhx=hy/hx; hxdhy=hx/hy;

305: /* Set various matrix options */
306:   MatAssembled(H,&assembled);
307:   if (assembled) {MatZeroEntries(H);}

309:   /* Get local vector */
310:   DMGetLocalVector(da,&localX);
311:   /* Get ghost points */
312:   DMGlobalToLocalBegin(da,X,INSERT_VALUES,localX);
313:   DMGlobalToLocalEnd(da,X,INSERT_VALUES,localX);

315:   /* Get pointers to vector data */
316:   DMDAVecGetArray(da,localX, &x);

318:   DMDAGetCorners(da,&xs,&ys,NULL,&xm,&ym,NULL);
319:   /* Compute Jacobian over the locally owned part of the mesh */
320:   for (j=ys; j< ys+ym; j++) {
321:     for (i=xs; i< xs+xm; i++) {
322:       xc = x[j][i];
323:       xlt=xrb=xl=xr=xb=xt=xc;

325:       /* Left */
326:       if (i==0) {
327:         xl  = user->left[j+1];
328:         xlt = user->left[j+2];
329:       } else xl = x[j][i-1];

331:       /* Bottom */
332:       if (j==0) {
333:         xb  =user->bottom[i+1];
334:         xrb = user->bottom[i+2];
335:       } else xb = x[j-1][i];

337:       /* Right */
338:       if (i+1 == mx) {
339:         xr  =user->right[j+1];
340:         xrb = user->right[j];
341:       } else xr = x[j][i+1];

343:       /* Top */
344:       if (j+1==my) {
345:         xt  =user->top[i+1];
346:         xlt = user->top[i];
347:       } else xt = x[j+1][i];

349:       /* Top left */
350:       if (i>0 && j+1<my) xlt = x[j+1][i-1];

352:       /* Bottom right */
353:       if (j>0 && i+1<mx) xrb = x[j-1][i+1];

355:       d1 = (xc-xl)/hx;
356:       d2 = (xc-xr)/hx;
357:       d3 = (xc-xt)/hy;
358:       d4 = (xc-xb)/hy;
359:       d5 = (xrb-xr)/hy;
360:       d6 = (xrb-xb)/hx;
361:       d7 = (xlt-xl)/hy;
362:       d8 = (xlt-xt)/hx;

364:       f1 = PetscSqrtScalar(1.0 + d1*d1 + d7*d7);
365:       f2 = PetscSqrtScalar(1.0 + d1*d1 + d4*d4);
366:       f3 = PetscSqrtScalar(1.0 + d3*d3 + d8*d8);
367:       f4 = PetscSqrtScalar(1.0 + d3*d3 + d2*d2);
368:       f5 = PetscSqrtScalar(1.0 + d2*d2 + d5*d5);
369:       f6 = PetscSqrtScalar(1.0 + d4*d4 + d6*d6);


372:       hl = (-hydhx*(1.0+d7*d7)+d1*d7)/(f1*f1*f1)+
373:            (-hydhx*(1.0+d4*d4)+d1*d4)/(f2*f2*f2);
374:       hr = (-hydhx*(1.0+d5*d5)+d2*d5)/(f5*f5*f5)+
375:            (-hydhx*(1.0+d3*d3)+d2*d3)/(f4*f4*f4);
376:       ht = (-hxdhy*(1.0+d8*d8)+d3*d8)/(f3*f3*f3)+
377:            (-hxdhy*(1.0+d2*d2)+d2*d3)/(f4*f4*f4);
378:       hb = (-hxdhy*(1.0+d6*d6)+d4*d6)/(f6*f6*f6)+
379:            (-hxdhy*(1.0+d1*d1)+d1*d4)/(f2*f2*f2);

381:       hbr = -d2*d5/(f5*f5*f5) - d4*d6/(f6*f6*f6);
382:       htl = -d1*d7/(f1*f1*f1) - d3*d8/(f3*f3*f3);

384:       hc = hydhx*(1.0+d7*d7)/(f1*f1*f1) + hxdhy*(1.0+d8*d8)/(f3*f3*f3) +
385:            hydhx*(1.0+d5*d5)/(f5*f5*f5) + hxdhy*(1.0+d6*d6)/(f6*f6*f6) +
386:            (hxdhy*(1.0+d1*d1)+hydhx*(1.0+d4*d4)-2.0*d1*d4)/(f2*f2*f2) +
387:            (hxdhy*(1.0+d2*d2)+hydhx*(1.0+d3*d3)-2.0*d2*d3)/(f4*f4*f4);

389:       hl/=2.0; hr/=2.0; ht/=2.0; hb/=2.0; hbr/=2.0; htl/=2.0;  hc/=2.0;

391:       k     =0;
392:       row.i = i;row.j= j;
393:       /* Bottom */
394:       if (j>0) {
395:         v[k]     =hb;
396:         col[k].i = i; col[k].j=j-1; k++;
397:       }

399:       /* Bottom right */
400:       if (j>0 && i < mx -1) {
401:         v[k]     =hbr;
402:         col[k].i = i+1; col[k].j = j-1; k++;
403:       }

405:       /* left */
406:       if (i>0) {
407:         v[k]     = hl;
408:         col[k].i = i-1; col[k].j = j; k++;
409:       }

411:       /* Centre */
412:       v[k]= hc; col[k].i= row.i; col[k].j = row.j; k++;

414:       /* Right */
415:       if (i < mx-1) {
416:         v[k]    = hr;
417:         col[k].i= i+1; col[k].j = j;k++;
418:       }

420:       /* Top left */
421:       if (i>0 && j < my-1) {
422:         v[k]     = htl;
423:         col[k].i = i-1;col[k].j = j+1; k++;
424:       }

426:       /* Top */
427:       if (j < my-1) {
428:         v[k]     = ht;
429:         col[k].i = i; col[k].j = j+1; k++;
430:       }

432:       MatSetValuesStencil(H,1,&row,k,col,v,INSERT_VALUES);
433:     }
434:   }

436:   /* Assemble the matrix */
437:   MatAssemblyBegin(H,MAT_FINAL_ASSEMBLY);
438:   DMDAVecRestoreArray(da,localX,&x);
439:   MatAssemblyEnd(H,MAT_FINAL_ASSEMBLY);
440:   DMRestoreLocalVector(da,&localX);

442:   PetscLogFlops(199*mx*my);
443:   return(0);
444: }

446: /* ------------------------------------------------------------------- */
449: /*
450:    FormBoundaryConditions -  Calculates the boundary conditions for
451:    the region.

453:    Input Parameter:
454: .  user - user-defined application context

456:    Output Parameter:
457: .  user - user-defined application context
458: */
459: PetscErrorCode FormBoundaryConditions(SNES snes,AppCtx **ouser)
460: {
462:   PetscInt       i,j,k,limit=0,maxits=5;
463:   PetscInt       mx,my;
464:   PetscInt       bsize=0, lsize=0, tsize=0, rsize=0;
465:   PetscScalar    one  =1.0, two=2.0, three=3.0;
466:   PetscScalar    det,hx,hy,xt=0,yt=0;
467:   PetscReal      fnorm, tol=1e-10;
468:   PetscScalar    u1,u2,nf1,nf2,njac11,njac12,njac21,njac22;
469:   PetscScalar    b=-0.5, t=0.5, l=-0.5, r=0.5;
470:   PetscScalar    *boundary;
471:   AppCtx         *user;
472:   DM             da;

475:   SNESGetDM(snes,&da);
476:   PetscNew(&user);
477:   *ouser   = user;
478:   user->lb = .05;
479:   user->ub = PETSC_INFINITY;
480:   DMDAGetInfo(da,PETSC_IGNORE,&mx,&my,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE);

482:   /* Check if lower and upper bounds are set */
483:   PetscOptionsGetScalar(NULL,NULL, "-lb", &user->lb, 0);
484:   PetscOptionsGetScalar(NULL,NULL, "-ub", &user->ub, 0);
485:   bsize=mx+2; lsize=my+2; rsize=my+2; tsize=mx+2;

487:   PetscMalloc1(bsize, &user->bottom);
488:   PetscMalloc1(tsize, &user->top);
489:   PetscMalloc1(lsize, &user->left);
490:   PetscMalloc1(rsize, &user->right);

492:   hx= (r-l)/(mx+1.0); hy=(t-b)/(my+1.0);

494:   for (j=0; j<4; j++) {
495:     if (j==0) {
496:       yt       = b;
497:       xt       = l;
498:       limit    = bsize;
499:       boundary = user->bottom;
500:     } else if (j==1) {
501:       yt       = t;
502:       xt       = l;
503:       limit    = tsize;
504:       boundary = user->top;
505:     } else if (j==2) {
506:       yt       = b;
507:       xt       = l;
508:       limit    = lsize;
509:       boundary = user->left;
510:     } else { /* if  (j==3) */
511:       yt       = b;
512:       xt       = r;
513:       limit    = rsize;
514:       boundary = user->right;
515:     }

517:     for (i=0; i<limit; i++) {
518:       u1=xt;
519:       u2=-yt;
520:       for (k=0; k<maxits; k++) {
521:         nf1   = u1 + u1*u2*u2 - u1*u1*u1/three-xt;
522:         nf2   = -u2 - u1*u1*u2 + u2*u2*u2/three-yt;
523:         fnorm = PetscRealPart(PetscSqrtScalar(nf1*nf1+nf2*nf2));
524:         if (fnorm <= tol) break;
525:         njac11=one+u2*u2-u1*u1;
526:         njac12=two*u1*u2;
527:         njac21=-two*u1*u2;
528:         njac22=-one - u1*u1 + u2*u2;
529:         det   = njac11*njac22-njac21*njac12;
530:         u1    = u1-(njac22*nf1-njac12*nf2)/det;
531:         u2    = u2-(njac11*nf2-njac21*nf1)/det;
532:       }

534:       boundary[i]=u1*u1-u2*u2;
535:       if (j==0 || j==1) xt=xt+hx;
536:       else yt=yt+hy; /* if (j==2 || j==3) */
537:     }
538:   }
539:   return(0);
540: }

544: PetscErrorCode DestroyBoundaryConditions(AppCtx **ouser)
545: {
547:   AppCtx         *user = *ouser;

550:   PetscFree(user->bottom);
551:   PetscFree(user->top);
552:   PetscFree(user->left);
553:   PetscFree(user->right);
554:   PetscFree(*ouser);
555:   return(0);
556: }


559: /* ------------------------------------------------------------------- */
562: /*
563:    ComputeInitialGuess - Calculates the initial guess

565:    Input Parameters:
566: .  user - user-defined application context
567: .  X - vector for initial guess

569:    Output Parameters:
570: .  X - newly computed initial guess
571: */
572: PetscErrorCode ComputeInitialGuess(SNES snes, Vec X,void *dummy)
573: {
575:   PetscInt       i,j,mx,my;
576:   DM             da;
577:   AppCtx         *user;
578:   PetscScalar    **x;
579:   PetscInt       xs,xm,ys,ym;

582:   SNESGetDM(snes,&da);
583:   SNESGetApplicationContext(snes,(void**)&user);

585:   DMDAGetCorners(da,&xs,&ys,NULL,&xm,&ym,NULL);
586:   DMDAGetInfo(da,PETSC_IGNORE,&mx,&my,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE);

588:   /* Get pointers to vector data */
589:   DMDAVecGetArray(da,X,&x);
590:   /* Perform local computations */
591:   for (j=ys; j<ys+ym; j++) {
592:     for (i=xs; i< xs+xm; i++) {
593:       x[j][i] = (((j+1.0)*user->bottom[i+1]+(my-j+1.0)*user->top[i+1])/(my+2.0)+((i+1.0)*user->left[j+1]+(mx-i+1.0)*user->right[j+1])/(mx+2.0))/2.0;
594:     }
595:   }
596:   /* Restore vectors */
597:   DMDAVecRestoreArray(da,X,&x);
598:   return(0);
599: }