1 2 3 /* 4 Implements the higher-level options database querying methods. These are self-documenting and can attach at runtime to 5 GUI code to display the options and get values from the users. 6 7 */ 8 9 #include <petsc/private/petscimpl.h> /*I "petscsys.h" I*/ 10 #include <petscviewer.h> 11 12 #define ManSection(str) ((str) ? (str) : "None") 13 14 /* 15 Keep a linked list of options that have been posted and we are waiting for 16 user selection. See the manual page for PetscOptionsBegin() 17 18 Eventually we'll attach this beast to a MPI_Comm 19 */ 20 21 22 /* 23 Handles setting up the data structure in a call to PetscOptionsBegin() 24 */ 25 PetscErrorCode PetscOptionsBegin_Private(PetscOptionItems *PetscOptionsObject,MPI_Comm comm,const char prefix[],const char title[],const char mansec[]) 26 { 27 PetscErrorCode ierr; 28 29 PetscFunctionBegin; 30 if (!PetscOptionsObject->alreadyprinted) { 31 if (!PetscOptionsHelpPrintedSingleton) { 32 ierr = PetscOptionsHelpPrintedCreate(&PetscOptionsHelpPrintedSingleton);CHKERRQ(ierr); 33 } 34 ierr = PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrintedSingleton,prefix,title,&PetscOptionsObject->alreadyprinted);CHKERRQ(ierr); 35 } 36 PetscOptionsObject->next = 0; 37 PetscOptionsObject->comm = comm; 38 PetscOptionsObject->changedmethod = PETSC_FALSE; 39 40 ierr = PetscStrallocpy(prefix,&PetscOptionsObject->prefix);CHKERRQ(ierr); 41 ierr = PetscStrallocpy(title,&PetscOptionsObject->title);CHKERRQ(ierr); 42 43 ierr = PetscOptionsHasName(PetscOptionsObject->options,NULL,"-help",&PetscOptionsObject->printhelp);CHKERRQ(ierr); 44 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1) { 45 if (!PetscOptionsObject->alreadyprinted) { 46 ierr = (*PetscHelpPrintf)(comm,"%s -------------------------------------------------\n",title);CHKERRQ(ierr); 47 } 48 } 49 PetscFunctionReturn(0); 50 } 51 52 /* 53 Handles setting up the data structure in a call to PetscObjectOptionsBegin() 54 */ 55 PetscErrorCode PetscObjectOptionsBegin_Private(PetscOptionItems *PetscOptionsObject,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(PetscOptionsObject,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 static int PetscOptionItemCreate_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscOptionType t,PetscOptionItem *amsopt) 80 { 81 int ierr; 82 PetscOptionItem next; 83 PetscBool valid; 84 85 PetscFunctionBegin; 86 ierr = PetscOptionsValidKey(opt,&valid);CHKERRQ(ierr); 87 if (!valid) SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_ARG_INCOMP,"The option '%s' is not a valid key",opt); 88 89 ierr = PetscNew(amsopt);CHKERRQ(ierr); 90 (*amsopt)->next = 0; 91 (*amsopt)->set = PETSC_FALSE; 92 (*amsopt)->type = t; 93 (*amsopt)->data = 0; 94 95 ierr = PetscStrallocpy(text,&(*amsopt)->text);CHKERRQ(ierr); 96 ierr = PetscStrallocpy(opt,&(*amsopt)->option);CHKERRQ(ierr); 97 ierr = PetscStrallocpy(man,&(*amsopt)->man);CHKERRQ(ierr); 98 99 if (!PetscOptionsObject->next) PetscOptionsObject->next = *amsopt; 100 else { 101 next = PetscOptionsObject->next; 102 while (next->next) next = next->next; 103 next->next = *amsopt; 104 } 105 PetscFunctionReturn(0); 106 } 107 108 /* 109 PetscScanString - Gets user input via stdin from process and broadcasts to all processes 110 111 Collective on MPI_Comm 112 113 Input Parameters: 114 + commm - communicator for the broadcast, must be PETSC_COMM_WORLD 115 . n - length of the string, must be the same on all processes 116 - str - location to store input 117 118 Bugs: 119 . Assumes process 0 of the given communicator has access to stdin 120 121 */ 122 static PetscErrorCode PetscScanString(MPI_Comm comm,size_t n,char str[]) 123 { 124 size_t i; 125 char c; 126 PetscMPIInt rank,nm; 127 PetscErrorCode ierr; 128 129 PetscFunctionBegin; 130 ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); 131 if (!rank) { 132 c = (char) getchar(); 133 i = 0; 134 while (c != '\n' && i < n-1) { 135 str[i++] = c; 136 c = (char)getchar(); 137 } 138 str[i] = 0; 139 } 140 ierr = PetscMPIIntCast(n,&nm);CHKERRQ(ierr); 141 ierr = MPI_Bcast(str,nm,MPI_CHAR,0,comm);CHKERRQ(ierr); 142 PetscFunctionReturn(0); 143 } 144 145 /* 146 This is needed because certain strings may be freed by SAWs, hence we cannot use PetscStrallocpy() 147 */ 148 static PetscErrorCode PetscStrdup(const char s[],char *t[]) 149 { 150 PetscErrorCode ierr; 151 size_t len; 152 char *tmp = 0; 153 154 PetscFunctionBegin; 155 if (s) { 156 ierr = PetscStrlen(s,&len);CHKERRQ(ierr); 157 tmp = (char*) malloc((len+1)*sizeof(char)); 158 if (!tmp) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_MEM,"No memory to duplicate string"); 159 ierr = PetscStrcpy(tmp,s);CHKERRQ(ierr); 160 } 161 *t = tmp; 162 PetscFunctionReturn(0); 163 } 164 165 166 /* 167 PetscOptionsGetFromTextInput - Presents all the PETSc Options processed by the program so the user may change them at runtime 168 169 Notes: 170 this isn't really practical, it is just to demonstrate the principle 171 172 A carriage return indicates no change from the default; but this like -ksp_monitor <stdout> the default is actually not stdout the default 173 is to do nothing so to get it to use stdout you need to type stdout. This is kind of bug? 174 175 Bugs: 176 + All processes must traverse through the exact same set of option queries due to the call to PetscScanString() 177 . Internal strings have arbitrary length and string copies are not checked that they fit into string space 178 - Only works for PetscInt == int, PetscReal == double etc 179 180 Developer Notes: 181 Normally the GUI that presents the options the user and retrieves the values would be running in a different 182 address space and communicating with the PETSc program 183 184 */ 185 PetscErrorCode PetscOptionsGetFromTextInput(PetscOptionItems *PetscOptionsObject) 186 { 187 PetscErrorCode ierr; 188 PetscOptionItem next = PetscOptionsObject->next; 189 char str[512]; 190 PetscBool bid; 191 PetscReal ir,*valr; 192 PetscInt *vald; 193 size_t i; 194 195 PetscFunctionBegin; 196 ierr = (*PetscPrintf)(PETSC_COMM_WORLD,"%s -------------------------------------------------\n",PetscOptionsObject->title);CHKERRQ(ierr); 197 while (next) { 198 switch (next->type) { 199 case OPTION_HEAD: 200 break; 201 case OPTION_INT_ARRAY: 202 ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1);CHKERRQ(ierr); 203 vald = (PetscInt*) next->data; 204 for (i=0; i<next->arraylength; i++) { 205 ierr = PetscPrintf(PETSC_COMM_WORLD,"%d",vald[i]);CHKERRQ(ierr); 206 if (i < next->arraylength-1) { 207 ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr); 208 } 209 } 210 ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s) ",next->text,next->man);CHKERRQ(ierr); 211 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 212 if (str[0]) { 213 PetscToken token; 214 PetscInt n=0,nmax = next->arraylength,*dvalue = (PetscInt*)next->data,start,end; 215 size_t len; 216 char *value; 217 PetscBool foundrange; 218 219 next->set = PETSC_TRUE; 220 value = str; 221 ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 222 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 223 while (n < nmax) { 224 if (!value) break; 225 226 /* look for form d-D where d and D are integers */ 227 foundrange = PETSC_FALSE; 228 ierr = PetscStrlen(value,&len);CHKERRQ(ierr); 229 if (value[0] == '-') i=2; 230 else i=1; 231 for (;i<len; i++) { 232 if (value[i] == '-') { 233 if (i == len-1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry %s\n",n,value); 234 value[i] = 0; 235 ierr = PetscOptionsStringToInt(value,&start);CHKERRQ(ierr); 236 ierr = PetscOptionsStringToInt(value+i+1,&end);CHKERRQ(ierr); 237 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); 238 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); 239 for (; start<end; start++) { 240 *dvalue = start; dvalue++;n++; 241 } 242 foundrange = PETSC_TRUE; 243 break; 244 } 245 } 246 if (!foundrange) { 247 ierr = PetscOptionsStringToInt(value,dvalue);CHKERRQ(ierr); 248 dvalue++; 249 n++; 250 } 251 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 252 } 253 ierr = PetscTokenDestroy(&token);CHKERRQ(ierr); 254 } 255 break; 256 case OPTION_REAL_ARRAY: 257 ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1);CHKERRQ(ierr); 258 valr = (PetscReal*) next->data; 259 for (i=0; i<next->arraylength; i++) { 260 ierr = PetscPrintf(PETSC_COMM_WORLD,"%g",valr[i]);CHKERRQ(ierr); 261 if (i < next->arraylength-1) { 262 ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr); 263 } 264 } 265 ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s) ",next->text,next->man);CHKERRQ(ierr); 266 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 267 if (str[0]) { 268 PetscToken token; 269 PetscInt n = 0,nmax = next->arraylength; 270 PetscReal *dvalue = (PetscReal*)next->data; 271 char *value; 272 273 next->set = PETSC_TRUE; 274 value = str; 275 ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 276 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 277 while (n < nmax) { 278 if (!value) break; 279 ierr = PetscOptionsStringToReal(value,dvalue);CHKERRQ(ierr); 280 dvalue++; 281 n++; 282 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 283 } 284 ierr = PetscTokenDestroy(&token);CHKERRQ(ierr); 285 } 286 break; 287 case OPTION_INT: 288 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); 289 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 290 if (str[0]) { 291 #if defined(PETSC_SIZEOF_LONG_LONG) 292 long long lid; 293 sscanf(str,"%lld",&lid); 294 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); 295 #else 296 long lid; 297 sscanf(str,"%ld",&lid); 298 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); 299 #endif 300 301 next->set = PETSC_TRUE; 302 *((PetscInt*)next->data) = (PetscInt)lid; 303 } 304 break; 305 case OPTION_REAL: 306 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); 307 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 308 if (str[0]) { 309 #if defined(PETSC_USE_REAL_SINGLE) 310 sscanf(str,"%e",&ir); 311 #elif defined(PETSC_USE_REAL___FP16) 312 float irtemp; 313 sscanf(str,"%e",&irtemp); 314 ir = irtemp; 315 #elif defined(PETSC_USE_REAL_DOUBLE) 316 sscanf(str,"%le",&ir); 317 #elif defined(PETSC_USE_REAL___FLOAT128) 318 ir = strtoflt128(str,0); 319 #else 320 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Unknown scalar type"); 321 #endif 322 next->set = PETSC_TRUE; 323 *((PetscReal*)next->data) = ir; 324 } 325 break; 326 case OPTION_BOOL: 327 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); 328 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 329 if (str[0]) { 330 ierr = PetscOptionsStringToBool(str,&bid);CHKERRQ(ierr); 331 next->set = PETSC_TRUE; 332 *((PetscBool*)next->data) = bid; 333 } 334 break; 335 case OPTION_STRING: 336 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); 337 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 338 if (str[0]) { 339 next->set = PETSC_TRUE; 340 /* must use system malloc since SAWs may free this */ 341 ierr = PetscStrdup(str,(char**)&next->data);CHKERRQ(ierr); 342 } 343 break; 344 case OPTION_FLIST: 345 ierr = PetscFunctionListPrintTypes(PETSC_COMM_WORLD,stdout,PetscOptionsObject->prefix,next->option,next->text,next->man,next->flist,(char*)next->data);CHKERRQ(ierr); 346 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 347 if (str[0]) { 348 PetscOptionsObject->changedmethod = PETSC_TRUE; 349 next->set = PETSC_TRUE; 350 /* must use system malloc since SAWs may free this */ 351 ierr = PetscStrdup(str,(char**)&next->data);CHKERRQ(ierr); 352 } 353 break; 354 default: 355 break; 356 } 357 next = next->next; 358 } 359 PetscFunctionReturn(0); 360 } 361 362 #if defined(PETSC_HAVE_SAWS) 363 #include <petscviewersaws.h> 364 365 static int count = 0; 366 367 PetscErrorCode PetscOptionsSAWsDestroy(void) 368 { 369 PetscFunctionBegin; 370 PetscFunctionReturn(0); 371 } 372 373 static const char *OptionsHeader = "<head>\n" 374 "<script type=\"text/javascript\" src=\"http://www.mcs.anl.gov/research/projects/saws/js/jquery-1.9.1.js\"></script>\n" 375 "<script type=\"text/javascript\" src=\"http://www.mcs.anl.gov/research/projects/saws/js/SAWs.js\"></script>\n" 376 "<script type=\"text/javascript\" src=\"js/PETSc.js\"></script>\n" 377 "<script>\n" 378 "jQuery(document).ready(function() {\n" 379 "PETSc.getAndDisplayDirectory(null,\"#variablesInfo\")\n" 380 "})\n" 381 "</script>\n" 382 "</head>\n"; 383 384 /* Determines the size and style of the scroll region where PETSc options selectable from users are displayed */ 385 static const char *OptionsBodyBottom = "<div id=\"variablesInfo\" style=\"background-color:lightblue;height:auto;max-height:500px;overflow:scroll;\"></div>\n<br>\n</body>"; 386 387 /* 388 PetscOptionsSAWsInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the SAWs 389 390 Bugs: 391 + All processes must traverse through the exact same set of option queries do to the call to PetscScanString() 392 . Internal strings have arbitrary length and string copies are not checked that they fit into string space 393 - Only works for PetscInt == int, PetscReal == double etc 394 395 396 */ 397 PetscErrorCode PetscOptionsSAWsInput(PetscOptionItems *PetscOptionsObject) 398 { 399 PetscErrorCode ierr; 400 PetscOptionItem next = PetscOptionsObject->next; 401 static int mancount = 0; 402 char options[16]; 403 PetscBool changedmethod = PETSC_FALSE; 404 PetscBool stopasking = PETSC_FALSE; 405 char manname[16],textname[16]; 406 char dir[1024]; 407 408 PetscFunctionBegin; 409 /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */ 410 sprintf(options,"Options_%d",count++); 411 412 PetscOptionsObject->pprefix = PetscOptionsObject->prefix; /* SAWs will change this, so cannot pass prefix directly */ 413 414 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s","_title");CHKERRQ(ierr); 415 PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject->title,1,SAWs_READ,SAWs_STRING)); 416 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s","prefix");CHKERRQ(ierr); 417 PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject->pprefix,1,SAWs_READ,SAWs_STRING)); 418 PetscStackCallSAWs(SAWs_Register,("/PETSc/Options/ChangedMethod",&changedmethod,1,SAWs_WRITE,SAWs_BOOLEAN)); 419 PetscStackCallSAWs(SAWs_Register,("/PETSc/Options/StopAsking",&stopasking,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,(int*)&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) PetscOptionsObject->count = -2; 506 507 if (stopasking) { 508 PetscOptionsPublish = PETSC_FALSE; 509 PetscOptionsObject->count = 0;//do not ask for same thing again 510 } 511 512 PetscStackCallSAWs(SAWs_Delete,("/PETSc/Options")); 513 PetscFunctionReturn(0); 514 } 515 #endif 516 517 PetscErrorCode PetscOptionsEnd_Private(PetscOptionItems *PetscOptionsObject) 518 { 519 PetscErrorCode ierr; 520 PetscOptionItem last; 521 char option[256],value[1024],tmp[32]; 522 size_t j; 523 524 PetscFunctionBegin; 525 if (PetscOptionsObject->next) { 526 if (!PetscOptionsObject->count) { 527 #if defined(PETSC_HAVE_SAWS) 528 ierr = PetscOptionsSAWsInput(PetscOptionsObject);CHKERRQ(ierr); 529 #else 530 ierr = PetscOptionsGetFromTextInput(PetscOptionsObject);CHKERRQ(ierr); 531 #endif 532 } 533 } 534 535 ierr = PetscFree(PetscOptionsObject->title);CHKERRQ(ierr); 536 537 /* reset counter to -2; this updates the screen with the new options for the selected method */ 538 if (PetscOptionsObject->changedmethod) PetscOptionsObject->count = -2; 539 /* reset alreadyprinted flag */ 540 PetscOptionsObject->alreadyprinted = PETSC_FALSE; 541 if (PetscOptionsObject->object) PetscOptionsObject->object->optionsprinted = PETSC_TRUE; 542 PetscOptionsObject->object = NULL; 543 544 while (PetscOptionsObject->next) { 545 if (PetscOptionsObject->next->set) { 546 if (PetscOptionsObject->prefix) { 547 ierr = PetscStrcpy(option,"-");CHKERRQ(ierr); 548 ierr = PetscStrcat(option,PetscOptionsObject->prefix);CHKERRQ(ierr); 549 ierr = PetscStrcat(option,PetscOptionsObject->next->option+1);CHKERRQ(ierr); 550 } else { 551 ierr = PetscStrcpy(option,PetscOptionsObject->next->option);CHKERRQ(ierr); 552 } 553 554 switch (PetscOptionsObject->next->type) { 555 case OPTION_HEAD: 556 break; 557 case OPTION_INT_ARRAY: 558 sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject->next->data)[0]); 559 for (j=1; j<PetscOptionsObject->next->arraylength; j++) { 560 sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject->next->data)[j]); 561 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 562 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 563 } 564 break; 565 case OPTION_INT: 566 sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject->next->data); 567 break; 568 case OPTION_REAL: 569 sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject->next->data); 570 break; 571 case OPTION_REAL_ARRAY: 572 sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject->next->data)[0]); 573 for (j=1; j<PetscOptionsObject->next->arraylength; j++) { 574 sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject->next->data)[j]); 575 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 576 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 577 } 578 break; 579 case OPTION_SCALAR_ARRAY: 580 sprintf(value,"%g+%gi",(double)PetscRealPart(((PetscScalar*)PetscOptionsObject->next->data)[0]),(double)PetscImaginaryPart(((PetscScalar*)PetscOptionsObject->next->data)[0])); 581 for (j=1; j<PetscOptionsObject->next->arraylength; j++) { 582 sprintf(tmp,"%g+%gi",(double)PetscRealPart(((PetscScalar*)PetscOptionsObject->next->data)[j]),(double)PetscImaginaryPart(((PetscScalar*)PetscOptionsObject->next->data)[j])); 583 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 584 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 585 } 586 break; 587 case OPTION_BOOL: 588 sprintf(value,"%d",*(int*)PetscOptionsObject->next->data); 589 break; 590 case OPTION_BOOL_ARRAY: 591 sprintf(value,"%d",(int)((PetscBool*)PetscOptionsObject->next->data)[0]); 592 for (j=1; j<PetscOptionsObject->next->arraylength; j++) { 593 sprintf(tmp,"%d",(int)((PetscBool*)PetscOptionsObject->next->data)[j]); 594 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 595 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 596 } 597 break; 598 case OPTION_FLIST: 599 ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr); 600 break; 601 case OPTION_ELIST: 602 ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr); 603 break; 604 case OPTION_STRING: 605 ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr); 606 break; 607 case OPTION_STRING_ARRAY: 608 sprintf(value,"%s",((char**)PetscOptionsObject->next->data)[0]); 609 for (j=1; j<PetscOptionsObject->next->arraylength; j++) { 610 sprintf(tmp,"%s",((char**)PetscOptionsObject->next->data)[j]); 611 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 612 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 613 } 614 break; 615 } 616 ierr = PetscOptionsSetValue(PetscOptionsObject->options,option,value);CHKERRQ(ierr); 617 } 618 if (PetscOptionsObject->next->type == OPTION_ELIST) { 619 ierr = PetscStrNArrayDestroy(PetscOptionsObject->next->nlist,(char ***)&PetscOptionsObject->next->list);CHKERRQ(ierr); 620 } 621 ierr = PetscFree(PetscOptionsObject->next->text);CHKERRQ(ierr); 622 ierr = PetscFree(PetscOptionsObject->next->option);CHKERRQ(ierr); 623 ierr = PetscFree(PetscOptionsObject->next->man);CHKERRQ(ierr); 624 ierr = PetscFree(PetscOptionsObject->next->edata);CHKERRQ(ierr); 625 626 if ((PetscOptionsObject->next->type == OPTION_STRING) || (PetscOptionsObject->next->type == OPTION_FLIST) || (PetscOptionsObject->next->type == OPTION_ELIST)){ 627 free(PetscOptionsObject->next->data); 628 } else { 629 ierr = PetscFree(PetscOptionsObject->next->data);CHKERRQ(ierr); 630 } 631 632 last = PetscOptionsObject->next; 633 PetscOptionsObject->next = PetscOptionsObject->next->next; 634 ierr = PetscFree(last);CHKERRQ(ierr); 635 } 636 ierr = PetscFree(PetscOptionsObject->prefix);CHKERRQ(ierr); 637 PetscOptionsObject->next = 0; 638 PetscFunctionReturn(0); 639 } 640 641 /*@C 642 PetscOptionsEnum - Gets the enum value for a particular option in the database. 643 644 Logically Collective on the communicator passed in PetscOptionsBegin() 645 646 Input Parameters: 647 + opt - option name 648 . text - short string that describes the option 649 . man - manual page with additional information on option 650 . list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null 651 - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 652 $ PetscOptionsEnum(..., obj->value,&object->value,...) or 653 $ value = defaultvalue 654 $ PetscOptionsEnum(..., value,&value,&flg); 655 $ if (flg) { 656 657 Output Parameter: 658 + value - the value to return 659 - set - PETSC_TRUE if found, else PETSC_FALSE 660 661 Level: beginner 662 663 Concepts: options database 664 665 Notes: 666 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 667 668 list is usually something like PCASMTypes or some other predefined list of enum names 669 670 If the user does not supply the option at all value is NOT changed. Thus 671 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 672 673 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 674 675 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 676 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 677 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 678 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 679 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 680 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 681 PetscOptionsFList(), PetscOptionsEList() 682 @*/ 683 PetscErrorCode PetscOptionsEnum_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],const char *const *list,PetscEnum currentvalue,PetscEnum *value,PetscBool *set) 684 { 685 PetscErrorCode ierr; 686 PetscInt ntext = 0; 687 PetscInt tval; 688 PetscBool tflg; 689 690 PetscFunctionBegin; 691 while (list[ntext++]) { 692 if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries"); 693 } 694 if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix"); 695 ntext -= 3; 696 ierr = PetscOptionsEList_Private(PetscOptionsObject,opt,text,man,list,ntext,list[currentvalue],&tval,&tflg);CHKERRQ(ierr); 697 /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */ 698 if (tflg) *value = (PetscEnum)tval; 699 if (set) *set = tflg; 700 PetscFunctionReturn(0); 701 } 702 703 /*@C 704 PetscOptionsEnumArray - Gets an array of enum values for a particular 705 option in the database. 706 707 Logically Collective on the communicator passed in PetscOptionsBegin() 708 709 Input Parameters: 710 + opt - the option one is seeking 711 . text - short string describing option 712 . man - manual page for option 713 - n - maximum number of values 714 715 Output Parameter: 716 + value - location to copy values 717 . n - actual number of values found 718 - set - PETSC_TRUE if found, else PETSC_FALSE 719 720 Level: beginner 721 722 Notes: 723 The array must be passed as a comma separated list. 724 725 There must be no intervening spaces between the values. 726 727 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 728 729 Concepts: options database^array of enums 730 731 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 732 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 733 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 734 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 735 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 736 PetscOptionsFList(), PetscOptionsEList(), PetscOptionsRealArray() 737 @*/ 738 PetscErrorCode PetscOptionsEnumArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],const char *const *list,PetscEnum value[],PetscInt *n,PetscBool *set) 739 { 740 PetscInt i,nlist = 0; 741 PetscOptionItem amsopt; 742 PetscErrorCode ierr; 743 744 PetscFunctionBegin; 745 while (list[nlist++]) if (nlist > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries"); 746 if (nlist < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix"); 747 nlist -= 3; /* drop enum name, prefix, and null termination */ 748 if (0 && !PetscOptionsObject->count) { /* XXX Requires additional support */ 749 PetscEnum *vals; 750 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT_ARRAY/*XXX OPTION_ENUM_ARRAY*/,&amsopt);CHKERRQ(ierr); 751 ierr = PetscStrNArrayallocpy(nlist,list,(char***)&amsopt->list);CHKERRQ(ierr); 752 amsopt->nlist = nlist; 753 ierr = PetscMalloc1(*n,(PetscEnum**)&amsopt->data);CHKERRQ(ierr); 754 amsopt->arraylength = *n; 755 vals = (PetscEnum*)amsopt->data; 756 for (i=0; i<*n; i++) vals[i] = value[i]; 757 } 758 ierr = PetscOptionsGetEnumArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,list,value,n,set);CHKERRQ(ierr); 759 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 760 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%s",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,list[value[0]]);CHKERRQ(ierr); 761 for (i=1; i<*n; i++) {ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%s",list[value[i]]);CHKERRQ(ierr);} 762 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (choose from)",text);CHKERRQ(ierr); 763 for (i=0; i<nlist; i++) {ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s",list[i]);CHKERRQ(ierr);} 764 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," (%s)\n",ManSection(man));CHKERRQ(ierr); 765 } 766 PetscFunctionReturn(0); 767 } 768 769 /* -------------------------------------------------------------------------------------------------------------*/ 770 /*@C 771 PetscOptionsInt - Gets the integer value for a particular option in the database. 772 773 Logically Collective on the communicator passed in PetscOptionsBegin() 774 775 Input Parameters: 776 + opt - option name 777 . text - short string that describes the option 778 . man - manual page with additional information on option 779 - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 780 $ PetscOptionsInt(..., obj->value,&object->value,...) or 781 $ value = defaultvalue 782 $ PetscOptionsInt(..., value,&value,&flg); 783 $ if (flg) { 784 785 Output Parameter: 786 + value - the integer value to return 787 - flg - PETSC_TRUE if found, else PETSC_FALSE 788 789 Notes: 790 If the user does not supply the option at all value is NOT changed. Thus 791 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 792 793 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 794 795 Level: beginner 796 797 Concepts: options database^has int 798 799 Notes: 800 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 801 802 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 803 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 804 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 805 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 806 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 807 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 808 PetscOptionsFList(), PetscOptionsEList() 809 @*/ 810 PetscErrorCode PetscOptionsInt_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *set) 811 { 812 PetscErrorCode ierr; 813 PetscOptionItem amsopt; 814 PetscBool wasset; 815 816 PetscFunctionBegin; 817 if (!PetscOptionsObject->count) { 818 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr); 819 ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr); 820 *(PetscInt*)amsopt->data = currentvalue; 821 822 ierr = PetscOptionsGetInt(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,¤tvalue,&wasset);CHKERRQ(ierr); 823 if (wasset) { 824 *(PetscInt*)amsopt->data = currentvalue; 825 } 826 } 827 ierr = PetscOptionsGetInt(NULL,PetscOptionsObject->prefix,opt,value,set);CHKERRQ(ierr); 828 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 829 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%d>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,currentvalue,text,ManSection(man));CHKERRQ(ierr); 830 } 831 PetscFunctionReturn(0); 832 } 833 834 /*@C 835 PetscOptionsString - Gets the string value for a particular option in the database. 836 837 Logically Collective on the communicator passed in PetscOptionsBegin() 838 839 Input Parameters: 840 + opt - option name 841 . text - short string that describes the option 842 . man - manual page with additional information on option 843 . currentvalue - the current value; caller is responsible for setting this value correctly. This is not used to set value 844 - len - length of the result string including null terminator 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: 855 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 856 857 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). 858 859 If the user does not supply the option at all value is NOT changed. Thus 860 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 861 862 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 863 864 865 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(NULL,), 866 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 867 PetscOptionsInt(), PetscOptionsReal(), PetscOptionsBool(), 868 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 869 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 870 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 871 PetscOptionsFList(), PetscOptionsEList() 872 @*/ 873 PetscErrorCode PetscOptionsString_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],const char currentvalue[],char value[],size_t len,PetscBool *set) 874 { 875 PetscErrorCode ierr; 876 PetscOptionItem amsopt; 877 878 PetscFunctionBegin; 879 if (!PetscOptionsObject->count) { 880 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr); 881 /* must use system malloc since SAWs may free this */ 882 ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr); 883 } 884 ierr = PetscOptionsGetString(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,len,set);CHKERRQ(ierr); 885 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 886 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%s>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,currentvalue,text,ManSection(man));CHKERRQ(ierr); 887 } 888 PetscFunctionReturn(0); 889 } 890 891 /*@C 892 PetscOptionsReal - Gets the PetscReal value for a particular option in the database. 893 894 Logically Collective on the communicator passed in PetscOptionsBegin() 895 896 Input Parameters: 897 + opt - option name 898 . text - short string that describes the option 899 . man - manual page with additional information on option 900 - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 901 $ PetscOptionsReal(..., obj->value,&object->value,...) or 902 $ value = defaultvalue 903 $ PetscOptionsReal(..., value,&value,&flg); 904 $ if (flg) { 905 906 Output Parameter: 907 + value - the value to return 908 - flg - PETSC_TRUE if found, else PETSC_FALSE 909 910 Notes: 911 If the user does not supply the option at all value is NOT changed. Thus 912 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 913 914 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 915 916 Level: beginner 917 918 Concepts: options database^has int 919 920 Notes: 921 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 922 923 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(NULL,), 924 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 925 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 926 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 927 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 928 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 929 PetscOptionsFList(), PetscOptionsEList() 930 @*/ 931 PetscErrorCode PetscOptionsReal_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscReal currentvalue,PetscReal *value,PetscBool *set) 932 { 933 PetscErrorCode ierr; 934 PetscOptionItem amsopt; 935 936 PetscFunctionBegin; 937 if (!PetscOptionsObject->count) { 938 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr); 939 ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr); 940 941 *(PetscReal*)amsopt->data = currentvalue; 942 } 943 ierr = PetscOptionsGetReal(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,set);CHKERRQ(ierr); 944 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 945 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%g>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,(double)currentvalue,text,ManSection(man));CHKERRQ(ierr); 946 } 947 PetscFunctionReturn(0); 948 } 949 950 /*@C 951 PetscOptionsScalar - Gets the scalar value for a particular option in the database. 952 953 Logically Collective on the communicator passed in PetscOptionsBegin() 954 955 Input Parameters: 956 + opt - option name 957 . text - short string that describes the option 958 . man - manual page with additional information on option 959 - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 960 $ PetscOptionsScalar(..., obj->value,&object->value,...) or 961 $ value = defaultvalue 962 $ PetscOptionsScalar(..., value,&value,&flg); 963 $ if (flg) { 964 965 966 Output Parameter: 967 + value - the value to return 968 - flg - PETSC_TRUE if found, else PETSC_FALSE 969 970 Notes: 971 If the user does not supply the option at all value is NOT changed. Thus 972 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 973 974 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 975 976 Level: beginner 977 978 Concepts: options database^has int 979 980 Notes: 981 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 982 983 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(NULL,), 984 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 985 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 986 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 987 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 988 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 989 PetscOptionsFList(), PetscOptionsEList() 990 @*/ 991 PetscErrorCode PetscOptionsScalar_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscScalar currentvalue,PetscScalar *value,PetscBool *set) 992 { 993 PetscErrorCode ierr; 994 995 PetscFunctionBegin; 996 #if !defined(PETSC_USE_COMPLEX) 997 ierr = PetscOptionsReal(opt,text,man,currentvalue,value,set);CHKERRQ(ierr); 998 #else 999 ierr = PetscOptionsGetScalar(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,set);CHKERRQ(ierr); 1000 #endif 1001 PetscFunctionReturn(0); 1002 } 1003 1004 /*@C 1005 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 1006 its value is set to false. 1007 1008 Logically Collective on the communicator passed in PetscOptionsBegin() 1009 1010 Input Parameters: 1011 + opt - option name 1012 . text - short string that describes the option 1013 - man - manual page with additional information on option 1014 1015 Output Parameter: 1016 . flg - PETSC_TRUE if found, else PETSC_FALSE 1017 1018 Level: beginner 1019 1020 Concepts: options database^has int 1021 1022 Notes: 1023 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1024 1025 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(NULL,), 1026 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 1027 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 1028 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1029 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1030 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1031 PetscOptionsFList(), PetscOptionsEList() 1032 @*/ 1033 PetscErrorCode PetscOptionsName_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool *flg) 1034 { 1035 PetscErrorCode ierr; 1036 PetscOptionItem amsopt; 1037 1038 PetscFunctionBegin; 1039 if (!PetscOptionsObject->count) { 1040 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1041 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1042 1043 *(PetscBool*)amsopt->data = PETSC_FALSE; 1044 } 1045 ierr = PetscOptionsHasName(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg);CHKERRQ(ierr); 1046 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1047 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1048 } 1049 PetscFunctionReturn(0); 1050 } 1051 1052 /*@C 1053 PetscOptionsFList - Puts a list of option values that a single one may be selected from 1054 1055 Logically Collective on the communicator passed in PetscOptionsBegin() 1056 1057 Input Parameters: 1058 + opt - option name 1059 . text - short string that describes the option 1060 . man - manual page with additional information on option 1061 . list - the possible choices 1062 . currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with 1063 $ PetscOptionsFlist(..., obj->value,value,len,&flg); 1064 $ if (flg) { 1065 - len - the length of the character array value 1066 1067 Output Parameter: 1068 + value - the value to return 1069 - set - PETSC_TRUE if found, else PETSC_FALSE 1070 1071 Level: intermediate 1072 1073 Notes: 1074 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1075 1076 If the user does not supply the option at all value is NOT changed. Thus 1077 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 1078 1079 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 1080 1081 See PetscOptionsEList() for when the choices are given in a string array 1082 1083 To get a listing of all currently specified options, 1084 see PetscOptionsView() or PetscOptionsGetAll() 1085 1086 Developer Note: This cannot check for invalid selection because of things like MATAIJ that are not included in the list 1087 1088 Concepts: options database^list 1089 1090 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1091 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1092 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1093 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1094 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1095 PetscOptionsFList(), PetscOptionsEList(), PetscOptionsEnum() 1096 @*/ 1097 PetscErrorCode PetscOptionsFList_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char currentvalue[],char value[],size_t len,PetscBool *set) 1098 { 1099 PetscErrorCode ierr; 1100 PetscOptionItem amsopt; 1101 1102 PetscFunctionBegin; 1103 if (!PetscOptionsObject->count) { 1104 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,ltext,man,OPTION_FLIST,&amsopt);CHKERRQ(ierr); 1105 /* must use system malloc since SAWs may free this */ 1106 ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr); 1107 amsopt->flist = list; 1108 } 1109 ierr = PetscOptionsGetString(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,len,set);CHKERRQ(ierr); 1110 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1111 ierr = PetscFunctionListPrintTypes(PetscOptionsObject->comm,stdout,PetscOptionsObject->prefix,opt,ltext,man,list,currentvalue);CHKERRQ(ierr);CHKERRQ(ierr); 1112 } 1113 PetscFunctionReturn(0); 1114 } 1115 1116 /*@C 1117 PetscOptionsEList - Puts a list of option values that a single one may be selected from 1118 1119 Logically Collective on the communicator passed in PetscOptionsBegin() 1120 1121 Input Parameters: 1122 + opt - option name 1123 . ltext - short string that describes the option 1124 . man - manual page with additional information on option 1125 . list - the possible choices (one of these must be selected, anything else is invalid) 1126 . ntext - number of choices 1127 - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with 1128 $ PetscOptionsElist(..., obj->value,&value,&flg); 1129 $ if (flg) { 1130 1131 1132 Output Parameter: 1133 + value - the index of the value to return 1134 - set - PETSC_TRUE if found, else PETSC_FALSE 1135 1136 Level: intermediate 1137 1138 Notes: 1139 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1140 1141 If the user does not supply the option at all value is NOT changed. Thus 1142 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 1143 1144 See PetscOptionsFList() for when the choices are given in a PetscFunctionList() 1145 1146 Concepts: options database^list 1147 1148 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1149 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1150 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1151 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1152 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1153 PetscOptionsFList(), PetscOptionsEnum() 1154 @*/ 1155 PetscErrorCode PetscOptionsEList_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char ltext[],const char man[],const char *const *list,PetscInt ntext,const char currentvalue[],PetscInt *value,PetscBool *set) 1156 { 1157 PetscErrorCode ierr; 1158 PetscInt i; 1159 PetscOptionItem amsopt; 1160 1161 PetscFunctionBegin; 1162 if (!PetscOptionsObject->count) { 1163 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,ltext,man,OPTION_ELIST,&amsopt);CHKERRQ(ierr); 1164 /* must use system malloc since SAWs may free this */ 1165 ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr); 1166 ierr = PetscStrNArrayallocpy(ntext,list,(char***)&amsopt->list);CHKERRQ(ierr); 1167 amsopt->nlist = ntext; 1168 } 1169 ierr = PetscOptionsGetEList(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,list,ntext,value,set);CHKERRQ(ierr); 1170 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1171 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%s> %s (choose one of)",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,currentvalue,ltext);CHKERRQ(ierr); 1172 for (i=0; i<ntext; i++) { 1173 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s",list[i]);CHKERRQ(ierr); 1174 } 1175 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," (%s)\n",ManSection(man));CHKERRQ(ierr); 1176 } 1177 PetscFunctionReturn(0); 1178 } 1179 1180 /*@C 1181 PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for 1182 which at most a single value can be true. 1183 1184 Logically Collective on the communicator passed in PetscOptionsBegin() 1185 1186 Input Parameters: 1187 + opt - option name 1188 . text - short string that describes the option 1189 - man - manual page with additional information on option 1190 1191 Output Parameter: 1192 . flg - whether that option was set or not 1193 1194 Level: intermediate 1195 1196 Notes: 1197 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1198 1199 Must be followed by 0 or more PetscOptionsBoolGroup()s and PetscOptionsBoolGroupEnd() 1200 1201 Concepts: options database^logical group 1202 1203 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1204 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1205 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1206 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1207 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1208 PetscOptionsFList(), PetscOptionsEList() 1209 @*/ 1210 PetscErrorCode PetscOptionsBoolGroupBegin_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool *flg) 1211 { 1212 PetscErrorCode ierr; 1213 PetscOptionItem amsopt; 1214 1215 PetscFunctionBegin; 1216 if (!PetscOptionsObject->count) { 1217 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1218 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1219 1220 *(PetscBool*)amsopt->data = PETSC_FALSE; 1221 } 1222 *flg = PETSC_FALSE; 1223 ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr); 1224 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1225 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," Pick at most one of -------------\n");CHKERRQ(ierr); 1226 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1227 } 1228 PetscFunctionReturn(0); 1229 } 1230 1231 /*@C 1232 PetscOptionsBoolGroup - One in a series of logical queries on the options database for 1233 which at most a single value can be true. 1234 1235 Logically Collective on the communicator passed in PetscOptionsBegin() 1236 1237 Input Parameters: 1238 + opt - option name 1239 . text - short string that describes the option 1240 - man - manual page with additional information on option 1241 1242 Output Parameter: 1243 . flg - PETSC_TRUE if found, else PETSC_FALSE 1244 1245 Level: intermediate 1246 1247 Notes: 1248 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1249 1250 Must follow a PetscOptionsBoolGroupBegin() and preceded a PetscOptionsBoolGroupEnd() 1251 1252 Concepts: options database^logical group 1253 1254 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1255 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1256 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1257 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1258 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1259 PetscOptionsFList(), PetscOptionsEList() 1260 @*/ 1261 PetscErrorCode PetscOptionsBoolGroup_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool *flg) 1262 { 1263 PetscErrorCode ierr; 1264 PetscOptionItem amsopt; 1265 1266 PetscFunctionBegin; 1267 if (!PetscOptionsObject->count) { 1268 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1269 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1270 1271 *(PetscBool*)amsopt->data = PETSC_FALSE; 1272 } 1273 *flg = PETSC_FALSE; 1274 ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr); 1275 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1276 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1277 } 1278 PetscFunctionReturn(0); 1279 } 1280 1281 /*@C 1282 PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for 1283 which at most a single value can be true. 1284 1285 Logically Collective on the communicator passed in PetscOptionsBegin() 1286 1287 Input Parameters: 1288 + opt - option name 1289 . text - short string that describes the option 1290 - man - manual page with additional information on option 1291 1292 Output Parameter: 1293 . flg - PETSC_TRUE if found, else PETSC_FALSE 1294 1295 Level: intermediate 1296 1297 Notes: 1298 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1299 1300 Must follow a PetscOptionsBoolGroupBegin() 1301 1302 Concepts: options database^logical group 1303 1304 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1305 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1306 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1307 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1308 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1309 PetscOptionsFList(), PetscOptionsEList() 1310 @*/ 1311 PetscErrorCode PetscOptionsBoolGroupEnd_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool *flg) 1312 { 1313 PetscErrorCode ierr; 1314 PetscOptionItem amsopt; 1315 1316 PetscFunctionBegin; 1317 if (!PetscOptionsObject->count) { 1318 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1319 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1320 1321 *(PetscBool*)amsopt->data = PETSC_FALSE; 1322 } 1323 *flg = PETSC_FALSE; 1324 ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr); 1325 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1326 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1327 } 1328 PetscFunctionReturn(0); 1329 } 1330 1331 /*@C 1332 PetscOptionsBool - Determines if a particular option is in the database with a true or false 1333 1334 Logically Collective on the communicator passed in PetscOptionsBegin() 1335 1336 Input Parameters: 1337 + opt - option name 1338 . text - short string that describes the option 1339 . man - manual page with additional information on option 1340 - currentvalue - the current value 1341 1342 Output Parameter: 1343 . flg - PETSC_TRUE or PETSC_FALSE 1344 . set - PETSC_TRUE if found, else PETSC_FALSE 1345 1346 Notes: 1347 TRUE, true, YES, yes, nostring, and 1 all translate to PETSC_TRUE 1348 FALSE, false, NO, no, and 0 all translate to PETSC_FALSE 1349 1350 If the option is given, but no value is provided, then flg and set are both given the value PETSC_TRUE. That is -requested_bool 1351 is equivalent to -requested_bool true 1352 1353 If the user does not supply the option at all flg is NOT changed. Thus 1354 you should ALWAYS initialize the flg if you access it without first checking if the set flag is true. 1355 1356 Level: beginner 1357 1358 Concepts: options database^logical 1359 1360 Notes: 1361 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1362 1363 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(NULL,), 1364 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 1365 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 1366 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1367 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1368 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1369 PetscOptionsFList(), PetscOptionsEList() 1370 @*/ 1371 PetscErrorCode PetscOptionsBool_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool currentvalue,PetscBool *flg,PetscBool *set) 1372 { 1373 PetscErrorCode ierr; 1374 PetscBool iset; 1375 PetscOptionItem amsopt; 1376 1377 PetscFunctionBegin; 1378 if (!PetscOptionsObject->count) { 1379 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1380 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1381 1382 *(PetscBool*)amsopt->data = currentvalue; 1383 } 1384 ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,&iset);CHKERRQ(ierr); 1385 if (set) *set = iset; 1386 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1387 const char *v = PetscBools[currentvalue]; 1388 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: <%s> %s (%s)\n",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,v,text,ManSection(man));CHKERRQ(ierr); 1389 } 1390 PetscFunctionReturn(0); 1391 } 1392 1393 /*@C 1394 PetscOptionsRealArray - Gets an array of double values for a particular 1395 option in the database. The values must be separated with commas with 1396 no intervening spaces. 1397 1398 Logically Collective on the communicator passed in PetscOptionsBegin() 1399 1400 Input Parameters: 1401 + opt - the option one is seeking 1402 . text - short string describing option 1403 . man - manual page for option 1404 - nmax - maximum number of values 1405 1406 Output Parameter: 1407 + value - location to copy values 1408 . nmax - actual number of values found 1409 - set - PETSC_TRUE if found, else PETSC_FALSE 1410 1411 Level: beginner 1412 1413 Notes: 1414 The user should pass in an array of doubles 1415 1416 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1417 1418 Concepts: options database^array of strings 1419 1420 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1421 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1422 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1423 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1424 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1425 PetscOptionsFList(), PetscOptionsEList() 1426 @*/ 1427 PetscErrorCode PetscOptionsRealArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool *set) 1428 { 1429 PetscErrorCode ierr; 1430 PetscInt i; 1431 PetscOptionItem amsopt; 1432 1433 PetscFunctionBegin; 1434 if (!PetscOptionsObject->count) { 1435 PetscReal *vals; 1436 1437 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr); 1438 ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr); 1439 vals = (PetscReal*)amsopt->data; 1440 for (i=0; i<*n; i++) vals[i] = value[i]; 1441 amsopt->arraylength = *n; 1442 } 1443 ierr = PetscOptionsGetRealArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr); 1444 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1445 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%g",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,(double)value[0]);CHKERRQ(ierr); 1446 for (i=1; i<*n; i++) { 1447 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%g",(double)value[i]);CHKERRQ(ierr); 1448 } 1449 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1450 } 1451 PetscFunctionReturn(0); 1452 } 1453 1454 /*@C 1455 PetscOptionsScalarArray - Gets an array of Scalar values for a particular 1456 option in the database. The values must be separated with commas with 1457 no intervening spaces. 1458 1459 Logically Collective on the communicator passed in PetscOptionsBegin() 1460 1461 Input Parameters: 1462 + opt - the option one is seeking 1463 . text - short string describing option 1464 . man - manual page for option 1465 - nmax - maximum number of values 1466 1467 Output Parameter: 1468 + value - location to copy values 1469 . nmax - actual number of values found 1470 - set - PETSC_TRUE if found, else PETSC_FALSE 1471 1472 Level: beginner 1473 1474 Notes: 1475 The user should pass in an array of doubles 1476 1477 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1478 1479 Concepts: options database^array of strings 1480 1481 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1482 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1483 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1484 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1485 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1486 PetscOptionsFList(), PetscOptionsEList() 1487 @*/ 1488 PetscErrorCode PetscOptionsScalarArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscScalar value[],PetscInt *n,PetscBool *set) 1489 { 1490 PetscErrorCode ierr; 1491 PetscInt i; 1492 PetscOptionItem amsopt; 1493 1494 PetscFunctionBegin; 1495 if (!PetscOptionsObject->count) { 1496 PetscScalar *vals; 1497 1498 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_SCALAR_ARRAY,&amsopt);CHKERRQ(ierr); 1499 ierr = PetscMalloc((*n)*sizeof(PetscScalar),&amsopt->data);CHKERRQ(ierr); 1500 vals = (PetscScalar*)amsopt->data; 1501 for (i=0; i<*n; i++) vals[i] = value[i]; 1502 amsopt->arraylength = *n; 1503 } 1504 ierr = PetscOptionsGetScalarArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr); 1505 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1506 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%g+%gi",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,(double)PetscRealPart(value[0]),(double)PetscImaginaryPart(value[0]));CHKERRQ(ierr); 1507 for (i=1; i<*n; i++) { 1508 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%g+%gi",(double)PetscRealPart(value[i]),(double)PetscImaginaryPart(value[i]));CHKERRQ(ierr); 1509 } 1510 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1511 } 1512 PetscFunctionReturn(0); 1513 } 1514 1515 /*@C 1516 PetscOptionsIntArray - Gets an array of integers for a particular 1517 option in the database. 1518 1519 Logically Collective on the communicator passed in PetscOptionsBegin() 1520 1521 Input Parameters: 1522 + opt - the option one is seeking 1523 . text - short string describing option 1524 . man - manual page for option 1525 - n - maximum number of values 1526 1527 Output Parameter: 1528 + value - location to copy values 1529 . n - actual number of values found 1530 - set - PETSC_TRUE if found, else PETSC_FALSE 1531 1532 Level: beginner 1533 1534 Notes: 1535 The array can be passed as 1536 a comma separated list: 0,1,2,3,4,5,6,7 1537 a range (start-end+1): 0-8 1538 a range with given increment (start-end+1:inc): 0-7:2 1539 a combination of values and ranges separated by commas: 0,1-8,8-15:2 1540 1541 There must be no intervening spaces between the values. 1542 1543 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1544 1545 Concepts: options database^array of ints 1546 1547 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1548 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1549 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1550 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1551 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1552 PetscOptionsFList(), PetscOptionsEList(), PetscOptionsRealArray() 1553 @*/ 1554 PetscErrorCode PetscOptionsIntArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool *set) 1555 { 1556 PetscErrorCode ierr; 1557 PetscInt i; 1558 PetscOptionItem amsopt; 1559 1560 PetscFunctionBegin; 1561 if (!PetscOptionsObject->count) { 1562 PetscInt *vals; 1563 1564 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr); 1565 ierr = PetscMalloc1(*n,(PetscInt**)&amsopt->data);CHKERRQ(ierr); 1566 vals = (PetscInt*)amsopt->data; 1567 for (i=0; i<*n; i++) vals[i] = value[i]; 1568 amsopt->arraylength = *n; 1569 } 1570 ierr = PetscOptionsGetIntArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr); 1571 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1572 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%d",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,value[0]);CHKERRQ(ierr); 1573 for (i=1; i<*n; i++) { 1574 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%d",value[i]);CHKERRQ(ierr); 1575 } 1576 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1577 } 1578 PetscFunctionReturn(0); 1579 } 1580 1581 /*@C 1582 PetscOptionsStringArray - Gets an array of string values for a particular 1583 option in the database. The values must be separated with commas with 1584 no intervening spaces. 1585 1586 Logically Collective on the communicator passed in PetscOptionsBegin() 1587 1588 Input Parameters: 1589 + opt - the option one is seeking 1590 . text - short string describing option 1591 . man - manual page for option 1592 - nmax - maximum number of strings 1593 1594 Output Parameter: 1595 + value - location to copy strings 1596 . nmax - actual number of strings found 1597 - set - PETSC_TRUE if found, else PETSC_FALSE 1598 1599 Level: beginner 1600 1601 Notes: 1602 The user should pass in an array of pointers to char, to hold all the 1603 strings returned by this function. 1604 1605 The user is responsible for deallocating the strings that are 1606 returned. The Fortran interface for this routine is not supported. 1607 1608 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1609 1610 Concepts: options database^array of strings 1611 1612 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1613 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1614 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1615 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1616 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1617 PetscOptionsFList(), PetscOptionsEList() 1618 @*/ 1619 PetscErrorCode PetscOptionsStringArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool *set) 1620 { 1621 PetscErrorCode ierr; 1622 PetscOptionItem amsopt; 1623 1624 PetscFunctionBegin; 1625 if (!PetscOptionsObject->count) { 1626 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING_ARRAY,&amsopt);CHKERRQ(ierr); 1627 ierr = PetscMalloc1(*nmax,(char**)&amsopt->data);CHKERRQ(ierr); 1628 1629 amsopt->arraylength = *nmax; 1630 } 1631 ierr = PetscOptionsGetStringArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,nmax,set);CHKERRQ(ierr); 1632 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1633 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1634 } 1635 PetscFunctionReturn(0); 1636 } 1637 1638 /*@C 1639 PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular 1640 option in the database. The values must be separated with commas with 1641 no intervening spaces. 1642 1643 Logically Collective on the communicator passed in PetscOptionsBegin() 1644 1645 Input Parameters: 1646 + opt - the option one is seeking 1647 . text - short string describing option 1648 . man - manual page for option 1649 - nmax - maximum number of values 1650 1651 Output Parameter: 1652 + value - location to copy values 1653 . nmax - actual number of values found 1654 - set - PETSC_TRUE if found, else PETSC_FALSE 1655 1656 Level: beginner 1657 1658 Notes: 1659 The user should pass in an array of doubles 1660 1661 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1662 1663 Concepts: options database^array of strings 1664 1665 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1666 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1667 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1668 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1669 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1670 PetscOptionsFList(), PetscOptionsEList() 1671 @*/ 1672 PetscErrorCode PetscOptionsBoolArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set) 1673 { 1674 PetscErrorCode ierr; 1675 PetscInt i; 1676 PetscOptionItem amsopt; 1677 1678 PetscFunctionBegin; 1679 if (!PetscOptionsObject->count) { 1680 PetscBool *vals; 1681 1682 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL_ARRAY,&amsopt);CHKERRQ(ierr); 1683 ierr = PetscMalloc1(*n,(PetscBool**)&amsopt->data);CHKERRQ(ierr); 1684 vals = (PetscBool*)amsopt->data; 1685 for (i=0; i<*n; i++) vals[i] = value[i]; 1686 amsopt->arraylength = *n; 1687 } 1688 ierr = PetscOptionsGetBoolArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr); 1689 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1690 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%d",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,value[0]);CHKERRQ(ierr); 1691 for (i=1; i<*n; i++) { 1692 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%d",value[i]);CHKERRQ(ierr); 1693 } 1694 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1695 } 1696 PetscFunctionReturn(0); 1697 } 1698 1699 /*@C 1700 PetscOptionsViewer - Gets a viewer appropriate for the type indicated by the user 1701 1702 Logically Collective on the communicator passed in PetscOptionsBegin() 1703 1704 Input Parameters: 1705 + opt - option name 1706 . text - short string that describes the option 1707 - man - manual page with additional information on option 1708 1709 Output Parameter: 1710 + viewer - the viewer 1711 - set - PETSC_TRUE if found, else PETSC_FALSE 1712 1713 Level: beginner 1714 1715 Concepts: options database^has int 1716 1717 Notes: 1718 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1719 1720 See PetscOptionsGetViewer() for the format of the supplied viewer and its options 1721 1722 .seealso: PetscOptionsGetViewer(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(NULL,), 1723 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 1724 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 1725 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1726 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1727 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1728 PetscOptionsFList(), PetscOptionsEList() 1729 @*/ 1730 PetscErrorCode PetscOptionsViewer_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool *set) 1731 { 1732 PetscErrorCode ierr; 1733 PetscOptionItem amsopt; 1734 1735 PetscFunctionBegin; 1736 if (!PetscOptionsObject->count) { 1737 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr); 1738 /* must use system malloc since SAWs may free this */ 1739 ierr = PetscStrdup("",(char**)&amsopt->data);CHKERRQ(ierr); 1740 } 1741 ierr = PetscOptionsGetViewer(PetscOptionsObject->comm,PetscOptionsObject->prefix,opt,viewer,format,set);CHKERRQ(ierr); 1742 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1743 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%s>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,"",text,ManSection(man));CHKERRQ(ierr); 1744 } 1745 PetscFunctionReturn(0); 1746 } 1747 1748 1749 /*@C 1750 PetscOptionsHead - Puts a heading before listing any more published options. Used, for example, 1751 in KSPSetFromOptions_GMRES(). 1752 1753 Logically Collective on the communicator passed in PetscOptionsBegin() 1754 1755 Input Parameter: 1756 . head - the heading text 1757 1758 1759 Level: intermediate 1760 1761 Notes: 1762 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1763 1764 Can be followed by a call to PetscOptionsTail() in the same function. 1765 1766 Concepts: options database^subheading 1767 1768 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1769 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1770 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1771 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1772 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1773 PetscOptionsFList(), PetscOptionsEList() 1774 @*/ 1775 PetscErrorCode PetscOptionsHead(PetscOptionItems *PetscOptionsObject,const char head[]) 1776 { 1777 PetscErrorCode ierr; 1778 1779 PetscFunctionBegin; 1780 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1781 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s\n",head);CHKERRQ(ierr); 1782 } 1783 PetscFunctionReturn(0); 1784 } 1785 1786 1787 1788 1789 1790 1791