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