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