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 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 668 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 669 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 670 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 671 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 672 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 673 PetscOptionsFList(), PetscOptionsEList() 674 @*/ 675 PetscErrorCode PetscOptionsEnum_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],const char *const *list,PetscEnum currentvalue,PetscEnum *value,PetscBool *set) 676 { 677 PetscErrorCode ierr; 678 PetscInt ntext = 0; 679 PetscInt tval; 680 PetscBool tflg; 681 682 PetscFunctionBegin; 683 while (list[ntext++]) { 684 if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries"); 685 } 686 if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix"); 687 ntext -= 3; 688 ierr = PetscOptionsEList_Private(PetscOptionsObject,opt,text,man,list,ntext,list[currentvalue],&tval,&tflg);CHKERRQ(ierr); 689 /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */ 690 if (tflg) *value = (PetscEnum)tval; 691 if (set) *set = tflg; 692 PetscFunctionReturn(0); 693 } 694 695 /*@C 696 PetscOptionsEnumArray - Gets an array of enum values for a particular 697 option in the database. 698 699 Logically Collective on the communicator passed in PetscOptionsBegin() 700 701 Input Parameters: 702 + opt - the option one is seeking 703 . text - short string describing option 704 . man - manual page for option 705 - n - maximum number of values 706 707 Output Parameter: 708 + value - location to copy values 709 . n - actual number of values found 710 - set - PETSC_TRUE if found, else PETSC_FALSE 711 712 Level: beginner 713 714 Notes: 715 The array must be passed as a comma separated list. 716 717 There must be no intervening spaces between the values. 718 719 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 720 721 Concepts: options database^array of enums 722 723 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 724 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 725 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 726 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 727 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 728 PetscOptionsFList(), PetscOptionsEList(), PetscOptionsRealArray() 729 @*/ 730 PetscErrorCode PetscOptionsEnumArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],const char *const *list,PetscEnum value[],PetscInt *n,PetscBool *set) 731 { 732 PetscInt i,nlist = 0; 733 PetscOptionItem amsopt; 734 PetscErrorCode ierr; 735 736 PetscFunctionBegin; 737 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"); 738 if (nlist < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix"); 739 nlist -= 3; /* drop enum name, prefix, and null termination */ 740 if (0 && !PetscOptionsObject->count) { /* XXX Requires additional support */ 741 PetscEnum *vals; 742 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT_ARRAY/*XXX OPTION_ENUM_ARRAY*/,&amsopt);CHKERRQ(ierr); 743 ierr = PetscStrNArrayallocpy(nlist,list,(char***)&amsopt->list);CHKERRQ(ierr); 744 amsopt->nlist = nlist; 745 ierr = PetscMalloc1(*n,(PetscEnum**)&amsopt->data);CHKERRQ(ierr); 746 amsopt->arraylength = *n; 747 vals = (PetscEnum*)amsopt->data; 748 for (i=0; i<*n; i++) vals[i] = value[i]; 749 } 750 ierr = PetscOptionsGetEnumArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,list,value,n,set);CHKERRQ(ierr); 751 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 752 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%s",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,list[value[0]]);CHKERRQ(ierr); 753 for (i=1; i<*n; i++) {ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%s",list[value[i]]);CHKERRQ(ierr);} 754 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (choose from)",text);CHKERRQ(ierr); 755 for (i=0; i<nlist; i++) {ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s",list[i]);CHKERRQ(ierr);} 756 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," (%s)\n",ManSection(man));CHKERRQ(ierr); 757 } 758 PetscFunctionReturn(0); 759 } 760 761 /* -------------------------------------------------------------------------------------------------------------*/ 762 /*@C 763 PetscOptionsInt - Gets the integer value for a particular option in the database. 764 765 Logically Collective on the communicator passed in PetscOptionsBegin() 766 767 Input Parameters: 768 + opt - option name 769 . text - short string that describes the option 770 . man - manual page with additional information on option 771 - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 772 $ PetscOptionsInt(..., obj->value,&object->value,...) or 773 $ value = defaultvalue 774 $ PetscOptionsInt(..., value,&value,&flg); 775 $ if (flg) { 776 777 Output Parameter: 778 + value - the integer value to return 779 - flg - PETSC_TRUE if found, else PETSC_FALSE 780 781 Level: beginner 782 783 Concepts: options database^has int 784 785 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 786 787 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 788 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 789 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 790 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 791 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 792 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 793 PetscOptionsFList(), PetscOptionsEList() 794 @*/ 795 PetscErrorCode PetscOptionsInt_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *set) 796 { 797 PetscErrorCode ierr; 798 PetscOptionItem amsopt; 799 PetscBool wasset; 800 801 PetscFunctionBegin; 802 if (!PetscOptionsObject->count) { 803 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr); 804 ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr); 805 *(PetscInt*)amsopt->data = currentvalue; 806 807 ierr = PetscOptionsGetInt(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,¤tvalue,&wasset);CHKERRQ(ierr); 808 if (wasset) { 809 *(PetscInt*)amsopt->data = currentvalue; 810 } 811 } 812 ierr = PetscOptionsGetInt(NULL,PetscOptionsObject->prefix,opt,value,set);CHKERRQ(ierr); 813 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 814 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%d>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,currentvalue,text,ManSection(man));CHKERRQ(ierr); 815 } 816 PetscFunctionReturn(0); 817 } 818 819 /*@C 820 PetscOptionsString - Gets the string value for a particular option in the database. 821 822 Logically Collective on the communicator passed in PetscOptionsBegin() 823 824 Input Parameters: 825 + opt - option name 826 . text - short string that describes the option 827 . man - manual page with additional information on option 828 . currentvalue - the current value; caller is responsible for setting this value correctly. This is not used to set value 829 - len - length of the result string including null terminator 830 831 Output Parameter: 832 + value - the value to return 833 - flg - PETSC_TRUE if found, else PETSC_FALSE 834 835 Level: beginner 836 837 Concepts: options database^has int 838 839 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 840 841 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). 842 843 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(NULL,), 844 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 845 PetscOptionsInt(), PetscOptionsReal(), PetscOptionsBool(), 846 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 847 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 848 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 849 PetscOptionsFList(), PetscOptionsEList() 850 @*/ 851 PetscErrorCode PetscOptionsString_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],const char currentvalue[],char value[],size_t len,PetscBool *set) 852 { 853 PetscErrorCode ierr; 854 PetscOptionItem amsopt; 855 856 PetscFunctionBegin; 857 if (!PetscOptionsObject->count) { 858 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr); 859 /* must use system malloc since SAWs may free this */ 860 ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr); 861 } 862 ierr = PetscOptionsGetString(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,len,set);CHKERRQ(ierr); 863 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 864 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%s>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,currentvalue,text,ManSection(man));CHKERRQ(ierr); 865 } 866 PetscFunctionReturn(0); 867 } 868 869 /*@C 870 PetscOptionsReal - Gets the PetscReal value for a particular option in the database. 871 872 Logically Collective on the communicator passed in PetscOptionsBegin() 873 874 Input Parameters: 875 + opt - option name 876 . text - short string that describes the option 877 . man - manual page with additional information on option 878 - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 879 $ PetscOptionsReal(..., obj->value,&object->value,...) or 880 $ value = defaultvalue 881 $ PetscOptionsReal(..., value,&value,&flg); 882 $ if (flg) { 883 884 Output Parameter: 885 + value - the value to return 886 - flg - PETSC_TRUE if found, else PETSC_FALSE 887 888 Level: beginner 889 890 Concepts: options database^has int 891 892 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 893 894 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(NULL,), 895 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 896 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 897 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 898 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 899 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 900 PetscOptionsFList(), PetscOptionsEList() 901 @*/ 902 PetscErrorCode PetscOptionsReal_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscReal currentvalue,PetscReal *value,PetscBool *set) 903 { 904 PetscErrorCode ierr; 905 PetscOptionItem amsopt; 906 907 PetscFunctionBegin; 908 if (!PetscOptionsObject->count) { 909 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr); 910 ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr); 911 912 *(PetscReal*)amsopt->data = currentvalue; 913 } 914 ierr = PetscOptionsGetReal(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,set);CHKERRQ(ierr); 915 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 916 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%g>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,(double)currentvalue,text,ManSection(man));CHKERRQ(ierr); 917 } 918 PetscFunctionReturn(0); 919 } 920 921 /*@C 922 PetscOptionsScalar - Gets the scalar value for a particular option in the database. 923 924 Logically Collective on the communicator passed in PetscOptionsBegin() 925 926 Input Parameters: 927 + opt - option name 928 . text - short string that describes the option 929 . man - manual page with additional information on option 930 - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 931 $ PetscOptionsScalar(..., obj->value,&object->value,...) or 932 $ value = defaultvalue 933 $ PetscOptionsScalar(..., value,&value,&flg); 934 $ if (flg) { 935 936 937 Output Parameter: 938 + value - the value to return 939 - flg - PETSC_TRUE if found, else PETSC_FALSE 940 941 Level: beginner 942 943 Concepts: options database^has int 944 945 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 946 947 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(NULL,), 948 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 949 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 950 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 951 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 952 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 953 PetscOptionsFList(), PetscOptionsEList() 954 @*/ 955 PetscErrorCode PetscOptionsScalar_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscScalar currentvalue,PetscScalar *value,PetscBool *set) 956 { 957 PetscErrorCode ierr; 958 959 PetscFunctionBegin; 960 #if !defined(PETSC_USE_COMPLEX) 961 ierr = PetscOptionsReal(opt,text,man,currentvalue,value,set);CHKERRQ(ierr); 962 #else 963 ierr = PetscOptionsGetScalar(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,set);CHKERRQ(ierr); 964 #endif 965 PetscFunctionReturn(0); 966 } 967 968 /*@C 969 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 970 its value is set to false. 971 972 Logically Collective on the communicator passed in PetscOptionsBegin() 973 974 Input Parameters: 975 + opt - option name 976 . text - short string that describes the option 977 - man - manual page with additional information on option 978 979 Output Parameter: 980 . flg - PETSC_TRUE if found, else PETSC_FALSE 981 982 Level: beginner 983 984 Concepts: options database^has int 985 986 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 987 988 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(NULL,), 989 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 990 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 991 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 992 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 993 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 994 PetscOptionsFList(), PetscOptionsEList() 995 @*/ 996 PetscErrorCode PetscOptionsName_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool *flg) 997 { 998 PetscErrorCode ierr; 999 PetscOptionItem amsopt; 1000 1001 PetscFunctionBegin; 1002 if (!PetscOptionsObject->count) { 1003 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1004 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1005 1006 *(PetscBool*)amsopt->data = PETSC_FALSE; 1007 } 1008 ierr = PetscOptionsHasName(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg);CHKERRQ(ierr); 1009 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1010 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1011 } 1012 PetscFunctionReturn(0); 1013 } 1014 1015 /*@C 1016 PetscOptionsFList - Puts a list of option values that a single one may be selected from 1017 1018 Logically Collective on the communicator passed in PetscOptionsBegin() 1019 1020 Input Parameters: 1021 + opt - option name 1022 . text - short string that describes the option 1023 . man - manual page with additional information on option 1024 . list - the possible choices 1025 . currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with 1026 $ PetscOptionsFlist(..., obj->value,value,len,&flg); 1027 $ if (flg) { 1028 - len - the length of the character array value 1029 1030 Output Parameter: 1031 + value - the value to return 1032 - set - PETSC_TRUE if found, else PETSC_FALSE 1033 1034 Level: intermediate 1035 1036 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1037 1038 See PetscOptionsEList() for when the choices are given in a string array 1039 1040 To get a listing of all currently specified options, 1041 see PetscOptionsView() or PetscOptionsGetAll() 1042 1043 Developer Note: This cannot check for invalid selection because of things like MATAIJ that are not included in the list 1044 1045 Concepts: options database^list 1046 1047 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1048 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1049 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1050 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1051 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1052 PetscOptionsFList(), PetscOptionsEList(), PetscOptionsEnum() 1053 @*/ 1054 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) 1055 { 1056 PetscErrorCode ierr; 1057 PetscOptionItem amsopt; 1058 1059 PetscFunctionBegin; 1060 if (!PetscOptionsObject->count) { 1061 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,ltext,man,OPTION_FLIST,&amsopt);CHKERRQ(ierr); 1062 /* must use system malloc since SAWs may free this */ 1063 ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr); 1064 amsopt->flist = list; 1065 } 1066 ierr = PetscOptionsGetString(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,len,set);CHKERRQ(ierr); 1067 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1068 ierr = PetscFunctionListPrintTypes(PetscOptionsObject->comm,stdout,PetscOptionsObject->prefix,opt,ltext,man,list,currentvalue);CHKERRQ(ierr);CHKERRQ(ierr); 1069 } 1070 PetscFunctionReturn(0); 1071 } 1072 1073 /*@C 1074 PetscOptionsEList - Puts a list of option values that a single one may be selected from 1075 1076 Logically Collective on the communicator passed in PetscOptionsBegin() 1077 1078 Input Parameters: 1079 + opt - option name 1080 . ltext - short string that describes the option 1081 . man - manual page with additional information on option 1082 . list - the possible choices (one of these must be selected, anything else is invalid) 1083 . ntext - number of choices 1084 - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with 1085 $ PetscOptionsElist(..., obj->value,&value,&flg); 1086 $ if (flg) { 1087 1088 1089 Output Parameter: 1090 + value - the index of the value to return 1091 - set - PETSC_TRUE if found, else PETSC_FALSE 1092 1093 Level: intermediate 1094 1095 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1096 1097 See PetscOptionsFList() for when the choices are given in a PetscFunctionList() 1098 1099 Concepts: options database^list 1100 1101 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1102 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1103 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1104 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1105 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1106 PetscOptionsFList(), PetscOptionsEnum() 1107 @*/ 1108 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) 1109 { 1110 PetscErrorCode ierr; 1111 PetscInt i; 1112 PetscOptionItem amsopt; 1113 1114 PetscFunctionBegin; 1115 if (!PetscOptionsObject->count) { 1116 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,ltext,man,OPTION_ELIST,&amsopt);CHKERRQ(ierr); 1117 /* must use system malloc since SAWs may free this */ 1118 ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr); 1119 ierr = PetscStrNArrayallocpy(ntext,list,(char***)&amsopt->list);CHKERRQ(ierr); 1120 amsopt->nlist = ntext; 1121 } 1122 ierr = PetscOptionsGetEList(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,list,ntext,value,set);CHKERRQ(ierr); 1123 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1124 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%s> %s (choose one of)",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,currentvalue,ltext);CHKERRQ(ierr); 1125 for (i=0; i<ntext; i++) { 1126 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s",list[i]);CHKERRQ(ierr); 1127 } 1128 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," (%s)\n",ManSection(man));CHKERRQ(ierr); 1129 } 1130 PetscFunctionReturn(0); 1131 } 1132 1133 /*@C 1134 PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for 1135 which at most a single value can be true. 1136 1137 Logically Collective on the communicator passed in PetscOptionsBegin() 1138 1139 Input Parameters: 1140 + opt - option name 1141 . text - short string that describes the option 1142 - man - manual page with additional information on option 1143 1144 Output Parameter: 1145 . flg - whether that option was set or not 1146 1147 Level: intermediate 1148 1149 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1150 1151 Must be followed by 0 or more PetscOptionsBoolGroup()s and PetscOptionsBoolGroupEnd() 1152 1153 Concepts: options database^logical group 1154 1155 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1156 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1157 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1158 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1159 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1160 PetscOptionsFList(), PetscOptionsEList() 1161 @*/ 1162 PetscErrorCode PetscOptionsBoolGroupBegin_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool *flg) 1163 { 1164 PetscErrorCode ierr; 1165 PetscOptionItem amsopt; 1166 1167 PetscFunctionBegin; 1168 if (!PetscOptionsObject->count) { 1169 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1170 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1171 1172 *(PetscBool*)amsopt->data = PETSC_FALSE; 1173 } 1174 *flg = PETSC_FALSE; 1175 ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr); 1176 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1177 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," Pick at most one of -------------\n");CHKERRQ(ierr); 1178 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1179 } 1180 PetscFunctionReturn(0); 1181 } 1182 1183 /*@C 1184 PetscOptionsBoolGroup - One in a series of logical queries on the options database for 1185 which at most a single value can be true. 1186 1187 Logically Collective on the communicator passed in PetscOptionsBegin() 1188 1189 Input Parameters: 1190 + opt - option name 1191 . text - short string that describes the option 1192 - man - manual page with additional information on option 1193 1194 Output Parameter: 1195 . flg - PETSC_TRUE if found, else PETSC_FALSE 1196 1197 Level: intermediate 1198 1199 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1200 1201 Must follow a PetscOptionsBoolGroupBegin() and preceded a PetscOptionsBoolGroupEnd() 1202 1203 Concepts: options database^logical group 1204 1205 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1206 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1207 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1208 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1209 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1210 PetscOptionsFList(), PetscOptionsEList() 1211 @*/ 1212 PetscErrorCode PetscOptionsBoolGroup_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool *flg) 1213 { 1214 PetscErrorCode ierr; 1215 PetscOptionItem amsopt; 1216 1217 PetscFunctionBegin; 1218 if (!PetscOptionsObject->count) { 1219 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1220 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1221 1222 *(PetscBool*)amsopt->data = PETSC_FALSE; 1223 } 1224 *flg = PETSC_FALSE; 1225 ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr); 1226 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1227 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1228 } 1229 PetscFunctionReturn(0); 1230 } 1231 1232 /*@C 1233 PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for 1234 which at most a single value can be true. 1235 1236 Logically Collective on the communicator passed in PetscOptionsBegin() 1237 1238 Input Parameters: 1239 + opt - option name 1240 . text - short string that describes the option 1241 - man - manual page with additional information on option 1242 1243 Output Parameter: 1244 . flg - PETSC_TRUE if found, else PETSC_FALSE 1245 1246 Level: intermediate 1247 1248 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1249 1250 Must follow a PetscOptionsBoolGroupBegin() 1251 1252 Concepts: options database^logical group 1253 1254 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1255 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1256 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1257 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1258 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1259 PetscOptionsFList(), PetscOptionsEList() 1260 @*/ 1261 PetscErrorCode PetscOptionsBoolGroupEnd_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool *flg) 1262 { 1263 PetscErrorCode ierr; 1264 PetscOptionItem amsopt; 1265 1266 PetscFunctionBegin; 1267 if (!PetscOptionsObject->count) { 1268 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1269 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1270 1271 *(PetscBool*)amsopt->data = PETSC_FALSE; 1272 } 1273 *flg = PETSC_FALSE; 1274 ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr); 1275 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1276 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1277 } 1278 PetscFunctionReturn(0); 1279 } 1280 1281 /*@C 1282 PetscOptionsBool - Determines if a particular option is in the database with a true or false 1283 1284 Logically Collective on the communicator passed in PetscOptionsBegin() 1285 1286 Input Parameters: 1287 + opt - option name 1288 . text - short string that describes the option 1289 . man - manual page with additional information on option 1290 - currentvalue - the current value 1291 1292 Output Parameter: 1293 . flg - PETSC_TRUE or PETSC_FALSE 1294 . set - PETSC_TRUE if found, else PETSC_FALSE 1295 1296 Level: beginner 1297 1298 Concepts: options database^logical 1299 1300 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1301 1302 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(NULL,), 1303 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 1304 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 1305 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1306 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1307 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1308 PetscOptionsFList(), PetscOptionsEList() 1309 @*/ 1310 PetscErrorCode PetscOptionsBool_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool currentvalue,PetscBool *flg,PetscBool *set) 1311 { 1312 PetscErrorCode ierr; 1313 PetscBool iset; 1314 PetscOptionItem amsopt; 1315 1316 PetscFunctionBegin; 1317 if (!PetscOptionsObject->count) { 1318 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1319 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1320 1321 *(PetscBool*)amsopt->data = currentvalue; 1322 } 1323 ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,&iset);CHKERRQ(ierr); 1324 if (set) *set = iset; 1325 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1326 const char *v = PetscBools[currentvalue]; 1327 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: <%s> %s (%s)\n",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,v,text,ManSection(man));CHKERRQ(ierr); 1328 } 1329 PetscFunctionReturn(0); 1330 } 1331 1332 /*@C 1333 PetscOptionsRealArray - Gets an array of double values for a particular 1334 option in the database. The values must be separated with commas with 1335 no intervening spaces. 1336 1337 Logically Collective on the communicator passed in PetscOptionsBegin() 1338 1339 Input Parameters: 1340 + opt - the option one is seeking 1341 . text - short string describing option 1342 . man - manual page for option 1343 - nmax - maximum number of values 1344 1345 Output Parameter: 1346 + value - location to copy values 1347 . nmax - actual number of values found 1348 - set - PETSC_TRUE if found, else PETSC_FALSE 1349 1350 Level: beginner 1351 1352 Notes: 1353 The user should pass in an array of doubles 1354 1355 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1356 1357 Concepts: options database^array of strings 1358 1359 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1360 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1361 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1362 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1363 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1364 PetscOptionsFList(), PetscOptionsEList() 1365 @*/ 1366 PetscErrorCode PetscOptionsRealArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool *set) 1367 { 1368 PetscErrorCode ierr; 1369 PetscInt i; 1370 PetscOptionItem amsopt; 1371 1372 PetscFunctionBegin; 1373 if (!PetscOptionsObject->count) { 1374 PetscReal *vals; 1375 1376 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr); 1377 ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr); 1378 vals = (PetscReal*)amsopt->data; 1379 for (i=0; i<*n; i++) vals[i] = value[i]; 1380 amsopt->arraylength = *n; 1381 } 1382 ierr = PetscOptionsGetRealArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr); 1383 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1384 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%g",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,(double)value[0]);CHKERRQ(ierr); 1385 for (i=1; i<*n; i++) { 1386 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%g",(double)value[i]);CHKERRQ(ierr); 1387 } 1388 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1389 } 1390 PetscFunctionReturn(0); 1391 } 1392 1393 /*@C 1394 PetscOptionsScalarArray - Gets an array of Scalar values for a particular 1395 option in the database. The values must be separated with commas with 1396 no intervening spaces. 1397 1398 Logically Collective on the communicator passed in PetscOptionsBegin() 1399 1400 Input Parameters: 1401 + opt - the option one is seeking 1402 . text - short string describing option 1403 . man - manual page for option 1404 - nmax - maximum number of values 1405 1406 Output Parameter: 1407 + value - location to copy values 1408 . nmax - actual number of values found 1409 - set - PETSC_TRUE if found, else PETSC_FALSE 1410 1411 Level: beginner 1412 1413 Notes: 1414 The user should pass in an array of doubles 1415 1416 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1417 1418 Concepts: options database^array of strings 1419 1420 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1421 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1422 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1423 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1424 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1425 PetscOptionsFList(), PetscOptionsEList() 1426 @*/ 1427 PetscErrorCode PetscOptionsScalarArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscScalar value[],PetscInt *n,PetscBool *set) 1428 { 1429 PetscErrorCode ierr; 1430 PetscInt i; 1431 PetscOptionItem amsopt; 1432 1433 PetscFunctionBegin; 1434 if (!PetscOptionsObject->count) { 1435 PetscScalar *vals; 1436 1437 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_SCALAR_ARRAY,&amsopt);CHKERRQ(ierr); 1438 ierr = PetscMalloc((*n)*sizeof(PetscScalar),&amsopt->data);CHKERRQ(ierr); 1439 vals = (PetscScalar*)amsopt->data; 1440 for (i=0; i<*n; i++) vals[i] = value[i]; 1441 amsopt->arraylength = *n; 1442 } 1443 ierr = PetscOptionsGetScalarArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr); 1444 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1445 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%g+%gi",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,(double)PetscRealPart(value[0]),(double)PetscImaginaryPart(value[0]));CHKERRQ(ierr); 1446 for (i=1; i<*n; i++) { 1447 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%g+%gi",(double)PetscRealPart(value[i]),(double)PetscImaginaryPart(value[i]));CHKERRQ(ierr); 1448 } 1449 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1450 } 1451 PetscFunctionReturn(0); 1452 } 1453 1454 /*@C 1455 PetscOptionsIntArray - Gets an array of integers for a particular 1456 option in the database. 1457 1458 Logically Collective on the communicator passed in PetscOptionsBegin() 1459 1460 Input Parameters: 1461 + opt - the option one is seeking 1462 . text - short string describing option 1463 . man - manual page for option 1464 - n - maximum number of values 1465 1466 Output Parameter: 1467 + value - location to copy values 1468 . n - actual number of values found 1469 - set - PETSC_TRUE if found, else PETSC_FALSE 1470 1471 Level: beginner 1472 1473 Notes: 1474 The array can be passed as 1475 a comma separated list: 0,1,2,3,4,5,6,7 1476 a range (start-end+1): 0-8 1477 a range with given increment (start-end+1:inc): 0-7:2 1478 a combination of values and ranges separated by commas: 0,1-8,8-15:2 1479 1480 There must be no intervening spaces between the values. 1481 1482 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1483 1484 Concepts: options database^array of ints 1485 1486 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1487 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1488 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1489 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1490 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1491 PetscOptionsFList(), PetscOptionsEList(), PetscOptionsRealArray() 1492 @*/ 1493 PetscErrorCode PetscOptionsIntArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool *set) 1494 { 1495 PetscErrorCode ierr; 1496 PetscInt i; 1497 PetscOptionItem amsopt; 1498 1499 PetscFunctionBegin; 1500 if (!PetscOptionsObject->count) { 1501 PetscInt *vals; 1502 1503 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr); 1504 ierr = PetscMalloc1(*n,(PetscInt**)&amsopt->data);CHKERRQ(ierr); 1505 vals = (PetscInt*)amsopt->data; 1506 for (i=0; i<*n; i++) vals[i] = value[i]; 1507 amsopt->arraylength = *n; 1508 } 1509 ierr = PetscOptionsGetIntArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr); 1510 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1511 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%d",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,value[0]);CHKERRQ(ierr); 1512 for (i=1; i<*n; i++) { 1513 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%d",value[i]);CHKERRQ(ierr); 1514 } 1515 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1516 } 1517 PetscFunctionReturn(0); 1518 } 1519 1520 /*@C 1521 PetscOptionsStringArray - Gets an array of string values for a particular 1522 option in the database. The values must be separated with commas with 1523 no intervening spaces. 1524 1525 Logically Collective on the communicator passed in PetscOptionsBegin() 1526 1527 Input Parameters: 1528 + opt - the option one is seeking 1529 . text - short string describing option 1530 . man - manual page for option 1531 - nmax - maximum number of strings 1532 1533 Output Parameter: 1534 + value - location to copy strings 1535 . nmax - actual number of strings found 1536 - set - PETSC_TRUE if found, else PETSC_FALSE 1537 1538 Level: beginner 1539 1540 Notes: 1541 The user should pass in an array of pointers to char, to hold all the 1542 strings returned by this function. 1543 1544 The user is responsible for deallocating the strings that are 1545 returned. The Fortran interface for this routine is not supported. 1546 1547 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1548 1549 Concepts: options database^array of strings 1550 1551 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1552 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1553 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1554 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1555 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1556 PetscOptionsFList(), PetscOptionsEList() 1557 @*/ 1558 PetscErrorCode PetscOptionsStringArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool *set) 1559 { 1560 PetscErrorCode ierr; 1561 PetscOptionItem amsopt; 1562 1563 PetscFunctionBegin; 1564 if (!PetscOptionsObject->count) { 1565 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING_ARRAY,&amsopt);CHKERRQ(ierr); 1566 ierr = PetscMalloc1(*nmax,(char**)&amsopt->data);CHKERRQ(ierr); 1567 1568 amsopt->arraylength = *nmax; 1569 } 1570 ierr = PetscOptionsGetStringArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,nmax,set);CHKERRQ(ierr); 1571 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1572 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1573 } 1574 PetscFunctionReturn(0); 1575 } 1576 1577 /*@C 1578 PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular 1579 option in the database. The values must be separated with commas with 1580 no intervening spaces. 1581 1582 Logically Collective on the communicator passed in PetscOptionsBegin() 1583 1584 Input Parameters: 1585 + opt - the option one is seeking 1586 . text - short string describing option 1587 . man - manual page for option 1588 - nmax - maximum number of values 1589 1590 Output Parameter: 1591 + value - location to copy values 1592 . nmax - actual number of values found 1593 - set - PETSC_TRUE if found, else PETSC_FALSE 1594 1595 Level: beginner 1596 1597 Notes: 1598 The user should pass in an array of doubles 1599 1600 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1601 1602 Concepts: options database^array of strings 1603 1604 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1605 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1606 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1607 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1608 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1609 PetscOptionsFList(), PetscOptionsEList() 1610 @*/ 1611 PetscErrorCode PetscOptionsBoolArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set) 1612 { 1613 PetscErrorCode ierr; 1614 PetscInt i; 1615 PetscOptionItem amsopt; 1616 1617 PetscFunctionBegin; 1618 if (!PetscOptionsObject->count) { 1619 PetscBool *vals; 1620 1621 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL_ARRAY,&amsopt);CHKERRQ(ierr); 1622 ierr = PetscMalloc1(*n,(PetscBool**)&amsopt->data);CHKERRQ(ierr); 1623 vals = (PetscBool*)amsopt->data; 1624 for (i=0; i<*n; i++) vals[i] = value[i]; 1625 amsopt->arraylength = *n; 1626 } 1627 ierr = PetscOptionsGetBoolArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr); 1628 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1629 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%d",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,value[0]);CHKERRQ(ierr); 1630 for (i=1; i<*n; i++) { 1631 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%d",value[i]);CHKERRQ(ierr); 1632 } 1633 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1634 } 1635 PetscFunctionReturn(0); 1636 } 1637 1638 /*@C 1639 PetscOptionsViewer - Gets a viewer appropriate for the type indicated by the user 1640 1641 Logically Collective on the communicator passed in PetscOptionsBegin() 1642 1643 Input Parameters: 1644 + opt - option name 1645 . text - short string that describes the option 1646 - man - manual page with additional information on option 1647 1648 Output Parameter: 1649 + viewer - the viewer 1650 - set - PETSC_TRUE if found, else PETSC_FALSE 1651 1652 Level: beginner 1653 1654 Concepts: options database^has int 1655 1656 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1657 1658 See PetscOptionsGetViewer() for the format of the supplied viewer and its options 1659 1660 .seealso: PetscOptionsGetViewer(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(NULL,), 1661 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 1662 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 1663 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1664 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1665 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1666 PetscOptionsFList(), PetscOptionsEList() 1667 @*/ 1668 PetscErrorCode PetscOptionsViewer_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool *set) 1669 { 1670 PetscErrorCode ierr; 1671 PetscOptionItem amsopt; 1672 1673 PetscFunctionBegin; 1674 if (!PetscOptionsObject->count) { 1675 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr); 1676 /* must use system malloc since SAWs may free this */ 1677 ierr = PetscStrdup("",(char**)&amsopt->data);CHKERRQ(ierr); 1678 } 1679 ierr = PetscOptionsGetViewer(PetscOptionsObject->comm,PetscOptionsObject->prefix,opt,viewer,format,set);CHKERRQ(ierr); 1680 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1681 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%s>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,"",text,ManSection(man));CHKERRQ(ierr); 1682 } 1683 PetscFunctionReturn(0); 1684 } 1685 1686 1687 /*@C 1688 PetscOptionsHead - Puts a heading before listing any more published options. Used, for example, 1689 in KSPSetFromOptions_GMRES(). 1690 1691 Logically Collective on the communicator passed in PetscOptionsBegin() 1692 1693 Input Parameter: 1694 . head - the heading text 1695 1696 1697 Level: intermediate 1698 1699 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1700 1701 Can be followed by a call to PetscOptionsTail() in the same function. 1702 1703 Concepts: options database^subheading 1704 1705 .seealso: PetscOptionsGetInt(NULL,), PetscOptionsGetReal(), 1706 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1707 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1708 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1709 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1710 PetscOptionsFList(), PetscOptionsEList() 1711 @*/ 1712 PetscErrorCode PetscOptionsHead(PetscOptionItems *PetscOptionsObject,const char head[]) 1713 { 1714 PetscErrorCode ierr; 1715 1716 PetscFunctionBegin; 1717 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1718 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s\n",head);CHKERRQ(ierr); 1719 } 1720 PetscFunctionReturn(0); 1721 } 1722 1723 1724 1725 1726 1727 1728