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 typedef enum {OPTION_INT,OPTION_LOGICAL,OPTION_REAL,OPTION_LIST,OPTION_STRING,OPTION_REAL_ARRAY,OPTION_HEAD} OptionType; 23 typedef struct _p_Options* PetscOptions; 24 struct _p_Options { 25 char *option; 26 char *text; 27 void *data; 28 void *edata; 29 char *man; 30 int arraylength; 31 PetscTruth set; 32 OptionType type; 33 PetscOptions next; 34 }; 35 36 static struct { 37 PetscOptions next; 38 char *prefix,*mprefix; 39 char *title; 40 MPI_Comm comm; 41 PetscTruth printhelp,changedmethod; 42 } PetscOptionsObject; 43 PetscInt PetscOptionsPublishCount = 0; 44 45 #undef __FUNCT__ 46 #define __FUNCT__ "PetscOptionsBegin_Private" 47 /* 48 Handles setting up the data structure in a call to PetscOptionsBegin() 49 */ 50 PetscErrorCode PetscOptionsBegin_Private(MPI_Comm comm,const char prefix[],const char title[],const char mansec[]) 51 { 52 PetscErrorCode ierr; 53 54 PetscFunctionBegin; 55 PetscOptionsObject.next = 0; 56 PetscOptionsObject.comm = comm; 57 PetscOptionsObject.changedmethod = PETSC_FALSE; 58 ierr = PetscStrallocpy(prefix,&PetscOptionsObject.prefix);CHKERRQ(ierr); 59 ierr = PetscStrallocpy(title,&PetscOptionsObject.title);CHKERRQ(ierr); 60 61 ierr = PetscOptionsHasName(PETSC_NULL,"-help",&PetscOptionsObject.printhelp);CHKERRQ(ierr); 62 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) { 63 ierr = (*PetscHelpPrintf)(comm,"%s -------------------------------------------------\n",title);CHKERRQ(ierr); 64 } 65 PetscFunctionReturn(0); 66 } 67 68 /* 69 Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd() 70 */ 71 #undef __FUNCT__ 72 #define __FUNCT__ "PetscOptionsCreate_Private" 73 static int PetscOptionsCreate_Private(const char opt[],const char text[],const char man[],OptionType t,PetscOptions *amsopt) 74 { 75 int ierr; 76 PetscOptions next; 77 78 PetscFunctionBegin; 79 ierr = PetscNew(struct _p_Options,amsopt);CHKERRQ(ierr); 80 (*amsopt)->next = 0; 81 (*amsopt)->set = PETSC_FALSE; 82 (*amsopt)->type = t; 83 (*amsopt)->data = 0; 84 (*amsopt)->edata = 0; 85 ierr = PetscStrallocpy(text,&(*amsopt)->text);CHKERRQ(ierr); 86 ierr = PetscStrallocpy(opt,&(*amsopt)->option);CHKERRQ(ierr); 87 ierr = PetscStrallocpy(man,&(*amsopt)->man);CHKERRQ(ierr); 88 89 if (!PetscOptionsObject.next) { 90 PetscOptionsObject.next = *amsopt; 91 } else { 92 next = PetscOptionsObject.next; 93 while (next->next) next = next->next; 94 next->next = *amsopt; 95 } 96 PetscFunctionReturn(0); 97 } 98 99 #undef __FUNCT__ 100 #define __FUNCT__ "PetscOptionsGetFromGui" 101 static PetscErrorCode PetscOptionsGetFromGUI() 102 { 103 PetscErrorCode ierr; 104 PetscOptions next = PetscOptionsObject.next; 105 char str[512]; 106 107 ierr = (*PetscPrintf)(PetscOptionsObject.comm,"%s -------------------------------------------------\n",PetscOptionsObject.title);CHKERRQ(ierr); 108 while (next) { 109 switch (next->type) { 110 case OPTION_HEAD: 111 break; 112 case OPTION_INT: 113 ierr = PetscPrintf(PetscOptionsObject.comm,"-%s%s <%d>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option,*(int*)next->data,next->text,next->man);CHKERRQ(ierr); 114 scanf("%s\n",str); 115 if (str[0] != '\n') { 116 printf("chainginf value\n"); 117 } 118 break; 119 } 120 next = next->next; 121 } 122 PetscFunctionReturn(0); 123 } 124 125 #undef __FUNCT__ 126 #define __FUNCT__ "PetscOptionsEnd_Private" 127 PetscErrorCode PetscOptionsEnd_Private(void) 128 { 129 PetscErrorCode ierr; 130 PetscOptions last; 131 char option[256],value[1024],tmp[32]; 132 PetscInt j; 133 134 PetscFunctionBegin; 135 136 if (PetscOptionsObject.next) { 137 ierr = PetscOptionsGetFromGUI(); 138 } 139 140 ierr = PetscStrfree(PetscOptionsObject.title);CHKERRQ(ierr); PetscOptionsObject.title = 0; 141 ierr = PetscStrfree(PetscOptionsObject.prefix);CHKERRQ(ierr); PetscOptionsObject.prefix = 0; 142 143 /* reset counter to -2; this updates the screen with the new options for the selected method */ 144 if (PetscOptionsObject.changedmethod) PetscOptionsPublishCount = -2; 145 146 while (PetscOptionsObject.next) { 147 if (PetscOptionsObject.next->set) { 148 if (PetscOptionsObject.prefix) { 149 ierr = PetscStrcpy(option,"-");CHKERRQ(ierr); 150 ierr = PetscStrcat(option,PetscOptionsObject.prefix);CHKERRQ(ierr); 151 ierr = PetscStrcat(option,PetscOptionsObject.next->option+1);CHKERRQ(ierr); 152 } else { 153 ierr = PetscStrcpy(option,PetscOptionsObject.next->option);CHKERRQ(ierr); 154 } 155 156 switch (PetscOptionsObject.next->type) { 157 case OPTION_HEAD: 158 break; 159 case OPTION_INT: 160 sprintf(value,"%d",*(PetscInt*)PetscOptionsObject.next->data); 161 break; 162 case OPTION_REAL: 163 sprintf(value,"%g",*(PetscReal*)PetscOptionsObject.next->data); 164 break; 165 case OPTION_REAL_ARRAY: 166 sprintf(value,"%g",((PetscReal*)PetscOptionsObject.next->data)[0]); 167 for (j=1; j<PetscOptionsObject.next->arraylength; j++) { 168 sprintf(tmp,"%g",((PetscReal*)PetscOptionsObject.next->data)[j]); 169 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 170 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 171 } 172 break; 173 case OPTION_LOGICAL: 174 sprintf(value,"%d",*(PetscInt*)PetscOptionsObject.next->data); 175 break; 176 case OPTION_LIST: 177 ierr = PetscStrcpy(value,*(char**)PetscOptionsObject.next->data);CHKERRQ(ierr); 178 break; 179 case OPTION_STRING: /* also handles string arrays */ 180 ierr = PetscStrcpy(value,*(char**)PetscOptionsObject.next->data);CHKERRQ(ierr); 181 break; 182 } 183 ierr = PetscOptionsSetValue(option,value);CHKERRQ(ierr); 184 } 185 ierr = PetscStrfree(PetscOptionsObject.next->text);CHKERRQ(ierr); 186 ierr = PetscStrfree(PetscOptionsObject.next->option);CHKERRQ(ierr); 187 ierr = PetscFree(PetscOptionsObject.next->man);CHKERRQ(ierr); 188 if (PetscOptionsObject.next->data) {ierr = PetscFree(PetscOptionsObject.next->data);CHKERRQ(ierr);} 189 if (PetscOptionsObject.next->edata) {ierr = PetscFree(PetscOptionsObject.next->edata);CHKERRQ(ierr);} 190 last = PetscOptionsObject.next; 191 PetscOptionsObject.next = PetscOptionsObject.next->next; 192 ierr = PetscFree(last);CHKERRQ(ierr); 193 } 194 PetscOptionsObject.next = 0; 195 PetscFunctionReturn(0); 196 } 197 198 #undef __FUNCT__ 199 #define __FUNCT__ "PetscOptionsEnum" 200 /*@C 201 PetscOptionsEnum - Gets the enum value for a particular option in the database. 202 203 Collective on the communicator passed in PetscOptionsBegin() 204 205 Input Parameters: 206 + opt - option name 207 . text - short string that describes the option 208 . man - manual page with additional information on option 209 . list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null 210 - defaultv - the default (current) value 211 212 Output Parameter: 213 + value - the value to return 214 - flg - PETSC_TRUE if found, else PETSC_FALSE 215 216 Level: beginner 217 218 Concepts: options database 219 220 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 221 222 list is usually something like PCASMTypes or some other predefined list of enum names 223 224 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 225 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 226 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 227 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 228 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 229 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 230 PetscOptionsList(), PetscOptionsEList() 231 @*/ 232 PetscErrorCode PETSC_DLLEXPORT PetscOptionsEnum(const char opt[],const char text[],const char man[],const char **list,PetscEnum defaultv,PetscEnum *value,PetscTruth *set) 233 { 234 PetscErrorCode ierr; 235 PetscInt ntext = 0; 236 237 PetscFunctionBegin; 238 while (list[ntext++]) { 239 if (ntext > 50) SETERRQ(PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries"); 240 } 241 if (ntext < 3) SETERRQ(PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix"); 242 ntext -= 3; 243 ierr = PetscOptionsEList(opt,text,man,list,ntext,list[defaultv],(PetscInt*)value,set);CHKERRQ(ierr); 244 PetscFunctionReturn(0); 245 } 246 247 /* -------------------------------------------------------------------------------------------------------------*/ 248 #undef __FUNCT__ 249 #define __FUNCT__ "PetscOptionsInt" 250 /*@C 251 PetscOptionsInt - Gets the integer value for a particular option in the database. 252 253 Collective on the communicator passed in PetscOptionsBegin() 254 255 Input Parameters: 256 + opt - option name 257 . text - short string that describes the option 258 . man - manual page with additional information on option 259 - defaultv - the default (current) value 260 261 Output Parameter: 262 + value - the integer value to return 263 - flg - PETSC_TRUE if found, else PETSC_FALSE 264 265 Level: beginner 266 267 Concepts: options database^has int 268 269 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 270 271 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 272 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 273 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 274 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 275 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 276 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 277 PetscOptionsList(), PetscOptionsEList() 278 @*/ 279 PetscErrorCode PETSC_DLLEXPORT PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt defaultv,PetscInt *value,PetscTruth *set) 280 { 281 PetscErrorCode ierr; 282 PetscOptions amsopt; 283 284 PetscFunctionBegin; 285 if (PetscOptionsPublishCount == 1) { 286 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr); 287 ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr); 288 *(PetscInt*)amsopt->data = defaultv; 289 } 290 ierr = PetscOptionsGetInt(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 291 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) { 292 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%d>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr); 293 } 294 PetscFunctionReturn(0); 295 } 296 297 #undef __FUNCT__ 298 #define __FUNCT__ "PetscOptionsString" 299 /*@C 300 PetscOptionsString - Gets the string value for a particular option in the database. 301 302 Collective on the communicator passed in PetscOptionsBegin() 303 304 Input Parameters: 305 + opt - option name 306 . text - short string that describes the option 307 . man - manual page with additional information on option 308 - defaultv - the default (current) value 309 310 Output Parameter: 311 + value - the value to return 312 - flg - PETSC_TRUE if found, else PETSC_FALSE 313 314 Level: beginner 315 316 Concepts: options database^has int 317 318 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 319 320 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 321 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 322 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 323 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 324 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 325 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 326 PetscOptionsList(), PetscOptionsEList() 327 @*/ 328 PetscErrorCode PETSC_DLLEXPORT PetscOptionsString(const char opt[],const char text[],const char man[],const char defaultv[],char value[],size_t len,PetscTruth *set) 329 { 330 PetscErrorCode ierr; 331 332 PetscFunctionBegin; 333 ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr); 334 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) { 335 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr); 336 } 337 PetscFunctionReturn(0); 338 } 339 340 /* 341 Publishes an AMS double field (with the default value in it) and with a name 342 given by the text string 343 */ 344 #undef __FUNCT__ 345 #define __FUNCT__ "PetscOptionsReal" 346 /*@C 347 PetscOptionsReal - Gets the PetscReal value for a particular option in the database. 348 349 Collective on the communicator passed in PetscOptionsBegin() 350 351 Input Parameters: 352 + opt - option name 353 . text - short string that describes the option 354 . man - manual page with additional information on option 355 - defaultv - the default (current) value 356 357 Output Parameter: 358 + value - the value to return 359 - flg - PETSC_TRUE if found, else PETSC_FALSE 360 361 Level: beginner 362 363 Concepts: options database^has int 364 365 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 366 367 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 368 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 369 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 370 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 371 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 372 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 373 PetscOptionsList(), PetscOptionsEList() 374 @*/ 375 PetscErrorCode PETSC_DLLEXPORT PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal defaultv,PetscReal *value,PetscTruth *set) 376 { 377 PetscErrorCode ierr; 378 379 PetscFunctionBegin; 380 ierr = PetscOptionsGetReal(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 381 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) { 382 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%g>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr); 383 } 384 PetscFunctionReturn(0); 385 } 386 387 #undef __FUNCT__ 388 #define __FUNCT__ "PetscOptionsScalar" 389 /*@C 390 PetscOptionsScalar - Gets the scalar value for a particular option in the database. 391 392 Collective on the communicator passed in PetscOptionsBegin() 393 394 Input Parameters: 395 + opt - option name 396 . text - short string that describes the option 397 . man - manual page with additional information on option 398 - defaultv - the default (current) value 399 400 Output Parameter: 401 + value - the value to return 402 - flg - PETSC_TRUE if found, else PETSC_FALSE 403 404 Level: beginner 405 406 Concepts: options database^has int 407 408 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 409 410 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 411 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 412 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 413 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 414 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 415 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 416 PetscOptionsList(), PetscOptionsEList() 417 @*/ 418 PetscErrorCode PETSC_DLLEXPORT PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar defaultv,PetscScalar *value,PetscTruth *set) 419 { 420 PetscErrorCode ierr; 421 422 PetscFunctionBegin; 423 #if !defined(PETSC_USE_COMPLEX) 424 ierr = PetscOptionsReal(opt,text,man,defaultv,value,set);CHKERRQ(ierr); 425 #else 426 ierr = PetscOptionsGetScalar(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 427 #endif 428 PetscFunctionReturn(0); 429 } 430 431 /* 432 Publishes an AMS logical field (with the default value in it) and with a name 433 given by the text string 434 */ 435 #undef __FUNCT__ 436 #define __FUNCT__ "PetscOptionsName" 437 /*@C 438 PetscOptionsName - Determines if a particular option is in the database 439 440 Collective on the communicator passed in PetscOptionsBegin() 441 442 Input Parameters: 443 + opt - option name 444 . text - short string that describes the option 445 - man - manual page with additional information on option 446 447 Output Parameter: 448 . flg - PETSC_TRUE if found, else PETSC_FALSE 449 450 Level: beginner 451 452 Concepts: options database^has int 453 454 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 455 456 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 457 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 458 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 459 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 460 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 461 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 462 PetscOptionsList(), PetscOptionsEList() 463 @*/ 464 PetscErrorCode PETSC_DLLEXPORT PetscOptionsName(const char opt[],const char text[],const char man[],PetscTruth *flg) 465 { 466 PetscErrorCode ierr; 467 468 PetscFunctionBegin; 469 ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr); 470 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) { 471 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr); 472 } 473 PetscFunctionReturn(0); 474 } 475 476 #undef __FUNCT__ 477 #define __FUNCT__ "PetscOptionsList" 478 /*@C 479 PetscOptionsList - Puts a list of option values that a single one may be selected from 480 481 Collective on the communicator passed in PetscOptionsBegin() 482 483 Input Parameters: 484 + opt - option name 485 . text - short string that describes the option 486 . man - manual page with additional information on option 487 . list - the possible choices 488 - defaultv - the default (current) value 489 490 Output Parameter: 491 + value - the value to return 492 - set - PETSC_TRUE if found, else PETSC_FALSE 493 494 Level: intermediate 495 496 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 497 498 See PetscOptionsEList() for when the choices are given in a string array 499 500 To get a listing of all currently specified options, 501 see PetscOptionsPrint() or PetscOptionsGetAll() 502 503 Concepts: options database^list 504 505 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 506 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 507 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 508 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 509 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 510 PetscOptionsList(), PetscOptionsEList() 511 @*/ 512 PetscErrorCode PETSC_DLLEXPORT PetscOptionsList(const char opt[],const char ltext[],const char man[],PetscFList list,const char defaultv[],char value[],PetscInt len,PetscTruth *set) 513 { 514 PetscErrorCode ierr; 515 516 PetscFunctionBegin; 517 ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr); 518 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) { 519 ierr = PetscFListPrintTypes(PetscOptionsObject.comm,stdout,PetscOptionsObject.prefix,opt,ltext,man,list);CHKERRQ(ierr);CHKERRQ(ierr); 520 } 521 PetscFunctionReturn(0); 522 } 523 524 #undef __FUNCT__ 525 #define __FUNCT__ "PetscOptionsEList" 526 /*@C 527 PetscOptionsEList - Puts a list of option values that a single one may be selected from 528 529 Collective on the communicator passed in PetscOptionsBegin() 530 531 Input Parameters: 532 + opt - option name 533 . ltext - short string that describes the option 534 . man - manual page with additional information on option 535 . list - the possible choices 536 . ntext - number of choices 537 - defaultv - the default (current) value 538 539 Output Parameter: 540 + value - the index of the value to return 541 - set - PETSC_TRUE if found, else PETSC_FALSE 542 543 Level: intermediate 544 545 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 546 547 See PetscOptionsList() for when the choices are given in a PetscFList() 548 549 Concepts: options database^list 550 551 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 552 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 553 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 554 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 555 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 556 PetscOptionsList(), PetscOptionsEList() 557 @*/ 558 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) 559 { 560 PetscErrorCode ierr; 561 PetscInt i; 562 563 PetscFunctionBegin; 564 ierr = PetscOptionsGetEList(PetscOptionsObject.prefix,opt,list,ntext,value,set);CHKERRQ(ierr); 565 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) { 566 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%s> (choose one of)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv);CHKERRQ(ierr); 567 for (i=0; i<ntext; i++){ 568 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s",list[i]);CHKERRQ(ierr); 569 } 570 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"\n");CHKERRQ(ierr); 571 } 572 PetscFunctionReturn(0); 573 } 574 575 #undef __FUNCT__ 576 #define __FUNCT__ "PetscOptionsTruthGroupBegin" 577 /*@C 578 PetscOptionsTruthGroupBegin - First in a series of logical queries on the options database for 579 which only a single value can be true. 580 581 Collective on the communicator passed in PetscOptionsBegin() 582 583 Input Parameters: 584 + opt - option name 585 . text - short string that describes the option 586 - man - manual page with additional information on option 587 588 Output Parameter: 589 . flg - whether that option was set or not 590 591 Level: intermediate 592 593 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 594 595 Must be followed by 0 or more PetscOptionsTruthGroup()s and PetscOptionsTruthGroupEnd() 596 597 Concepts: options database^logical group 598 599 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 600 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 601 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 602 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 603 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 604 PetscOptionsList(), PetscOptionsEList() 605 @*/ 606 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroupBegin(const char opt[],const char text[],const char man[],PetscTruth *flg) 607 { 608 PetscErrorCode ierr; 609 610 PetscFunctionBegin; 611 ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr); 612 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) { 613 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," Pick at most one of -------------\n");CHKERRQ(ierr); 614 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr); 615 } 616 PetscFunctionReturn(0); 617 } 618 619 #undef __FUNCT__ 620 #define __FUNCT__ "PetscOptionsTruthGroup" 621 /*@C 622 PetscOptionsTruthGroup - One in a series of logical queries on the options database for 623 which only a single value can be true. 624 625 Collective on the communicator passed in PetscOptionsBegin() 626 627 Input Parameters: 628 + opt - option name 629 . text - short string that describes the option 630 - man - manual page with additional information on option 631 632 Output Parameter: 633 . flg - PETSC_TRUE if found, else PETSC_FALSE 634 635 Level: intermediate 636 637 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 638 639 Must follow a PetscOptionsTruthGroupBegin() and preceded a PetscOptionsTruthGroupEnd() 640 641 Concepts: options database^logical group 642 643 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 644 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 645 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 646 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 647 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 648 PetscOptionsList(), PetscOptionsEList() 649 @*/ 650 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroup(const char opt[],const char text[],const char man[],PetscTruth *flg) 651 { 652 PetscErrorCode ierr; 653 654 PetscFunctionBegin; 655 ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr); 656 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) { 657 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr); 658 } 659 PetscFunctionReturn(0); 660 } 661 662 #undef __FUNCT__ 663 #define __FUNCT__ "PetscOptionsTruthGroupEnd" 664 /*@C 665 PetscOptionsTruthGroupEnd - Last in a series of logical queries on the options database for 666 which only a single value can be true. 667 668 Collective on the communicator passed in PetscOptionsBegin() 669 670 Input Parameters: 671 + opt - option name 672 . text - short string that describes the option 673 - man - manual page with additional information on option 674 675 Output Parameter: 676 . flg - PETSC_TRUE if found, else PETSC_FALSE 677 678 Level: intermediate 679 680 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 681 682 Must follow a PetscOptionsTruthGroupBegin() 683 684 Concepts: options database^logical group 685 686 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 687 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 688 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 689 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 690 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 691 PetscOptionsList(), PetscOptionsEList() 692 @*/ 693 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroupEnd(const char opt[],const char text[],const char man[],PetscTruth *flg) 694 { 695 PetscErrorCode ierr; 696 697 PetscFunctionBegin; 698 ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr); 699 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) { 700 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr); 701 } 702 PetscFunctionReturn(0); 703 } 704 705 #undef __FUNCT__ 706 #define __FUNCT__ "PetscOptionsTruth" 707 /*@C 708 PetscOptionsTruth - Determines if a particular option is in the database with a true or false 709 710 Collective on the communicator passed in PetscOptionsBegin() 711 712 Input Parameters: 713 + opt - option name 714 . text - short string that describes the option 715 - man - manual page with additional information on option 716 717 Output Parameter: 718 . flg - PETSC_TRUE or PETSC_FALSE 719 . set - PETSC_TRUE if found, else PETSC_FALSE 720 721 Level: beginner 722 723 Concepts: options database^logical 724 725 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 726 727 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 728 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 729 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 730 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 731 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 732 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 733 PetscOptionsList(), PetscOptionsEList() 734 @*/ 735 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruth(const char opt[],const char text[],const char man[],PetscTruth deflt,PetscTruth *flg,PetscTruth *set) 736 { 737 PetscErrorCode ierr; 738 PetscTruth iset; 739 740 PetscFunctionBegin; 741 ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,&iset);CHKERRQ(ierr); 742 if (!iset) { 743 if (flg) *flg = deflt; 744 } 745 if (set) *set = iset; 746 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) { 747 const char *v = PetscTruths[deflt]; 748 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: <%s> %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,v,text,man);CHKERRQ(ierr); 749 } 750 PetscFunctionReturn(0); 751 } 752 753 #undef __FUNCT__ 754 #define __FUNCT__ "PetscOptionsRealArray" 755 /*@C 756 PetscOptionsRealArray - Gets an array of double values for a particular 757 option in the database. The values must be separated with commas with 758 no intervening spaces. 759 760 Collective on the communicator passed in PetscOptionsBegin() 761 762 Input Parameters: 763 + opt - the option one is seeking 764 . text - short string describing option 765 . man - manual page for option 766 - nmax - maximum number of values 767 768 Output Parameter: 769 + value - location to copy values 770 . nmax - actual number of values found 771 - set - PETSC_TRUE if found, else PETSC_FALSE 772 773 Level: beginner 774 775 Notes: 776 The user should pass in an array of doubles 777 778 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 779 780 Concepts: options database^array of strings 781 782 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 783 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 784 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 785 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 786 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 787 PetscOptionsList(), PetscOptionsEList() 788 @*/ 789 PetscErrorCode PETSC_DLLEXPORT PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscTruth *set) 790 { 791 PetscErrorCode ierr; 792 PetscInt i; 793 794 PetscFunctionBegin; 795 ierr = PetscOptionsGetRealArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr); 796 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) { 797 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%g",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr); 798 for (i=1; i<*n; i++) { 799 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%g",value[i]);CHKERRQ(ierr); 800 } 801 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr); 802 } 803 PetscFunctionReturn(0); 804 } 805 806 807 #undef __FUNCT__ 808 #define __FUNCT__ "PetscOptionsIntArray" 809 /*@C 810 PetscOptionsIntArray - Gets an array of integers for a particular 811 option in the database. The values must be separated with commas with 812 no intervening spaces. 813 814 Collective on the communicator passed in PetscOptionsBegin() 815 816 Input Parameters: 817 + opt - the option one is seeking 818 . text - short string describing option 819 . man - manual page for option 820 - nmax - maximum number of values 821 822 Output Parameter: 823 + value - location to copy values 824 . nmax - actual number of values found 825 - set - PETSC_TRUE if found, else PETSC_FALSE 826 827 Level: beginner 828 829 Notes: 830 The user should pass in an array of integers 831 832 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 833 834 Concepts: options database^array of strings 835 836 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 837 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 838 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 839 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 840 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 841 PetscOptionsList(), PetscOptionsEList(), PetscOptionsRealArray() 842 @*/ 843 PetscErrorCode PETSC_DLLEXPORT PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscTruth *set) 844 { 845 PetscErrorCode ierr; 846 PetscInt i; 847 848 PetscFunctionBegin; 849 ierr = PetscOptionsGetIntArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr); 850 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) { 851 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr); 852 for (i=1; i<*n; i++) { 853 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr); 854 } 855 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr); 856 } 857 PetscFunctionReturn(0); 858 } 859 860 #undef __FUNCT__ 861 #define __FUNCT__ "PetscOptionsStringArray" 862 /*@C 863 PetscOptionsStringArray - Gets an array of string values for a particular 864 option in the database. The values must be separated with commas with 865 no intervening spaces. 866 867 Collective on the communicator passed in PetscOptionsBegin() 868 869 Input Parameters: 870 + opt - the option one is seeking 871 . text - short string describing option 872 . man - manual page for option 873 - nmax - maximum number of strings 874 875 Output Parameter: 876 + value - location to copy strings 877 . nmax - actual number of strings found 878 - set - PETSC_TRUE if found, else PETSC_FALSE 879 880 Level: beginner 881 882 Notes: 883 The user should pass in an array of pointers to char, to hold all the 884 strings returned by this function. 885 886 The user is responsible for deallocating the strings that are 887 returned. The Fortran interface for this routine is not supported. 888 889 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 890 891 Concepts: options database^array of strings 892 893 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 894 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 895 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 896 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 897 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 898 PetscOptionsList(), PetscOptionsEList() 899 @*/ 900 PetscErrorCode PETSC_DLLEXPORT PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscTruth *set) 901 { 902 PetscErrorCode ierr; 903 904 PetscFunctionBegin; 905 ierr = PetscOptionsGetStringArray(PetscOptionsObject.prefix,opt,value,nmax,set);CHKERRQ(ierr); 906 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) { 907 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr); 908 } 909 PetscFunctionReturn(0); 910 } 911 912 913 #undef __FUNCT__ 914 #define __FUNCT__ "PetscOptionsHead" 915 /*@C 916 PetscOptionsHead - Puts a heading before list any more published options. Used, for example, 917 in KSPSetFromOptions_GMRES(). 918 919 Collective on the communicator passed in PetscOptionsBegin() 920 921 Input Parameter: 922 . head - the heading text 923 924 925 Level: intermediate 926 927 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 928 929 Must be followed by a call to PetscOptionsTail() in the same function. 930 931 Concepts: options database^subheading 932 933 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 934 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 935 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 936 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 937 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 938 PetscOptionsList(), PetscOptionsEList() 939 @*/ 940 PetscErrorCode PETSC_DLLEXPORT PetscOptionsHead(const char head[]) 941 { 942 PetscErrorCode ierr; 943 944 PetscFunctionBegin; 945 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) { 946 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s\n",head);CHKERRQ(ierr); 947 } 948 PetscFunctionReturn(0); 949 } 950 951 952 953 954 955 956