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