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