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