Actual source code: ao.c

  1: #define PETSCDM_DLL

  3: /*  
  4:    Defines the abstract operations on AO (application orderings) 
  5: */
 6:  #include src/dm/ao/aoimpl.h

  8: /* Logging support */
  9: PetscCookie  AO_COOKIE = 0;
 10: PetscCookie  AODATA_COOKIE = 0;
 11: PetscEvent  AO_PetscToApplication = 0, AO_ApplicationToPetsc = 0;

 15: /*@C
 16:    AOView - Displays an application ordering.

 18:    Collective on AO and PetscViewer

 20:    Input Parameters:
 21: +  ao - the application ordering context
 22: -  viewer - viewer used for display

 24:    Level: intermediate

 26:    Note:
 27:    The available visualization contexts include
 28: +     PETSC_VIEWER_STDOUT_SELF - standard output (default)
 29: -     PETSC_VIEWER_STDOUT_WORLD - synchronized standard
 30:          output where only the first processor opens
 31:          the file.  All other processors send their 
 32:          data to the first processor to print. 

 34:    The user can open an alternative visualization context with
 35:    PetscViewerASCIIOpen() - output to a specified file.

 37: .keywords: application ordering

 39: .seealso: PetscViewerASCIIOpen()
 40: @*/
 41: PetscErrorCode  AOView(AO ao,PetscViewer viewer)
 42: {

 47:   if (!viewer) viewer = PETSC_VIEWER_STDOUT_(ao->comm);
 49:   (*ao->ops->view)(ao,viewer);
 50:   return(0);
 51: }

 55: /*@
 56:    AODestroy - Destroys an application ordering set.

 58:    Collective on AO

 60:    Input Parameters:
 61: .  ao - the application ordering context

 63:    Level: beginner

 65: .keywords: destroy, application ordering

 67: .seealso: AOCreateBasic()
 68: @*/
 69: PetscErrorCode  AODestroy(AO ao)
 70: {

 74:   if (!ao) return(0);
 76:   if (--ao->refct > 0) return(0);

 78:   /* if memory was published with AMS then destroy it */
 79:   PetscObjectDepublish(ao);

 81:   (*ao->ops->destroy)(ao);
 82:   PetscHeaderDestroy(ao);
 83:   return(0);
 84: }


 87: /* ---------------------------------------------------------------------*/
 90: /*@
 91:    AOPetscToApplicationIS - Maps an index set in the PETSc ordering to 
 92:    the application-defined ordering.

 94:    Collective on AO and IS

 96:    Input Parameters:
 97: +  ao - the application ordering context
 98: -  is - the index set

100:    Level: intermediate

102:    Notes:
103:    The index set cannot be of type stride or block
104:    
105:    Any integers in ia[] that are negative are left unchanged. This 
106:          allows one to convert, for example, neighbor lists that use negative
107:          entries to indicate nonexistent neighbors due to boundary conditions
108:          etc.

110: .keywords: application ordering, mapping

112: .seealso: AOCreateBasic(), AOView(),AOApplicationToPetsc(),
113:           AOApplicationToPetscIS(),AOPetscToApplication()
114: @*/
115: PetscErrorCode  AOPetscToApplicationIS(AO ao,IS is)
116: {
118:   PetscInt       n,*ia;
119:   PetscTruth     flag;

124:   ISBlock(is,&flag);
125:   if (flag) SETERRQ(PETSC_ERR_SUP,"Cannot translate block index sets");
126:   ISStride(is,&flag);
127:   if (flag) {
128:     ISStrideToGeneral(is);
129:   }

131:   ISGetLocalSize(is,&n);
132:   ISGetIndices(is,&ia);
133:   (*ao->ops->petsctoapplication)(ao,n,ia);
134:   ISRestoreIndices(is,&ia);
135:   return(0);
136: }

140: /*@
141:    AOApplicationToPetscIS - Maps an index set in the application-defined
142:    ordering to the PETSc ordering.

144:    Collective on AO and IS

146:    Input Parameters:
147: +  ao - the application ordering context
148: -  is - the index set

150:    Level: beginner

152:    Note:
153:    The index set cannot be of type stride or block
154:    
155:    Any integers in ia[] that are negative are left unchanged. This 
156:    allows one to convert, for example, neighbor lists that use negative
157:    entries to indicate nonexistent neighbors due to boundary conditions, etc.

159: .keywords: application ordering, mapping

161: .seealso: AOCreateBasic(), AOView(), AOPetscToApplication(),
162:           AOPetscToApplicationIS(), AOApplicationToPetsc()
163: @*/
164: PetscErrorCode  AOApplicationToPetscIS(AO ao,IS is)
165: {
167:   PetscInt       n,*ia;
168:   PetscTruth     flag;

173:   ISBlock(is,&flag);
174:   if (flag) SETERRQ(PETSC_ERR_SUP,"Cannot translate block index sets");
175:   ISStride(is,&flag);
176:   if (flag) {
177:     ISStrideToGeneral(is);
178:   }

180:   ISGetLocalSize(is,&n);
181:   ISGetIndices(is,&ia);
182:   (*ao->ops->applicationtopetsc)(ao,n,ia);
183:   ISRestoreIndices(is,&ia);
184:   return(0);
185: }

