Actual source code: gr2.c

  1: #define PETSCDM_DLL

  3: /* 
  4:    Plots vectors obtained with DACreate2d()
  5: */

 7:  #include ../src/dm/da/daimpl.h
 8:  #include private/vecimpl.h

 10: #if defined(PETSC_HAVE_PNETCDF)
 12: #include "pnetcdf.h"
 14: #endif


 17: /*
 18:         The data that is passed into the graphics callback
 19: */
 20: typedef struct {
 21:   PetscInt     m,n,step,k;
 22:   PetscReal    min,max,scale;
 23:   PetscScalar  *xy,*v;
 24:   PetscTruth   showgrid;
 25: } ZoomCtx;

 27: /*
 28:        This does the drawing for one particular field 
 29:     in one particular set of coordinates. It is a callback
 30:     called from PetscDrawZoom()
 31: */
 34: PetscErrorCode VecView_MPI_Draw_DA2d_Zoom(PetscDraw draw,void *ctx)
 35: {
 36:   ZoomCtx        *zctx = (ZoomCtx*)ctx;
 38:   PetscInt       m,n,i,j,k,step,id,c1,c2,c3,c4;
 39:   PetscReal      s,min,x1,x2,x3,x4,y_1,y2,y3,y4;
 40:   PetscScalar   *v,*xy;

 43:   m    = zctx->m;
 44:   n    = zctx->n;
 45:   step = zctx->step;
 46:   k    = zctx->k;
 47:   v    = zctx->v;
 48:   xy   = zctx->xy;
 49:   s    = zctx->scale;
 50:   min  = zctx->min;
 51: 
 52:   /* PetscDraw the contour plot patch */
 53:   for (j=0; j<n-1; j++) {
 54:     for (i=0; i<m-1; i++) {
 55: #if !defined(PETSC_USE_COMPLEX)
 56:       id = i+j*m;    x1 = xy[2*id];y_1 = xy[2*id+1];c1 = (int)(PETSC_DRAW_BASIC_COLORS+s*(v[k+step*id]-min));
 57:       id = i+j*m+1;  x2 = xy[2*id];y2  = y_1;       c2 = (int)(PETSC_DRAW_BASIC_COLORS+s*(v[k+step*id]-min));
 58:       id = i+j*m+1+m;x3 = x2;      y3  = xy[2*id+1];c3 = (int)(PETSC_DRAW_BASIC_COLORS+s*(v[k+step*id]-min));
 59:       id = i+j*m+m;  x4 = x1;      y4  = y3;        c4 = (int)(PETSC_DRAW_BASIC_COLORS+s*(v[k+step*id]-min));
 60: #else
 61:       id = i+j*m;    x1 = PetscRealPart(xy[2*id]);y_1 = PetscRealPart(xy[2*id+1]);c1 = (int)(PETSC_DRAW_BASIC_COLORS+s*(PetscRealPart(v[k+step*id])-min));
 62:       id = i+j*m+1;  x2 = PetscRealPart(xy[2*id]);y2  = y_1;       c2 = (int)(PETSC_DRAW_BASIC_COLORS+s*(PetscRealPart(v[k+step*id])-min));
 63:       id = i+j*m+1+m;x3 = x2;      y3  = PetscRealPart(xy[2*id+1]);c3 = (int)(PETSC_DRAW_BASIC_COLORS+s*(PetscRealPart(v[k+step*id])-min));
 64:       id = i+j*m+m;  x4 = x1;      y4  = y3;        c4 = (int)(PETSC_DRAW_BASIC_COLORS+s*(PetscRealPart(v[k+step*id])-min));
 65: #endif
 66:       PetscDrawTriangle(draw,x1,y_1,x2,y2,x3,y3,c1,c2,c3);
 67:       PetscDrawTriangle(draw,x1,y_1,x3,y3,x4,y4,c1,c3,c4);
 68:       if (zctx->showgrid) {
 69:         PetscDrawLine(draw,x1,y_1,x2,y2,PETSC_DRAW_BLACK);
 70:         PetscDrawLine(draw,x2,y2,x3,y3,PETSC_DRAW_BLACK);
 71:         PetscDrawLine(draw,x3,y3,x4,y4,PETSC_DRAW_BLACK);
 72:         PetscDrawLine(draw,x4,y4,x1,y_1,PETSC_DRAW_BLACK);
 73:       }
 74:     }
 75:   }
 76:   return(0);
 77: }

 81: PetscErrorCode VecView_MPI_Draw_DA2d(Vec xin,PetscViewer viewer)
 82: {
 83:   DA                 da,dac,dag;
 84:   PetscErrorCode     ierr;
 85:   PetscMPIInt        rank;
 86:   PetscInt           igstart,N,s,M,istart,isize,jgstart,w;
 87:   const PetscInt     *lx,*ly;
 88:   PetscReal          coors[4],ymin,ymax,xmin,xmax;
 89:   PetscDraw          draw,popup;
 90:   PetscTruth         isnull,useports;
 91:   MPI_Comm           comm;
 92:   Vec                xlocal,xcoor,xcoorl;
 93:   DAPeriodicType     periodic;
 94:   DAStencilType      st;
 95:   ZoomCtx            zctx;
 96:   PetscDrawViewPorts *ports;
 97:   PetscViewerFormat  format;

100:   PetscViewerDrawGetDraw(viewer,0,&draw);
101:   PetscDrawIsNull(draw,&isnull); if (isnull) return(0);

103:   PetscObjectQuery((PetscObject)xin,"DA",(PetscObject*)&da);
104:   if (!da) SETERRQ(PETSC_ERR_ARG_WRONG,"Vector not generated from a DA");

106:   PetscObjectGetComm((PetscObject)xin,&comm);
107:   MPI_Comm_rank(comm,&rank);

109:   DAGetInfo(da,0,&M,&N,0,&zctx.m,&zctx.n,0,&w,&s,&periodic,&st);
110:   DAGetOwnershipRanges(da,&lx,&ly,PETSC_NULL);

112:   /* 
113:         Obtain a sequential vector that is going to contain the local values plus ONE layer of 
114:      ghosted values to draw the graphics from. We also need its corresponding DA (dac) that will
115:      update the local values pluse ONE layer of ghost values. 
116:   */
117:   PetscObjectQuery((PetscObject)da,"GraphicsGhosted",(PetscObject*)&xlocal);
118:   if (!xlocal) {
119:     if (periodic != DA_NONPERIODIC || s != 1 || st != DA_STENCIL_BOX) {
120:       /* 
121:          if original da is not of stencil width one, or periodic or not a box stencil then
122:          create a special DA to handle one level of ghost points for graphics
123:       */
124:       DACreate2d(comm,DA_NONPERIODIC,DA_STENCIL_BOX,M,N,zctx.m,zctx.n,w,1,lx,ly,&dac);
125:       PetscInfo(da,"Creating auxilary DA for managing graphics ghost points\n");
126:     } else {
127:       /* otherwise we can use the da we already have */
128:       dac = da;
129:     }
130:     /* create local vector for holding ghosted values used in graphics */
131:     DACreateLocalVector(dac,&xlocal);
132:     if (dac != da) {
133:       /* don't keep any public reference of this DA, is is only available through xlocal */
134:       DADestroy(dac);
135:     } else {
136:       /* remove association between xlocal and da, because below we compose in the opposite
137:          direction and if we left this connect we'd get a loop, so the objects could 
138:          never be destroyed */
139:       PetscObjectCompose((PetscObject)xlocal,"DA",0);
140:     }
141:     PetscObjectCompose((PetscObject)da,"GraphicsGhosted",(PetscObject)xlocal);
142:     PetscObjectDereference((PetscObject)xlocal);
143:   } else {
144:     if (periodic == DA_NONPERIODIC && s == 1 && st == DA_STENCIL_BOX) {
145:       dac = da;
146:     } else {
147:       PetscObjectQuery((PetscObject)xlocal,"DA",(PetscObject*)&dac);
148:     }
149:   }

151:   /*
152:       Get local (ghosted) values of vector
153:   */
154:   DAGlobalToLocalBegin(dac,xin,INSERT_VALUES,xlocal);
155:   DAGlobalToLocalEnd(dac,xin,INSERT_VALUES,xlocal);
156:   VecGetArray(xlocal,&zctx.v);

158:   /* get coordinates of nodes */
159:   DAGetCoordinates(da,&xcoor);
160:   if (!xcoor) {
161:     DASetUniformCoordinates(da,0.0,1.0,0.0,1.0,0.0,0.0);
162:     DAGetCoordinates(da,&xcoor);
163:   }

165:   /*
166:       Determine the min and max  coordinates in plot 
167:   */
168:   VecStrideMin(xcoor,0,PETSC_NULL,&xmin);
169:   VecStrideMax(xcoor,0,PETSC_NULL,&xmax);
170:   VecStrideMin(xcoor,1,PETSC_NULL,&ymin);
171:   VecStrideMax(xcoor,1,PETSC_NULL,&ymax);
172:   coors[0] = xmin - .05*(xmax- xmin); coors[2] = xmax + .05*(xmax - xmin);
173:   coors[1] = ymin - .05*(ymax- ymin); coors[3] = ymax + .05*(ymax - ymin);
174:   PetscInfo4(da,"Preparing DA 2d contour plot coordinates %G %G %G %G\n",coors[0],coors[1],coors[2],coors[3]);

176:   /*
177:        get local ghosted version of coordinates 
178:   */
179:   PetscObjectQuery((PetscObject)da,"GraphicsCoordinateGhosted",(PetscObject*)&xcoorl);
180:   if (!xcoorl) {
181:     /* create DA to get local version of graphics */
182:     DACreate2d(comm,DA_NONPERIODIC,DA_STENCIL_BOX,M,N,zctx.m,zctx.n,2,1,lx,ly,&dag);
183:     PetscInfo(dag,"Creating auxilary DA for managing graphics coordinates ghost points\n");
184:     DACreateLocalVector(dag,&xcoorl);
185:     PetscObjectCompose((PetscObject)da,"GraphicsCoordinateGhosted",(PetscObject)xcoorl);
186:     DADestroy(dag);/* dereference dag */
187:     PetscObjectDereference((PetscObject)xcoorl);
188:   } else {
189:     PetscObjectQuery((PetscObject)xcoorl,"DA",(PetscObject*)&dag);
190:   }
191:   DAGlobalToLocalBegin(dag,xcoor,INSERT_VALUES,xcoorl);
192:   DAGlobalToLocalEnd(dag,xcoor,INSERT_VALUES,xcoorl);
193:   VecGetArray(xcoorl,&zctx.xy);
194: 
195:   /*
196:         Get information about size of area each processor must do graphics for
197:   */
198:   DAGetInfo(dac,0,&M,&N,0,0,0,0,&zctx.step,0,&periodic,0);
199:   DAGetGhostCorners(dac,&igstart,&jgstart,0,&zctx.m,&zctx.n,0);
200:   DAGetCorners(dac,&istart,0,0,&isize,0,0);

202:   PetscOptionsHasName(PETSC_NULL,"-draw_contour_grid",&zctx.showgrid);

204:   PetscViewerGetFormat(viewer,&format);
205:   PetscOptionsHasName(PETSC_NULL,"-draw_ports",&useports);
206:   if (useports || format == PETSC_VIEWER_DRAW_PORTS){
207:     PetscDrawSynchronizedClear(draw);
208:     PetscDrawViewPortsCreate(draw,zctx.step,&ports);
209:   }
210:   /*
211:      Loop over each field; drawing each in a different window
212:   */
213:   for (zctx.k=0; zctx.k<zctx.step; zctx.k++) {
214:     if (useports) {
215:       PetscDrawViewPortsSet(ports,zctx.k);
216:     } else {
217:       PetscViewerDrawGetDraw(viewer,zctx.k,&draw);
218:       PetscDrawSynchronizedClear(draw);
219:     }

221:     /*
222:         Determine the min and max color in plot 
223:     */
224:     VecStrideMin(xin,zctx.k,PETSC_NULL,&zctx.min);
225:     VecStrideMax(xin,zctx.k,PETSC_NULL,&zctx.max);
226:     if (zctx.min == zctx.max) {
227:       zctx.min -= 1.e-12;
228:       zctx.max += 1.e-12;
229:     }

231:     if (!rank) {
232:       char *title;

234:       DAGetFieldName(da,zctx.k,&title);
235:       if (title) {
236:         PetscDrawSetTitle(draw,title);
237:       }
238:     }
239:     PetscDrawSetCoordinates(draw,coors[0],coors[1],coors[2],coors[3]);
240:     PetscInfo2(da,"DA 2d contour plot min %G max %G\n",zctx.min,zctx.max);

242:     PetscDrawGetPopup(draw,&popup);
243:     if (popup) {PetscDrawScalePopup(popup,zctx.min,zctx.max);}

245:     zctx.scale = (245.0 - PETSC_DRAW_BASIC_COLORS)/(zctx.max - zctx.min);

247:     PetscDrawZoom(draw,VecView_MPI_Draw_DA2d_Zoom,&zctx);
248:   }
249:   if (useports){
250:     PetscDrawViewPortsDestroy(ports);
251:   }

253:   VecRestoreArray(xcoorl,&zctx.xy);
254:   VecRestoreArray(xlocal,&zctx.v);
255:   VecDestroy(xcoor);
256:   return(0);
257: }

