1 2 /* 3 Defines the abstract operations on AO (application orderings) 4 */ 5 #include <../src/vec/is/ao/aoimpl.h> /*I "petscao.h" I*/ 6 7 /* Logging support */ 8 PetscClassId AO_CLASSID; 9 PetscLogEvent AO_PetscToApplication, AO_ApplicationToPetsc; 10 11 #undef __FUNCT__ 12 #define __FUNCT__ "AOView" 13 /*@C 14 AOView - Displays an application ordering. 15 16 Collective on AO and PetscViewer 17 18 Input Parameters: 19 + ao - the application ordering context 20 - viewer - viewer used for display 21 22 Level: intermediate 23 24 Options Database Key: 25 . -ao_view - calls AOView() at end of AOCreate() 26 27 Note: 28 The available visualization contexts include 29 + PETSC_VIEWER_STDOUT_SELF - standard output (default) 30 - PETSC_VIEWER_STDOUT_WORLD - synchronized standard 31 output where only the first processor opens 32 the file. All other processors send their 33 data to the first processor to print. 34 35 The user can open an alternative visualization context with 36 PetscViewerASCIIOpen() - output to a specified file. 37 38 .keywords: application ordering 39 40 .seealso: PetscViewerASCIIOpen() 41 @*/ 42 PetscErrorCode AOView(AO ao,PetscViewer viewer) 43 { 44 PetscErrorCode ierr; 45 46 PetscFunctionBegin; 47 PetscValidHeaderSpecific(ao,AO_CLASSID,1); 48 if (!viewer) viewer = PETSC_VIEWER_STDOUT_(PetscObjectComm((PetscObject)ao)); 49 PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 50 51 ierr = PetscObjectPrintClassNamePrefixType((PetscObject)ao,viewer);CHKERRQ(ierr); 52 ierr = (*ao->ops->view)(ao,viewer);CHKERRQ(ierr); 53 PetscFunctionReturn(0); 54 } 55 56 #undef __FUNCT__ 57 #define __FUNCT__ "AODestroy" 58 /*@C 59 AODestroy - Destroys an application ordering. 60 61 Collective on AO 62 63 Input Parameters: 64 . ao - the application ordering context 65 66 Level: beginner 67 68 .keywords: destroy, application ordering 69 70 .seealso: AOCreate() 71 @*/ 72 PetscErrorCode AODestroy(AO *ao) 73 { 74 PetscErrorCode ierr; 75 76 PetscFunctionBegin; 77 if (!*ao) PetscFunctionReturn(0); 78 PetscValidHeaderSpecific((*ao),AO_CLASSID,1); 79 if (--((PetscObject)(*ao))->refct > 0) {*ao = 0; PetscFunctionReturn(0);} 80 /* if memory was published with SAWs then destroy it */ 81 ierr = PetscObjectSAWsViewOff((PetscObject)*ao);CHKERRQ(ierr); 82 /* destroy the internal part */ 83 if ((*ao)->ops->destroy) { 84 ierr = (*(*ao)->ops->destroy)(*ao);CHKERRQ(ierr); 85 } 86 ierr = PetscHeaderDestroy(ao);CHKERRQ(ierr); 87 PetscFunctionReturn(0); 88 } 89 90 91 #include <../src/vec/is/is/impls/general/general.h> 92 /* ---------------------------------------------------------------------*/ 93 #undef __FUNCT__ 94 #define __FUNCT__ "AOPetscToApplicationIS" 95 /*@ 96 AOPetscToApplicationIS - Maps an index set in the PETSc ordering to 97 the application-defined ordering. 98 99 Collective on AO and IS 100 101 Input Parameters: 102 + ao - the application ordering context 103 - is - the index set; this is replaced with its mapped values 104 105 Output Parameter: 106 . is - the mapped index set 107 108 Level: intermediate 109 110 Notes: 111 The index set cannot be of type stride or block 112 113 Any integers in ia[] that are negative are left unchanged. This 114 allows one to convert, for example, neighbor lists that use negative 115 entries to indicate nonexistent neighbors due to boundary conditions 116 etc. 117 118 .keywords: application ordering, mapping 119 120 .seealso: AOCreateBasic(), AOView(),AOApplicationToPetsc(), 121 AOApplicationToPetscIS(),AOPetscToApplication() 122 @*/ 123 PetscErrorCode AOPetscToApplicationIS(AO ao,IS is) 124 { 125 PetscErrorCode ierr; 126 PetscInt n; 127 PetscInt *ia; 128 129 PetscFunctionBegin; 130 PetscValidHeaderSpecific(ao,AO_CLASSID,1); 131 PetscValidHeaderSpecific(is,IS_CLASSID,2); 132 ierr = ISToGeneral(is);CHKERRQ(ierr); 133 /* we cheat because we know the is is general and that we can change the indices */ 134 ierr = ISGetIndices(is,(const PetscInt**)&ia);CHKERRQ(ierr); 135 ierr = ISGetLocalSize(is,&n);CHKERRQ(ierr); 136 ierr = (*ao->ops->petsctoapplication)(ao,n,ia);CHKERRQ(ierr); 137 ierr = ISRestoreIndices(is,(const PetscInt**)&ia);CHKERRQ(ierr); 138 PetscFunctionReturn(0); 139 } 140 141 #undef __FUNCT__ 142 #define __FUNCT__ "AOApplicationToPetscIS" 143 /*@ 144 AOApplicationToPetscIS - Maps an index set in the application-defined 145 ordering to the PETSc ordering. 146 147 Collective on AO and IS 148 149 Input Parameters: 150 + ao - the application ordering context 151 - is - the index set; this is replaced with its mapped values 152 153 Output Parameter: 154 . is - the mapped index set 155 156 Level: beginner 157 158 Note: 159 The index set cannot be of type stride or block 160 161 Any integers in ia[] that are negative are left unchanged. This 162 allows one to convert, for example, neighbor lists that use negative 163 entries to indicate nonexistent neighbors due to boundary conditions, etc. 164 165 .keywords: application ordering, mapping 166 167 .seealso: AOCreateBasic(), AOView(), AOPetscToApplication(), 168 AOPetscToApplicationIS(), AOApplicationToPetsc() 169 @*/ 170 PetscErrorCode AOApplicationToPetscIS(AO ao,IS is) 171 { 172 PetscErrorCode ierr; 173 PetscInt n,*ia; 174 175 PetscFunctionBegin; 176 PetscValidHeaderSpecific(ao,AO_CLASSID,1); 177 PetscValidHeaderSpecific(is,IS_CLASSID,2); 178 ierr = ISToGeneral(is);CHKERRQ(ierr); 179 /* we cheat because we know the is is general and that we can change the indices */ 180 ierr = ISGetIndices(is,(const PetscInt**)&ia);CHKERRQ(ierr); 181 ierr = ISGetLocalSize(is,&n);CHKERRQ(ierr); 182 ierr = (*ao->ops->applicationtopetsc)(ao,n,ia);CHKERRQ(ierr); 183 ierr = ISRestoreIndices(is,(const PetscInt**)&ia);CHKERRQ(ierr); 184 PetscFunctionReturn(0); 185 } 186 187 #undef __FUNCT__ 188 #define __FUNCT__ "AOPetscToApplication" 189 /*@ 190 AOPetscToApplication - Maps a set of integers in the PETSc ordering to 191 the application-defined ordering. 192 193 Collective on AO 194 195 Input Parameters: 196 + ao - the application ordering context 197 . n - the number of integers 198 - ia - the integers; these are replaced with their mapped value 199 200 Output Parameter: 201 . ia - the mapped integers 202 203 Level: beginner 204 205 Note: 206 Any integers in ia[] that are negative are left unchanged. This 207 allows one to convert, for example, neighbor lists that use negative 208 entries to indicate nonexistent neighbors due to boundary conditions, etc. 209 210 Integers that are out of range are mapped to -1 211 212 .keywords: application ordering, mapping 213 214 .seealso: AOCreateBasic(), AOView(),AOApplicationToPetsc(), 215 AOPetscToApplicationIS(), AOApplicationToPetsc() 216 @*/ 217 PetscErrorCode AOPetscToApplication(AO ao,PetscInt n,PetscInt ia[]) 218 { 219 PetscErrorCode ierr; 220 221 PetscFunctionBegin; 222 PetscValidHeaderSpecific(ao,AO_CLASSID,1); 223 if (n) PetscValidIntPointer(ia,3); 224 ierr = (*ao->ops->petsctoapplication)(ao,n,ia);CHKERRQ(ierr); 225 PetscFunctionReturn(0); 226 } 227 228 #undef __FUNCT__ 229 #define __FUNCT__ "AOApplicationToPetsc" 230 /*@ 231 AOApplicationToPetsc - Maps a set of integers in the application-defined 232 ordering to the PETSc ordering. 233 234 Collective on AO 235 236 Input Parameters: 237 + ao - the application ordering context 238 . n - the number of integers 239 - ia - the integers; these are replaced with their mapped value 240 241 Output Parameter: 242 . ia - the mapped integers 243 244 Level: beginner 245 246 Note: 247 Any integers in ia[] that are negative are left unchanged. This 248 allows one to convert, for example, neighbor lists that use negative 249 entries to indicate nonexistent neighbors due to boundary conditions, etc. 250 251 Integers that are out of range are mapped to -1 252 253 .keywords: application ordering, mapping 254 255 .seealso: AOCreateBasic(), AOView(), AOPetscToApplication(), 256 AOPetscToApplicationIS(), AOApplicationToPetsc() 257 @*/ 258 PetscErrorCode AOApplicationToPetsc(AO ao,PetscInt n,PetscInt ia[]) 259 { 260 PetscErrorCode ierr; 261 262 PetscFunctionBegin; 263 PetscValidHeaderSpecific(ao,AO_CLASSID,1); 264 if (n) PetscValidIntPointer(ia,3); 265 ierr = (*ao->ops->applicationtopetsc)(ao,n,ia);CHKERRQ(ierr); 266 PetscFunctionReturn(0); 267 } 268 269 #undef __FUNCT__ 270 #define __FUNCT__ "AOPetscToApplicationPermuteInt" 271 /*@ 272 AOPetscToApplicationPermuteInt - Permutes an array of blocks of integers 273 in the PETSc ordering to the application-defined ordering. 274 275 Collective on AO 276 277 Input Parameters: 278 + ao - The application ordering context 279 . block - The block size 280 - array - The integer array 281 282 Output Parameter: 283 . array - The permuted array 284 285 Note: The length of the array should be block*N, where N is length 286 provided to the AOCreate*() method that created the AO. 287 288 The permutation takes array[i_pet] --> array[i_app], where i_app is 289 the index of 'i' in the application ordering and i_pet is the index 290 of 'i' in the petsc ordering. 291 292 Level: beginner 293 294 .keywords: application ordering, mapping 295 .seealso: AOCreateBasic(), AOView(), AOApplicationToPetsc(), AOPetscToApplicationIS() 296 @*/ 297 PetscErrorCode AOPetscToApplicationPermuteInt(AO ao, PetscInt block, PetscInt array[]) 298 { 299 PetscErrorCode ierr; 300 301 PetscFunctionBegin; 302 PetscValidHeaderSpecific(ao, AO_CLASSID,1); 303 PetscValidIntPointer(array,3); 304 ierr = (*ao->ops->petsctoapplicationpermuteint)(ao, block, array);CHKERRQ(ierr); 305 PetscFunctionReturn(0); 306 } 307 308 #undef __FUNCT__ 309 #define __FUNCT__ "AOApplicationToPetscPermuteInt" 310 /*@ 311 AOApplicationToPetscPermuteInt - Permutes an array of blocks of integers 312 in the application-defined ordering to the PETSc ordering. 313 314 Collective on AO 315 316 Input Parameters: 317 + ao - The application ordering context 318 . block - The block size 319 - array - The integer array 320 321 Output Parameter: 322 . array - The permuted array 323 324 Note: The length of the array should be block*N, where N is length 325 provided to the AOCreate*() method that created the AO. 326 327 The permutation takes array[i_app] --> array[i_pet], where i_app is 328 the index of 'i' in the application ordering and i_pet is the index 329 of 'i' in the petsc ordering. 330 331 Level: beginner 332 333 .keywords: application ordering, mapping 334 335 .seealso: AOCreateBasic(), AOView(), AOPetscToApplicationIS(), AOApplicationToPetsc() 336 @*/ 337 PetscErrorCode AOApplicationToPetscPermuteInt(AO ao, PetscInt block, PetscInt array[]) 338 { 339 PetscErrorCode ierr; 340 341 PetscFunctionBegin; 342 PetscValidHeaderSpecific(ao, AO_CLASSID,1); 343 PetscValidIntPointer(array,3); 344 ierr = (*ao->ops->applicationtopetscpermuteint)(ao, block, array);CHKERRQ(ierr); 345 PetscFunctionReturn(0); 346 } 347 348 #undef __FUNCT__ 349 #define __FUNCT__ "AOPetscToApplicationPermuteReal" 350 /*@ 351 AOPetscToApplicationPermuteReal - Permutes an array of blocks of reals 352 in the PETSc ordering to the application-defined ordering. 353 354 Collective on AO 355 356 Input Parameters: 357 + ao - The application ordering context 358 . block - The block size 359 - array - The integer array 360 361 Output Parameter: 362 . array - The permuted array 363 364 Note: The length of the array should be block*N, where N is length 365 provided to the AOCreate*() method that created the AO. 366 367 The permutation takes array[i_pet] --> array[i_app], where i_app is 368 the index of 'i' in the application ordering and i_pet is the index 369 of 'i' in the petsc ordering. 370 371 Level: beginner 372 373 .keywords: application ordering, mapping 374 375 .seealso: AOCreateBasic(), AOView(), AOApplicationToPetsc(), AOPetscToApplicationIS() 376 @*/ 377 PetscErrorCode AOPetscToApplicationPermuteReal(AO ao, PetscInt block, PetscReal array[]) 378 { 379 PetscErrorCode ierr; 380 381 PetscFunctionBegin; 382 PetscValidHeaderSpecific(ao, AO_CLASSID,1); 383 PetscValidIntPointer(array,3); 384 ierr = (*ao->ops->petsctoapplicationpermutereal)(ao, block, array);CHKERRQ(ierr); 385 PetscFunctionReturn(0); 386 } 387 388 #undef __FUNCT__ 389 #define __FUNCT__ "AOApplicationToPetscPermuteReal" 390 /*@ 391 AOApplicationToPetscPermuteReal - Permutes an array of blocks of reals 392 in the application-defined ordering to the PETSc ordering. 393 394 Collective on AO 395 396 Input Parameters: 397 + ao - The application ordering context 398 . block - The block size 399 - array - The integer array 400 401 Output Parameter: 402 . array - The permuted array 403 404 Note: The length of the array should be block*N, where N is length 405 provided to the AOCreate*() method that created the AO. 406 407 The permutation takes array[i_app] --> array[i_pet], where i_app is 408 the index of 'i' in the application ordering and i_pet is the index 409 of 'i' in the petsc ordering. 410 411 Level: beginner 412 413 .keywords: application ordering, mapping 414 415 .seealso: AOCreateBasic(), AOView(),AOApplicationToPetsc(), AOPetscToApplicationIS() 416 @*/ 417 PetscErrorCode AOApplicationToPetscPermuteReal(AO ao, PetscInt block, PetscReal array[]) 418 { 419 PetscErrorCode ierr; 420 421 PetscFunctionBegin; 422 PetscValidHeaderSpecific(ao, AO_CLASSID,1); 423 PetscValidIntPointer(array,3); 424 ierr = (*ao->ops->applicationtopetscpermutereal)(ao, block, array);CHKERRQ(ierr); 425 PetscFunctionReturn(0); 426 } 427 428 #undef __FUNCT__ 429 #define __FUNCT__ "AOSetFromOptions" 430 /*@C 431 AOSetFromOptions - Sets AO options from the options database. 432 433 Collective on AO 434 435 Input Parameter: 436 . ao - the application ordering 437 438 Level: beginner 439 440 .keywords: AO, options, database 441 442 .seealso: AOCreate(), AOSetType(), AODestroy(), AOPetscToApplication(), AOApplicationToPetsc() 443 @*/ 444 PetscErrorCode AOSetFromOptions(AO ao) 445 { 446 PetscErrorCode ierr; 447 char type[256]; 448 const char *def=AOBASIC; 449 PetscBool flg; 450 451 PetscFunctionBegin; 452 PetscValidHeaderSpecific(ao,AO_CLASSID,1); 453 454 ierr = PetscObjectOptionsBegin((PetscObject)ao);CHKERRQ(ierr); 455 ierr = PetscOptionsFList("-ao_type","AO type","AOSetType",AOList,def,type,256,&flg);CHKERRQ(ierr); 456 if (flg) { 457 ierr = AOSetType(ao,type);CHKERRQ(ierr); 458 } else if (!((PetscObject)ao)->type_name) { 459 ierr = AOSetType(ao,def);CHKERRQ(ierr); 460 } 461 ierr = PetscOptionsEnd();CHKERRQ(ierr); 462 PetscFunctionReturn(0); 463 } 464 465 #undef __FUNCT__ 466 #define __FUNCT__ "AOSetIS" 467 /*@C 468 AOSetIS - Sets the IS associated with the application ordering. 469 470 Collective on MPI_Comm 471 472 Input Parameters: 473 + ao - the application ordering 474 . isapp - index set that defines an ordering 475 - ispetsc - index set that defines another ordering (may be NULL to use the 476 natural ordering) 477 478 Notes: 479 The index sets isapp and ispetsc are used only for creation of ao. 480 481 Level: beginner 482 483 .keywords: AO, create 484 485 .seealso: AOCreate(), AODestroy(), AOPetscToApplication(), AOApplicationToPetsc() 486 @*/ 487 PetscErrorCode AOSetIS(AO ao,IS isapp,IS ispetsc) 488 { 489 PetscErrorCode ierr; 490 491 PetscFunctionBegin; 492 if (ispetsc) { 493 PetscInt napp,npetsc; 494 ierr = ISGetLocalSize(isapp,&napp);CHKERRQ(ierr); 495 ierr = ISGetLocalSize(ispetsc,&npetsc);CHKERRQ(ierr); 496 if (napp != npetsc) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_SIZ,"napp %D != npetsc %d. Local IS lengths must match",napp,npetsc); 497 } 498 ao->isapp = isapp; 499 ao->ispetsc = ispetsc; 500 PetscFunctionReturn(0); 501 } 502 503 #undef __FUNCT__ 504 #define __FUNCT__ "AOCreate" 505 /*@C 506 AOCreate - Creates an application ordering. 507 508 Collective on MPI_Comm 509 510 Input Parameters: 511 . comm - MPI communicator that is to share AO 512 513 Output Parameter: 514 . ao - the new application ordering 515 516 Options Database Key: 517 + -ao_type <aotype> - create ao with particular format 518 - -ao_view - call AOView() at the conclusion of AOCreate() 519 520 Level: beginner 521 522 .keywords: AO, create 523 524 .seealso: AOSetIS(), AODestroy(), AOPetscToApplication(), AOApplicationToPetsc() 525 @*/ 526 PetscErrorCode AOCreate(MPI_Comm comm,AO *ao) 527 { 528 PetscErrorCode ierr; 529 AO aonew; 530 531 PetscFunctionBegin; 532 PetscValidPointer(ao,2); 533 *ao = NULL; 534 ierr = AOInitializePackage();CHKERRQ(ierr); 535 536 ierr = PetscHeaderCreate(aonew,_p_AO,struct _AOOps,AO_CLASSID,"AO","Application Ordering","AO",comm,AODestroy,AOView);CHKERRQ(ierr); 537 ierr = PetscMemzero(aonew->ops, sizeof(struct _AOOps));CHKERRQ(ierr); 538 *ao = aonew; 539 PetscFunctionReturn(0); 540 } 541