Actual source code: ao.c


  2: /*
  3:    Defines the abstract operations on AO (application orderings)
  4: */
  5: #include <../src/vec/is/ao/aoimpl.h>

  7: /* Logging support */
  8: PetscClassId  AO_CLASSID;
  9: PetscLogEvent AO_PetscToApplication, AO_ApplicationToPetsc;

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

 14:    Collective on AO

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

 20:    Level: intermediate

 22:     Options Database Key:
 23: .   -ao_view - calls AOView() at end of AOCreate()

 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: .seealso: PetscViewerASCIIOpen()
 37: @*/
 38: PetscErrorCode  AOView(AO ao,PetscViewer viewer)
 39: {
 41:   if (!viewer) {
 42:     PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)ao),&viewer);
 43:   }

 46:   PetscObjectPrintClassNamePrefixType((PetscObject)ao,viewer);
 47:   (*ao->ops->view)(ao,viewer);
 48:   return 0;
 49: }

 51: /*@C
 52:    AOViewFromOptions - View from Options

 54:    Collective on AO

 56:    Input Parameters:
 57: +  ao - the application ordering context
 58: .  obj - Optional object
 59: -  name - command line option

 61:    Level: intermediate
 62: .seealso:  AO, AOView, PetscObjectViewFromOptions(), AOCreate()
 63: @*/
 64: PetscErrorCode  AOViewFromOptions(AO ao,PetscObject obj,const char name[])
 65: {
 67:   PetscObjectViewFromOptions((PetscObject)ao,obj,name);
 68:   return 0;
 69: }

 71: /*@
 72:    AODestroy - Destroys an application ordering.

 74:    Collective on AO

 76:    Input Parameters:
 77: .  ao - the application ordering context

 79:    Level: beginner

 81: .seealso: AOCreate()
 82: @*/
 83: PetscErrorCode  AODestroy(AO *ao)
 84: {
 85:   if (!*ao) return 0;
 87:   if (--((PetscObject)(*ao))->refct > 0) {*ao = NULL; return 0;}
 88:   /* if memory was published with SAWs then destroy it */
 89:   PetscObjectSAWsViewOff((PetscObject)*ao);
 90:   ISDestroy(&(*ao)->isapp);
 91:   ISDestroy(&(*ao)->ispetsc);
 92:   /* destroy the internal part */
 93:   if ((*ao)->ops->destroy) {
 94:     (*(*ao)->ops->destroy)(*ao);
 95:   }
 96:   PetscHeaderDestroy(ao);
 97:   return 0;
 98: }

100: #include <../src/vec/is/is/impls/general/general.h>
101: /* ---------------------------------------------------------------------*/

103: PETSC_INTERN PetscErrorCode ISSetUp_General(IS);

105: /*@
106:    AOPetscToApplicationIS - Maps an index set in the PETSc ordering to
107:    the application-defined ordering.

109:    Collective on AO

111:    Input Parameters:
112: +  ao - the application ordering context
113: -  is - the index set; this is replaced with its mapped values

115:    Output Parameter:
116: .  is - the mapped index set

118:    Level: intermediate

120:    Notes:
121:    The index set cannot be of type stride or block

123:    Any integers in ia[] that are negative are left unchanged. This
124:          allows one to convert, for example, neighbor lists that use negative
125:          entries to indicate nonexistent neighbors due to boundary conditions
126:          etc.

128: .seealso: AOCreateBasic(), AOView(),AOApplicationToPetsc(),
129:           AOApplicationToPetscIS(),AOPetscToApplication()
130: @*/
131: PetscErrorCode  AOPetscToApplicationIS(AO ao,IS is)
132: {
133:   PetscInt       n;
134:   PetscInt       *ia;

138:   ISToGeneral(is);
139:   /* we cheat because we know the is is general and that we can change the indices */
140:   ISGetIndices(is,(const PetscInt**)&ia);
141:   ISGetLocalSize(is,&n);
142:   (*ao->ops->petsctoapplication)(ao,n,ia);
143:   ISRestoreIndices(is,(const PetscInt**)&ia);
144:   /* updated cached values (sorted, min, max, etc.)*/
145:   ISSetUp_General(is);
146:   return 0;
147: }

