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