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