149: /*@
150:    AOApplicationToPetscIS - Maps an index set in the application-defined
151:    ordering to the PETSc ordering.

153:    Collective on AO

155:    Input Parameters:
156: +  ao - the application ordering context
157: -  is - the index set; this is replaced with its mapped values

159:    Output Parameter:
160: .  is - the mapped index set

162:    Level: beginner

164:    Note:
165:    The index set cannot be of type stride or block

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

171: .seealso: AOCreateBasic(), AOView(), AOPetscToApplication(),
172:           AOPetscToApplicationIS(), AOApplicationToPetsc()
173: @*/
174: PetscErrorCode  AOApplicationToPetscIS(AO ao,IS is)
175: {
176:   PetscInt       n,*ia;

180:   ISToGeneral(is);
181:   /* we cheat because we know the is is general and that we can change the indices */
182:   ISGetIndices(is,(const PetscInt**)&ia);
183:   ISGetLocalSize(is,&n);
184:   (*ao->ops->applicationtopetsc)(ao,n,ia);
185:   ISRestoreIndices(is,(const PetscInt**)&ia);
186:   /* updated cached values (sorted, min, max, etc.)*/
187:   ISSetUp_General(is);
188:   return 0;
189: }

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

195:    Collective on AO

197:    Input Parameters:
198: +  ao - the application ordering context
199: .  n - the number of integers
200: -  ia - the integers; these are replaced with their mapped value

202:    Output Parameter:
203: .   ia - the mapped integers

205:    Level: beginner

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

212:    Integers that are out of range are mapped to -1

214: .seealso: AOCreateBasic(), AOView(),AOApplicationToPetsc(),
215:           AOPetscToApplicationIS(), AOApplicationToPetsc()
216: @*/
217: PetscErrorCode  AOPetscToApplication(AO ao,PetscInt n,PetscInt ia[])
218: {
221:   (*ao->ops->petsctoapplication)(ao,n,ia);
222:   return 0;
223: }

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:    Output Parameter:
237: .   ia - the mapped integers

239:    Level: beginner

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

246:    Integers that are out of range are mapped to -1

248: .seealso: AOCreateBasic(), AOView(), AOPetscToApplication(),
249:           AOPetscToApplicationIS(), AOApplicationToPetsc()
250: @*/
251: PetscErrorCode  AOApplicationToPetsc(AO ao,PetscInt n,PetscInt ia[])
252: {
255:   (*ao->ops->applicationtopetsc)(ao,n,ia);
256:   return 0;
257: }

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:   Output Parameter:
271: . array - The permuted array

273:   Note: The length of the array should be block*N, where N is length
274:   provided to the AOCreate*() method that created the AO.

276:   The permutation takes array[i_pet] --> array[i_app], where i_app is
277:   the index of 'i' in the application ordering and i_pet is the index
278:   of 'i' in the petsc ordering.

280:   Level: beginner

282: .seealso: AOCreateBasic(), AOView(), AOApplicationToPetsc(), AOPetscToApplicationIS()
283: @*/
284: PetscErrorCode  AOPetscToApplicationPermuteInt(AO ao, PetscInt block, PetscInt array[])
285: {
288:   (*ao->ops->petsctoapplicationpermuteint)(ao, block, array);
289:   return 0;
290: }

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

296:   Collective on AO

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

303:   Output Parameter:
304: . array - The permuted array

306:   Note: The length of the array should be block*N, where N is length
307:   provided to the AOCreate*() method that created the AO.

309:   The permutation takes array[i_app] --> array[i_pet], where i_app is
310:   the index of 'i' in the application ordering and i_pet is the index
311:   of 'i' in the petsc ordering.

313:   Level: beginner

315: .seealso: AOCreateBasic(), AOView(), AOPetscToApplicationIS(), AOApplicationToPetsc()
316: @*/
317: PetscErrorCode  AOApplicationToPetscPermuteInt(AO ao, PetscInt block, PetscInt array[])
318: {
321:   (*ao->ops->applicationtopetscpermuteint)(ao, block, array);
322:   return 0;
323: }

325: /*@
326:   AOPetscToApplicationPermuteReal - Permutes an array of blocks of reals
327:   in the PETSc ordering to the application-defined ordering.

329:   Collective on AO

331:   Input Parameters:
332: + ao    - The application ordering context
333: . block - The block size
334: - array - The integer array

336:   Output Parameter:
337: . array - The permuted array

339:   Note: The length of the array should be block*N, where N is length
340:   provided to the AOCreate*() method that created the AO.

342:   The permutation takes array[i_pet] --> array[i_app], where i_app is
343:   the index of 'i' in the application ordering and i_pet is the index
344:   of 'i' in the petsc ordering.

346:   Level: beginner

348: .seealso: AOCreateBasic(), AOView(), AOApplicationToPetsc(), AOPetscToApplicationIS()
349: @*/
350: PetscErrorCode  AOPetscToApplicationPermuteReal(AO ao, PetscInt block, PetscReal array[])
351: {
354:   (*ao->ops->petsctoapplicationpermutereal)(ao, block, array);
355:   return 0;
356: }

