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 10*ffeef943SBarry 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 35cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `PetscViewerASCIIOpen()` 361447629fSBarry Smith @*/ 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 49*ffeef943SBarry 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 56736c3998SJose E. Roman . obj - Optional object 57736c3998SJose E. Roman - name - command line option 58fe2efc57SMark 59fe2efc57SMark Level: intermediate 60cab54364SBarry Smith 61cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOView`, `PetscObjectViewFromOptions()`, `AOCreate()` 62fe2efc57SMark @*/ 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 @*/ 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> 1031447629fSBarry Smith /* ---------------------------------------------------------------------*/ 1041cc6b274SLisandro Dalcin 1051cc6b274SLisandro Dalcin PETSC_INTERN PetscErrorCode ISSetUp_General(IS); 1061cc6b274SLisandro Dalcin 1071447629fSBarry Smith /*@ 1081447629fSBarry Smith AOPetscToApplicationIS - Maps an index set in the PETSc ordering to 1091447629fSBarry Smith the application-defined ordering. 1101447629fSBarry Smith 111c3339decSBarry Smith Collective 1121447629fSBarry Smith 1131447629fSBarry Smith Input Parameters: 1141447629fSBarry Smith + ao - the application ordering context 1151447629fSBarry Smith - is - the index set; this is replaced with its mapped values 1161447629fSBarry Smith 1171447629fSBarry Smith Output Parameter: 1181447629fSBarry Smith . is - the mapped index set 1191447629fSBarry Smith 1201447629fSBarry Smith Level: intermediate 1211447629fSBarry Smith 1221447629fSBarry Smith Notes: 1231447629fSBarry Smith The index set cannot be of type stride or block 1241447629fSBarry Smith 125cab54364SBarry Smith Any integers in is that are negative are left unchanged. This 1261447629fSBarry Smith allows one to convert, for example, neighbor lists that use negative 127cab54364SBarry Smith entries to indicate nonexistent neighbors due to boundary conditions etc. 1281447629fSBarry Smith 129cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOApplicationToPetsc()`, 130c2e3fba1SPatrick Sanan `AOApplicationToPetscIS()`, `AOPetscToApplication()` 1311447629fSBarry Smith @*/ 132d71ae5a4SJacob Faibussowitsch PetscErrorCode AOPetscToApplicationIS(AO ao, IS is) 133d71ae5a4SJacob Faibussowitsch { 1341447629fSBarry Smith PetscInt n; 1351447629fSBarry Smith PetscInt *ia; 1361447629fSBarry Smith 1371447629fSBarry Smith PetscFunctionBegin; 1381447629fSBarry Smith PetscValidHeaderSpecific(ao, AO_CLASSID, 1); 1391447629fSBarry Smith PetscValidHeaderSpecific(is, IS_CLASSID, 2); 1409566063dSJacob Faibussowitsch PetscCall(ISToGeneral(is)); 14115229ffcSPierre Jolivet /* we cheat because we know the IS is general and that we can change the indices */ 1429566063dSJacob Faibussowitsch PetscCall(ISGetIndices(is, (const PetscInt **)&ia)); 1439566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(is, &n)); 144dbbe0bcdSBarry Smith PetscUseTypeMethod(ao, petsctoapplication, n, ia); 1459566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(is, (const PetscInt **)&ia)); 1461cc6b274SLisandro Dalcin /* updated cached values (sorted, min, max, etc.)*/ 1479566063dSJacob Faibussowitsch PetscCall(ISSetUp_General(is)); 1483ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1491447629fSBarry Smith } 1501447629fSBarry Smith 1511447629fSBarry Smith /*@ 1521447629fSBarry Smith AOApplicationToPetscIS - Maps an index set in the application-defined 1531447629fSBarry Smith ordering to the PETSc ordering. 1541447629fSBarry Smith 155c3339decSBarry Smith Collective 1561447629fSBarry Smith 1571447629fSBarry Smith Input Parameters: 1581447629fSBarry Smith + ao - the application ordering context 1591447629fSBarry Smith - is - the index set; this is replaced with its mapped values 1601447629fSBarry Smith 1611447629fSBarry Smith Output Parameter: 1621447629fSBarry Smith . is - the mapped index set 1631447629fSBarry Smith 1641447629fSBarry Smith Level: beginner 1651447629fSBarry Smith 166cab54364SBarry Smith Notes: 1671447629fSBarry Smith The index set cannot be of type stride or block 1681447629fSBarry Smith 169cab54364SBarry Smith Any integers in is that are negative are left unchanged. This 1701447629fSBarry Smith allows one to convert, for example, neighbor lists that use negative 1711447629fSBarry Smith entries to indicate nonexistent neighbors due to boundary conditions, etc. 1721447629fSBarry Smith 173cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOPetscToApplication()`, 174db781477SPatrick Sanan `AOPetscToApplicationIS()`, `AOApplicationToPetsc()` 1751447629fSBarry Smith @*/ 176d71ae5a4SJacob Faibussowitsch PetscErrorCode AOApplicationToPetscIS(AO ao, IS is) 177d71ae5a4SJacob Faibussowitsch { 1781447629fSBarry Smith PetscInt n, *ia; 1791447629fSBarry Smith 1801447629fSBarry Smith PetscFunctionBegin; 1811447629fSBarry Smith PetscValidHeaderSpecific(ao, AO_CLASSID, 1); 1821447629fSBarry Smith PetscValidHeaderSpecific(is, IS_CLASSID, 2); 1839566063dSJacob Faibussowitsch PetscCall(ISToGeneral(is)); 18415229ffcSPierre Jolivet /* we cheat because we know the IS is general and that we can change the indices */ 1859566063dSJacob Faibussowitsch PetscCall(ISGetIndices(is, (const PetscInt **)&ia)); 1869566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(is, &n)); 187dbbe0bcdSBarry Smith PetscUseTypeMethod(ao, applicationtopetsc, n, ia); 1889566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(is, (const PetscInt **)&ia)); 1891cc6b274SLisandro Dalcin /* updated cached values (sorted, min, max, etc.)*/ 1909566063dSJacob Faibussowitsch PetscCall(ISSetUp_General(is)); 1913ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1921447629fSBarry Smith } 1931447629fSBarry Smith 1941447629fSBarry Smith /*@ 1951447629fSBarry Smith AOPetscToApplication - Maps a set of integers in the PETSc ordering to 1961447629fSBarry Smith the application-defined ordering. 1971447629fSBarry Smith 198c3339decSBarry Smith Collective 1991447629fSBarry Smith 2001447629fSBarry Smith Input Parameters: 2011447629fSBarry Smith + ao - the application ordering context 2021447629fSBarry Smith . n - the number of integers 2031447629fSBarry Smith - ia - the integers; these are replaced with their mapped value 2041447629fSBarry Smith 2051447629fSBarry Smith Output Parameter: 2061447629fSBarry Smith . ia - the mapped integers 2071447629fSBarry Smith 2081447629fSBarry Smith Level: beginner 2091447629fSBarry Smith 2101447629fSBarry Smith Note: 2111447629fSBarry Smith Any integers in ia[] that are negative are left unchanged. This 2121447629fSBarry Smith allows one to convert, for example, neighbor lists that use negative 2131447629fSBarry Smith entries to indicate nonexistent neighbors due to boundary conditions, etc. 2141447629fSBarry Smith 2151447629fSBarry Smith Integers that are out of range are mapped to -1 2161447629fSBarry Smith 217cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOApplicationToPetsc()`, 21838b5cf2dSJacob Faibussowitsch `AOPetscToApplicationIS()` 2191447629fSBarry Smith @*/ 220d71ae5a4SJacob Faibussowitsch PetscErrorCode AOPetscToApplication(AO ao, PetscInt n, PetscInt ia[]) 221d71ae5a4SJacob Faibussowitsch { 2221447629fSBarry Smith PetscFunctionBegin; 2231447629fSBarry Smith PetscValidHeaderSpecific(ao, AO_CLASSID, 1); 2244f572ea9SToby Isaac if (n) PetscAssertPointer(ia, 3); 225dbbe0bcdSBarry Smith PetscUseTypeMethod(ao, petsctoapplication, n, ia); 2263ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2271447629fSBarry Smith } 2281447629fSBarry Smith 2291447629fSBarry Smith /*@ 2301447629fSBarry Smith AOApplicationToPetsc - Maps a set of integers in the application-defined 2311447629fSBarry Smith ordering to the PETSc ordering. 2321447629fSBarry Smith 233c3339decSBarry Smith Collective 2341447629fSBarry Smith 2351447629fSBarry Smith Input Parameters: 2361447629fSBarry Smith + ao - the application ordering context 2371447629fSBarry Smith . n - the number of integers 2381447629fSBarry Smith - ia - the integers; these are replaced with their mapped value 2391447629fSBarry Smith 2401447629fSBarry Smith Output Parameter: 2411447629fSBarry Smith . ia - the mapped integers 2421447629fSBarry Smith 2431447629fSBarry Smith Level: beginner 2441447629fSBarry Smith 245cab54364SBarry Smith Notes: 2461447629fSBarry Smith Any integers in ia[] that are negative are left unchanged. This 2471447629fSBarry Smith allows one to convert, for example, neighbor lists that use negative 2481447629fSBarry Smith entries to indicate nonexistent neighbors due to boundary conditions, etc. 2491447629fSBarry Smith 2501447629fSBarry Smith Integers that are out of range are mapped to -1 2511447629fSBarry Smith 252cab54364SBarry Smith .seealso: [](sec_ao), `AOCreateBasic()`, `AOView()`, `AOPetscToApplication()`, 25342747ad1SJacob Faibussowitsch `AOPetscToApplicationIS()` 2541447629fSBarry Smith @*/ 255d71ae5a4SJacob Faibussowitsch PetscErrorCode AOApplicationToPetsc(AO ao, PetscInt n, PetscInt ia[]) 256d71ae5a4SJacob Faibussowitsch { 2571447629fSBarry Smith PetscFunctionBegin; 2581447629fSBarry Smith PetscValidHeaderSpecific(ao, AO_CLASSID, 1); 2594f572ea9SToby Isaac if (n) PetscAssertPointer(ia, 3); 260dbbe0bcdSBarry Smith PetscUseTypeMethod(ao, applicationtopetsc, n, ia); 2613ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2621447629fSBarry Smith } 2631447629fSBarry Smith 2641447629fSBarry Smith /*@ 2651447629fSBarry Smith AOPetscToApplicationPermuteInt - Permutes an array of blocks of integers 2661447629fSBarry Smith in the PETSc ordering to the application-defined ordering. 2671447629fSBarry Smith 268c3339decSBarry Smith Collective 2691447629fSBarry Smith 2701447629fSBarry Smith Input Parameters: 2711447629fSBarry Smith + ao - The application ordering context 2721447629fSBarry Smith . block - The block size 2731447629fSBarry Smith - array - The integer array 2741447629fSBarry Smith 2751447629fSBarry Smith Output Parameter: 2761447629fSBarry Smith . array - The permuted array 2771447629fSBarry Smith 278cab54364SBarry Smith Level: beginner 279cab54364SBarry Smith 280cab54364SBarry Smith Notes: 281cab54364SBarry Smith The length of the array should be block*N, where N is length 2821447629fSBarry Smith provided to the AOCreate*() method that created the AO. 2831447629fSBarry Smith 2841447629fSBarry Smith The permutation takes array[i_pet] --> array[i_app], where i_app is 2851447629fSBarry Smith the index of 'i' in the application ordering and i_pet is the index 2861447629fSBarry Smith of 'i' in the petsc ordering. 2871447629fSBarry Smith 288cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOApplicationToPetsc()`, `AOPetscToApplicationIS()` 2891447629fSBarry Smith @*/ 290d71ae5a4SJacob Faibussowitsch PetscErrorCode AOPetscToApplicationPermuteInt(AO ao, PetscInt block, PetscInt array[]) 291d71ae5a4SJacob Faibussowitsch { 2921447629fSBarry Smith PetscFunctionBegin; 2931447629fSBarry Smith PetscValidHeaderSpecific(ao, AO_CLASSID, 1); 2944f572ea9SToby Isaac PetscAssertPointer(array, 3); 295dbbe0bcdSBarry Smith PetscUseTypeMethod(ao, petsctoapplicationpermuteint, block, array); 2963ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2971447629fSBarry Smith } 2981447629fSBarry Smith 2991447629fSBarry Smith /*@ 3001447629fSBarry Smith AOApplicationToPetscPermuteInt - Permutes an array of blocks of integers 3011447629fSBarry Smith in the application-defined ordering to the PETSc ordering. 3021447629fSBarry Smith 303c3339decSBarry Smith Collective 3041447629fSBarry Smith 3051447629fSBarry Smith Input Parameters: 3061447629fSBarry Smith + ao - The application ordering context 3071447629fSBarry Smith . block - The block size 3081447629fSBarry Smith - array - The integer array 3091447629fSBarry Smith 3101447629fSBarry Smith Output Parameter: 3111447629fSBarry Smith . array - The permuted array 3121447629fSBarry Smith 313cab54364SBarry Smith Level: beginner 314cab54364SBarry Smith 315cab54364SBarry Smith Notes: 316cab54364SBarry Smith The length of the array should be block*N, where N is length 3171447629fSBarry Smith provided to the AOCreate*() method that created the AO. 3181447629fSBarry Smith 3191447629fSBarry Smith The permutation takes array[i_app] --> array[i_pet], where i_app is 3201447629fSBarry Smith the index of 'i' in the application ordering and i_pet is the index 3211447629fSBarry Smith of 'i' in the petsc ordering. 3221447629fSBarry Smith 323cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOPetscToApplicationIS()`, `AOApplicationToPetsc()` 3241447629fSBarry Smith @*/ 325d71ae5a4SJacob Faibussowitsch PetscErrorCode AOApplicationToPetscPermuteInt(AO ao, PetscInt block, PetscInt array[]) 326d71ae5a4SJacob Faibussowitsch { 3271447629fSBarry Smith PetscFunctionBegin; 3281447629fSBarry Smith PetscValidHeaderSpecific(ao, AO_CLASSID, 1); 3294f572ea9SToby Isaac PetscAssertPointer(array, 3); 330dbbe0bcdSBarry Smith PetscUseTypeMethod(ao, applicationtopetscpermuteint, block, array); 3313ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 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 338c3339decSBarry Smith Collective 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 348cab54364SBarry Smith Level: beginner 349cab54364SBarry Smith 350cab54364SBarry Smith Notes: 351cab54364SBarry Smith The length of the array should be block*N, where N is length 3521447629fSBarry Smith provided to the AOCreate*() method that created the AO. 3531447629fSBarry Smith 3541447629fSBarry Smith The permutation takes array[i_pet] --> array[i_app], where i_app is 3551447629fSBarry Smith the index of 'i' in the application ordering and i_pet is the index 3561447629fSBarry Smith of 'i' in the petsc ordering. 3571447629fSBarry Smith 358cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOApplicationToPetsc()`, `AOPetscToApplicationIS()` 3591447629fSBarry Smith @*/ 360d71ae5a4SJacob Faibussowitsch PetscErrorCode AOPetscToApplicationPermuteReal(AO ao, PetscInt block, PetscReal array[]) 361d71ae5a4SJacob Faibussowitsch { 3621447629fSBarry Smith PetscFunctionBegin; 3631447629fSBarry Smith PetscValidHeaderSpecific(ao, AO_CLASSID, 1); 3644f572ea9SToby Isaac PetscAssertPointer(array, 3); 365dbbe0bcdSBarry Smith PetscUseTypeMethod(ao, petsctoapplicationpermutereal, block, array); 3663ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3671447629fSBarry Smith } 3681447629fSBarry Smith 3691447629fSBarry Smith /*@ 3701447629fSBarry Smith AOApplicationToPetscPermuteReal - Permutes an array of blocks of reals 3711447629fSBarry Smith in the application-defined ordering to the PETSc ordering. 3721447629fSBarry Smith 373c3339decSBarry Smith Collective 3741447629fSBarry Smith 3751447629fSBarry Smith Input Parameters: 3761447629fSBarry Smith + ao - The application ordering context 3771447629fSBarry Smith . block - The block size 3781447629fSBarry Smith - array - The integer array 3791447629fSBarry Smith 3801447629fSBarry Smith Output Parameter: 3811447629fSBarry Smith . array - The permuted array 3821447629fSBarry Smith 383cab54364SBarry Smith Level: beginner 384cab54364SBarry Smith 385cab54364SBarry Smith Notes: 386cab54364SBarry Smith The length of the array should be block*N, where N is length 3871447629fSBarry Smith provided to the AOCreate*() method that created the AO. 3881447629fSBarry Smith 3891447629fSBarry Smith The permutation takes array[i_app] --> array[i_pet], where i_app is 3901447629fSBarry Smith the index of 'i' in the application ordering and i_pet is the index 3911447629fSBarry Smith of 'i' in the petsc ordering. 3921447629fSBarry Smith 393cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreateBasic()`, `AOView()`, `AOApplicationToPetsc()`, `AOPetscToApplicationIS()` 3941447629fSBarry Smith @*/ 395d71ae5a4SJacob Faibussowitsch PetscErrorCode AOApplicationToPetscPermuteReal(AO ao, PetscInt block, PetscReal array[]) 396d71ae5a4SJacob Faibussowitsch { 3971447629fSBarry Smith PetscFunctionBegin; 3981447629fSBarry Smith PetscValidHeaderSpecific(ao, AO_CLASSID, 1); 3994f572ea9SToby Isaac PetscAssertPointer(array, 3); 400dbbe0bcdSBarry Smith PetscUseTypeMethod(ao, applicationtopetscpermutereal, block, array); 4013ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 4021447629fSBarry Smith } 4031447629fSBarry Smith 40401e608bcSBarry Smith /*@ 405cab54364SBarry Smith AOSetFromOptions - Sets `AO` options from the options database. 4061447629fSBarry Smith 407c3339decSBarry Smith Collective 4081447629fSBarry Smith 4091447629fSBarry Smith Input Parameter: 4101447629fSBarry Smith . ao - the application ordering 4111447629fSBarry Smith 4121447629fSBarry Smith Level: beginner 4131447629fSBarry Smith 414cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOCreate()`, `AOSetType()`, `AODestroy()`, `AOPetscToApplication()`, `AOApplicationToPetsc()` 4151447629fSBarry Smith @*/ 416d71ae5a4SJacob Faibussowitsch PetscErrorCode AOSetFromOptions(AO ao) 417d71ae5a4SJacob Faibussowitsch { 4181447629fSBarry Smith char type[256]; 4191447629fSBarry Smith const char *def = AOBASIC; 4201447629fSBarry Smith PetscBool flg; 4211447629fSBarry Smith 4221447629fSBarry Smith PetscFunctionBegin; 4231447629fSBarry Smith PetscValidHeaderSpecific(ao, AO_CLASSID, 1); 4241447629fSBarry Smith 425d0609cedSBarry Smith PetscObjectOptionsBegin((PetscObject)ao); 4269566063dSJacob Faibussowitsch PetscCall(PetscOptionsFList("-ao_type", "AO type", "AOSetType", AOList, def, type, 256, &flg)); 4271447629fSBarry Smith if (flg) { 4289566063dSJacob Faibussowitsch PetscCall(AOSetType(ao, type)); 4291447629fSBarry Smith } else if (!((PetscObject)ao)->type_name) { 4309566063dSJacob Faibussowitsch PetscCall(AOSetType(ao, def)); 4311447629fSBarry Smith } 432d0609cedSBarry Smith PetscOptionsEnd(); 4333ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 4341447629fSBarry Smith } 4351447629fSBarry Smith 43601e608bcSBarry Smith /*@ 437cab54364SBarry Smith AOSetIS - Sets the `IS` associated with the application ordering. 4381447629fSBarry Smith 439d083f849SBarry Smith Collective 4401447629fSBarry Smith 4411447629fSBarry Smith Input Parameters: 4421447629fSBarry Smith + ao - the application ordering 4431447629fSBarry Smith . isapp - index set that defines an ordering 4442fe279fdSBarry Smith - ispetsc - index set that defines another ordering (may be `NULL` to use the 4451447629fSBarry Smith natural ordering) 4461447629fSBarry Smith 447cab54364SBarry Smith Level: beginner 448cab54364SBarry Smith 4491447629fSBarry Smith Notes: 4501447629fSBarry Smith The index sets isapp and ispetsc are used only for creation of ao. 4511447629fSBarry Smith 45201e608bcSBarry 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 45301e608bcSBarry Smith 454cab54364SBarry Smith .seealso: [](sec_ao), [](sec_scatter), `AO`, `AOCreate()`, `AODestroy()`, `AOPetscToApplication()`, `AOApplicationToPetsc()` 4551447629fSBarry Smith @*/ 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: 4861447629fSBarry Smith + -ao_type <aotype> - create ao with particular format 4871447629fSBarry Smith - -ao_view - call AOView() at the conclusion of AOCreate() 4881447629fSBarry Smith 4891447629fSBarry Smith Level: beginner 4901447629fSBarry Smith 491cab54364SBarry Smith .seealso: [](sec_ao), `AO`, `AOSetIS()`, `AODestroy()`, `AOPetscToApplication()`, `AOApplicationToPetsc()` 4921447629fSBarry Smith @*/ 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); 4991447629fSBarry Smith *ao = NULL; 5009566063dSJacob Faibussowitsch PetscCall(AOInitializePackage()); 5011447629fSBarry Smith 5029566063dSJacob Faibussowitsch PetscCall(PetscHeaderCreate(aonew, AO_CLASSID, "AO", "Application Ordering", "AO", comm, AODestroy, AOView)); 5031447629fSBarry Smith *ao = aonew; 5043ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 5051447629fSBarry Smith } 506