Actual source code: dacorn.c
1: /*$Id: dacorn.c,v 1.38 2001/03/23 23:25:00 balay Exp $*/
2:
3: /*
4: Code for manipulating distributed regular arrays in parallel.
5: */
7: #include src/dm/da/daimpl.h
11: /*@
12: DASetCoordinates - Sets into the DA a vector that indicates the
13: coordinates of the local nodes (NOT including ghost nodes).
15: Not Collective
17: Input Parameter:
18: + da - the distributed array
19: - c - coordinate vector
21: Note:
22: The coordinates should NOT include those for all ghost points
24: Does NOT increase the reference count of this vector, so caller should NOT
25: destroy the vector.
27: Level: intermediate
29: .keywords: distributed array, get, corners, nodes, local indices, coordinates
31: .seealso: DAGetGhostCorners(), DAGetCoordinates()
32: @*/
33: int DASetCoordinates(DA da,Vec c)
34: {
40: da->coordinates = c;
41: VecSetBlockSize(c,da->dim);
42: return(0);
43: }
47: /*@
48: DAGetCoordinates - Gets the node coordinates associated with a DA.
50: Not Collective
52: Input Parameter:
53: . da - the distributed array
55: Output Parameter:
56: . c - coordinate vector
58: Note:
59: Each process has only the coordinates for its local nodes (does NOT have the
60: coordinates for the ghost nodes).
62: For two and three dimensions coordinates are interlaced (x_0,y_0,x_1,y_1,...)
63: and (x_0,y_0,z_0,x_1,y_1,z_1...)
65: You should not destroy or keep around this vector after the DA is destroyed.
67: Level: intermediate
69: .keywords: distributed array, get, corners, nodes, local indices, coordinates
71: .seealso: DAGetGhostCorners(), DASetCoordinates()
72: @*/
73: int DAGetCoordinates(DA da,Vec *c)
74: {
76:
79: *c = da->coordinates;
80: return(0);
81: }
85: /*@C
86: DASetFieldName - Sets the names of individual field components in multicomponent
87: vectors associated with a DA.
89: Not Collective
91: Input Parameters:
92: + da - the distributed array
93: . nf - field number for the DA (0, 1, ... dof-1), where dof indicates the
94: number of degrees of freedom per node within the DA
95: - names - the name of the field (component)
97: Level: intermediate
99: .keywords: distributed array, get, component name
101: .seealso: DAGetFieldName()
102: @*/
103: int DASetFieldName(DA da,int nf,const char name[])
104: {
108:
110: if (nf < 0 || nf >= da->w) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Invalid field number: %d",nf);
111: if (da->fieldname[nf]) {PetscFree(da->fieldname[nf]);}
112:
113: PetscStrallocpy(name,&da->fieldname[nf]);
114: return(0);
115: }
119: /*@C
120: DAGetFieldName - Gets the names of individual field components in multicomponent
121: vectors associated with a DA.
123: Not Collective
125: Input Parameter:
126: + da - the distributed array
127: - nf - field number for the DA (0, 1, ... dof-1), where dof indicates the
128: number of degrees of freedom per node within the DA
130: Output Parameter:
131: . names - the name of the field (component)
133: Level: intermediate
135: .keywords: distributed array, get, component name
137: .seealso: DASetFieldName()
138: @*/
139: int DAGetFieldName(DA da,int nf,char **name)
140: {
142:
145: if (nf < 0 || nf >= da->w) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Invalid field number: %d",nf);
146: *name = da->fieldname[nf];
147: return(0);
148: }
152: /*@
153: DAGetCorners - Returns the global (x,y,z) indices of the lower left
154: corner of the local region, excluding ghost points.
156: Not Collective
158: Input Parameter:
159: . da - the distributed array
161: Output Parameters:
162: + x,y,z - the corner indices (where y and z are optional; these are used
163: for 2D and 3D problems)
164: - m,n,p - widths in the corresponding directions (where n and p are optional;
165: these are used for 2D and 3D problems)
167: Note:
168: The corner information is independent of the number of degrees of
169: freedom per node set with the DACreateXX() routine. Thus the x, y, z, and
170: m, n, p can be thought of as coordinates on a logical grid, where each
171: grid point has (potentially) several degrees of freedom.
172: Any of y, z, n, and p can be passed in as PETSC_NULL if not needed.
174: Level: beginner
176: .keywords: distributed array, get, corners, nodes, local indices
178: .seealso: DAGetGhostCorners()
179: @*/
180: int DAGetCorners(DA da,int *x,int *y,int *z,int *m,int *n,int *p)
181: {
182: int w;
186: /* since the xs, xe ... have all been multiplied by the number of degrees
187: of freedom per cell, w = da->w, we divide that out before returning.*/
188: w = da->w;
189: if (x) *x = da->xs/w; if(m) *m = (da->xe - da->xs)/w;
190: /* the y and z have NOT been multiplied by w */
191: if (y) *y = da->ys; if (n) *n = (da->ye - da->ys);
192: if (z) *z = da->zs; if (p) *p = (da->ze - da->zs);
193: return(0);
194: }