1 #define PETSC_DLL 2 /* 3 These routines simplify the use of command line, file options, etc., 4 and are used to manipulate the options database. 5 6 This file uses regular malloc and free because it cannot know 7 what malloc is being used until it has already processed the input. 8 */ 9 10 #include "petsc.h" /*I "petsc.h" I*/ 11 #include "petscsys.h" 12 #if defined(PETSC_HAVE_STDLIB_H) 13 #include <stdlib.h> 14 #endif 15 16 /* 17 Keep a linked list of options that have been posted and we are waiting for 18 user selection 19 20 Eventually we'll attach this beast to a MPI_Comm 21 */ 22 PetscOptionsObjectType PetscOptionsObject; 23 PetscInt PetscOptionsPublishCount = 0; 24 25 26 #undef __FUNCT__ 27 #define __FUNCT__ "PetscOptionsHelpAddList" 28 PetscErrorCode PetscOptionsHelpAddList(const char prefix[],const char title[],const char mansec[]) 29 { 30 int ierr; 31 PetscOptionsHelp newhelp; 32 PetscFunctionBegin; 33 ierr = PetscNew(struct _p_PetscOptionsHelp,&newhelp);CHKERRQ(ierr); 34 ierr = PetscStrallocpy(prefix,&newhelp->prefix);CHKERRQ(ierr); 35 ierr = PetscStrallocpy(title,&newhelp->title);CHKERRQ(ierr); 36 ierr = PetscStrallocpy(mansec,&newhelp->mansec);CHKERRQ(ierr); 37 newhelp->next = 0; 38 39 if (!PetscOptionsObject.help) { 40 PetscOptionsObject.help = newhelp; 41 } else { 42 newhelp->next = PetscOptionsObject.help; 43 PetscOptionsObject.help = newhelp; 44 } 45 PetscFunctionReturn(0); 46 } 47 48 #undef __FUNCT__ 49 #define __FUNCT__ "PetscOptionsHelpDestroyList" 50 PetscErrorCode PetscOptionsHelpDestroyList(void) 51 { 52 PetscErrorCode ierr; 53 PetscOptionsHelp help = PetscOptionsObject.help, next; 54 55 PetscFunctionBegin; 56 while (help) { 57 next = help->next; 58 ierr = PetscStrfree(help->prefix);CHKERRQ(ierr); 59 ierr = PetscStrfree(help->title);CHKERRQ(ierr); 60 ierr = PetscStrfree(help->mansec);CHKERRQ(ierr); 61 ierr = PetscFree(help);CHKERRQ(ierr); 62 help = next; 63 } 64 PetscFunctionReturn(0); 65 } 66 67 68 #undef __FUNCT__ 69 #define __FUNCT__ "PetscOptionsHelpFindList" 70 PetscErrorCode PetscOptionsHelpFindList(const char prefix[],const char title[],const char mansec[],PetscTruth *flg) 71 { 72 PetscErrorCode ierr; 73 PetscTruth flg1,flg2,flg3; 74 PetscOptionsHelp help = PetscOptionsObject.help; 75 PetscFunctionBegin; 76 while (help) { 77 ierr = PetscStrcmp(help->prefix,prefix,&flg1);CHKERRQ(ierr); 78 ierr = PetscStrcmp(help->title,title,&flg2);CHKERRQ(ierr); 79 ierr = PetscStrcmp(help->mansec,mansec,&flg3);CHKERRQ(ierr); 80 if (flg1 && flg2 && flg3) { 81 *flg = PETSC_TRUE; 82 break; 83 } 84 help = help->next; 85 } 86 PetscFunctionReturn(0); 87 88 } 89 90 #undef __FUNCT__ 91 #define __FUNCT__ "PetscOptionsHelpCheckAddList" 92 PetscErrorCode PetscOptionsHelpCheckAddList(const char prefix[],const char title[],const char mansec[],PetscTruth *flg) 93 { 94 PetscFunctionBegin; 95 PetscOptionsHelpFindList(prefix,title,mansec,flg); 96 if (!(*flg)) PetscOptionsHelpAddList(prefix,title,mansec); 97 PetscFunctionReturn(0); 98 } 99 100 #undef __FUNCT__ 101 #define __FUNCT__ "PetscOptionsBegin_Private" 102 /* 103 Handles setting up the data structure in a call to PetscOptionsBegin() 104 */ 105 PetscErrorCode PetscOptionsBegin_Private(MPI_Comm comm,const char prefix[],const char title[],const char mansec[]) 106 { 107 PetscErrorCode ierr; 108 109 PetscFunctionBegin; 110 PetscOptionsObject.next = 0; 111 PetscOptionsObject.comm = comm; 112 PetscOptionsObject.changedmethod = PETSC_FALSE; 113 if (PetscOptionsObject.prefix) { 114 ierr = PetscStrfree(PetscOptionsObject.prefix);CHKERRQ(ierr); PetscOptionsObject.prefix = 0; 115 } 116 ierr = PetscStrallocpy(prefix,&PetscOptionsObject.prefix);CHKERRQ(ierr); 117 if (PetscOptionsObject.title) { 118 ierr = PetscStrfree(PetscOptionsObject.title);CHKERRQ(ierr); PetscOptionsObject.title = 0; 119 } 120 ierr = PetscStrallocpy(title,&PetscOptionsObject.title);CHKERRQ(ierr); 121 122 ierr = PetscOptionsHasName(PETSC_NULL,"-help",&PetscOptionsObject.printhelp);CHKERRQ(ierr); 123 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) { 124 ierr = PetscOptionsHelpCheckAddList(prefix,title,mansec,&PetscOptionsObject.alreadyprinted); 125 if (!PetscOptionsObject.alreadyprinted) { 126 ierr = (*PetscHelpPrintf)(comm,"%s -------------------------------------------------\n",title);CHKERRQ(ierr); 127 } 128 } 129 PetscFunctionReturn(0); 130 } 131 132 /* 133 Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd() 134 */ 135 #undef __FUNCT__ 136 #define __FUNCT__ "PetscOptionsCreate_Private" 137 static int PetscOptionsCreate_Private(const char opt[],const char text[],const char man[],PetscOptionType t,PetscOptions *amsopt) 138 { 139 int ierr; 140 PetscOptions next; 141 142 PetscFunctionBegin; 143 ierr = PetscNew(struct _p_PetscOptions,amsopt);CHKERRQ(ierr); 144 (*amsopt)->next = 0; 145 (*amsopt)->set = PETSC_FALSE; 146 (*amsopt)->type = t; 147 (*amsopt)->data = 0; 148 (*amsopt)->edata = 0; 149 150 ierr = PetscStrallocpy(text,&(*amsopt)->text);CHKERRQ(ierr); 151 ierr = PetscStrallocpy(opt,&(*amsopt)->option);CHKERRQ(ierr); 152 ierr = PetscStrallocpy(man,&(*amsopt)->man);CHKERRQ(ierr); 153 154 if (!PetscOptionsObject.next) { 155 PetscOptionsObject.next = *amsopt; 156 } else { 157 next = PetscOptionsObject.next; 158 while (next->next) next = next->next; 159 next->next = *amsopt; 160 } 161 PetscFunctionReturn(0); 162 } 163 164 #undef __FUNCT__ 165 #define __FUNCT__ "PetscScanString" 166 /* 167 PetscScanString - 168 169 Bugs: 170 . Assumes process 0 of the given communicator has access to stdin 171 172 */ 173 static PetscErrorCode PetscScanString(MPI_Comm comm,PetscInt n,char str[],PetscTruth *set) 174 { 175 PetscInt i; 176 char c; 177 PetscMPIInt rank; 178 PetscErrorCode ierr; 179 180 PetscFunctionBegin; 181 ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); 182 if (!rank) { 183 c = (char) getchar(); 184 i = 0; 185 while ( c != '\n' && i < n-1) { 186 str[i++] = c; 187 c = (char) getchar(); 188 } 189 str[i] = 0; 190 } 191 ierr = MPI_Bcast(str,n,MPI_CHAR,0,comm);CHKERRQ(ierr); 192 if (str[0]) *set = PETSC_TRUE; else *set = PETSC_FALSE; 193 PetscFunctionReturn(0); 194 } 195 196 #undef __FUNCT__ 197 #define __FUNCT__ "PetscOptionsGetFromTextInput" 198 /* 199 PetscOptionsGetFromTextInput 200 201 Notes: this isn't really practical, it is just to demonstrate the principle 202 203 Bugs: 204 + All processes must traverse through the exact same set of option queries do to the call to PetscScanString() 205 - Only works for PetscInt == int, PetscReal == double etc 206 207 */ 208 PetscErrorCode PetscOptionsGetFromTextInput() 209 { 210 PetscErrorCode ierr; 211 PetscOptions next = PetscOptionsObject.next; 212 char str[512]; 213 int id; 214 PetscTruth set; 215 double ir; 216 217 ierr = (*PetscPrintf)(PetscOptionsObject.comm,"%s -------------------------------------------------\n",PetscOptionsObject.title);CHKERRQ(ierr); 218 while (next) { 219 switch (next->type) { 220 case OPTION_HEAD: 221 break; 222 case OPTION_INT: 223 ierr = PetscPrintf(PetscOptionsObject.comm,"-%s%s <%d>: %s (%s)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1,*(int*)next->data,next->text,next->man);CHKERRQ(ierr); 224 ierr = PetscScanString(PETSC_COMM_WORLD,512,str,&set);CHKERRQ(ierr); 225 if (set) { 226 sscanf(str,"%d",&id); 227 next->set = PETSC_TRUE; 228 *((PetscInt*)next->data) = id; 229 } 230 break; 231 case OPTION_REAL: 232 ierr = PetscPrintf(PetscOptionsObject.comm,"-%s%s <%g>: %s (%s)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1,*(double*)next->data,next->text,next->man);CHKERRQ(ierr); 233 ierr = PetscScanString(PETSC_COMM_WORLD,512,str,&set);CHKERRQ(ierr); 234 if (set) { 235 sscanf(str,"%le",&ir); 236 next->set = PETSC_TRUE; 237 *((PetscReal*)next->data) = ir; 238 } 239 break; 240 case OPTION_LOGICAL: 241 case OPTION_STRING: 242 ierr = PetscPrintf(PetscOptionsObject.comm,"-%s%s <%s>: %s (%s)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1,(char*)next->data,next->text,next->man);CHKERRQ(ierr); 243 ierr = PetscScanString(PETSC_COMM_WORLD,512,str,&set);CHKERRQ(ierr); 244 if (set) { 245 next->set = PETSC_TRUE; 246 ierr = PetscStrcpy(next->data,str);CHKERRQ(ierr); 247 } 248 break; 249 default: 250 break; 251 } 252 next = next->next; 253 } 254 PetscFunctionReturn(0); 255 } 256 257 #undef __FUNCT__ 258 #define __FUNCT__ "PetscOptionsEnd_Private" 259 PetscErrorCode PetscOptionsEnd_Private(void) 260 { 261 PetscErrorCode ierr; 262 PetscOptions last; 263 char option[256],value[1024],tmp[32]; 264 PetscInt j; 265 266 PetscFunctionBegin; 267 268 if (PetscOptionsObject.next) { 269 if (PetscOptionsPublishCount == 0) { 270 ierr = PetscOptionsGetFromTextInput(); 271 } 272 } 273 274 ierr = PetscStrfree(PetscOptionsObject.title);CHKERRQ(ierr); PetscOptionsObject.title = 0; 275 ierr = PetscStrfree(PetscOptionsObject.prefix);CHKERRQ(ierr); PetscOptionsObject.prefix = 0; 276 277 /* reset counter to -2; this updates the screen with the new options for the selected method */ 278 if (PetscOptionsObject.changedmethod) PetscOptionsPublishCount = -2; 279 /* reset alreadyprinted flag */ 280 PetscOptionsObject.alreadyprinted = PETSC_FALSE; 281 282 while (PetscOptionsObject.next) { 283 if (PetscOptionsObject.next->set) { 284 if (PetscOptionsObject.prefix) { 285 ierr = PetscStrcpy(option,"-");CHKERRQ(ierr); 286 ierr = PetscStrcat(option,PetscOptionsObject.prefix);CHKERRQ(ierr); 287 ierr = PetscStrcat(option,PetscOptionsObject.next->option+1);CHKERRQ(ierr); 288 } else { 289 ierr = PetscStrcpy(option,PetscOptionsObject.next->option);CHKERRQ(ierr); 290 } 291 292 switch (PetscOptionsObject.next->type) { 293 case OPTION_HEAD: 294 break; 295 case OPTION_INT: 296 sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject.next->data); 297 break; 298 case OPTION_REAL: 299 sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject.next->data); 300 break; 301 case OPTION_REAL_ARRAY: 302 sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[0]); 303 for (j=1; j<PetscOptionsObject.next->arraylength; j++) { 304 sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[j]); 305 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 306 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 307 } 308 break; 309 case OPTION_LOGICAL: 310 ierr = PetscStrcpy(value,(char*)PetscOptionsObject.next->data);CHKERRQ(ierr); 311 break; 312 case OPTION_LIST: 313 ierr = PetscStrcpy(value,(char*)PetscOptionsObject.next->data);CHKERRQ(ierr); 314 break; 315 case OPTION_STRING: /* also handles string arrays */ 316 ierr = PetscStrcpy(value,(char*)PetscOptionsObject.next->data);CHKERRQ(ierr); 317 break; 318 } 319 ierr = PetscOptionsSetValue(option,value);CHKERRQ(ierr); 320 } 321 ierr = PetscStrfree(PetscOptionsObject.next->text);CHKERRQ(ierr); 322 ierr = PetscStrfree(PetscOptionsObject.next->option);CHKERRQ(ierr); 323 ierr = PetscFree(PetscOptionsObject.next->man);CHKERRQ(ierr); 324 ierr = PetscFree(PetscOptionsObject.next->data);CHKERRQ(ierr); 325 ierr = PetscFree(PetscOptionsObject.next->edata);CHKERRQ(ierr); 326 last = PetscOptionsObject.next; 327 PetscOptionsObject.next = PetscOptionsObject.next->next; 328 ierr = PetscFree(last);CHKERRQ(ierr); 329 } 330 PetscOptionsObject.next = 0; 331 PetscFunctionReturn(0); 332 } 333 334 #undef __FUNCT__ 335 #define __FUNCT__ "PetscOptionsEnum" 336 /*@C 337 PetscOptionsEnum - Gets the enum value for a particular option in the database. 338 339 Collective on the communicator passed in PetscOptionsBegin() 340 341 Input Parameters: 342 + opt - option name 343 . text - short string that describes the option 344 . man - manual page with additional information on option 345 . list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null 346 - defaultv - the default (current) value 347 348 Output Parameter: 349 + value - the value to return 350 - flg - PETSC_TRUE if found, else PETSC_FALSE 351 352 Level: beginner 353 354 Concepts: options database 355 356 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 357 358 list is usually something like PCASMTypes or some other predefined list of enum names 359 360 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 361 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 362 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 363 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 364 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 365 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 366 PetscOptionsList(), PetscOptionsEList() 367 @*/ 368 PetscErrorCode PETSC_DLLEXPORT PetscOptionsEnum(const char opt[],const char text[],const char man[],const char **list,PetscEnum defaultv,PetscEnum *value,PetscTruth *set) 369 { 370 PetscErrorCode ierr; 371 PetscInt ntext = 0; 372 PetscInt tval; 373 PetscTruth tflg; 374 375 PetscFunctionBegin; 376 while (list[ntext++]) { 377 if (ntext > 50) SETERRQ(PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries"); 378 } 379 if (ntext < 3) SETERRQ(PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix"); 380 ntext -= 3; 381 ierr = PetscOptionsEList(opt,text,man,list,ntext,list[defaultv],&tval,&tflg);CHKERRQ(ierr); 382 /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */ 383 if (tflg) *value = (PetscEnum)tval; 384 if (set) *set = tflg; 385 PetscFunctionReturn(0); 386 } 387 388 /* -------------------------------------------------------------------------------------------------------------*/ 389 #undef __FUNCT__ 390 #define __FUNCT__ "PetscOptionsInt" 391 /*@C 392 PetscOptionsInt - Gets the integer value for a particular option in the database. 393 394 Collective on the communicator passed in PetscOptionsBegin() 395 396 Input Parameters: 397 + opt - option name 398 . text - short string that describes the option 399 . man - manual page with additional information on option 400 - defaultv - the default (current) value 401 402 Output Parameter: 403 + value - the integer value to return 404 - flg - PETSC_TRUE if found, else PETSC_FALSE 405 406 Level: beginner 407 408 Concepts: options database^has int 409 410 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 411 412 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 413 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 414 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 415 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 416 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 417 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 418 PetscOptionsList(), PetscOptionsEList() 419 @*/ 420 PetscErrorCode PETSC_DLLEXPORT PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt defaultv,PetscInt *value,PetscTruth *set) 421 { 422 PetscErrorCode ierr; 423 PetscOptions amsopt; 424 425 PetscFunctionBegin; 426 if (PetscOptionsPublishCount == 0) { 427 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr); 428 ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr); 429 *(PetscInt*)amsopt->data = defaultv; 430 } 431 ierr = PetscOptionsGetInt(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 432 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 433 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%d>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr); 434 } 435 PetscFunctionReturn(0); 436 } 437 438 #undef __FUNCT__ 439 #define __FUNCT__ "PetscOptionsString" 440 /*@C 441 PetscOptionsString - Gets the string value for a particular option in the database. 442 443 Collective on the communicator passed in PetscOptionsBegin() 444 445 Input Parameters: 446 + opt - option name 447 . text - short string that describes the option 448 . man - manual page with additional information on option 449 - defaultv - the default (current) value 450 451 Output Parameter: 452 + value - the value to return 453 - flg - PETSC_TRUE if found, else PETSC_FALSE 454 455 Level: beginner 456 457 Concepts: options database^has int 458 459 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 460 461 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 462 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 463 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 464 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 465 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 466 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 467 PetscOptionsList(), PetscOptionsEList() 468 @*/ 469 PetscErrorCode PETSC_DLLEXPORT PetscOptionsString(const char opt[],const char text[],const char man[],const char defaultv[],char value[],size_t len,PetscTruth *set) 470 { 471 PetscErrorCode ierr; 472 PetscOptions amsopt; 473 474 PetscFunctionBegin; 475 if (PetscOptionsPublishCount == 0) { 476 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr); 477 ierr = PetscMalloc(len*sizeof(char),&amsopt->data);CHKERRQ(ierr); 478 ierr = PetscStrcpy((char*)amsopt->data,defaultv);CHKERRQ(ierr); 479 } 480 ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr); 481 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 482 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr); 483 } 484 PetscFunctionReturn(0); 485 } 486 487 #undef __FUNCT__ 488 #define __FUNCT__ "PetscOptionsReal" 489 /*@C 490 PetscOptionsReal - Gets the PetscReal value for a particular option in the database. 491 492 Collective on the communicator passed in PetscOptionsBegin() 493 494 Input Parameters: 495 + opt - option name 496 . text - short string that describes the option 497 . man - manual page with additional information on option 498 - defaultv - the default (current) value 499 500 Output Parameter: 501 + value - the value to return 502 - flg - PETSC_TRUE if found, else PETSC_FALSE 503 504 Level: beginner 505 506 Concepts: options database^has int 507 508 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 509 510 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 511 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 512 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 513 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 514 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 515 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 516 PetscOptionsList(), PetscOptionsEList() 517 @*/ 518 PetscErrorCode PETSC_DLLEXPORT PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal defaultv,PetscReal *value,PetscTruth *set) 519 { 520 PetscErrorCode ierr; 521 PetscOptions amsopt; 522 523 PetscFunctionBegin; 524 if (PetscOptionsPublishCount == 0) { 525 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr); 526 ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr); 527 *(PetscReal*)amsopt->data = defaultv; 528 } 529 ierr = PetscOptionsGetReal(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 530 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 531 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%G>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr); 532 } 533 PetscFunctionReturn(0); 534 } 535 536 #undef __FUNCT__ 537 #define __FUNCT__ "PetscOptionsScalar" 538 /*@C 539 PetscOptionsScalar - Gets the scalar value for a particular option in the database. 540 541 Collective on the communicator passed in PetscOptionsBegin() 542 543 Input Parameters: 544 + opt - option name 545 . text - short string that describes the option 546 . man - manual page with additional information on option 547 - defaultv - the default (current) value 548 549 Output Parameter: 550 + value - the value to return 551 - flg - PETSC_TRUE if found, else PETSC_FALSE 552 553 Level: beginner 554 555 Concepts: options database^has int 556 557 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 558 559 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 560 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 561 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 562 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 563 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 564 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 565 PetscOptionsList(), PetscOptionsEList() 566 @*/ 567 PetscErrorCode PETSC_DLLEXPORT PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar defaultv,PetscScalar *value,PetscTruth *set) 568 { 569 PetscErrorCode ierr; 570 571 PetscFunctionBegin; 572 #if !defined(PETSC_USE_COMPLEX) 573 ierr = PetscOptionsReal(opt,text,man,defaultv,value,set);CHKERRQ(ierr); 574 #else 575 ierr = PetscOptionsGetScalar(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 576 #endif 577 PetscFunctionReturn(0); 578 } 579 580 #undef __FUNCT__ 581 #define __FUNCT__ "PetscOptionsName" 582 /*@C 583 PetscOptionsName - Determines if a particular option has been set in the database. This returns true whether the option is a number, string or boolean, even 584 its value is set to false. 585 586 Collective on the communicator passed in PetscOptionsBegin() 587 588 Input Parameters: 589 + opt - option name 590 . text - short string that describes the option 591 - man - manual page with additional information on option 592 593 Output Parameter: 594 . flg - PETSC_TRUE if found, else PETSC_FALSE 595 596 Level: beginner 597 598 Concepts: options database^has int 599 600 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 601 602 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 603 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 604 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 605 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 606 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 607 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 608 PetscOptionsList(), PetscOptionsEList() 609 @*/ 610 PetscErrorCode PETSC_DLLEXPORT PetscOptionsName(const char opt[],const char text[],const char man[],PetscTruth *flg) 611 { 612 PetscErrorCode ierr; 613 614 PetscFunctionBegin; 615 ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr); 616 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 617 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr); 618 } 619 PetscFunctionReturn(0); 620 } 621 622 #undef __FUNCT__ 623 #define __FUNCT__ "PetscOptionsList" 624 /*@C 625 PetscOptionsList - Puts a list of option values that a single one may be selected from 626 627 Collective on the communicator passed in PetscOptionsBegin() 628 629 Input Parameters: 630 + opt - option name 631 . text - short string that describes the option 632 . man - manual page with additional information on option 633 . list - the possible choices 634 - defaultv - the default (current) value 635 636 Output Parameter: 637 + value - the value to return 638 - set - PETSC_TRUE if found, else PETSC_FALSE 639 640 Level: intermediate 641 642 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 643 644 See PetscOptionsEList() for when the choices are given in a string array 645 646 To get a listing of all currently specified options, 647 see PetscOptionsPrint() or PetscOptionsGetAll() 648 649 Concepts: options database^list 650 651 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 652 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 653 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 654 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 655 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 656 PetscOptionsList(), PetscOptionsEList() 657 @*/ 658 PetscErrorCode PETSC_DLLEXPORT PetscOptionsList(const char opt[],const char ltext[],const char man[],PetscFList list,const char defaultv[],char value[],PetscInt len,PetscTruth *set) 659 { 660 PetscErrorCode ierr; 661 662 PetscFunctionBegin; 663 ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr); 664 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 665 ierr = PetscFListPrintTypes(list,PetscOptionsObject.comm,stdout,PetscOptionsObject.prefix,opt,ltext,man);CHKERRQ(ierr);CHKERRQ(ierr); 666 } 667 PetscFunctionReturn(0); 668 } 669 670 #undef __FUNCT__ 671 #define __FUNCT__ "PetscOptionsEList" 672 /*@C 673 PetscOptionsEList - Puts a list of option values that a single one may be selected from 674 675 Collective on the communicator passed in PetscOptionsBegin() 676 677 Input Parameters: 678 + opt - option name 679 . ltext - short string that describes the option 680 . man - manual page with additional information on option 681 . list - the possible choices 682 . ntext - number of choices 683 - defaultv - the default (current) value 684 685 Output Parameter: 686 + value - the index of the value to return 687 - set - PETSC_TRUE if found, else PETSC_FALSE 688 689 Level: intermediate 690 691 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 692 693 See PetscOptionsList() for when the choices are given in a PetscFList() 694 695 Concepts: options database^list 696 697 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 698 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 699 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 700 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 701 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 702 PetscOptionsList(), PetscOptionsEList() 703 @*/ 704 PetscErrorCode PETSC_DLLEXPORT PetscOptionsEList(const char opt[],const char ltext[],const char man[],const char **list,PetscInt ntext,const char defaultv[],PetscInt *value,PetscTruth *set) 705 { 706 PetscErrorCode ierr; 707 PetscInt i; 708 709 PetscFunctionBegin; 710 ierr = PetscOptionsGetEList(PetscOptionsObject.prefix,opt,list,ntext,value,set);CHKERRQ(ierr); 711 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 712 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%s> (choose one of)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv);CHKERRQ(ierr); 713 for (i=0; i<ntext; i++){ 714 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s",list[i]);CHKERRQ(ierr); 715 } 716 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"\n");CHKERRQ(ierr); 717 } 718 PetscFunctionReturn(0); 719 } 720 721 #undef __FUNCT__ 722 #define __FUNCT__ "PetscOptionsTruthGroupBegin" 723 /*@C 724 PetscOptionsTruthGroupBegin - First in a series of logical queries on the options database for 725 which only a single value can be true. 726 727 Collective on the communicator passed in PetscOptionsBegin() 728 729 Input Parameters: 730 + opt - option name 731 . text - short string that describes the option 732 - man - manual page with additional information on option 733 734 Output Parameter: 735 . flg - whether that option was set or not 736 737 Level: intermediate 738 739 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 740 741 Must be followed by 0 or more PetscOptionsTruthGroup()s and PetscOptionsTruthGroupEnd() 742 743 Concepts: options database^logical group 744 745 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 746 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 747 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 748 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 749 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 750 PetscOptionsList(), PetscOptionsEList() 751 @*/ 752 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroupBegin(const char opt[],const char text[],const char man[],PetscTruth *flg) 753 { 754 PetscErrorCode ierr; 755 756 PetscFunctionBegin; 757 *flg = PETSC_FALSE; 758 ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr); 759 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 760 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," Pick at most one of -------------\n");CHKERRQ(ierr); 761 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr); 762 } 763 PetscFunctionReturn(0); 764 } 765 766 #undef __FUNCT__ 767 #define __FUNCT__ "PetscOptionsTruthGroup" 768 /*@C 769 PetscOptionsTruthGroup - One in a series of logical queries on the options database for 770 which only a single value can be true. 771 772 Collective on the communicator passed in PetscOptionsBegin() 773 774 Input Parameters: 775 + opt - option name 776 . text - short string that describes the option 777 - man - manual page with additional information on option 778 779 Output Parameter: 780 . flg - PETSC_TRUE if found, else PETSC_FALSE 781 782 Level: intermediate 783 784 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 785 786 Must follow a PetscOptionsTruthGroupBegin() and preceded a PetscOptionsTruthGroupEnd() 787 788 Concepts: options database^logical group 789 790 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 791 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 792 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 793 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 794 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 795 PetscOptionsList(), PetscOptionsEList() 796 @*/ 797 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroup(const char opt[],const char text[],const char man[],PetscTruth *flg) 798 { 799 PetscErrorCode ierr; 800 801 PetscFunctionBegin; 802 *flg = PETSC_FALSE; 803 ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr); 804 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 805 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr); 806 } 807 PetscFunctionReturn(0); 808 } 809 810 #undef __FUNCT__ 811 #define __FUNCT__ "PetscOptionsTruthGroupEnd" 812 /*@C 813 PetscOptionsTruthGroupEnd - Last in a series of logical queries on the options database for 814 which only a single value can be true. 815 816 Collective on the communicator passed in PetscOptionsBegin() 817 818 Input Parameters: 819 + opt - option name 820 . text - short string that describes the option 821 - man - manual page with additional information on option 822 823 Output Parameter: 824 . flg - PETSC_TRUE if found, else PETSC_FALSE 825 826 Level: intermediate 827 828 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 829 830 Must follow a PetscOptionsTruthGroupBegin() 831 832 Concepts: options database^logical group 833 834 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 835 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 836 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 837 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 838 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 839 PetscOptionsList(), PetscOptionsEList() 840 @*/ 841 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroupEnd(const char opt[],const char text[],const char man[],PetscTruth *flg) 842 { 843 PetscErrorCode ierr; 844 845 PetscFunctionBegin; 846 *flg = PETSC_FALSE; 847 ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr); 848 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 849 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr); 850 } 851 PetscFunctionReturn(0); 852 } 853 854 #undef __FUNCT__ 855 #define __FUNCT__ "PetscOptionsTruth" 856 /*@C 857 PetscOptionsTruth - Determines if a particular option is in the database with a true or false 858 859 Collective on the communicator passed in PetscOptionsBegin() 860 861 Input Parameters: 862 + opt - option name 863 . text - short string that describes the option 864 - man - manual page with additional information on option 865 866 Output Parameter: 867 . flg - PETSC_TRUE or PETSC_FALSE 868 . set - PETSC_TRUE if found, else PETSC_FALSE 869 870 Level: beginner 871 872 Concepts: options database^logical 873 874 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 875 876 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 877 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 878 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 879 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 880 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 881 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 882 PetscOptionsList(), PetscOptionsEList() 883 @*/ 884 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruth(const char opt[],const char text[],const char man[],PetscTruth deflt,PetscTruth *flg,PetscTruth *set) 885 { 886 PetscErrorCode ierr; 887 PetscTruth iset; 888 PetscOptions amsopt; 889 890 PetscFunctionBegin; 891 if (PetscOptionsPublishCount == 0) { 892 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr); 893 ierr = PetscMalloc(16*sizeof(char),&amsopt->data);CHKERRQ(ierr); 894 ierr = PetscStrcpy((char*)amsopt->data,deflt ? "true" : "false");CHKERRQ(ierr); 895 } 896 ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,&iset);CHKERRQ(ierr); 897 if (!iset) { 898 if (flg) *flg = deflt; 899 } 900 if (set) *set = iset; 901 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 902 const char *v = PetscTruths[deflt]; 903 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: <%s> %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,v,text,man);CHKERRQ(ierr); 904 } 905 PetscFunctionReturn(0); 906 } 907 908 #undef __FUNCT__ 909 #define __FUNCT__ "PetscOptionsRealArray" 910 /*@C 911 PetscOptionsRealArray - Gets an array of double values for a particular 912 option in the database. The values must be separated with commas with 913 no intervening spaces. 914 915 Collective on the communicator passed in PetscOptionsBegin() 916 917 Input Parameters: 918 + opt - the option one is seeking 919 . text - short string describing option 920 . man - manual page for option 921 - nmax - maximum number of values 922 923 Output Parameter: 924 + value - location to copy values 925 . nmax - actual number of values found 926 - set - PETSC_TRUE if found, else PETSC_FALSE 927 928 Level: beginner 929 930 Notes: 931 The user should pass in an array of doubles 932 933 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 934 935 Concepts: options database^array of strings 936 937 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 938 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 939 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 940 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 941 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 942 PetscOptionsList(), PetscOptionsEList() 943 @*/ 944 PetscErrorCode PETSC_DLLEXPORT PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscTruth *set) 945 { 946 PetscErrorCode ierr; 947 PetscInt i; 948 949 PetscFunctionBegin; 950 ierr = PetscOptionsGetRealArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr); 951 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 952 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%G",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr); 953 for (i=1; i<*n; i++) { 954 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%G",value[i]);CHKERRQ(ierr); 955 } 956 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr); 957 } 958 PetscFunctionReturn(0); 959 } 960 961 962 #undef __FUNCT__ 963 #define __FUNCT__ "PetscOptionsIntArray" 964 /*@C 965 PetscOptionsIntArray - Gets an array of integers for a particular 966 option in the database. The values must be separated with commas with 967 no intervening spaces. 968 969 Collective on the communicator passed in PetscOptionsBegin() 970 971 Input Parameters: 972 + opt - the option one is seeking 973 . text - short string describing option 974 . man - manual page for option 975 - n - maximum number of values 976 977 Output Parameter: 978 + value - location to copy values 979 . n - actual number of values found 980 - set - PETSC_TRUE if found, else PETSC_FALSE 981 982 Level: beginner 983 984 Notes: 985 The user should pass in an array of integers 986 987 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 988 989 Concepts: options database^array of strings 990 991 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 992 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 993 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 994 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 995 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 996 PetscOptionsList(), PetscOptionsEList(), PetscOptionsRealArray() 997 @*/ 998 PetscErrorCode PETSC_DLLEXPORT PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscTruth *set) 999 { 1000 PetscErrorCode ierr; 1001 PetscInt i; 1002 1003 PetscFunctionBegin; 1004 ierr = PetscOptionsGetIntArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr); 1005 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1006 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr); 1007 for (i=1; i<*n; i++) { 1008 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr); 1009 } 1010 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr); 1011 } 1012 PetscFunctionReturn(0); 1013 } 1014 1015 #undef __FUNCT__ 1016 #define __FUNCT__ "PetscOptionsStringArray" 1017 /*@C 1018 PetscOptionsStringArray - Gets an array of string values for a particular 1019 option in the database. The values must be separated with commas with 1020 no intervening spaces. 1021 1022 Collective on the communicator passed in PetscOptionsBegin() 1023 1024 Input Parameters: 1025 + opt - the option one is seeking 1026 . text - short string describing option 1027 . man - manual page for option 1028 - nmax - maximum number of strings 1029 1030 Output Parameter: 1031 + value - location to copy strings 1032 . nmax - actual number of strings found 1033 - set - PETSC_TRUE if found, else PETSC_FALSE 1034 1035 Level: beginner 1036 1037 Notes: 1038 The user should pass in an array of pointers to char, to hold all the 1039 strings returned by this function. 1040 1041 The user is responsible for deallocating the strings that are 1042 returned. The Fortran interface for this routine is not supported. 1043 1044 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1045 1046 Concepts: options database^array of strings 1047 1048 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1049 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 1050 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1051 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1052 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 1053 PetscOptionsList(), PetscOptionsEList() 1054 @*/ 1055 PetscErrorCode PETSC_DLLEXPORT PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscTruth *set) 1056 { 1057 PetscErrorCode ierr; 1058 1059 PetscFunctionBegin; 1060 ierr = PetscOptionsGetStringArray(PetscOptionsObject.prefix,opt,value,nmax,set);CHKERRQ(ierr); 1061 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1062 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr); 1063 } 1064 PetscFunctionReturn(0); 1065 } 1066 1067 #undef __FUNCT__ 1068 #define __FUNCT__ "PetscOptionsTruthArray" 1069 /*@C 1070 PetscOptionsTruthArray - Gets an array of logical values (true or false) for a particular 1071 option in the database. The values must be separated with commas with 1072 no intervening spaces. 1073 1074 Collective on the communicator passed in PetscOptionsBegin() 1075 1076 Input Parameters: 1077 + opt - the option one is seeking 1078 . text - short string describing option 1079 . man - manual page for option 1080 - nmax - maximum number of values 1081 1082 Output Parameter: 1083 + value - location to copy values 1084 . nmax - actual number of values found 1085 - set - PETSC_TRUE if found, else PETSC_FALSE 1086 1087 Level: beginner 1088 1089 Notes: 1090 The user should pass in an array of doubles 1091 1092 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1093 1094 Concepts: options database^array of strings 1095 1096 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1097 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 1098 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1099 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1100 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 1101 PetscOptionsList(), PetscOptionsEList() 1102 @*/ 1103 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthArray(const char opt[],const char text[],const char man[],PetscTruth value[],PetscInt *n,PetscTruth *set) 1104 { 1105 PetscErrorCode ierr; 1106 PetscInt i; 1107 1108 PetscFunctionBegin; 1109 ierr = PetscOptionsGetTruthArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr); 1110 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1111 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr); 1112 for (i=1; i<*n; i++) { 1113 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr); 1114 } 1115 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr); 1116 } 1117 PetscFunctionReturn(0); 1118 } 1119 1120 1121 #undef __FUNCT__ 1122 #define __FUNCT__ "PetscOptionsHead" 1123 /*@C 1124 PetscOptionsHead - Puts a heading before listing any more published options. Used, for example, 1125 in KSPSetFromOptions_GMRES(). 1126 1127 Collective on the communicator passed in PetscOptionsBegin() 1128 1129 Input Parameter: 1130 . head - the heading text 1131 1132 1133 Level: intermediate 1134 1135 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1136 1137 Can be followed by a call to PetscOptionsTail() in the same function. 1138 1139 Concepts: options database^subheading 1140 1141 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1142 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 1143 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1144 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1145 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 1146 PetscOptionsList(), PetscOptionsEList() 1147 @*/ 1148 PetscErrorCode PETSC_DLLEXPORT PetscOptionsHead(const char head[]) 1149 { 1150 PetscErrorCode ierr; 1151 1152 PetscFunctionBegin; 1153 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1154 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s\n",head);CHKERRQ(ierr); 1155 } 1156 PetscFunctionReturn(0); 1157 } 1158 1159 1160 1161 1162 1163 1164