259: EXTERN PetscErrorCode VecView_MPI_HDF4_Ex(Vec X, PetscViewer viewer, PetscInt d, PetscInt *dims);

261: #if defined(PETSC_HAVE_HDF4)
264: PetscErrorCode VecView_MPI_HDF4_DA2d(Vec xin,PetscViewer viewer)
265: {
267:   PetscInt       dims[2];
268:   DA             da;
269:   Vec            natural;


273:   PetscObjectQuery((PetscObject)xin,"DA",(PetscObject*)&da);
274:   if (!da) SETERRQ(PETSC_ERR_ARG_WRONG,"Vector not generated from a DA");

276:   dims[0] = da->M;
277:   dims[1] = da->N;

279:   DACreateNaturalVector(da,&natural);
280:   DAGlobalToNaturalBegin(da,xin,INSERT_VALUES,natural);
281:   DAGlobalToNaturalEnd(da,xin,INSERT_VALUES,natural);
282:   VecView_MPI_HDF4_Ex(natural, viewer, 2, dims);
283:   VecDestroy(natural);
284:   return(0);
285: }
286: #endif

288: #if defined(PETSC_HAVE_PNETCDF)
291: PetscErrorCode VecView_MPI_Netcdf_DA(Vec xin,PetscViewer viewer)
292: {
294:   PetscInt       ncid,xstart,xdim_num=1;
295:   PetscInt       dim,m,n,p,dof,swidth,M,N,P;
296:   PetscInt       xin_dim,xin_id,xin_n,xin_N,xyz_dim,xyz_id,xyz_n,xyz_N;
297:   const PetscInt *lx,*ly,*lz;
298:   PetscScalar    *xarray;
299:   DA             da,dac;
300:   Vec            natural,xyz;
301:   DAStencilType  stencil;
302:   DAPeriodicType periodic;
303:   MPI_Comm       comm;

306:   PetscObjectGetComm((PetscObject)xin,&comm);
307:   PetscObjectQuery((PetscObject)xin,"DA",(PetscObject*)&da);
308:   if (!da) SETERRQ(PETSC_ERR_ARG_WRONG,"Vector not generated from a DA");
309:   DAGetInfo(da,&dim,&m,&n,&p,&M,&N,&P,&dof,&swidth,&periodic,&stencil);

311:   /* create the appropriate DA to map the coordinates to natural ordering */
312:   DAGetOwnershipRanges(da,&lx,&ly,&lz);
313:   if (dim == 1) {
314:     DACreate1d(comm,DA_NONPERIODIC,m,dim,0,lx,&dac);
315:   } else if (dim == 2) {
316:     DACreate2d(comm,DA_NONPERIODIC,DA_STENCIL_BOX,m,n,M,N,dim,0,lx,ly,&dac);
317:   } else if (dim == 3) {
318:     DACreate3d(comm,DA_NONPERIODIC,DA_STENCIL_BOX,m,n,p,M,N,P,dim,0,lx,ly,lz,&dac);
319:   } else {
320:     SETERRQ1(PETSC_ERR_ARG_CORRUPT,"Dimension is not 1 2 or 3: %D\n",dim);
321:   }
322:   DACreateNaturalVector(dac,&xyz);
323:   PetscObjectSetOptionsPrefix((PetscObject)xyz,"coor_");
324:   DAGlobalToNaturalBegin(dac,da->coordinates,INSERT_VALUES,xyz);
325:   DAGlobalToNaturalEnd(dac,da->coordinates,INSERT_VALUES,xyz);
326:   /* Create the DA vector in natural ordering */
327:   DACreateNaturalVector(da,&natural);
328:   DAGlobalToNaturalBegin(da,xin,INSERT_VALUES,natural);
329:   DAGlobalToNaturalEnd(da,xin,INSERT_VALUES,natural);
330:   /* Write the netCDF dataset */
331:   PetscViewerNetcdfGetID(viewer,&ncid);
332:   if (ncid < 0) SETERRQ(PETSC_ERR_ORDER,"First call PetscViewerNetcdfOpen to create NetCDF dataset");
333:   /* define dimensions */
334:   VecGetSize(xin,&xin_N);
335:   VecGetLocalSize(xin,&xin_n);
336:   ncmpi_def_dim(ncid,"PETSc_DA_Vector_Global_Size",xin_N,&xin_dim);
337:   VecGetSize(xyz,&xyz_N);
338:   VecGetLocalSize(xyz,&xyz_n);
339:   ncmpi_def_dim(ncid,"PETSc_DA_Coordinate_Vector_Global_Size",xyz_N,&xyz_dim);
340:   /* define variables */
341:   ncmpi_def_var(ncid,"PETSc_DA_Vector",NC_DOUBLE,xdim_num,&xin_dim,&xin_id);
342:   ncmpi_def_var(ncid,"PETSc_DA_Coordinate_Vector",NC_DOUBLE,xdim_num,&xyz_dim,&xyz_id);
343:   /* leave define mode */
344:   ncmpi_enddef(ncid);
345:   /* store the vector */
346:   VecGetArray(xin,&xarray);
347:   VecGetOwnershipRange(xin,&xstart,PETSC_NULL);
348:   ncmpi_put_vara_double_all(ncid,xin_id,(const MPI_Offset*)&xstart,(const MPI_Offset*)&xin_n,xarray);
349:   VecRestoreArray(xin,&xarray);
350:   /* store the coordinate vector */
351:   VecGetArray(xyz,&xarray);
352:   VecGetOwnershipRange(xyz,&xstart,PETSC_NULL);
353:   ncmpi_put_vara_double_all(ncid,xyz_id,(const MPI_Offset*)&xstart,(const MPI_Offset*)&xyz_n,xarray);
354:   VecRestoreArray(xyz,&xarray);
355:   /* destroy the vectors and da */
356:   VecDestroy(natural);
357:   VecDestroy(xyz);
358:   DADestroy(dac);
359:   return(0);
360: }
361: #endif

