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 static int count = 0,mancount = 0; 310 char options[16]; 311 AMS_Comm acomm = -1; 312 AMS_Memory amem = -1; 313 PetscTruth changedmethod = PETSC_FALSE; 314 char manname[16]; 315 316 /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */ 317 ierr = PetscViewerAMSGetAMSComm(PETSC_VIEWER_AMS_(PETSC_COMM_WORLD),&acomm);CHKERRQ(ierr); 318 sprintf(options,"Options_%d",count++); 319 ierr = AMS_Memory_create(acomm,options,&amem);CHKERRQ(ierr); 320 ierr = AMS_Memory_take_access(amem);CHKERRQ(ierr); 321 PetscOptionsObject.pprefix = PetscOptionsObject.prefix; /* AMS will change this, so cannot pass prefix directly */ 322 323 ierr = AMS_Memory_add_field(amem,PetscOptionsObject.title,&PetscOptionsObject.pprefix,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr); 324 // ierr = AMS_Memory_add_field(amem,"mansec",&PetscOptionsObject.pprefix,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr); 325 ierr = AMS_Memory_add_field(amem,"ChangedMethod",&changedmethod,1,AMS_BOOLEAN,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr); 326 327 while (next) { 328 ierr = AMS_Memory_add_field(amem,next->option,&next->set,1,AMS_INT,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr); 329 ierr = PetscMalloc(sizeof(char*),&next->pman);CHKERRQ(ierr); 330 *(char **)next->pman = next->man; 331 sprintf(manname,"man_%d",mancount++); 332 ierr = AMS_Memory_add_field(amem,manname,next->pman,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr); 333 334 switch (next->type) { 335 case OPTION_HEAD: 336 break; 337 case OPTION_INT_ARRAY: 338 ierr = AMS_Memory_add_field(amem,next->text,next->data,next->arraylength,AMS_INT,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr); 339 break; 340 case OPTION_REAL_ARRAY: 341 ierr = AMS_Memory_add_field(amem,next->text,next->data,next->arraylength,AMS_DOUBLE,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr); 342 break; 343 case OPTION_INT: 344 ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_INT,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr); 345 break; 346 case OPTION_REAL: 347 ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_DOUBLE,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr); 348 break; 349 case OPTION_LOGICAL: 350 ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_BOOLEAN,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr); 351 break; 352 case OPTION_STRING: 353 ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr); 354 break; 355 case OPTION_LIST: 356 {PetscInt ntext; 357 char ldefault[128]; 358 ierr = PetscStrcpy(ldefault,"DEFAULT:");CHKERRQ(ierr); 359 ierr = PetscStrcat(ldefault,next->text);CHKERRQ(ierr); 360 ierr = AMS_Memory_add_field(amem,ldefault,next->data,1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr); 361 ierr = PetscFListGet(next->flist,(char***)&next->edata,&ntext);CHKERRQ(ierr); 362 ierr = AMS_Memory_add_field(amem,next->text,next->edata,ntext,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr); 363 break;} 364 default: 365 break; 366 } 367 next = next->next; 368 } 369 370 ierr = AMS_Memory_publish(amem);CHKERRQ(ierr); 371 ierr = AMS_Memory_grant_access(amem);CHKERRQ(ierr); 372 /* wait until accessor has unlocked the memory */ 373 ierr = AMS_Memory_lock(amem,0);CHKERRQ(ierr); 374 ierr = AMS_Memory_take_access(amem);CHKERRQ(ierr); 375 376 /* reset counter to -2; this updates the screen with the new options for the selected method */ 377 if (changedmethod) PetscOptionsPublishCount = -2; 378 379 ierr = AMS_Memory_grant_access(amem);CHKERRQ(ierr); 380 ierr = AMS_Memory_destroy(amem);CHKERRQ(ierr); 381 PetscFunctionReturn(0); 382 } 383 #endif 384 385 #undef __FUNCT__ 386 #define __FUNCT__ "PetscOptionsEnd_Private" 387 PetscErrorCode PetscOptionsEnd_Private(void) 388 { 389 PetscErrorCode ierr; 390 PetscOptions last; 391 char option[256],value[1024],tmp[32]; 392 size_t j; 393 394 PetscFunctionBegin; 395 396 CHKMEMQ; 397 if (PetscOptionsObject.next) { 398 if (!PetscOptionsPublishCount) { 399 #if defined(PETSC_HAVE_AMS) 400 ierr = PetscOptionsGetFromAMSInput();CHKERRQ(ierr); 401 #else 402 ierr = PetscOptionsGetFromTextInput();CHKERRQ(ierr); 403 #endif 404 } 405 } 406 407 ierr = PetscFree(PetscOptionsObject.title);CHKERRQ(ierr); PetscOptionsObject.title = 0; 408 ierr = PetscFree(PetscOptionsObject.prefix);CHKERRQ(ierr); PetscOptionsObject.prefix = 0; 409 410 /* reset counter to -2; this updates the screen with the new options for the selected method */ 411 if (PetscOptionsObject.changedmethod) PetscOptionsPublishCount = -2; 412 /* reset alreadyprinted flag */ 413 PetscOptionsObject.alreadyprinted = PETSC_FALSE; 414 415 while (PetscOptionsObject.next) { 416 if (PetscOptionsObject.next->set) { 417 if (PetscOptionsObject.prefix) { 418 ierr = PetscStrcpy(option,"-");CHKERRQ(ierr); 419 ierr = PetscStrcat(option,PetscOptionsObject.prefix);CHKERRQ(ierr); 420 ierr = PetscStrcat(option,PetscOptionsObject.next->option+1);CHKERRQ(ierr); 421 } else { 422 ierr = PetscStrcpy(option,PetscOptionsObject.next->option);CHKERRQ(ierr); 423 } 424 425 switch (PetscOptionsObject.next->type) { 426 case OPTION_HEAD: 427 break; 428 case OPTION_INT_ARRAY: 429 sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[0]); 430 for (j=1; j<PetscOptionsObject.next->arraylength; j++) { 431 sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[j]); 432 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 433 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 434 } 435 break; 436 case OPTION_INT: 437 sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject.next->data); 438 break; 439 case OPTION_REAL: 440 sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject.next->data); 441 break; 442 case OPTION_REAL_ARRAY: 443 sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[0]); 444 for (j=1; j<PetscOptionsObject.next->arraylength; j++) { 445 sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[j]); 446 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 447 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 448 } 449 break; 450 case OPTION_LOGICAL: 451 sprintf(value,"%d",*(int*)PetscOptionsObject.next->data); 452 break; 453 case OPTION_LIST: 454 ierr = PetscStrcpy(value,*(char**)PetscOptionsObject.next->data);CHKERRQ(ierr); 455 break; 456 case OPTION_STRING: /* also handles string arrays */ 457 ierr = PetscStrcpy(value,*(char**)PetscOptionsObject.next->data);CHKERRQ(ierr); 458 break; 459 } 460 ierr = PetscOptionsSetValue(option,value);CHKERRQ(ierr); 461 } 462 ierr = PetscFree(PetscOptionsObject.next->text);CHKERRQ(ierr); 463 ierr = PetscFree(PetscOptionsObject.next->option);CHKERRQ(ierr); 464 ierr = PetscFree(PetscOptionsObject.next->man);CHKERRQ(ierr); 465 ierr = PetscFree(PetscOptionsObject.next->data);CHKERRQ(ierr); 466 ierr = PetscFree(PetscOptionsObject.next->edata);CHKERRQ(ierr); 467 last = PetscOptionsObject.next; 468 PetscOptionsObject.next = PetscOptionsObject.next->next; 469 ierr = PetscFree(last);CHKERRQ(ierr); 470 CHKMEMQ; 471 } 472 CHKMEMQ; 473 PetscOptionsObject.next = 0; 474 PetscFunctionReturn(0); 475 } 476 477 #undef __FUNCT__ 478 #define __FUNCT__ "PetscOptionsEnum" 479 /*@C 480 PetscOptionsEnum - Gets the enum value for a particular option in the database. 481 482 Collective on the communicator passed in PetscOptionsBegin() 483 484 Input Parameters: 485 + opt - option name 486 . text - short string that describes the option 487 . man - manual page with additional information on option 488 . list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null 489 - defaultv - the default (current) value 490 491 Output Parameter: 492 + value - the value to return 493 - flg - PETSC_TRUE if found, else PETSC_FALSE 494 495 Level: beginner 496 497 Concepts: options database 498 499 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 500 501 list is usually something like PCASMTypes or some other predefined list of enum names 502 503 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 504 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 505 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 506 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 507 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 508 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 509 PetscOptionsList(), PetscOptionsEList() 510 @*/ 511 PetscErrorCode PETSC_DLLEXPORT PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const*list,PetscEnum defaultv,PetscEnum *value,PetscTruth *set) 512 { 513 PetscErrorCode ierr; 514 PetscInt ntext = 0; 515 PetscInt tval; 516 PetscTruth tflg; 517 518 PetscFunctionBegin; 519 while (list[ntext++]) { 520 if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries"); 521 } 522 if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix"); 523 ntext -= 3; 524 ierr = PetscOptionsEList(opt,text,man,list,ntext,list[defaultv],&tval,&tflg);CHKERRQ(ierr); 525 /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */ 526 if (tflg) *value = (PetscEnum)tval; 527 if (set) *set = tflg; 528 PetscFunctionReturn(0); 529 } 530 531 /* -------------------------------------------------------------------------------------------------------------*/ 532 #undef __FUNCT__ 533 #define __FUNCT__ "PetscOptionsInt" 534 /*@C 535 PetscOptionsInt - Gets the integer value for a particular option in the database. 536 537 Collective on the communicator passed in PetscOptionsBegin() 538 539 Input Parameters: 540 + opt - option name 541 . text - short string that describes the option 542 . man - manual page with additional information on option 543 - defaultv - the default (current) value 544 545 Output Parameter: 546 + value - the integer value to return 547 - flg - PETSC_TRUE if found, else PETSC_FALSE 548 549 Level: beginner 550 551 Concepts: options database^has int 552 553 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 554 555 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 556 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 557 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 558 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 559 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 560 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 561 PetscOptionsList(), PetscOptionsEList() 562 @*/ 563 PetscErrorCode PETSC_DLLEXPORT PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt defaultv,PetscInt *value,PetscTruth *set) 564 { 565 PetscErrorCode ierr; 566 PetscOptions amsopt; 567 568 PetscFunctionBegin; 569 if (!PetscOptionsPublishCount) { 570 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr); 571 ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr); 572 *(PetscInt*)amsopt->data = defaultv; 573 } 574 ierr = PetscOptionsGetInt(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 575 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 576 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%d>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr); 577 } 578 PetscFunctionReturn(0); 579 } 580 581 #undef __FUNCT__ 582 #define __FUNCT__ "PetscOptionsString" 583 /*@C 584 PetscOptionsString - Gets the string value for a particular option in the database. 585 586 Collective on the communicator passed in PetscOptionsBegin() 587 588 Input Parameters: 589 + opt - option name 590 . text - short string that describes the option 591 . man - manual page with additional information on option 592 - defaultv - the default (current) value 593 594 Output Parameter: 595 + value - the value to return 596 - flg - PETSC_TRUE if found, else PETSC_FALSE 597 598 Level: beginner 599 600 Concepts: options database^has int 601 602 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 603 604 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 605 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 606 PetscOptionsInt(), PetscOptionsReal(), PetscOptionsTruth(), 607 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 608 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 609 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 610 PetscOptionsList(), PetscOptionsEList() 611 @*/ 612 PetscErrorCode PETSC_DLLEXPORT PetscOptionsString(const char opt[],const char text[],const char man[],const char defaultv[],char value[],size_t len,PetscTruth *set) 613 { 614 PetscErrorCode ierr; 615 PetscOptions amsopt; 616 617 PetscFunctionBegin; 618 if (!PetscOptionsPublishCount) { 619 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr); 620 ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr); 621 *(const char**)amsopt->data = defaultv; 622 } 623 ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr); 624 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 625 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr); 626 } 627 PetscFunctionReturn(0); 628 } 629 630 #undef __FUNCT__ 631 #define __FUNCT__ "PetscOptionsReal" 632 /*@C 633 PetscOptionsReal - Gets the PetscReal value for a particular option in the database. 634 635 Collective on the communicator passed in PetscOptionsBegin() 636 637 Input Parameters: 638 + opt - option name 639 . text - short string that describes the option 640 . man - manual page with additional information on option 641 - defaultv - the default (current) value 642 643 Output Parameter: 644 + value - the value to return 645 - flg - PETSC_TRUE if found, else PETSC_FALSE 646 647 Level: beginner 648 649 Concepts: options database^has int 650 651 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 652 653 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 654 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 655 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 656 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 657 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 658 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 659 PetscOptionsList(), PetscOptionsEList() 660 @*/ 661 PetscErrorCode PETSC_DLLEXPORT PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal defaultv,PetscReal *value,PetscTruth *set) 662 { 663 PetscErrorCode ierr; 664 PetscOptions amsopt; 665 666 PetscFunctionBegin; 667 if (!PetscOptionsPublishCount) { 668 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr); 669 ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr); 670 *(PetscReal*)amsopt->data = defaultv; 671 } 672 ierr = PetscOptionsGetReal(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 673 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 674 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%G>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr); 675 } 676 PetscFunctionReturn(0); 677 } 678 679 #undef __FUNCT__ 680 #define __FUNCT__ "PetscOptionsScalar" 681 /*@C 682 PetscOptionsScalar - Gets the scalar value for a particular option in the database. 683 684 Collective on the communicator passed in PetscOptionsBegin() 685 686 Input Parameters: 687 + opt - option name 688 . text - short string that describes the option 689 . man - manual page with additional information on option 690 - defaultv - the default (current) value 691 692 Output Parameter: 693 + value - the value to return 694 - flg - PETSC_TRUE if found, else PETSC_FALSE 695 696 Level: beginner 697 698 Concepts: options database^has int 699 700 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 701 702 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 703 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 704 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 705 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 706 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 707 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 708 PetscOptionsList(), PetscOptionsEList() 709 @*/ 710 PetscErrorCode PETSC_DLLEXPORT PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar defaultv,PetscScalar *value,PetscTruth *set) 711 { 712 PetscErrorCode ierr; 713 714 PetscFunctionBegin; 715 #if !defined(PETSC_USE_COMPLEX) 716 ierr = PetscOptionsReal(opt,text,man,defaultv,value,set);CHKERRQ(ierr); 717 #else 718 ierr = PetscOptionsGetScalar(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 719 #endif 720 PetscFunctionReturn(0); 721 } 722 723 #undef __FUNCT__ 724 #define __FUNCT__ "PetscOptionsName" 725 /*@C 726 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 727 its value is set to false. 728 729 Collective on the communicator passed in PetscOptionsBegin() 730 731 Input Parameters: 732 + opt - option name 733 . text - short string that describes the option 734 - man - manual page with additional information on option 735 736 Output Parameter: 737 . flg - PETSC_TRUE if found, else PETSC_FALSE 738 739 Level: beginner 740 741 Concepts: options database^has int 742 743 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 744 745 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 746 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 747 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 748 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 749 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 750 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 751 PetscOptionsList(), PetscOptionsEList() 752 @*/ 753 PetscErrorCode PETSC_DLLEXPORT PetscOptionsName(const char opt[],const char text[],const char man[],PetscTruth *flg) 754 { 755 PetscErrorCode ierr; 756 757 PetscFunctionBegin; 758 ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr); 759 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 760 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr); 761 } 762 PetscFunctionReturn(0); 763 } 764 765 #undef __FUNCT__ 766 #define __FUNCT__ "PetscOptionsList" 767 /*@C 768 PetscOptionsList - Puts a list of option values that a single one may be selected from 769 770 Collective on the communicator passed in PetscOptionsBegin() 771 772 Input Parameters: 773 + opt - option name 774 . text - short string that describes the option 775 . man - manual page with additional information on option 776 . list - the possible choices 777 . defaultv - the default (current) value 778 - len - the length of the character array value 779 780 Output Parameter: 781 + value - the value to return 782 - set - PETSC_TRUE if found, else PETSC_FALSE 783 784 Level: intermediate 785 786 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 787 788 See PetscOptionsEList() for when the choices are given in a string array 789 790 To get a listing of all currently specified options, 791 see PetscOptionsPrint() or PetscOptionsGetAll() 792 793 Concepts: options database^list 794 795 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 796 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 797 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 798 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 799 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 800 PetscOptionsList(), PetscOptionsEList() 801 @*/ 802 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) 803 { 804 PetscErrorCode ierr; 805 PetscOptions amsopt; 806 807 PetscFunctionBegin; 808 if (!PetscOptionsPublishCount) { 809 ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_LIST,&amsopt);CHKERRQ(ierr); 810 ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr); 811 *(const char**)amsopt->data = defaultv; 812 amsopt->flist = list; 813 } 814 ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr); 815 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 816 ierr = PetscFListPrintTypes(PetscOptionsObject.comm,stdout,PetscOptionsObject.prefix,opt,ltext,man,list,defaultv);CHKERRQ(ierr);CHKERRQ(ierr); 817 } 818 PetscFunctionReturn(0); 819 } 820 821 #undef __FUNCT__ 822 #define __FUNCT__ "PetscOptionsEList" 823 /*@C 824 PetscOptionsEList - Puts a list of option values that a single one may be selected from 825 826 Collective on the communicator passed in PetscOptionsBegin() 827 828 Input Parameters: 829 + opt - option name 830 . ltext - short string that describes the option 831 . man - manual page with additional information on option 832 . list - the possible choices 833 . ntext - number of choices 834 - defaultv - the default (current) value 835 836 Output Parameter: 837 + value - the index of the value to return 838 - set - PETSC_TRUE if found, else PETSC_FALSE 839 840 Level: intermediate 841 842 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 843 844 See PetscOptionsList() for when the choices are given in a PetscFList() 845 846 Concepts: options database^list 847 848 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 849 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 850 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 851 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 852 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 853 PetscOptionsList(), PetscOptionsEList() 854 @*/ 855 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) 856 { 857 PetscErrorCode ierr; 858 PetscInt i; 859 860 PetscFunctionBegin; 861 ierr = PetscOptionsGetEList(PetscOptionsObject.prefix,opt,list,ntext,value,set);CHKERRQ(ierr); 862 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 863 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%s> (choose one of)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv);CHKERRQ(ierr); 864 for (i=0; i<ntext; i++){ 865 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s",list[i]);CHKERRQ(ierr); 866 } 867 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"\n");CHKERRQ(ierr); 868 } 869 PetscFunctionReturn(0); 870 } 871 872 #undef __FUNCT__ 873 #define __FUNCT__ "PetscOptionsTruthGroupBegin" 874 /*@C 875 PetscOptionsTruthGroupBegin - First in a series of logical queries on the options database for 876 which only a single value can be true. 877 878 Collective on the communicator passed in PetscOptionsBegin() 879 880 Input Parameters: 881 + opt - option name 882 . text - short string that describes the option 883 - man - manual page with additional information on option 884 885 Output Parameter: 886 . flg - whether that option was set or not 887 888 Level: intermediate 889 890 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 891 892 Must be followed by 0 or more PetscOptionsTruthGroup()s and PetscOptionsTruthGroupEnd() 893 894 Concepts: options database^logical group 895 896 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 897 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 898 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 899 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 900 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 901 PetscOptionsList(), PetscOptionsEList() 902 @*/ 903 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroupBegin(const char opt[],const char text[],const char man[],PetscTruth *flg) 904 { 905 PetscErrorCode ierr; 906 907 PetscFunctionBegin; 908 *flg = PETSC_FALSE; 909 ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr); 910 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 911 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," Pick at most one of -------------\n");CHKERRQ(ierr); 912 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr); 913 } 914 PetscFunctionReturn(0); 915 } 916 917 #undef __FUNCT__ 918 #define __FUNCT__ "PetscOptionsTruthGroup" 919 /*@C 920 PetscOptionsTruthGroup - One in a series of logical queries on the options database for 921 which only a single value can be true. 922 923 Collective on the communicator passed in PetscOptionsBegin() 924 925 Input Parameters: 926 + opt - option name 927 . text - short string that describes the option 928 - man - manual page with additional information on option 929 930 Output Parameter: 931 . flg - PETSC_TRUE if found, else PETSC_FALSE 932 933 Level: intermediate 934 935 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 936 937 Must follow a PetscOptionsTruthGroupBegin() and preceded a PetscOptionsTruthGroupEnd() 938 939 Concepts: options database^logical group 940 941 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 942 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 943 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 944 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 945 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 946 PetscOptionsList(), PetscOptionsEList() 947 @*/ 948 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroup(const char opt[],const char text[],const char man[],PetscTruth *flg) 949 { 950 PetscErrorCode ierr; 951 952 PetscFunctionBegin; 953 *flg = PETSC_FALSE; 954 ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr); 955 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 956 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr); 957 } 958 PetscFunctionReturn(0); 959 } 960 961 #undef __FUNCT__ 962 #define __FUNCT__ "PetscOptionsTruthGroupEnd" 963 /*@C 964 PetscOptionsTruthGroupEnd - Last in a series of logical queries on the options database for 965 which only a single value can be true. 966 967 Collective on the communicator passed in PetscOptionsBegin() 968 969 Input Parameters: 970 + opt - option name 971 . text - short string that describes the option 972 - man - manual page with additional information on option 973 974 Output Parameter: 975 . flg - PETSC_TRUE if found, else PETSC_FALSE 976 977 Level: intermediate 978 979 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 980 981 Must follow a PetscOptionsTruthGroupBegin() 982 983 Concepts: options database^logical group 984 985 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 986 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 987 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 988 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 989 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 990 PetscOptionsList(), PetscOptionsEList() 991 @*/ 992 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroupEnd(const char opt[],const char text[],const char man[],PetscTruth *flg) 993 { 994 PetscErrorCode ierr; 995 996 PetscFunctionBegin; 997 *flg = PETSC_FALSE; 998 ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr); 999 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1000 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr); 1001 } 1002 PetscFunctionReturn(0); 1003 } 1004 1005 #undef __FUNCT__ 1006 #define __FUNCT__ "PetscOptionsTruth" 1007 /*@C 1008 PetscOptionsTruth - Determines if a particular option is in the database with a true or false 1009 1010 Collective on the communicator passed in PetscOptionsBegin() 1011 1012 Input Parameters: 1013 + opt - option name 1014 . text - short string that describes the option 1015 - man - manual page with additional information on option 1016 1017 Output Parameter: 1018 . flg - PETSC_TRUE or PETSC_FALSE 1019 . set - PETSC_TRUE if found, else PETSC_FALSE 1020 1021 Level: beginner 1022 1023 Concepts: options database^logical 1024 1025 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1026 1027 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 1028 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 1029 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 1030 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1031 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1032 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 1033 PetscOptionsList(), PetscOptionsEList() 1034 @*/ 1035 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruth(const char opt[],const char text[],const char man[],PetscTruth deflt,PetscTruth *flg,PetscTruth *set) 1036 { 1037 PetscErrorCode ierr; 1038 PetscTruth iset; 1039 PetscOptions amsopt; 1040 1041 PetscFunctionBegin; 1042 if (!PetscOptionsPublishCount) { 1043 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr); 1044 ierr = PetscMalloc(sizeof(PetscTruth),&amsopt->data);CHKERRQ(ierr); 1045 *(PetscTruth*)amsopt->data = deflt; 1046 } 1047 ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,&iset);CHKERRQ(ierr); 1048 if (!iset) { 1049 if (flg) *flg = deflt; 1050 } 1051 if (set) *set = iset; 1052 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1053 const char *v = PetscTruths[deflt]; 1054 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: <%s> %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,v,text,man);CHKERRQ(ierr); 1055 } 1056 PetscFunctionReturn(0); 1057 } 1058 1059 #undef __FUNCT__ 1060 #define __FUNCT__ "PetscOptionsRealArray" 1061 /*@C 1062 PetscOptionsRealArray - Gets an array of double values for a particular 1063 option in the database. The values must be separated with commas with 1064 no intervening spaces. 1065 1066 Collective on the communicator passed in PetscOptionsBegin() 1067 1068 Input Parameters: 1069 + opt - the option one is seeking 1070 . text - short string describing option 1071 . man - manual page for option 1072 - nmax - maximum number of values 1073 1074 Output Parameter: 1075 + value - location to copy values 1076 . nmax - actual number of values found 1077 - set - PETSC_TRUE if found, else PETSC_FALSE 1078 1079 Level: beginner 1080 1081 Notes: 1082 The user should pass in an array of doubles 1083 1084 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1085 1086 Concepts: options database^array of strings 1087 1088 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1089 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 1090 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1091 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1092 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 1093 PetscOptionsList(), PetscOptionsEList() 1094 @*/ 1095 PetscErrorCode PETSC_DLLEXPORT PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscTruth *set) 1096 { 1097 PetscErrorCode ierr; 1098 PetscInt i; 1099 PetscOptions amsopt; 1100 1101 PetscFunctionBegin; 1102 if (!PetscOptionsPublishCount) { 1103 PetscReal *vals; 1104 1105 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr); 1106 ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr); 1107 vals = (PetscReal*)amsopt->data; 1108 for (i=0; i<*n; i++) vals[i] = value[i]; 1109 amsopt->arraylength = *n; 1110 } 1111 ierr = PetscOptionsGetRealArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr); 1112 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1113 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%G",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr); 1114 for (i=1; i<*n; i++) { 1115 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%G",value[i]);CHKERRQ(ierr); 1116 } 1117 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr); 1118 } 1119 PetscFunctionReturn(0); 1120 } 1121 1122 1123 #undef __FUNCT__ 1124 #define __FUNCT__ "PetscOptionsIntArray" 1125 /*@C 1126 PetscOptionsIntArray - Gets an array of integers for a particular 1127 option in the database. The values must be separated with commas with 1128 no intervening spaces. 1129 1130 Collective on the communicator passed in PetscOptionsBegin() 1131 1132 Input Parameters: 1133 + opt - the option one is seeking 1134 . text - short string describing option 1135 . man - manual page for option 1136 - n - maximum number of values 1137 1138 Output Parameter: 1139 + value - location to copy values 1140 . n - actual number of values found 1141 - set - PETSC_TRUE if found, else PETSC_FALSE 1142 1143 Level: beginner 1144 1145 Notes: 1146 The user should pass in an array of integers 1147 1148 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1149 1150 Concepts: options database^array of strings 1151 1152 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1153 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 1154 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1155 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1156 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 1157 PetscOptionsList(), PetscOptionsEList(), PetscOptionsRealArray() 1158 @*/ 1159 PetscErrorCode PETSC_DLLEXPORT PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscTruth *set) 1160 { 1161 PetscErrorCode ierr; 1162 PetscInt i; 1163 PetscOptions amsopt; 1164 1165 PetscFunctionBegin; 1166 if (!PetscOptionsPublishCount) { 1167 PetscInt *vals; 1168 1169 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr); 1170 ierr = PetscMalloc((*n)*sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr); 1171 vals = (PetscInt*)amsopt->data; 1172 for (i=0; i<*n; i++) vals[i] = value[i]; 1173 amsopt->arraylength = *n; 1174 } 1175 ierr = PetscOptionsGetIntArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr); 1176 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1177 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr); 1178 for (i=1; i<*n; i++) { 1179 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr); 1180 } 1181 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr); 1182 } 1183 PetscFunctionReturn(0); 1184 } 1185 1186 #undef __FUNCT__ 1187 #define __FUNCT__ "PetscOptionsStringArray" 1188 /*@C 1189 PetscOptionsStringArray - Gets an array of string values for a particular 1190 option in the database. The values must be separated with commas with 1191 no intervening spaces. 1192 1193 Collective on the communicator passed in PetscOptionsBegin() 1194 1195 Input Parameters: 1196 + opt - the option one is seeking 1197 . text - short string describing option 1198 . man - manual page for option 1199 - nmax - maximum number of strings 1200 1201 Output Parameter: 1202 + value - location to copy strings 1203 . nmax - actual number of strings found 1204 - set - PETSC_TRUE if found, else PETSC_FALSE 1205 1206 Level: beginner 1207 1208 Notes: 1209 The user should pass in an array of pointers to char, to hold all the 1210 strings returned by this function. 1211 1212 The user is responsible for deallocating the strings that are 1213 returned. The Fortran interface for this routine is not supported. 1214 1215 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1216 1217 Concepts: options database^array of strings 1218 1219 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1220 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 1221 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1222 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1223 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 1224 PetscOptionsList(), PetscOptionsEList() 1225 @*/ 1226 PetscErrorCode PETSC_DLLEXPORT PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscTruth *set) 1227 { 1228 PetscErrorCode ierr; 1229 1230 PetscFunctionBegin; 1231 ierr = PetscOptionsGetStringArray(PetscOptionsObject.prefix,opt,value,nmax,set);CHKERRQ(ierr); 1232 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1233 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr); 1234 } 1235 PetscFunctionReturn(0); 1236 } 1237 1238 #undef __FUNCT__ 1239 #define __FUNCT__ "PetscOptionsTruthArray" 1240 /*@C 1241 PetscOptionsTruthArray - Gets an array of logical values (true or false) for a particular 1242 option in the database. The values must be separated with commas with 1243 no intervening spaces. 1244 1245 Collective on the communicator passed in PetscOptionsBegin() 1246 1247 Input Parameters: 1248 + opt - the option one is seeking 1249 . text - short string describing option 1250 . man - manual page for option 1251 - nmax - maximum number of values 1252 1253 Output Parameter: 1254 + value - location to copy values 1255 . nmax - actual number of values found 1256 - set - PETSC_TRUE if found, else PETSC_FALSE 1257 1258 Level: beginner 1259 1260 Notes: 1261 The user should pass in an array of doubles 1262 1263 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1264 1265 Concepts: options database^array of strings 1266 1267 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1268 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 1269 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1270 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1271 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 1272 PetscOptionsList(), PetscOptionsEList() 1273 @*/ 1274 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthArray(const char opt[],const char text[],const char man[],PetscTruth value[],PetscInt *n,PetscTruth *set) 1275 { 1276 PetscErrorCode ierr; 1277 PetscInt i; 1278 1279 PetscFunctionBegin; 1280 ierr = PetscOptionsGetTruthArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr); 1281 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1282 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr); 1283 for (i=1; i<*n; i++) { 1284 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr); 1285 } 1286 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr); 1287 } 1288 PetscFunctionReturn(0); 1289 } 1290 1291 1292 #undef __FUNCT__ 1293 #define __FUNCT__ "PetscOptionsHead" 1294 /*@C 1295 PetscOptionsHead - Puts a heading before listing any more published options. Used, for example, 1296 in KSPSetFromOptions_GMRES(). 1297 1298 Collective on the communicator passed in PetscOptionsBegin() 1299 1300 Input Parameter: 1301 . head - the heading text 1302 1303 1304 Level: intermediate 1305 1306 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1307 1308 Can be followed by a call to PetscOptionsTail() in the same function. 1309 1310 Concepts: options database^subheading 1311 1312 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1313 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 1314 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1315 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1316 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 1317 PetscOptionsList(), PetscOptionsEList() 1318 @*/ 1319 PetscErrorCode PETSC_DLLEXPORT PetscOptionsHead(const char head[]) 1320 { 1321 PetscErrorCode ierr; 1322 1323 PetscFunctionBegin; 1324 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1325 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s\n",head);CHKERRQ(ierr); 1326 } 1327 PetscFunctionReturn(0); 1328 } 1329 1330 1331 1332 1333 1334 1335