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