1 /* 2 Implements the higher-level options database querying methods. These are self-documenting and can attach at runtime to 3 GUI code to display the options and get values from the users. 4 5 */ 6 7 #include <petsc/private/petscimpl.h> /*I "petscsys.h" I*/ 8 #include <petscviewer.h> 9 10 #define ManSection(str) ((str) ? (str) : "None") 11 12 /* 13 Keep a linked list of options that have been posted and we are waiting for 14 user selection. See the manual page for PetscOptionsBegin() 15 16 Eventually we'll attach this beast to a MPI_Comm 17 */ 18 19 /* 20 Handles setting up the data structure in a call to PetscOptionsBegin() 21 */ 22 PetscErrorCode PetscOptionsBegin_Private(PetscOptionItems *PetscOptionsObject,MPI_Comm comm,const char prefix[],const char title[],const char mansec[]) 23 { 24 PetscErrorCode ierr; 25 26 PetscFunctionBegin; 27 if (prefix) PetscValidCharPointer(prefix,3); 28 PetscValidCharPointer(title,4); 29 if (mansec) PetscValidCharPointer(mansec,5); 30 if (!PetscOptionsObject->alreadyprinted) { 31 if (!PetscOptionsHelpPrintedSingleton) { 32 ierr = PetscOptionsHelpPrintedCreate(&PetscOptionsHelpPrintedSingleton);CHKERRQ(ierr); 33 } 34 ierr = PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrintedSingleton,prefix,title,&PetscOptionsObject->alreadyprinted);CHKERRQ(ierr); 35 } 36 PetscOptionsObject->next = NULL; 37 PetscOptionsObject->comm = comm; 38 PetscOptionsObject->changedmethod = PETSC_FALSE; 39 40 ierr = PetscStrallocpy(prefix,&PetscOptionsObject->prefix);CHKERRQ(ierr); 41 ierr = PetscStrallocpy(title,&PetscOptionsObject->title);CHKERRQ(ierr); 42 43 ierr = PetscOptionsHasHelp(PetscOptionsObject->options,&PetscOptionsObject->printhelp);CHKERRQ(ierr); 44 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1) { 45 if (!PetscOptionsObject->alreadyprinted) { 46 ierr = (*PetscHelpPrintf)(comm,"----------------------------------------\n%s:\n",title);CHKERRQ(ierr); 47 } 48 } 49 PetscFunctionReturn(0); 50 } 51 52 /* 53 Handles setting up the data structure in a call to PetscObjectOptionsBegin() 54 */ 55 PetscErrorCode PetscObjectOptionsBegin_Private(PetscOptionItems *PetscOptionsObject,PetscObject obj) 56 { 57 PetscErrorCode ierr; 58 char title[256]; 59 PetscBool flg; 60 61 PetscFunctionBegin; 62 PetscValidHeader(obj,2); 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(PetscOptionsObject,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 static int PetscOptionItemCreate_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscOptionType t,PetscOptionItem *amsopt) 80 { 81 int ierr; 82 PetscOptionItem next; 83 PetscBool valid; 84 85 PetscFunctionBegin; 86 ierr = PetscOptionsValidKey(opt,&valid);CHKERRQ(ierr); 87 if (!valid) SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_ARG_INCOMP,"The option '%s' is not a valid key",opt); 88 89 ierr = PetscNew(amsopt);CHKERRQ(ierr); 90 (*amsopt)->next = NULL; 91 (*amsopt)->set = PETSC_FALSE; 92 (*amsopt)->type = t; 93 (*amsopt)->data = NULL; 94 95 ierr = PetscStrallocpy(text,&(*amsopt)->text);CHKERRQ(ierr); 96 ierr = PetscStrallocpy(opt,&(*amsopt)->option);CHKERRQ(ierr); 97 ierr = PetscStrallocpy(man,&(*amsopt)->man);CHKERRQ(ierr); 98 99 if (!PetscOptionsObject->next) PetscOptionsObject->next = *amsopt; 100 else { 101 next = PetscOptionsObject->next; 102 while (next->next) next = next->next; 103 next->next = *amsopt; 104 } 105 PetscFunctionReturn(0); 106 } 107 108 /* 109 PetscScanString - Gets user input via stdin from process and broadcasts to all processes 110 111 Collective 112 113 Input Parameters: 114 + commm - communicator for the broadcast, must be PETSC_COMM_WORLD 115 . n - length of the string, must be the same on all processes 116 - str - location to store input 117 118 Bugs: 119 . Assumes process 0 of the given communicator has access to stdin 120 121 */ 122 static PetscErrorCode PetscScanString(MPI_Comm comm,size_t n,char str[]) 123 { 124 size_t i; 125 char c; 126 PetscMPIInt rank,nm; 127 PetscErrorCode ierr; 128 129 PetscFunctionBegin; 130 ierr = MPI_Comm_rank(comm,&rank);CHKERRMPI(ierr); 131 if (rank == 0) { 132 c = (char) getchar(); 133 i = 0; 134 while (c != '\n' && i < n-1) { 135 str[i++] = c; 136 c = (char)getchar(); 137 } 138 str[i] = 0; 139 } 140 ierr = PetscMPIIntCast(n,&nm);CHKERRQ(ierr); 141 ierr = MPI_Bcast(str,nm,MPI_CHAR,0,comm);CHKERRMPI(ierr); 142 PetscFunctionReturn(0); 143 } 144 145 /* 146 This is needed because certain strings may be freed by SAWs, hence we cannot use PetscStrallocpy() 147 */ 148 static PetscErrorCode PetscStrdup(const char s[],char *t[]) 149 { 150 PetscErrorCode ierr; 151 size_t len; 152 char *tmp = NULL; 153 154 PetscFunctionBegin; 155 if (s) { 156 ierr = PetscStrlen(s,&len);CHKERRQ(ierr); 157 tmp = (char*) malloc((len+1)*sizeof(char)); 158 if (!tmp) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_MEM,"No memory to duplicate string"); 159 ierr = PetscStrcpy(tmp,s);CHKERRQ(ierr); 160 } 161 *t = tmp; 162 PetscFunctionReturn(0); 163 } 164 165 /* 166 PetscOptionsGetFromTextInput - Presents all the PETSc Options processed by the program so the user may change them at runtime 167 168 Notes: 169 this isn't really practical, it is just to demonstrate the principle 170 171 A carriage return indicates no change from the default; but this like -ksp_monitor <stdout> the default is actually not stdout the default 172 is to do nothing so to get it to use stdout you need to type stdout. This is kind of bug? 173 174 Bugs: 175 + All processes must traverse through the exact same set of option queries due to the call to PetscScanString() 176 . Internal strings have arbitrary length and string copies are not checked that they fit into string space 177 - Only works for PetscInt == int, PetscReal == double etc 178 179 Developer Notes: 180 Normally the GUI that presents the options the user and retrieves the values would be running in a different 181 address space and communicating with the PETSc program 182 183 */ 184 PetscErrorCode PetscOptionsGetFromTextInput(PetscOptionItems *PetscOptionsObject) 185 { 186 PetscErrorCode ierr; 187 PetscOptionItem next = PetscOptionsObject->next; 188 char str[512]; 189 PetscBool bid; 190 PetscReal ir,*valr; 191 PetscInt *vald; 192 size_t i; 193 194 PetscFunctionBegin; 195 ierr = (*PetscPrintf)(PETSC_COMM_WORLD,"%s --------------------\n",PetscOptionsObject->title);CHKERRQ(ierr); 196 while (next) { 197 switch (next->type) { 198 case OPTION_HEAD: 199 break; 200 case OPTION_INT_ARRAY: 201 ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1);CHKERRQ(ierr); 202 vald = (PetscInt*) next->data; 203 for (i=0; i<next->arraylength; i++) { 204 ierr = PetscPrintf(PETSC_COMM_WORLD,"%" PetscInt_FMT,vald[i]);CHKERRQ(ierr); 205 if (i < next->arraylength-1) { 206 ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr); 207 } 208 } 209 ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s) ",next->text,next->man);CHKERRQ(ierr); 210 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 211 if (str[0]) { 212 PetscToken token; 213 PetscInt n=0,nmax = next->arraylength,*dvalue = (PetscInt*)next->data,start,end; 214 size_t len; 215 char *value; 216 PetscBool foundrange; 217 218 next->set = PETSC_TRUE; 219 value = str; 220 ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 221 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 222 while (n < nmax) { 223 if (!value) break; 224 225 /* look for form d-D where d and D are integers */ 226 foundrange = PETSC_FALSE; 227 ierr = PetscStrlen(value,&len);CHKERRQ(ierr); 228 if (value[0] == '-') i=2; 229 else i=1; 230 for (;i<len; i++) { 231 if (value[i] == '-') { 232 if (i == len-1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %" PetscInt_FMT "-th array entry %s",n,value); 233 value[i] = 0; 234 ierr = PetscOptionsStringToInt(value,&start);CHKERRQ(ierr); 235 ierr = PetscOptionsStringToInt(value+i+1,&end);CHKERRQ(ierr); 236 if (end <= start) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %" PetscInt_FMT "-th array entry, %s-%s cannot have decreasing list",n,value,value+i+1); 237 if (n + end - start - 1 >= nmax) SETERRQ4(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %" PetscInt_FMT "-th array entry, not enough space in left in array (%" PetscInt_FMT ") to contain entire range from %" PetscInt_FMT " to %" PetscInt_FMT,n,nmax-n,start,end); 238 for (; start<end; start++) { 239 *dvalue = start; dvalue++;n++; 240 } 241 foundrange = PETSC_TRUE; 242 break; 243 } 244 } 245 if (!foundrange) { 246 ierr = PetscOptionsStringToInt(value,dvalue);CHKERRQ(ierr); 247 dvalue++; 248 n++; 249 } 250 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 251 } 252 ierr = PetscTokenDestroy(&token);CHKERRQ(ierr); 253 } 254 break; 255 case OPTION_REAL_ARRAY: 256 ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1);CHKERRQ(ierr); 257 valr = (PetscReal*) next->data; 258 for (i=0; i<next->arraylength; i++) { 259 ierr = PetscPrintf(PETSC_COMM_WORLD,"%g",(double)valr[i]);CHKERRQ(ierr); 260 if (i < next->arraylength-1) { 261 ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr); 262 } 263 } 264 ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s) ",next->text,next->man);CHKERRQ(ierr); 265 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 266 if (str[0]) { 267 PetscToken token; 268 PetscInt n = 0,nmax = next->arraylength; 269 PetscReal *dvalue = (PetscReal*)next->data; 270 char *value; 271 272 next->set = PETSC_TRUE; 273 value = str; 274 ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 275 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 276 while (n < nmax) { 277 if (!value) break; 278 ierr = PetscOptionsStringToReal(value,dvalue);CHKERRQ(ierr); 279 dvalue++; 280 n++; 281 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 282 } 283 ierr = PetscTokenDestroy(&token);CHKERRQ(ierr); 284 } 285 break; 286 case OPTION_INT: 287 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); 288 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 289 if (str[0]) { 290 #if defined(PETSC_SIZEOF_LONG_LONG) 291 long long lid; 292 sscanf(str,"%lld",&lid); 293 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); 294 #else 295 long lid; 296 sscanf(str,"%ld",&lid); 297 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); 298 #endif 299 300 next->set = PETSC_TRUE; 301 *((PetscInt*)next->data) = (PetscInt)lid; 302 } 303 break; 304 case OPTION_REAL: 305 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); 306 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 307 if (str[0]) { 308 #if defined(PETSC_USE_REAL_SINGLE) 309 sscanf(str,"%e",&ir); 310 #elif defined(PETSC_USE_REAL___FP16) 311 float irtemp; 312 sscanf(str,"%e",&irtemp); 313 ir = irtemp; 314 #elif defined(PETSC_USE_REAL_DOUBLE) 315 sscanf(str,"%le",&ir); 316 #elif defined(PETSC_USE_REAL___FLOAT128) 317 ir = strtoflt128(str,0); 318 #else 319 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Unknown scalar type"); 320 #endif 321 next->set = PETSC_TRUE; 322 *((PetscReal*)next->data) = ir; 323 } 324 break; 325 case OPTION_BOOL: 326 ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <%s>: %s (%s) ",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1,*(PetscBool*)next->data ? "true": "false",next->text,next->man);CHKERRQ(ierr); 327 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 328 if (str[0]) { 329 ierr = PetscOptionsStringToBool(str,&bid);CHKERRQ(ierr); 330 next->set = PETSC_TRUE; 331 *((PetscBool*)next->data) = bid; 332 } 333 break; 334 case OPTION_STRING: 335 ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <%s>: %s (%s) ",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1,(char*)next->data,next->text,next->man);CHKERRQ(ierr); 336 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 337 if (str[0]) { 338 next->set = PETSC_TRUE; 339 /* must use system malloc since SAWs may free this */ 340 ierr = PetscStrdup(str,(char**)&next->data);CHKERRQ(ierr); 341 } 342 break; 343 case OPTION_FLIST: 344 ierr = PetscFunctionListPrintTypes(PETSC_COMM_WORLD,stdout,PetscOptionsObject->prefix,next->option,next->text,next->man,next->flist,(char*)next->data,(char*)next->data);CHKERRQ(ierr); 345 ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 346 if (str[0]) { 347 PetscOptionsObject->changedmethod = PETSC_TRUE; 348 next->set = PETSC_TRUE; 349 /* must use system malloc since SAWs may free this */ 350 ierr = PetscStrdup(str,(char**)&next->data);CHKERRQ(ierr); 351 } 352 break; 353 default: 354 break; 355 } 356 next = next->next; 357 } 358 PetscFunctionReturn(0); 359 } 360 361 #if defined(PETSC_HAVE_SAWS) 362 #include <petscviewersaws.h> 363 364 static int count = 0; 365 366 PetscErrorCode PetscOptionsSAWsDestroy(void) 367 { 368 PetscFunctionBegin; 369 PetscFunctionReturn(0); 370 } 371 372 static const char *OptionsHeader = "<head>\n" 373 "<script type=\"text/javascript\" src=\"https://www.mcs.anl.gov/research/projects/saws/js/jquery-1.9.1.js\"></script>\n" 374 "<script type=\"text/javascript\" src=\"https://www.mcs.anl.gov/research/projects/saws/js/SAWs.js\"></script>\n" 375 "<script type=\"text/javascript\" src=\"js/PETSc.js\"></script>\n" 376 "<script>\n" 377 "jQuery(document).ready(function() {\n" 378 "PETSc.getAndDisplayDirectory(null,\"#variablesInfo\")\n" 379 "})\n" 380 "</script>\n" 381 "</head>\n"; 382 383 /* Determines the size and style of the scroll region where PETSc options selectable from users are displayed */ 384 static const char *OptionsBodyBottom = "<div id=\"variablesInfo\" style=\"background-color:lightblue;height:auto;max-height:500px;overflow:scroll;\"></div>\n<br>\n</body>"; 385 386 /* 387 PetscOptionsSAWsInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the SAWs 388 389 Bugs: 390 + All processes must traverse through the exact same set of option queries do to the call to PetscScanString() 391 . Internal strings have arbitrary length and string copies are not checked that they fit into string space 392 - Only works for PetscInt == int, PetscReal == double etc 393 394 */ 395 PetscErrorCode PetscOptionsSAWsInput(PetscOptionItems *PetscOptionsObject) 396 { 397 PetscErrorCode ierr; 398 PetscOptionItem next = PetscOptionsObject->next; 399 static int mancount = 0; 400 char options[16]; 401 PetscBool changedmethod = PETSC_FALSE; 402 PetscBool stopasking = PETSC_FALSE; 403 char manname[16],textname[16]; 404 char dir[1024]; 405 406 PetscFunctionBegin; 407 /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */ 408 sprintf(options,"Options_%d",count++); 409 410 PetscOptionsObject->pprefix = PetscOptionsObject->prefix; /* SAWs will change this, so cannot pass prefix directly */ 411 412 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s","_title");CHKERRQ(ierr); 413 PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject->title,1,SAWs_READ,SAWs_STRING)); 414 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s","prefix");CHKERRQ(ierr); 415 PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject->pprefix,1,SAWs_READ,SAWs_STRING)); 416 PetscStackCallSAWs(SAWs_Register,("/PETSc/Options/ChangedMethod",&changedmethod,1,SAWs_WRITE,SAWs_BOOLEAN)); 417 PetscStackCallSAWs(SAWs_Register,("/PETSc/Options/StopAsking",&stopasking,1,SAWs_WRITE,SAWs_BOOLEAN)); 418 419 while (next) { 420 sprintf(manname,"_man_%d",mancount); 421 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",manname);CHKERRQ(ierr); 422 PetscStackCallSAWs(SAWs_Register,(dir,&next->man,1,SAWs_READ,SAWs_STRING)); 423 sprintf(textname,"_text_%d",mancount++); 424 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",textname);CHKERRQ(ierr); 425 PetscStackCallSAWs(SAWs_Register,(dir,&next->text,1,SAWs_READ,SAWs_STRING)); 426 427 switch (next->type) { 428 case OPTION_HEAD: 429 break; 430 case OPTION_INT_ARRAY: 431 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 432 PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_INT)); 433 break; 434 case OPTION_REAL_ARRAY: 435 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 436 PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_DOUBLE)); 437 break; 438 case OPTION_INT: 439 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 440 PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_INT)); 441 break; 442 case OPTION_REAL: 443 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 444 PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_DOUBLE)); 445 break; 446 case OPTION_BOOL: 447 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 448 PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_BOOLEAN)); 449 break; 450 case OPTION_BOOL_ARRAY: 451 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 452 PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_BOOLEAN)); 453 break; 454 case OPTION_STRING: 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 break; 458 case OPTION_STRING_ARRAY: 459 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 460 PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_STRING)); 461 break; 462 case OPTION_FLIST: 463 { 464 PetscInt ntext; 465 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 466 PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING)); 467 ierr = PetscFunctionListGet(next->flist,(const char***)&next->edata,&ntext);CHKERRQ(ierr); 468 PetscStackCallSAWs(SAWs_Set_Legal_Variable_Values,(dir,ntext,next->edata)); 469 } 470 break; 471 case OPTION_ELIST: 472 { 473 PetscInt ntext = next->nlist; 474 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 475 PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING)); 476 ierr = PetscMalloc1((ntext+1),(char***)&next->edata);CHKERRQ(ierr); 477 ierr = PetscMemcpy(next->edata,next->list,ntext*sizeof(char*));CHKERRQ(ierr); 478 PetscStackCallSAWs(SAWs_Set_Legal_Variable_Values,(dir,ntext,next->edata)); 479 } 480 break; 481 default: 482 break; 483 } 484 next = next->next; 485 } 486 487 /* wait until accessor has unlocked the memory */ 488 PetscStackCallSAWs(SAWs_Push_Header,("index.html",OptionsHeader)); 489 PetscStackCallSAWs(SAWs_Push_Body,("index.html",2,OptionsBodyBottom)); 490 ierr = PetscSAWsBlock();CHKERRQ(ierr); 491 PetscStackCallSAWs(SAWs_Pop_Header,("index.html")); 492 PetscStackCallSAWs(SAWs_Pop_Body,("index.html",2)); 493 494 /* determine if any values have been set in GUI */ 495 next = PetscOptionsObject->next; 496 while (next) { 497 ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 498 PetscStackCallSAWs(SAWs_Selected,(dir,(int*)&next->set)); 499 next = next->next; 500 } 501 502 /* reset counter to -2; this updates the screen with the new options for the selected method */ 503 if (changedmethod) PetscOptionsObject->count = -2; 504 505 if (stopasking) { 506 PetscOptionsPublish = PETSC_FALSE; 507 PetscOptionsObject->count = 0;//do not ask for same thing again 508 } 509 510 PetscStackCallSAWs(SAWs_Delete,("/PETSc/Options")); 511 PetscFunctionReturn(0); 512 } 513 #endif 514 515 PetscErrorCode PetscOptionsEnd_Private(PetscOptionItems *PetscOptionsObject) 516 { 517 PetscErrorCode ierr; 518 PetscOptionItem last; 519 char option[256],value[1024],tmp[32]; 520 size_t j; 521 522 PetscFunctionBegin; 523 if (PetscOptionsObject->next) { 524 if (!PetscOptionsObject->count) { 525 #if defined(PETSC_HAVE_SAWS) 526 ierr = PetscOptionsSAWsInput(PetscOptionsObject);CHKERRQ(ierr); 527 #else 528 ierr = PetscOptionsGetFromTextInput(PetscOptionsObject);CHKERRQ(ierr); 529 #endif 530 } 531 } 532 533 ierr = PetscFree(PetscOptionsObject->title);CHKERRQ(ierr); 534 535 /* reset counter to -2; this updates the screen with the new options for the selected method */ 536 if (PetscOptionsObject->changedmethod) PetscOptionsObject->count = -2; 537 /* reset alreadyprinted flag */ 538 PetscOptionsObject->alreadyprinted = PETSC_FALSE; 539 if (PetscOptionsObject->object) PetscOptionsObject->object->optionsprinted = PETSC_TRUE; 540 PetscOptionsObject->object = NULL; 541 542 while (PetscOptionsObject->next) { 543 if (PetscOptionsObject->next->set) { 544 if (PetscOptionsObject->prefix) { 545 ierr = PetscStrcpy(option,"-");CHKERRQ(ierr); 546 ierr = PetscStrcat(option,PetscOptionsObject->prefix);CHKERRQ(ierr); 547 ierr = PetscStrcat(option,PetscOptionsObject->next->option+1);CHKERRQ(ierr); 548 } else { 549 ierr = PetscStrcpy(option,PetscOptionsObject->next->option);CHKERRQ(ierr); 550 } 551 552 switch (PetscOptionsObject->next->type) { 553 case OPTION_HEAD: 554 break; 555 case OPTION_INT_ARRAY: 556 sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject->next->data)[0]); 557 for (j=1; j<PetscOptionsObject->next->arraylength; j++) { 558 sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject->next->data)[j]); 559 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 560 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 561 } 562 break; 563 case OPTION_INT: 564 sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject->next->data); 565 break; 566 case OPTION_REAL: 567 sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject->next->data); 568 break; 569 case OPTION_REAL_ARRAY: 570 sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject->next->data)[0]); 571 for (j=1; j<PetscOptionsObject->next->arraylength; j++) { 572 sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject->next->data)[j]); 573 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 574 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 575 } 576 break; 577 case OPTION_SCALAR_ARRAY: 578 sprintf(value,"%g+%gi",(double)PetscRealPart(((PetscScalar*)PetscOptionsObject->next->data)[0]),(double)PetscImaginaryPart(((PetscScalar*)PetscOptionsObject->next->data)[0])); 579 for (j=1; j<PetscOptionsObject->next->arraylength; j++) { 580 sprintf(tmp,"%g+%gi",(double)PetscRealPart(((PetscScalar*)PetscOptionsObject->next->data)[j]),(double)PetscImaginaryPart(((PetscScalar*)PetscOptionsObject->next->data)[j])); 581 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 582 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 583 } 584 break; 585 case OPTION_BOOL: 586 sprintf(value,"%d",*(int*)PetscOptionsObject->next->data); 587 break; 588 case OPTION_BOOL_ARRAY: 589 sprintf(value,"%d",(int)((PetscBool*)PetscOptionsObject->next->data)[0]); 590 for (j=1; j<PetscOptionsObject->next->arraylength; j++) { 591 sprintf(tmp,"%d",(int)((PetscBool*)PetscOptionsObject->next->data)[j]); 592 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 593 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 594 } 595 break; 596 case OPTION_FLIST: 597 ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr); 598 break; 599 case OPTION_ELIST: 600 ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr); 601 break; 602 case OPTION_STRING: 603 ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr); 604 break; 605 case OPTION_STRING_ARRAY: 606 sprintf(value,"%s",((char**)PetscOptionsObject->next->data)[0]); 607 for (j=1; j<PetscOptionsObject->next->arraylength; j++) { 608 sprintf(tmp,"%s",((char**)PetscOptionsObject->next->data)[j]); 609 ierr = PetscStrcat(value,",");CHKERRQ(ierr); 610 ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 611 } 612 break; 613 } 614 ierr = PetscOptionsSetValue(PetscOptionsObject->options,option,value);CHKERRQ(ierr); 615 } 616 if (PetscOptionsObject->next->type == OPTION_ELIST) { 617 ierr = PetscStrNArrayDestroy(PetscOptionsObject->next->nlist,(char ***)&PetscOptionsObject->next->list);CHKERRQ(ierr); 618 } 619 ierr = PetscFree(PetscOptionsObject->next->text);CHKERRQ(ierr); 620 ierr = PetscFree(PetscOptionsObject->next->option);CHKERRQ(ierr); 621 ierr = PetscFree(PetscOptionsObject->next->man);CHKERRQ(ierr); 622 ierr = PetscFree(PetscOptionsObject->next->edata);CHKERRQ(ierr); 623 624 if ((PetscOptionsObject->next->type == OPTION_STRING) || (PetscOptionsObject->next->type == OPTION_FLIST) || (PetscOptionsObject->next->type == OPTION_ELIST)) { 625 free(PetscOptionsObject->next->data); 626 } else { 627 ierr = PetscFree(PetscOptionsObject->next->data);CHKERRQ(ierr); 628 } 629 630 last = PetscOptionsObject->next; 631 PetscOptionsObject->next = PetscOptionsObject->next->next; 632 ierr = PetscFree(last);CHKERRQ(ierr); 633 } 634 ierr = PetscFree(PetscOptionsObject->prefix);CHKERRQ(ierr); 635 PetscOptionsObject->next = NULL; 636 PetscFunctionReturn(0); 637 } 638 639 /*MC 640 PetscOptionsEnum - Gets the enum value for a particular option in the database. 641 642 Logically Collective on the communicator passed in PetscOptionsBegin() 643 644 Synopsis: 645 #include "petscsys.h" 646 PetscErrorCode PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum currentvalue,PetscEnum *value,PetscBool *set) 647 648 Input Parameters: 649 + opt - option name 650 . text - short string that describes the option 651 . man - manual page with additional information on option 652 . list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null 653 - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 654 $ PetscOptionsEnum(..., obj->value,&object->value,...) or 655 $ value = defaultvalue 656 $ PetscOptionsEnum(..., value,&value,&flg); 657 $ if (flg) { 658 659 Output Parameters: 660 + value - the value to return 661 - set - PETSC_TRUE if found, else PETSC_FALSE 662 663 Level: beginner 664 665 Notes: 666 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 667 668 list is usually something like PCASMTypes or some other predefined list of enum names 669 670 If the user does not supply the option at all value is NOT changed. Thus 671 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 672 673 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 674 675 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 676 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), 677 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 678 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 679 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 680 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 681 PetscOptionsFList(), PetscOptionsEList() 682 M*/ 683 684 PetscErrorCode PetscOptionsEnum_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],const char *const *list,PetscEnum currentvalue,PetscEnum *value,PetscBool *set) 685 { 686 PetscErrorCode ierr; 687 PetscInt ntext = 0; 688 PetscInt tval; 689 PetscBool tflg; 690 691 PetscFunctionBegin; 692 while (list[ntext++]) { 693 if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries"); 694 } 695 if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix"); 696 ntext -= 3; 697 ierr = PetscOptionsEList_Private(PetscOptionsObject,opt,text,man,list,ntext,list[currentvalue],&tval,&tflg);CHKERRQ(ierr); 698 /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */ 699 if (tflg) *value = (PetscEnum)tval; 700 if (set) *set = tflg; 701 PetscFunctionReturn(0); 702 } 703 704 /*MC 705 PetscOptionsEnumArray - Gets an array of enum values for a particular 706 option in the database. 707 708 Logically Collective on the communicator passed in PetscOptionsBegin() 709 710 Synopsis: 711 #include "petscsys.h" 712 PetscErrorCode PetscOptionsEnumArray(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum value[],PetscInt *n,PetscBool *set) 713 714 Input Parameters: 715 + opt - the option one is seeking 716 . text - short string describing option 717 . man - manual page for option 718 . list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null 719 - n - maximum number of values 720 721 Output Parameters: 722 + value - location to copy values 723 . n - actual number of values found 724 - set - PETSC_TRUE if found, else PETSC_FALSE 725 726 Level: beginner 727 728 Notes: 729 The array must be passed as a comma separated list. 730 731 There must be no intervening spaces between the values. 732 733 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 734 735 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 736 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), 737 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 738 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 739 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 740 PetscOptionsFList(), PetscOptionsEList(), PetscOptionsRealArray() 741 M*/ 742 743 PetscErrorCode PetscOptionsEnumArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],const char *const *list,PetscEnum value[],PetscInt *n,PetscBool *set) 744 { 745 PetscInt i,nlist = 0; 746 PetscOptionItem amsopt; 747 PetscErrorCode ierr; 748 749 PetscFunctionBegin; 750 while (list[nlist++]) if (nlist > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries"); 751 if (nlist < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix"); 752 nlist -= 3; /* drop enum name, prefix, and null termination */ 753 if (0 && !PetscOptionsObject->count) { /* XXX Requires additional support */ 754 PetscEnum *vals; 755 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT_ARRAY/*XXX OPTION_ENUM_ARRAY*/,&amsopt);CHKERRQ(ierr); 756 ierr = PetscStrNArrayallocpy(nlist,list,(char***)&amsopt->list);CHKERRQ(ierr); 757 amsopt->nlist = nlist; 758 ierr = PetscMalloc1(*n,(PetscEnum**)&amsopt->data);CHKERRQ(ierr); 759 amsopt->arraylength = *n; 760 vals = (PetscEnum*)amsopt->data; 761 for (i=0; i<*n; i++) vals[i] = value[i]; 762 } 763 ierr = PetscOptionsGetEnumArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,list,value,n,set);CHKERRQ(ierr); 764 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 765 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%s",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,list[value[0]]);CHKERRQ(ierr); 766 for (i=1; i<*n; i++) {ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%s",list[value[i]]);CHKERRQ(ierr);} 767 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (choose from)",text);CHKERRQ(ierr); 768 for (i=0; i<nlist; i++) {ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s",list[i]);CHKERRQ(ierr);} 769 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," (%s)\n",ManSection(man));CHKERRQ(ierr); 770 } 771 PetscFunctionReturn(0); 772 } 773 774 /*MC 775 PetscOptionsBoundedInt - Gets an integer value greater than or equal a given bound for a particular option in the database. 776 777 Logically Collective on the communicator passed in PetscOptionsBegin() 778 779 Synopsis: 780 #include "petscsys.h" 781 PetscErrorCode PetscOptionsBoundInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt bound) 782 783 Input Parameters: 784 + opt - option name 785 . text - short string that describes the option 786 . man - manual page with additional information on option 787 . currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 788 $ PetscOptionsInt(..., obj->value,&obj->value,...) or 789 $ value = defaultvalue 790 $ PetscOptionsInt(..., value,&value,&flg); 791 $ if (flg) { 792 - bound - the requested value should be greater than or equal this bound or an error is generated 793 794 Output Parameters: 795 + value - the integer value to return 796 - flg - PETSC_TRUE if found, else PETSC_FALSE 797 798 Notes: 799 If the user does not supply the option at all value is NOT changed. Thus 800 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 801 802 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 803 804 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 805 806 Level: beginner 807 808 .seealso: PetscOptionsInt(), PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 809 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), PetscOptionsRangeInt() 810 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 811 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 812 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 813 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 814 PetscOptionsFList(), PetscOptionsEList() 815 M*/ 816 817 /*MC 818 PetscOptionsRangeInt - Gets an integer value within a range of values for a particular option in the database. 819 820 Logically Collective on the communicator passed in PetscOptionsBegin() 821 822 Synopsis: 823 #include "petscsys.h" 824 PetscErrorCode PetscOptionsRangeInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt lb,PetscInt ub) 825 826 Input Parameters: 827 + opt - option name 828 . text - short string that describes the option 829 . man - manual page with additional information on option 830 . currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 831 $ PetscOptionsInt(..., obj->value,&obj->value,...) or 832 $ value = defaultvalue 833 $ PetscOptionsInt(..., value,&value,&flg); 834 $ if (flg) { 835 . lb - the lower bound, provided value must be greater than or equal to this value or an error is generated 836 - ub - the upper bound, provided value must be less than or equal to this value or an error is generated 837 838 Output Parameters: 839 + value - the integer value to return 840 - flg - PETSC_TRUE if found, else PETSC_FALSE 841 842 Notes: 843 If the user does not supply the option at all value is NOT changed. Thus 844 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 845 846 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 847 848 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 849 850 Level: beginner 851 852 .seealso: PetscOptionsInt(), PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 853 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), PetscOptionsBoundedInt() 854 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 855 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 856 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 857 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 858 PetscOptionsFList(), PetscOptionsEList() 859 M*/ 860 861 /*MC 862 PetscOptionsInt - Gets the integer value for a particular option in the database. 863 864 Logically Collective on the communicator passed in PetscOptionsBegin() 865 866 Synopsis: 867 #include "petscsys.h" 868 PetscErrorCode PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg)) 869 870 Input Parameters: 871 + opt - option name 872 . text - short string that describes the option 873 . man - manual page with additional information on option 874 - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 875 $ PetscOptionsInt(..., obj->value,&obj->value,...) or 876 $ value = defaultvalue 877 $ PetscOptionsInt(..., value,&value,&flg); 878 $ if (flg) { 879 880 Output Parameters: 881 + value - the integer value to return 882 - flg - PETSC_TRUE if found, else PETSC_FALSE 883 884 Notes: 885 If the user does not supply the option at all value is NOT changed. Thus 886 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 887 888 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 889 890 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 891 892 Level: beginner 893 894 .seealso: PetscOptionsBoundedInt(), PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 895 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), PetscOptionsRangeInt() 896 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 897 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 898 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 899 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 900 PetscOptionsFList(), PetscOptionsEList() 901 M*/ 902 903 PetscErrorCode PetscOptionsInt_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *set,PetscInt lb,PetscInt ub) 904 { 905 PetscErrorCode ierr; 906 PetscOptionItem amsopt; 907 PetscBool wasset; 908 909 PetscFunctionBegin; 910 if (currentvalue < lb) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Current value %" PetscInt_FMT " less than allowed bound %" PetscInt_FMT,currentvalue,lb); 911 if (currentvalue > ub) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Current value %" PetscInt_FMT " greater than allowed bound %" PetscInt_FMT,currentvalue,ub); 912 if (!PetscOptionsObject->count) { 913 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr); 914 ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr); 915 *(PetscInt*)amsopt->data = currentvalue; 916 917 ierr = PetscOptionsGetInt(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,¤tvalue,&wasset);CHKERRQ(ierr); 918 if (wasset) { 919 *(PetscInt*)amsopt->data = currentvalue; 920 } 921 } 922 ierr = PetscOptionsGetInt(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,&wasset);CHKERRQ(ierr); 923 if (wasset && *value < lb) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Newly set value %" PetscInt_FMT " less than allowed bound %" PetscInt_FMT,*value,lb); 924 if (wasset && *value > ub) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Newly set value %" PetscInt_FMT " greater than allowed bound %" PetscInt_FMT,*value,ub); 925 if (set) *set = wasset; 926 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 927 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <now %" PetscInt_FMT " : formerly %" PetscInt_FMT ">: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,wasset && value ? *value : currentvalue,currentvalue,text,ManSection(man));CHKERRQ(ierr); 928 } 929 PetscFunctionReturn(0); 930 } 931 932 /*MC 933 PetscOptionsString - Gets the string value for a particular option in the database. 934 935 Logically Collective on the communicator passed in PetscOptionsBegin() 936 937 Synopsis: 938 #include "petscsys.h" 939 PetscErrorCode PetscOptionsString(const char opt[],const char text[],const char man[],const char currentvalue[],char value[],size_t len,PetscBool *set) 940 941 Input Parameters: 942 + opt - option name 943 . text - short string that describes the option 944 . man - manual page with additional information on option 945 . currentvalue - the current value; caller is responsible for setting this value correctly. This is not used to set value 946 - len - length of the result string including null terminator 947 948 Output Parameters: 949 + value - the value to return 950 - flg - PETSC_TRUE if found, else PETSC_FALSE 951 952 Level: beginner 953 954 Notes: 955 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 956 957 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). 958 959 If the user does not supply the option at all value is NOT changed. Thus 960 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 961 962 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 963 964 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 965 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), 966 PetscOptionsInt(), PetscOptionsReal(), PetscOptionsBool(), 967 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 968 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 969 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 970 PetscOptionsFList(), PetscOptionsEList() 971 M*/ 972 973 PetscErrorCode PetscOptionsString_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],const char currentvalue[],char value[],size_t len,PetscBool *set) 974 { 975 PetscErrorCode ierr; 976 PetscOptionItem amsopt; 977 PetscBool lset; 978 979 PetscFunctionBegin; 980 if (!PetscOptionsObject->count) { 981 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr); 982 /* must use system malloc since SAWs may free this */ 983 ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr); 984 } 985 ierr = PetscOptionsGetString(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,len,&lset);CHKERRQ(ierr); 986 if (set) *set = lset; 987 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 988 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <now %s : formerly %s>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,lset && value ? value : currentvalue,currentvalue,text,ManSection(man));CHKERRQ(ierr); 989 } 990 PetscFunctionReturn(0); 991 } 992 993 /*MC 994 PetscOptionsReal - Gets the PetscReal value for a particular option in the database. 995 996 Logically Collective on the communicator passed in PetscOptionsBegin() 997 998 Synopsis: 999 #include "petscsys.h" 1000 PetscErrorCode PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal currentvalue,PetscReal *value,PetscBool *set) 1001 1002 Input Parameters: 1003 + opt - option name 1004 . text - short string that describes the option 1005 . man - manual page with additional information on option 1006 - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 1007 $ PetscOptionsReal(..., obj->value,&obj->value,...) or 1008 $ value = defaultvalue 1009 $ PetscOptionsReal(..., value,&value,&flg); 1010 $ if (flg) { 1011 1012 Output Parameters: 1013 + value - the value to return 1014 - flg - PETSC_TRUE if found, else PETSC_FALSE 1015 1016 Notes: 1017 If the user does not supply the option at all value is NOT changed. Thus 1018 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 1019 1020 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 1021 1022 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1023 1024 Level: beginner 1025 1026 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 1027 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), 1028 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 1029 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1030 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1031 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1032 PetscOptionsFList(), PetscOptionsEList() 1033 M*/ 1034 1035 PetscErrorCode PetscOptionsReal_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscReal currentvalue,PetscReal *value,PetscBool *set) 1036 { 1037 PetscErrorCode ierr; 1038 PetscOptionItem amsopt; 1039 PetscBool lset; 1040 1041 PetscFunctionBegin; 1042 if (!PetscOptionsObject->count) { 1043 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr); 1044 ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr); 1045 1046 *(PetscReal*)amsopt->data = currentvalue; 1047 } 1048 ierr = PetscOptionsGetReal(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,&lset);CHKERRQ(ierr); 1049 if (set) *set = lset; 1050 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1051 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%g : %g>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,lset && value ? (double)*value : (double) currentvalue,(double)currentvalue,text,ManSection(man));CHKERRQ(ierr); 1052 } 1053 PetscFunctionReturn(0); 1054 } 1055 1056 /*MC 1057 PetscOptionsScalar - Gets the scalar value for a particular option in the database. 1058 1059 Logically Collective on the communicator passed in PetscOptionsBegin() 1060 1061 Synopsis: 1062 #include "petscsys.h" 1063 PetscErrorCode PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar currentvalue,PetscScalar *value,PetscBool *set) 1064 1065 Input Parameters: 1066 + opt - option name 1067 . text - short string that describes the option 1068 . man - manual page with additional information on option 1069 - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 1070 $ PetscOptionsScalar(..., obj->value,&obj->value,...) or 1071 $ value = defaultvalue 1072 $ PetscOptionsScalar(..., value,&value,&flg); 1073 $ if (flg) { 1074 1075 Output Parameters: 1076 + value - the value to return 1077 - flg - PETSC_TRUE if found, else PETSC_FALSE 1078 1079 Notes: 1080 If the user does not supply the option at all value is NOT changed. Thus 1081 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 1082 1083 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 1084 1085 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1086 1087 Level: beginner 1088 1089 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 1090 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), 1091 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 1092 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1093 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1094 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1095 PetscOptionsFList(), PetscOptionsEList() 1096 M*/ 1097 1098 PetscErrorCode PetscOptionsScalar_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscScalar currentvalue,PetscScalar *value,PetscBool *set) 1099 { 1100 PetscErrorCode ierr; 1101 1102 PetscFunctionBegin; 1103 #if !defined(PETSC_USE_COMPLEX) 1104 ierr = PetscOptionsReal(opt,text,man,currentvalue,value,set);CHKERRQ(ierr); 1105 #else 1106 ierr = PetscOptionsGetScalar(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,set);CHKERRQ(ierr); 1107 #endif 1108 PetscFunctionReturn(0); 1109 } 1110 1111 /*MC 1112 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 1113 its value is set to false. 1114 1115 Logically Collective on the communicator passed in PetscOptionsBegin() 1116 1117 Synopsis: 1118 #include "petscsys.h" 1119 PetscErrorCode PetscOptionsName(const char opt[],const char text[],const char man[],PetscBool *flg) 1120 1121 Input Parameters: 1122 + opt - option name 1123 . text - short string that describes the option 1124 - man - manual page with additional information on option 1125 1126 Output Parameter: 1127 . flg - PETSC_TRUE if found, else PETSC_FALSE 1128 1129 Level: beginner 1130 1131 Notes: 1132 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1133 1134 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 1135 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), 1136 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 1137 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1138 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1139 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1140 PetscOptionsFList(), PetscOptionsEList() 1141 M*/ 1142 1143 PetscErrorCode PetscOptionsName_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool *flg) 1144 { 1145 PetscErrorCode ierr; 1146 PetscOptionItem amsopt; 1147 1148 PetscFunctionBegin; 1149 if (!PetscOptionsObject->count) { 1150 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1151 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1152 1153 *(PetscBool*)amsopt->data = PETSC_FALSE; 1154 } 1155 ierr = PetscOptionsHasName(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg);CHKERRQ(ierr); 1156 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1157 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1158 } 1159 PetscFunctionReturn(0); 1160 } 1161 1162 /*MC 1163 PetscOptionsFList - Puts a list of option values that a single one may be selected from 1164 1165 Logically Collective on the communicator passed in PetscOptionsBegin() 1166 1167 Synopsis: 1168 #include "petscsys.h" 1169 PetscErrorCode PetscOptionsFList(const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char currentvalue[],char value[],size_t len,PetscBool *set) 1170 1171 Input Parameters: 1172 + opt - option name 1173 . text - short string that describes the option 1174 . man - manual page with additional information on option 1175 . list - the possible choices 1176 . currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with 1177 $ PetscOptionsFlist(..., obj->value,value,len,&flg); 1178 $ if (flg) { 1179 - len - the length of the character array value 1180 1181 Output Parameters: 1182 + value - the value to return 1183 - set - PETSC_TRUE if found, else PETSC_FALSE 1184 1185 Level: intermediate 1186 1187 Notes: 1188 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1189 1190 If the user does not supply the option at all value is NOT changed. Thus 1191 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 1192 1193 The default/currentvalue passed into this routine does not get transferred to the output value variable automatically. 1194 1195 See PetscOptionsEList() for when the choices are given in a string array 1196 1197 To get a listing of all currently specified options, 1198 see PetscOptionsView() or PetscOptionsGetAll() 1199 1200 Developer Note: This cannot check for invalid selection because of things like MATAIJ that are not included in the list 1201 1202 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1203 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1204 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1205 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1206 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1207 PetscOptionsFList(), PetscOptionsEList(), PetscOptionsEnum() 1208 M*/ 1209 1210 PetscErrorCode PetscOptionsFList_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char currentvalue[],char value[],size_t len,PetscBool *set) 1211 { 1212 PetscErrorCode ierr; 1213 PetscOptionItem amsopt; 1214 PetscBool lset; 1215 1216 PetscFunctionBegin; 1217 if (!PetscOptionsObject->count) { 1218 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,ltext,man,OPTION_FLIST,&amsopt);CHKERRQ(ierr); 1219 /* must use system malloc since SAWs may free this */ 1220 ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr); 1221 amsopt->flist = list; 1222 } 1223 ierr = PetscOptionsGetString(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,len,&lset);CHKERRQ(ierr); 1224 if (set) *set = lset; 1225 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1226 ierr = PetscFunctionListPrintTypes(PetscOptionsObject->comm,stdout,PetscOptionsObject->prefix,opt,ltext,man,list,currentvalue,lset && value ? value : currentvalue);CHKERRQ(ierr); 1227 } 1228 PetscFunctionReturn(0); 1229 } 1230 1231 /*MC 1232 PetscOptionsEList - Puts a list of option values that a single one may be selected from 1233 1234 Logically Collective on the communicator passed in PetscOptionsBegin() 1235 1236 Synopsis: 1237 #include "petscsys.h" 1238 PetscErrorCode PetscOptionsEList(const char opt[],const char ltext[],const char man[],const char *const *list,PetscInt ntext,const char currentvalue[],PetscInt *value,PetscBool *set) 1239 1240 Input Parameters: 1241 + opt - option name 1242 . ltext - short string that describes the option 1243 . man - manual page with additional information on option 1244 . list - the possible choices (one of these must be selected, anything else is invalid) 1245 . ntext - number of choices 1246 - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with 1247 $ PetscOptionsElist(..., obj->value,&value,&flg); 1248 $ if (flg) { 1249 1250 Output Parameters: 1251 + value - the index of the value to return 1252 - set - PETSC_TRUE if found, else PETSC_FALSE 1253 1254 Level: intermediate 1255 1256 Notes: 1257 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1258 1259 If the user does not supply the option at all value is NOT changed. Thus 1260 you should ALWAYS initialize value if you access it without first checking if the set flag is true. 1261 1262 See PetscOptionsFList() for when the choices are given in a PetscFunctionList() 1263 1264 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1265 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1266 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1267 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1268 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1269 PetscOptionsFList(), PetscOptionsEnum() 1270 M*/ 1271 1272 PetscErrorCode PetscOptionsEList_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char ltext[],const char man[],const char *const *list,PetscInt ntext,const char currentvalue[],PetscInt *value,PetscBool *set) 1273 { 1274 PetscErrorCode ierr; 1275 PetscInt i; 1276 PetscOptionItem amsopt; 1277 PetscBool lset; 1278 1279 PetscFunctionBegin; 1280 if (!PetscOptionsObject->count) { 1281 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,ltext,man,OPTION_ELIST,&amsopt);CHKERRQ(ierr); 1282 /* must use system malloc since SAWs may free this */ 1283 ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr); 1284 ierr = PetscStrNArrayallocpy(ntext,list,(char***)&amsopt->list);CHKERRQ(ierr); 1285 amsopt->nlist = ntext; 1286 } 1287 ierr = PetscOptionsGetEList(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,list,ntext,value,&lset);CHKERRQ(ierr); 1288 if (set) *set = lset; 1289 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1290 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <now %s : formerly %s> %s (choose one of)",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,lset && value ? list[*value] : currentvalue,currentvalue,ltext);CHKERRQ(ierr); 1291 for (i=0; i<ntext; i++) { 1292 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s",list[i]);CHKERRQ(ierr); 1293 } 1294 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," (%s)\n",ManSection(man));CHKERRQ(ierr); 1295 } 1296 PetscFunctionReturn(0); 1297 } 1298 1299 /*MC 1300 PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for 1301 which at most a single value can be true. 1302 1303 Logically Collective on the communicator passed in PetscOptionsBegin() 1304 1305 Synopsis: 1306 #include "petscsys.h" 1307 PetscErrorCode PetscOptionsBoolGroupBegin(const char opt[],const char text[],const char man[],PetscBool *flg) 1308 1309 Input Parameters: 1310 + opt - option name 1311 . text - short string that describes the option 1312 - man - manual page with additional information on option 1313 1314 Output Parameter: 1315 . flg - whether that option was set or not 1316 1317 Level: intermediate 1318 1319 Notes: 1320 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1321 1322 Must be followed by 0 or more PetscOptionsBoolGroup()s and PetscOptionsBoolGroupEnd() 1323 1324 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1325 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1326 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1327 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1328 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1329 PetscOptionsFList(), PetscOptionsEList() 1330 M*/ 1331 1332 PetscErrorCode PetscOptionsBoolGroupBegin_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool *flg) 1333 { 1334 PetscErrorCode ierr; 1335 PetscOptionItem amsopt; 1336 1337 PetscFunctionBegin; 1338 if (!PetscOptionsObject->count) { 1339 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1340 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1341 1342 *(PetscBool*)amsopt->data = PETSC_FALSE; 1343 } 1344 *flg = PETSC_FALSE; 1345 ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr); 1346 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1347 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," Pick at most one of -------------\n");CHKERRQ(ierr); 1348 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1349 } 1350 PetscFunctionReturn(0); 1351 } 1352 1353 /*MC 1354 PetscOptionsBoolGroup - One in a series of logical queries on the options database for 1355 which at most a single value can be true. 1356 1357 Logically Collective on the communicator passed in PetscOptionsBegin() 1358 1359 Synopsis: 1360 #include "petscsys.h" 1361 PetscErrorCode PetscOptionsBoolGroup(const char opt[],const char text[],const char man[],PetscBool *flg) 1362 1363 Input Parameters: 1364 + opt - option name 1365 . text - short string that describes the option 1366 - man - manual page with additional information on option 1367 1368 Output Parameter: 1369 . flg - PETSC_TRUE if found, else PETSC_FALSE 1370 1371 Level: intermediate 1372 1373 Notes: 1374 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1375 1376 Must follow a PetscOptionsBoolGroupBegin() and preceded a PetscOptionsBoolGroupEnd() 1377 1378 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1379 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1380 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1381 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1382 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1383 PetscOptionsFList(), PetscOptionsEList() 1384 M*/ 1385 1386 PetscErrorCode PetscOptionsBoolGroup_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool *flg) 1387 { 1388 PetscErrorCode ierr; 1389 PetscOptionItem amsopt; 1390 1391 PetscFunctionBegin; 1392 if (!PetscOptionsObject->count) { 1393 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1394 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1395 1396 *(PetscBool*)amsopt->data = PETSC_FALSE; 1397 } 1398 *flg = PETSC_FALSE; 1399 ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr); 1400 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1401 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1402 } 1403 PetscFunctionReturn(0); 1404 } 1405 1406 /*MC 1407 PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for 1408 which at most a single value can be true. 1409 1410 Logically Collective on the communicator passed in PetscOptionsBegin() 1411 1412 Synopsis: 1413 #include "petscsys.h" 1414 PetscErrorCode PetscOptionsBoolGroupEnd(const char opt[],const char text[],const char man[],PetscBool *flg) 1415 1416 Input Parameters: 1417 + opt - option name 1418 . text - short string that describes the option 1419 - man - manual page with additional information on option 1420 1421 Output Parameter: 1422 . flg - PETSC_TRUE if found, else PETSC_FALSE 1423 1424 Level: intermediate 1425 1426 Notes: 1427 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1428 1429 Must follow a PetscOptionsBoolGroupBegin() 1430 1431 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1432 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1433 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1434 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1435 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1436 PetscOptionsFList(), PetscOptionsEList() 1437 M*/ 1438 1439 PetscErrorCode PetscOptionsBoolGroupEnd_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool *flg) 1440 { 1441 PetscErrorCode ierr; 1442 PetscOptionItem amsopt; 1443 1444 PetscFunctionBegin; 1445 if (!PetscOptionsObject->count) { 1446 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1447 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1448 1449 *(PetscBool*)amsopt->data = PETSC_FALSE; 1450 } 1451 *flg = PETSC_FALSE; 1452 ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr); 1453 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1454 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1455 } 1456 PetscFunctionReturn(0); 1457 } 1458 1459 /*MC 1460 PetscOptionsBool - Determines if a particular option is in the database with a true or false 1461 1462 Logically Collective on the communicator passed in PetscOptionsBegin() 1463 1464 Synopsis: 1465 #include "petscsys.h" 1466 PetscErrorCode PetscOptionsBool(const char opt[],const char text[],const char man[],PetscBool currentvalue,PetscBool *flg,PetscBool *set) 1467 1468 Input Parameters: 1469 + opt - option name 1470 . text - short string that describes the option 1471 . man - manual page with additional information on option 1472 - currentvalue - the current value 1473 1474 Output Parameters: 1475 + flg - PETSC_TRUE or PETSC_FALSE 1476 - set - PETSC_TRUE if found, else PETSC_FALSE 1477 1478 Notes: 1479 TRUE, true, YES, yes, nostring, and 1 all translate to PETSC_TRUE 1480 FALSE, false, NO, no, and 0 all translate to PETSC_FALSE 1481 1482 If the option is given, but no value is provided, then flg and set are both given the value PETSC_TRUE. That is -requested_bool 1483 is equivalent to -requested_bool true 1484 1485 If the user does not supply the option at all flg is NOT changed. Thus 1486 you should ALWAYS initialize the flg if you access it without first checking if the set flag is true. 1487 1488 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1489 1490 Level: beginner 1491 1492 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 1493 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), 1494 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), 1495 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1496 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1497 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1498 PetscOptionsFList(), PetscOptionsEList() 1499 M*/ 1500 1501 PetscErrorCode PetscOptionsBool_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool currentvalue,PetscBool *flg,PetscBool *set) 1502 { 1503 PetscErrorCode ierr; 1504 PetscBool iset; 1505 PetscOptionItem amsopt; 1506 1507 PetscFunctionBegin; 1508 if (!PetscOptionsObject->count) { 1509 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1510 ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1511 1512 *(PetscBool*)amsopt->data = currentvalue; 1513 } 1514 ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,&iset);CHKERRQ(ierr); 1515 if (set) *set = iset; 1516 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1517 const char *v = PetscBools[currentvalue], *vn = PetscBools[iset && flg ? *flg : currentvalue]; 1518 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: <%s : %s> %s (%s)\n",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,v,vn,text,ManSection(man));CHKERRQ(ierr); 1519 } 1520 PetscFunctionReturn(0); 1521 } 1522 1523 /*MC 1524 PetscOptionsRealArray - Gets an array of double values for a particular 1525 option in the database. The values must be separated with commas with 1526 no intervening spaces. 1527 1528 Logically Collective on the communicator passed in PetscOptionsBegin() 1529 1530 Synopsis: 1531 #include "petscsys.h" 1532 PetscErrorCode PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool *set) 1533 1534 Input Parameters: 1535 + opt - the option one is seeking 1536 . text - short string describing option 1537 . man - manual page for option 1538 - nmax - maximum number of values 1539 1540 Output Parameters: 1541 + value - location to copy values 1542 . nmax - actual number of values found 1543 - set - PETSC_TRUE if found, else PETSC_FALSE 1544 1545 Level: beginner 1546 1547 Notes: 1548 The user should pass in an array of doubles 1549 1550 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1551 1552 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1553 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1554 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1555 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1556 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1557 PetscOptionsFList(), PetscOptionsEList() 1558 M*/ 1559 1560 PetscErrorCode PetscOptionsRealArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool *set) 1561 { 1562 PetscErrorCode ierr; 1563 PetscInt i; 1564 PetscOptionItem amsopt; 1565 1566 PetscFunctionBegin; 1567 if (!PetscOptionsObject->count) { 1568 PetscReal *vals; 1569 1570 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr); 1571 ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr); 1572 vals = (PetscReal*)amsopt->data; 1573 for (i=0; i<*n; i++) vals[i] = value[i]; 1574 amsopt->arraylength = *n; 1575 } 1576 ierr = PetscOptionsGetRealArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr); 1577 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1578 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%g",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,(double)value[0]);CHKERRQ(ierr); 1579 for (i=1; i<*n; i++) { 1580 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%g",(double)value[i]);CHKERRQ(ierr); 1581 } 1582 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1583 } 1584 PetscFunctionReturn(0); 1585 } 1586 1587 /*MC 1588 PetscOptionsScalarArray - Gets an array of Scalar values for a particular 1589 option in the database. The values must be separated with commas with 1590 no intervening spaces. 1591 1592 Logically Collective on the communicator passed in PetscOptionsBegin() 1593 1594 Synopsis: 1595 #include "petscsys.h" 1596 PetscErrorCode PetscOptionsScalarArray(const char opt[],const char text[],const char man[],PetscScalar value[],PetscInt *n,PetscBool *set) 1597 1598 Input Parameters: 1599 + opt - the option one is seeking 1600 . text - short string describing option 1601 . man - manual page for option 1602 - nmax - maximum number of values 1603 1604 Output Parameters: 1605 + value - location to copy values 1606 . nmax - actual number of values found 1607 - set - PETSC_TRUE if found, else PETSC_FALSE 1608 1609 Level: beginner 1610 1611 Notes: 1612 The user should pass in an array of doubles 1613 1614 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1615 1616 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1617 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1618 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1619 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1620 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1621 PetscOptionsFList(), PetscOptionsEList() 1622 M*/ 1623 1624 PetscErrorCode PetscOptionsScalarArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscScalar value[],PetscInt *n,PetscBool *set) 1625 { 1626 PetscErrorCode ierr; 1627 PetscInt i; 1628 PetscOptionItem amsopt; 1629 1630 PetscFunctionBegin; 1631 if (!PetscOptionsObject->count) { 1632 PetscScalar *vals; 1633 1634 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_SCALAR_ARRAY,&amsopt);CHKERRQ(ierr); 1635 ierr = PetscMalloc((*n)*sizeof(PetscScalar),&amsopt->data);CHKERRQ(ierr); 1636 vals = (PetscScalar*)amsopt->data; 1637 for (i=0; i<*n; i++) vals[i] = value[i]; 1638 amsopt->arraylength = *n; 1639 } 1640 ierr = PetscOptionsGetScalarArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr); 1641 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1642 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%g+%gi",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,(double)PetscRealPart(value[0]),(double)PetscImaginaryPart(value[0]));CHKERRQ(ierr); 1643 for (i=1; i<*n; i++) { 1644 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%g+%gi",(double)PetscRealPart(value[i]),(double)PetscImaginaryPart(value[i]));CHKERRQ(ierr); 1645 } 1646 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1647 } 1648 PetscFunctionReturn(0); 1649 } 1650 1651 /*MC 1652 PetscOptionsIntArray - Gets an array of integers for a particular 1653 option in the database. 1654 1655 Logically Collective on the communicator passed in PetscOptionsBegin() 1656 1657 Synopsis: 1658 #include "petscsys.h" 1659 PetscErrorCode PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool *set) 1660 1661 Input Parameters: 1662 + opt - the option one is seeking 1663 . text - short string describing option 1664 . man - manual page for option 1665 - n - maximum number of values 1666 1667 Output Parameters: 1668 + value - location to copy values 1669 . n - actual number of values found 1670 - set - PETSC_TRUE if found, else PETSC_FALSE 1671 1672 Level: beginner 1673 1674 Notes: 1675 The array can be passed as 1676 a comma separated list: 0,1,2,3,4,5,6,7 1677 a range (start-end+1): 0-8 1678 a range with given increment (start-end+1:inc): 0-7:2 1679 a combination of values and ranges separated by commas: 0,1-8,8-15:2 1680 1681 There must be no intervening spaces between the values. 1682 1683 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1684 1685 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1686 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1687 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1688 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1689 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1690 PetscOptionsFList(), PetscOptionsEList(), PetscOptionsRealArray() 1691 M*/ 1692 1693 PetscErrorCode PetscOptionsIntArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool *set) 1694 { 1695 PetscErrorCode ierr; 1696 PetscInt i; 1697 PetscOptionItem amsopt; 1698 1699 PetscFunctionBegin; 1700 if (!PetscOptionsObject->count) { 1701 PetscInt *vals; 1702 1703 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr); 1704 ierr = PetscMalloc1(*n,(PetscInt**)&amsopt->data);CHKERRQ(ierr); 1705 vals = (PetscInt*)amsopt->data; 1706 for (i=0; i<*n; i++) vals[i] = value[i]; 1707 amsopt->arraylength = *n; 1708 } 1709 ierr = PetscOptionsGetIntArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr); 1710 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1711 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%" PetscInt_FMT,PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,value[0]);CHKERRQ(ierr); 1712 for (i=1; i<*n; i++) { 1713 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%" PetscInt_FMT,value[i]);CHKERRQ(ierr); 1714 } 1715 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1716 } 1717 PetscFunctionReturn(0); 1718 } 1719 1720 /*MC 1721 PetscOptionsStringArray - Gets an array of string values for a particular 1722 option in the database. The values must be separated with commas with 1723 no intervening spaces. 1724 1725 Logically Collective on the communicator passed in PetscOptionsBegin() 1726 1727 Synopsis: 1728 #include "petscsys.h" 1729 PetscErrorCode PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool *set) 1730 1731 Input Parameters: 1732 + opt - the option one is seeking 1733 . text - short string describing option 1734 . man - manual page for option 1735 - nmax - maximum number of strings 1736 1737 Output Parameters: 1738 + value - location to copy strings 1739 . nmax - actual number of strings found 1740 - set - PETSC_TRUE if found, else PETSC_FALSE 1741 1742 Level: beginner 1743 1744 Notes: 1745 The user should pass in an array of pointers to char, to hold all the 1746 strings returned by this function. 1747 1748 The user is responsible for deallocating the strings that are 1749 returned. The Fortran interface for this routine is not supported. 1750 1751 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1752 1753 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1754 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1755 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1756 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1757 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1758 PetscOptionsFList(), PetscOptionsEList() 1759 M*/ 1760 1761 PetscErrorCode PetscOptionsStringArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool *set) 1762 { 1763 PetscErrorCode ierr; 1764 PetscOptionItem amsopt; 1765 1766 PetscFunctionBegin; 1767 if (!PetscOptionsObject->count) { 1768 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING_ARRAY,&amsopt);CHKERRQ(ierr); 1769 ierr = PetscMalloc1(*nmax,(char**)&amsopt->data);CHKERRQ(ierr); 1770 1771 amsopt->arraylength = *nmax; 1772 } 1773 ierr = PetscOptionsGetStringArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,nmax,set);CHKERRQ(ierr); 1774 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1775 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 1776 } 1777 PetscFunctionReturn(0); 1778 } 1779 1780 /*MC 1781 PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular 1782 option in the database. The values must be separated with commas with 1783 no intervening spaces. 1784 1785 Logically Collective on the communicator passed in PetscOptionsBegin() 1786 1787 Synopsis: 1788 #include "petscsys.h" 1789 PetscErrorCode PetscOptionsBoolArray(const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set) 1790 1791 Input Parameters: 1792 + opt - the option one is seeking 1793 . text - short string describing option 1794 . man - manual page for option 1795 - nmax - maximum number of values 1796 1797 Output Parameters: 1798 + value - location to copy values 1799 . nmax - actual number of values found 1800 - set - PETSC_TRUE if found, else PETSC_FALSE 1801 1802 Level: beginner 1803 1804 Notes: 1805 The user should pass in an array of doubles 1806 1807 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1808 1809 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1810 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1811 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1812 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1813 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1814 PetscOptionsFList(), PetscOptionsEList() 1815 M*/ 1816 1817 PetscErrorCode PetscOptionsBoolArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set) 1818 { 1819 PetscErrorCode ierr; 1820 PetscInt i; 1821 PetscOptionItem amsopt; 1822 1823 PetscFunctionBegin; 1824 if (!PetscOptionsObject->count) { 1825 PetscBool *vals; 1826 1827 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL_ARRAY,&amsopt);CHKERRQ(ierr); 1828 ierr = PetscMalloc1(*n,(PetscBool**)&amsopt->data);CHKERRQ(ierr); 1829 vals = (PetscBool*)amsopt->data; 1830 for (i=0; i<*n; i++) vals[i] = value[i]; 1831 amsopt->arraylength = *n; 1832 } 1833 ierr = PetscOptionsGetBoolArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr); 1834 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1835 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%d",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,value[0]);CHKERRQ(ierr); 1836 for (i=1; i<*n; i++) { 1837 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%d",value[i]);CHKERRQ(ierr); 1838 } 1839 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1840 } 1841 PetscFunctionReturn(0); 1842 } 1843 1844 /*MC 1845 PetscOptionsViewer - Gets a viewer appropriate for the type indicated by the user 1846 1847 Logically Collective on the communicator passed in PetscOptionsBegin() 1848 1849 Synopsis: 1850 #include "petscsys.h" 1851 PetscErrorCode PetscOptionsViewer(const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool *set) 1852 1853 Input Parameters: 1854 + opt - option name 1855 . text - short string that describes the option 1856 - man - manual page with additional information on option 1857 1858 Output Parameters: 1859 + viewer - the viewer 1860 - set - PETSC_TRUE if found, else PETSC_FALSE 1861 1862 Level: beginner 1863 1864 Notes: 1865 Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1866 1867 See PetscOptionsGetViewer() for the format of the supplied viewer and its options 1868 1869 .seealso: PetscOptionsGetViewer(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 1870 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 1871 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 1872 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1873 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1874 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1875 PetscOptionsFList(), PetscOptionsEList() 1876 M*/ 1877 1878 PetscErrorCode PetscOptionsViewer_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool *set) 1879 { 1880 PetscErrorCode ierr; 1881 PetscOptionItem amsopt; 1882 1883 PetscFunctionBegin; 1884 if (!PetscOptionsObject->count) { 1885 ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr); 1886 /* must use system malloc since SAWs may free this */ 1887 ierr = PetscStrdup("",(char**)&amsopt->data);CHKERRQ(ierr); 1888 } 1889 ierr = PetscOptionsGetViewer(PetscOptionsObject->comm,PetscOptionsObject->options,PetscOptionsObject->prefix,opt,viewer,format,set);CHKERRQ(ierr); 1890 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1891 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%s>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,"",text,ManSection(man));CHKERRQ(ierr); 1892 } 1893 PetscFunctionReturn(0); 1894 } 1895 1896 /*@C 1897 PetscOptionsHead - Puts a heading before listing any more published options. Used, for example, 1898 in KSPSetFromOptions_GMRES(). 1899 1900 Logically Collective on the communicator passed in PetscOptionsBegin() 1901 1902 Input Parameter: 1903 . head - the heading text 1904 1905 Level: intermediate 1906 1907 Notes: 1908 Must be between a PetscOptionsBegin() and a PetscOptionsEnd(), and PetscOptionsObject created in PetscOptionsBegin() should be the first argument 1909 1910 Can be followed by a call to PetscOptionsTail() in the same function. 1911 1912 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1913 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1914 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1915 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1916 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1917 PetscOptionsFList(), PetscOptionsEList() 1918 @*/ 1919 PetscErrorCode PetscOptionsHead(PetscOptionItems *PetscOptionsObject,const char head[]) 1920 { 1921 PetscErrorCode ierr; 1922 1923 PetscFunctionBegin; 1924 if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1925 ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s\n",head);CHKERRQ(ierr); 1926 } 1927 PetscFunctionReturn(0); 1928 } 1929 1930