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: #undef __FUNCT__  
 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: }

 45: #undef __FUNCT__  
 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:     Does NOT nclude the coordinates for the the ghost nodes

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

 63:   Level: intermediate

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

 67: .seealso: DAGetGhostCorners(), DASetCoordinates()
 68: @*/
 69: int DAGetCoordinates(DA da,Vec *c)
 70: {
 72: 
 74:   *c = da->coordinates;
 75:   return(0);
 76: }

 78: #undef __FUNCT__  
 80: /*@C
 81:    DASetFieldName - Sets the names of individual field components in multicomponent
 82:    vectors associated with a DA.

 84:    Not Collective

 86:    Input Parameters:
 87: +  da - the distributed array
 88: .  nf - field number for the DA (0, 1, ... dof-1), where dof indicates the 
 89:         number of degrees of freedom per node within the DA
 90: -  names - the name of the field (component)

 92:   Level: intermediate

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

 96: .seealso: DAGetFieldName()
 97: @*/
 98: int DASetFieldName(DA da,int nf,const char name[])
 99: {

103: 
105:   if (nf < 0 || nf >= da->w) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Invalid field number: %d",nf);
106:   if (da->fieldname[nf]) {PetscFree(da->fieldname[nf]);}
107: 
108:   PetscStrallocpy(name,&da->fieldname[nf]);
109:   return(0);
110: }

112: #undef __FUNCT__  
114: /*@C
115:    DAGetFieldName - Gets the names of individual field components in multicomponent
116:    vectors associated with a DA.

118:    Not Collective

120:    Input Parameter:
121: +  da - the distributed array
122: -  nf - field number for the DA (0, 1, ... dof-1), where dof indicates the 
123:         number of degrees of freedom per node within the DA

125:    Output Parameter:
126: .  names - the name of the field (component)

128:   Level: intermediate

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

132: .seealso: DASetFieldName()
133: @*/
134: int DAGetFieldName(DA da,int nf,char **name)
135: {
137: 
139:   if (nf < 0 || nf >= da->w) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Invalid field number: %d",nf);
140:   *name = da->fieldname[nf];
141:   return(0);
142: }

144: #undef __FUNCT__  
146: /*@
147:    DAGetCorners - Returns the global (x,y,z) indices of the lower left
148:    corner of the local region, excluding ghost points.

150:    Not Collective

152:    Input Parameter:
153: .  da - the distributed array

155:    Output Parameters:
156: +  x,y,z - the corner indices (where y and z are optional; these are used
157:            for 2D and 3D problems)
158: -  m,n,p - widths in the corresponding directions (where n and p are optional;
159:            these are used for 2D and 3D problems)

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

168:   Level: beginner

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

172: .seealso: DAGetGhostCorners()
173: @*/
174: int DAGetCorners(DA da,int *x,int *y,int *z,int *m,int *n,int *p)
175: {
176:   int w;

180:   /* since the xs, xe ... have all been multiplied by the number of degrees 
181:      of freedom per cell, w = da->w, we divide that out before returning.*/
182:   w = da->w;
183:   if (x) *x = da->xs/w; if(m) *m = (da->xe - da->xs)/w;
184:   /* the y and z have NOT been multiplied by w */
185:   if (y) *y = da->ys;   if (n) *n = (da->ye - da->ys);
186:   if (z) *z = da->zs;   if (p) *p = (da->ze - da->zs);
187:   return(0);
188: }