189: /*@
190:    AOPetscToApplication - Maps a set of integers in the PETSc ordering to 
191:    the application-defined ordering.

193:    Collective on AO

195:    Input Parameters:
196: +  ao - the application ordering context
197: .  n - the number of integers
198: -  ia - the integers

200:    Level: beginner

202:    Note:
203:    Any integers in ia[] that are negative are left unchanged. This 
204:    allows one to convert, for example, neighbor lists that use negative
205:    entries to indicate nonexistent neighbors due to boundary conditions, etc.

207: .keywords: application ordering, mapping

209: .seealso: AOCreateBasic(), AOView(),AOApplicationToPetsc(),
210:           AOPetscToApplicationIS(), AOApplicationToPetsc()
211: @*/
212: PetscErrorCode  AOPetscToApplication(AO ao,PetscInt n,PetscInt ia[])
213: {

219:   (*ao->ops->petsctoapplication)(ao,n,ia);
220:   return(0);
221: }

225: /*@
226:    AOApplicationToPetsc - Maps a set of integers in the application-defined
227:    ordering to the PETSc ordering.

229:    Collective on AO

231:    Input Parameters:
232: +  ao - the application ordering context
233: .  n - the number of integers
234: -  ia - the integers; these are replaced with their mapped value

236:    Level: beginner

238:    Note:
239:    Any integers in ia[] that are negative are left unchanged. This 
240:    allows one to convert, for example, neighbor lists that use negative
241:    entries to indicate nonexistent neighbors due to boundary conditions, etc.

243: .keywords: application ordering, mapping

245: .seealso: AOCreateBasic(), AOView(), AOPetscToApplication(),
246:           AOPetscToApplicationIS(), AOApplicationToPetsc()
247: @*/
248: PetscErrorCode  AOApplicationToPetsc(AO ao,PetscInt n,PetscInt ia[])
249: {

255:   (*ao->ops->applicationtopetsc)(ao,n,ia);
256:   return(0);
257: }

261: /*@
262:   AOPetscToApplicationPermuteInt - Permutes an array of blocks of integers
263:   in the PETSc ordering to the application-defined ordering.

265:   Collective on AO

267:   Input Parameters:
268: + ao    - The application ordering context
269: . block - The block size
270: - array - The integer array

272:   Level: beginner

274: .keywords: application ordering, mapping
275: .seealso: AOCreateBasic(), AOView(), AOApplicationToPetsc(), AOPetscToApplicationIS()
276: @*/
277: PetscErrorCode  AOPetscToApplicationPermuteInt(AO ao, PetscInt block, PetscInt array[])
278: {

284:   (*ao->ops->petsctoapplicationpermuteint)(ao, block, array);
285:   return(0);
286: }

290: /*@
291:   AOApplicationToPetscPermuteInt - Permutes an array of blocks of integers
292:   in the application-defined ordering to the PETSc ordering.

294:   Collective on AO

296:   Input Parameters:
297: + ao    - The application ordering context
298: . block - The block size
299: - array - The integer array

301:   Level: beginner

303: .keywords: application ordering, mapping

305: .seealso: AOCreateBasic(), AOView(), AOPetscToApplicationIS(), AOApplicationToPetsc()
306: @*/
307: PetscErrorCode  AOApplicationToPetscPermuteInt(AO ao, PetscInt block, PetscInt array[])
308: {

314:   (*ao->ops->applicationtopetscpermuteint)(ao, block, array);
315:   return(0);
316: }

320: /*@
321:   AOPetscToApplicationPermuteReal - Permutes an array of blocks of reals
322:   in the PETSc ordering to the application-defined ordering.

324:   Collective on AO

326:   Input Parameters:
327: + ao    - The application ordering context
328: . block - The block size
329: - array - The integer array

331:   Level: beginner

333: .keywords: application ordering, mapping

335: .seealso: AOCreateBasic(), AOView(), AOApplicationToPetsc(), AOPetscToApplicationIS()
336: @*/
337: PetscErrorCode  AOPetscToApplicationPermuteReal(AO ao, PetscInt block, PetscReal array[])
338: {

344:   (*ao->ops->petsctoapplicationpermutereal)(ao, block, array);
345:   return(0);
346: }

350: /*@
351:   AOApplicationToPetscPermuteReal - Permutes an array of blocks of reals
352:   in the application-defined ordering to the PETSc ordering.

354:   Collective on AO

356:   Input Parameters:
357: + ao    - The application ordering context
358: . block - The block size
359: - array - The integer array

361:   Level: beginner

363: .keywords: application ordering, mapping

365: .seealso: AOCreateBasic(), AOView(),AOApplicationToPetsc(), AOPetscToApplicationIS()
366: @*/
367: PetscErrorCode  AOApplicationToPetscPermuteReal(AO ao, PetscInt block, PetscReal array[])
368: {

374:   (*ao->ops->applicationtopetscpermutereal)(ao, block, array);
375:   return(0);
376: }