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

  9: /*@
 10:    DASetCoordinates - Sets into the DA a vector that indicates the 
 11:       coordinates of the local nodes (NOT including ghost nodes).

 13:    Not Collective

 15:    Input Parameter:
 16: +  da - the distributed array
 17: -  c - coordinate vector

 19:    Note:
 20:     The coordinates should NOT include those for all ghost points

 22:      Does NOT increase the reference count of this vector, so caller should NOT
 23:   destroy the vector.

 25:   Level: intermediate

 27: .keywords: distributed array, get, corners, nodes, local indices, coordinates

 29: .seealso: DAGetGhostCorners(), DAGetCoordinates()
 30: @*/
 31: int DASetCoordinates(DA da,Vec c)
 32: {

 38:   da->coordinates = c;
 39:   VecSetBlockSize(c,da->dim);
 40:   return(0);
 41: }

 43: /*@
 44:    DAGetCoordinates - Gets the node coordinates associated with a DA.

 46:    Not Collective

 48:    Input Parameter:
 49: .  da - the distributed array

 51:    Output Parameter:
 52: .  c - coordinate vector

 54:    Note:
 55:     Does NOT nclude the coordinates for the the ghost nodes

 57:     You should not destroy or keep around this vector.

 59:   Level: intermediate

 61: .keywords: distributed array, get, corners, nodes, local indices, coordinates

 63: .seealso: DAGetGhostCorners(), DASetCoordinates()
 64: @*/
 65: int DAGetCoordinates(DA da,Vec *c)
 66: {
 68: 
 70:   *c = da->coordinates;
 71:   return(0);
 72: }

 74: /*@C
 75:    DASetFieldName - Sets the names of individual field components in multicomponent
 76:    vectors associated with a DA.

 78:    Not Collective

 80:    Input Parameters:
 81: +  da - the distributed array
 82: .  nf - field number for the DA (0, 1, ... dof-1), where dof indicates the 
 83:         number of degrees of freedom per node within the DA
 84: -  names - the name of the field (component)

 86:   Level: intermediate

 88: .keywords: distributed array, get, component name

 90: .seealso: DAGetFieldName()
 91: @*/
 92: int DASetFieldName(DA da,int nf,const char name[])
 93: {

 97: 
 99:   if (nf < 0 || nf >= da->w) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Invalid field number: %d",nf);
100:   if (da->fieldname[nf]) {PetscFree(da->fieldname[nf]);}
101: 
102:   PetscStrallocpy(name,&da->fieldname[nf]);
103:   return(0);
104: }

106: /*@C
107:    DAGetFieldName - Gets the names of individual field components in multicomponent
108:    vectors associated with a DA.

110:    Not Collective

112:    Input Parameter:
113: +  da - the distributed array
114: -  nf - field number for the DA (0, 1, ... dof-1), where dof indicates the 
115:         number of degrees of freedom per node within the DA

117:    Output Parameter:
118: .  names - the name of the field (component)

120:   Level: intermediate

122: .keywords: distributed array, get, component name

124: .seealso: DASetFieldName()
125: @*/
126: int DAGetFieldName(DA da,int nf,char **name)
127: {
129: 
131:   if (nf < 0 || nf >= da->w) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Invalid field number: %d",nf);
132:   *name = da->fieldname[nf];
133:   return(0);
134: }

136: /*@
137:    DAGetCorners - Returns the global (x,y,z) indices of the lower left
138:    corner of the local region, excluding ghost points.

140:    Not Collective

142:    Input Parameter:
143: .  da - the distributed array

145:    Output Parameters:
146: +  x,y,z - the corner indices (where y and z are optional; these are used
147:            for 2D and 3D problems)
148: -  m,n,p - widths in the corresponding directions (where n and p are optional;
149:            these are used for 2D and 3D problems)

151:    Note:
152:    The corner information is independent of the number of degrees of 
153:    freedom per node set with the DACreateXX() routine. Thus the x, y, z, and
154:    m, n, p can be thought of as coordinates on a logical grid, where each
155:    grid point has (potentially) several degrees of freedom.
156:    Any of y, z, n, and p can be passed in as PETSC_NULL if not needed.

158:   Level: beginner

160: .keywords: distributed array, get, corners, nodes, local indices

162: .seealso: DAGetGhostCorners()
163: @*/
164: int DAGetCorners(DA da,int *x,int *y,int *z,int *m,int *n,int *p)
165: {
166:   int w;

170:   /* since the xs, xe ... have all been multiplied by the number of degrees 
171:      of freedom per cell, w = da->w, we divide that out before returning.*/
172:   w = da->w;
173:   if (x) *x = da->xs/w; if(m) *m = (da->xe - da->xs)/w;
174:   /* the y and z have NOT been multiplied by w */
175:   if (y) *y = da->ys;   if (n) *n = (da->ye - da->ys);
176:   if (z) *z = da->zs;   if (p) *p = (da->ze - da->zs);
177:   return(0);
178: }