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