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