363: EXTERN PetscErrorCode VecView_MPI_Draw_DA1d(Vec,PetscViewer);

365: #if defined(PETSC_HAVE_MPIIO)
368: static PetscErrorCode DAArrayMPIIO(DA da,PetscViewer viewer,Vec xin,PetscTruth write)
369: {
371:   MPI_File       mfdes;
372:   PetscMPIInt    gsizes[4],lsizes[4],lstarts[4],asiz,dof;
373:   MPI_Datatype   view;
374:   PetscScalar    *array;
375:   MPI_Offset     off;
376:   MPI_Aint       ub,ul;
377:   PetscInt       type,rows,vecrows,tr[2];

380:   VecGetSize(xin,&vecrows);
381:   if (!write) {
382:     /* Read vector header. */
383:     PetscViewerBinaryRead(viewer,tr,2,PETSC_INT);
384:     type = tr[0];
385:     rows = tr[1];
386:     if (type != VEC_FILE_COOKIE) {
387:       SETERRQ(PETSC_ERR_ARG_WRONG,"Not vector next in file");
388:     }
389:     if (rows != vecrows) SETERRQ(PETSC_ERR_ARG_SIZ,"Vector in file not same size as DA vector");
390:   } else {
391:     tr[0] = VEC_FILE_COOKIE;
392:     tr[1] = vecrows;
393:     PetscViewerBinaryWrite(viewer,tr,2,PETSC_INT,PETSC_TRUE);
394:   }

396:   dof = PetscMPIIntCast(da->w);
397:   gsizes[0]  = dof; gsizes[1] = PetscMPIIntCast(da->M); gsizes[2] = PetscMPIIntCast(da->N); gsizes[3] = PetscMPIIntCast(da->P);
398:   lsizes[0]  = dof;lsizes[1] = PetscMPIIntCast((da->xe-da->xs)/dof); lsizes[2] = PetscMPIIntCast(da->ye-da->ys); lsizes[3] = PetscMPIIntCast(da->ze-da->zs);
399:   lstarts[0] = 0;  lstarts[1] = PetscMPIIntCast(da->xs/dof); lstarts[2] = PetscMPIIntCast(da->ys); lstarts[3] = PetscMPIIntCast(da->zs);
400:   MPI_Type_create_subarray(da->dim+1,gsizes,lsizes,lstarts,MPI_ORDER_FORTRAN,MPIU_SCALAR,&view);
401:   MPI_Type_commit(&view);
402: 
403:   PetscViewerBinaryGetMPIIODescriptor(viewer,&mfdes);
404:   PetscViewerBinaryGetMPIIOOffset(viewer,&off);
405:   MPI_File_set_view(mfdes,off,MPIU_SCALAR,view,(char *)"native",MPI_INFO_NULL);
406:   VecGetArray(xin,&array);
407:   asiz = lsizes[1]*(lsizes[2] > 0 ? lsizes[2] : 1)*(lsizes[3] > 0 ? lsizes[3] : 1)*dof;
408:   if (write) {
409:     MPIU_File_write_all(mfdes,array,asiz,MPIU_SCALAR,MPI_STATUS_IGNORE);
410:   } else {
411:     MPIU_File_read_all(mfdes,array,asiz,MPIU_SCALAR,MPI_STATUS_IGNORE);
412:   }
413:   MPI_Type_get_extent(view,&ul,&ub);
414:   PetscViewerBinaryAddMPIIOOffset(viewer,ub);
415:   VecRestoreArray(xin,&array);
416:   MPI_Type_free(&view);
417:   return(0);
418: }
419: #endif

