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