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