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