424: PetscErrorCode  VecView_MPI_DA(Vec xin,PetscViewer viewer)
425: {
426:   DA             da;
428:   PetscInt       dim;
429:   Vec            natural;
430:   PetscTruth     isdraw;
431: #if defined(PETSC_HAVE_HDF4)
432:   PetscTruth     ishdf4;
433: #endif
434: #if defined(PETSC_HAVE_PNETCDF)
435:   PetscTruth     isnetcdf;
436: #endif
437:   const char     *prefix;

440:   PetscObjectQuery((PetscObject)xin,"DA",(PetscObject*)&da);
441:   if (!da) SETERRQ(PETSC_ERR_ARG_WRONG,"Vector not generated from a DA");
442:   PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_DRAW,&isdraw);
443: #if defined(PETSC_HAVE_HDF4)
444:   PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_HDF4,&ishdf4);
445: #endif
446: #if defined(PETSC_HAVE_PNETCDF)
447:   PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_NETCDF,&isnetcdf);
448: #endif
449:   if (isdraw) {
450:     DAGetInfo(da,&dim,0,0,0,0,0,0,0,0,0,0);
451:     if (dim == 1) {
452:       VecView_MPI_Draw_DA1d(xin,viewer);
453:     } else if (dim == 2) {
454:       VecView_MPI_Draw_DA2d(xin,viewer);
455:     } else {
456:       SETERRQ1(PETSC_ERR_SUP,"Cannot graphically view vector associated with this dimensional DA %D",dim);
457:     }
458: #if defined(PETSC_HAVE_HDF4)
459:   } else if (ishdf4) {
460:     DAGetInfo(da,&dim,0,0,0,0,0,0,0,0,0,0);
461:     switch (dim) {
462:     case 2:
463:       VecView_MPI_HDF4_DA2d(xin,viewer);
464:       break;
465:     default:
466:       SETERRQ1(PETSC_ERR_SUP,"Cannot view HDF4 vector associated with this dimensional DA %D",dim);
467:     }
468: #endif
469: #if defined(PETSC_HAVE_PNETCDF)
470:   } else if (isnetcdf) {
471:     VecView_MPI_Netcdf_DA(xin,viewer);
472: #endif
473:   } else {
474: #if defined(PETSC_HAVE_MPIIO)
475:     PetscTruth isbinary,isMPIIO;

477:     PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_BINARY,&isbinary);
478:     if (isbinary) {
479:       PetscViewerBinaryGetMPIIO(viewer,&isMPIIO);
480:       if (isMPIIO) {
481:        DAArrayMPIIO(da,viewer,xin,PETSC_TRUE);
482:        return(0);
483:       }
484:     }
485: #endif
486: 
487:     /* call viewer on natural ordering */
488:     PetscObjectGetOptionsPrefix((PetscObject)xin,&prefix);
489:     DACreateNaturalVector(da,&natural);
490:     PetscObjectSetOptionsPrefix((PetscObject)natural,prefix);
491:     DAGlobalToNaturalBegin(da,xin,INSERT_VALUES,natural);
492:     DAGlobalToNaturalEnd(da,xin,INSERT_VALUES,natural);
493:     PetscObjectName((PetscObject)xin);
494:     PetscObjectSetName((PetscObject)natural,((PetscObject)xin)->name);
495:     VecView(natural,viewer);
496:     VecDestroy(natural);
497:   }
498:   return(0);
499: }


