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