Actual source code: ao.c

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

  6: /* Logging support */
  7: PetscCookie AO_COOKIE = 0, AODATA_COOKIE = 0;
  8: PetscEvent  AO_PetscToApplication = 0, AO_ApplicationToPetsc = 0;

 12: /*@C
 13:    AOView - Displays an application ordering.

 15:    Collective on AO and PetscViewer

 17:    Input Parameters:
 18: +  ao - the application ordering context
 19: -  viewer - viewer used for display

 21:    Level: intermediate

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

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

 34: .keywords: application ordering

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

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

 52: /*@
 53:    AODestroy - Destroys an application ordering set.

 55:    Collective on AO

 57:    Input Parameters:
 58: .  ao - the application ordering context

 60:    Level: beginner

 62: .keywords: destroy, application ordering

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

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

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

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


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

 92:    Collective on AO and IS

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

 98:    Level: intermediate

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

108: .keywords: application ordering, mapping

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

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

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

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

142:    Collective on AO and IS

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

148:    Level: beginner

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

157: .keywords: application ordering, mapping

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

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

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

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

191:    Collective on AO

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

198:    Level: beginner

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

205: .keywords: application ordering, mapping

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

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

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

227:    Collective on AO

229:    Input Parameters:
230: +  ao - the application ordering context
231: .  n - the number of integers
232: -  ia - the integers

234:    Level: beginner

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

241: .keywords: application ordering, mapping

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

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

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

263:   Collective on AO

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

270:   Level: beginner

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

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

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

292:   Collective on AO

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

299:   Level: beginner

301: .keywords: application ordering, mapping

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

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

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

322:   Collective on AO

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

329:   Level: beginner

331: .keywords: application ordering, mapping

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

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

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

352:   Collective on AO

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

359:   Level: beginner

361: .keywords: application ordering, mapping

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

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