506: PetscErrorCode  VecLoadIntoVector_Binary_DA(PetscViewer viewer,Vec xin)
507: {
508:   DA             da;
510:   Vec            natural;
511:   const char     *prefix;
512:   PetscInt       bs;
513:   PetscTruth     flag;
514: #if defined(PETSC_HAVE_MPIIO)
515:   PetscTruth     isMPIIO;
516: #endif

519:   PetscObjectQuery((PetscObject)xin,"DA",(PetscObject*)&da);
520:   if (!da) SETERRQ(PETSC_ERR_ARG_WRONG,"Vector not generated from a DA");

522: #if defined(PETSC_HAVE_MPIIO)
523:   PetscViewerBinaryGetMPIIO(viewer,&isMPIIO);
524:   if (isMPIIO) {
525:     DAArrayMPIIO(da,viewer,xin,PETSC_FALSE);
526:     return(0);
527:   }
528: #endif

530:   PetscObjectGetOptionsPrefix((PetscObject)xin,&prefix);
531:   DACreateNaturalVector(da,&natural);
532:   PetscObjectSetOptionsPrefix((PetscObject)natural,prefix);
533:   VecLoadIntoVector(viewer,natural);
534:   DANaturalToGlobalBegin(da,natural,INSERT_VALUES,xin);
535:   DANaturalToGlobalEnd(da,natural,INSERT_VALUES,xin);
536:   VecDestroy(natural);
537:   PetscInfo(xin,"Loading vector from natural ordering into DA\n");
538:   PetscOptionsGetInt(((PetscObject)xin)->prefix,"-vecload_block_size",&bs,&flag);
539:   if (flag && bs != da->w) {
540:     PetscInfo2(xin,"Block size in file %D not equal to DA's dof %D\n",bs,da->w);
541:   }
542:   return(0);
543: }