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