1 2 /* 3 Implements the higher-level options database querying methods. These are self-documenting and can attach at runtime to 4 GUI code to display the options and get values from the users. 5 6 */ 7 8 #include <petsc/private/petscimpl.h> /*I "petscsys.h" I*/ 9 #include <petscviewer.h> 10 11 #define ManSection(str) ((str) ? (str) : "None") 12 13 /* 14 Keep a linked list of options that have been posted and we are waiting for 15 user selection. See the manual page for PetscOptionsBegin() 16 17 Eventually we'll attach this beast to a MPI_Comm 18 */ 19 20 /* 21 Handles setting up the data structure in a call to PetscOptionsBegin() 22 */ 23 PetscErrorCode PetscOptionsBegin_Private(PetscOptionItems *PetscOptionsObject,MPI_Comm comm,const char prefix[],const char title[],const char mansec[]) 24 { 25 PetscErrorCode ierr; 26 27 PetscFunctionBegin; 28 if (prefix) PetscValidCharPointer(prefix,3); 29 PetscValidCharPointer(title,4); 30 if (mansec) PetscValidCharPointer(mansec,5); 31 if (!PetscOptionsObject->alreadyprinted) { 32 if (!PetscOptionsHelpPrintedSingleton) { 33 ierr = PetscOptionsHelpPrintedCreate(&PetscOptionsHelpPrintedSingleton);CHKERRQ(ierr); 34 } 35 ierr = PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrintedSingleton,prefix,title,&PetscOptionsObject->alreadyprinted);CHKERRQ(ierr); 36 } 37 PetscOptionsObject->next = NULL; 38 PetscOptionsObject->comm = comm; 39 PetscOptionsObject->changedmethod = PETSC_FALSE; 40 41 ierr = PetscStrallocpy(prefix,&PetscOptionsObject->prefix);CHKERRQ(ierr); 42 ierr = PetscStrallocpy(title,&PetscOptionsObject->title);CHKERRQ(ierr); 43 44 ierr = PetscOptionsHasHelp(PetscOptionsObject->options,&PetscOptionsObject->printhelp);CHKERRQ(ierr); 45 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1) { 46 if (!PetscOptionsObject->alreadyprinted) { 47 ierr = (*PetscHelpPrintf)(comm,"----------------------------------------\n%s:\n",title);CHKERRQ(ierr); 48 } 49 } 50 PetscFunctionReturn(0); 51 } 52 53 /* 54 Handles setting up the data structure in a call to PetscObjectOptionsBegin() 55 */ 56 PetscErrorCode PetscObjectOptionsBegin_Private(PetscOptionItems *PetscOptionsObject,PetscObject obj) 57 { 58 PetscErrorCode ierr; 59 char title[256]; 60 PetscBool flg; 61 62 PetscFunctionBegin; 63 PetscValidHeader(obj,2); 64 PetscOptionsObject->object = obj; 65 PetscOptionsObject->alreadyprinted = obj->optionsprinted; 66 67 ierr = PetscStrcmp(obj->description,obj->class_name,&flg);CHKERRQ(ierr); 68 if (flg) { 69 ierr = PetscSNPrintf(title,sizeof(title),"%s options",obj->class_name);CHKERRQ(ierr); 70 } else { 71 ierr = PetscSNPrintf(title,sizeof(title),"%s (%s) options",obj->description,obj->class_name);CHKERRQ(ierr); 72 } 73 ierr = PetscOptionsBegin_Private(PetscOptionsObject,obj->comm,obj->prefix,title,obj->mansec);CHKERRQ(ierr); 74 PetscFunctionReturn(0); 75 } 76 77 /* 78 Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd() 79 */ 80 static int PetscOptionItemCreate_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscOptionType t,PetscOptionItem *amsopt) 81 { 82 int ierr; 83 PetscOptionItem next; 84 PetscBool valid; 85 86 PetscFunctionBegin; 87 ierr = PetscOptionsValidKey(opt,&valid);CHKERRQ(ierr); 88 if (!valid) SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_ARG_INCOMP,"The option '%s' is not a valid key",opt); 89 90 ierr = PetscNew(amsopt);CHKERRQ(ierr); 91 (*amsopt)->next = NULL; 92 (*amsopt)->set = PETSC_FALSE; 93 (*amsopt)->type = t; 94 (*amsopt)->data = NULL; 95 96 ierr = PetscStrallocpy(text,&(*amsopt)->text);CHKERRQ(ierr); 97 ierr = PetscStrallocpy(opt,&(*amsopt)->option);CHKERRQ(ierr); 98 ierr = PetscStrallocpy(man,&(*amsopt)->man);CHKERRQ(ierr); 99 100 if (!PetscOptionsObject->next) PetscOptionsObject->next = *amsopt; 101 else { 102 next = PetscOptionsObject->next; 103 while (next->next) next = next->next; 104 next->next = *amsopt; 105 } 106 PetscFunctionReturn(0); 107 } 108 109 /* 110 PetscScanString - Gets user input via stdin from process and broadcasts to all processes 111 112 Collective 113 114 Input Parameters: 115 + commm - communicator for the broadcast, must be PETSC_COMM_WORLD 116 . n - length of the string, must be the same on all processes 117 - str - location to store input 118 119 Bugs: 120 . Assumes process 0 of the given communicator has access to stdin 121 122 */ 123 static PetscErrorCode PetscScanString(MPI_Comm comm,size_t n,char str[]) 124 { 125 size_t i; 126 char c; 127 PetscMPIInt rank,nm; 128 PetscErrorCode ierr; 129 130 PetscFunctionBegin; 131 ierr = MPI_Comm_rank(comm,&rank);CHKERRMPI(ierr); 132 if (rank == 0) { 133 c = (char) getchar(); 134 i = 0; 135 while (c != '\n' && i < n-1) { 136 str[i++] = c; 137 c = (char)getchar(); 138 } 139 str[i] = 0; 140 } 141 ierr = PetscMPIIntCast(n,&nm);CHKERRQ(ierr); 142 ierr = MPI_Bcast(str,nm,MPI_CHAR,0,comm);CHKERRMPI(ierr); 143 PetscFunctionReturn(0); 144 } 145 146 /* 147 This is needed because certain strings may be freed by SAWs, hence we cannot use PetscStrallocpy() 148 */ 149 static PetscErrorCode PetscStrdup(const char s[],char *t[]) 150 { 151 PetscErrorCode ierr; 152 size_t len; 153 char *tmp = NULL; 154 155 PetscFunctionBegin; 156 if (s) { 157 ierr = PetscStrlen(s,&len);CHKERRQ(ierr); 158 tmp = (char*) malloc((len+1)*sizeof(char)); 159 if (!tmp) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_MEM,"No memory to duplicate string"); 160 ierr = PetscStrcpy(tmp,s);CHKERRQ(ierr); 161 } 162 *t = tmp; 163 PetscFunctionReturn(0); 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,(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=\"https://www.mcs.anl.gov/research/projects/saws/js/jquery-1.9.1.js\"></script>\n" 375 "<script type=\"text/javascript\" src=\"https://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 PetscErrorCode PetscOptionsSAWsInput(PetscOptionItems *PetscOptionsObject) 397 { 398 PetscErrorCode ierr; 399 PetscOptionItem next = PetscOptionsObject->next; 400 static int mancount = 0; 401 char options[16]; 402 PetscBool changedmethod = PETSC_FALSE; 403 PetscBool stopasking = PETSC_FALSE; 404 char manname[16],textname[16]; 405 char dir[1024]; 406 407 PetscFunctionBegin; 408 /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */ 409 sprintf(options,"Options_%d",count++); 410 411 PetscOptionsObject->pprefix = PetscOptionsObject->prefix; /* SAWs will change this, so cannot pass prefix directly */ 412 413 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s","_title");CHKERRQ(ierr); 414 PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject->title,1,SAWs_READ,SAWs_STRING)); 415 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s","prefix");CHKERRQ(ierr); 416 PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject->pprefix,1,SAWs_READ,SAWs_STRING)); 417 PetscStackCallSAWs(SAWs_Register,("/PETSc/Options/ChangedMethod",&changedmethod,1,SAWs_WRITE,SAWs_BOOLEAN)); 418 PetscStackCallSAWs(SAWs_Register,("/PETSc/Options/StopAsking",&stopasking,1,SAWs_WRITE,SAWs_BOOLEAN)); 419 420 while (next) { 421 sprintf(manname,"_man_%d",mancount); 422 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",manname);CHKERRQ(ierr); 423 PetscStackCallSAWs(SAWs_Register,(dir,&next->man,1,SAWs_READ,SAWs_STRING)); 424 sprintf(textname,"_text_%d",mancount++); 425 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",textname);CHKERRQ(ierr); 426 PetscStackCallSAWs(SAWs_Register,(dir,&next->text,1,SAWs_READ,SAWs_STRING)); 427 428 switch (next->type) { 429 case OPTION_HEAD: 430 break; 431 case OPTION_INT_ARRAY: 432 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 433 PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_INT)); 434 break; 435 case OPTION_REAL_ARRAY: 436 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 437 PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_DOUBLE)); 438 break; 439 case OPTION_INT: 440 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 441 PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_INT)); 442 break; 443 case OPTION_REAL: 444 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 445 PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_DOUBLE)); 446 break; 447 case OPTION_BOOL: 448 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 449 PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_BOOLEAN)); 450 break; 451 case OPTION_BOOL_ARRAY: 452 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 453 PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_BOOLEAN)); 454 break; 455 case OPTION_STRING: 456 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 457 PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING)); 458 break; 459 case OPTION_STRING_ARRAY: 460 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 461 PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_STRING)); 462 break; 463 case OPTION_FLIST: 464 { 465 PetscInt ntext; 466 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 467 PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING)); 468 ierr = PetscFunctionListGet(next->flist,(const char***)&next->edata,&ntext);CHKERRQ(ierr); 469 PetscStackCallSAWs(SAWs_Set_Legal_Variable_Values,(dir,ntext,next->edata)); 470 } 471 break; 472 case OPTION_ELIST: 473 { 474 PetscInt ntext = next->nlist; 475 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 476 PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING)); 477 ierr = PetscMalloc1((ntext+1),(char***)&next->edata);CHKERRQ(ierr); 478 ierr = PetscMemcpy(next->edata,next->list,ntext*sizeof(char*));CHKERRQ(ierr); 479 PetscStackCallSAWs(SAWs_Set_Legal_Variable_Values,(dir,ntext,next->edata)); 480 } 481 break; 482 default: 483 break; 484 } 485 next = next->next; 486 } 487 488 /* wait until accessor has unlocked the memory */ 489 PetscStackCallSAWs(SAWs_Push_Header,("index.html",OptionsHeader)); 490 PetscStackCallSAWs(SAWs_Push_Body,("index.html",2,OptionsBodyBottom)); 491 ierr = PetscSAWsBlock();CHKERRQ(ierr); 492 PetscStackCallSAWs(SAWs_Pop_Header,("index.html")); 493 PetscStackCallSAWs(SAWs_Pop_Body,("index.html",2)); 494 495 /* determine if any values have been set in GUI */ 496 next = PetscOptionsObject->next; 497 while (next) { 498 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 499 PetscStackCallSAWs(SAWs_Selected,(dir,(int*)&next->set)); 500 next = next->next; 501 } 502 503 /* reset counter to -2; this updates the screen with the new options for the selected method */ 504 if (changedmethod) PetscOptionsObject->count = -2; 505 506 if (stopasking) { 507 PetscOptionsPublish = PETSC_FALSE; 508 PetscOptionsObject->count = 0;//do not ask for same thing again 509 } 510 511 PetscStackCallSAWs(SAWs_Delete,("/PETSc/Options")); 512 PetscFunctionReturn(0); 513 } 514 #endif 515 516 PetscErrorCode PetscOptionsEnd_Private(PetscOptionItems *PetscOptionsObject) 517 { 518 PetscErrorCode ierr; 519 PetscOptionItem last; 520 char option[256],value[1024],tmp[32]; 521 size_t j; 522 523 PetscFunctionBegin; 524 if (PetscOptionsObject->next) { 525 if (!PetscOptionsObject->count) { 526 #if defined(PETSC_HAVE_SAWS) 527 ierr = PetscOptionsSAWsInput(PetscOptionsObject);CHKERRQ(ierr); 528 #else 529 ierr = PetscOptionsGetFromTextInput(PetscOptionsObject);CHKERRQ(ierr); 530 #endif 531 } 532 } 533 534 ierr = PetscFree(PetscOptionsObject->title);CHKERRQ(ierr); 535 536 /* reset counter to -2; this updates the screen with the new options for the selected method */ 537 if (PetscOptionsObject->changedmethod) PetscOptionsObject->count = -2; 538 /* reset alreadyprinted flag */ 539 PetscOptionsObject->alreadyprinted = PETSC_FALSE; 540 if (PetscOptionsObject->object) PetscOptionsObject->object->optionsprinted = PETSC_TRUE; 541 PetscOptionsObject->object = NULL; 542 543 while (PetscOptionsObject->next) { 544 if (PetscOptionsObject->next->set) { 545 if (PetscOptionsObject->prefix) { 546 ierr = PetscStrcpy(option,"-");CHKERRQ(ierr); 547 ierr = PetscStrcat(option,PetscOptionsObject->prefix);CHKERRQ(ierr); 548 ierr = PetscStrcat(option,PetscOptionsObject->next->option+1);CHKERRQ(ierr); 549 } else { 550 ierr = PetscStrcpy(option,PetscOptionsObject->next->option);CHKERRQ(ierr); 551 } 552 553 switch (PetscOptionsObject->next->type) { 554 case OPTION_HEAD: 555 break; 556 case OPTION_INT_ARRAY: 557 sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject->next->data)[0]); 558 for (j=1; j<PetscOptionsObject->next->arraylength; j++) { 559 sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject->next->data)[j]); 560 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 561 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 562 } 563 break; 564 case OPTION_INT: 565 sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject->next->data); 566 break; 567 case OPTION_REAL: 568 sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject->next->data); 569 break; 570 case OPTION_REAL_ARRAY: 571 sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject->next->data)[0]); 572 for (j=1; j<PetscOptionsObject->next->arraylength; j++) { 573 sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject->next->data)[j]); 574 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 575 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 576 } 577 break; 578 case OPTION_SCALAR_ARRAY: 579 sprintf(value,"%g+%gi",(double)PetscRealPart(((PetscScalar*)PetscOptionsObject->next->data)[0]),(double)PetscImaginaryPart(((PetscScalar*)PetscOptionsObject->next->data)[0])); 580 for (j=1; j<PetscOptionsObject->next->arraylength; j++) { 581 sprintf(tmp,"%g+%gi",(double)PetscRealPart(((PetscScalar*)PetscOptionsObject->next->data)[j]),(double)PetscImaginaryPart(((PetscScalar*)PetscOptionsObject->next->data)[j])); 582 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 583 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 584 } 585 break; 586 case OPTION_BOOL: 587 sprintf(value,"%d",*(int*)PetscOptionsObject->next->data); 588 break; 589 case OPTION_BOOL_ARRAY: 590 sprintf(value,"%d",(int)((PetscBool*)PetscOptionsObject->next->data)[0]); 591 for (j=1; j<PetscOptionsObject->next->arraylength; j++) { 592 sprintf(tmp,"%d",(int)((PetscBool*)PetscOptionsObject->next->data)[j]); 593 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 594 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 595 } 596 break; 597 case OPTION_FLIST: 598 ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr); 599 break; 600 case OPTION_ELIST: 601 ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr); 602 break; 603 case OPTION_STRING: 604 ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr); 605 break; 606 case OPTION_STRING_ARRAY: 607 sprintf(value,"%s",((char**)PetscOptionsObject->next->data)[0]); 608 for (j=1; j<PetscOptionsObject->next->arraylength; j++) { 609 sprintf(tmp,"%s",((char**)PetscOptionsObject->next->data)[j]); 610 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 611 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 612 } 613 break; 614 } 615 ierr = PetscOptionsSetValue(PetscOptionsObject->options,option,value);CHKERRQ(ierr); 616 } 617 if (PetscOptionsObject->next->type == OPTION_ELIST) { 618 ierr = PetscStrNArrayDestroy(PetscOptionsObject->next->nlist,(char ***)&PetscOptionsObject->next->list);CHKERRQ(ierr); 619 } 620 ierr = PetscFree(PetscOptionsObject->next->text);CHKERRQ(ierr); 621 ierr = PetscFree(PetscOptionsObject->next->option);CHKERRQ(ierr); 622 ierr = PetscFree(PetscOptionsObject->next->man);CHKERRQ(ierr); 623 ierr = PetscFree(PetscOptionsObject->next->edata);CHKERRQ(ierr); 624 625 if ((PetscOptionsObject->next->type == OPTION_STRING) || (PetscOptionsObject->next->type == OPTION_FLIST) || (PetscOptionsObject->next->type == OPTION_ELIST)) { 626 free(PetscOptionsObject->next->data); 627 } else { 628 ierr = PetscFree(PetscOptionsObject->next->data);CHKERRQ(ierr); 629 } 630 631 last = PetscOptionsObject->next; 632 PetscOptionsObject->next = PetscOptionsObject->next->next; 633 ierr = PetscFree(last);CHKERRQ(ierr); 634 } 635 ierr = PetscFree(PetscOptionsObject->prefix);CHKERRQ(ierr); 636 PetscOptionsObject->next = NULL; 637 PetscFunctionReturn(0); 638 } 639 640 /*MC 641 PetscOptionsEnum - Gets the enum value for a particular option in the database. 642 643 Logically Collective on the communicator passed in PetscOptionsBegin() 644 645 Synopsis: 646 #include "petscsys.h" 647 PetscErrorCode PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum currentvalue,PetscEnum *value,PetscBool *set) 648 649 Input Parameters: 650 + opt - option name 651 . text - short string that describes the option 652 . man - manual page with additional information on option 653 . list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null 654 - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 655 $ PetscOptionsEnum(..., obj->value,&object->value,...) or 656 $ value = defaultvalue 657 $ PetscOptionsEnum(..., value,&value,&flg); 658 $ if (flg) { 659 660 Output Parameters: 661 + value - the value to return 662 - set - PETSC_TRUE if found, else PETSC_FALSE 663 664 Level: beginner 665 666 Notes: 667 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 668 669 list is usually something like PCASMTypes or some other predefined list of enum names 670 671 If the user does not supply the option at all value is NOT changed. Thus 672 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 673 674 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 675 676 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 677 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), 678 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 679 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 680 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 681 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 682 PetscOptionsFList(), PetscOptionsEList() 683 M*/ 684 685 PetscErrorCode PetscOptionsEnum_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],const char *const *list,PetscEnum currentvalue,PetscEnum *value,PetscBool *set) 686 { 687 PetscErrorCode ierr; 688 PetscInt ntext = 0; 689 PetscInt tval; 690 PetscBool tflg; 691 692 PetscFunctionBegin; 693 while (list[ntext++]) { 694 if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries"); 695 } 696 if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix"); 697 ntext -= 3; 698 ierr = PetscOptionsEList_Private(PetscOptionsObject,opt,text,man,list,ntext,list[currentvalue],&tval,&tflg);CHKERRQ(ierr); 699 /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */ 700 if (tflg) *value = (PetscEnum)tval; 701 if (set) *set = tflg; 702 PetscFunctionReturn(0); 703 } 704 705 /*MC 706 PetscOptionsEnumArray - Gets an array of enum values for a particular 707 option in the database. 708 709 Logically Collective on the communicator passed in PetscOptionsBegin() 710 711 Synopsis: 712 #include "petscsys.h" 713 PetscErrorCode PetscOptionsEnumArray(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum value[],PetscInt *n,PetscBool *set) 714 715 Input Parameters: 716 + opt - the option one is seeking 717 . text - short string describing option 718 . man - manual page for option 719 . list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null 720 - n - maximum number of values 721 722 Output Parameters: 723 + value - location to copy values 724 . n - actual number of values found 725 - set - PETSC_TRUE if found, else PETSC_FALSE 726 727 Level: beginner 728 729 Notes: 730 The array must be passed as a comma separated list. 731 732 There must be no intervening spaces between the values. 733 734 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 735 736 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 737 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), 738 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 739 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 740 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 741 PetscOptionsFList(), PetscOptionsEList(), PetscOptionsRealArray() 742 M*/ 743 744 PetscErrorCode PetscOptionsEnumArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],const char *const *list,PetscEnum value[],PetscInt *n,PetscBool *set) 745 { 746 PetscInt i,nlist = 0; 747 PetscOptionItem amsopt; 748 PetscErrorCode ierr; 749 750 PetscFunctionBegin; 751 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"); 752 if (nlist < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix"); 753 nlist -= 3; /* drop enum name, prefix, and null termination */ 754 if (0 && !PetscOptionsObject->count) { /* XXX Requires additional support */ 755 PetscEnum *vals; 756 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT_ARRAY/*XXX OPTION_ENUM_ARRAY*/,&amsopt);CHKERRQ(ierr); 757 ierr = PetscStrNArrayallocpy(nlist,list,(char***)&amsopt->list);CHKERRQ(ierr); 758 amsopt->nlist = nlist; 759 ierr = PetscMalloc1(*n,(PetscEnum**)&amsopt->data);CHKERRQ(ierr); 760 amsopt->arraylength = *n; 761 vals = (PetscEnum*)amsopt->data; 762 for (i=0; i<*n; i++) vals[i] = value[i]; 763 } 764 ierr = PetscOptionsGetEnumArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,list,value,n,set);CHKERRQ(ierr); 765 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 766 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%s",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,list[value[0]]);CHKERRQ(ierr); 767 for (i=1; i<*n; i++) {ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%s",list[value[i]]);CHKERRQ(ierr);} 768 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (choose from)",text);CHKERRQ(ierr); 769 for (i=0; i<nlist; i++) {ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s",list[i]);CHKERRQ(ierr);} 770 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," (%s)\n",ManSection(man));CHKERRQ(ierr); 771 } 772 PetscFunctionReturn(0); 773 } 774 775 /*MC 776 PetscOptionsBoundedInt - Gets an integer value greater than or equal a given bound for a particular option in the database. 777 778 Logically Collective on the communicator passed in PetscOptionsBegin() 779 780 Synopsis: 781 #include "petscsys.h" 782 PetscErrorCode PetscOptionsBoundInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt bound) 783 784 Input Parameters: 785 + opt - option name 786 . text - short string that describes the option 787 . man - manual page with additional information on option 788 . currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 789 $ PetscOptionsInt(..., obj->value,&obj->value,...) or 790 $ value = defaultvalue 791 $ PetscOptionsInt(..., value,&value,&flg); 792 $ if (flg) { 793 - bound - the requested value should be greater than or equal this bound or an error is generated 794 795 Output Parameters: 796 + value - the integer value to return 797 - flg - PETSC_TRUE if found, else PETSC_FALSE 798 799 Notes: 800 If the user does not supply the option at all value is NOT changed. Thus 801 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 802 803 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 804 805 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 806 807 Level: beginner 808 809 .seealso: PetscOptionsInt(), PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 810 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), PetscOptionsRangeInt() 811 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 812 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 813 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 814 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 815 PetscOptionsFList(), PetscOptionsEList() 816 M*/ 817 818 /*MC 819 PetscOptionsRangeInt - Gets an integer value within a range of values for a particular option in the database. 820 821 Logically Collective on the communicator passed in PetscOptionsBegin() 822 823 Synopsis: 824 #include "petscsys.h" 825 PetscErrorCode PetscOptionsRangeInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt lb,PetscInt ub) 826 827 Input Parameters: 828 + opt - option name 829 . text - short string that describes the option 830 . man - manual page with additional information on option 831 . currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 832 $ PetscOptionsInt(..., obj->value,&obj->value,...) or 833 $ value = defaultvalue 834 $ PetscOptionsInt(..., value,&value,&flg); 835 $ if (flg) { 836 . lb - the lower bound, provided value must be greater than or equal to this value or an error is generated 837 - ub - the upper bound, provided value must be less than or equal to this value or an error is generated 838 839 Output Parameters: 840 + value - the integer value to return 841 - flg - PETSC_TRUE if found, else PETSC_FALSE 842 843 Notes: 844 If the user does not supply the option at all value is NOT changed. Thus 845 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 846 847 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 848 849 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 850 851 Level: beginner 852 853 .seealso: PetscOptionsInt(), PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 854 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), PetscOptionsBoundedInt() 855 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 856 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 857 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 858 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 859 PetscOptionsFList(), PetscOptionsEList() 860 M*/ 861 862 /*MC 863 PetscOptionsInt - Gets the integer value for a particular option in the database. 864 865 Logically Collective on the communicator passed in PetscOptionsBegin() 866 867 Synopsis: 868 #include "petscsys.h" 869 PetscErrorCode PetscOptionsInt(const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg)) 870 871 Input Parameters: 872 + opt - option name 873 . text - short string that describes the option 874 . man - manual page with additional information on option 875 - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 876 $ PetscOptionsInt(..., obj->value,&obj->value,...) or 877 $ value = defaultvalue 878 $ PetscOptionsInt(..., value,&value,&flg); 879 $ if (flg) { 880 881 Output Parameters: 882 + value - the integer value to return 883 - flg - PETSC_TRUE if found, else PETSC_FALSE 884 885 Notes: 886 If the user does not supply the option at all value is NOT changed. Thus 887 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 888 889 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 890 891 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 892 893 Level: beginner 894 895 .seealso: PetscOptionsBoundedInt(), PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 896 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), PetscOptionsRangeInt() 897 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 898 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 899 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 900 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 901 PetscOptionsFList(), PetscOptionsEList() 902 M*/ 903 904 PetscErrorCode PetscOptionsInt_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *set,PetscInt lb,PetscInt ub) 905 { 906 PetscErrorCode ierr; 907 PetscOptionItem amsopt; 908 PetscBool wasset; 909 910 PetscFunctionBegin; 911 if (currentvalue < lb) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Current value %D less than allowed bound %D",currentvalue,lb); 912 if (currentvalue > ub) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Current value %D greater than allowed bound %D",currentvalue,ub); 913 if (!PetscOptionsObject->count) { 914 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr); 915 ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr); 916 *(PetscInt*)amsopt->data = currentvalue; 917 918 ierr = PetscOptionsGetInt(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,¤tvalue,&wasset);CHKERRQ(ierr); 919 if (wasset) { 920 *(PetscInt*)amsopt->data = currentvalue; 921 } 922 } 923 ierr = PetscOptionsGetInt(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,&wasset);CHKERRQ(ierr); 924 if (wasset && *value < lb) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Newly set value %D less than allowed bound %D",*value,lb); 925 if (wasset && *value > ub) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Newly set value %D greater than allowed bound %D",*value,ub); 926 if (set) *set = wasset; 927 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 928 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <now %D : formerly %D>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,wasset && value ? *value : currentvalue,currentvalue,text,ManSection(man));CHKERRQ(ierr); 929 } 930 PetscFunctionReturn(0); 931 } 932 933 /*MC 934 PetscOptionsString - Gets the string value for a particular option in the database. 935 936 Logically Collective on the communicator passed in PetscOptionsBegin() 937 938 Synopsis: 939 #include "petscsys.h" 940 PetscErrorCode PetscOptionsString(const char opt[],const char text[],const char man[],const char currentvalue[],char value[],size_t len,PetscBool *set) 941 942 Input Parameters: 943 + opt - option name 944 . text - short string that describes the option 945 . man - manual page with additional information on option 946 . currentvalue - the current value; caller is responsible for setting this value correctly. This is not used to set value 947 - len - length of the result string including null terminator 948 949 Output Parameters: 950 + value - the value to return 951 - flg - PETSC_TRUE if found, else PETSC_FALSE 952 953 Level: beginner 954 955 Notes: 956 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 957 958 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). 959 960 If the user does not supply the option at all value is NOT changed. Thus 961 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 962 963 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 964 965 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 966 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), 967 PetscOptionsInt(), PetscOptionsReal(), PetscOptionsBool(), 968 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 969 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 970 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 971 PetscOptionsFList(), PetscOptionsEList() 972 M*/ 973 974 PetscErrorCode PetscOptionsString_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],const char currentvalue[],char value[],size_t len,PetscBool *set) 975 { 976 PetscErrorCode ierr; 977 PetscOptionItem amsopt; 978 PetscBool lset; 979 980 PetscFunctionBegin; 981 if (!PetscOptionsObject->count) { 982 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr); 983 /* must use system malloc since SAWs may free this */ 984 ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr); 985 } 986 ierr = PetscOptionsGetString(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,len,&lset);CHKERRQ(ierr); 987 if (set) *set = lset; 988 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 989 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <now %s : formerly %s>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,lset && value ? value : currentvalue,currentvalue,text,ManSection(man));CHKERRQ(ierr); 990 } 991 PetscFunctionReturn(0); 992 } 993 994 /*MC 995 PetscOptionsReal - Gets the PetscReal value for a particular option in the database. 996 997 Logically Collective on the communicator passed in PetscOptionsBegin() 998 999 Synopsis: 1000 #include "petscsys.h" 1001 PetscErrorCode PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal currentvalue,PetscReal *value,PetscBool *set) 1002 1003 Input Parameters: 1004 + opt - option name 1005 . text - short string that describes the option 1006 . man - manual page with additional information on option 1007 - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 1008 $ PetscOptionsReal(..., obj->value,&obj->value,...) or 1009 $ value = defaultvalue 1010 $ PetscOptionsReal(..., value,&value,&flg); 1011 $ if (flg) { 1012 1013 Output Parameters: 1014 + value - the value to return 1015 - flg - PETSC_TRUE if found, else PETSC_FALSE 1016 1017 Notes: 1018 If the user does not supply the option at all value is NOT changed. Thus 1019 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 1020 1021 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 1022 1023 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1024 1025 Level: beginner 1026 1027 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 1028 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), 1029 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 1030 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1031 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1032 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1033 PetscOptionsFList(), PetscOptionsEList() 1034 M*/ 1035 1036 PetscErrorCode PetscOptionsReal_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscReal currentvalue,PetscReal *value,PetscBool *set) 1037 { 1038 PetscErrorCode ierr; 1039 PetscOptionItem amsopt; 1040 PetscBool lset; 1041 1042 PetscFunctionBegin; 1043 if (!PetscOptionsObject->count) { 1044 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr); 1045 ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr); 1046 1047 *(PetscReal*)amsopt->data = currentvalue; 1048 } 1049 ierr = PetscOptionsGetReal(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,&lset);CHKERRQ(ierr); 1050 if (set) *set = lset; 1051 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1052 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%g : %g>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,lset && value ? (double)*value : (double) currentvalue,(double)currentvalue,text,ManSection(man));CHKERRQ(ierr); 1053 } 1054 PetscFunctionReturn(0); 1055 } 1056 1057 /*MC 1058 PetscOptionsScalar - Gets the scalar value for a particular option in the database. 1059 1060 Logically Collective on the communicator passed in PetscOptionsBegin() 1061 1062 Synopsis: 1063 #include "petscsys.h" 1064 PetscErrorCode PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar currentvalue,PetscScalar *value,PetscBool *set) 1065 1066 Input Parameters: 1067 + opt - option name 1068 . text - short string that describes the option 1069 . man - manual page with additional information on option 1070 - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 1071 $ PetscOptionsScalar(..., obj->value,&obj->value,...) or 1072 $ value = defaultvalue 1073 $ PetscOptionsScalar(..., value,&value,&flg); 1074 $ if (flg) { 1075 1076 Output Parameters: 1077 + value - the value to return 1078 - flg - PETSC_TRUE if found, else PETSC_FALSE 1079 1080 Notes: 1081 If the user does not supply the option at all value is NOT changed. Thus 1082 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 1083 1084 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 1085 1086 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1087 1088 Level: beginner 1089 1090 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 1091 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), 1092 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 1093 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1094 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1095 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1096 PetscOptionsFList(), PetscOptionsEList() 1097 M*/ 1098 1099 PetscErrorCode PetscOptionsScalar_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscScalar currentvalue,PetscScalar *value,PetscBool *set) 1100 { 1101 PetscErrorCode ierr; 1102 1103 PetscFunctionBegin; 1104 #if !defined(PETSC_USE_COMPLEX) 1105 ierr = PetscOptionsReal(opt,text,man,currentvalue,value,set);CHKERRQ(ierr); 1106 #else 1107 ierr = PetscOptionsGetScalar(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,set);CHKERRQ(ierr); 1108 #endif 1109 PetscFunctionReturn(0); 1110 } 1111 1112 /*MC 1113 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 1114 its value is set to false. 1115 1116 Logically Collective on the communicator passed in PetscOptionsBegin() 1117 1118 Synopsis: 1119 #include "petscsys.h" 1120 PetscErrorCode PetscOptionsName(const char opt[],const char text[],const char man[],PetscBool *flg) 1121 1122 Input Parameters: 1123 + opt - option name 1124 . text - short string that describes the option 1125 - man - manual page with additional information on option 1126 1127 Output Parameter: 1128 . flg - PETSC_TRUE if found, else PETSC_FALSE 1129 1130 Level: beginner 1131 1132 Notes: 1133 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1134 1135 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 1136 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), 1137 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 1138 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1139 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1140 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1141 PetscOptionsFList(), PetscOptionsEList() 1142 M*/ 1143 1144 PetscErrorCode PetscOptionsName_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool *flg) 1145 { 1146 PetscErrorCode ierr; 1147 PetscOptionItem amsopt; 1148 1149 PetscFunctionBegin; 1150 if (!PetscOptionsObject->count) { 1151 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1152 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1153 1154 *(PetscBool*)amsopt->data = PETSC_FALSE; 1155 } 1156 ierr = PetscOptionsHasName(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg);CHKERRQ(ierr); 1157 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1158 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1159 } 1160 PetscFunctionReturn(0); 1161 } 1162 1163 /*MC 1164 PetscOptionsFList - Puts a list of option values that a single one may be selected from 1165 1166 Logically Collective on the communicator passed in PetscOptionsBegin() 1167 1168 Synopsis: 1169 #include "petscsys.h" 1170 PetscErrorCode PetscOptionsFList(const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char currentvalue[],char value[],size_t len,PetscBool *set) 1171 1172 Input Parameters: 1173 + opt - option name 1174 . text - short string that describes the option 1175 . man - manual page with additional information on option 1176 . list - the possible choices 1177 . currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with 1178 $ PetscOptionsFlist(..., obj->value,value,len,&flg); 1179 $ if (flg) { 1180 - len - the length of the character array value 1181 1182 Output Parameters: 1183 + value - the value to return 1184 - set - PETSC_TRUE if found, else PETSC_FALSE 1185 1186 Level: intermediate 1187 1188 Notes: 1189 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1190 1191 If the user does not supply the option at all value is NOT changed. Thus 1192 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 1193 1194 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 1195 1196 See PetscOptionsEList() for when the choices are given in a string array 1197 1198 To get a listing of all currently specified options, 1199 see PetscOptionsView() or PetscOptionsGetAll() 1200 1201 Developer Note: This cannot check for invalid selection because of things like MATAIJ that are not included in the list 1202 1203 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1204 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1205 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1206 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1207 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1208 PetscOptionsFList(), PetscOptionsEList(), PetscOptionsEnum() 1209 M*/ 1210 1211 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) 1212 { 1213 PetscErrorCode ierr; 1214 PetscOptionItem amsopt; 1215 PetscBool lset; 1216 1217 PetscFunctionBegin; 1218 if (!PetscOptionsObject->count) { 1219 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,ltext,man,OPTION_FLIST,&amsopt);CHKERRQ(ierr); 1220 /* must use system malloc since SAWs may free this */ 1221 ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr); 1222 amsopt->flist = list; 1223 } 1224 ierr = PetscOptionsGetString(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,len,&lset);CHKERRQ(ierr); 1225 if (set) *set = lset; 1226 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1227 ierr = PetscFunctionListPrintTypes(PetscOptionsObject->comm,stdout,PetscOptionsObject->prefix,opt,ltext,man,list,currentvalue,lset && value ? value : currentvalue);CHKERRQ(ierr); 1228 } 1229 PetscFunctionReturn(0); 1230 } 1231 1232 /*MC 1233 PetscOptionsEList - Puts a list of option values that a single one may be selected from 1234 1235 Logically Collective on the communicator passed in PetscOptionsBegin() 1236 1237 Synopsis: 1238 #include "petscsys.h" 1239 PetscErrorCode PetscOptionsEList(const char opt[],const char ltext[],const char man[],const char *const *list,PetscInt ntext,const char currentvalue[],PetscInt *value,PetscBool *set) 1240 1241 Input Parameters: 1242 + opt - option name 1243 . ltext - short string that describes the option 1244 . man - manual page with additional information on option 1245 . list - the possible choices (one of these must be selected, anything else is invalid) 1246 . ntext - number of choices 1247 - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with 1248 $ PetscOptionsElist(..., obj->value,&value,&flg); 1249 $ if (flg) { 1250 1251 Output Parameters: 1252 + value - the index of the value to return 1253 - set - PETSC_TRUE if found, else PETSC_FALSE 1254 1255 Level: intermediate 1256 1257 Notes: 1258 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1259 1260 If the user does not supply the option at all value is NOT changed. Thus 1261 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 1262 1263 See PetscOptionsFList() for when the choices are given in a PetscFunctionList() 1264 1265 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1266 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1267 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1268 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1269 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1270 PetscOptionsFList(), PetscOptionsEnum() 1271 M*/ 1272 1273 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) 1274 { 1275 PetscErrorCode ierr; 1276 PetscInt i; 1277 PetscOptionItem amsopt; 1278 PetscBool lset; 1279 1280 PetscFunctionBegin; 1281 if (!PetscOptionsObject->count) { 1282 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,ltext,man,OPTION_ELIST,&amsopt);CHKERRQ(ierr); 1283 /* must use system malloc since SAWs may free this */ 1284 ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr); 1285 ierr = PetscStrNArrayallocpy(ntext,list,(char***)&amsopt->list);CHKERRQ(ierr); 1286 amsopt->nlist = ntext; 1287 } 1288 ierr = PetscOptionsGetEList(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,list,ntext,value,&lset);CHKERRQ(ierr); 1289 if (set) *set = lset; 1290 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1291 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <now %s : formerly %s> %s (choose one of)",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,lset && value ? list[*value] : currentvalue,currentvalue,ltext);CHKERRQ(ierr); 1292 for (i=0; i<ntext; i++) { 1293 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s",list[i]);CHKERRQ(ierr); 1294 } 1295 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," (%s)\n",ManSection(man));CHKERRQ(ierr); 1296 } 1297 PetscFunctionReturn(0); 1298 } 1299 1300 /*MC 1301 PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for 1302 which at most a single value can be true. 1303 1304 Logically Collective on the communicator passed in PetscOptionsBegin() 1305 1306 Synopsis: 1307 #include "petscsys.h" 1308 PetscErrorCode PetscOptionsBoolGroupBegin(const char opt[],const char text[],const char man[],PetscBool *flg) 1309 1310 Input Parameters: 1311 + opt - option name 1312 . text - short string that describes the option 1313 - man - manual page with additional information on option 1314 1315 Output Parameter: 1316 . flg - whether that option was set or not 1317 1318 Level: intermediate 1319 1320 Notes: 1321 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1322 1323 Must be followed by 0 or more PetscOptionsBoolGroup()s and PetscOptionsBoolGroupEnd() 1324 1325 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1326 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1327 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1328 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1329 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1330 PetscOptionsFList(), PetscOptionsEList() 1331 M*/ 1332 1333 PetscErrorCode PetscOptionsBoolGroupBegin_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool *flg) 1334 { 1335 PetscErrorCode ierr; 1336 PetscOptionItem amsopt; 1337 1338 PetscFunctionBegin; 1339 if (!PetscOptionsObject->count) { 1340 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1341 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1342 1343 *(PetscBool*)amsopt->data = PETSC_FALSE; 1344 } 1345 *flg = PETSC_FALSE; 1346 ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr); 1347 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1348 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," Pick at most one of -------------\n");CHKERRQ(ierr); 1349 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1350 } 1351 PetscFunctionReturn(0); 1352 } 1353 1354 /*MC 1355 PetscOptionsBoolGroup - One in a series of logical queries on the options database for 1356 which at most a single value can be true. 1357 1358 Logically Collective on the communicator passed in PetscOptionsBegin() 1359 1360 Synopsis: 1361 #include "petscsys.h" 1362 PetscErrorCode PetscOptionsBoolGroup(const char opt[],const char text[],const char man[],PetscBool *flg) 1363 1364 Input Parameters: 1365 + opt - option name 1366 . text - short string that describes the option 1367 - man - manual page with additional information on option 1368 1369 Output Parameter: 1370 . flg - PETSC_TRUE if found, else PETSC_FALSE 1371 1372 Level: intermediate 1373 1374 Notes: 1375 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1376 1377 Must follow a PetscOptionsBoolGroupBegin() and preceded a PetscOptionsBoolGroupEnd() 1378 1379 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1380 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1381 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1382 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1383 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1384 PetscOptionsFList(), PetscOptionsEList() 1385 M*/ 1386 1387 PetscErrorCode PetscOptionsBoolGroup_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool *flg) 1388 { 1389 PetscErrorCode ierr; 1390 PetscOptionItem amsopt; 1391 1392 PetscFunctionBegin; 1393 if (!PetscOptionsObject->count) { 1394 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1395 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1396 1397 *(PetscBool*)amsopt->data = PETSC_FALSE; 1398 } 1399 *flg = PETSC_FALSE; 1400 ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr); 1401 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1402 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1403 } 1404 PetscFunctionReturn(0); 1405 } 1406 1407 /*MC 1408 PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for 1409 which at most a single value can be true. 1410 1411 Logically Collective on the communicator passed in PetscOptionsBegin() 1412 1413 Synopsis: 1414 #include "petscsys.h" 1415 PetscErrorCode PetscOptionsBoolGroupEnd(const char opt[],const char text[],const char man[],PetscBool *flg) 1416 1417 Input Parameters: 1418 + opt - option name 1419 . text - short string that describes the option 1420 - man - manual page with additional information on option 1421 1422 Output Parameter: 1423 . flg - PETSC_TRUE if found, else PETSC_FALSE 1424 1425 Level: intermediate 1426 1427 Notes: 1428 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1429 1430 Must follow a PetscOptionsBoolGroupBegin() 1431 1432 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1433 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1434 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1435 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1436 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1437 PetscOptionsFList(), PetscOptionsEList() 1438 M*/ 1439 1440 PetscErrorCode PetscOptionsBoolGroupEnd_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool *flg) 1441 { 1442 PetscErrorCode ierr; 1443 PetscOptionItem amsopt; 1444 1445 PetscFunctionBegin; 1446 if (!PetscOptionsObject->count) { 1447 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1448 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1449 1450 *(PetscBool*)amsopt->data = PETSC_FALSE; 1451 } 1452 *flg = PETSC_FALSE; 1453 ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr); 1454 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1455 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1456 } 1457 PetscFunctionReturn(0); 1458 } 1459 1460 /*MC 1461 PetscOptionsBool - Determines if a particular option is in the database with a true or false 1462 1463 Logically Collective on the communicator passed in PetscOptionsBegin() 1464 1465 Synopsis: 1466 #include "petscsys.h" 1467 PetscErrorCode PetscOptionsBool(const char opt[],const char text[],const char man[],PetscBool currentvalue,PetscBool *flg,PetscBool *set) 1468 1469 Input Parameters: 1470 + opt - option name 1471 . text - short string that describes the option 1472 . man - manual page with additional information on option 1473 - currentvalue - the current value 1474 1475 Output Parameters: 1476 + flg - PETSC_TRUE or PETSC_FALSE 1477 - set - PETSC_TRUE if found, else PETSC_FALSE 1478 1479 Notes: 1480 TRUE, true, YES, yes, nostring, and 1 all translate to PETSC_TRUE 1481 FALSE, false, NO, no, and 0 all translate to PETSC_FALSE 1482 1483 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 1484 is equivalent to -requested_bool true 1485 1486 If the user does not supply the option at all flg is NOT changed. Thus 1487 you should ALWAYS initialize the flg if you access it without first checking if the set flag is true. 1488 1489 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1490 1491 Level: beginner 1492 1493 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 1494 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), 1495 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), 1496 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1497 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1498 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1499 PetscOptionsFList(), PetscOptionsEList() 1500 M*/ 1501 1502 PetscErrorCode PetscOptionsBool_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool currentvalue,PetscBool *flg,PetscBool *set) 1503 { 1504 PetscErrorCode ierr; 1505 PetscBool iset; 1506 PetscOptionItem amsopt; 1507 1508 PetscFunctionBegin; 1509 if (!PetscOptionsObject->count) { 1510 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1511 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1512 1513 *(PetscBool*)amsopt->data = currentvalue; 1514 } 1515 ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,&iset);CHKERRQ(ierr); 1516 if (set) *set = iset; 1517 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1518 const char *v = PetscBools[currentvalue], *vn = PetscBools[iset && flg ? *flg : currentvalue]; 1519 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: <%s : %s> %s (%s)\n",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,v,vn,text,ManSection(man));CHKERRQ(ierr); 1520 } 1521 PetscFunctionReturn(0); 1522 } 1523 1524 /*MC 1525 PetscOptionsRealArray - Gets an array of double values for a particular 1526 option in the database. The values must be separated with commas with 1527 no intervening spaces. 1528 1529 Logically Collective on the communicator passed in PetscOptionsBegin() 1530 1531 Synopsis: 1532 #include "petscsys.h" 1533 PetscErrorCode PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool *set) 1534 1535 Input Parameters: 1536 + opt - the option one is seeking 1537 . text - short string describing option 1538 . man - manual page for option 1539 - nmax - maximum number of values 1540 1541 Output Parameters: 1542 + value - location to copy values 1543 . nmax - actual number of values found 1544 - set - PETSC_TRUE if found, else PETSC_FALSE 1545 1546 Level: beginner 1547 1548 Notes: 1549 The user should pass in an array of doubles 1550 1551 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1552 1553 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1554 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1555 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1556 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1557 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1558 PetscOptionsFList(), PetscOptionsEList() 1559 M*/ 1560 1561 PetscErrorCode PetscOptionsRealArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool *set) 1562 { 1563 PetscErrorCode ierr; 1564 PetscInt i; 1565 PetscOptionItem amsopt; 1566 1567 PetscFunctionBegin; 1568 if (!PetscOptionsObject->count) { 1569 PetscReal *vals; 1570 1571 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr); 1572 ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr); 1573 vals = (PetscReal*)amsopt->data; 1574 for (i=0; i<*n; i++) vals[i] = value[i]; 1575 amsopt->arraylength = *n; 1576 } 1577 ierr = PetscOptionsGetRealArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr); 1578 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1579 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%g",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,(double)value[0]);CHKERRQ(ierr); 1580 for (i=1; i<*n; i++) { 1581 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%g",(double)value[i]);CHKERRQ(ierr); 1582 } 1583 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1584 } 1585 PetscFunctionReturn(0); 1586 } 1587 1588 /*MC 1589 PetscOptionsScalarArray - Gets an array of Scalar values for a particular 1590 option in the database. The values must be separated with commas with 1591 no intervening spaces. 1592 1593 Logically Collective on the communicator passed in PetscOptionsBegin() 1594 1595 Synopsis: 1596 #include "petscsys.h" 1597 PetscErrorCode PetscOptionsScalarArray(const char opt[],const char text[],const char man[],PetscScalar value[],PetscInt *n,PetscBool *set) 1598 1599 Input Parameters: 1600 + opt - the option one is seeking 1601 . text - short string describing option 1602 . man - manual page for option 1603 - nmax - maximum number of values 1604 1605 Output Parameters: 1606 + value - location to copy values 1607 . nmax - actual number of values found 1608 - set - PETSC_TRUE if found, else PETSC_FALSE 1609 1610 Level: beginner 1611 1612 Notes: 1613 The user should pass in an array of doubles 1614 1615 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1616 1617 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1618 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1619 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1620 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1621 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1622 PetscOptionsFList(), PetscOptionsEList() 1623 M*/ 1624 1625 PetscErrorCode PetscOptionsScalarArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscScalar value[],PetscInt *n,PetscBool *set) 1626 { 1627 PetscErrorCode ierr; 1628 PetscInt i; 1629 PetscOptionItem amsopt; 1630 1631 PetscFunctionBegin; 1632 if (!PetscOptionsObject->count) { 1633 PetscScalar *vals; 1634 1635 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_SCALAR_ARRAY,&amsopt);CHKERRQ(ierr); 1636 ierr = PetscMalloc((*n)*sizeof(PetscScalar),&amsopt->data);CHKERRQ(ierr); 1637 vals = (PetscScalar*)amsopt->data; 1638 for (i=0; i<*n; i++) vals[i] = value[i]; 1639 amsopt->arraylength = *n; 1640 } 1641 ierr = PetscOptionsGetScalarArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr); 1642 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1643 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%g+%gi",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,(double)PetscRealPart(value[0]),(double)PetscImaginaryPart(value[0]));CHKERRQ(ierr); 1644 for (i=1; i<*n; i++) { 1645 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%g+%gi",(double)PetscRealPart(value[i]),(double)PetscImaginaryPart(value[i]));CHKERRQ(ierr); 1646 } 1647 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1648 } 1649 PetscFunctionReturn(0); 1650 } 1651 1652 /*MC 1653 PetscOptionsIntArray - Gets an array of integers for a particular 1654 option in the database. 1655 1656 Logically Collective on the communicator passed in PetscOptionsBegin() 1657 1658 Synopsis: 1659 #include "petscsys.h" 1660 PetscErrorCode PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool *set) 1661 1662 Input Parameters: 1663 + opt - the option one is seeking 1664 . text - short string describing option 1665 . man - manual page for option 1666 - n - maximum number of values 1667 1668 Output Parameters: 1669 + value - location to copy values 1670 . n - actual number of values found 1671 - set - PETSC_TRUE if found, else PETSC_FALSE 1672 1673 Level: beginner 1674 1675 Notes: 1676 The array can be passed as 1677 a comma separated list: 0,1,2,3,4,5,6,7 1678 a range (start-end+1): 0-8 1679 a range with given increment (start-end+1:inc): 0-7:2 1680 a combination of values and ranges separated by commas: 0,1-8,8-15:2 1681 1682 There must be no intervening spaces between the values. 1683 1684 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1685 1686 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1687 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1688 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1689 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1690 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1691 PetscOptionsFList(), PetscOptionsEList(), PetscOptionsRealArray() 1692 M*/ 1693 1694 PetscErrorCode PetscOptionsIntArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool *set) 1695 { 1696 PetscErrorCode ierr; 1697 PetscInt i; 1698 PetscOptionItem amsopt; 1699 1700 PetscFunctionBegin; 1701 if (!PetscOptionsObject->count) { 1702 PetscInt *vals; 1703 1704 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr); 1705 ierr = PetscMalloc1(*n,(PetscInt**)&amsopt->data);CHKERRQ(ierr); 1706 vals = (PetscInt*)amsopt->data; 1707 for (i=0; i<*n; i++) vals[i] = value[i]; 1708 amsopt->arraylength = *n; 1709 } 1710 ierr = PetscOptionsGetIntArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr); 1711 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1712 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%d",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,value[0]);CHKERRQ(ierr); 1713 for (i=1; i<*n; i++) { 1714 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%d",value[i]);CHKERRQ(ierr); 1715 } 1716 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1717 } 1718 PetscFunctionReturn(0); 1719 } 1720 1721 /*MC 1722 PetscOptionsStringArray - Gets an array of string values for a particular 1723 option in the database. The values must be separated with commas with 1724 no intervening spaces. 1725 1726 Logically Collective on the communicator passed in PetscOptionsBegin() 1727 1728 Synopsis: 1729 #include "petscsys.h" 1730 PetscErrorCode PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool *set) 1731 1732 Input Parameters: 1733 + opt - the option one is seeking 1734 . text - short string describing option 1735 . man - manual page for option 1736 - nmax - maximum number of strings 1737 1738 Output Parameters: 1739 + value - location to copy strings 1740 . nmax - actual number of strings found 1741 - set - PETSC_TRUE if found, else PETSC_FALSE 1742 1743 Level: beginner 1744 1745 Notes: 1746 The user should pass in an array of pointers to char, to hold all the 1747 strings returned by this function. 1748 1749 The user is responsible for deallocating the strings that are 1750 returned. The Fortran interface for this routine is not supported. 1751 1752 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1753 1754 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1755 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1756 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1757 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1758 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1759 PetscOptionsFList(), PetscOptionsEList() 1760 M*/ 1761 1762 PetscErrorCode PetscOptionsStringArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool *set) 1763 { 1764 PetscErrorCode ierr; 1765 PetscOptionItem amsopt; 1766 1767 PetscFunctionBegin; 1768 if (!PetscOptionsObject->count) { 1769 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING_ARRAY,&amsopt);CHKERRQ(ierr); 1770 ierr = PetscMalloc1(*nmax,(char**)&amsopt->data);CHKERRQ(ierr); 1771 1772 amsopt->arraylength = *nmax; 1773 } 1774 ierr = PetscOptionsGetStringArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,nmax,set);CHKERRQ(ierr); 1775 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1776 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1777 } 1778 PetscFunctionReturn(0); 1779 } 1780 1781 /*MC 1782 PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular 1783 option in the database. The values must be separated with commas with 1784 no intervening spaces. 1785 1786 Logically Collective on the communicator passed in PetscOptionsBegin() 1787 1788 Synopsis: 1789 #include "petscsys.h" 1790 PetscErrorCode PetscOptionsBoolArray(const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set) 1791 1792 Input Parameters: 1793 + opt - the option one is seeking 1794 . text - short string describing option 1795 . man - manual page for option 1796 - nmax - maximum number of values 1797 1798 Output Parameters: 1799 + value - location to copy values 1800 . nmax - actual number of values found 1801 - set - PETSC_TRUE if found, else PETSC_FALSE 1802 1803 Level: beginner 1804 1805 Notes: 1806 The user should pass in an array of doubles 1807 1808 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1809 1810 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1811 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1812 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1813 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1814 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1815 PetscOptionsFList(), PetscOptionsEList() 1816 M*/ 1817 1818 PetscErrorCode PetscOptionsBoolArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set) 1819 { 1820 PetscErrorCode ierr; 1821 PetscInt i; 1822 PetscOptionItem amsopt; 1823 1824 PetscFunctionBegin; 1825 if (!PetscOptionsObject->count) { 1826 PetscBool *vals; 1827 1828 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL_ARRAY,&amsopt);CHKERRQ(ierr); 1829 ierr = PetscMalloc1(*n,(PetscBool**)&amsopt->data);CHKERRQ(ierr); 1830 vals = (PetscBool*)amsopt->data; 1831 for (i=0; i<*n; i++) vals[i] = value[i]; 1832 amsopt->arraylength = *n; 1833 } 1834 ierr = PetscOptionsGetBoolArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr); 1835 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1836 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%d",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,value[0]);CHKERRQ(ierr); 1837 for (i=1; i<*n; i++) { 1838 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%d",value[i]);CHKERRQ(ierr); 1839 } 1840 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1841 } 1842 PetscFunctionReturn(0); 1843 } 1844 1845 /*MC 1846 PetscOptionsViewer - Gets a viewer appropriate for the type indicated by the user 1847 1848 Logically Collective on the communicator passed in PetscOptionsBegin() 1849 1850 Synopsis: 1851 #include "petscsys.h" 1852 PetscErrorCode PetscOptionsViewer(const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool *set) 1853 1854 Input Parameters: 1855 + opt - option name 1856 . text - short string that describes the option 1857 - man - manual page with additional information on option 1858 1859 Output Parameters: 1860 + viewer - the viewer 1861 - set - PETSC_TRUE if found, else PETSC_FALSE 1862 1863 Level: beginner 1864 1865 Notes: 1866 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1867 1868 See PetscOptionsGetViewer() for the format of the supplied viewer and its options 1869 1870 .seealso: PetscOptionsGetViewer(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 1871 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 1872 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 1873 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1874 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1875 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1876 PetscOptionsFList(), PetscOptionsEList() 1877 M*/ 1878 1879 PetscErrorCode PetscOptionsViewer_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool *set) 1880 { 1881 PetscErrorCode ierr; 1882 PetscOptionItem amsopt; 1883 1884 PetscFunctionBegin; 1885 if (!PetscOptionsObject->count) { 1886 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr); 1887 /* must use system malloc since SAWs may free this */ 1888 ierr = PetscStrdup("",(char**)&amsopt->data);CHKERRQ(ierr); 1889 } 1890 ierr = PetscOptionsGetViewer(PetscOptionsObject->comm,PetscOptionsObject->options,PetscOptionsObject->prefix,opt,viewer,format,set);CHKERRQ(ierr); 1891 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1892 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%s>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,"",text,ManSection(man));CHKERRQ(ierr); 1893 } 1894 PetscFunctionReturn(0); 1895 } 1896 1897 /*@C 1898 PetscOptionsHead - Puts a heading before listing any more published options. Used, for example, 1899 in KSPSetFromOptions_GMRES(). 1900 1901 Logically Collective on the communicator passed in PetscOptionsBegin() 1902 1903 Input Parameter: 1904 . head - the heading text 1905 1906 Level: intermediate 1907 1908 Notes: 1909 Must be between a PetscOptionsBegin() and a PetscOptionsEnd(), and PetscOptionsObject created in PetscOptionsBegin() should be the first argument 1910 1911 Can be followed by a call to PetscOptionsTail() in the same function. 1912 1913 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1914 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1915 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1916 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1917 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1918 PetscOptionsFList(), PetscOptionsEList() 1919 @*/ 1920 PetscErrorCode PetscOptionsHead(PetscOptionItems *PetscOptionsObject,const char head[]) 1921 { 1922 PetscErrorCode ierr; 1923 1924 PetscFunctionBegin; 1925 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1926 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s\n",head);CHKERRQ(ierr); 1927 } 1928 PetscFunctionReturn(0); 1929 } 1930 1931