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