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