Actual source code: daview.c

  1: /*$Id: daview.c,v 1.50 2001/06/21 21:19:09 bsmith Exp $*/
  2: 
  3: /*
  4:   Code for manipulating distributed regular arrays in parallel.
  5: */

 7:  #include src/dm/da/daimpl.h

  9: #undef __FUNCT__  
 11: /*@C
 12:    DAView - Visualizes a distributed array object.

 14:    Collective on DA

 16:    Input Parameters:
 17: +  da - the distributed array
 18: -  ptr - an optional visualization context

 20:    Notes:
 21:    The available visualization contexts include
 22: +     PETSC_VIEWER_STDOUT_SELF - standard output (default)
 23: .     PETSC_VIEWER_STDOUT_WORLD - synchronized standard
 24:          output where only the first processor opens
 25:          the file.  All other processors send their 
 26:          data to the first processor to print. 
 27: -     PETSC_VIEWER_DRAW_WORLD - to default window

 29:    The user can open alternative visualization contexts with
 30: +    PetscViewerASCIIOpen() - Outputs vector to a specified file
 31: -    PetscViewerDrawOpen() - Outputs vector to an X window display

 33:    Default Output Format:
 34:   (for 3d arrays)
 35: .vb
 36:    Processor [proc] M  N  P  m  n  p  w  s
 37:    X range: xs xe, Y range: ys, ye, Z range: zs, ze

 39:    where
 40:       M,N,P - global dimension in each direction of the array
 41:       m,n,p - corresponding number of procs in each dimension 
 42:       w - number of degrees of freedom per node
 43:       s - stencil width
 44:       xs, xe - internal local starting/ending grid points
 45:                in x-direction, (augmented to handle multiple 
 46:                degrees of freedom per node)
 47:       ys, ye - local starting/ending grid points in y-direction
 48:       zs, ze - local starting/ending grid points in z-direction
 49: .ve

 51:    Options Database Key:
 52: .  -da_view - Calls DAView() at the conclusion of DACreate1d(),
 53:               DACreate2d(), and DACreate3d()

 55:    Level: beginner

 57:    Notes:
 58:    Use DAGetCorners() and DAGetGhostCorners() to get the starting
 59:    and ending grid points (ghost points) in each direction.

 61: .keywords: distributed array, view, visualize

 63: .seealso: PetscViewerASCIIOpen(), PetscViewerDrawOpen(), DAGetInfo(), DAGetCorners(),
 64:           DAGetGhostCorners()
 65: @*/
 66: int DAView(DA da,PetscViewer viewer)
 67: {
 68:   int        ierr,i,dof = da->w;
 69:   PetscTruth isascii,fieldsnamed = PETSC_FALSE;

 73:   if (!viewer) viewer = PETSC_VIEWER_STDOUT_(da->comm);

 76:   PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&isascii);
 77:   if (isascii) {
 78:     for (i=0; i<dof; i++) {
 79:       if (da->fieldname[i]) {
 80:         fieldsnamed = PETSC_TRUE;
 81:         break;
 82:       }
 83:     }
 84:     if (fieldsnamed) {
 85:       PetscViewerASCIIPrintf(viewer,"FieldNames: ");
 86:       for (i=0; i<dof; i++) {
 87:         if (da->fieldname[i]) {
 88:           PetscViewerASCIIPrintf(viewer,"%s ",da->fieldname[i]);
 89:         } else {
 90:           PetscViewerASCIIPrintf(viewer,"(not named) ");
 91:         }
 92:       }
 93:       PetscViewerASCIIPrintf(viewer,"n");
 94:     }
 95:   }
 96:   (*da->ops->view)(da,viewer);
 97:   return(0);
 98: }

100: #undef __FUNCT__  
102: /*@C
103:    DAGetInfo - Gets information about a given distributed array.

105:    Not Collective

107:    Input Parameter:
108: .  da - the distributed array

110:    Output Parameters:
111: +  dim     - dimension of the distributed array (1, 2, or 3)
112: .  M, N, P - global dimension in each direction of the array
113: .  m, n, p - corresponding number of procs in each dimension
114: .  dof     - number of degrees of freedom per node
115: .  s       - stencil width
116: .  wrap    - type of periodicity, on of DA_NONPERIODIC, DA_XPERIODIC, DA_YPERIODIC, 
117:              DA_XYPERIODIC, DA_XYZPERIODIC, DA_XZPERIODIC, DA_YZPERIODIC,DA_ZPERIODIC
118: -  st      - stencil type, either DA_STENCIL_STAR or DA_STENCIL_BOX

120:    Level: beginner
121:   
122:    Note:
123:    Use PETSC_NULL (PETSC_NULL_INTEGER in Fortran) in place of any output parameter that is not of interest.

125: .keywords: distributed array, get, information

127: .seealso: DAView(), DAGetCorners(), DAGetLocalInfo()
128: @*/
129: int DAGetInfo(DA da,int *dim,int *M,int *N,int *P,int *m,int *n,int *p,int *dof,int *s,DAPeriodicType *wrap,DAStencilType *st)
130: {
133:   if (dim)  *dim  = da->dim;
134:   if (M)    *M    = da->M;
135:   if (N)    *N    = da->N;
136:   if (P)    *P    = da->P;
137:   if (m)    *m    = da->m;
138:   if (n)    *n    = da->n;
139:   if (p)    *p    = da->p;
140:   if (dof)  *dof  = da->w;
141:   if (s)    *s    = da->s;
142:   if (wrap) *wrap = da->wrap;
143:   if (st)   *st   = da->stencil_type;
144:   return(0);
145: }

