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