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 PetscBool bid; 174 PetscReal ir,*valr; 175 PetscInt *vald; 176 size_t i; 177 178 ierr = (*PetscPrintf)(PETSC_COMM_WORLD,"%s -------------------------------------------------\n",PetscOptionsObject.title);CHKERRQ(ierr); 179 while (next) { 180 switch (next->type) { 181 case OPTION_HEAD: 182 break; 183 case OPTION_INT_ARRAY: 184 ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",next->option+1);CHKERRQ(ierr); 185 vald = (PetscInt*) next->data; 186 for (i=0; i<next->arraylength; i++) { 187 ierr = PetscPrintf(PETSC_COMM_WORLD,"%d",vald[i]);CHKERRQ(ierr); 188 if (i < next->arraylength-1) { 189 ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr); 190 } 191 } 192 ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s) ",next->text,next->man);CHKERRQ(ierr); 193 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 194 if (str[0]) { 195 PetscToken token; 196 PetscInt n=0,nmax = next->arraylength,*dvalue = (PetscInt*)next->data,start,end; 197 size_t len; 198 char *value; 199 PetscBool foundrange; 200 201 next->set = PETSC_TRUE; 202 value = str; 203 ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 204 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 205 while (n < nmax) { 206 if (!value) break; 207 208 /* look for form d-D where d and D are integers */ 209 foundrange = PETSC_FALSE; 210 ierr = PetscStrlen(value,&len);CHKERRQ(ierr); 211 if (value[0] == '-') i=2; 212 else i=1; 213 for (;i<len; i++) { 214 if (value[i] == '-') { 215 if (i == len-1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry %s\n",n,value); 216 value[i] = 0; 217 ierr = PetscOptionsStringToInt(value,&start);CHKERRQ(ierr); 218 ierr = PetscOptionsStringToInt(value+i+1,&end);CHKERRQ(ierr); 219 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); 220 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); 221 for (; start<end; start++) { 222 *dvalue = start; dvalue++;n++; 223 } 224 foundrange = PETSC_TRUE; 225 break; 226 } 227 } 228 if (!foundrange) { 229 ierr = PetscOptionsStringToInt(value,dvalue);CHKERRQ(ierr); 230 dvalue++; 231 n++; 232 } 233 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 234 } 235 ierr = PetscTokenDestroy(&token);CHKERRQ(ierr); 236 } 237 break; 238 case OPTION_REAL_ARRAY: 239 ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",next->option+1);CHKERRQ(ierr); 240 valr = (PetscReal*) next->data; 241 for (i=0; i<next->arraylength; i++) { 242 ierr = PetscPrintf(PETSC_COMM_WORLD,"%g",valr[i]);CHKERRQ(ierr); 243 if (i < next->arraylength-1) { 244 ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr); 245 } 246 } 247 ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s) ",next->text,next->man);CHKERRQ(ierr); 248 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 249 if (str[0]) { 250 PetscToken token; 251 PetscInt n = 0,nmax = next->arraylength; 252 PetscReal *dvalue = (PetscReal*)next->data; 253 char *value; 254 255 next->set = PETSC_TRUE; 256 value = str; 257 ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 258 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 259 while (n < nmax) { 260 if (!value) break; 261 ierr = PetscOptionsStringToReal(value,dvalue);CHKERRQ(ierr); 262 dvalue++; 263 n++; 264 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 265 } 266 ierr = PetscTokenDestroy(&token);CHKERRQ(ierr); 267 } 268 break; 269 case OPTION_INT: 270 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); 271 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 272 if (str[0]) { 273 #if defined(PETSC_SIZEOF_LONG_LONG) 274 long long lid; 275 sscanf(str,"%lld",&lid); 276 if (lid > PETSC_MAX_INT || lid < PETSC_MIN_INT) SETERRQ3(PETSC_COMM_WORLD,PETSC_ERR_ARG_OUTOFRANGE,"Argument: -%s%s %lld",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",next->option+1,lid); 277 #else 278 long lid; 279 sscanf(str,"%ld",&lid); 280 if (lid > PETSC_MAX_INT || lid < PETSC_MIN_INT) SETERRQ3(PETSC_COMM_WORLD,PETSC_ERR_ARG_OUTOFRANGE,"Argument: -%s%s %ld",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",next->option+1,lid); 281 #endif 282 283 next->set = PETSC_TRUE; 284 *((PetscInt*)next->data) = (PetscInt)lid; 285 } 286 break; 287 case OPTION_REAL: 288 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); 289 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 290 if (str[0]) { 291 #if defined(PETSC_USE_REAL_SINGLE) 292 sscanf(str,"%e",&ir); 293 #elif defined(PETSC_USE_REAL_DOUBLE) 294 sscanf(str,"%le",&ir); 295 #elif defined(PETSC_USE_REAL___FLOAT128) 296 ir = strtoflt128(str,0); 297 #else 298 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Unknown scalar type"); 299 #endif 300 next->set = PETSC_TRUE; 301 *((PetscReal*)next->data) = ir; 302 } 303 break; 304 case OPTION_BOOL: 305 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); 306 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 307 if (str[0]) { 308 ierr = PetscOptionsStringToBool(str,&bid);CHKERRQ(ierr); 309 next->set = PETSC_TRUE; 310 *((PetscBool*)next->data) = bid; 311 } 312 break; 313 case OPTION_STRING: 314 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); 315 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 316 if (str[0]) { 317 next->set = PETSC_TRUE; 318 next->data = (void*)strdup(str); 319 } 320 break; 321 case OPTION_FLIST: 322 ierr = PetscFunctionListPrintTypes(PETSC_COMM_WORLD,stdout,PetscOptionsObject.prefix,next->option,next->text,next->man,next->flist,(char*)next->data);CHKERRQ(ierr); 323 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 324 if (str[0]) { 325 PetscOptionsObject.changedmethod = PETSC_TRUE; 326 next->set = PETSC_TRUE; 327 next->data = (void*)strdup(str); 328 } 329 break; 330 default: 331 break; 332 } 333 next = next->next; 334 } 335 PetscFunctionReturn(0); 336 } 337 338 #if defined(PETSC_HAVE_SAWS) 339 #include <petscviewersaws.h> 340 341 static int count = 0; 342 343 #undef __FUNCT__ 344 #define __FUNCT__ "PetscOptionsSAWsDestroy" 345 PetscErrorCode PetscOptionsSAWsDestroy(void) 346 { 347 PetscFunctionBegin; 348 PetscFunctionReturn(0); 349 } 350 351 #undef __FUNCT__ 352 #define __FUNCT__ "PetscOptionsSAWsInput" 353 /* 354 PetscOptionsSAWsInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the SAWs 355 356 Bugs: 357 + All processes must traverse through the exact same set of option queries do to the call to PetscScanString() 358 . Internal strings have arbitrary length and string copies are not checked that they fit into string space 359 - Only works for PetscInt == int, PetscReal == double etc 360 361 362 */ 363 PetscErrorCode PetscOptionsSAWsInput() 364 { 365 PetscErrorCode ierr; 366 PetscOptions next = PetscOptionsObject.next; 367 static int mancount = 0; 368 char options[16]; 369 PetscBool changedmethod = PETSC_FALSE; 370 char manname[16],textname[16]; 371 char dir[1024]; 372 373 /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */ 374 sprintf(options,"Options_%d",count++); 375 376 PetscOptionsObject.pprefix = PetscOptionsObject.prefix; /* SAWs will change this, so cannot pass prefix directly */ 377 378 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s","_title");CHKERRQ(ierr); 379 PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject.title,1,SAWs_READ,SAWs_STRING)); 380 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s","prefix");CHKERRQ(ierr); 381 PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject.pprefix,1,SAWs_READ,SAWs_STRING)); 382 PetscStackCallSAWs(SAWs_Register,("/PETSc/Options/ChangedMethod",&changedmethod,1,SAWs_WRITE,SAWs_BOOLEAN)); 383 384 while (next) { 385 sprintf(manname,"_man_%d",mancount); 386 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",manname);CHKERRQ(ierr); 387 PetscStackCallSAWs(SAWs_Register,(dir,&next->man,1,SAWs_READ,SAWs_STRING)); 388 sprintf(textname,"_text_%d",mancount++); 389 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",textname);CHKERRQ(ierr); 390 PetscStackCallSAWs(SAWs_Register,(dir,&next->text,1,SAWs_READ,SAWs_STRING)); 391 392 switch (next->type) { 393 case OPTION_HEAD: 394 break; 395 case OPTION_INT_ARRAY: 396 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 397 PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_INT)); 398 break; 399 case OPTION_REAL_ARRAY: 400 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 401 PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_DOUBLE)); 402 break; 403 case OPTION_INT: 404 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 405 PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_INT)); 406 break; 407 case OPTION_REAL: 408 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 409 PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_DOUBLE)); 410 break; 411 case OPTION_BOOL: 412 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 413 PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_BOOLEAN)); 414 break; 415 case OPTION_BOOL_ARRAY: 416 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 417 PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_BOOLEAN)); 418 break; 419 case OPTION_STRING: 420 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 421 PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING)); 422 break; 423 case OPTION_STRING_ARRAY: 424 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 425 PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_STRING)); 426 break; 427 case OPTION_FLIST: 428 { 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 PetscStackCallSAWs(SAWs_Set_Legal_Variable_Values,(dir,ntext,next->edata)); 434 } 435 break; 436 case OPTION_ELIST: 437 { 438 PetscInt ntext = next->nlist; 439 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 440 PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING)); 441 ierr = PetscMalloc((ntext+1)*sizeof(char*),&next->edata);CHKERRQ(ierr); 442 ierr = PetscMemcpy(next->edata,next->list,ntext*sizeof(char*));CHKERRQ(ierr); 443 PetscStackCallSAWs(SAWs_Set_Legal_Variable_Values,(dir,ntext,next->edata)); 444 } 445 break; 446 default: 447 break; 448 } 449 next = next->next; 450 } 451 452 /* wait until accessor has unlocked the memory */ 453 ierr = PetscSAWsBlock();CHKERRQ(ierr); 454 455 /* determine if any values have been set in GUI */ 456 next = PetscOptionsObject.next; 457 while (next) { 458 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 459 PetscStackCallSAWs(SAWs_Selected,(dir,&next->set)); 460 next = next->next; 461 } 462 463 /* reset counter to -2; this updates the screen with the new options for the selected method */ 464 if (changedmethod) PetscOptionsPublishCount = -2; 465 466 PetscStackCallSAWs(SAWs_Delete,("/PETSc/Options")); 467 PetscFunctionReturn(0); 468 } 469 #endif 470 471 #undef __FUNCT__ 472 #define __FUNCT__ "PetscOptionsEnd_Private" 473 PetscErrorCode PetscOptionsEnd_Private(void) 474 { 475 PetscErrorCode ierr; 476 PetscOptions last; 477 char option[256],value[1024],tmp[32]; 478 size_t j; 479 480 PetscFunctionBegin; 481 if (PetscOptionsObject.next) { 482 if (!PetscOptionsPublishCount) { 483 #if defined(PETSC_HAVE_SAWS) 484 ierr = PetscOptionsSAWsInput();CHKERRQ(ierr); 485 #else 486 ierr = PetscOptionsGetFromTextInput();CHKERRQ(ierr); 487 #endif 488 } 489 } 490 491 ierr = PetscFree(PetscOptionsObject.title);CHKERRQ(ierr); 492 ierr = PetscFree(PetscOptionsObject.prefix);CHKERRQ(ierr); 493 494 /* reset counter to -2; this updates the screen with the new options for the selected method */ 495 if (PetscOptionsObject.changedmethod) PetscOptionsPublishCount = -2; 496 /* reset alreadyprinted flag */ 497 PetscOptionsObject.alreadyprinted = PETSC_FALSE; 498 if (PetscOptionsObject.object) PetscOptionsObject.object->optionsprinted = PETSC_TRUE; 499 PetscOptionsObject.object = NULL; 500 501 while (PetscOptionsObject.next) { 502 if (PetscOptionsObject.next->set) { 503 if (PetscOptionsObject.prefix) { 504 ierr = PetscStrcpy(option,"-");CHKERRQ(ierr); 505 ierr = PetscStrcat(option,PetscOptionsObject.prefix);CHKERRQ(ierr); 506 ierr = PetscStrcat(option,PetscOptionsObject.next->option+1);CHKERRQ(ierr); 507 } else { 508 ierr = PetscStrcpy(option,PetscOptionsObject.next->option);CHKERRQ(ierr); 509 } 510 511 switch (PetscOptionsObject.next->type) { 512 case OPTION_HEAD: 513 break; 514 case OPTION_INT_ARRAY: 515 sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[0]); 516 for (j=1; j<PetscOptionsObject.next->arraylength; j++) { 517 sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[j]); 518 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 519 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 520 } 521 break; 522 case OPTION_INT: 523 sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject.next->data); 524 break; 525 case OPTION_REAL: 526 sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject.next->data); 527 break; 528 case OPTION_REAL_ARRAY: 529 sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[0]); 530 for (j=1; j<PetscOptionsObject.next->arraylength; j++) { 531 sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[j]); 532 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 533 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 534 } 535 break; 536 case OPTION_BOOL: 537 sprintf(value,"%d",*(int*)PetscOptionsObject.next->data); 538 break; 539 case OPTION_BOOL_ARRAY: 540 sprintf(value,"%d",(int)((PetscBool*)PetscOptionsObject.next->data)[0]); 541 for (j=1; j<PetscOptionsObject.next->arraylength; j++) { 542 sprintf(tmp,"%d",(int)((PetscBool*)PetscOptionsObject.next->data)[j]); 543 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 544 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 545 } 546 break; 547 case OPTION_FLIST: 548 case OPTION_ELIST: 549 ierr = PetscStrcpy(value,(char*)PetscOptionsObject.next->data);CHKERRQ(ierr); 550 break; 551 case OPTION_STRING: 552 ierr = PetscStrcpy(value,(char*)PetscOptionsObject.next->data);CHKERRQ(ierr); 553 break; 554 case OPTION_STRING_ARRAY: 555 sprintf(value,"%s",((char**)PetscOptionsObject.next->data)[0]); 556 for (j=1; j<PetscOptionsObject.next->arraylength; j++) { 557 sprintf(tmp,"%s",((char**)PetscOptionsObject.next->data)[j]); 558 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 559 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 560 } 561 break; 562 } 563 ierr = PetscOptionsSetValue(option,value);CHKERRQ(ierr); 564 } 565 ierr = PetscFree(PetscOptionsObject.next->text);CHKERRQ(ierr); 566 ierr = PetscFree(PetscOptionsObject.next->option);CHKERRQ(ierr); 567 ierr = PetscFree(PetscOptionsObject.next->man);CHKERRQ(ierr); 568 ierr = PetscFree(PetscOptionsObject.next->edata);CHKERRQ(ierr); 569 570 if ((PetscOptionsObject.next->type == OPTION_STRING) || (PetscOptionsObject.next->type == OPTION_FLIST) || (PetscOptionsObject.next->type == OPTION_ELIST)){ 571 free(PetscOptionsObject.next->data); 572 } else { 573 ierr = PetscFree(PetscOptionsObject.next->data);CHKERRQ(ierr); 574 } 575 576 last = PetscOptionsObject.next; 577 PetscOptionsObject.next = PetscOptionsObject.next->next; 578 ierr = PetscFree(last);CHKERRQ(ierr); 579 } 580 PetscOptionsObject.next = 0; 581 PetscFunctionReturn(0); 582 } 583 584 #undef __FUNCT__ 585 #define __FUNCT__ "PetscOptionsEnum" 586 /*@C 587 PetscOptionsEnum - Gets the enum value for a particular option in the database. 588 589 Logically Collective on the communicator passed in PetscOptionsBegin() 590 591 Input Parameters: 592 + opt - option name 593 . text - short string that describes the option 594 . man - manual page with additional information on option 595 . list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null 596 - defaultv - the default (current) value 597 598 Output Parameter: 599 + value - the value to return 600 - set - PETSC_TRUE if found, else PETSC_FALSE 601 602 Level: beginner 603 604 Concepts: options database 605 606 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 607 608 list is usually something like PCASMTypes or some other predefined list of enum names 609 610 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 611 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 612 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 613 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 614 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 615 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 616 PetscOptionsFList(), PetscOptionsEList() 617 @*/ 618 PetscErrorCode PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum defaultv,PetscEnum *value,PetscBool *set) 619 { 620 PetscErrorCode ierr; 621 PetscInt ntext = 0; 622 PetscInt tval; 623 PetscBool tflg; 624 625 PetscFunctionBegin; 626 while (list[ntext++]) { 627 if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries"); 628 } 629 if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix"); 630 ntext -= 3; 631 ierr = PetscOptionsEList(opt,text,man,list,ntext,list[defaultv],&tval,&tflg);CHKERRQ(ierr); 632 /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */ 633 if (tflg) *value = (PetscEnum)tval; 634 if (set) *set = tflg; 635 PetscFunctionReturn(0); 636 } 637 638 /* -------------------------------------------------------------------------------------------------------------*/ 639 #undef __FUNCT__ 640 #define __FUNCT__ "PetscOptionsInt" 641 /*@C 642 PetscOptionsInt - Gets the integer value for a particular option in the database. 643 644 Logically Collective on the communicator passed in PetscOptionsBegin() 645 646 Input Parameters: 647 + opt - option name 648 . text - short string that describes the option 649 . man - manual page with additional information on option 650 - defaultv - the default (current) value 651 652 Output Parameter: 653 + value - the integer value to return 654 - flg - PETSC_TRUE if found, else PETSC_FALSE 655 656 Level: beginner 657 658 Concepts: options database^has int 659 660 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 661 662 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 663 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 664 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 665 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 666 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 667 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 668 PetscOptionsFList(), PetscOptionsEList() 669 @*/ 670 PetscErrorCode PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt defaultv,PetscInt *value,PetscBool *set) 671 { 672 PetscErrorCode ierr; 673 PetscOptions amsopt; 674 675 PetscFunctionBegin; 676 if (!PetscOptionsPublishCount) { 677 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr); 678 ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr); 679 680 *(PetscInt*)amsopt->data = defaultv; 681 } 682 ierr = PetscOptionsGetInt(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 683 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 684 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%d>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr); 685 } 686 PetscFunctionReturn(0); 687 } 688 689 #undef __FUNCT__ 690 #define __FUNCT__ "PetscOptionsString" 691 /*@C 692 PetscOptionsString - Gets the string value for a particular option in the database. 693 694 Logically Collective on the communicator passed in PetscOptionsBegin() 695 696 Input Parameters: 697 + opt - option name 698 . text - short string that describes the option 699 . man - manual page with additional information on option 700 . defaultv - the default (current) value 701 - len - length of the result string including null terminator 702 703 Output Parameter: 704 + value - the value to return 705 - flg - PETSC_TRUE if found, else PETSC_FALSE 706 707 Level: beginner 708 709 Concepts: options database^has int 710 711 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 712 713 Even if the user provided no string (for example -optionname -someotheroption) the flag is set to PETSC_TRUE (and the string is fulled with nulls). 714 715 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 716 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 717 PetscOptionsInt(), PetscOptionsReal(), PetscOptionsBool(), 718 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 719 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 720 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 721 PetscOptionsFList(), PetscOptionsEList() 722 @*/ 723 PetscErrorCode PetscOptionsString(const char opt[],const char text[],const char man[],const char defaultv[],char value[],size_t len,PetscBool *set) 724 { 725 PetscErrorCode ierr; 726 PetscOptions amsopt; 727 728 PetscFunctionBegin; 729 if (!PetscOptionsPublishCount) { 730 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr); 731 amsopt->data = (void*)strdup(defaultv ? defaultv : ""); 732 } 733 ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr); 734 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 735 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr); 736 } 737 PetscFunctionReturn(0); 738 } 739 740 #undef __FUNCT__ 741 #define __FUNCT__ "PetscOptionsReal" 742 /*@C 743 PetscOptionsReal - Gets the PetscReal value for a particular option in the database. 744 745 Logically Collective on the communicator passed in PetscOptionsBegin() 746 747 Input Parameters: 748 + opt - option name 749 . text - short string that describes the option 750 . man - manual page with additional information on option 751 - defaultv - the default (current) value 752 753 Output Parameter: 754 + value - the value to return 755 - flg - PETSC_TRUE if found, else PETSC_FALSE 756 757 Level: beginner 758 759 Concepts: options database^has int 760 761 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 762 763 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 764 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 765 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 766 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 767 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 768 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 769 PetscOptionsFList(), PetscOptionsEList() 770 @*/ 771 PetscErrorCode PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal defaultv,PetscReal *value,PetscBool *set) 772 { 773 PetscErrorCode ierr; 774 PetscOptions amsopt; 775 776 PetscFunctionBegin; 777 if (!PetscOptionsPublishCount) { 778 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr); 779 ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr); 780 781 *(PetscReal*)amsopt->data = defaultv; 782 } 783 ierr = PetscOptionsGetReal(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 784 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 785 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%G>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr); 786 } 787 PetscFunctionReturn(0); 788 } 789 790 #undef __FUNCT__ 791 #define __FUNCT__ "PetscOptionsScalar" 792 /*@C 793 PetscOptionsScalar - Gets the scalar value for a particular option in the database. 794 795 Logically Collective on the communicator passed in PetscOptionsBegin() 796 797 Input Parameters: 798 + opt - option name 799 . text - short string that describes the option 800 . man - manual page with additional information on option 801 - defaultv - the default (current) value 802 803 Output Parameter: 804 + value - the value to return 805 - flg - PETSC_TRUE if found, else PETSC_FALSE 806 807 Level: beginner 808 809 Concepts: options database^has int 810 811 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 812 813 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 814 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 815 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 816 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 817 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 818 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 819 PetscOptionsFList(), PetscOptionsEList() 820 @*/ 821 PetscErrorCode PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar defaultv,PetscScalar *value,PetscBool *set) 822 { 823 PetscErrorCode ierr; 824 825 PetscFunctionBegin; 826 #if !defined(PETSC_USE_COMPLEX) 827 ierr = PetscOptionsReal(opt,text,man,defaultv,value,set);CHKERRQ(ierr); 828 #else 829 ierr = PetscOptionsGetScalar(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 830 #endif 831 PetscFunctionReturn(0); 832 } 833 834 #undef __FUNCT__ 835 #define __FUNCT__ "PetscOptionsName" 836 /*@C 837 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 838 its value is set to false. 839 840 Logically Collective on the communicator passed in PetscOptionsBegin() 841 842 Input Parameters: 843 + opt - option name 844 . text - short string that describes the option 845 - man - manual page with additional information on option 846 847 Output Parameter: 848 . flg - PETSC_TRUE if found, else PETSC_FALSE 849 850 Level: beginner 851 852 Concepts: options database^has int 853 854 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 855 856 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 857 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 858 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 859 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 860 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 861 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 862 PetscOptionsFList(), PetscOptionsEList() 863 @*/ 864 PetscErrorCode PetscOptionsName(const char opt[],const char text[],const char man[],PetscBool *flg) 865 { 866 PetscErrorCode ierr; 867 PetscOptions amsopt; 868 869 PetscFunctionBegin; 870 if (!PetscOptionsPublishCount) { 871 ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 872 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 873 874 *(PetscBool*)amsopt->data = PETSC_FALSE; 875 } 876 ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr); 877 if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 878 ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 879 } 880 PetscFunctionReturn(0); 881 } 882 883 #undef __FUNCT__ 884 #define __FUNCT__ "PetscOptionsFList" 885 /*@C 886 PetscOptionsFList - Puts a list of option values that a single one may be selected from 887 888 Logically Collective on the communicator passed in PetscOptionsBegin() 889 890 Input Parameters: 891 + opt - option name 892 . text - short string that describes the option 893 . man - manual page with additional information on option 894 . list - the possible choices 895 . defaultv - the default (current) value 896 - len - the length of the character array value 897 898 Output Parameter: 899 + value - the value to return 900 - set - PETSC_TRUE if found, else PETSC_FALSE 901 902 Level: intermediate 903 904 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 905 906 See PetscOptionsEList() for when the choices are given in a string array 907 908 To get a listing of all currently specified options, 909 see PetscOptionsView() or PetscOptionsGetAll() 910 911 Developer Note: This cannot check for invalid selection because of things like MATAIJ that are not included in the list 912 913 Concepts: options database^list 914 915 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 916 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 917 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 918 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 919 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 920 PetscOptionsFList(), PetscOptionsEList(), PetscOptionsEnum() 921 @*/ 922 PetscErrorCode PetscOptionsFList(const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char defaultv[],char value[],size_t len,PetscBool *set) 923 { 924 PetscErrorCode ierr; 925 PetscOptions amsopt; 926 927 PetscFunctionBegin; 928 if (!PetscOptionsPublishCount) { 929 ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_FLIST,&amsopt);CHKERRQ(ierr); 930 amsopt->data = (void*)strdup(defaultv ? defaultv : ""); 931 amsopt->flist = list; 932 } 933 ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr); 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 (one of these must be selected, anything else is invalid) 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 PetscOptionsFList() 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 PetscOptionsFList(), 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 PetscOptionsFList(), 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 PetscOptionsFList(), 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 PetscOptionsFList(), 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 PetscOptionsFList(), 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 PetscOptionsFList(), 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 PetscOptionsFList(), 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 PetscOptionsFList(), 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 PetscOptionsFList(), 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 PetscOptionsFList(), 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 PetscOptionsFList(), 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