358: /*@
359:   AOApplicationToPetscPermuteReal - Permutes an array of blocks of reals
360:   in the application-defined ordering to the PETSc ordering.

362:   Collective on AO

364:   Input Parameters:
365: + ao    - The application ordering context
366: . block - The block size
367: - array - The integer array

369:   Output Parameter:
370: . array - The permuted array

372:   Note: The length of the array should be block*N, where N is length
373:   provided to the AOCreate*() method that created the AO.

375:   The permutation takes array[i_app] --> array[i_pet], where i_app is
376:   the index of 'i' in the application ordering and i_pet is the index
377:   of 'i' in the petsc ordering.

379:   Level: beginner

381: .seealso: AOCreateBasic(), AOView(),AOApplicationToPetsc(), AOPetscToApplicationIS()
382: @*/
383: PetscErrorCode  AOApplicationToPetscPermuteReal(AO ao, PetscInt block, PetscReal array[])
384: {
387:   (*ao->ops->applicationtopetscpermutereal)(ao, block, array);
388:   return 0;
389: }

391: /*@
392:     AOSetFromOptions - Sets AO options from the options database.

394:    Collective on AO

396:    Input Parameter:
397: .  ao - the application ordering

399:    Level: beginner

401: .seealso: AOCreate(), AOSetType(), AODestroy(), AOPetscToApplication(), AOApplicationToPetsc()
402: @*/
403: PetscErrorCode AOSetFromOptions(AO ao)
404: {
406:   char           type[256];
407:   const char     *def=AOBASIC;
408:   PetscBool      flg;


412:   PetscObjectOptionsBegin((PetscObject)ao);
413:   PetscOptionsFList("-ao_type","AO type","AOSetType",AOList,def,type,256,&flg);
414:   if (flg) {
415:     AOSetType(ao,type);
416:   } else if (!((PetscObject)ao)->type_name) {
417:     AOSetType(ao,def);
418:   }
419:   PetscOptionsEnd();
420:   return 0;
421: }

423: /*@
424:    AOSetIS - Sets the IS associated with the application ordering.

426:    Collective

428:    Input Parameters:
429: +  ao - the application ordering
430: .  isapp -  index set that defines an ordering
431: -  ispetsc - index set that defines another ordering (may be NULL to use the
432:              natural ordering)

434:    Notes:
435:    The index sets isapp and ispetsc are used only for creation of ao.

437:    This routine increases the reference count of isapp and ispetsc so you may/should destroy these arguments after this call if you no longer need them

439:    Level: beginner

441: .seealso: AOCreate(), AODestroy(), AOPetscToApplication(), AOApplicationToPetsc()
442: @*/
443: PetscErrorCode AOSetIS(AO ao,IS isapp,IS ispetsc)
444: {
445:   if (ispetsc) {
446:     PetscInt napp,npetsc;
447:     ISGetLocalSize(isapp,&napp);
448:     ISGetLocalSize(ispetsc,&npetsc);
450:   }
451:   if (isapp) PetscObjectReference((PetscObject)isapp);
452:   if (ispetsc) PetscObjectReference((PetscObject)ispetsc);
453:   ISDestroy(&ao->isapp);
454:   ISDestroy(&ao->ispetsc);
455:   ao->isapp   = isapp;
456:   ao->ispetsc = ispetsc;
457:   return 0;
458: }

460: /*@
461:    AOCreate - Creates an application ordering.

463:    Collective

465:    Input Parameters:
466: .  comm - MPI communicator that is to share AO

468:    Output Parameter:
469: .  ao - the new application ordering

471:    Options Database Key:
472: +   -ao_type <aotype> - create ao with particular format
473: -   -ao_view - call AOView() at the conclusion of AOCreate()

475:    Level: beginner

477: .seealso: AOSetIS(), AODestroy(), AOPetscToApplication(), AOApplicationToPetsc()
478: @*/
479: PetscErrorCode  AOCreate(MPI_Comm comm,AO *ao)
480: {
481:   AO             aonew;

484:   *ao = NULL;
485:   AOInitializePackage();

487:   PetscHeaderCreate(aonew,AO_CLASSID,"AO","Application Ordering","AO",comm,AODestroy,AOView);
488:   *ao  = aonew;
489:   return 0;
490: }