11447629fSBarry Smith /*
21447629fSBarry Smith Defines the abstract operations on AO (application orderings)
31447629fSBarry Smith */
41447629fSBarry Smith #include <../src/vec/is/ao/aoimpl.h> /*I "petscao.h" I*/
51447629fSBarry Smith
61447629fSBarry Smith /* Logging support */
71447629fSBarry Smith PetscClassId AO_CLASSID;
81447629fSBarry Smith PetscLogEvent AO_PetscToApplication, AO_ApplicationToPetsc;
91447629fSBarry Smith
10ffeef943SBarry Smith /*@
111447629fSBarry Smith AOView - Displays an application ordering.
121447629fSBarry Smith
13c3339decSBarry Smith Collective
141447629fSBarry Smith
151447629fSBarry Smith Input Parameters:
161447629fSBarry Smith + ao - the application ordering context
171447629fSBarry Smith - viewer - viewer used for display
181447629fSBarry Smith
191447629fSBarry Smith Level: intermediate
201447629fSBarry Smith
211447629fSBarry Smith Options Database Key:
22cab54364SBarry Smith . -ao_view - calls `AOView()` at end of `AOCreate()`
231447629fSBarry Smith
24cab54364SBarry Smith Notes:
251447629fSBarry Smith The available visualization contexts include
26cab54364SBarry Smith + `PETSC_VIEWER_STDOUT_SELF` - standard output (default)
27cab54364SBarry Smith - `PETSC_VIEWER_STDOUT_WORLD` - synchronized standard
281447629fSBarry Smith output where only the first processor opens
291447629fSBarry Smith the file. All other processors send their
301447629fSBarry Smith data to the first processor to print.
311447629fSBarry Smith
321447629fSBarry Smith The user can open an alternative visualization context with
33cab54364SBarry Smith `PetscViewerASCIIOpen()` - output to a specified file.
341447629fSBarry Smith
35*d38ec673SBarry Smith .seealso: [](sec_ao), `AO`, `PetscViewerASCIIOpen()`, `AOViewFromOptions()`
361447629fSBarry Smith @*/
AOView(AO ao,PetscViewer viewer)37d71ae5a4SJacob Faibussowitsch PetscErrorCode AOView(AO ao, PetscViewer viewer)
38d71ae5a4SJacob Faibussowitsch {
391447629fSBarry Smith PetscFunctionBegin;
401447629fSBarry Smith PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
4148a46eb9SPierre Jolivet if (!viewer) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)ao), &viewer));
421447629fSBarry Smith PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2);
4398c3331eSBarry Smith
449566063dSJacob Faibussowitsch PetscCall(PetscObjectPrintClassNamePrefixType((PetscObject)ao, viewer));
45dbbe0bcdSBarry Smith PetscUseTypeMethod(ao, view, viewer);
463ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
471447629fSBarry Smith }
481447629fSBarry Smith
49ffeef943SBarry Smith /*@
50cab54364SBarry Smith AOViewFromOptions - View an `AO` based on values in the options database
51fe2efc57SMark
52c3339decSBarry Smith Collective
53fe2efc57SMark
54fe2efc57SMark Input Parameters:
55fe2efc57SMark + ao - the application ordering context
56*d38ec673SBarry Smith . obj - optional object that provides the prefix used to search the options database
57736c3998SJose E. Roman - name - command line option
58fe2efc57SMark
59fe2efc57SMark Level: intermediate
60cab54364SBarry Smith
61*d38ec673SBarry Smith .seealso: [](sec_ao), `AO`, `AOView()`, `PetscObjectViewFromOptions()`, `AOCreate()`
62fe2efc57SMark @*/
AOViewFromOptions(AO ao,PetscObject obj,const char name[])63d71ae5a4SJacob Faibussowitsch PetscErrorCode AOViewFromOptions(AO ao, PetscObject obj, const char name[])
64d71ae5a4SJacob Faibussowitsch {
65fe2efc57SMark PetscFunctionBegin;
66fe2efc57SMark PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
679566063dSJacob Faibussowitsch PetscCall(PetscObjectViewFromOptions((PetscObject)ao, obj, name));
683ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
69fe2efc57SMark }
70fe2efc57SMark
7101e608bcSBarry Smith /*@
721447629fSBarry Smith AODestroy - Destroys an application ordering.
731447629fSBarry Smith
74c3339decSBarry Smith Collective
751447629fSBarry Smith
762fe279fdSBarry Smith Input Parameter:
771447629fSBarry Smith . ao - the application ordering context
781447629fSBarry Smith
791447629fSBarry Smith Level: beginner
801447629fSBarry Smith
81cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreate()`
821447629fSBarry Smith @*/
AODestroy(AO * ao)83d71ae5a4SJacob Faibussowitsch PetscErrorCode AODestroy(AO *ao)
84d71ae5a4SJacob Faibussowitsch {
851447629fSBarry Smith PetscFunctionBegin;
863ba16761SJacob Faibussowitsch if (!*ao) PetscFunctionReturn(PETSC_SUCCESS);
87f4f49eeaSPierre Jolivet PetscValidHeaderSpecific(*ao, AO_CLASSID, 1);
88f4f49eeaSPierre Jolivet if (--((PetscObject)*ao)->refct > 0) {
899371c9d4SSatish Balay *ao = NULL;
903ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
919371c9d4SSatish Balay }
92e04113cfSBarry Smith /* if memory was published with SAWs then destroy it */
939566063dSJacob Faibussowitsch PetscCall(PetscObjectSAWsViewOff((PetscObject)*ao));
949566063dSJacob Faibussowitsch PetscCall(ISDestroy(&(*ao)->isapp));
959566063dSJacob Faibussowitsch PetscCall(ISDestroy(&(*ao)->ispetsc));
961447629fSBarry Smith /* destroy the internal part */
97213acdd3SPierre Jolivet PetscTryTypeMethod(*ao, destroy);
989566063dSJacob Faibussowitsch PetscCall(PetscHeaderDestroy(ao));
993ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1001447629fSBarry Smith }
1011447629fSBarry Smith
1021447629fSBarry Smith #include <../src/vec/is/is/impls/general/general.h>
1031cc6b274SLisandro Dalcin
1041cc6b274SLisandro Dalcin PETSC_INTERN PetscErrorCode ISSetUp_General(IS);
1051cc6b274SLisandro Dalcin
1061447629fSBarry Smith /*@
1071447629fSBarry Smith AOPetscToApplicationIS - Maps an index set in the PETSc ordering to
1081447629fSBarry Smith the application-defined ordering.
1091447629fSBarry Smith
110c3339decSBarry Smith Collective
1111447629fSBarry Smith
1121447629fSBarry Smith Input Parameters:
1131447629fSBarry Smith + ao - the application ordering context
1141447629fSBarry Smith - is - the index set; this is replaced with its mapped values
1151447629fSBarry Smith
1161447629fSBarry Smith Output Parameter:
1171447629fSBarry Smith . is - the mapped index set
1181447629fSBarry Smith
1191447629fSBarry Smith Level: intermediate
1201447629fSBarry Smith
1211447629fSBarry Smith Notes:
122*d38ec673SBarry Smith The index set cannot be of `ISType` `ISSTRIDE` or `ISBLOCK`.
1231447629fSBarry Smith
124cab54364SBarry Smith Any integers in is that are negative are left unchanged. This
1251447629fSBarry Smith allows one to convert, for example, neighbor lists that use negative
126cab54364SBarry Smith entries to indicate nonexistent neighbors due to boundary conditions etc.
1271447629fSBarry Smith
128cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOApplicationToPetsc()`,
129*d38ec673SBarry Smith `AOApplicationToPetscIS()`, `AOPetscToApplication()`, `ISSTRIDE`, `ISBLOCK`
1301447629fSBarry Smith @*/
AOPetscToApplicationIS(AO ao,IS is)131d71ae5a4SJacob Faibussowitsch PetscErrorCode AOPetscToApplicationIS(AO ao, IS is)
132d71ae5a4SJacob Faibussowitsch {
1331447629fSBarry Smith PetscInt n;
1341447629fSBarry Smith PetscInt *ia;
1351447629fSBarry Smith
1361447629fSBarry Smith PetscFunctionBegin;
1371447629fSBarry Smith PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
1381447629fSBarry Smith PetscValidHeaderSpecific(is, IS_CLASSID, 2);
1399566063dSJacob Faibussowitsch PetscCall(ISToGeneral(is));
14015229ffcSPierre Jolivet /* we cheat because we know the IS is general and that we can change the indices */
1419566063dSJacob Faibussowitsch PetscCall(ISGetIndices(is, (const PetscInt **)&ia));
1429566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(is, &n));
143dbbe0bcdSBarry Smith PetscUseTypeMethod(ao, petsctoapplication, n, ia);
1449566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(is, (const PetscInt **)&ia));
1451cc6b274SLisandro Dalcin /* updated cached values (sorted, min, max, etc.)*/
1469566063dSJacob Faibussowitsch PetscCall(ISSetUp_General(is));
1473ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1481447629fSBarry Smith }
1491447629fSBarry Smith
1501447629fSBarry Smith /*@
1511447629fSBarry Smith AOApplicationToPetscIS - Maps an index set in the application-defined
1521447629fSBarry Smith ordering to the PETSc ordering.
1531447629fSBarry Smith
154c3339decSBarry Smith Collective
1551447629fSBarry Smith
1561447629fSBarry Smith Input Parameters:
1571447629fSBarry Smith + ao - the application ordering context
1581447629fSBarry Smith - is - the index set; this is replaced with its mapped values
1591447629fSBarry Smith
1601447629fSBarry Smith Output Parameter:
1611447629fSBarry Smith . is - the mapped index set
1621447629fSBarry Smith
1631447629fSBarry Smith Level: beginner
1641447629fSBarry Smith
165cab54364SBarry Smith Notes:
166*d38ec673SBarry Smith The index set cannot be of `ISType` `ISSTRIDE` or `ISBLOCK`
1671447629fSBarry Smith
168cab54364SBarry Smith Any integers in is that are negative are left unchanged. This
1691447629fSBarry Smith allows one to convert, for example, neighbor lists that use negative
1701447629fSBarry Smith entries to indicate nonexistent neighbors due to boundary conditions, etc.
1711447629fSBarry Smith
172cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOPetscToApplication()`,
173*d38ec673SBarry Smith `AOPetscToApplicationIS()`, `AOApplicationToPetsc()`, `ISSTRIDE`, `ISBLOCK`
1741447629fSBarry Smith @*/
AOApplicationToPetscIS(AO ao,IS is)175d71ae5a4SJacob Faibussowitsch PetscErrorCode AOApplicationToPetscIS(AO ao, IS is)
176d71ae5a4SJacob Faibussowitsch {
1771447629fSBarry Smith PetscInt n, *ia;
1781447629fSBarry Smith
1791447629fSBarry Smith PetscFunctionBegin;
1801447629fSBarry Smith PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
1811447629fSBarry Smith PetscValidHeaderSpecific(is, IS_CLASSID, 2);
1829566063dSJacob Faibussowitsch PetscCall(ISToGeneral(is));
18315229ffcSPierre Jolivet /* we cheat because we know the IS is general and that we can change the indices */
1849566063dSJacob Faibussowitsch PetscCall(ISGetIndices(is, (const PetscInt **)&ia));
1859566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(is, &n));
186dbbe0bcdSBarry Smith PetscUseTypeMethod(ao, applicationtopetsc, n, ia);
1879566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(is, (const PetscInt **)&ia));
1881cc6b274SLisandro Dalcin /* updated cached values (sorted, min, max, etc.)*/
1899566063dSJacob Faibussowitsch PetscCall(ISSetUp_General(is));
1903ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1911447629fSBarry Smith }
1921447629fSBarry Smith
1931447629fSBarry Smith /*@
1941447629fSBarry Smith AOPetscToApplication - Maps a set of integers in the PETSc ordering to
1951447629fSBarry Smith the application-defined ordering.
1961447629fSBarry Smith
197c3339decSBarry Smith Collective
1981447629fSBarry Smith
1991447629fSBarry Smith Input Parameters:
2001447629fSBarry Smith + ao - the application ordering context
2011447629fSBarry Smith . n - the number of integers
2021447629fSBarry Smith - ia - the integers; these are replaced with their mapped value
2031447629fSBarry Smith
2041447629fSBarry Smith Output Parameter:
2051447629fSBarry Smith . ia - the mapped integers
2061447629fSBarry Smith
2071447629fSBarry Smith Level: beginner
2081447629fSBarry Smith
2091447629fSBarry Smith Note:
210*d38ec673SBarry Smith Any integers in `ia` that are negative are left unchanged. This
2111447629fSBarry Smith allows one to convert, for example, neighbor lists that use negative
2121447629fSBarry Smith entries to indicate nonexistent neighbors due to boundary conditions, etc.
2131447629fSBarry Smith
2141447629fSBarry Smith Integers that are out of range are mapped to -1
2151447629fSBarry Smith
216cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOApplicationToPetsc()`,
21738b5cf2dSJacob Faibussowitsch `AOPetscToApplicationIS()`
2181447629fSBarry Smith @*/
AOPetscToApplication(AO ao,PetscInt n,PetscInt ia[])219d71ae5a4SJacob Faibussowitsch PetscErrorCode AOPetscToApplication(AO ao, PetscInt n, PetscInt ia[])
220d71ae5a4SJacob Faibussowitsch {
2211447629fSBarry Smith PetscFunctionBegin;
2221447629fSBarry Smith PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
2234f572ea9SToby Isaac if (n) PetscAssertPointer(ia, 3);
224dbbe0bcdSBarry Smith PetscUseTypeMethod(ao, petsctoapplication, n, ia);
2253ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2261447629fSBarry Smith }
2271447629fSBarry Smith
2281447629fSBarry Smith /*@
2291447629fSBarry Smith AOApplicationToPetsc - Maps a set of integers in the application-defined
2301447629fSBarry Smith ordering to the PETSc ordering.
2311447629fSBarry Smith
232c3339decSBarry Smith Collective
2331447629fSBarry Smith
2341447629fSBarry Smith Input Parameters:
2351447629fSBarry Smith + ao - the application ordering context
2361447629fSBarry Smith . n - the number of integers
2371447629fSBarry Smith - ia - the integers; these are replaced with their mapped value
2381447629fSBarry Smith
2391447629fSBarry Smith Output Parameter:
2401447629fSBarry Smith . ia - the mapped integers
2411447629fSBarry Smith
2421447629fSBarry Smith Level: beginner
2431447629fSBarry Smith
244cab54364SBarry Smith Notes:
245*d38ec673SBarry Smith Any integers in `ia` that are negative are left unchanged. This
2461447629fSBarry Smith allows one to convert, for example, neighbor lists that use negative
2471447629fSBarry Smith entries to indicate nonexistent neighbors due to boundary conditions, etc.
2481447629fSBarry Smith
2491447629fSBarry Smith Integers that are out of range are mapped to -1
2501447629fSBarry Smith
251cab54364SBarry Smith .seealso: [](sec_ao), `AOCreateBasic()`, `AOView()`, `AOPetscToApplication()`,
25242747ad1SJacob Faibussowitsch `AOPetscToApplicationIS()`
2531447629fSBarry Smith @*/
AOApplicationToPetsc(AO ao,PetscInt n,PetscInt ia[])254d71ae5a4SJacob Faibussowitsch PetscErrorCode AOApplicationToPetsc(AO ao, PetscInt n, PetscInt ia[])
255d71ae5a4SJacob Faibussowitsch {
2561447629fSBarry Smith PetscFunctionBegin;
2571447629fSBarry Smith PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
2584f572ea9SToby Isaac if (n) PetscAssertPointer(ia, 3);
259dbbe0bcdSBarry Smith PetscUseTypeMethod(ao, applicationtopetsc, n, ia);
2603ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2611447629fSBarry Smith }
2621447629fSBarry Smith
2631447629fSBarry Smith /*@
2641447629fSBarry Smith AOPetscToApplicationPermuteInt - Permutes an array of blocks of integers
2651447629fSBarry Smith in the PETSc ordering to the application-defined ordering.
2661447629fSBarry Smith
267c3339decSBarry Smith Collective
2681447629fSBarry Smith
2691447629fSBarry Smith Input Parameters:
2701447629fSBarry Smith + ao - The application ordering context
2711447629fSBarry Smith . block - The block size
2721447629fSBarry Smith - array - The integer array
2731447629fSBarry Smith
2741447629fSBarry Smith Output Parameter:
2751447629fSBarry Smith . array - The permuted array
2761447629fSBarry Smith
277cab54364SBarry Smith Level: beginner
278cab54364SBarry Smith
279cab54364SBarry Smith Notes:
280*d38ec673SBarry Smith The length of the array should be $block*N$, where `N` is length
281*d38ec673SBarry Smith provided to the AOCreate*() method that created the `AO`.
2821447629fSBarry Smith
283*d38ec673SBarry Smith The permutation takes `array[i_pet] --> array[i_app]`, where `i_app` is
284*d38ec673SBarry Smith the index of `i` in the application ordering and `i_pet` is the index
285*d38ec673SBarry Smith of `i` in the PETSc ordering.
2861447629fSBarry Smith
287cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOApplicationToPetsc()`, `AOPetscToApplicationIS()`
2881447629fSBarry Smith @*/
AOPetscToApplicationPermuteInt(AO ao,PetscInt block,PetscInt array[])289d71ae5a4SJacob Faibussowitsch PetscErrorCode AOPetscToApplicationPermuteInt(AO ao, PetscInt block, PetscInt array[])
290d71ae5a4SJacob Faibussowitsch {
2911447629fSBarry Smith PetscFunctionBegin;
2921447629fSBarry Smith PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
2934f572ea9SToby Isaac PetscAssertPointer(array, 3);
294dbbe0bcdSBarry Smith PetscUseTypeMethod(ao, petsctoapplicationpermuteint, block, array);
2953ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2961447629fSBarry Smith }
2971447629fSBarry Smith
2981447629fSBarry Smith /*@
2991447629fSBarry Smith AOApplicationToPetscPermuteInt - Permutes an array of blocks of integers
3001447629fSBarry Smith in the application-defined ordering to the PETSc ordering.
3011447629fSBarry Smith
302c3339decSBarry Smith Collective
3031447629fSBarry Smith
3041447629fSBarry Smith Input Parameters:
3051447629fSBarry Smith + ao - The application ordering context
3061447629fSBarry Smith . block - The block size
3071447629fSBarry Smith - array - The integer array
3081447629fSBarry Smith
3091447629fSBarry Smith Output Parameter:
3101447629fSBarry Smith . array - The permuted array
3111447629fSBarry Smith
312cab54364SBarry Smith Level: beginner
313cab54364SBarry Smith
314cab54364SBarry Smith Notes:
315*d38ec673SBarry Smith The length of the array should be $ block*N $, where `N` is length
316*d38ec673SBarry Smith provided to the AOCreate*() method that created the `AO`.
3171447629fSBarry Smith
318*d38ec673SBarry Smith The permutation takes `array[i_app] --> array[i_pet]`, where `i_app` is
319*d38ec673SBarry Smith the index of `i` in the application ordering and `i_pet` is the index
320*d38ec673SBarry Smith of `i` in the PETSc ordering.
3211447629fSBarry Smith
322cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOPetscToApplicationIS()`, `AOApplicationToPetsc()`
3231447629fSBarry Smith @*/
AOApplicationToPetscPermuteInt(AO ao,PetscInt block,PetscInt array[])324d71ae5a4SJacob Faibussowitsch PetscErrorCode AOApplicationToPetscPermuteInt(AO ao, PetscInt block, PetscInt array[])
325d71ae5a4SJacob Faibussowitsch {
3261447629fSBarry Smith PetscFunctionBegin;
3271447629fSBarry Smith PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
3284f572ea9SToby Isaac PetscAssertPointer(array, 3);
329dbbe0bcdSBarry Smith PetscUseTypeMethod(ao, applicationtopetscpermuteint, block, array);
3303ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3311447629fSBarry Smith }
3321447629fSBarry Smith
3331447629fSBarry Smith /*@
3341447629fSBarry Smith AOPetscToApplicationPermuteReal - Permutes an array of blocks of reals
3351447629fSBarry Smith in the PETSc ordering to the application-defined ordering.
3361447629fSBarry Smith
337c3339decSBarry Smith Collective
3381447629fSBarry Smith
3391447629fSBarry Smith Input Parameters:
3401447629fSBarry Smith + ao - The application ordering context
3411447629fSBarry Smith . block - The block size
3421447629fSBarry Smith - array - The integer array
3431447629fSBarry Smith
3441447629fSBarry Smith Output Parameter:
3451447629fSBarry Smith . array - The permuted array
3461447629fSBarry Smith
347cab54364SBarry Smith Level: beginner
348cab54364SBarry Smith
349cab54364SBarry Smith Notes:
350*d38ec673SBarry Smith The length of the array should be $block*N$, where `N` is length
351*d38ec673SBarry Smith provided to the AOCreate*() method that created the `AO`.
3521447629fSBarry Smith
353*d38ec673SBarry Smith The permutation takes `array[i_pet] --> array[i_app]`, where `i_app` is
354*d38ec673SBarry Smith the index of `i` in the application ordering and `i_pet` is the index
355*d38ec673SBarry Smith of `i` in the PETSc ordering.
3561447629fSBarry Smith
357cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOApplicationToPetsc()`, `AOPetscToApplicationIS()`
3581447629fSBarry Smith @*/
AOPetscToApplicationPermuteReal(AO ao,PetscInt block,PetscReal array[])359d71ae5a4SJacob Faibussowitsch PetscErrorCode AOPetscToApplicationPermuteReal(AO ao, PetscInt block, PetscReal array[])
360d71ae5a4SJacob Faibussowitsch {
3611447629fSBarry Smith PetscFunctionBegin;
3621447629fSBarry Smith PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
3634f572ea9SToby Isaac PetscAssertPointer(array, 3);
364dbbe0bcdSBarry Smith PetscUseTypeMethod(ao, petsctoapplicationpermutereal, block, array);
3653ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
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
372c3339decSBarry Smith Collective
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
382cab54364SBarry Smith Level: beginner
383cab54364SBarry Smith
384cab54364SBarry Smith Notes:
385*d38ec673SBarry Smith The length of the array should be $block*N$, where `N` is length
386*d38ec673SBarry Smith provided to the AOCreate*() method that created the `AO`.
3871447629fSBarry Smith
388*d38ec673SBarry Smith The permutation takes `array[i_app] --> array[i_pet]`, where `i_app` is
389*d38ec673SBarry Smith the index of `i` in the application ordering and `i_pet` is the index
390*d38ec673SBarry Smith of `i` in the PETSc ordering.
3911447629fSBarry Smith
392cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOApplicationToPetsc()`, `AOPetscToApplicationIS()`
3931447629fSBarry Smith @*/
AOApplicationToPetscPermuteReal(AO ao,PetscInt block,PetscReal array[])394d71ae5a4SJacob Faibussowitsch PetscErrorCode AOApplicationToPetscPermuteReal(AO ao, PetscInt block, PetscReal array[])
395d71ae5a4SJacob Faibussowitsch {
3961447629fSBarry Smith PetscFunctionBegin;
3971447629fSBarry Smith PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
3984f572ea9SToby Isaac PetscAssertPointer(array, 3);
399dbbe0bcdSBarry Smith PetscUseTypeMethod(ao, applicationtopetscpermutereal, block, array);
4003ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
4011447629fSBarry Smith }
4021447629fSBarry Smith
40301e608bcSBarry Smith /*@
404cab54364SBarry Smith AOSetFromOptions - Sets `AO` options from the options database.
4051447629fSBarry Smith
406c3339decSBarry Smith Collective
4071447629fSBarry Smith
4081447629fSBarry Smith Input Parameter:
4091447629fSBarry Smith . ao - the application ordering
4101447629fSBarry Smith
411*d38ec673SBarry Smith Options Database Key:
412*d38ec673SBarry Smith . -ao_type <basic, memoryscalable> - sets the type of the `AO`
413*d38ec673SBarry Smith
4141447629fSBarry Smith Level: beginner
4151447629fSBarry Smith
416cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreate()`, `AOSetType()`, `AODestroy()`, `AOPetscToApplication()`, `AOApplicationToPetsc()`
4171447629fSBarry Smith @*/
AOSetFromOptions(AO ao)418d71ae5a4SJacob Faibussowitsch PetscErrorCode AOSetFromOptions(AO ao)
419d71ae5a4SJacob Faibussowitsch {
4201447629fSBarry Smith char type[256];
4211447629fSBarry Smith const char *def = AOBASIC;
4221447629fSBarry Smith PetscBool flg;
4231447629fSBarry Smith
4241447629fSBarry Smith PetscFunctionBegin;
4251447629fSBarry Smith PetscValidHeaderSpecific(ao, AO_CLASSID, 1);
4261447629fSBarry Smith
427d0609cedSBarry Smith PetscObjectOptionsBegin((PetscObject)ao);
4289566063dSJacob Faibussowitsch PetscCall(PetscOptionsFList("-ao_type", "AO type", "AOSetType", AOList, def, type, 256, &flg));
4291447629fSBarry Smith if (flg) {
4309566063dSJacob Faibussowitsch PetscCall(AOSetType(ao, type));
4311447629fSBarry Smith } else if (!((PetscObject)ao)->type_name) {
4329566063dSJacob Faibussowitsch PetscCall(AOSetType(ao, def));
4331447629fSBarry Smith }
434d0609cedSBarry Smith PetscOptionsEnd();
4353ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
4361447629fSBarry Smith }
4371447629fSBarry Smith
43801e608bcSBarry Smith /*@
439cab54364SBarry Smith AOSetIS - Sets the `IS` associated with the application ordering.
4401447629fSBarry Smith
441d083f849SBarry Smith Collective
4421447629fSBarry Smith
4431447629fSBarry Smith Input Parameters:
4441447629fSBarry Smith + ao - the application ordering
4451447629fSBarry Smith . isapp - index set that defines an ordering
446*d38ec673SBarry Smith - ispetsc - index set that defines another ordering (may be `NULL` to use the natural ordering)
4471447629fSBarry Smith
448cab54364SBarry Smith Level: beginner
449cab54364SBarry Smith
450*d38ec673SBarry Smith Note:
451*d38ec673SBarry Smith This routine increases the reference count of `isapp` and `ispetsc` so you may/should destroy these arguments after this call
452*d38ec673SBarry Smith if you no longer need them
45301e608bcSBarry Smith
454cab54364SBarry Smith .seealso: [](sec_ao), [](sec_scatter), `AO`, `AOCreate()`, `AODestroy()`, `AOPetscToApplication()`, `AOApplicationToPetsc()`
4551447629fSBarry Smith @*/
AOSetIS(AO ao,IS isapp,IS ispetsc)456d71ae5a4SJacob Faibussowitsch PetscErrorCode AOSetIS(AO ao, IS isapp, IS ispetsc)
457d71ae5a4SJacob Faibussowitsch {
4581447629fSBarry Smith PetscFunctionBegin;
4591447629fSBarry Smith if (ispetsc) {
4601447629fSBarry Smith PetscInt napp, npetsc;
4619566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(isapp, &napp));
4629566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(ispetsc, &npetsc));
46308401ef6SPierre Jolivet PetscCheck(napp == npetsc, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "napp %" PetscInt_FMT " != npetsc %" PetscInt_FMT ". Local IS lengths must match", napp, npetsc);
4641447629fSBarry Smith }
4659566063dSJacob Faibussowitsch if (isapp) PetscCall(PetscObjectReference((PetscObject)isapp));
4669566063dSJacob Faibussowitsch if (ispetsc) PetscCall(PetscObjectReference((PetscObject)ispetsc));
4679566063dSJacob Faibussowitsch PetscCall(ISDestroy(&ao->isapp));
4689566063dSJacob Faibussowitsch PetscCall(ISDestroy(&ao->ispetsc));
4691447629fSBarry Smith ao->isapp = isapp;
4701447629fSBarry Smith ao->ispetsc = ispetsc;
4713ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
4721447629fSBarry Smith }
4731447629fSBarry Smith
47401e608bcSBarry Smith /*@
475cab54364SBarry Smith AOCreate - Creates an application ordering. That is an object that maps from an application ordering to a PETSc ordering and vice versa
4761447629fSBarry Smith
477d083f849SBarry Smith Collective
4781447629fSBarry Smith
4792fe279fdSBarry Smith Input Parameter:
480cab54364SBarry Smith . comm - MPI communicator that is to share the `AO`
4811447629fSBarry Smith
4821447629fSBarry Smith Output Parameter:
4831447629fSBarry Smith . ao - the new application ordering
4841447629fSBarry Smith
4851447629fSBarry Smith Options Database Key:
486*d38ec673SBarry Smith + -ao_type <aotype> - create `AO` with particular format
487*d38ec673SBarry Smith - -ao_view - call `AOView()` at the conclusion of `AOCreate()`
4881447629fSBarry Smith
4891447629fSBarry Smith Level: beginner
4901447629fSBarry Smith
491*d38ec673SBarry Smith .seealso: [](sec_ao), `AO`, `AOView()`, `AOSetIS()`, `AODestroy()`, `AOPetscToApplication()`, `AOApplicationToPetsc()`
4921447629fSBarry Smith @*/
AOCreate(MPI_Comm comm,AO * ao)493d71ae5a4SJacob Faibussowitsch PetscErrorCode AOCreate(MPI_Comm comm, AO *ao)
494d71ae5a4SJacob Faibussowitsch {
4951447629fSBarry Smith AO aonew;
4961447629fSBarry Smith
4971447629fSBarry Smith PetscFunctionBegin;
4984f572ea9SToby Isaac PetscAssertPointer(ao, 2);
4999566063dSJacob Faibussowitsch PetscCall(AOInitializePackage());
5001447629fSBarry Smith
5019566063dSJacob Faibussowitsch PetscCall(PetscHeaderCreate(aonew, AO_CLASSID, "AO", "Application Ordering", "AO", comm, AODestroy, AOView));
5021447629fSBarry Smith *ao = aonew;
5033ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
5041447629fSBarry Smith }
505