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