1 2 /* 3 Implements the higher-level options database querying methods. These are self-documenting and can attach at runtime to 4 GUI code to display the options and get values from the users. 5 6 */ 7 8 #include <petsc-private/petscimpl.h> /*I "petscsys.h" I*/ 9 #include <petscviewer.h> 10 11 #define ManSection(str) ((str) ? (str) : "None") 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 36 ierr = PetscFree(PetscOptionsObject.prefix);CHKERRQ(ierr); 37 ierr = PetscStrallocpy(prefix,&PetscOptionsObject.prefix);CHKERRQ(ierr); 38 ierr = PetscFree(PetscOptionsObject.title);CHKERRQ(ierr); 39 ierr = PetscStrallocpy(title,&PetscOptionsObject.title);CHKERRQ(ierr); 40 41 ierr = PetscOptionsHasName(NULL,"-help",&PetscOptionsObject.printhelp);CHKERRQ(ierr); 42 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) { 43 if (!PetscOptionsObject.alreadyprinted) { 44 ierr = (*PetscHelpPrintf)(comm,"%s -------------------------------------------------\n",title);CHKERRQ(ierr); 45 } 46 } 47 PetscFunctionReturn(0); 48 } 49 50 #undef __FUNCT__ 51 #define __FUNCT__ "PetscObjectOptionsBegin_Private" 52 /* 53 Handles setting up the data structure in a call to PetscObjectOptionsBegin() 54 */ 55 PetscErrorCode PetscObjectOptionsBegin_Private(PetscObject obj) 56 { 57 PetscErrorCode ierr; 58 char title[256]; 59 PetscBool flg; 60 61 PetscFunctionBegin; 62 PetscValidHeader(obj,1); 63 PetscOptionsObject.object = obj; 64 PetscOptionsObject.alreadyprinted = obj->optionsprinted; 65 66 ierr = PetscStrcmp(obj->description,obj->class_name,&flg);CHKERRQ(ierr); 67 if (flg) { 68 ierr = PetscSNPrintf(title,sizeof(title),"%s options",obj->class_name);CHKERRQ(ierr); 69 } else { 70 ierr = PetscSNPrintf(title,sizeof(title),"%s (%s) options",obj->description,obj->class_name);CHKERRQ(ierr); 71 } 72 ierr = PetscOptionsBegin_Private(obj->comm,obj->prefix,title,obj->mansec);CHKERRQ(ierr); 73 PetscFunctionReturn(0); 74 } 75 76 /* 77 Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd() 78 */ 79 #undef __FUNCT__ 80 #define __FUNCT__ "PetscOptionsCreate_Private" 81 static int PetscOptionsCreate_Private(const char opt[],const char text[],const char man[],PetscOptionType t,PetscOptions *amsopt) 82 { 83 int ierr; 84 PetscOptions next; 85 PetscBool valid; 86 87 PetscFunctionBegin; 88 ierr = PetscOptionsValidKey(opt,&valid);CHKERRQ(ierr); 89 if (!valid) SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_ARG_INCOMP,"The option '%s' is not a valid key",opt); 90 91 ierr = PetscNew(struct _n_PetscOptions,amsopt);CHKERRQ(ierr); 92 (*amsopt)->next = 0; 93 (*amsopt)->set = PETSC_FALSE; 94 (*amsopt)->type = t; 95 (*amsopt)->data = 0; 96 97 ierr = PetscStrallocpy(text,&(*amsopt)->text);CHKERRQ(ierr); 98 ierr = PetscStrallocpy(opt,&(*amsopt)->option);CHKERRQ(ierr); 99 ierr = PetscStrallocpy(man,&(*amsopt)->man);CHKERRQ(ierr); 100 101 if (!PetscOptionsObject.next) PetscOptionsObject.next = *amsopt; 102 else { 103 next = PetscOptionsObject.next; 104 while (next->next) next = next->next; 105 next->next = *amsopt; 106 } 107 PetscFunctionReturn(0); 108 } 109 110 #undef __FUNCT__ 111 #define __FUNCT__ "PetscScanString" 112 /* 113 PetscScanString - Gets user input via stdin from process and broadcasts to all processes 114 115 Collective on MPI_Comm 116 117 Input Parameters: 118 + commm - communicator for the broadcast, must be PETSC_COMM_WORLD 119 . n - length of the string, must be the same on all processes 120 - str - location to store input 121 122 Bugs: 123 . Assumes process 0 of the given communicator has access to stdin 124 125 */ 126 static PetscErrorCode PetscScanString(MPI_Comm comm,size_t n,char str[]) 127 { 128 size_t i; 129 char c; 130 PetscMPIInt rank,nm; 131 PetscErrorCode ierr; 132 133 PetscFunctionBegin; 134 ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); 135 if (!rank) { 136 c = (char) getchar(); 137 i = 0; 138 while (c != '\n' && i < n-1) { 139 str[i++] = c; 140 c = (char)getchar(); 141 } 142 str[i] = 0; 143 } 144 ierr = PetscMPIIntCast(n,&nm);CHKERRQ(ierr); 145 ierr = MPI_Bcast(str,nm,MPI_CHAR,0,comm);CHKERRQ(ierr); 146 PetscFunctionReturn(0); 147 } 148 149 #undef __FUNCT__ 150 #define __FUNCT__ "PetscOptionsGetFromTextInput" 151 /* 152 PetscOptionsGetFromTextInput - Presents all the PETSc Options processed by the program so the user may change them at runtime 153 154 Notes: this isn't really practical, it is just to demonstrate the principle 155 156 Bugs: 157 + All processes must traverse through the exact same set of option queries do to the call to PetscScanString() 158 . Internal strings have arbitrary length and string copies are not checked that they fit into string space 159 - Only works for PetscInt == int, PetscReal == double etc 160 161 Developer Notes: Normally the GUI that presents the options the user and retrieves the values would be running in a different 162 address space and communicating with the PETSc program 163 164 */ 165 PetscErrorCode PetscOptionsGetFromTextInput() 166 { 167 PetscErrorCode ierr; 168 PetscOptions next = PetscOptionsObject.next; 169 char str[512]; 170 PetscInt id; 171 PetscReal ir,*valr; 172 PetscInt *vald; 173 size_t i; 174 175 ierr = (*PetscPrintf)(PETSC_COMM_WORLD,"%s -------------------------------------------------\n",PetscOptionsObject.title);CHKERRQ(ierr); 176 while (next) { 177 switch (next->type) { 178 case OPTION_HEAD: 179 break; 180 case OPTION_INT_ARRAY: 181 ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",next->option+1);CHKERRQ(ierr); 182 vald = (PetscInt*) next->data; 183 for (i=0; i<next->arraylength; i++) { 184 ierr = PetscPrintf(PETSC_COMM_WORLD,"%d",vald[i]);CHKERRQ(ierr); 185 if (i < next->arraylength-1) { 186 ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr); 187 } 188 } 189 ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s)",next->text,next->man);CHKERRQ(ierr); 190 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 191 if (str[0]) { 192 PetscToken token; 193 PetscInt n=0,nmax = next->arraylength,*dvalue = (PetscInt*)next->data,start,end; 194 size_t len; 195 char *value; 196 PetscBool foundrange; 197 198 next->set = PETSC_TRUE; 199 value = str; 200 ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 201 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 202 while (n < nmax) { 203 if (!value) break; 204 205 /* look for form d-D where d and D are integers */ 206 foundrange = PETSC_FALSE; 207 ierr = PetscStrlen(value,&len);CHKERRQ(ierr); 208 if (value[0] == '-') i=2; 209 else i=1; 210 for (;i<len; i++) { 211 if (value[i] == '-') { 212 if (i == len-1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry %s\n",n,value); 213 value[i] = 0; 214 ierr = PetscOptionsStringToInt(value,&start);CHKERRQ(ierr); 215 ierr = PetscOptionsStringToInt(value+i+1,&end);CHKERRQ(ierr); 216 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); 217 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); 218 for (; start<end; start++) { 219 *dvalue = start; dvalue++;n++; 220 } 221 foundrange = PETSC_TRUE; 222 break; 223 } 224 } 225 if (!foundrange) { 226 ierr = PetscOptionsStringToInt(value,dvalue);CHKERRQ(ierr); 227 dvalue++; 228 n++; 229 } 230 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 231 } 232 ierr = PetscTokenDestroy(&token);CHKERRQ(ierr); 233 } 234 break; 235 case OPTION_REAL_ARRAY: 236 ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",next->option+1);CHKERRQ(ierr); 237 valr = (PetscReal*) next->data; 238 for (i=0; i<next->arraylength; i++) { 239 ierr = PetscPrintf(PETSC_COMM_WORLD,"%g",valr[i]);CHKERRQ(ierr); 240 if (i < next->arraylength-1) { 241 ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr); 242 } 243 } 244 ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s)",next->text,next->man);CHKERRQ(ierr); 245 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 246 if (str[0]) { 247 PetscToken token; 248 PetscInt n = 0,nmax = next->arraylength; 249 PetscReal *dvalue = (PetscReal*)next->data; 250 char *value; 251 252 next->set = PETSC_TRUE; 253 value = str; 254 ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 255 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 256 while (n < nmax) { 257 if (!value) break; 258 ierr = PetscOptionsStringToReal(value,dvalue);CHKERRQ(ierr); 259 dvalue++; 260 n++; 261 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 262 } 263 ierr = PetscTokenDestroy(&token);CHKERRQ(ierr); 264 } 265 break; 266 case OPTION_INT: 267 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); 268 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 269 if (str[0]) { 270 #if defined(PETSC_USE_64BIT_INDICES) 271 sscanf(str,"%lld",&id); 272 #else 273 sscanf(str,"%d",&id); 274 #endif 275 next->set = PETSC_TRUE; 276 277 *((PetscInt*)next->data) = id; 278 } 279 break; 280 case OPTION_REAL: 281 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); 282 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 283 if (str[0]) { 284 #if defined(PETSC_USE_REAL_SINGLE) 285 sscanf(str,"%e",&ir); 286 #elif defined(PETSC_USE_REAL_DOUBLE) 287 sscanf(str,"%le",&ir); 288 #elif defined(PETSC_USE_REAL___FLOAT128) 289 ir = strtoflt128(str,0); 290 #else 291 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Unknown scalar type"); 292 #endif 293 next->set = PETSC_TRUE; 294 *((PetscReal*)next->data) = ir; 295 } 296 break; 297 case OPTION_LOGICAL: 298 case OPTION_STRING: 299 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); 300 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 301 if (str[0]) { 302 next->set = PETSC_TRUE; 303 304 ierr = PetscStrcpy((char*)next->data,str);CHKERRQ(ierr); 305 } 306 break; 307 case OPTION_LIST: 308 ierr = PetscFunctionListPrintTypes(PETSC_COMM_WORLD,stdout,PetscOptionsObject.prefix,next->option,next->text,next->man,next->flist,(char*)next->data);CHKERRQ(ierr); 309 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 310 if (str[0]) { 311 PetscOptionsObject.changedmethod = PETSC_TRUE; 312 next->set = PETSC_TRUE; 313 ierr = PetscStrcpy((char*)next->data,str);CHKERRQ(ierr); 314 } 315 break; 316 default: 317 break; 318 } 319 next = next->next; 320 } 321 PetscFunctionReturn(0); 322 } 323 324 #if defined(PETSC_HAVE_AMS) 325 #include <petscviewerams.h> 326 327 static int count = 0; 328 329 #undef __FUNCT__ 330 #define __FUNCT__ "PetscOptionsAMSDestroy" 331 PetscErrorCode PetscOptionsAMSDestroy(void) 332 { 333 PetscErrorCode ierr; 334 AMS_Comm acomm = -1; 335 AMS_Memory amem = -1; 336 char options[16]; 337 const char *string = "Exit"; 338 339 /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */ 340 ierr = PetscViewerAMSGetAMSComm(PETSC_VIEWER_AMS_(PETSC_COMM_WORLD),&acomm);CHKERRQ(ierr); 341 sprintf(options,"Options_%d",count++); 342 PetscStackCallAMS(AMS_Memory_create,(acomm,options,&amem)); 343 PetscStackCallAMS(AMS_Memory_add_field,(amem,"Exit",&string,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF)); 344 345 PetscStackCallAMS(AMS_Memory_take_access,(amem)); 346 PetscStackCallAMS(AMS_Memory_publish,(amem)); 347 PetscStackCallAMS(AMS_Memory_grant_access,(amem)); 348 /* wait until accessor has unlocked the memory */ 349 PetscStackCallAMS(AMS_Memory_lock,(amem,0)); 350 PetscStackCallAMS(AMS_Memory_take_access,(amem)); 351 PetscStackCallAMS(AMS_Memory_grant_access,(amem)); 352 PetscStackCallAMS(AMS_Memory_destroy,(amem)); 353 PetscFunctionReturn(0); 354 } 355 356 #undef __FUNCT__ 357 #define __FUNCT__ "PetscOptionsAMSInput" 358 /* 359 PetscOptionsAMSInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the AMS 360 361 Bugs: 362 + All processes must traverse through the exact same set of option queries do to the call to PetscScanString() 363 . Internal strings have arbitrary length and string copies are not checked that they fit into string space 364 - Only works for PetscInt == int, PetscReal == double etc 365 366 367 */ 368 PetscErrorCode PetscOptionsAMSInput() 369 { 370 PetscErrorCode ierr; 371 PetscOptions next = PetscOptionsObject.next; 372 static int mancount = 0; 373 char options[16]; 374 AMS_Comm acomm = -1; 375 AMS_Memory amem = -1; 376 PetscBool changedmethod = PETSC_FALSE; 377 char manname[16]; 378 379 /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */ 380 ierr = PetscViewerAMSGetAMSComm(PETSC_VIEWER_AMS_(PETSC_COMM_WORLD),&acomm);CHKERRQ(ierr); 381 sprintf(options,"Options_%d",count++); 382 PetscStackCallAMS(AMS_Memory_create,(acomm,options,&amem)); 383 PetscStackCallAMS(AMS_Memory_take_access,(amem)); 384 385 PetscOptionsObject.pprefix = PetscOptionsObject.prefix; /* AMS will change this, so cannot pass prefix directly */ 386 387 PetscStackCallAMS(AMS_Memory_add_field,(amem,PetscOptionsObject.title,&PetscOptionsObject.pprefix,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF)); 388 /* PetscStackCallAMS(AMS_Memory_add_field(amem,"mansec",&PetscOptionsObject.pprefix,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF)); */ 389 PetscStackCallAMS(AMS_Memory_add_field,(amem,"ChangedMethod",&changedmethod,1,AMS_BOOLEAN,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF)); 390 391 while (next) { 392 PetscStackCallAMS(AMS_Memory_add_field,(amem,next->option,&next->set,1,AMS_INT,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF)); 393 ierr = PetscMalloc(sizeof(char*),&next->pman);CHKERRQ(ierr); 394 395 *(char**)next->pman = next->man; 396 sprintf(manname,"man_%d",mancount++); 397 PetscStackCallAMS(AMS_Memory_add_field,(amem,manname,next->pman,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF)); 398 399 switch (next->type) { 400 case OPTION_HEAD: 401 break; 402 case OPTION_INT_ARRAY: 403 PetscStackCallAMS(AMS_Memory_add_field,(amem,next->text,next->data,next->arraylength,AMS_INT,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF)); 404 break; 405 case OPTION_REAL_ARRAY: 406 PetscStackCallAMS(AMS_Memory_add_field,(amem,next->text,next->data,next->arraylength,AMS_DOUBLE,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF)); 407 break; 408 case OPTION_INT: 409 PetscStackCallAMS(AMS_Memory_add_field,(amem,next->text,next->data,1,AMS_INT,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF)); 410 break; 411 case OPTION_REAL: 412 PetscStackCallAMS(AMS_Memory_add_field,(amem,next->text,next->data,1,AMS_DOUBLE,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF)); 413 break; 414 case OPTION_LOGICAL: 415 PetscStackCallAMS(AMS_Memory_add_field,(amem,next->text,next->data,1,AMS_BOOLEAN,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF)); 416 break; 417 case OPTION_LOGICAL_ARRAY: 418 PetscStackCallAMS(AMS_Memory_add_field,(amem,next->text,next->data,next->arraylength,AMS_BOOLEAN,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF)); 419 break; 420 case OPTION_STRING: 421 PetscStackCallAMS(AMS_Memory_add_field,(amem,next->text,next->data,1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF)); 422 break; 423 case OPTION_STRING_ARRAY: 424 PetscStackCallAMS(AMS_Memory_add_field,(amem,next->text,next->data,next->arraylength,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF)); 425 break; 426 case OPTION_LIST: 427 {PetscInt ntext; 428 char ldefault[128]; 429 ierr = PetscStrcpy(ldefault,"DEFAULT:");CHKERRQ(ierr); 430 ierr = PetscStrcat(ldefault,next->text);CHKERRQ(ierr); 431 PetscStackCallAMS(AMS_Memory_add_field,(amem,ldefault,next->data,1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF)); 432 ierr = PetscFunctionListGet(next->flist,(const char***)&next->edata,&ntext);CHKERRQ(ierr); 433 PetscStackCallAMS(AMS_Memory_add_field,(amem,next->text,next->edata,ntext-1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF)); 434 break;} 435 case OPTION_ELIST: 436 {PetscInt ntext = next->nlist; 437 char ldefault[128]; 438 ierr = PetscStrcpy(ldefault,"DEFAULT:");CHKERRQ(ierr); 439 ierr = PetscStrcat(ldefault,next->text);CHKERRQ(ierr); 440 PetscStackCallAMS(AMS_Memory_add_field,(amem,ldefault,next->data,1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF)); 441 ierr = PetscMalloc((ntext+1)*sizeof(char**),&next->edata);CHKERRQ(ierr); 442 ierr = PetscMemcpy(next->edata,next->list,ntext*sizeof(char*));CHKERRQ(ierr); 443 PetscStackCallAMS(AMS_Memory_add_field,(amem,next->text,next->edata,ntext,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF)); 444 break;} 445 default: 446 break; 447 } 448 next = next->next; 449 } 450 451 PetscStackCallAMS(AMS_Memory_publish,(amem)); 452 PetscStackCallAMS(AMS_Memory_grant_access,(amem)); 453 /* wait until accessor has unlocked the memory */ 454 PetscStackCallAMS(AMS_Memory_lock,(amem,0)); 455 PetscStackCallAMS(AMS_Memory_take_access,(amem)); 456 457 /* reset counter to -2; this updates the screen with the new options for the selected method */ 458 if (changedmethod) PetscOptionsPublishCount = -2; 459 460 PetscStackCallAMS(AMS_Memory_grant_access,(amem)); 461 PetscStackCallAMS(AMS_Memory_destroy,(amem)); 462 PetscFunctionReturn(0); 463 } 464 #endif 465 466 #undef __FUNCT__ 467 #define __FUNCT__ "PetscOptionsEnd_Private" 468 PetscErrorCode PetscOptionsEnd_Private(void) 469 { 470 PetscErrorCode ierr; 471 PetscOptions last; 472 char option[256],value[1024],tmp[32]; 473 size_t j; 474 475 PetscFunctionBegin; 476 if (PetscOptionsObject.next) { 477 if (!PetscOptionsPublishCount) { 478 #if defined(PETSC_HAVE_AMS) 479 ierr = PetscOptionsAMSInput();CHKERRQ(ierr); 480 #else 481 ierr = PetscOptionsGetFromTextInput();CHKERRQ(ierr); 482 #endif 483 } 484 } 485 486 ierr = PetscFree(PetscOptionsObject.title);CHKERRQ(ierr); 487 ierr = PetscFree(PetscOptionsObject.prefix);CHKERRQ(ierr); 488 489 /* reset counter to -2; this updates the screen with the new options for the selected method */ 490 if (PetscOptionsObject.changedmethod) PetscOptionsPublishCount = -2; 491 /* reset alreadyprinted flag */ 492 PetscOptionsObject.alreadyprinted = PETSC_FALSE; 493 if (PetscOptionsObject.object) PetscOptionsObject.object->optionsprinted = PETSC_TRUE; 494 PetscOptionsObject.object = NULL; 495 496 while (PetscOptionsObject.next) { 497 if (PetscOptionsObject.next->set) { 498 if (PetscOptionsObject.prefix) { 499 ierr = PetscStrcpy(option,"-");CHKERRQ(ierr); 500 ierr = PetscStrcat(option,PetscOptionsObject.prefix);CHKERRQ(ierr); 501 ierr = PetscStrcat(option,PetscOptionsObject.next->option+1);CHKERRQ(ierr); 502 } else { 503 ierr = PetscStrcpy(option,PetscOptionsObject.next->option);CHKERRQ(ierr); 504 } 505 506 switch (PetscOptionsObject.next->type) { 507 case OPTION_HEAD: 508 break; 509 case OPTION_INT_ARRAY: 510 sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[0]); 511 for (j=1; j<PetscOptionsObject.next->arraylength; j++) { 512 sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[j]); 513 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 514 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 515 } 516 break; 517 case OPTION_INT: 518 sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject.next->data); 519 break; 520 case OPTION_REAL: 521 sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject.next->data); 522 break; 523 case OPTION_REAL_ARRAY: 524 sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[0]); 525 for (j=1; j<PetscOptionsObject.next->arraylength; j++) { 526 sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[j]); 527 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 528 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 529 } 530 break; 531 case OPTION_LOGICAL: 532 sprintf(value,"%d",*(int*)PetscOptionsObject.next->data); 533 break; 534 case OPTION_LOGICAL_ARRAY: 535 sprintf(value,"%d",(int)((PetscBool*)PetscOptionsObject.next->data)[0]); 536 for (j=1; j<PetscOptionsObject.next->arraylength; j++) { 537 sprintf(tmp,"%d",(int)((PetscBool*)PetscOptionsObject.next->data)[j]); 538 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 539 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 540 } 541 break; 542 case OPTION_LIST: 543 case OPTION_ELIST: 544 ierr = PetscStrcpy(value,*(char**)PetscOptionsObject.next->data);CHKERRQ(ierr); 545 break; 546 case OPTION_STRING: 547 ierr = PetscStrcpy(value,*(char**)PetscOptionsObject.next->data);CHKERRQ(ierr); 548 case OPTION_STRING_ARRAY: 549 sprintf(value,"%s",((char**)PetscOptionsObject.next->data)[0]); 550 for (j=1; j<PetscOptionsObject.next->arraylength; j++) { 551 sprintf(tmp,"%s",((char**)PetscOptionsObject.next->data)[j]); 552 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 553 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 554 } 555 break; 556 } 557 ierr = PetscOptionsSetValue(option,value);CHKERRQ(ierr); 558 } 559 ierr = PetscFree(PetscOptionsObject.next->text);CHKERRQ(ierr); 560 ierr = PetscFree(PetscOptionsObject.next->option);CHKERRQ(ierr); 561 ierr = PetscFree(PetscOptionsObject.next->man);CHKERRQ(ierr); 562 ierr = PetscFree(PetscOptionsObject.next->data);CHKERRQ(ierr); 563 ierr = PetscFree(PetscOptionsObject.next->edata);CHKERRQ(ierr); 564 565 last = PetscOptionsObject.next; 566 PetscOptionsObject.next = PetscOptionsObject.next->next; 567 ierr = PetscFree(last);CHKERRQ(ierr); 568 } 569 PetscOptionsObject.next = 0; 570 PetscFunctionReturn(0); 571 } 572 573 #undef __FUNCT__ 574 #define __FUNCT__ "PetscOptionsEnum" 575 /*@C 576 PetscOptionsEnum - Gets the enum value for a particular option in the database. 577 578 Logically Collective on the communicator passed in PetscOptionsBegin() 579 580 Input Parameters: 581 + opt - option name 582 . text - short string that describes the option 583 . man - manual page with additional information on option 584 . list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null 585 - defaultv - the default (current) value 586 587 Output Parameter: 588 + value - the value to return 589 - set - PETSC_TRUE if found, else PETSC_FALSE 590 591 Level: beginner 592 593 Concepts: options database 594 595 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 596 597 list is usually something like PCASMTypes or some other predefined list of enum names 598 599 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 600 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 601 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 602 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 603 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 604 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 605 PetscOptionsList(), PetscOptionsEList() 606 @*/ 607 PetscErrorCode PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum defaultv,PetscEnum *value,PetscBool *set) 608 { 609 PetscErrorCode ierr; 610 PetscInt ntext = 0; 611 PetscInt tval; 612 PetscBool tflg; 613 614 PetscFunctionBegin; 615 while (list[ntext++]) { 616 if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries"); 617 } 618 if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix"); 619 ntext -= 3; 620 ierr = PetscOptionsEList(opt,text,man,list,ntext,list[defaultv],&tval,&tflg);CHKERRQ(ierr); 621 /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */ 622 if (tflg) *value = (PetscEnum)tval; 623 if (set) *set = tflg; 624 PetscFunctionReturn(0); 625 } 626 627 /* -------------------------------------------------------------------------------------------------------------*/ 628 #undef __FUNCT__ 629 #define __FUNCT__ "PetscOptionsInt" 630 /*@C 631 PetscOptionsInt - Gets the integer value for a particular option in the database. 632 633 Logically Collective on the communicator passed in PetscOptionsBegin() 634 635 Input Parameters: 636 + opt - option name 637 . text - short string that describes the option 638 . man - manual page with additional information on option 639 - defaultv - the default (current) value 640 641 Output Parameter: 642 + value - the integer value to return 643 - flg - PETSC_TRUE if found, else PETSC_FALSE 644 645 Level: beginner 646 647 Concepts: options database^has int 648 649 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 650 651 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 652 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 653 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 654 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 655 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 656 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 657 PetscOptionsList(), PetscOptionsEList() 658 @*/ 659 PetscErrorCode PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt defaultv,PetscInt *value,PetscBool *set) 660 { 661 PetscErrorCode ierr; 662 PetscOptions amsopt; 663 664 PetscFunctionBegin; 665 if (!PetscOptionsPublishCount) { 666 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr); 667 ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr); 668 669 *(PetscInt*)amsopt->data = defaultv; 670 } 671 ierr = PetscOptionsGetInt(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 672 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 673 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%d>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr); 674 } 675 PetscFunctionReturn(0); 676 } 677 678 #undef __FUNCT__ 679 #define __FUNCT__ "PetscOptionsString" 680 /*@C 681 PetscOptionsString - Gets the string value for a particular option in the database. 682 683 Logically Collective on the communicator passed in PetscOptionsBegin() 684 685 Input Parameters: 686 + opt - option name 687 . text - short string that describes the option 688 . man - manual page with additional information on option 689 . defaultv - the default (current) value 690 - len - length of the result string including null terminator 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 Even if the user provided no string (for example -optionname -someotheroption) the flag is set to PETSC_TRUE (and the string is fulled with nulls). 703 704 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 705 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 706 PetscOptionsInt(), PetscOptionsReal(), PetscOptionsBool(), 707 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 708 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 709 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 710 PetscOptionsList(), PetscOptionsEList() 711 @*/ 712 PetscErrorCode PetscOptionsString(const char opt[],const char text[],const char man[],const char defaultv[],char value[],size_t len,PetscBool *set) 713 { 714 PetscErrorCode ierr; 715 PetscOptions amsopt; 716 717 PetscFunctionBegin; 718 if (!PetscOptionsPublishCount) { 719 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr); 720 ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr); 721 722 *(const char**)amsopt->data = defaultv; 723 } 724 ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr); 725 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 726 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr); 727 } 728 PetscFunctionReturn(0); 729 } 730 731 #undef __FUNCT__ 732 #define __FUNCT__ "PetscOptionsReal" 733 /*@C 734 PetscOptionsReal - Gets the PetscReal value for a particular option in the database. 735 736 Logically Collective on the communicator passed in PetscOptionsBegin() 737 738 Input Parameters: 739 + opt - option name 740 . text - short string that describes the option 741 . man - manual page with additional information on option 742 - defaultv - the default (current) value 743 744 Output Parameter: 745 + value - the value to return 746 - flg - PETSC_TRUE if found, else PETSC_FALSE 747 748 Level: beginner 749 750 Concepts: options database^has int 751 752 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 753 754 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 755 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 756 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 757 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 758 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 759 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 760 PetscOptionsList(), PetscOptionsEList() 761 @*/ 762 PetscErrorCode PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal defaultv,PetscReal *value,PetscBool *set) 763 { 764 PetscErrorCode ierr; 765 PetscOptions amsopt; 766 767 PetscFunctionBegin; 768 if (!PetscOptionsPublishCount) { 769 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr); 770 ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr); 771 772 *(PetscReal*)amsopt->data = defaultv; 773 } 774 ierr = PetscOptionsGetReal(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 775 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 776 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%G>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr); 777 } 778 PetscFunctionReturn(0); 779 } 780 781 #undef __FUNCT__ 782 #define __FUNCT__ "PetscOptionsScalar" 783 /*@C 784 PetscOptionsScalar - Gets the scalar value for a particular option in the database. 785 786 Logically Collective on the communicator passed in PetscOptionsBegin() 787 788 Input Parameters: 789 + opt - option name 790 . text - short string that describes the option 791 . man - manual page with additional information on option 792 - defaultv - the default (current) value 793 794 Output Parameter: 795 + value - the value to return 796 - flg - PETSC_TRUE if found, else PETSC_FALSE 797 798 Level: beginner 799 800 Concepts: options database^has int 801 802 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 803 804 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 805 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 806 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 807 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 808 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 809 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 810 PetscOptionsList(), PetscOptionsEList() 811 @*/ 812 PetscErrorCode PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar defaultv,PetscScalar *value,PetscBool *set) 813 { 814 PetscErrorCode ierr; 815 816 PetscFunctionBegin; 817 #if !defined(PETSC_USE_COMPLEX) 818 ierr = PetscOptionsReal(opt,text,man,defaultv,value,set);CHKERRQ(ierr); 819 #else 820 ierr = PetscOptionsGetScalar(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 821 #endif 822 PetscFunctionReturn(0); 823 } 824 825 #undef __FUNCT__ 826 #define __FUNCT__ "PetscOptionsName" 827 /*@C 828 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 829 its value is set to false. 830 831 Logically Collective on the communicator passed in PetscOptionsBegin() 832 833 Input Parameters: 834 + opt - option name 835 . text - short string that describes the option 836 - man - manual page with additional information on option 837 838 Output Parameter: 839 . flg - PETSC_TRUE if found, else PETSC_FALSE 840 841 Level: beginner 842 843 Concepts: options database^has int 844 845 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 846 847 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 848 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 849 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 850 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 851 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 852 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 853 PetscOptionsList(), PetscOptionsEList() 854 @*/ 855 PetscErrorCode PetscOptionsName(const char opt[],const char text[],const char man[],PetscBool *flg) 856 { 857 PetscErrorCode ierr; 858 PetscOptions amsopt; 859 860 PetscFunctionBegin; 861 if (!PetscOptionsPublishCount) { 862 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr); 863 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 864 865 *(PetscBool*)amsopt->data = PETSC_FALSE; 866 } 867 ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr); 868 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 869 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 870 } 871 PetscFunctionReturn(0); 872 } 873 874 #undef __FUNCT__ 875 #define __FUNCT__ "PetscOptionsList" 876 /*@C 877 PetscOptionsList - Puts a list of option values that a single one may be selected from 878 879 Logically Collective on the communicator passed in PetscOptionsBegin() 880 881 Input Parameters: 882 + opt - option name 883 . text - short string that describes the option 884 . man - manual page with additional information on option 885 . list - the possible choices 886 . defaultv - the default (current) value 887 - len - the length of the character array value 888 889 Output Parameter: 890 + value - the value to return 891 - set - PETSC_TRUE if found, else PETSC_FALSE 892 893 Level: intermediate 894 895 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 896 897 See PetscOptionsEList() for when the choices are given in a string array 898 899 To get a listing of all currently specified options, 900 see PetscOptionsView() or PetscOptionsGetAll() 901 902 Concepts: options database^list 903 904 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 905 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 906 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 907 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 908 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 909 PetscOptionsList(), PetscOptionsEList(), PetscOptionsEnum() 910 @*/ 911 PetscErrorCode PetscOptionsList(const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char defaultv[],char value[],size_t len,PetscBool *set) 912 { 913 PetscErrorCode ierr; 914 PetscOptions amsopt; 915 916 PetscFunctionBegin; 917 if (!PetscOptionsPublishCount) { 918 ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_LIST,&amsopt);CHKERRQ(ierr); 919 ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr); 920 921 *(const char**)amsopt->data = defaultv; 922 923 amsopt->flist = list; 924 } 925 ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr); 926 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 927 ierr = PetscFunctionListPrintTypes(PetscOptionsObject.comm,stdout,PetscOptionsObject.prefix,opt,ltext,man,list,defaultv);CHKERRQ(ierr);CHKERRQ(ierr); 928 } 929 PetscFunctionReturn(0); 930 } 931 932 #undef __FUNCT__ 933 #define __FUNCT__ "PetscOptionsEList" 934 /*@C 935 PetscOptionsEList - Puts a list of option values that a single one may be selected from 936 937 Logically Collective on the communicator passed in PetscOptionsBegin() 938 939 Input Parameters: 940 + opt - option name 941 . ltext - short string that describes the option 942 . man - manual page with additional information on option 943 . list - the possible choices 944 . ntext - number of choices 945 - defaultv - the default (current) value 946 947 Output Parameter: 948 + value - the index of the value to return 949 - set - PETSC_TRUE if found, else PETSC_FALSE 950 951 Level: intermediate 952 953 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 954 955 See PetscOptionsList() for when the choices are given in a PetscFunctionList() 956 957 Concepts: options database^list 958 959 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 960 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 961 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 962 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 963 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 964 PetscOptionsList(), PetscOptionsEnum() 965 @*/ 966 PetscErrorCode PetscOptionsEList(const char opt[],const char ltext[],const char man[],const char *const *list,PetscInt ntext,const char defaultv[],PetscInt *value,PetscBool *set) 967 { 968 PetscErrorCode ierr; 969 PetscInt i; 970 PetscOptions amsopt; 971 972 PetscFunctionBegin; 973 if (!PetscOptionsPublishCount) { 974 ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_ELIST,&amsopt);CHKERRQ(ierr); 975 ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr); 976 977 *(const char**)amsopt->data = defaultv; 978 979 amsopt->list = list; 980 amsopt->nlist = ntext; 981 } 982 ierr = PetscOptionsGetEList(PetscOptionsObject.prefix,opt,list,ntext,value,set);CHKERRQ(ierr); 983 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 984 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%s> (choose one of)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv);CHKERRQ(ierr); 985 for (i=0; i<ntext; i++) { 986 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s",list[i]);CHKERRQ(ierr); 987 } 988 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," (%s)\n",ManSection(man));CHKERRQ(ierr); 989 } 990 PetscFunctionReturn(0); 991 } 992 993 #undef __FUNCT__ 994 #define __FUNCT__ "PetscOptionsBoolGroupBegin" 995 /*@C 996 PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for 997 which at most a single value can be true. 998 999 Logically Collective on the communicator passed in PetscOptionsBegin() 1000 1001 Input Parameters: 1002 + opt - option name 1003 . text - short string that describes the option 1004 - man - manual page with additional information on option 1005 1006 Output Parameter: 1007 . flg - whether that option was set or not 1008 1009 Level: intermediate 1010 1011 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1012 1013 Must be followed by 0 or more PetscOptionsBoolGroup()s and PetscOptionsBoolGroupEnd() 1014 1015 Concepts: options database^logical group 1016 1017 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1018 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1019 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1020 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1021 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1022 PetscOptionsList(), PetscOptionsEList() 1023 @*/ 1024 PetscErrorCode PetscOptionsBoolGroupBegin(const char opt[],const char text[],const char man[],PetscBool *flg) 1025 { 1026 PetscErrorCode ierr; 1027 PetscOptions amsopt; 1028 1029 PetscFunctionBegin; 1030 if (!PetscOptionsPublishCount) { 1031 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr); 1032 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1033 1034 *(PetscBool*)amsopt->data = PETSC_FALSE; 1035 } 1036 *flg = PETSC_FALSE; 1037 ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,NULL);CHKERRQ(ierr); 1038 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1039 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," Pick at most one of -------------\n");CHKERRQ(ierr); 1040 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1041 } 1042 PetscFunctionReturn(0); 1043 } 1044 1045 #undef __FUNCT__ 1046 #define __FUNCT__ "PetscOptionsBoolGroup" 1047 /*@C 1048 PetscOptionsBoolGroup - One in a series of logical queries on the options database for 1049 which at most a single value can be true. 1050 1051 Logically Collective on the communicator passed in PetscOptionsBegin() 1052 1053 Input Parameters: 1054 + opt - option name 1055 . text - short string that describes the option 1056 - man - manual page with additional information on option 1057 1058 Output Parameter: 1059 . flg - PETSC_TRUE if found, else PETSC_FALSE 1060 1061 Level: intermediate 1062 1063 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1064 1065 Must follow a PetscOptionsBoolGroupBegin() and preceded a PetscOptionsBoolGroupEnd() 1066 1067 Concepts: options database^logical group 1068 1069 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1070 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1071 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1072 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1073 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1074 PetscOptionsList(), PetscOptionsEList() 1075 @*/ 1076 PetscErrorCode PetscOptionsBoolGroup(const char opt[],const char text[],const char man[],PetscBool *flg) 1077 { 1078 PetscErrorCode ierr; 1079 PetscOptions amsopt; 1080 1081 PetscFunctionBegin; 1082 if (!PetscOptionsPublishCount) { 1083 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr); 1084 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1085 1086 *(PetscBool*)amsopt->data = PETSC_FALSE; 1087 } 1088 *flg = PETSC_FALSE; 1089 ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,NULL);CHKERRQ(ierr); 1090 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1091 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1092 } 1093 PetscFunctionReturn(0); 1094 } 1095 1096 #undef __FUNCT__ 1097 #define __FUNCT__ "PetscOptionsBoolGroupEnd" 1098 /*@C 1099 PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for 1100 which at most a single value can be true. 1101 1102 Logically Collective on the communicator passed in PetscOptionsBegin() 1103 1104 Input Parameters: 1105 + opt - option name 1106 . text - short string that describes the option 1107 - man - manual page with additional information on option 1108 1109 Output Parameter: 1110 . flg - PETSC_TRUE if found, else PETSC_FALSE 1111 1112 Level: intermediate 1113 1114 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1115 1116 Must follow a PetscOptionsBoolGroupBegin() 1117 1118 Concepts: options database^logical group 1119 1120 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1121 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1122 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1123 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1124 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1125 PetscOptionsList(), PetscOptionsEList() 1126 @*/ 1127 PetscErrorCode PetscOptionsBoolGroupEnd(const char opt[],const char text[],const char man[],PetscBool *flg) 1128 { 1129 PetscErrorCode ierr; 1130 PetscOptions amsopt; 1131 1132 PetscFunctionBegin; 1133 if (!PetscOptionsPublishCount) { 1134 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr); 1135 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1136 1137 *(PetscBool*)amsopt->data = PETSC_FALSE; 1138 } 1139 *flg = PETSC_FALSE; 1140 ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,NULL);CHKERRQ(ierr); 1141 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1142 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1143 } 1144 PetscFunctionReturn(0); 1145 } 1146 1147 #undef __FUNCT__ 1148 #define __FUNCT__ "PetscOptionsBool" 1149 /*@C 1150 PetscOptionsBool - Determines if a particular option is in the database with a true or false 1151 1152 Logically Collective on the communicator passed in PetscOptionsBegin() 1153 1154 Input Parameters: 1155 + opt - option name 1156 . text - short string that describes the option 1157 - man - manual page with additional information on option 1158 1159 Output Parameter: 1160 . flg - PETSC_TRUE or PETSC_FALSE 1161 . set - PETSC_TRUE if found, else PETSC_FALSE 1162 1163 Level: beginner 1164 1165 Concepts: options database^logical 1166 1167 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1168 1169 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 1170 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 1171 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 1172 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1173 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1174 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1175 PetscOptionsList(), PetscOptionsEList() 1176 @*/ 1177 PetscErrorCode PetscOptionsBool(const char opt[],const char text[],const char man[],PetscBool deflt,PetscBool *flg,PetscBool *set) 1178 { 1179 PetscErrorCode ierr; 1180 PetscBool iset; 1181 PetscOptions amsopt; 1182 1183 PetscFunctionBegin; 1184 if (!PetscOptionsPublishCount) { 1185 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr); 1186 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1187 1188 *(PetscBool*)amsopt->data = deflt; 1189 } 1190 ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,&iset);CHKERRQ(ierr); 1191 if (!iset) { 1192 if (flg) *flg = deflt; 1193 } 1194 if (set) *set = iset; 1195 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1196 const char *v = PetscBools[deflt]; 1197 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: <%s> %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,v,text,ManSection(man));CHKERRQ(ierr); 1198 } 1199 PetscFunctionReturn(0); 1200 } 1201 1202 #undef __FUNCT__ 1203 #define __FUNCT__ "PetscOptionsRealArray" 1204 /*@C 1205 PetscOptionsRealArray - Gets an array of double values for a particular 1206 option in the database. The values must be separated with commas with 1207 no intervening spaces. 1208 1209 Logically Collective on the communicator passed in PetscOptionsBegin() 1210 1211 Input Parameters: 1212 + opt - the option one is seeking 1213 . text - short string describing option 1214 . man - manual page for option 1215 - nmax - maximum number of values 1216 1217 Output Parameter: 1218 + value - location to copy values 1219 . nmax - actual number of values found 1220 - set - PETSC_TRUE if found, else PETSC_FALSE 1221 1222 Level: beginner 1223 1224 Notes: 1225 The user should pass in an array of doubles 1226 1227 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1228 1229 Concepts: options database^array of strings 1230 1231 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1232 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1233 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1234 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1235 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1236 PetscOptionsList(), PetscOptionsEList() 1237 @*/ 1238 PetscErrorCode PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool *set) 1239 { 1240 PetscErrorCode ierr; 1241 PetscInt i; 1242 PetscOptions amsopt; 1243 1244 PetscFunctionBegin; 1245 if (!PetscOptionsPublishCount) { 1246 PetscReal *vals; 1247 1248 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr); 1249 ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr); 1250 vals = (PetscReal*)amsopt->data; 1251 for (i=0; i<*n; i++) vals[i] = value[i]; 1252 amsopt->arraylength = *n; 1253 } 1254 ierr = PetscOptionsGetRealArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr); 1255 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1256 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%G",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr); 1257 for (i=1; i<*n; i++) { 1258 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%G",value[i]);CHKERRQ(ierr); 1259 } 1260 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1261 } 1262 PetscFunctionReturn(0); 1263 } 1264 1265 1266 #undef __FUNCT__ 1267 #define __FUNCT__ "PetscOptionsIntArray" 1268 /*@C 1269 PetscOptionsIntArray - Gets an array of integers for a particular 1270 option in the database. 1271 1272 Logically Collective on the communicator passed in PetscOptionsBegin() 1273 1274 Input Parameters: 1275 + opt - the option one is seeking 1276 . text - short string describing option 1277 . man - manual page for option 1278 - n - maximum number of values 1279 1280 Output Parameter: 1281 + value - location to copy values 1282 . n - actual number of values found 1283 - set - PETSC_TRUE if found, else PETSC_FALSE 1284 1285 Level: beginner 1286 1287 Notes: 1288 The array can be passed as 1289 a comma seperated list: 0,1,2,3,4,5,6,7 1290 a range (start-end+1): 0-8 1291 a range with given increment (start-end+1:inc): 0-7:2 1292 a combination of values and ranges seperated by commas: 0,1-8,8-15:2 1293 1294 There must be no intervening spaces between the values. 1295 1296 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1297 1298 Concepts: options database^array of ints 1299 1300 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1301 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1302 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1303 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1304 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1305 PetscOptionsList(), PetscOptionsEList(), PetscOptionsRealArray() 1306 @*/ 1307 PetscErrorCode PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool *set) 1308 { 1309 PetscErrorCode ierr; 1310 PetscInt i; 1311 PetscOptions amsopt; 1312 1313 PetscFunctionBegin; 1314 if (!PetscOptionsPublishCount) { 1315 PetscInt *vals; 1316 1317 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr); 1318 ierr = PetscMalloc((*n)*sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr); 1319 vals = (PetscInt*)amsopt->data; 1320 for (i=0; i<*n; i++) vals[i] = value[i]; 1321 amsopt->arraylength = *n; 1322 } 1323 ierr = PetscOptionsGetIntArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr); 1324 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1325 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%d",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,value[0]);CHKERRQ(ierr); 1326 for (i=1; i<*n; i++) { 1327 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr); 1328 } 1329 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1330 } 1331 PetscFunctionReturn(0); 1332 } 1333 1334 #undef __FUNCT__ 1335 #define __FUNCT__ "PetscOptionsStringArray" 1336 /*@C 1337 PetscOptionsStringArray - Gets an array of string values for a particular 1338 option in the database. The values must be separated with commas with 1339 no intervening spaces. 1340 1341 Logically Collective on the communicator passed in PetscOptionsBegin() 1342 1343 Input Parameters: 1344 + opt - the option one is seeking 1345 . text - short string describing option 1346 . man - manual page for option 1347 - nmax - maximum number of strings 1348 1349 Output Parameter: 1350 + value - location to copy strings 1351 . nmax - actual number of strings found 1352 - set - PETSC_TRUE if found, else PETSC_FALSE 1353 1354 Level: beginner 1355 1356 Notes: 1357 The user should pass in an array of pointers to char, to hold all the 1358 strings returned by this function. 1359 1360 The user is responsible for deallocating the strings that are 1361 returned. The Fortran interface for this routine is not supported. 1362 1363 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1364 1365 Concepts: options database^array of strings 1366 1367 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1368 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1369 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1370 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1371 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1372 PetscOptionsList(), PetscOptionsEList() 1373 @*/ 1374 PetscErrorCode PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool *set) 1375 { 1376 PetscErrorCode ierr; 1377 PetscOptions amsopt; 1378 1379 PetscFunctionBegin; 1380 if (!PetscOptionsPublishCount) { 1381 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING_ARRAY,&amsopt);CHKERRQ(ierr); 1382 ierr = PetscMalloc((*nmax)*sizeof(char*),&amsopt->data);CHKERRQ(ierr); 1383 1384 amsopt->arraylength = *nmax; 1385 } 1386 ierr = PetscOptionsGetStringArray(PetscOptionsObject.prefix,opt,value,nmax,set);CHKERRQ(ierr); 1387 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1388 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1389 } 1390 PetscFunctionReturn(0); 1391 } 1392 1393 #undef __FUNCT__ 1394 #define __FUNCT__ "PetscOptionsBoolArray" 1395 /*@C 1396 PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular 1397 option in the database. The values must be separated with commas with 1398 no intervening spaces. 1399 1400 Logically Collective on the communicator passed in PetscOptionsBegin() 1401 1402 Input Parameters: 1403 + opt - the option one is seeking 1404 . text - short string describing option 1405 . man - manual page for option 1406 - nmax - maximum number of values 1407 1408 Output Parameter: 1409 + value - location to copy values 1410 . nmax - actual number of values found 1411 - set - PETSC_TRUE if found, else PETSC_FALSE 1412 1413 Level: beginner 1414 1415 Notes: 1416 The user should pass in an array of doubles 1417 1418 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1419 1420 Concepts: options database^array of strings 1421 1422 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1423 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1424 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1425 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1426 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1427 PetscOptionsList(), PetscOptionsEList() 1428 @*/ 1429 PetscErrorCode PetscOptionsBoolArray(const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set) 1430 { 1431 PetscErrorCode ierr; 1432 PetscInt i; 1433 PetscOptions amsopt; 1434 1435 PetscFunctionBegin; 1436 if (!PetscOptionsPublishCount) { 1437 PetscBool *vals; 1438 1439 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL_ARRAY,&amsopt);CHKERRQ(ierr); 1440 ierr = PetscMalloc((*n)*sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1441 vals = (PetscBool*)amsopt->data; 1442 for (i=0; i<*n; i++) vals[i] = value[i]; 1443 amsopt->arraylength = *n; 1444 } 1445 ierr = PetscOptionsGetBoolArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr); 1446 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1447 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%d",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,value[0]);CHKERRQ(ierr); 1448 for (i=1; i<*n; i++) { 1449 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr); 1450 } 1451 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1452 } 1453 PetscFunctionReturn(0); 1454 } 1455 1456 #undef __FUNCT__ 1457 #define __FUNCT__ "PetscOptionsViewer" 1458 /*@C 1459 PetscOptionsInt - Gets a viewer appropriate for the type indicated by the user 1460 1461 Logically Collective on the communicator passed in PetscOptionsBegin() 1462 1463 Input Parameters: 1464 + opt - option name 1465 . text - short string that describes the option 1466 - man - manual page with additional information on option 1467 1468 Output Parameter: 1469 + viewer - the viewer 1470 - set - PETSC_TRUE if found, else PETSC_FALSE 1471 1472 Level: beginner 1473 1474 Concepts: options database^has int 1475 1476 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1477 If no value is provided ascii:stdout is used 1478 $ ascii[:[filename][:format]] defaults to stdout - format can be one of info, info_detailed, or matlab, for example ascii::info prints just the info 1479 $ about the object to standard out 1480 $ binary[:filename] defaults to binaryoutput 1481 $ draw 1482 $ socket[:port] defaults to the standard output port 1483 1484 Use PetscRestoreViewerDestroy() after using the viewer, otherwise a memory leak will occur 1485 1486 .seealso: PetscOptionsGetViewer(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 1487 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 1488 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 1489 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1490 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1491 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1492 PetscOptionsList(), PetscOptionsEList() 1493 @*/ 1494 PetscErrorCode PetscOptionsViewer(const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool *set) 1495 { 1496 PetscErrorCode ierr; 1497 PetscOptions amsopt; 1498 1499 PetscFunctionBegin; 1500 if (!PetscOptionsPublishCount) { 1501 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr); 1502 ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr); 1503 1504 *(const char**)amsopt->data = ""; 1505 } 1506 ierr = PetscOptionsGetViewer(PetscOptionsObject.comm,PetscOptionsObject.prefix,opt,viewer,format,set);CHKERRQ(ierr); 1507 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1508 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,"",text,ManSection(man));CHKERRQ(ierr); 1509 } 1510 PetscFunctionReturn(0); 1511 } 1512 1513 1514 #undef __FUNCT__ 1515 #define __FUNCT__ "PetscOptionsHead" 1516 /*@C 1517 PetscOptionsHead - Puts a heading before listing any more published options. Used, for example, 1518 in KSPSetFromOptions_GMRES(). 1519 1520 Logically Collective on the communicator passed in PetscOptionsBegin() 1521 1522 Input Parameter: 1523 . head - the heading text 1524 1525 1526 Level: intermediate 1527 1528 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1529 1530 Can be followed by a call to PetscOptionsTail() in the same function. 1531 1532 Concepts: options database^subheading 1533 1534 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1535 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1536 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1537 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1538 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1539 PetscOptionsList(), PetscOptionsEList() 1540 @*/ 1541 PetscErrorCode PetscOptionsHead(const char head[]) 1542 { 1543 PetscErrorCode ierr; 1544 1545 PetscFunctionBegin; 1546 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1547 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s\n",head);CHKERRQ(ierr); 1548 } 1549 PetscFunctionReturn(0); 1550 } 1551 1552 1553 1554 1555 1556 1557