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