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