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: {
44: if (!viewer) {
45: PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)ao),&viewer);
46: }
49: PetscObjectPrintClassNamePrefixType((PetscObject)ao,viewer);
50: (*ao->ops->view)(ao,viewer);
51: return(0);
52: }
54: /*@C
55: AOViewFromOptions - View from Options
57: Collective on AO
59: Input Parameters:
60: + ao - the application ordering context
61: . obj - Optional object
62: - name - command line option
64: Level: intermediate
65: .seealso: AO, AOView, PetscObjectViewFromOptions(), AOCreate()
66: @*/
67: PetscErrorCode AOViewFromOptions(AO ao,PetscObject obj,const char name[])
68: {
73: PetscObjectViewFromOptions((PetscObject)ao,obj,name);
74: return(0);
75: }
77: /*@
78: AODestroy - Destroys an application ordering.
80: Collective on AO
82: Input Parameters:
83: . ao - the application ordering context
85: Level: beginner
87: .seealso: AOCreate()
88: @*/
89: PetscErrorCode AODestroy(AO *ao)
90: {
94: if (!*ao) return(0);
96: if (--((PetscObject)(*ao))->refct > 0) {*ao = NULL; return(0);}
97: /* if memory was published with SAWs then destroy it */
98: PetscObjectSAWsViewOff((PetscObject)*ao);
99: ISDestroy(&(*ao)->isapp);
100: ISDestroy(&(*ao)->ispetsc);
101: /* destroy the internal part */
102: if ((*ao)->ops->destroy) {
103: (*(*ao)->ops->destroy)(*ao);
104: }
105: PetscHeaderDestroy(ao);
106: return(0);
107: }
109: #include <../src/vec/is/is/impls/general/general.h>
110: /* ---------------------------------------------------------------------*/
112: PETSC_INTERN PetscErrorCode ISSetUp_General(IS);
114: /*@
115: AOPetscToApplicationIS - Maps an index set in the PETSc ordering to
116: the application-defined ordering.
118: Collective on AO
120: Input Parameters:
121: + ao - the application ordering context
122: - is - the index set; this is replaced with its mapped values
124: Output Parameter:
125: . is - the mapped index set
127: Level: intermediate
129: Notes:
130: The index set cannot be of type stride or block
132: Any integers in ia[] that are negative are left unchanged. This
133: allows one to convert, for example, neighbor lists that use negative
134: entries to indicate nonexistent neighbors due to boundary conditions
135: etc.
137: .seealso: AOCreateBasic(), AOView(),AOApplicationToPetsc(),
138: AOApplicationToPetscIS(),AOPetscToApplication()
139: @*/
140: PetscErrorCode AOPetscToApplicationIS(AO ao,IS is)
141: {
143: PetscInt n;
144: PetscInt *ia;
149: ISToGeneral(is);
150: /* we cheat because we know the is is general and that we can change the indices */
151: ISGetIndices(is,(const PetscInt**)&ia);
152: ISGetLocalSize(is,&n);
153: (*ao->ops->petsctoapplication)(ao,n,ia);
154: ISRestoreIndices(is,(const PetscInt**)&ia);
155: /* updated cached values (sorted, min, max, etc.)*/
156: ISSetUp_General(is);
157: return(0);
158: }
160: /*@
161: AOApplicationToPetscIS - Maps an index set in the application-defined
162: ordering to the PETSc ordering.
164: Collective on AO
166: Input Parameters:
167: + ao - the application ordering context
168: - is - the index set; this is replaced with its mapped values
170: Output Parameter:
171: . is - the mapped index set
173: Level: beginner
175: Note:
176: The index set cannot be of type stride or block
178: Any integers in ia[] that are negative are left unchanged. This
179: allows one to convert, for example, neighbor lists that use negative
180: entries to indicate nonexistent neighbors due to boundary conditions, etc.
182: .seealso: AOCreateBasic(), AOView(), AOPetscToApplication(),
183: AOPetscToApplicationIS(), AOApplicationToPetsc()
184: @*/
185: PetscErrorCode AOApplicationToPetscIS(AO ao,IS is)
186: {
188: PetscInt n,*ia;
193: ISToGeneral(is);
194: /* we cheat because we know the is is general and that we can change the indices */
195: ISGetIndices(is,(const PetscInt**)&ia);
196: ISGetLocalSize(is,&n);
197: (*ao->ops->applicationtopetsc)(ao,n,ia);
198: ISRestoreIndices(is,(const PetscInt**)&ia);
199: /* updated cached values (sorted, min, max, etc.)*/
200: ISSetUp_General(is);
201: return(0);
202: }
204: /*@
205: AOPetscToApplication - Maps a set of integers in the PETSc ordering to
206: the application-defined ordering.
208: Collective on AO
210: Input Parameters:
211: + ao - the application ordering context
212: . n - the number of integers
213: - ia - the integers; these are replaced with their mapped value
215: Output Parameter:
216: . ia - the mapped integers
218: Level: beginner
220: Note:
221: Any integers in ia[] that are negative are left unchanged. This
222: allows one to convert, for example, neighbor lists that use negative
223: entries to indicate nonexistent neighbors due to boundary conditions, etc.
225: Integers that are out of range are mapped to -1
227: .seealso: AOCreateBasic(), AOView(),AOApplicationToPetsc(),
228: AOPetscToApplicationIS(), AOApplicationToPetsc()
229: @*/
230: PetscErrorCode AOPetscToApplication(AO ao,PetscInt n,PetscInt ia[])
231: {
237: (*ao->ops->petsctoapplication)(ao,n,ia);
238: return(0);
239: }
241: /*@
242: AOApplicationToPetsc - Maps a set of integers in the application-defined
243: ordering to the PETSc ordering.
245: Collective on AO
247: Input Parameters:
248: + ao - the application ordering context
249: . n - the number of integers
250: - ia - the integers; these are replaced with their mapped value
252: Output Parameter:
253: . ia - the mapped integers
255: Level: beginner
257: Note:
258: Any integers in ia[] that are negative are left unchanged. This
259: allows one to convert, for example, neighbor lists that use negative
260: entries to indicate nonexistent neighbors due to boundary conditions, etc.
262: Integers that are out of range are mapped to -1
264: .seealso: AOCreateBasic(), AOView(), AOPetscToApplication(),
265: AOPetscToApplicationIS(), AOApplicationToPetsc()
266: @*/
267: PetscErrorCode AOApplicationToPetsc(AO ao,PetscInt n,PetscInt ia[])
268: {
274: (*ao->ops->applicationtopetsc)(ao,n,ia);
275: return(0);
276: }
278: /*@
279: AOPetscToApplicationPermuteInt - Permutes an array of blocks of integers
280: in the PETSc ordering to the application-defined ordering.
282: Collective on AO
284: Input Parameters:
285: + ao - The application ordering context
286: . block - The block size
287: - array - The integer array
289: Output Parameter:
290: . array - The permuted array
292: Note: The length of the array should be block*N, where N is length
293: provided to the AOCreate*() method that created the AO.
295: The permutation takes array[i_pet] --> array[i_app], where i_app is
296: the index of 'i' in the application ordering and i_pet is the index
297: of 'i' in the petsc ordering.
299: Level: beginner
301: .seealso: AOCreateBasic(), AOView(), AOApplicationToPetsc(), AOPetscToApplicationIS()
302: @*/
303: PetscErrorCode AOPetscToApplicationPermuteInt(AO ao, PetscInt block, PetscInt array[])
304: {
310: (*ao->ops->petsctoapplicationpermuteint)(ao, block, array);
311: return(0);
312: }
314: /*@
315: AOApplicationToPetscPermuteInt - Permutes an array of blocks of integers
316: in the application-defined ordering to the PETSc ordering.
318: Collective on AO
320: Input Parameters:
321: + ao - The application ordering context
322: . block - The block size
323: - array - The integer array
325: Output Parameter:
326: . array - The permuted array
328: Note: The length of the array should be block*N, where N is length
329: provided to the AOCreate*() method that created the AO.
331: The permutation takes array[i_app] --> array[i_pet], where i_app is
332: the index of 'i' in the application ordering and i_pet is the index
333: of 'i' in the petsc ordering.
335: Level: beginner
337: .seealso: AOCreateBasic(), AOView(), AOPetscToApplicationIS(), AOApplicationToPetsc()
338: @*/
339: PetscErrorCode AOApplicationToPetscPermuteInt(AO ao, PetscInt block, PetscInt array[])
340: {
346: (*ao->ops->applicationtopetscpermuteint)(ao, block, array);
347: return(0);
348: }
350: /*@
351: AOPetscToApplicationPermuteReal - Permutes an array of blocks of reals
352: in the PETSc ordering to the application-defined 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: Output Parameter:
362: . array - The permuted array
364: Note: The length of the array should be block*N, where N is length
365: provided to the AOCreate*() method that created the AO.
367: The permutation takes array[i_pet] --> array[i_app], where i_app is
368: the index of 'i' in the application ordering and i_pet is the index
369: of 'i' in the petsc ordering.
371: Level: beginner
373: .seealso: AOCreateBasic(), AOView(), AOApplicationToPetsc(), AOPetscToApplicationIS()
374: @*/
375: PetscErrorCode AOPetscToApplicationPermuteReal(AO ao, PetscInt block, PetscReal array[])
376: {
382: (*ao->ops->petsctoapplicationpermutereal)(ao, block, array);
383: return(0);
384: }
386: /*@
387: AOApplicationToPetscPermuteReal - Permutes an array of blocks of reals
388: in the application-defined ordering to the PETSc ordering.
390: Collective on AO
392: Input Parameters:
393: + ao - The application ordering context
394: . block - The block size
395: - array - The integer array
397: Output Parameter:
398: . array - The permuted array
400: Note: The length of the array should be block*N, where N is length
401: provided to the AOCreate*() method that created the AO.
403: The permutation takes array[i_app] --> array[i_pet], where i_app is
404: the index of 'i' in the application ordering and i_pet is the index
405: of 'i' in the petsc ordering.
407: Level: beginner
409: .seealso: AOCreateBasic(), AOView(),AOApplicationToPetsc(), AOPetscToApplicationIS()
410: @*/
411: PetscErrorCode AOApplicationToPetscPermuteReal(AO ao, PetscInt block, PetscReal array[])
412: {
418: (*ao->ops->applicationtopetscpermutereal)(ao, block, array);
419: return(0);
420: }
422: /*@
423: AOSetFromOptions - Sets AO options from the options database.
425: Collective on AO
427: Input Parameter:
428: . ao - the application ordering
430: Level: beginner
432: .seealso: AOCreate(), AOSetType(), AODestroy(), AOPetscToApplication(), AOApplicationToPetsc()
433: @*/
434: PetscErrorCode AOSetFromOptions(AO ao)
435: {
437: char type[256];
438: const char *def=AOBASIC;
439: PetscBool flg;
444: PetscObjectOptionsBegin((PetscObject)ao);
445: PetscOptionsFList("-ao_type","AO type","AOSetType",AOList,def,type,256,&flg);
446: if (flg) {
447: AOSetType(ao,type);
448: } else if (!((PetscObject)ao)->type_name) {
449: AOSetType(ao,def);
450: }
451: PetscOptionsEnd();
452: return(0);
453: }
455: /*@
456: AOSetIS - Sets the IS associated with the application ordering.
458: Collective
460: Input Parameters:
461: + ao - the application ordering
462: . isapp - index set that defines an ordering
463: - ispetsc - index set that defines another ordering (may be NULL to use the
464: natural ordering)
466: Notes:
467: The index sets isapp and ispetsc are used only for creation of ao.
469: 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
471: Level: beginner
473: .seealso: AOCreate(), AODestroy(), AOPetscToApplication(), AOApplicationToPetsc()
474: @*/
475: PetscErrorCode AOSetIS(AO ao,IS isapp,IS ispetsc)
476: {
480: if (ispetsc) {
481: PetscInt napp,npetsc;
482: ISGetLocalSize(isapp,&napp);
483: ISGetLocalSize(ispetsc,&npetsc);
484: if (napp != npetsc) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_SIZ,"napp %D != npetsc %D. Local IS lengths must match",napp,npetsc);
485: }
486: if (isapp) {PetscObjectReference((PetscObject)isapp);}
487: if (ispetsc) {PetscObjectReference((PetscObject)ispetsc);}
488: ISDestroy(&ao->isapp);
489: ISDestroy(&ao->ispetsc);
490: ao->isapp = isapp;
491: ao->ispetsc = ispetsc;
492: return(0);
493: }
495: /*@
496: AOCreate - Creates an application ordering.
498: Collective
500: Input Parameters:
501: . comm - MPI communicator that is to share AO
503: Output Parameter:
504: . ao - the new application ordering
506: Options Database Key:
507: + -ao_type <aotype> - create ao with particular format
508: - -ao_view - call AOView() at the conclusion of AOCreate()
510: Level: beginner
512: .seealso: AOSetIS(), AODestroy(), AOPetscToApplication(), AOApplicationToPetsc()
513: @*/
514: PetscErrorCode AOCreate(MPI_Comm comm,AO *ao)
515: {
517: AO aonew;
521: *ao = NULL;
522: AOInitializePackage();
524: PetscHeaderCreate(aonew,AO_CLASSID,"AO","Application Ordering","AO",comm,AODestroy,AOView);
525: *ao = aonew;
526: return(0);
527: }