xref: /petsc/src/vec/is/ao/interface/ao.c (revision c2e3fba1fe1cda7e6350bbca19c4ed35ce95940a)
11447629fSBarry Smith 
21447629fSBarry Smith /*
31447629fSBarry Smith    Defines the abstract operations on AO (application orderings)
41447629fSBarry Smith */
51447629fSBarry Smith #include <../src/vec/is/ao/aoimpl.h>      /*I "petscao.h" I*/
61447629fSBarry Smith 
71447629fSBarry Smith /* Logging support */
81447629fSBarry Smith PetscClassId  AO_CLASSID;
91447629fSBarry Smith PetscLogEvent AO_PetscToApplication, AO_ApplicationToPetsc;
101447629fSBarry Smith 
111447629fSBarry Smith /*@C
121447629fSBarry Smith    AOView - Displays an application ordering.
131447629fSBarry Smith 
14d083f849SBarry Smith    Collective on AO
151447629fSBarry Smith 
161447629fSBarry Smith    Input Parameters:
171447629fSBarry Smith +  ao - the application ordering context
181447629fSBarry Smith -  viewer - viewer used for display
191447629fSBarry Smith 
201447629fSBarry Smith    Level: intermediate
211447629fSBarry Smith 
221447629fSBarry Smith     Options Database Key:
231447629fSBarry Smith .   -ao_view - calls AOView() at end of AOCreate()
241447629fSBarry Smith 
251447629fSBarry Smith    Note:
261447629fSBarry Smith    The available visualization contexts include
271447629fSBarry Smith +     PETSC_VIEWER_STDOUT_SELF - standard output (default)
281447629fSBarry Smith -     PETSC_VIEWER_STDOUT_WORLD - synchronized standard
291447629fSBarry Smith          output where only the first processor opens
301447629fSBarry Smith          the file.  All other processors send their
311447629fSBarry Smith          data to the first processor to print.
321447629fSBarry Smith 
331447629fSBarry Smith    The user can open an alternative visualization context with
341447629fSBarry Smith    PetscViewerASCIIOpen() - output to a specified file.
351447629fSBarry Smith 
36db781477SPatrick Sanan .seealso: `PetscViewerASCIIOpen()`
371447629fSBarry Smith @*/
381447629fSBarry Smith PetscErrorCode  AOView(AO ao,PetscViewer viewer)
391447629fSBarry Smith {
401447629fSBarry Smith   PetscFunctionBegin;
411447629fSBarry Smith   PetscValidHeaderSpecific(ao,AO_CLASSID,1);
4276d20c1aSBarry Smith   if (!viewer) {
439566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)ao),&viewer));
4476d20c1aSBarry Smith   }
451447629fSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
4698c3331eSBarry Smith 
479566063dSJacob Faibussowitsch   PetscCall(PetscObjectPrintClassNamePrefixType((PetscObject)ao,viewer));
489566063dSJacob Faibussowitsch   PetscCall((*ao->ops->view)(ao,viewer));
491447629fSBarry Smith   PetscFunctionReturn(0);
501447629fSBarry Smith }
511447629fSBarry Smith 
52fe2efc57SMark /*@C
53fe2efc57SMark    AOViewFromOptions - View from Options
54fe2efc57SMark 
55fe2efc57SMark    Collective on AO
56fe2efc57SMark 
57fe2efc57SMark    Input Parameters:
58fe2efc57SMark +  ao - the application ordering context
59736c3998SJose E. Roman .  obj - Optional object
60736c3998SJose E. Roman -  name - command line option
61fe2efc57SMark 
62fe2efc57SMark    Level: intermediate
63db781477SPatrick Sanan .seealso: `AO`, `AOView`, `PetscObjectViewFromOptions()`, `AOCreate()`
64fe2efc57SMark @*/
65fe2efc57SMark PetscErrorCode  AOViewFromOptions(AO ao,PetscObject obj,const char name[])
66fe2efc57SMark {
67fe2efc57SMark   PetscFunctionBegin;
68fe2efc57SMark   PetscValidHeaderSpecific(ao,AO_CLASSID,1);
699566063dSJacob Faibussowitsch   PetscCall(PetscObjectViewFromOptions((PetscObject)ao,obj,name));
70fe2efc57SMark   PetscFunctionReturn(0);
71fe2efc57SMark }
72fe2efc57SMark 
7301e608bcSBarry Smith /*@
741447629fSBarry Smith    AODestroy - Destroys an application ordering.
751447629fSBarry Smith 
761447629fSBarry Smith    Collective on AO
771447629fSBarry Smith 
781447629fSBarry Smith    Input Parameters:
791447629fSBarry Smith .  ao - the application ordering context
801447629fSBarry Smith 
811447629fSBarry Smith    Level: beginner
821447629fSBarry Smith 
83db781477SPatrick Sanan .seealso: `AOCreate()`
841447629fSBarry Smith @*/
851447629fSBarry Smith PetscErrorCode  AODestroy(AO *ao)
861447629fSBarry Smith {
871447629fSBarry Smith   PetscFunctionBegin;
881447629fSBarry Smith   if (!*ao) PetscFunctionReturn(0);
891447629fSBarry Smith   PetscValidHeaderSpecific((*ao),AO_CLASSID,1);
904c8fdceaSLisandro Dalcin   if (--((PetscObject)(*ao))->refct > 0) {*ao = NULL; PetscFunctionReturn(0);}
91e04113cfSBarry Smith   /* if memory was published with SAWs then destroy it */
929566063dSJacob Faibussowitsch   PetscCall(PetscObjectSAWsViewOff((PetscObject)*ao));
939566063dSJacob Faibussowitsch   PetscCall(ISDestroy(&(*ao)->isapp));
949566063dSJacob Faibussowitsch   PetscCall(ISDestroy(&(*ao)->ispetsc));
951447629fSBarry Smith   /* destroy the internal part */
961447629fSBarry Smith   if ((*ao)->ops->destroy) {
979566063dSJacob Faibussowitsch     PetscCall((*(*ao)->ops->destroy)(*ao));
981447629fSBarry Smith   }
999566063dSJacob Faibussowitsch   PetscCall(PetscHeaderDestroy(ao));
1001447629fSBarry Smith   PetscFunctionReturn(0);
1011447629fSBarry Smith }
1021447629fSBarry Smith 
1031447629fSBarry Smith #include <../src/vec/is/is/impls/general/general.h>
1041447629fSBarry Smith /* ---------------------------------------------------------------------*/
1051cc6b274SLisandro Dalcin 
1061cc6b274SLisandro Dalcin PETSC_INTERN PetscErrorCode ISSetUp_General(IS);
1071cc6b274SLisandro Dalcin 
1081447629fSBarry Smith /*@
1091447629fSBarry Smith    AOPetscToApplicationIS - Maps an index set in the PETSc ordering to
1101447629fSBarry Smith    the application-defined ordering.
1111447629fSBarry Smith 
112d083f849SBarry Smith    Collective on AO
1131447629fSBarry Smith 
1141447629fSBarry Smith    Input Parameters:
1151447629fSBarry Smith +  ao - the application ordering context
1161447629fSBarry Smith -  is - the index set; this is replaced with its mapped values
1171447629fSBarry Smith 
1181447629fSBarry Smith    Output Parameter:
1191447629fSBarry Smith .  is - the mapped index set
1201447629fSBarry Smith 
1211447629fSBarry Smith    Level: intermediate
1221447629fSBarry Smith 
1231447629fSBarry Smith    Notes:
1241447629fSBarry Smith    The index set cannot be of type stride or block
1251447629fSBarry Smith 
1261447629fSBarry Smith    Any integers in ia[] that are negative are left unchanged. This
1271447629fSBarry Smith          allows one to convert, for example, neighbor lists that use negative
1281447629fSBarry Smith          entries to indicate nonexistent neighbors due to boundary conditions
1291447629fSBarry Smith          etc.
1301447629fSBarry Smith 
131*c2e3fba1SPatrick Sanan .seealso: `AOCreateBasic()`, `AOView()`, `AOApplicationToPetsc()`,
132*c2e3fba1SPatrick Sanan           `AOApplicationToPetscIS()`, `AOPetscToApplication()`
1331447629fSBarry Smith @*/
1341447629fSBarry Smith PetscErrorCode  AOPetscToApplicationIS(AO ao,IS is)
1351447629fSBarry Smith {
1361447629fSBarry Smith   PetscInt       n;
1371447629fSBarry Smith   PetscInt       *ia;
1381447629fSBarry Smith 
1391447629fSBarry Smith   PetscFunctionBegin;
1401447629fSBarry Smith   PetscValidHeaderSpecific(ao,AO_CLASSID,1);
1411447629fSBarry Smith   PetscValidHeaderSpecific(is,IS_CLASSID,2);
1429566063dSJacob Faibussowitsch   PetscCall(ISToGeneral(is));
1431447629fSBarry Smith   /* we cheat because we know the is is general and that we can change the indices */
1449566063dSJacob Faibussowitsch   PetscCall(ISGetIndices(is,(const PetscInt**)&ia));
1459566063dSJacob Faibussowitsch   PetscCall(ISGetLocalSize(is,&n));
1469566063dSJacob Faibussowitsch   PetscCall((*ao->ops->petsctoapplication)(ao,n,ia));
1479566063dSJacob Faibussowitsch   PetscCall(ISRestoreIndices(is,(const PetscInt**)&ia));
1481cc6b274SLisandro Dalcin   /* updated cached values (sorted, min, max, etc.)*/
1499566063dSJacob Faibussowitsch   PetscCall(ISSetUp_General(is));
1501447629fSBarry Smith   PetscFunctionReturn(0);
1511447629fSBarry Smith }
1521447629fSBarry Smith 
1531447629fSBarry Smith /*@
1541447629fSBarry Smith    AOApplicationToPetscIS - Maps an index set in the application-defined
1551447629fSBarry Smith    ordering to the PETSc ordering.
1561447629fSBarry Smith 
157d083f849SBarry Smith    Collective on AO
1581447629fSBarry Smith 
1591447629fSBarry Smith    Input Parameters:
1601447629fSBarry Smith +  ao - the application ordering context
1611447629fSBarry Smith -  is - the index set; this is replaced with its mapped values
1621447629fSBarry Smith 
1631447629fSBarry Smith    Output Parameter:
1641447629fSBarry Smith .  is - the mapped index set
1651447629fSBarry Smith 
1661447629fSBarry Smith    Level: beginner
1671447629fSBarry Smith 
1681447629fSBarry Smith    Note:
1691447629fSBarry Smith    The index set cannot be of type stride or block
1701447629fSBarry Smith 
1711447629fSBarry Smith    Any integers in ia[] that are negative are left unchanged. This
1721447629fSBarry Smith    allows one to convert, for example, neighbor lists that use negative
1731447629fSBarry Smith    entries to indicate nonexistent neighbors due to boundary conditions, etc.
1741447629fSBarry Smith 
175db781477SPatrick Sanan .seealso: `AOCreateBasic()`, `AOView()`, `AOPetscToApplication()`,
176db781477SPatrick Sanan           `AOPetscToApplicationIS()`, `AOApplicationToPetsc()`
1771447629fSBarry Smith @*/
1781447629fSBarry Smith PetscErrorCode  AOApplicationToPetscIS(AO ao,IS is)
1791447629fSBarry Smith {
1801447629fSBarry Smith   PetscInt       n,*ia;
1811447629fSBarry Smith 
1821447629fSBarry Smith   PetscFunctionBegin;
1831447629fSBarry Smith   PetscValidHeaderSpecific(ao,AO_CLASSID,1);
1841447629fSBarry Smith   PetscValidHeaderSpecific(is,IS_CLASSID,2);
1859566063dSJacob Faibussowitsch   PetscCall(ISToGeneral(is));
1861447629fSBarry Smith   /* we cheat because we know the is is general and that we can change the indices */
1879566063dSJacob Faibussowitsch   PetscCall(ISGetIndices(is,(const PetscInt**)&ia));
1889566063dSJacob Faibussowitsch   PetscCall(ISGetLocalSize(is,&n));
1899566063dSJacob Faibussowitsch   PetscCall((*ao->ops->applicationtopetsc)(ao,n,ia));
1909566063dSJacob Faibussowitsch   PetscCall(ISRestoreIndices(is,(const PetscInt**)&ia));
1911cc6b274SLisandro Dalcin   /* updated cached values (sorted, min, max, etc.)*/
1929566063dSJacob Faibussowitsch   PetscCall(ISSetUp_General(is));
1931447629fSBarry Smith   PetscFunctionReturn(0);
1941447629fSBarry Smith }
1951447629fSBarry Smith 
1961447629fSBarry Smith /*@
1971447629fSBarry Smith    AOPetscToApplication - Maps a set of integers in the PETSc ordering to
1981447629fSBarry Smith    the application-defined ordering.
1991447629fSBarry Smith 
2001447629fSBarry Smith    Collective on AO
2011447629fSBarry Smith 
2021447629fSBarry Smith    Input Parameters:
2031447629fSBarry Smith +  ao - the application ordering context
2041447629fSBarry Smith .  n - the number of integers
2051447629fSBarry Smith -  ia - the integers; these are replaced with their mapped value
2061447629fSBarry Smith 
2071447629fSBarry Smith    Output Parameter:
2081447629fSBarry Smith .   ia - the mapped integers
2091447629fSBarry Smith 
2101447629fSBarry Smith    Level: beginner
2111447629fSBarry Smith 
2121447629fSBarry Smith    Note:
2131447629fSBarry Smith    Any integers in ia[] that are negative are left unchanged. This
2141447629fSBarry Smith    allows one to convert, for example, neighbor lists that use negative
2151447629fSBarry Smith    entries to indicate nonexistent neighbors due to boundary conditions, etc.
2161447629fSBarry Smith 
2171447629fSBarry Smith    Integers that are out of range are mapped to -1
2181447629fSBarry Smith 
219*c2e3fba1SPatrick Sanan .seealso: `AOCreateBasic()`, `AOView()`, `AOApplicationToPetsc()`,
220db781477SPatrick Sanan           `AOPetscToApplicationIS()`, `AOApplicationToPetsc()`
2211447629fSBarry Smith @*/
2221447629fSBarry Smith PetscErrorCode  AOPetscToApplication(AO ao,PetscInt n,PetscInt ia[])
2231447629fSBarry Smith {
2241447629fSBarry Smith   PetscFunctionBegin;
2251447629fSBarry Smith   PetscValidHeaderSpecific(ao,AO_CLASSID,1);
2261447629fSBarry Smith   if (n) PetscValidIntPointer(ia,3);
2279566063dSJacob Faibussowitsch   PetscCall((*ao->ops->petsctoapplication)(ao,n,ia));
2281447629fSBarry Smith   PetscFunctionReturn(0);
2291447629fSBarry Smith }
2301447629fSBarry Smith 
2311447629fSBarry Smith /*@
2321447629fSBarry Smith    AOApplicationToPetsc - Maps a set of integers in the application-defined
2331447629fSBarry Smith    ordering to the PETSc ordering.
2341447629fSBarry Smith 
2351447629fSBarry Smith    Collective on AO
2361447629fSBarry Smith 
2371447629fSBarry Smith    Input Parameters:
2381447629fSBarry Smith +  ao - the application ordering context
2391447629fSBarry Smith .  n - the number of integers
2401447629fSBarry Smith -  ia - the integers; these are replaced with their mapped value
2411447629fSBarry Smith 
2421447629fSBarry Smith    Output Parameter:
2431447629fSBarry Smith .   ia - the mapped integers
2441447629fSBarry Smith 
2451447629fSBarry Smith    Level: beginner
2461447629fSBarry Smith 
2471447629fSBarry Smith    Note:
2481447629fSBarry Smith    Any integers in ia[] that are negative are left unchanged. This
2491447629fSBarry Smith    allows one to convert, for example, neighbor lists that use negative
2501447629fSBarry Smith    entries to indicate nonexistent neighbors due to boundary conditions, etc.
2511447629fSBarry Smith 
2521447629fSBarry Smith    Integers that are out of range are mapped to -1
2531447629fSBarry Smith 
254db781477SPatrick Sanan .seealso: `AOCreateBasic()`, `AOView()`, `AOPetscToApplication()`,
255db781477SPatrick Sanan           `AOPetscToApplicationIS()`, `AOApplicationToPetsc()`
2561447629fSBarry Smith @*/
2571447629fSBarry Smith PetscErrorCode  AOApplicationToPetsc(AO ao,PetscInt n,PetscInt ia[])
2581447629fSBarry Smith {
2591447629fSBarry Smith   PetscFunctionBegin;
2601447629fSBarry Smith   PetscValidHeaderSpecific(ao,AO_CLASSID,1);
2611447629fSBarry Smith   if (n) PetscValidIntPointer(ia,3);
2629566063dSJacob Faibussowitsch   PetscCall((*ao->ops->applicationtopetsc)(ao,n,ia));
2631447629fSBarry Smith   PetscFunctionReturn(0);
2641447629fSBarry Smith }
2651447629fSBarry Smith 
2661447629fSBarry Smith /*@
2671447629fSBarry Smith   AOPetscToApplicationPermuteInt - Permutes an array of blocks of integers
2681447629fSBarry Smith   in the PETSc ordering to the application-defined ordering.
2691447629fSBarry Smith 
2701447629fSBarry Smith   Collective on AO
2711447629fSBarry Smith 
2721447629fSBarry Smith   Input Parameters:
2731447629fSBarry Smith + ao    - The application ordering context
2741447629fSBarry Smith . block - The block size
2751447629fSBarry Smith - array - The integer array
2761447629fSBarry Smith 
2771447629fSBarry Smith   Output Parameter:
2781447629fSBarry Smith . array - The permuted array
2791447629fSBarry Smith 
2801447629fSBarry Smith   Note: The length of the array should be block*N, where N is length
2811447629fSBarry Smith   provided to the AOCreate*() method that created the AO.
2821447629fSBarry Smith 
2831447629fSBarry Smith   The permutation takes array[i_pet] --> array[i_app], where i_app is
2841447629fSBarry Smith   the index of 'i' in the application ordering and i_pet is the index
2851447629fSBarry Smith   of 'i' in the petsc ordering.
2861447629fSBarry Smith 
2871447629fSBarry Smith   Level: beginner
2881447629fSBarry Smith 
289db781477SPatrick Sanan .seealso: `AOCreateBasic()`, `AOView()`, `AOApplicationToPetsc()`, `AOPetscToApplicationIS()`
2901447629fSBarry Smith @*/
2911447629fSBarry Smith PetscErrorCode  AOPetscToApplicationPermuteInt(AO ao, PetscInt block, PetscInt array[])
2921447629fSBarry Smith {
2931447629fSBarry Smith   PetscFunctionBegin;
2941447629fSBarry Smith   PetscValidHeaderSpecific(ao, AO_CLASSID,1);
2951447629fSBarry Smith   PetscValidIntPointer(array,3);
2969566063dSJacob Faibussowitsch   PetscCall((*ao->ops->petsctoapplicationpermuteint)(ao, block, array));
2971447629fSBarry Smith   PetscFunctionReturn(0);
2981447629fSBarry Smith }
2991447629fSBarry Smith 
3001447629fSBarry Smith /*@
3011447629fSBarry Smith   AOApplicationToPetscPermuteInt - Permutes an array of blocks of integers
3021447629fSBarry Smith   in the application-defined ordering to the PETSc ordering.
3031447629fSBarry Smith 
3041447629fSBarry Smith   Collective on AO
3051447629fSBarry Smith 
3061447629fSBarry Smith   Input Parameters:
3071447629fSBarry Smith + ao    - The application ordering context
3081447629fSBarry Smith . block - The block size
3091447629fSBarry Smith - array - The integer array
3101447629fSBarry Smith 
3111447629fSBarry Smith   Output Parameter:
3121447629fSBarry Smith . array - The permuted array
3131447629fSBarry Smith 
3141447629fSBarry Smith   Note: The length of the array should be block*N, where N is length
3151447629fSBarry Smith   provided to the AOCreate*() method that created the AO.
3161447629fSBarry Smith 
3171447629fSBarry Smith   The permutation takes array[i_app] --> array[i_pet], where i_app is
3181447629fSBarry Smith   the index of 'i' in the application ordering and i_pet is the index
3191447629fSBarry Smith   of 'i' in the petsc ordering.
3201447629fSBarry Smith 
3211447629fSBarry Smith   Level: beginner
3221447629fSBarry Smith 
323db781477SPatrick Sanan .seealso: `AOCreateBasic()`, `AOView()`, `AOPetscToApplicationIS()`, `AOApplicationToPetsc()`
3241447629fSBarry Smith @*/
3251447629fSBarry Smith PetscErrorCode  AOApplicationToPetscPermuteInt(AO ao, PetscInt block, PetscInt array[])
3261447629fSBarry Smith {
3271447629fSBarry Smith   PetscFunctionBegin;
3281447629fSBarry Smith   PetscValidHeaderSpecific(ao, AO_CLASSID,1);
3291447629fSBarry Smith   PetscValidIntPointer(array,3);
3309566063dSJacob Faibussowitsch   PetscCall((*ao->ops->applicationtopetscpermuteint)(ao, block, array));
3311447629fSBarry Smith   PetscFunctionReturn(0);
3321447629fSBarry Smith }
3331447629fSBarry Smith 
3341447629fSBarry Smith /*@
3351447629fSBarry Smith   AOPetscToApplicationPermuteReal - Permutes an array of blocks of reals
3361447629fSBarry Smith   in the PETSc ordering to the application-defined ordering.
3371447629fSBarry Smith 
3381447629fSBarry Smith   Collective on AO
3391447629fSBarry Smith 
3401447629fSBarry Smith   Input Parameters:
3411447629fSBarry Smith + ao    - The application ordering context
3421447629fSBarry Smith . block - The block size
3431447629fSBarry Smith - array - The integer array
3441447629fSBarry Smith 
3451447629fSBarry Smith   Output Parameter:
3461447629fSBarry Smith . array - The permuted array
3471447629fSBarry Smith 
3481447629fSBarry Smith   Note: The length of the array should be block*N, where N is length
3491447629fSBarry Smith   provided to the AOCreate*() method that created the AO.
3501447629fSBarry Smith 
3511447629fSBarry Smith   The permutation takes array[i_pet] --> array[i_app], where i_app is
3521447629fSBarry Smith   the index of 'i' in the application ordering and i_pet is the index
3531447629fSBarry Smith   of 'i' in the petsc ordering.
3541447629fSBarry Smith 
3551447629fSBarry Smith   Level: beginner
3561447629fSBarry Smith 
357db781477SPatrick Sanan .seealso: `AOCreateBasic()`, `AOView()`, `AOApplicationToPetsc()`, `AOPetscToApplicationIS()`
3581447629fSBarry Smith @*/
3591447629fSBarry Smith PetscErrorCode  AOPetscToApplicationPermuteReal(AO ao, PetscInt block, PetscReal array[])
3601447629fSBarry Smith {
3611447629fSBarry Smith   PetscFunctionBegin;
3621447629fSBarry Smith   PetscValidHeaderSpecific(ao, AO_CLASSID,1);
363064a246eSJacob Faibussowitsch   PetscValidRealPointer(array,3);
3649566063dSJacob Faibussowitsch   PetscCall((*ao->ops->petsctoapplicationpermutereal)(ao, block, array));
3651447629fSBarry Smith   PetscFunctionReturn(0);
3661447629fSBarry Smith }
3671447629fSBarry Smith 
3681447629fSBarry Smith /*@
3691447629fSBarry Smith   AOApplicationToPetscPermuteReal - Permutes an array of blocks of reals
3701447629fSBarry Smith   in the application-defined ordering to the PETSc ordering.
3711447629fSBarry Smith 
3721447629fSBarry Smith   Collective on AO
3731447629fSBarry Smith 
3741447629fSBarry Smith   Input Parameters:
3751447629fSBarry Smith + ao    - The application ordering context
3761447629fSBarry Smith . block - The block size
3771447629fSBarry Smith - array - The integer array
3781447629fSBarry Smith 
3791447629fSBarry Smith   Output Parameter:
3801447629fSBarry Smith . array - The permuted array
3811447629fSBarry Smith 
3821447629fSBarry Smith   Note: The length of the array should be block*N, where N is length
3831447629fSBarry Smith   provided to the AOCreate*() method that created the AO.
3841447629fSBarry Smith 
3851447629fSBarry Smith   The permutation takes array[i_app] --> array[i_pet], where i_app is
3861447629fSBarry Smith   the index of 'i' in the application ordering and i_pet is the index
3871447629fSBarry Smith   of 'i' in the petsc ordering.
3881447629fSBarry Smith 
3891447629fSBarry Smith   Level: beginner
3901447629fSBarry Smith 
391*c2e3fba1SPatrick Sanan .seealso: `AOCreateBasic()`, `AOView()`, `AOApplicationToPetsc()`, `AOPetscToApplicationIS()`
3921447629fSBarry Smith @*/
3931447629fSBarry Smith PetscErrorCode  AOApplicationToPetscPermuteReal(AO ao, PetscInt block, PetscReal array[])
3941447629fSBarry Smith {
3951447629fSBarry Smith   PetscFunctionBegin;
3961447629fSBarry Smith   PetscValidHeaderSpecific(ao, AO_CLASSID,1);
397064a246eSJacob Faibussowitsch   PetscValidRealPointer(array,3);
3989566063dSJacob Faibussowitsch   PetscCall((*ao->ops->applicationtopetscpermutereal)(ao, block, array));
3991447629fSBarry Smith   PetscFunctionReturn(0);
4001447629fSBarry Smith }
4011447629fSBarry Smith 
40201e608bcSBarry Smith /*@
4031447629fSBarry Smith     AOSetFromOptions - Sets AO options from the options database.
4041447629fSBarry Smith 
4051447629fSBarry Smith    Collective on AO
4061447629fSBarry Smith 
4071447629fSBarry Smith    Input Parameter:
4081447629fSBarry Smith .  ao - the application ordering
4091447629fSBarry Smith 
4101447629fSBarry Smith    Level: beginner
4111447629fSBarry Smith 
412db781477SPatrick Sanan .seealso: `AOCreate()`, `AOSetType()`, `AODestroy()`, `AOPetscToApplication()`, `AOApplicationToPetsc()`
4131447629fSBarry Smith @*/
4141447629fSBarry Smith PetscErrorCode AOSetFromOptions(AO ao)
4151447629fSBarry Smith {
4161447629fSBarry Smith   char           type[256];
4171447629fSBarry Smith   const char     *def=AOBASIC;
4181447629fSBarry Smith   PetscBool      flg;
4191447629fSBarry Smith 
4201447629fSBarry Smith   PetscFunctionBegin;
4211447629fSBarry Smith   PetscValidHeaderSpecific(ao,AO_CLASSID,1);
4221447629fSBarry Smith 
423d0609cedSBarry Smith   PetscObjectOptionsBegin((PetscObject)ao);
4249566063dSJacob Faibussowitsch   PetscCall(PetscOptionsFList("-ao_type","AO type","AOSetType",AOList,def,type,256,&flg));
4251447629fSBarry Smith   if (flg) {
4269566063dSJacob Faibussowitsch     PetscCall(AOSetType(ao,type));
4271447629fSBarry Smith   } else if (!((PetscObject)ao)->type_name) {
4289566063dSJacob Faibussowitsch     PetscCall(AOSetType(ao,def));
4291447629fSBarry Smith   }
430d0609cedSBarry Smith   PetscOptionsEnd();
4311447629fSBarry Smith   PetscFunctionReturn(0);
4321447629fSBarry Smith }
4331447629fSBarry Smith 
43401e608bcSBarry Smith /*@
4351447629fSBarry Smith    AOSetIS - Sets the IS associated with the application ordering.
4361447629fSBarry Smith 
437d083f849SBarry Smith    Collective
4381447629fSBarry Smith 
4391447629fSBarry Smith    Input Parameters:
4401447629fSBarry Smith +  ao - the application ordering
4411447629fSBarry Smith .  isapp -  index set that defines an ordering
4421447629fSBarry Smith -  ispetsc - index set that defines another ordering (may be NULL to use the
4431447629fSBarry Smith              natural ordering)
4441447629fSBarry Smith 
4451447629fSBarry Smith    Notes:
4461447629fSBarry Smith    The index sets isapp and ispetsc are used only for creation of ao.
4471447629fSBarry Smith 
44801e608bcSBarry Smith    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
44901e608bcSBarry Smith 
4501447629fSBarry Smith    Level: beginner
4511447629fSBarry Smith 
452db781477SPatrick Sanan .seealso: `AOCreate()`, `AODestroy()`, `AOPetscToApplication()`, `AOApplicationToPetsc()`
4531447629fSBarry Smith @*/
4541447629fSBarry Smith PetscErrorCode AOSetIS(AO ao,IS isapp,IS ispetsc)
4551447629fSBarry Smith {
4561447629fSBarry Smith   PetscFunctionBegin;
4571447629fSBarry Smith   if (ispetsc) {
4581447629fSBarry Smith     PetscInt napp,npetsc;
4599566063dSJacob Faibussowitsch     PetscCall(ISGetLocalSize(isapp,&napp));
4609566063dSJacob Faibussowitsch     PetscCall(ISGetLocalSize(ispetsc,&npetsc));
46108401ef6SPierre Jolivet     PetscCheck(napp == npetsc,PETSC_COMM_SELF,PETSC_ERR_ARG_SIZ,"napp %" PetscInt_FMT " != npetsc %" PetscInt_FMT ". Local IS lengths must match",napp,npetsc);
4621447629fSBarry Smith   }
4639566063dSJacob Faibussowitsch   if (isapp) PetscCall(PetscObjectReference((PetscObject)isapp));
4649566063dSJacob Faibussowitsch   if (ispetsc) PetscCall(PetscObjectReference((PetscObject)ispetsc));
4659566063dSJacob Faibussowitsch   PetscCall(ISDestroy(&ao->isapp));
4669566063dSJacob Faibussowitsch   PetscCall(ISDestroy(&ao->ispetsc));
4671447629fSBarry Smith   ao->isapp   = isapp;
4681447629fSBarry Smith   ao->ispetsc = ispetsc;
4691447629fSBarry Smith   PetscFunctionReturn(0);
4701447629fSBarry Smith }
4711447629fSBarry Smith 
47201e608bcSBarry Smith /*@
4731447629fSBarry Smith    AOCreate - Creates an application ordering.
4741447629fSBarry Smith 
475d083f849SBarry Smith    Collective
4761447629fSBarry Smith 
4771447629fSBarry Smith    Input Parameters:
4781447629fSBarry Smith .  comm - MPI communicator that is to share AO
4791447629fSBarry Smith 
4801447629fSBarry Smith    Output Parameter:
4811447629fSBarry Smith .  ao - the new application ordering
4821447629fSBarry Smith 
4831447629fSBarry Smith    Options Database Key:
4841447629fSBarry Smith +   -ao_type <aotype> - create ao with particular format
4851447629fSBarry Smith -   -ao_view - call AOView() at the conclusion of AOCreate()
4861447629fSBarry Smith 
4871447629fSBarry Smith    Level: beginner
4881447629fSBarry Smith 
489db781477SPatrick Sanan .seealso: `AOSetIS()`, `AODestroy()`, `AOPetscToApplication()`, `AOApplicationToPetsc()`
4901447629fSBarry Smith @*/
4911447629fSBarry Smith PetscErrorCode  AOCreate(MPI_Comm comm,AO *ao)
4921447629fSBarry Smith {
4931447629fSBarry Smith   AO             aonew;
4941447629fSBarry Smith 
4951447629fSBarry Smith   PetscFunctionBegin;
4961447629fSBarry Smith   PetscValidPointer(ao,2);
4971447629fSBarry Smith   *ao = NULL;
4989566063dSJacob Faibussowitsch   PetscCall(AOInitializePackage());
4991447629fSBarry Smith 
5009566063dSJacob Faibussowitsch   PetscCall(PetscHeaderCreate(aonew,AO_CLASSID,"AO","Application Ordering","AO",comm,AODestroy,AOView));
5011447629fSBarry Smith   *ao  = aonew;
5021447629fSBarry Smith   PetscFunctionReturn(0);
5031447629fSBarry Smith }
504