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