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