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
8: #if defined(PETSC_HAVE_PNETCDF)
9: EXTERN_C_BEGIN
10: #include "pnetcdf.h"
11: EXTERN_C_END
12: #endif
16: /*@C
17: DAView - Visualizes a distributed array object.
19: Collective on DA
21: Input Parameters:
22: + da - the distributed array
23: - ptr - an optional visualization context
25: Notes:
26: The available visualization contexts include
27: + PETSC_VIEWER_STDOUT_SELF - standard output (default)
28: . PETSC_VIEWER_STDOUT_WORLD - synchronized standard
29: output where only the first processor opens
30: the file. All other processors send their
31: data to the first processor to print.
32: - PETSC_VIEWER_DRAW_WORLD - to default window
34: The user can open alternative visualization contexts with
35: + PetscViewerASCIIOpen() - Outputs vector to a specified file
36: - PetscViewerDrawOpen() - Outputs vector to an X window display
38: Default Output Format:
39: (for 3d arrays)
40: .vb
41: Processor [proc] M N P m n p w s
42: X range: xs xe, Y range: ys, ye, Z range: zs, ze
44: where
45: M,N,P - global dimension in each direction of the array
46: m,n,p - corresponding number of procs in each dimension
47: w - number of degrees of freedom per node
48: s - stencil width
49: xs, xe - internal local starting/ending grid points
50: in x-direction, (augmented to handle multiple
51: degrees of freedom per node)
52: ys, ye - local starting/ending grid points in y-direction
53: zs, ze - local starting/ending grid points in z-direction
54: .ve
56: Options Database Key:
57: . -da_view - Calls DAView() at the conclusion of DACreate1d(),
58: DACreate2d(), and DACreate3d()
60: Level: beginner
62: Notes:
63: Use DAGetCorners() and DAGetGhostCorners() to get the starting
64: and ending grid points (ghost points) in each direction.
66: .keywords: distributed array, view, visualize
68: .seealso: PetscViewerASCIIOpen(), PetscViewerDrawOpen(), DAGetInfo(), DAGetCorners(),
69: DAGetGhostCorners()
70: @*/
71: int DAView(DA da,PetscViewer viewer)
72: {
73: int ierr,i,dof = da->w;
74: PetscTruth isascii,fieldsnamed = PETSC_FALSE;
78: if (!viewer) viewer = PETSC_VIEWER_STDOUT_(da->comm);
81: PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&isascii);
82: if (isascii) {
83: for (i=0; i<dof; i++) {
84: if (da->fieldname[i]) {
85: fieldsnamed = PETSC_TRUE;
86: break;
87: }
88: }
89: if (fieldsnamed) {
90: PetscViewerASCIIPrintf(viewer,"FieldNames: ");
91: for (i=0; i<dof; i++) {
92: if (da->fieldname[i]) {
93: PetscViewerASCIIPrintf(viewer,"%s ",da->fieldname[i]);
94: } else {
95: PetscViewerASCIIPrintf(viewer,"(not named) ");
96: }
97: }
98: PetscViewerASCIIPrintf(viewer,"\n");
99: }
100: }
101: (*da->ops->view)(da,viewer);
102: return(0);
103: }
107: /*@C
108: DAGetInfo - Gets information about a given distributed array.
110: Not Collective
112: Input Parameter:
113: . da - the distributed array
115: Output Parameters:
116: + dim - dimension of the distributed array (1, 2, or 3)
117: . M, N, P - global dimension in each direction of the array
118: . m, n, p - corresponding number of procs in each dimension
119: . dof - number of degrees of freedom per node
120: . s - stencil width
121: . wrap - type of periodicity, on of DA_NONPERIODIC, DA_XPERIODIC, DA_YPERIODIC,
122: DA_XYPERIODIC, DA_XYZPERIODIC, DA_XZPERIODIC, DA_YZPERIODIC,DA_ZPERIODIC
123: - st - stencil type, either DA_STENCIL_STAR or DA_STENCIL_BOX
125: Level: beginner
126:
127: Note:
128: Use PETSC_NULL (PETSC_NULL_INTEGER in Fortran) in place of any output parameter that is not of interest.
130: .keywords: distributed array, get, information
132: .seealso: DAView(), DAGetCorners(), DAGetLocalInfo()
133: @*/
134: 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)
135: {
138: if (dim) *dim = da->dim;
139: if (M) *M = da->M;
140: if (N) *N = da->N;
141: if (P) *P = da->P;
142: if (m) *m = da->m;
143: if (n) *n = da->n;
144: if (p) *p = da->p;
145: if (dof) *dof = da->w;
146: if (s) *s = da->s;
147: if (wrap) *wrap = da->wrap;
148: if (st) *st = da->stencil_type;
149: return(0);
150: }
154: /*@C
155: DAGetLocalInfo - Gets information about a given distributed array and this processors location in it
157: Not Collective
159: Input Parameter:
160: . da - the distributed array
162: Output Parameters:
163: . dainfo - structure containing the information
165: Level: beginner
166:
167: .keywords: distributed array, get, information
169: .seealso: DAGetInfo(), DAGetCorners()
170: @*/
171: int DAGetLocalInfo(DA da,DALocalInfo *info)
172: {
173: int w;
177: info->da = da;
178: info->dim = da->dim;
179: info->mx = da->M;
180: info->my = da->N;
181: info->mz = da->P;
182: info->dof = da->w;
183: info->sw = da->s;
184: info->pt = da->wrap;
185: info->st = da->stencil_type;
187: /* since the xs, xe ... have all been multiplied by the number of degrees
188: of freedom per cell, w = da->w, we divide that out before returning.*/
189: w = da->w;
190: info->xs = da->xs/w;
191: info->xm = (da->xe - da->xs)/w;
192: /* the y and z have NOT been multiplied by w */
193: info->ys = da->ys;
194: info->ym = (da->ye - da->ys);
195: info->zs = da->zs;
196: info->zm = (da->ze - da->zs);
198: info->gxs = da->Xs/w;
199: info->gxm = (da->Xe - da->Xs)/w;
200: /* the y and z have NOT been multiplied by w */
201: info->gys = da->Ys;
202: info->gym = (da->Ye - da->Ys);
203: info->gzs = da->Zs;
204: info->gzm = (da->Ze - da->Zs);
205: return(0);
206: }
211: int DAView_Binary(DA da,PetscViewer viewer)
212: {
213: int rank,ierr;
214: int i,j,len,dim,m,n,p,dof,swidth,M,N,P;
215: DAStencilType stencil;
216: DAPeriodicType periodic;
217: MPI_Comm comm;
220: PetscObjectGetComm((PetscObject)da,&comm);
222: DAGetInfo(da,&dim,&m,&n,&p,&M,&N,&P,&dof,&swidth,&periodic,&stencil);
223: MPI_Comm_rank(comm,&rank);
224: if (!rank) {
225: FILE *file;
227: PetscViewerBinaryGetInfoPointer(viewer,&file);
228: if (file) {
229: char fieldname[256];
231: fprintf(file,"-daload_info %d,%d,%d,%d,%d,%d,%d,%d\n",dim,m,n,p,dof,swidth,stencil,periodic);
232: for (i=0; i<dof; i++) {
233: if (da->fieldname[i]) {
234: PetscStrncpy(fieldname,da->fieldname[i],256);
235: PetscStrlen(fieldname,&len);
236: len = PetscMin(256,len);
237: for (j=0; j<len; j++) {
238: if (fieldname[j] == ' ') fieldname[j] = '_';
239: }
240: fprintf(file,"-daload_fieldname_%d %s\n",i,fieldname);
241: }
242: }
243: if (da->coordinates) { /* save the DA's coordinates */
244: fprintf(file,"-daload_coordinates\n");
245: }
246: }
247: }
249: /* save the coordinates if they exist to disk (in the natural ordering) */
250: if (da->coordinates) {
251: DA dac;
252: int *lx,*ly,*lz;
253: Vec natural;
255: /* create the appropriate DA to map to natural ordering */
256: DAGetOwnershipRange(da,&lx,&ly,&lz);
257: if (dim == 1) {
258: DACreate1d(comm,DA_NONPERIODIC,m,dim,0,lx,&dac);
259: } else if (dim == 2) {
260: DACreate2d(comm,DA_NONPERIODIC,DA_STENCIL_BOX,m,n,M,N,dim,0,lx,ly,&dac);
261: } else if (dim == 3) {
262: DACreate3d(comm,DA_NONPERIODIC,DA_STENCIL_BOX,m,n,p,M,N,P,dim,0,lx,ly,lz,&dac);
263: } else {
264: SETERRQ1(1,"Dimension is not 1 2 or 3: %d\n",dim);
265: }
266: DACreateNaturalVector(dac,&natural);
267: PetscObjectSetOptionsPrefix((PetscObject)natural,"coor_");
268: DAGlobalToNaturalBegin(dac,da->coordinates,INSERT_VALUES,natural);
269: DAGlobalToNaturalEnd(dac,da->coordinates,INSERT_VALUES,natural);
270: VecView(natural,viewer);
271: VecDestroy(natural);
272: DADestroy(dac);
273: }
275: return(0);
276: }