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