147: #undef __FUNCT__  
149: /*@C
150:    DAGetLocalInfo - Gets information about a given distributed array and this processors location in it

152:    Not Collective

154:    Input Parameter:
155: .  da - the distributed array

157:    Output Parameters:
158: .  dainfo - structure containing the information

160:    Level: beginner
161:   
162: .keywords: distributed array, get, information

164: .seealso: DAGetInfo(), DAGetCorners()
165: @*/
166: int DAGetLocalInfo(DA da,DALocalInfo *info)
167: {
168:   int w;

172:   info->da   = da;
173:   info->dim  = da->dim;
174:   info->mx   = da->M;
175:   info->my   = da->N;
176:   info->mz   = da->P;
177:   info->dof  = da->w;
178:   info->sw   = da->s;
179:   info->pt   = da->wrap;
180:   info->st   = da->stencil_type;

182:   /* since the xs, xe ... have all been multiplied by the number of degrees 
183:      of freedom per cell, w = da->w, we divide that out before returning.*/
184:   w = da->w;
185:   info->xs = da->xs/w;
186:   info->xm = (da->xe - da->xs)/w;
187:   /* the y and z have NOT been multiplied by w */
188:   info->ys = da->ys;
189:   info->ym = (da->ye - da->ys);
190:   info->zs = da->zs;
191:   info->zm = (da->ze - da->zs);

193:   info->gxs = da->Xs/w;
194:   info->gxm = (da->Xe - da->Xs)/w;
195:   /* the y and z have NOT been multiplied by w */
196:   info->gys = da->Ys;
197:   info->gym = (da->Ye - da->Ys);
198:   info->gzs = da->Zs;
199:   info->gzm = (da->Ze - da->Zs);
200:   return(0);
201: }


204: #undef __FUNCT__  
206: int DAView_Binary(DA da,PetscViewer viewer)
207: {
208:   int            rank,ierr;
209:   int            i,j,len,dim,m,n,p,dof,swidth,M,N,P;
210:   DAStencilType  stencil;
211:   DAPeriodicType periodic;
212:   MPI_Comm       comm;

215:   PetscObjectGetComm((PetscObject)da,&comm);

217:   DAGetInfo(da,&dim,&m,&n,&p,&M,&N,&P,&dof,&swidth,&periodic,&stencil);
218:   MPI_Comm_rank(comm,&rank);
219:   if (!rank) {
220:     FILE *file;

222:     PetscViewerBinaryGetInfoPointer(viewer,&file);
223:     if (file) {
224:       char           fieldname[256];

226:       fprintf(file,"-daload_info %d,%d,%d,%d,%d,%d,%d,%dn",dim,m,n,p,dof,swidth,stencil,periodic);
227:       for (i=0; i<dof; i++) {
228:         if (da->fieldname[i]) {
229:           PetscStrncpy(fieldname,da->fieldname[i],256);
230:           PetscStrlen(fieldname,&len);
231:           len  = PetscMin(256,len);
232:           for (j=0; j<len; j++) {
233:             if (fieldname[j] == ' ') fieldname[j] = '_';
234:           }
235:           fprintf(file,"-daload_fieldname_%d %sn",i,fieldname);
236:         }
237:       }
238:       if (da->coordinates) { /* save the DA's coordinates */
239:         fprintf(file,"-daload_coordinatesn");
240:       }
241:     }
242:   }

244:   /* save the coordinates if they exist to disk (in the natural ordering) */
245:   if (da->coordinates) {
246:     DA  dac;
247:     int *lx,*ly,*lz;
248:     Vec natural;

250:     /* create the appropriate DA to map to natural ordering */
251:     DAGetOwnershipRange(da,&lx,&ly,&lz);
252:     if (dim == 1) {
253:       DACreate1d(comm,DA_NONPERIODIC,m,dim,0,lx,&dac);
254:     } else if (dim == 2) {
255:       DACreate2d(comm,DA_NONPERIODIC,DA_STENCIL_BOX,m,n,M,N,dim,0,lx,ly,&dac);
256:     } else if (dim == 3) {
257:       DACreate3d(comm,DA_NONPERIODIC,DA_STENCIL_BOX,m,n,p,M,N,P,dim,0,lx,ly,lz,&dac);
258:     } else {
259:       SETERRQ1(1,"Dimension is not 1 2 or 3: %dn",dim);
260:     }
261:     DACreateNaturalVector(dac,&natural);
262:     DAGlobalToNaturalBegin(dac,da->coordinates,INSERT_VALUES,natural);
263:     DAGlobalToNaturalEnd(dac,da->coordinates,INSERT_VALUES,natural);
264:     VecView(natural,viewer);
265:     VecDestroy(natural);
266:     DADestroy(dac);
267:   }

269:   return(0);
270: }