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