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: PetscEvent  AO_PetscToApplication = 0, AO_ApplicationToPetsc = 0;

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

 17:    Collective on AO and PetscViewer

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

 23:    Level: intermediate

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

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

 36: .keywords: application ordering

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

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

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

 57:    Collective on AO

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

 62:    Level: beginner

 64: .keywords: destroy, application ordering

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

 73:   if (!ao) return(0);
 75:   if (--ao->refct > 0) return(0);

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

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


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

 93:    Collective on AO and IS

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

 99:    Level: intermediate

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

109: .keywords: application ordering, mapping

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

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

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

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

143:    Collective on AO and IS

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

149:    Level: beginner

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

158: .keywords: application ordering, mapping

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

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

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

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

192:    Collective on AO

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

199:    Level: beginner

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

206: .keywords: application ordering, mapping

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

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

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

228:    Collective on AO

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

235:    Level: beginner

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

242: .keywords: application ordering, mapping

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

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

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

264:   Collective on AO

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

271:   Level: beginner

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

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

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

293:   Collective on AO

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

300:   Level: beginner

302: .keywords: application ordering, mapping

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

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

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

323:   Collective on AO

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

330:   Level: beginner

332: .keywords: application ordering, mapping

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

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

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

353:   Collective on AO

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

360:   Level: beginner

362: .keywords: application ordering, mapping

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

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