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