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