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