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