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