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