xref: /petsc/src/vec/is/ao/interface/ao.c (revision 2fe279fdf3e687a416e4eadb7d3c7a82d60442c6)
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 
14c3339decSBarry Smith    Collective
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:
23cab54364SBarry Smith .   -ao_view - calls `AOView()` at end of `AOCreate()`
241447629fSBarry Smith 
25cab54364SBarry Smith    Notes:
261447629fSBarry Smith    The available visualization contexts include
27cab54364SBarry Smith +     `PETSC_VIEWER_STDOUT_SELF` - standard output (default)
28cab54364SBarry 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
34cab54364SBarry Smith    `PetscViewerASCIIOpen()` - output to a specified file.
351447629fSBarry Smith 
36cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `PetscViewerASCIIOpen()`
371447629fSBarry Smith @*/
38d71ae5a4SJacob Faibussowitsch PetscErrorCode AOView(AO ao, PetscViewer viewer)
39d71ae5a4SJacob Faibussowitsch {
401447629fSBarry Smith   PetscFunctionBegin;
411447629fSBarry Smith   PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
4248a46eb9SPierre Jolivet   if (!viewer) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)ao), &viewer));
431447629fSBarry Smith   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2);
4498c3331eSBarry Smith 
459566063dSJacob Faibussowitsch   PetscCall(PetscObjectPrintClassNamePrefixType((PetscObject)ao, viewer));
46dbbe0bcdSBarry Smith   PetscUseTypeMethod(ao, view, viewer);
473ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
481447629fSBarry Smith }
491447629fSBarry Smith 
50fe2efc57SMark /*@C
51cab54364SBarry Smith    AOViewFromOptions - View an `AO` based on values in the options database
52fe2efc57SMark 
53c3339decSBarry Smith    Collective
54fe2efc57SMark 
55fe2efc57SMark    Input Parameters:
56fe2efc57SMark +  ao - the application ordering context
57736c3998SJose E. Roman .  obj - Optional object
58736c3998SJose E. Roman -  name - command line option
59fe2efc57SMark 
60fe2efc57SMark    Level: intermediate
61cab54364SBarry Smith 
62cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOView`, `PetscObjectViewFromOptions()`, `AOCreate()`
63fe2efc57SMark @*/
64d71ae5a4SJacob Faibussowitsch PetscErrorCode AOViewFromOptions(AO ao, PetscObject obj, const char name[])
65d71ae5a4SJacob Faibussowitsch {
66fe2efc57SMark   PetscFunctionBegin;
67fe2efc57SMark   PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
689566063dSJacob Faibussowitsch   PetscCall(PetscObjectViewFromOptions((PetscObject)ao, obj, name));
693ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
70fe2efc57SMark }
71fe2efc57SMark 
7201e608bcSBarry Smith /*@
731447629fSBarry Smith    AODestroy - Destroys an application ordering.
741447629fSBarry Smith 
75c3339decSBarry Smith    Collective
761447629fSBarry Smith 
77*2fe279fdSBarry Smith    Input Parameter:
781447629fSBarry Smith .  ao - the application ordering context
791447629fSBarry Smith 
801447629fSBarry Smith    Level: beginner
811447629fSBarry Smith 
82cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreate()`
831447629fSBarry Smith @*/
84d71ae5a4SJacob Faibussowitsch PetscErrorCode AODestroy(AO *ao)
85d71ae5a4SJacob Faibussowitsch {
861447629fSBarry Smith   PetscFunctionBegin;
873ba16761SJacob Faibussowitsch   if (!*ao) PetscFunctionReturn(PETSC_SUCCESS);
881447629fSBarry Smith   PetscValidHeaderSpecific((*ao), AO_CLASSID, 1);
899371c9d4SSatish Balay   if (--((PetscObject)(*ao))->refct > 0) {
909371c9d4SSatish Balay     *ao = NULL;
913ba16761SJacob Faibussowitsch     PetscFunctionReturn(PETSC_SUCCESS);
929371c9d4SSatish Balay   }
93e04113cfSBarry Smith   /* if memory was published with SAWs then destroy it */
949566063dSJacob Faibussowitsch   PetscCall(PetscObjectSAWsViewOff((PetscObject)*ao));
959566063dSJacob Faibussowitsch   PetscCall(ISDestroy(&(*ao)->isapp));
969566063dSJacob Faibussowitsch   PetscCall(ISDestroy(&(*ao)->ispetsc));
971447629fSBarry Smith   /* destroy the internal part */
9848a46eb9SPierre Jolivet   if ((*ao)->ops->destroy) PetscCall((*(*ao)->ops->destroy)(*ao));
999566063dSJacob Faibussowitsch   PetscCall(PetscHeaderDestroy(ao));
1003ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
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 
112c3339decSBarry Smith    Collective
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 
126cab54364SBarry Smith    Any integers in is that are negative are left unchanged. This
1271447629fSBarry Smith    allows one to convert, for example, neighbor lists that use negative
128cab54364SBarry Smith    entries to indicate nonexistent neighbors due to boundary conditions etc.
1291447629fSBarry Smith 
130cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOApplicationToPetsc()`,
131c2e3fba1SPatrick Sanan           `AOApplicationToPetscIS()`, `AOPetscToApplication()`
1321447629fSBarry Smith @*/
133d71ae5a4SJacob Faibussowitsch PetscErrorCode AOPetscToApplicationIS(AO ao, IS is)
134d71ae5a4SJacob Faibussowitsch {
1351447629fSBarry Smith   PetscInt  n;
1361447629fSBarry Smith   PetscInt *ia;
1371447629fSBarry Smith 
1381447629fSBarry Smith   PetscFunctionBegin;
1391447629fSBarry Smith   PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
1401447629fSBarry Smith   PetscValidHeaderSpecific(is, IS_CLASSID, 2);
1419566063dSJacob Faibussowitsch   PetscCall(ISToGeneral(is));
1421447629fSBarry Smith   /* we cheat because we know the is is general and that we can change the indices */
1439566063dSJacob Faibussowitsch   PetscCall(ISGetIndices(is, (const PetscInt **)&ia));
1449566063dSJacob Faibussowitsch   PetscCall(ISGetLocalSize(is, &n));
145dbbe0bcdSBarry Smith   PetscUseTypeMethod(ao, petsctoapplication, n, ia);
1469566063dSJacob Faibussowitsch   PetscCall(ISRestoreIndices(is, (const PetscInt **)&ia));
1471cc6b274SLisandro Dalcin   /* updated cached values (sorted, min, max, etc.)*/
1489566063dSJacob Faibussowitsch   PetscCall(ISSetUp_General(is));
1493ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1501447629fSBarry Smith }
1511447629fSBarry Smith 
1521447629fSBarry Smith /*@
1531447629fSBarry Smith    AOApplicationToPetscIS - Maps an index set in the application-defined
1541447629fSBarry Smith    ordering to the PETSc ordering.
1551447629fSBarry Smith 
156c3339decSBarry Smith    Collective
1571447629fSBarry Smith 
1581447629fSBarry Smith    Input Parameters:
1591447629fSBarry Smith +  ao - the application ordering context
1601447629fSBarry Smith -  is - the index set; this is replaced with its mapped values
1611447629fSBarry Smith 
1621447629fSBarry Smith    Output Parameter:
1631447629fSBarry Smith .  is - the mapped index set
1641447629fSBarry Smith 
1651447629fSBarry Smith    Level: beginner
1661447629fSBarry Smith 
167cab54364SBarry Smith    Notes:
1681447629fSBarry Smith    The index set cannot be of type stride or block
1691447629fSBarry Smith 
170cab54364SBarry Smith    Any integers in is that are negative are left unchanged. This
1711447629fSBarry Smith    allows one to convert, for example, neighbor lists that use negative
1721447629fSBarry Smith    entries to indicate nonexistent neighbors due to boundary conditions, etc.
1731447629fSBarry Smith 
174cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOPetscToApplication()`,
175db781477SPatrick Sanan           `AOPetscToApplicationIS()`, `AOApplicationToPetsc()`
1761447629fSBarry Smith @*/
177d71ae5a4SJacob Faibussowitsch PetscErrorCode AOApplicationToPetscIS(AO ao, IS is)
178d71ae5a4SJacob Faibussowitsch {
1791447629fSBarry Smith   PetscInt n, *ia;
1801447629fSBarry Smith 
1811447629fSBarry Smith   PetscFunctionBegin;
1821447629fSBarry Smith   PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
1831447629fSBarry Smith   PetscValidHeaderSpecific(is, IS_CLASSID, 2);
1849566063dSJacob Faibussowitsch   PetscCall(ISToGeneral(is));
1851447629fSBarry Smith   /* we cheat because we know the is is general and that we can change the indices */
1869566063dSJacob Faibussowitsch   PetscCall(ISGetIndices(is, (const PetscInt **)&ia));
1879566063dSJacob Faibussowitsch   PetscCall(ISGetLocalSize(is, &n));
188dbbe0bcdSBarry Smith   PetscUseTypeMethod(ao, applicationtopetsc, n, ia);
1899566063dSJacob Faibussowitsch   PetscCall(ISRestoreIndices(is, (const PetscInt **)&ia));
1901cc6b274SLisandro Dalcin   /* updated cached values (sorted, min, max, etc.)*/
1919566063dSJacob Faibussowitsch   PetscCall(ISSetUp_General(is));
1923ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1931447629fSBarry Smith }
1941447629fSBarry Smith 
1951447629fSBarry Smith /*@
1961447629fSBarry Smith    AOPetscToApplication - Maps a set of integers in the PETSc ordering to
1971447629fSBarry Smith    the application-defined ordering.
1981447629fSBarry Smith 
199c3339decSBarry Smith    Collective
2001447629fSBarry Smith 
2011447629fSBarry Smith    Input Parameters:
2021447629fSBarry Smith +  ao - the application ordering context
2031447629fSBarry Smith .  n - the number of integers
2041447629fSBarry Smith -  ia - the integers; these are replaced with their mapped value
2051447629fSBarry Smith 
2061447629fSBarry Smith    Output Parameter:
2071447629fSBarry Smith .   ia - the mapped integers
2081447629fSBarry Smith 
2091447629fSBarry Smith    Level: beginner
2101447629fSBarry Smith 
2111447629fSBarry Smith    Note:
2121447629fSBarry Smith    Any integers in ia[] that are negative are left unchanged. This
2131447629fSBarry Smith    allows one to convert, for example, neighbor lists that use negative
2141447629fSBarry Smith    entries to indicate nonexistent neighbors due to boundary conditions, etc.
2151447629fSBarry Smith 
2161447629fSBarry Smith    Integers that are out of range are mapped to -1
2171447629fSBarry Smith 
218cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOApplicationToPetsc()`,
219db781477SPatrick Sanan           `AOPetscToApplicationIS()`, `AOApplicationToPetsc()`
2201447629fSBarry Smith @*/
221d71ae5a4SJacob Faibussowitsch PetscErrorCode AOPetscToApplication(AO ao, PetscInt n, PetscInt ia[])
222d71ae5a4SJacob Faibussowitsch {
2231447629fSBarry Smith   PetscFunctionBegin;
2241447629fSBarry Smith   PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
2251447629fSBarry Smith   if (n) PetscValidIntPointer(ia, 3);
226dbbe0bcdSBarry Smith   PetscUseTypeMethod(ao, petsctoapplication, n, ia);
2273ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
2281447629fSBarry Smith }
2291447629fSBarry Smith 
2301447629fSBarry Smith /*@
2311447629fSBarry Smith    AOApplicationToPetsc - Maps a set of integers in the application-defined
2321447629fSBarry Smith    ordering to the PETSc ordering.
2331447629fSBarry Smith 
234c3339decSBarry Smith    Collective
2351447629fSBarry Smith 
2361447629fSBarry Smith    Input Parameters:
2371447629fSBarry Smith +  ao - the application ordering context
2381447629fSBarry Smith .  n - the number of integers
2391447629fSBarry Smith -  ia - the integers; these are replaced with their mapped value
2401447629fSBarry Smith 
2411447629fSBarry Smith    Output Parameter:
2421447629fSBarry Smith .   ia - the mapped integers
2431447629fSBarry Smith 
2441447629fSBarry Smith    Level: beginner
2451447629fSBarry Smith 
246cab54364SBarry Smith    Notes:
2471447629fSBarry Smith    Any integers in ia[] that are negative are left unchanged. This
2481447629fSBarry Smith    allows one to convert, for example, neighbor lists that use negative
2491447629fSBarry Smith    entries to indicate nonexistent neighbors due to boundary conditions, etc.
2501447629fSBarry Smith 
2511447629fSBarry Smith    Integers that are out of range are mapped to -1
2521447629fSBarry Smith 
253cab54364SBarry Smith .seealso: [](sec_ao), `AOCreateBasic()`, `AOView()`, `AOPetscToApplication()`,
254db781477SPatrick Sanan           `AOPetscToApplicationIS()`, `AOApplicationToPetsc()`
2551447629fSBarry Smith @*/
256d71ae5a4SJacob Faibussowitsch PetscErrorCode AOApplicationToPetsc(AO ao, PetscInt n, PetscInt ia[])
257d71ae5a4SJacob Faibussowitsch {
2581447629fSBarry Smith   PetscFunctionBegin;
2591447629fSBarry Smith   PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
2601447629fSBarry Smith   if (n) PetscValidIntPointer(ia, 3);
261dbbe0bcdSBarry Smith   PetscUseTypeMethod(ao, applicationtopetsc, n, ia);
2623ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
2631447629fSBarry Smith }
2641447629fSBarry Smith 
2651447629fSBarry Smith /*@
2661447629fSBarry Smith   AOPetscToApplicationPermuteInt - Permutes an array of blocks of integers
2671447629fSBarry Smith   in the PETSc ordering to the application-defined ordering.
2681447629fSBarry Smith 
269c3339decSBarry Smith   Collective
2701447629fSBarry Smith 
2711447629fSBarry Smith   Input Parameters:
2721447629fSBarry Smith + ao    - The application ordering context
2731447629fSBarry Smith . block - The block size
2741447629fSBarry Smith - array - The integer array
2751447629fSBarry Smith 
2761447629fSBarry Smith   Output Parameter:
2771447629fSBarry Smith . array - The permuted array
2781447629fSBarry Smith 
279cab54364SBarry Smith   Level: beginner
280cab54364SBarry Smith 
281cab54364SBarry Smith   Notes:
282cab54364SBarry Smith   The length of the array should be block*N, where N is length
2831447629fSBarry Smith   provided to the AOCreate*() method that created the AO.
2841447629fSBarry Smith 
2851447629fSBarry Smith   The permutation takes array[i_pet] --> array[i_app], where i_app is
2861447629fSBarry Smith   the index of 'i' in the application ordering and i_pet is the index
2871447629fSBarry Smith   of 'i' in the petsc ordering.
2881447629fSBarry Smith 
289cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOApplicationToPetsc()`, `AOPetscToApplicationIS()`
2901447629fSBarry Smith @*/
291d71ae5a4SJacob Faibussowitsch PetscErrorCode AOPetscToApplicationPermuteInt(AO ao, PetscInt block, PetscInt array[])
292d71ae5a4SJacob Faibussowitsch {
2931447629fSBarry Smith   PetscFunctionBegin;
2941447629fSBarry Smith   PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
2951447629fSBarry Smith   PetscValidIntPointer(array, 3);
296dbbe0bcdSBarry Smith   PetscUseTypeMethod(ao, petsctoapplicationpermuteint, block, array);
2973ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
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 
304c3339decSBarry Smith   Collective
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 
314cab54364SBarry Smith   Level: beginner
315cab54364SBarry Smith 
316cab54364SBarry Smith   Notes:
317cab54364SBarry Smith   The length of the array should be block*N, where N is length
3181447629fSBarry Smith   provided to the AOCreate*() method that created the AO.
3191447629fSBarry Smith 
3201447629fSBarry Smith   The permutation takes array[i_app] --> array[i_pet], where i_app is
3211447629fSBarry Smith   the index of 'i' in the application ordering and i_pet is the index
3221447629fSBarry Smith   of 'i' in the petsc ordering.
3231447629fSBarry Smith 
324cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOPetscToApplicationIS()`, `AOApplicationToPetsc()`
3251447629fSBarry Smith @*/
326d71ae5a4SJacob Faibussowitsch PetscErrorCode AOApplicationToPetscPermuteInt(AO ao, PetscInt block, PetscInt array[])
327d71ae5a4SJacob Faibussowitsch {
3281447629fSBarry Smith   PetscFunctionBegin;
3291447629fSBarry Smith   PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
3301447629fSBarry Smith   PetscValidIntPointer(array, 3);
331dbbe0bcdSBarry Smith   PetscUseTypeMethod(ao, applicationtopetscpermuteint, block, array);
3323ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
3331447629fSBarry Smith }
3341447629fSBarry Smith 
3351447629fSBarry Smith /*@
3361447629fSBarry Smith   AOPetscToApplicationPermuteReal - Permutes an array of blocks of reals
3371447629fSBarry Smith   in the PETSc ordering to the application-defined ordering.
3381447629fSBarry Smith 
339c3339decSBarry Smith   Collective
3401447629fSBarry Smith 
3411447629fSBarry Smith   Input Parameters:
3421447629fSBarry Smith + ao    - The application ordering context
3431447629fSBarry Smith . block - The block size
3441447629fSBarry Smith - array - The integer array
3451447629fSBarry Smith 
3461447629fSBarry Smith   Output Parameter:
3471447629fSBarry Smith . array - The permuted array
3481447629fSBarry Smith 
349cab54364SBarry Smith   Level: beginner
350cab54364SBarry Smith 
351cab54364SBarry Smith   Notes:
352cab54364SBarry Smith   The length of the array should be block*N, where N is length
3531447629fSBarry Smith   provided to the AOCreate*() method that created the AO.
3541447629fSBarry Smith 
3551447629fSBarry Smith   The permutation takes array[i_pet] --> array[i_app], where i_app is
3561447629fSBarry Smith   the index of 'i' in the application ordering and i_pet is the index
3571447629fSBarry Smith   of 'i' in the petsc ordering.
3581447629fSBarry Smith 
359cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOApplicationToPetsc()`, `AOPetscToApplicationIS()`
3601447629fSBarry Smith @*/
361d71ae5a4SJacob Faibussowitsch PetscErrorCode AOPetscToApplicationPermuteReal(AO ao, PetscInt block, PetscReal array[])
362d71ae5a4SJacob Faibussowitsch {
3631447629fSBarry Smith   PetscFunctionBegin;
3641447629fSBarry Smith   PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
365064a246eSJacob Faibussowitsch   PetscValidRealPointer(array, 3);
366dbbe0bcdSBarry Smith   PetscUseTypeMethod(ao, petsctoapplicationpermutereal, block, array);
3673ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
3681447629fSBarry Smith }
3691447629fSBarry Smith 
3701447629fSBarry Smith /*@
3711447629fSBarry Smith   AOApplicationToPetscPermuteReal - Permutes an array of blocks of reals
3721447629fSBarry Smith   in the application-defined ordering to the PETSc ordering.
3731447629fSBarry Smith 
374c3339decSBarry Smith   Collective
3751447629fSBarry Smith 
3761447629fSBarry Smith   Input Parameters:
3771447629fSBarry Smith + ao    - The application ordering context
3781447629fSBarry Smith . block - The block size
3791447629fSBarry Smith - array - The integer array
3801447629fSBarry Smith 
3811447629fSBarry Smith   Output Parameter:
3821447629fSBarry Smith . array - The permuted array
3831447629fSBarry Smith 
384cab54364SBarry Smith   Level: beginner
385cab54364SBarry Smith 
386cab54364SBarry Smith   Notes:
387cab54364SBarry Smith   The length of the array should be block*N, where N is length
3881447629fSBarry Smith   provided to the AOCreate*() method that created the AO.
3891447629fSBarry Smith 
3901447629fSBarry Smith   The permutation takes array[i_app] --> array[i_pet], where i_app is
3911447629fSBarry Smith   the index of 'i' in the application ordering and i_pet is the index
3921447629fSBarry Smith   of 'i' in the petsc ordering.
3931447629fSBarry Smith 
394cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOApplicationToPetsc()`, `AOPetscToApplicationIS()`
3951447629fSBarry Smith @*/
396d71ae5a4SJacob Faibussowitsch PetscErrorCode AOApplicationToPetscPermuteReal(AO ao, PetscInt block, PetscReal array[])
397d71ae5a4SJacob Faibussowitsch {
3981447629fSBarry Smith   PetscFunctionBegin;
3991447629fSBarry Smith   PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
400064a246eSJacob Faibussowitsch   PetscValidRealPointer(array, 3);
401dbbe0bcdSBarry Smith   PetscUseTypeMethod(ao, applicationtopetscpermutereal, block, array);
4023ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
4031447629fSBarry Smith }
4041447629fSBarry Smith 
40501e608bcSBarry Smith /*@
406cab54364SBarry Smith     AOSetFromOptions - Sets `AO` options from the options database.
4071447629fSBarry Smith 
408c3339decSBarry Smith    Collective
4091447629fSBarry Smith 
4101447629fSBarry Smith    Input Parameter:
4111447629fSBarry Smith .  ao - the application ordering
4121447629fSBarry Smith 
4131447629fSBarry Smith    Level: beginner
4141447629fSBarry Smith 
415cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreate()`, `AOSetType()`, `AODestroy()`, `AOPetscToApplication()`, `AOApplicationToPetsc()`
4161447629fSBarry Smith @*/
417d71ae5a4SJacob Faibussowitsch PetscErrorCode AOSetFromOptions(AO ao)
418d71ae5a4SJacob Faibussowitsch {
4191447629fSBarry Smith   char        type[256];
4201447629fSBarry Smith   const char *def = AOBASIC;
4211447629fSBarry Smith   PetscBool   flg;
4221447629fSBarry Smith 
4231447629fSBarry Smith   PetscFunctionBegin;
4241447629fSBarry Smith   PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
4251447629fSBarry Smith 
426d0609cedSBarry Smith   PetscObjectOptionsBegin((PetscObject)ao);
4279566063dSJacob Faibussowitsch   PetscCall(PetscOptionsFList("-ao_type", "AO type", "AOSetType", AOList, def, type, 256, &flg));
4281447629fSBarry Smith   if (flg) {
4299566063dSJacob Faibussowitsch     PetscCall(AOSetType(ao, type));
4301447629fSBarry Smith   } else if (!((PetscObject)ao)->type_name) {
4319566063dSJacob Faibussowitsch     PetscCall(AOSetType(ao, def));
4321447629fSBarry Smith   }
433d0609cedSBarry Smith   PetscOptionsEnd();
4343ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
4351447629fSBarry Smith }
4361447629fSBarry Smith 
43701e608bcSBarry Smith /*@
438cab54364SBarry Smith    AOSetIS - Sets the `IS` associated with the application ordering.
4391447629fSBarry Smith 
440d083f849SBarry Smith    Collective
4411447629fSBarry Smith 
4421447629fSBarry Smith    Input Parameters:
4431447629fSBarry Smith +  ao - the application ordering
4441447629fSBarry Smith .  isapp -  index set that defines an ordering
445*2fe279fdSBarry Smith -  ispetsc - index set that defines another ordering (may be `NULL` to use the
4461447629fSBarry Smith              natural ordering)
4471447629fSBarry Smith 
448cab54364SBarry Smith    Level: beginner
449cab54364SBarry Smith 
4501447629fSBarry Smith    Notes:
4511447629fSBarry Smith    The index sets isapp and ispetsc are used only for creation of ao.
4521447629fSBarry Smith 
45301e608bcSBarry 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
45401e608bcSBarry Smith 
455cab54364SBarry Smith .seealso: [](sec_ao), [](sec_scatter), `AO`, `AOCreate()`, `AODestroy()`, `AOPetscToApplication()`, `AOApplicationToPetsc()`
4561447629fSBarry Smith @*/
457d71ae5a4SJacob Faibussowitsch PetscErrorCode AOSetIS(AO ao, IS isapp, IS ispetsc)
458d71ae5a4SJacob Faibussowitsch {
4591447629fSBarry Smith   PetscFunctionBegin;
4601447629fSBarry Smith   if (ispetsc) {
4611447629fSBarry Smith     PetscInt napp, npetsc;
4629566063dSJacob Faibussowitsch     PetscCall(ISGetLocalSize(isapp, &napp));
4639566063dSJacob Faibussowitsch     PetscCall(ISGetLocalSize(ispetsc, &npetsc));
46408401ef6SPierre Jolivet     PetscCheck(napp == npetsc, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "napp %" PetscInt_FMT " != npetsc %" PetscInt_FMT ". Local IS lengths must match", napp, npetsc);
4651447629fSBarry Smith   }
4669566063dSJacob Faibussowitsch   if (isapp) PetscCall(PetscObjectReference((PetscObject)isapp));
4679566063dSJacob Faibussowitsch   if (ispetsc) PetscCall(PetscObjectReference((PetscObject)ispetsc));
4689566063dSJacob Faibussowitsch   PetscCall(ISDestroy(&ao->isapp));
4699566063dSJacob Faibussowitsch   PetscCall(ISDestroy(&ao->ispetsc));
4701447629fSBarry Smith   ao->isapp   = isapp;
4711447629fSBarry Smith   ao->ispetsc = ispetsc;
4723ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
4731447629fSBarry Smith }
4741447629fSBarry Smith 
47501e608bcSBarry Smith /*@
476cab54364SBarry Smith    AOCreate - Creates an application ordering. That is an object that maps from an application ordering to a PETSc ordering and vice versa
4771447629fSBarry Smith 
478d083f849SBarry Smith    Collective
4791447629fSBarry Smith 
480*2fe279fdSBarry Smith    Input Parameter:
481cab54364SBarry Smith .  comm - MPI communicator that is to share the `AO`
4821447629fSBarry Smith 
4831447629fSBarry Smith    Output Parameter:
4841447629fSBarry Smith .  ao - the new application ordering
4851447629fSBarry Smith 
4861447629fSBarry Smith    Options Database Key:
4871447629fSBarry Smith +   -ao_type <aotype> - create ao with particular format
4881447629fSBarry Smith -   -ao_view - call AOView() at the conclusion of AOCreate()
4891447629fSBarry Smith 
4901447629fSBarry Smith    Level: beginner
4911447629fSBarry Smith 
492cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOSetIS()`, `AODestroy()`, `AOPetscToApplication()`, `AOApplicationToPetsc()`
4931447629fSBarry Smith @*/
494d71ae5a4SJacob Faibussowitsch PetscErrorCode AOCreate(MPI_Comm comm, AO *ao)
495d71ae5a4SJacob Faibussowitsch {
4961447629fSBarry Smith   AO aonew;
4971447629fSBarry Smith 
4981447629fSBarry Smith   PetscFunctionBegin;
4991447629fSBarry Smith   PetscValidPointer(ao, 2);
5001447629fSBarry Smith   *ao = NULL;
5019566063dSJacob Faibussowitsch   PetscCall(AOInitializePackage());
5021447629fSBarry Smith 
5039566063dSJacob Faibussowitsch   PetscCall(PetscHeaderCreate(aonew, AO_CLASSID, "AO", "Application Ordering", "AO", comm, AODestroy, AOView));
5041447629fSBarry Smith   *ao = aonew;
5053ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
5061447629fSBarry Smith }
507