Actual source code: daview.c
1: /*$Id: daview.c,v 1.49 2001/03/30 16:27:15 bsmith Exp $*/
2:
3: /*
4: Code for manipulating distributed regular arrays in parallel.
5: */
7: #include "src/dm/da/daimpl.h" /*I "petscda.h" I*/
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) ",da->fieldname[i]);
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->dim = da->dim;
167: info->mx = da->M;
168: info->my = da->N;
169: info->mz = da->P;
170: info->dof = da->w;
171: info->sw = da->s;
172: info->pt = da->wrap;
173: info->st = da->stencil_type;
175: /* since the xs, xe ... have all been multiplied by the number of degrees
176: of freedom per cell, w = da->w, we divide that out before returning.*/
177: w = da->w;
178: info->xs = da->xs/w;
179: info->xm = (da->xe - da->xs)/w;
180: /* the y and z have NOT been multiplied by w */
181: info->ys = da->ys;
182: info->ym = (da->ye - da->ys);
183: info->zs = da->zs;
184: info->zm = (da->ze - da->zs);
186: return(0);
187: }
190: int DAView_Binary(DA da,PetscViewer viewer)
191: {
192: int rank,ierr;
193: int i,j,len,dim,m,n,p,dof,swidth,M,N,P;
194: DAStencilType stencil;
195: DAPeriodicType periodic;
196: MPI_Comm comm;
199: PetscObjectGetComm((PetscObject)da,&comm);
201: DAGetInfo(da,&dim,&m,&n,&p,&M,&N,&P,&dof,&swidth,&periodic,&stencil);
202: MPI_Comm_rank(comm,&rank);
203: if (!rank) {
204: FILE *file;
206: PetscViewerBinaryGetInfoPointer(viewer,&file);
207: if (file) {
208: char fieldname[256];
210: fprintf(file,"-daload_info %d,%d,%d,%d,%d,%d,%d,%dn",dim,m,n,p,dof,swidth,stencil,periodic);
211: for (i=0; i<dof; i++) {
212: if (da->fieldname[i]) {
213: PetscStrncpy(fieldname,da->fieldname[i],256);
214: PetscStrlen(fieldname,&len);
215: len = PetscMin(256,len);
216: for (j=0; j<len; j++) {
217: if (fieldname[j] == ' ') fieldname[j] = '_';
218: }
219: fprintf(file,"-daload_fieldname_%d %sn",i,fieldname);
220: }
221: }
222: if (da->coordinates) { /* save the DA's coordinates */
223: fprintf(file,"-daload_coordinatesn");
224: }
225: }
226: }
228: /* save the coordinates if they exist to disk (in the natural ordering) */
229: if (da->coordinates) {
230: DA dac;
231: int *lx,*ly,*lz;
232: Vec natural;
234: /* create the appropriate DA to map to natural ordering */
235: DAGetOwnershipRange(da,&lx,&ly,&lz);
236: if (dim == 1) {
237: DACreate1d(comm,DA_NONPERIODIC,m,dim,0,lx,&dac);
238: } else if (dim == 2) {
239: DACreate2d(comm,DA_NONPERIODIC,DA_STENCIL_BOX,m,n,M,N,dim,0,lx,ly,&dac);
240: } else if (dim == 3) {
241: DACreate3d(comm,DA_NONPERIODIC,DA_STENCIL_BOX,m,n,p,M,N,P,dim,0,lx,ly,lz,&dac);
242: } else {
243: SETERRQ1(1,"Dimension is not 1 2 or 3: %dn",dim);
244: }
245: DACreateNaturalVector(dac,&natural);
246: DAGlobalToNaturalBegin(dac,da->coordinates,INSERT_VALUES,natural);
247: DAGlobalToNaturalEnd(dac,da->coordinates,INSERT_VALUES,natural);
248: VecView(natural,viewer);
249: VecDestroy(natural);
250: DADestroy(dac);
251: }
253: return(0);
254: }