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