153acd3b1SBarry Smith #define PETSC_DLL 253acd3b1SBarry Smith /* 33fc1eb6aSBarry Smith Implements the higher-level options database querying methods. These are self-documenting and can attach at runtime to 43fc1eb6aSBarry Smith GUI code to display the options and get values from the users. 553acd3b1SBarry Smith 653acd3b1SBarry Smith */ 753acd3b1SBarry Smith 8d382aafbSBarry Smith #include "petscsys.h" /*I "petscsys.h" I*/ 953acd3b1SBarry Smith #if defined(PETSC_HAVE_STDLIB_H) 1053acd3b1SBarry Smith #include <stdlib.h> 1153acd3b1SBarry Smith #endif 1253acd3b1SBarry Smith 1353acd3b1SBarry Smith /* 1453acd3b1SBarry Smith Keep a linked list of options that have been posted and we are waiting for 153fc1eb6aSBarry Smith user selection. See the manual page for PetscOptionsBegin() 1653acd3b1SBarry Smith 1753acd3b1SBarry Smith Eventually we'll attach this beast to a MPI_Comm 1853acd3b1SBarry Smith */ 19f8d0b74dSMatthew Knepley PetscOptionsObjectType PetscOptionsObject; 2053acd3b1SBarry Smith PetscInt PetscOptionsPublishCount = 0; 2153acd3b1SBarry Smith 2253acd3b1SBarry Smith #undef __FUNCT__ 2353acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsBegin_Private" 2453acd3b1SBarry Smith /* 2553acd3b1SBarry Smith Handles setting up the data structure in a call to PetscOptionsBegin() 2653acd3b1SBarry Smith */ 2753acd3b1SBarry Smith PetscErrorCode PetscOptionsBegin_Private(MPI_Comm comm,const char prefix[],const char title[],const char mansec[]) 2853acd3b1SBarry Smith { 2953acd3b1SBarry Smith PetscErrorCode ierr; 3053acd3b1SBarry Smith 3153acd3b1SBarry Smith PetscFunctionBegin; 3253acd3b1SBarry Smith PetscOptionsObject.next = 0; 3353acd3b1SBarry Smith PetscOptionsObject.comm = comm; 346356e834SBarry Smith PetscOptionsObject.changedmethod = PETSC_FALSE; 35f8d0b74dSMatthew Knepley if (PetscOptionsObject.prefix) { 36503cfb0cSBarry Smith ierr = PetscFree(PetscOptionsObject.prefix);CHKERRQ(ierr); PetscOptionsObject.prefix = 0; 37f8d0b74dSMatthew Knepley } 3853acd3b1SBarry Smith ierr = PetscStrallocpy(prefix,&PetscOptionsObject.prefix);CHKERRQ(ierr); 39f8d0b74dSMatthew Knepley if (PetscOptionsObject.title) { 40503cfb0cSBarry Smith ierr = PetscFree(PetscOptionsObject.title);CHKERRQ(ierr); PetscOptionsObject.title = 0; 41f8d0b74dSMatthew Knepley } 4253acd3b1SBarry Smith ierr = PetscStrallocpy(title,&PetscOptionsObject.title);CHKERRQ(ierr); 4353acd3b1SBarry Smith 4453acd3b1SBarry Smith ierr = PetscOptionsHasName(PETSC_NULL,"-help",&PetscOptionsObject.printhelp);CHKERRQ(ierr); 4553acd3b1SBarry Smith if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) { 4661b37b28SSatish Balay if (!PetscOptionsObject.alreadyprinted) { 4753acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(comm,"%s -------------------------------------------------\n",title);CHKERRQ(ierr); 4853acd3b1SBarry Smith } 4961b37b28SSatish Balay } 5053acd3b1SBarry Smith PetscFunctionReturn(0); 5153acd3b1SBarry Smith } 5253acd3b1SBarry Smith 5353acd3b1SBarry Smith /* 5453acd3b1SBarry Smith Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd() 5553acd3b1SBarry Smith */ 5653acd3b1SBarry Smith #undef __FUNCT__ 5753acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsCreate_Private" 58e3ed6ec8SBarry Smith static int PetscOptionsCreate_Private(const char opt[],const char text[],const char man[],PetscOptionType t,PetscOptions *amsopt) 5953acd3b1SBarry Smith { 6053acd3b1SBarry Smith int ierr; 6153acd3b1SBarry Smith PetscOptions next; 6253acd3b1SBarry Smith 6353acd3b1SBarry Smith PetscFunctionBegin; 64e3ed6ec8SBarry Smith ierr = PetscNew(struct _p_PetscOptions,amsopt);CHKERRQ(ierr); 6553acd3b1SBarry Smith (*amsopt)->next = 0; 6653acd3b1SBarry Smith (*amsopt)->set = PETSC_FALSE; 676356e834SBarry Smith (*amsopt)->type = t; 6853acd3b1SBarry Smith (*amsopt)->data = 0; 6961b37b28SSatish Balay 7053acd3b1SBarry Smith ierr = PetscStrallocpy(text,&(*amsopt)->text);CHKERRQ(ierr); 7153acd3b1SBarry Smith ierr = PetscStrallocpy(opt,&(*amsopt)->option);CHKERRQ(ierr); 726356e834SBarry Smith ierr = PetscStrallocpy(man,&(*amsopt)->man);CHKERRQ(ierr); 7353acd3b1SBarry Smith 7453acd3b1SBarry Smith if (!PetscOptionsObject.next) { 7553acd3b1SBarry Smith PetscOptionsObject.next = *amsopt; 7653acd3b1SBarry Smith } else { 7753acd3b1SBarry Smith next = PetscOptionsObject.next; 7853acd3b1SBarry Smith while (next->next) next = next->next; 7953acd3b1SBarry Smith next->next = *amsopt; 8053acd3b1SBarry Smith } 8153acd3b1SBarry Smith PetscFunctionReturn(0); 8253acd3b1SBarry Smith } 8353acd3b1SBarry Smith 8453acd3b1SBarry Smith #undef __FUNCT__ 85aee2cecaSBarry Smith #define __FUNCT__ "PetscScanString" 86aee2cecaSBarry Smith /* 873fc1eb6aSBarry Smith PetscScanString - Gets user input via stdin from process and broadcasts to all processes 883fc1eb6aSBarry Smith 893fc1eb6aSBarry Smith Collective on MPI_Comm 903fc1eb6aSBarry Smith 913fc1eb6aSBarry Smith Input Parameters: 923fc1eb6aSBarry Smith + commm - communicator for the broadcast, must be PETSC_COMM_WORLD 933fc1eb6aSBarry Smith . n - length of the string, must be the same on all processes 943fc1eb6aSBarry Smith - str - location to store input 95aee2cecaSBarry Smith 96aee2cecaSBarry Smith Bugs: 97aee2cecaSBarry Smith . Assumes process 0 of the given communicator has access to stdin 98aee2cecaSBarry Smith 99aee2cecaSBarry Smith */ 1003fc1eb6aSBarry Smith static PetscErrorCode PetscScanString(MPI_Comm comm,size_t n,char str[]) 101aee2cecaSBarry Smith { 102330cf3c9SBarry Smith size_t i; 103aee2cecaSBarry Smith char c; 1043fc1eb6aSBarry Smith PetscMPIInt rank,nm; 105aee2cecaSBarry Smith PetscErrorCode ierr; 106aee2cecaSBarry Smith 107aee2cecaSBarry Smith PetscFunctionBegin; 108aee2cecaSBarry Smith ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); 109aee2cecaSBarry Smith if (!rank) { 110aee2cecaSBarry Smith c = (char) getchar(); 111aee2cecaSBarry Smith i = 0; 112aee2cecaSBarry Smith while ( c != '\n' && i < n-1) { 113aee2cecaSBarry Smith str[i++] = c; 114aee2cecaSBarry Smith c = (char) getchar(); 115aee2cecaSBarry Smith } 116aee2cecaSBarry Smith str[i] = 0; 117aee2cecaSBarry Smith } 1183fc1eb6aSBarry Smith nm = PetscMPIIntCast(n); 1193fc1eb6aSBarry Smith ierr = MPI_Bcast(str,nm,MPI_CHAR,0,comm);CHKERRQ(ierr); 120aee2cecaSBarry Smith PetscFunctionReturn(0); 121aee2cecaSBarry Smith } 122aee2cecaSBarry Smith 123aee2cecaSBarry Smith #undef __FUNCT__ 124aee2cecaSBarry Smith #define __FUNCT__ "PetscOptionsGetFromTextInput" 125aee2cecaSBarry Smith /* 1263cc1e11dSBarry Smith PetscOptionsGetFromTextInput - Presents all the PETSc Options processed by the program so the user may change them at runtime 127aee2cecaSBarry Smith 128aee2cecaSBarry Smith Notes: this isn't really practical, it is just to demonstrate the principle 129aee2cecaSBarry Smith 130aee2cecaSBarry Smith Bugs: 131aee2cecaSBarry Smith + All processes must traverse through the exact same set of option queries do to the call to PetscScanString() 1323cc1e11dSBarry Smith . Internal strings have arbitrary length and string copies are not checked that they fit into string space 133aee2cecaSBarry Smith - Only works for PetscInt == int, PetscReal == double etc 134aee2cecaSBarry Smith 1353cc1e11dSBarry Smith Developer Notes: Normally the GUI that presents the options the user and retrieves the values would be running in a different 1363cc1e11dSBarry Smith address space and communicating with the PETSc program 1373cc1e11dSBarry Smith 138aee2cecaSBarry Smith */ 139aee2cecaSBarry Smith PetscErrorCode PetscOptionsGetFromTextInput() 1406356e834SBarry Smith { 1416356e834SBarry Smith PetscErrorCode ierr; 1426356e834SBarry Smith PetscOptions next = PetscOptionsObject.next; 1436356e834SBarry Smith char str[512]; 144a4404d99SBarry Smith PetscInt id; 145a4404d99SBarry Smith PetscReal ir,*valr; 146330cf3c9SBarry Smith PetscInt *vald; 147330cf3c9SBarry Smith size_t i; 1486356e834SBarry Smith 149e26ddf31SBarry Smith ierr = (*PetscPrintf)(PETSC_COMM_WORLD,"%s -------------------------------------------------\n",PetscOptionsObject.title);CHKERRQ(ierr); 1506356e834SBarry Smith while (next) { 1516356e834SBarry Smith switch (next->type) { 1526356e834SBarry Smith case OPTION_HEAD: 1536356e834SBarry Smith break; 154e26ddf31SBarry Smith case OPTION_INT_ARRAY: 155e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1);CHKERRQ(ierr); 156e26ddf31SBarry Smith vald = (PetscInt*) next->data; 157e26ddf31SBarry Smith for (i=0; i<next->arraylength; i++) { 158e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,"%d",vald[i]);CHKERRQ(ierr); 159e26ddf31SBarry Smith if (i < next->arraylength-1) { 160e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr); 161e26ddf31SBarry Smith } 162e26ddf31SBarry Smith } 163e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s)",next->text,next->man);CHKERRQ(ierr); 164e26ddf31SBarry Smith ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 165e26ddf31SBarry Smith if (str[0]) { 166e26ddf31SBarry Smith PetscToken token; 167e26ddf31SBarry Smith PetscInt n=0,nmax = next->arraylength,*dvalue = (PetscInt*)next->data,start,end; 168e26ddf31SBarry Smith size_t len; 169e26ddf31SBarry Smith char* value; 170e26ddf31SBarry Smith PetscTruth foundrange; 171e26ddf31SBarry Smith 172e26ddf31SBarry Smith next->set = PETSC_TRUE; 173e26ddf31SBarry Smith value = str; 174e26ddf31SBarry Smith ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 175e26ddf31SBarry Smith ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 176e26ddf31SBarry Smith while (n < nmax) { 177e26ddf31SBarry Smith if (!value) break; 178e26ddf31SBarry Smith 179e26ddf31SBarry Smith /* look for form d-D where d and D are integers */ 180e26ddf31SBarry Smith foundrange = PETSC_FALSE; 181e26ddf31SBarry Smith ierr = PetscStrlen(value,&len);CHKERRQ(ierr); 182e26ddf31SBarry Smith if (value[0] == '-') i=2; 183e26ddf31SBarry Smith else i=1; 184330cf3c9SBarry Smith for (;i<len; i++) { 185e26ddf31SBarry Smith if (value[i] == '-') { 186e32f2f54SBarry Smith if (i == len-1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry %s\n",n,value); 187e26ddf31SBarry Smith value[i] = 0; 188e26ddf31SBarry Smith ierr = PetscOptionsAtoi(value,&start);CHKERRQ(ierr); 189e26ddf31SBarry Smith ierr = PetscOptionsAtoi(value+i+1,&end);CHKERRQ(ierr); 190e32f2f54SBarry Smith 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); 191e32f2f54SBarry Smith 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); 192e26ddf31SBarry Smith for (;start<end; start++) { 193e26ddf31SBarry Smith *dvalue = start; dvalue++;n++; 194e26ddf31SBarry Smith } 195e26ddf31SBarry Smith foundrange = PETSC_TRUE; 196e26ddf31SBarry Smith break; 197e26ddf31SBarry Smith } 198e26ddf31SBarry Smith } 199e26ddf31SBarry Smith if (!foundrange) { 200e26ddf31SBarry Smith ierr = PetscOptionsAtoi(value,dvalue);CHKERRQ(ierr); 201e26ddf31SBarry Smith dvalue++; 202e26ddf31SBarry Smith n++; 203e26ddf31SBarry Smith } 204e26ddf31SBarry Smith ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 205e26ddf31SBarry Smith } 206e26ddf31SBarry Smith ierr = PetscTokenDestroy(token);CHKERRQ(ierr); 207e26ddf31SBarry Smith } 208e26ddf31SBarry Smith break; 209e26ddf31SBarry Smith case OPTION_REAL_ARRAY: 210e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1);CHKERRQ(ierr); 211e26ddf31SBarry Smith valr = (PetscReal*) next->data; 212e26ddf31SBarry Smith for (i=0; i<next->arraylength; i++) { 213e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,"%g",valr[i]);CHKERRQ(ierr); 214e26ddf31SBarry Smith if (i < next->arraylength-1) { 215e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr); 216e26ddf31SBarry Smith } 217e26ddf31SBarry Smith } 218e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s)",next->text,next->man);CHKERRQ(ierr); 219e26ddf31SBarry Smith ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 220e26ddf31SBarry Smith if (str[0]) { 221e26ddf31SBarry Smith PetscToken token; 222e26ddf31SBarry Smith PetscInt n=0,nmax = next->arraylength; 223e26ddf31SBarry Smith PetscReal *dvalue = (PetscReal*)next->data; 224e26ddf31SBarry Smith char* value; 225e26ddf31SBarry Smith 226e26ddf31SBarry Smith next->set = PETSC_TRUE; 227e26ddf31SBarry Smith value = str; 228e26ddf31SBarry Smith ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 229e26ddf31SBarry Smith ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 230e26ddf31SBarry Smith while (n < nmax) { 231e26ddf31SBarry Smith if (!value) break; 232e26ddf31SBarry Smith ierr = PetscOptionsAtod(value,dvalue);CHKERRQ(ierr); 233e26ddf31SBarry Smith dvalue++; 234e26ddf31SBarry Smith n++; 235e26ddf31SBarry Smith ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 236e26ddf31SBarry Smith } 237e26ddf31SBarry Smith ierr = PetscTokenDestroy(token);CHKERRQ(ierr); 238e26ddf31SBarry Smith } 239e26ddf31SBarry Smith break; 2406356e834SBarry Smith case OPTION_INT: 241e26ddf31SBarry Smith 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); 2423fc1eb6aSBarry Smith ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 2433fc1eb6aSBarry Smith if (str[0]) { 244c272547aSJed Brown #if defined(PETSC_USE_64BIT_INDICES) 245c272547aSJed Brown sscanf(str,"%lld",&id); 246c272547aSJed Brown #else 247aee2cecaSBarry Smith sscanf(str,"%d",&id); 248c272547aSJed Brown #endif 249aee2cecaSBarry Smith next->set = PETSC_TRUE; 250aee2cecaSBarry Smith *((PetscInt*)next->data) = id; 251aee2cecaSBarry Smith } 252aee2cecaSBarry Smith break; 253aee2cecaSBarry Smith case OPTION_REAL: 254e26ddf31SBarry Smith 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); 2553fc1eb6aSBarry Smith ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 2563fc1eb6aSBarry Smith if (str[0]) { 257a4404d99SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE) 258a4404d99SBarry Smith sscanf(str,"%e",&ir); 259a4404d99SBarry Smith #else 260aee2cecaSBarry Smith sscanf(str,"%le",&ir); 261a4404d99SBarry Smith #endif 262aee2cecaSBarry Smith next->set = PETSC_TRUE; 263aee2cecaSBarry Smith *((PetscReal*)next->data) = ir; 264aee2cecaSBarry Smith } 265aee2cecaSBarry Smith break; 266aee2cecaSBarry Smith case OPTION_LOGICAL: 267aee2cecaSBarry Smith case OPTION_STRING: 268e26ddf31SBarry Smith 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); 2693fc1eb6aSBarry Smith ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 2703fc1eb6aSBarry Smith if (str[0]) { 271aee2cecaSBarry Smith next->set = PETSC_TRUE; 272330cf3c9SBarry Smith ierr = PetscStrcpy((char*)next->data,str);CHKERRQ(ierr); 2736356e834SBarry Smith } 2746356e834SBarry Smith break; 2753cc1e11dSBarry Smith case OPTION_LIST: 2763cc1e11dSBarry Smith ierr = PetscFListPrintTypes(PETSC_COMM_WORLD,stdout,PetscOptionsObject.prefix,next->option,next->text,next->man,next->flist,(char*)next->data);CHKERRQ(ierr); 2773cc1e11dSBarry Smith ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 2783cc1e11dSBarry Smith if (str[0]) { 2793cc1e11dSBarry Smith PetscOptionsObject.changedmethod = PETSC_TRUE; 2803cc1e11dSBarry Smith next->set = PETSC_TRUE; 281330cf3c9SBarry Smith ierr = PetscStrcpy((char*)next->data,str);CHKERRQ(ierr); 2823cc1e11dSBarry Smith } 2833cc1e11dSBarry Smith break; 284b432afdaSMatthew Knepley default: 285b432afdaSMatthew Knepley break; 2866356e834SBarry Smith } 2876356e834SBarry Smith next = next->next; 2886356e834SBarry Smith } 2896356e834SBarry Smith PetscFunctionReturn(0); 2906356e834SBarry Smith } 2916356e834SBarry Smith 292b3506946SBarry Smith #if defined(PETSC_HAVE_AMS) 2931ae3d29cSBarry Smith #define CHKERRAMS(err) if (err) {char *msg; AMS_Explain_error((err), &(msg)); SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"AMS Error: %s",msg);} 2941ae3d29cSBarry Smith #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);} 295d5649816SBarry Smith 296d5649816SBarry Smith static int count = 0; 297d5649816SBarry Smith 298b3506946SBarry Smith #undef __FUNCT__ 299d5649816SBarry Smith #define __FUNCT__ "PetscOptionsAMSDestroy" 300d5649816SBarry Smith PetscErrorCode PetscOptionsAMSDestroy(void) 301d5649816SBarry Smith { 302d5649816SBarry Smith PetscErrorCode ierr; 303d5649816SBarry Smith AMS_Comm acomm = -1; 304d5649816SBarry Smith AMS_Memory amem = -1; 305d5649816SBarry Smith char options[16]; 306d5649816SBarry Smith const char *string = "Exit"; 307d5649816SBarry Smith 308d5649816SBarry Smith /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */ 309d5649816SBarry Smith ierr = PetscViewerAMSGetAMSComm(PETSC_VIEWER_AMS_(PETSC_COMM_WORLD),&acomm);CHKERRQ(ierr); 310d5649816SBarry Smith sprintf(options,"Options_%d",count++); 311d5649816SBarry Smith ierr = AMS_Memory_create(acomm,options,&amem);CHKERRAMS(ierr); 312d5649816SBarry Smith ierr = AMS_Memory_add_field(amem,"Exit",&string,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,"Exit"); 313d5649816SBarry Smith 314d5649816SBarry Smith ierr = AMS_Memory_take_access(amem);CHKERRAMS(ierr); 315d5649816SBarry Smith ierr = AMS_Memory_publish(amem);CHKERRAMS(ierr); 316d5649816SBarry Smith ierr = AMS_Memory_grant_access(amem);CHKERRAMS(ierr); 317d5649816SBarry Smith /* wait until accessor has unlocked the memory */ 318d5649816SBarry Smith ierr = AMS_Memory_lock(amem,0);CHKERRAMS(ierr); 319d5649816SBarry Smith ierr = AMS_Memory_take_access(amem);CHKERRAMS(ierr); 320d5649816SBarry Smith ierr = AMS_Memory_grant_access(amem);CHKERRAMS(ierr); 321d5649816SBarry Smith ierr = AMS_Memory_destroy(amem);CHKERRAMS(ierr); 322d5649816SBarry Smith PetscFunctionReturn(0); 323d5649816SBarry Smith } 324d5649816SBarry Smith 325d5649816SBarry Smith #undef __FUNCT__ 326d5649816SBarry Smith #define __FUNCT__ "PetscOptionsAMSInput" 327b3506946SBarry Smith /* 328d5649816SBarry Smith PetscOptionsAMSInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the AMS 329b3506946SBarry Smith 330b3506946SBarry Smith Bugs: 331b3506946SBarry Smith + All processes must traverse through the exact same set of option queries do to the call to PetscScanString() 332b3506946SBarry Smith . Internal strings have arbitrary length and string copies are not checked that they fit into string space 333b3506946SBarry Smith - Only works for PetscInt == int, PetscReal == double etc 334b3506946SBarry Smith 335b3506946SBarry Smith 336b3506946SBarry Smith */ 337d5649816SBarry Smith PetscErrorCode PetscOptionsAMSInput() 338b3506946SBarry Smith { 339b3506946SBarry Smith PetscErrorCode ierr; 340b3506946SBarry Smith PetscOptions next = PetscOptionsObject.next; 341d5649816SBarry Smith static int mancount = 0; 342b3506946SBarry Smith char options[16]; 343b3506946SBarry Smith AMS_Comm acomm = -1; 344b3506946SBarry Smith AMS_Memory amem = -1; 345b3506946SBarry Smith PetscTruth changedmethod = PETSC_FALSE; 3469f32e415SBarry Smith char manname[16]; 347b3506946SBarry Smith 348b3506946SBarry Smith /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */ 349b3506946SBarry Smith ierr = PetscViewerAMSGetAMSComm(PETSC_VIEWER_AMS_(PETSC_COMM_WORLD),&acomm);CHKERRQ(ierr); 350b3506946SBarry Smith sprintf(options,"Options_%d",count++); 3511ae3d29cSBarry Smith ierr = AMS_Memory_create(acomm,options,&amem);CHKERRAMS(ierr); 3521ae3d29cSBarry Smith ierr = AMS_Memory_take_access(amem);CHKERRAMS(ierr); 3531bc75a8dSBarry Smith PetscOptionsObject.pprefix = PetscOptionsObject.prefix; /* AMS will change this, so cannot pass prefix directly */ 3541bc75a8dSBarry Smith 3551ae3d29cSBarry Smith ierr = AMS_Memory_add_field(amem,PetscOptionsObject.title,&PetscOptionsObject.pprefix,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,PetscOptionsObject.title); 3561ae3d29cSBarry Smith // ierr = AMS_Memory_add_field(amem,"mansec",&PetscOptionsObject.pprefix,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMS(ierr); 3571ae3d29cSBarry Smith ierr = AMS_Memory_add_field(amem,"ChangedMethod",&changedmethod,1,AMS_BOOLEAN,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,"ChangedMethod"); 358b3506946SBarry Smith 359b3506946SBarry Smith while (next) { 3601ae3d29cSBarry Smith ierr = AMS_Memory_add_field(amem,next->option,&next->set,1,AMS_INT,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->option); 3611bc75a8dSBarry Smith ierr = PetscMalloc(sizeof(char*),&next->pman);CHKERRQ(ierr); 3621bc75a8dSBarry Smith *(char **)next->pman = next->man; 3639f32e415SBarry Smith sprintf(manname,"man_%d",mancount++); 3641ae3d29cSBarry Smith ierr = AMS_Memory_add_field(amem,manname,next->pman,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,manname); 3659f32e415SBarry Smith 366b3506946SBarry Smith switch (next->type) { 367b3506946SBarry Smith case OPTION_HEAD: 368b3506946SBarry Smith break; 369b3506946SBarry Smith case OPTION_INT_ARRAY: 3701ae3d29cSBarry Smith 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); 371b3506946SBarry Smith break; 372b3506946SBarry Smith case OPTION_REAL_ARRAY: 3731ae3d29cSBarry Smith 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); 374b3506946SBarry Smith break; 375b3506946SBarry Smith case OPTION_INT: 3761ae3d29cSBarry Smith ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_INT,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text); 377b3506946SBarry Smith break; 378b3506946SBarry Smith case OPTION_REAL: 3791ae3d29cSBarry Smith ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_DOUBLE,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text); 380b3506946SBarry Smith break; 381b3506946SBarry Smith case OPTION_LOGICAL: 3821ae3d29cSBarry Smith ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_BOOLEAN,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text); 3831ae3d29cSBarry Smith break; 3841ae3d29cSBarry Smith case OPTION_LOGICAL_ARRAY: 3851ae3d29cSBarry Smith 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); 38671f08665SBarry Smith break; 387b3506946SBarry Smith case OPTION_STRING: 3881ae3d29cSBarry Smith ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text); 3891ae3d29cSBarry Smith break; 3901ae3d29cSBarry Smith case OPTION_STRING_ARRAY: 3911ae3d29cSBarry Smith 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); 392b3506946SBarry Smith break; 393b3506946SBarry Smith case OPTION_LIST: 39471f08665SBarry Smith {PetscInt ntext; 39571f08665SBarry Smith char ldefault[128]; 39671f08665SBarry Smith ierr = PetscStrcpy(ldefault,"DEFAULT:");CHKERRQ(ierr); 39771f08665SBarry Smith ierr = PetscStrcat(ldefault,next->text);CHKERRQ(ierr); 3981ae3d29cSBarry Smith ierr = AMS_Memory_add_field(amem,ldefault,next->data,1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,ldefault); 39971f08665SBarry Smith ierr = PetscFListGet(next->flist,(char***)&next->edata,&ntext);CHKERRQ(ierr); 400d5649816SBarry Smith 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); 4011ae3d29cSBarry Smith break;} 4021ae3d29cSBarry Smith case OPTION_ELIST: 403d5649816SBarry Smith {PetscInt ntext = next->nlist; 4041ae3d29cSBarry Smith char ldefault[128]; 4051ae3d29cSBarry Smith ierr = PetscStrcpy(ldefault,"DEFAULT:");CHKERRQ(ierr); 4061ae3d29cSBarry Smith ierr = PetscStrcat(ldefault,next->text);CHKERRQ(ierr); 4071ae3d29cSBarry Smith ierr = AMS_Memory_add_field(amem,ldefault,next->data,1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,ldefault); 4081ae3d29cSBarry Smith ierr = PetscMalloc((ntext+1)*sizeof(char**),&next->edata);CHKERRQ(ierr); 4091ae3d29cSBarry Smith ierr = PetscMemcpy(next->edata,next->list,ntext*sizeof(char*));CHKERRQ(ierr); 4101ae3d29cSBarry Smith ierr = AMS_Memory_add_field(amem,next->text,next->edata,ntext,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text); 41171f08665SBarry Smith break;} 412b3506946SBarry Smith default: 413b3506946SBarry Smith break; 414b3506946SBarry Smith } 415b3506946SBarry Smith next = next->next; 416b3506946SBarry Smith } 417b3506946SBarry Smith 4181ae3d29cSBarry Smith ierr = AMS_Memory_publish(amem);CHKERRAMS(ierr); 4191ae3d29cSBarry Smith ierr = AMS_Memory_grant_access(amem);CHKERRAMS(ierr); 420b3506946SBarry Smith /* wait until accessor has unlocked the memory */ 4211ae3d29cSBarry Smith ierr = AMS_Memory_lock(amem,0);CHKERRAMS(ierr); 4221ae3d29cSBarry Smith ierr = AMS_Memory_take_access(amem);CHKERRAMS(ierr); 423b3506946SBarry Smith 424b3506946SBarry Smith /* reset counter to -2; this updates the screen with the new options for the selected method */ 425b3506946SBarry Smith if (changedmethod) PetscOptionsPublishCount = -2; 426b3506946SBarry Smith 4271ae3d29cSBarry Smith ierr = AMS_Memory_grant_access(amem);CHKERRAMS(ierr); 4281ae3d29cSBarry Smith ierr = AMS_Memory_destroy(amem);CHKERRAMS(ierr); 429b3506946SBarry Smith PetscFunctionReturn(0); 430b3506946SBarry Smith } 431b3506946SBarry Smith #endif 432b3506946SBarry Smith 4336356e834SBarry Smith #undef __FUNCT__ 43453acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsEnd_Private" 43553acd3b1SBarry Smith PetscErrorCode PetscOptionsEnd_Private(void) 43653acd3b1SBarry Smith { 43753acd3b1SBarry Smith PetscErrorCode ierr; 4386356e834SBarry Smith PetscOptions last; 4396356e834SBarry Smith char option[256],value[1024],tmp[32]; 440330cf3c9SBarry Smith size_t j; 44153acd3b1SBarry Smith 44253acd3b1SBarry Smith PetscFunctionBegin; 4436356e834SBarry Smith 4441bc75a8dSBarry Smith CHKMEMQ; 445aee2cecaSBarry Smith if (PetscOptionsObject.next) { 446b3506946SBarry Smith if (!PetscOptionsPublishCount) { 447b3506946SBarry Smith #if defined(PETSC_HAVE_AMS) 448d5649816SBarry Smith ierr = PetscOptionsAMSInput();CHKERRQ(ierr); 449b3506946SBarry Smith #else 45071f08665SBarry Smith ierr = PetscOptionsGetFromTextInput();CHKERRQ(ierr); 451b3506946SBarry Smith #endif 452aee2cecaSBarry Smith } 453aee2cecaSBarry Smith } 4546356e834SBarry Smith 455503cfb0cSBarry Smith ierr = PetscFree(PetscOptionsObject.title);CHKERRQ(ierr); PetscOptionsObject.title = 0; 456503cfb0cSBarry Smith ierr = PetscFree(PetscOptionsObject.prefix);CHKERRQ(ierr); PetscOptionsObject.prefix = 0; 4576356e834SBarry Smith 4586356e834SBarry Smith /* reset counter to -2; this updates the screen with the new options for the selected method */ 4596356e834SBarry Smith if (PetscOptionsObject.changedmethod) PetscOptionsPublishCount = -2; 46061b37b28SSatish Balay /* reset alreadyprinted flag */ 46161b37b28SSatish Balay PetscOptionsObject.alreadyprinted = PETSC_FALSE; 4626356e834SBarry Smith 4636356e834SBarry Smith while (PetscOptionsObject.next) { 4646356e834SBarry Smith if (PetscOptionsObject.next->set) { 4656356e834SBarry Smith if (PetscOptionsObject.prefix) { 4666356e834SBarry Smith ierr = PetscStrcpy(option,"-");CHKERRQ(ierr); 4676356e834SBarry Smith ierr = PetscStrcat(option,PetscOptionsObject.prefix);CHKERRQ(ierr); 4686356e834SBarry Smith ierr = PetscStrcat(option,PetscOptionsObject.next->option+1);CHKERRQ(ierr); 4696356e834SBarry Smith } else { 4706356e834SBarry Smith ierr = PetscStrcpy(option,PetscOptionsObject.next->option);CHKERRQ(ierr); 4716356e834SBarry Smith } 4726356e834SBarry Smith 4736356e834SBarry Smith switch (PetscOptionsObject.next->type) { 4746356e834SBarry Smith case OPTION_HEAD: 4756356e834SBarry Smith break; 476e26ddf31SBarry Smith case OPTION_INT_ARRAY: 477e26ddf31SBarry Smith sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[0]); 478e26ddf31SBarry Smith for (j=1; j<PetscOptionsObject.next->arraylength; j++) { 479e26ddf31SBarry Smith sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[j]); 480e26ddf31SBarry Smith ierr = PetscStrcat(value,",");CHKERRQ(ierr); 481e26ddf31SBarry Smith ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 482e26ddf31SBarry Smith } 483e26ddf31SBarry Smith break; 4846356e834SBarry Smith case OPTION_INT: 4857a72a596SBarry Smith sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject.next->data); 4866356e834SBarry Smith break; 4876356e834SBarry Smith case OPTION_REAL: 4887a72a596SBarry Smith sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject.next->data); 4896356e834SBarry Smith break; 4906356e834SBarry Smith case OPTION_REAL_ARRAY: 4917a72a596SBarry Smith sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[0]); 4926356e834SBarry Smith for (j=1; j<PetscOptionsObject.next->arraylength; j++) { 4937a72a596SBarry Smith sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[j]); 4946356e834SBarry Smith ierr = PetscStrcat(value,",");CHKERRQ(ierr); 4956356e834SBarry Smith ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 4966356e834SBarry Smith } 4976356e834SBarry Smith break; 4986356e834SBarry Smith case OPTION_LOGICAL: 49971f08665SBarry Smith sprintf(value,"%d",*(int*)PetscOptionsObject.next->data); 5006356e834SBarry Smith break; 5011ae3d29cSBarry Smith case OPTION_LOGICAL_ARRAY: 5021ae3d29cSBarry Smith sprintf(value,"%d",(int)((PetscTruth*)PetscOptionsObject.next->data)[0]); 5031ae3d29cSBarry Smith for (j=1; j<PetscOptionsObject.next->arraylength; j++) { 5041ae3d29cSBarry Smith sprintf(tmp,"%d",(int)((PetscTruth*)PetscOptionsObject.next->data)[j]); 5051ae3d29cSBarry Smith ierr = PetscStrcat(value,",");CHKERRQ(ierr); 5061ae3d29cSBarry Smith ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 5071ae3d29cSBarry Smith } 5081ae3d29cSBarry Smith break; 5096356e834SBarry Smith case OPTION_LIST: 5101ae3d29cSBarry Smith case OPTION_ELIST: 51171f08665SBarry Smith ierr = PetscStrcpy(value,*(char**)PetscOptionsObject.next->data);CHKERRQ(ierr); 5126356e834SBarry Smith break; 5131ae3d29cSBarry Smith case OPTION_STRING: 51471f08665SBarry Smith ierr = PetscStrcpy(value,*(char**)PetscOptionsObject.next->data);CHKERRQ(ierr); 5151ae3d29cSBarry Smith case OPTION_STRING_ARRAY: 5161ae3d29cSBarry Smith sprintf(value,"%s",((char**)PetscOptionsObject.next->data)[0]); 5171ae3d29cSBarry Smith for (j=1; j<PetscOptionsObject.next->arraylength; j++) { 5181ae3d29cSBarry Smith sprintf(tmp,"%s",((char**)PetscOptionsObject.next->data)[j]); 5191ae3d29cSBarry Smith ierr = PetscStrcat(value,",");CHKERRQ(ierr); 5201ae3d29cSBarry Smith ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 5211ae3d29cSBarry Smith } 5226356e834SBarry Smith break; 5236356e834SBarry Smith } 5246356e834SBarry Smith ierr = PetscOptionsSetValue(option,value);CHKERRQ(ierr); 5256356e834SBarry Smith } 526503cfb0cSBarry Smith ierr = PetscFree(PetscOptionsObject.next->text);CHKERRQ(ierr); 527503cfb0cSBarry Smith ierr = PetscFree(PetscOptionsObject.next->option);CHKERRQ(ierr); 5286356e834SBarry Smith ierr = PetscFree(PetscOptionsObject.next->man);CHKERRQ(ierr); 52905b42c5fSBarry Smith ierr = PetscFree(PetscOptionsObject.next->data);CHKERRQ(ierr); 53071f08665SBarry Smith ierr = PetscFree(PetscOptionsObject.next->edata);CHKERRQ(ierr); 5316356e834SBarry Smith last = PetscOptionsObject.next; 5326356e834SBarry Smith PetscOptionsObject.next = PetscOptionsObject.next->next; 5336356e834SBarry Smith ierr = PetscFree(last);CHKERRQ(ierr); 5341bc75a8dSBarry Smith CHKMEMQ; 5356356e834SBarry Smith } 5361bc75a8dSBarry Smith CHKMEMQ; 5376356e834SBarry Smith PetscOptionsObject.next = 0; 53853acd3b1SBarry Smith PetscFunctionReturn(0); 53953acd3b1SBarry Smith } 54053acd3b1SBarry Smith 54153acd3b1SBarry Smith #undef __FUNCT__ 54253acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsEnum" 54353acd3b1SBarry Smith /*@C 54453acd3b1SBarry Smith PetscOptionsEnum - Gets the enum value for a particular option in the database. 54553acd3b1SBarry Smith 54653acd3b1SBarry Smith Collective on the communicator passed in PetscOptionsBegin() 54753acd3b1SBarry Smith 54853acd3b1SBarry Smith Input Parameters: 54953acd3b1SBarry Smith + opt - option name 55053acd3b1SBarry Smith . text - short string that describes the option 55153acd3b1SBarry Smith . man - manual page with additional information on option 55253acd3b1SBarry Smith . list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null 55353acd3b1SBarry Smith - defaultv - the default (current) value 55453acd3b1SBarry Smith 55553acd3b1SBarry Smith Output Parameter: 55653acd3b1SBarry Smith + value - the value to return 55753acd3b1SBarry Smith - flg - PETSC_TRUE if found, else PETSC_FALSE 55853acd3b1SBarry Smith 55953acd3b1SBarry Smith Level: beginner 56053acd3b1SBarry Smith 56153acd3b1SBarry Smith Concepts: options database 56253acd3b1SBarry Smith 56353acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 56453acd3b1SBarry Smith 56553acd3b1SBarry Smith list is usually something like PCASMTypes or some other predefined list of enum names 56653acd3b1SBarry Smith 56753acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 56853acd3b1SBarry Smith PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 56953acd3b1SBarry Smith PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 57053acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 57153acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 57253acd3b1SBarry Smith PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 57353acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 57453acd3b1SBarry Smith @*/ 5752ae9f97cSJed Brown PetscErrorCode PETSC_DLLEXPORT PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const*list,PetscEnum defaultv,PetscEnum *value,PetscTruth *set) 57653acd3b1SBarry Smith { 57753acd3b1SBarry Smith PetscErrorCode ierr; 57853acd3b1SBarry Smith PetscInt ntext = 0; 579aa5bb8c0SSatish Balay PetscInt tval; 580aa5bb8c0SSatish Balay PetscTruth tflg; 58153acd3b1SBarry Smith 58253acd3b1SBarry Smith PetscFunctionBegin; 58353acd3b1SBarry Smith while (list[ntext++]) { 584e32f2f54SBarry Smith if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries"); 58553acd3b1SBarry Smith } 586e32f2f54SBarry Smith if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix"); 58753acd3b1SBarry Smith ntext -= 3; 588aa5bb8c0SSatish Balay ierr = PetscOptionsEList(opt,text,man,list,ntext,list[defaultv],&tval,&tflg);CHKERRQ(ierr); 589aa5bb8c0SSatish Balay /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */ 590aa5bb8c0SSatish Balay if (tflg) *value = (PetscEnum)tval; 591aa5bb8c0SSatish Balay if (set) *set = tflg; 59253acd3b1SBarry Smith PetscFunctionReturn(0); 59353acd3b1SBarry Smith } 59453acd3b1SBarry Smith 59553acd3b1SBarry Smith /* -------------------------------------------------------------------------------------------------------------*/ 59653acd3b1SBarry Smith #undef __FUNCT__ 59753acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsInt" 59853acd3b1SBarry Smith /*@C 59953acd3b1SBarry Smith PetscOptionsInt - Gets the integer value for a particular option in the database. 60053acd3b1SBarry Smith 60153acd3b1SBarry Smith Collective on the communicator passed in PetscOptionsBegin() 60253acd3b1SBarry Smith 60353acd3b1SBarry Smith Input Parameters: 60453acd3b1SBarry Smith + opt - option name 60553acd3b1SBarry Smith . text - short string that describes the option 60653acd3b1SBarry Smith . man - manual page with additional information on option 60753acd3b1SBarry Smith - defaultv - the default (current) value 60853acd3b1SBarry Smith 60953acd3b1SBarry Smith Output Parameter: 61053acd3b1SBarry Smith + value - the integer value to return 61153acd3b1SBarry Smith - flg - PETSC_TRUE if found, else PETSC_FALSE 61253acd3b1SBarry Smith 61353acd3b1SBarry Smith Level: beginner 61453acd3b1SBarry Smith 61553acd3b1SBarry Smith Concepts: options database^has int 61653acd3b1SBarry Smith 61753acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 61853acd3b1SBarry Smith 61953acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 62053acd3b1SBarry Smith PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 62153acd3b1SBarry Smith PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 62253acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 62353acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 62453acd3b1SBarry Smith PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 62553acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 62653acd3b1SBarry Smith @*/ 62753acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt defaultv,PetscInt *value,PetscTruth *set) 62853acd3b1SBarry Smith { 62953acd3b1SBarry Smith PetscErrorCode ierr; 6306356e834SBarry Smith PetscOptions amsopt; 63153acd3b1SBarry Smith 63253acd3b1SBarry Smith PetscFunctionBegin; 633b3506946SBarry Smith if (!PetscOptionsPublishCount) { 6346356e834SBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr); 6356356e834SBarry Smith ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr); 6366356e834SBarry Smith *(PetscInt*)amsopt->data = defaultv; 637af6d86caSBarry Smith } 63853acd3b1SBarry Smith ierr = PetscOptionsGetInt(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 63961b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 64053acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%d>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr); 64153acd3b1SBarry Smith } 64253acd3b1SBarry Smith PetscFunctionReturn(0); 64353acd3b1SBarry Smith } 64453acd3b1SBarry Smith 64553acd3b1SBarry Smith #undef __FUNCT__ 64653acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsString" 64753acd3b1SBarry Smith /*@C 64853acd3b1SBarry Smith PetscOptionsString - Gets the string value for a particular option in the database. 64953acd3b1SBarry Smith 65053acd3b1SBarry Smith Collective on the communicator passed in PetscOptionsBegin() 65153acd3b1SBarry Smith 65253acd3b1SBarry Smith Input Parameters: 65353acd3b1SBarry Smith + opt - option name 65453acd3b1SBarry Smith . text - short string that describes the option 65553acd3b1SBarry Smith . man - manual page with additional information on option 65653acd3b1SBarry Smith - defaultv - the default (current) value 65753acd3b1SBarry Smith 65853acd3b1SBarry Smith Output Parameter: 65953acd3b1SBarry Smith + value - the value to return 66053acd3b1SBarry Smith - flg - PETSC_TRUE if found, else PETSC_FALSE 66153acd3b1SBarry Smith 66253acd3b1SBarry Smith Level: beginner 66353acd3b1SBarry Smith 66453acd3b1SBarry Smith Concepts: options database^has int 66553acd3b1SBarry Smith 66653acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 66753acd3b1SBarry Smith 66853acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 66953acd3b1SBarry Smith PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 67071f08665SBarry Smith PetscOptionsInt(), PetscOptionsReal(), PetscOptionsTruth(), 67153acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 67253acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 67353acd3b1SBarry Smith PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 67453acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 67553acd3b1SBarry Smith @*/ 67653acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsString(const char opt[],const char text[],const char man[],const char defaultv[],char value[],size_t len,PetscTruth *set) 67753acd3b1SBarry Smith { 67853acd3b1SBarry Smith PetscErrorCode ierr; 679aee2cecaSBarry Smith PetscOptions amsopt; 68053acd3b1SBarry Smith 68153acd3b1SBarry Smith PetscFunctionBegin; 682b3506946SBarry Smith if (!PetscOptionsPublishCount) { 683aee2cecaSBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr); 68471f08665SBarry Smith ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr); 68571f08665SBarry Smith *(const char**)amsopt->data = defaultv; 686af6d86caSBarry Smith } 68753acd3b1SBarry Smith ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr); 68861b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 68953acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr); 69053acd3b1SBarry Smith } 69153acd3b1SBarry Smith PetscFunctionReturn(0); 69253acd3b1SBarry Smith } 69353acd3b1SBarry Smith 69453acd3b1SBarry Smith #undef __FUNCT__ 69553acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsReal" 69653acd3b1SBarry Smith /*@C 69753acd3b1SBarry Smith PetscOptionsReal - Gets the PetscReal value for a particular option in the database. 69853acd3b1SBarry Smith 69953acd3b1SBarry Smith Collective on the communicator passed in PetscOptionsBegin() 70053acd3b1SBarry Smith 70153acd3b1SBarry Smith Input Parameters: 70253acd3b1SBarry Smith + opt - option name 70353acd3b1SBarry Smith . text - short string that describes the option 70453acd3b1SBarry Smith . man - manual page with additional information on option 70553acd3b1SBarry Smith - defaultv - the default (current) value 70653acd3b1SBarry Smith 70753acd3b1SBarry Smith Output Parameter: 70853acd3b1SBarry Smith + value - the value to return 70953acd3b1SBarry Smith - flg - PETSC_TRUE if found, else PETSC_FALSE 71053acd3b1SBarry Smith 71153acd3b1SBarry Smith Level: beginner 71253acd3b1SBarry Smith 71353acd3b1SBarry Smith Concepts: options database^has int 71453acd3b1SBarry Smith 71553acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 71653acd3b1SBarry Smith 71753acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 71853acd3b1SBarry Smith PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 71953acd3b1SBarry Smith PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 72053acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 72153acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 72253acd3b1SBarry Smith PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 72353acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 72453acd3b1SBarry Smith @*/ 72553acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal defaultv,PetscReal *value,PetscTruth *set) 72653acd3b1SBarry Smith { 72753acd3b1SBarry Smith PetscErrorCode ierr; 728538aa990SBarry Smith PetscOptions amsopt; 72953acd3b1SBarry Smith 73053acd3b1SBarry Smith PetscFunctionBegin; 731b3506946SBarry Smith if (!PetscOptionsPublishCount) { 732538aa990SBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr); 733538aa990SBarry Smith ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr); 734538aa990SBarry Smith *(PetscReal*)amsopt->data = defaultv; 735538aa990SBarry Smith } 73653acd3b1SBarry Smith ierr = PetscOptionsGetReal(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 73761b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 738a83599f4SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%G>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr); 73953acd3b1SBarry Smith } 74053acd3b1SBarry Smith PetscFunctionReturn(0); 74153acd3b1SBarry Smith } 74253acd3b1SBarry Smith 74353acd3b1SBarry Smith #undef __FUNCT__ 74453acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsScalar" 74553acd3b1SBarry Smith /*@C 74653acd3b1SBarry Smith PetscOptionsScalar - Gets the scalar value for a particular option in the database. 74753acd3b1SBarry Smith 74853acd3b1SBarry Smith Collective on the communicator passed in PetscOptionsBegin() 74953acd3b1SBarry Smith 75053acd3b1SBarry Smith Input Parameters: 75153acd3b1SBarry Smith + opt - option name 75253acd3b1SBarry Smith . text - short string that describes the option 75353acd3b1SBarry Smith . man - manual page with additional information on option 75453acd3b1SBarry Smith - defaultv - the default (current) value 75553acd3b1SBarry Smith 75653acd3b1SBarry Smith Output Parameter: 75753acd3b1SBarry Smith + value - the value to return 75853acd3b1SBarry Smith - flg - PETSC_TRUE if found, else PETSC_FALSE 75953acd3b1SBarry Smith 76053acd3b1SBarry Smith Level: beginner 76153acd3b1SBarry Smith 76253acd3b1SBarry Smith Concepts: options database^has int 76353acd3b1SBarry Smith 76453acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 76553acd3b1SBarry Smith 76653acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 76753acd3b1SBarry Smith PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 76853acd3b1SBarry Smith PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 76953acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 77053acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 77153acd3b1SBarry Smith PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 77253acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 77353acd3b1SBarry Smith @*/ 77453acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar defaultv,PetscScalar *value,PetscTruth *set) 77553acd3b1SBarry Smith { 77653acd3b1SBarry Smith PetscErrorCode ierr; 77753acd3b1SBarry Smith 77853acd3b1SBarry Smith PetscFunctionBegin; 77953acd3b1SBarry Smith #if !defined(PETSC_USE_COMPLEX) 78053acd3b1SBarry Smith ierr = PetscOptionsReal(opt,text,man,defaultv,value,set);CHKERRQ(ierr); 78153acd3b1SBarry Smith #else 78253acd3b1SBarry Smith ierr = PetscOptionsGetScalar(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 78353acd3b1SBarry Smith #endif 78453acd3b1SBarry Smith PetscFunctionReturn(0); 78553acd3b1SBarry Smith } 78653acd3b1SBarry Smith 78753acd3b1SBarry Smith #undef __FUNCT__ 78853acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsName" 78953acd3b1SBarry Smith /*@C 79090d69ab7SBarry Smith 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 79190d69ab7SBarry Smith its value is set to false. 79253acd3b1SBarry Smith 79353acd3b1SBarry Smith Collective on the communicator passed in PetscOptionsBegin() 79453acd3b1SBarry Smith 79553acd3b1SBarry Smith Input Parameters: 79653acd3b1SBarry Smith + opt - option name 79753acd3b1SBarry Smith . text - short string that describes the option 79853acd3b1SBarry Smith - man - manual page with additional information on option 79953acd3b1SBarry Smith 80053acd3b1SBarry Smith Output Parameter: 80153acd3b1SBarry Smith . flg - PETSC_TRUE if found, else PETSC_FALSE 80253acd3b1SBarry Smith 80353acd3b1SBarry Smith Level: beginner 80453acd3b1SBarry Smith 80553acd3b1SBarry Smith Concepts: options database^has int 80653acd3b1SBarry Smith 80753acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 80853acd3b1SBarry Smith 80953acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 81053acd3b1SBarry Smith PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 81153acd3b1SBarry Smith PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 81253acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 81353acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 81453acd3b1SBarry Smith PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 81553acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 81653acd3b1SBarry Smith @*/ 81753acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsName(const char opt[],const char text[],const char man[],PetscTruth *flg) 81853acd3b1SBarry Smith { 81953acd3b1SBarry Smith PetscErrorCode ierr; 8201ae3d29cSBarry Smith PetscOptions amsopt; 82153acd3b1SBarry Smith 82253acd3b1SBarry Smith PetscFunctionBegin; 8231ae3d29cSBarry Smith if (!PetscOptionsPublishCount) { 8241ae3d29cSBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr); 8251ae3d29cSBarry Smith ierr = PetscMalloc(sizeof(PetscTruth),&amsopt->data);CHKERRQ(ierr); 8261ae3d29cSBarry Smith *(PetscTruth*)amsopt->data = PETSC_FALSE; 8271ae3d29cSBarry Smith } 82853acd3b1SBarry Smith ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr); 82961b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 83053acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr); 83153acd3b1SBarry Smith } 83253acd3b1SBarry Smith PetscFunctionReturn(0); 83353acd3b1SBarry Smith } 83453acd3b1SBarry Smith 83553acd3b1SBarry Smith #undef __FUNCT__ 83653acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsList" 83753acd3b1SBarry Smith /*@C 83853acd3b1SBarry Smith PetscOptionsList - Puts a list of option values that a single one may be selected from 83953acd3b1SBarry Smith 84053acd3b1SBarry Smith Collective on the communicator passed in PetscOptionsBegin() 84153acd3b1SBarry Smith 84253acd3b1SBarry Smith Input Parameters: 84353acd3b1SBarry Smith + opt - option name 84453acd3b1SBarry Smith . text - short string that describes the option 84553acd3b1SBarry Smith . man - manual page with additional information on option 84653acd3b1SBarry Smith . list - the possible choices 8473cc1e11dSBarry Smith . defaultv - the default (current) value 8483cc1e11dSBarry Smith - len - the length of the character array value 84953acd3b1SBarry Smith 85053acd3b1SBarry Smith Output Parameter: 85153acd3b1SBarry Smith + value - the value to return 85253acd3b1SBarry Smith - set - PETSC_TRUE if found, else PETSC_FALSE 85353acd3b1SBarry Smith 85453acd3b1SBarry Smith Level: intermediate 85553acd3b1SBarry Smith 85653acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 85753acd3b1SBarry Smith 85853acd3b1SBarry Smith See PetscOptionsEList() for when the choices are given in a string array 85953acd3b1SBarry Smith 86053acd3b1SBarry Smith To get a listing of all currently specified options, 86153acd3b1SBarry Smith see PetscOptionsPrint() or PetscOptionsGetAll() 86253acd3b1SBarry Smith 86353acd3b1SBarry Smith Concepts: options database^list 86453acd3b1SBarry Smith 86553acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 86653acd3b1SBarry Smith PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 86753acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 86853acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 86953acd3b1SBarry Smith PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 87053acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 87153acd3b1SBarry Smith @*/ 8723cc1e11dSBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsList(const char opt[],const char ltext[],const char man[],PetscFList list,const char defaultv[],char value[],size_t len,PetscTruth *set) 87353acd3b1SBarry Smith { 87453acd3b1SBarry Smith PetscErrorCode ierr; 8753cc1e11dSBarry Smith PetscOptions amsopt; 87653acd3b1SBarry Smith 87753acd3b1SBarry Smith PetscFunctionBegin; 878b3506946SBarry Smith if (!PetscOptionsPublishCount) { 8793cc1e11dSBarry Smith ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_LIST,&amsopt);CHKERRQ(ierr); 88071f08665SBarry Smith ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr); 88171f08665SBarry Smith *(const char**)amsopt->data = defaultv; 8823cc1e11dSBarry Smith amsopt->flist = list; 8833cc1e11dSBarry Smith } 88453acd3b1SBarry Smith ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr); 88561b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 8863cc1e11dSBarry Smith ierr = PetscFListPrintTypes(PetscOptionsObject.comm,stdout,PetscOptionsObject.prefix,opt,ltext,man,list,defaultv);CHKERRQ(ierr);CHKERRQ(ierr); 88753acd3b1SBarry Smith } 88853acd3b1SBarry Smith PetscFunctionReturn(0); 88953acd3b1SBarry Smith } 89053acd3b1SBarry Smith 89153acd3b1SBarry Smith #undef __FUNCT__ 89253acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsEList" 89353acd3b1SBarry Smith /*@C 89453acd3b1SBarry Smith PetscOptionsEList - Puts a list of option values that a single one may be selected from 89553acd3b1SBarry Smith 89653acd3b1SBarry Smith Collective on the communicator passed in PetscOptionsBegin() 89753acd3b1SBarry Smith 89853acd3b1SBarry Smith Input Parameters: 89953acd3b1SBarry Smith + opt - option name 90053acd3b1SBarry Smith . ltext - short string that describes the option 90153acd3b1SBarry Smith . man - manual page with additional information on option 90253acd3b1SBarry Smith . list - the possible choices 90353acd3b1SBarry Smith . ntext - number of choices 90453acd3b1SBarry Smith - defaultv - the default (current) value 90553acd3b1SBarry Smith 90653acd3b1SBarry Smith Output Parameter: 90753acd3b1SBarry Smith + value - the index of the value to return 90853acd3b1SBarry Smith - set - PETSC_TRUE if found, else PETSC_FALSE 90953acd3b1SBarry Smith 91053acd3b1SBarry Smith Level: intermediate 91153acd3b1SBarry Smith 91253acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 91353acd3b1SBarry Smith 91453acd3b1SBarry Smith See PetscOptionsList() for when the choices are given in a PetscFList() 91553acd3b1SBarry Smith 91653acd3b1SBarry Smith Concepts: options database^list 91753acd3b1SBarry Smith 91853acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 91953acd3b1SBarry Smith PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 92053acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 92153acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 92253acd3b1SBarry Smith PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 92353acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 92453acd3b1SBarry Smith @*/ 9252ae9f97cSJed Brown PetscErrorCode PETSC_DLLEXPORT PetscOptionsEList(const char opt[],const char ltext[],const char man[],const char *const*list,PetscInt ntext,const char defaultv[],PetscInt *value,PetscTruth *set) 92653acd3b1SBarry Smith { 92753acd3b1SBarry Smith PetscErrorCode ierr; 92853acd3b1SBarry Smith PetscInt i; 9291ae3d29cSBarry Smith PetscOptions amsopt; 93053acd3b1SBarry Smith 93153acd3b1SBarry Smith PetscFunctionBegin; 9321ae3d29cSBarry Smith if (!PetscOptionsPublishCount) { 933d5649816SBarry Smith ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_ELIST,&amsopt);CHKERRQ(ierr); 9341ae3d29cSBarry Smith ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr); 9351ae3d29cSBarry Smith *(const char**)amsopt->data = defaultv; 9361ae3d29cSBarry Smith amsopt->list = list; 9371ae3d29cSBarry Smith amsopt->nlist = ntext; 9381ae3d29cSBarry Smith } 93953acd3b1SBarry Smith ierr = PetscOptionsGetEList(PetscOptionsObject.prefix,opt,list,ntext,value,set);CHKERRQ(ierr); 94061b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 94153acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%s> (choose one of)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv);CHKERRQ(ierr); 94253acd3b1SBarry Smith for (i=0; i<ntext; i++){ 94353acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s",list[i]);CHKERRQ(ierr); 94453acd3b1SBarry Smith } 94553acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"\n");CHKERRQ(ierr); 94653acd3b1SBarry Smith } 94753acd3b1SBarry Smith PetscFunctionReturn(0); 94853acd3b1SBarry Smith } 94953acd3b1SBarry Smith 95053acd3b1SBarry Smith #undef __FUNCT__ 95153acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsTruthGroupBegin" 95253acd3b1SBarry Smith /*@C 95353acd3b1SBarry Smith PetscOptionsTruthGroupBegin - First in a series of logical queries on the options database for 954d5649816SBarry Smith which at most a single value can be true. 95553acd3b1SBarry Smith 95653acd3b1SBarry Smith Collective on the communicator passed in PetscOptionsBegin() 95753acd3b1SBarry Smith 95853acd3b1SBarry Smith Input Parameters: 95953acd3b1SBarry Smith + opt - option name 96053acd3b1SBarry Smith . text - short string that describes the option 96153acd3b1SBarry Smith - man - manual page with additional information on option 96253acd3b1SBarry Smith 96353acd3b1SBarry Smith Output Parameter: 96453acd3b1SBarry Smith . flg - whether that option was set or not 96553acd3b1SBarry Smith 96653acd3b1SBarry Smith Level: intermediate 96753acd3b1SBarry Smith 96853acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 96953acd3b1SBarry Smith 97053acd3b1SBarry Smith Must be followed by 0 or more PetscOptionsTruthGroup()s and PetscOptionsTruthGroupEnd() 97153acd3b1SBarry Smith 97253acd3b1SBarry Smith Concepts: options database^logical group 97353acd3b1SBarry Smith 97453acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 97553acd3b1SBarry Smith PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 97653acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 97753acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 97853acd3b1SBarry Smith PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 97953acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 98053acd3b1SBarry Smith @*/ 98153acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroupBegin(const char opt[],const char text[],const char man[],PetscTruth *flg) 98253acd3b1SBarry Smith { 98353acd3b1SBarry Smith PetscErrorCode ierr; 9841ae3d29cSBarry Smith PetscOptions amsopt; 98553acd3b1SBarry Smith 98653acd3b1SBarry Smith PetscFunctionBegin; 9871ae3d29cSBarry Smith if (!PetscOptionsPublishCount) { 9881ae3d29cSBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr); 9891ae3d29cSBarry Smith ierr = PetscMalloc(sizeof(PetscTruth),&amsopt->data);CHKERRQ(ierr); 990d5649816SBarry Smith *(PetscTruth*)amsopt->data = PETSC_FALSE; 9911ae3d29cSBarry Smith } 992*68b16fdaSBarry Smith *flg = PETSC_FALSE; 99317326d04SJed Brown ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr); 99461b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 99553acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," Pick at most one of -------------\n");CHKERRQ(ierr); 99653acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr); 99753acd3b1SBarry Smith } 99853acd3b1SBarry Smith PetscFunctionReturn(0); 99953acd3b1SBarry Smith } 100053acd3b1SBarry Smith 100153acd3b1SBarry Smith #undef __FUNCT__ 100253acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsTruthGroup" 100353acd3b1SBarry Smith /*@C 100453acd3b1SBarry Smith PetscOptionsTruthGroup - One in a series of logical queries on the options database for 1005d5649816SBarry Smith which at most a single value can be true. 100653acd3b1SBarry Smith 100753acd3b1SBarry Smith Collective on the communicator passed in PetscOptionsBegin() 100853acd3b1SBarry Smith 100953acd3b1SBarry Smith Input Parameters: 101053acd3b1SBarry Smith + opt - option name 101153acd3b1SBarry Smith . text - short string that describes the option 101253acd3b1SBarry Smith - man - manual page with additional information on option 101353acd3b1SBarry Smith 101453acd3b1SBarry Smith Output Parameter: 101553acd3b1SBarry Smith . flg - PETSC_TRUE if found, else PETSC_FALSE 101653acd3b1SBarry Smith 101753acd3b1SBarry Smith Level: intermediate 101853acd3b1SBarry Smith 101953acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 102053acd3b1SBarry Smith 102153acd3b1SBarry Smith Must follow a PetscOptionsTruthGroupBegin() and preceded a PetscOptionsTruthGroupEnd() 102253acd3b1SBarry Smith 102353acd3b1SBarry Smith Concepts: options database^logical group 102453acd3b1SBarry Smith 102553acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 102653acd3b1SBarry Smith PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 102753acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 102853acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 102953acd3b1SBarry Smith PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 103053acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 103153acd3b1SBarry Smith @*/ 103253acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroup(const char opt[],const char text[],const char man[],PetscTruth *flg) 103353acd3b1SBarry Smith { 103453acd3b1SBarry Smith PetscErrorCode ierr; 10351ae3d29cSBarry Smith PetscOptions amsopt; 103653acd3b1SBarry Smith 103753acd3b1SBarry Smith PetscFunctionBegin; 10381ae3d29cSBarry Smith if (!PetscOptionsPublishCount) { 10391ae3d29cSBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr); 10401ae3d29cSBarry Smith ierr = PetscMalloc(sizeof(PetscTruth),&amsopt->data);CHKERRQ(ierr); 10411ae3d29cSBarry Smith *(PetscTruth*)amsopt->data = PETSC_FALSE; 10421ae3d29cSBarry Smith } 104317326d04SJed Brown *flg = PETSC_FALSE; 104417326d04SJed Brown ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr); 104561b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 104653acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr); 104753acd3b1SBarry Smith } 104853acd3b1SBarry Smith PetscFunctionReturn(0); 104953acd3b1SBarry Smith } 105053acd3b1SBarry Smith 105153acd3b1SBarry Smith #undef __FUNCT__ 105253acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsTruthGroupEnd" 105353acd3b1SBarry Smith /*@C 105453acd3b1SBarry Smith PetscOptionsTruthGroupEnd - Last in a series of logical queries on the options database for 1055d5649816SBarry Smith which at most a single value can be true. 105653acd3b1SBarry Smith 105753acd3b1SBarry Smith Collective on the communicator passed in PetscOptionsBegin() 105853acd3b1SBarry Smith 105953acd3b1SBarry Smith Input Parameters: 106053acd3b1SBarry Smith + opt - option name 106153acd3b1SBarry Smith . text - short string that describes the option 106253acd3b1SBarry Smith - man - manual page with additional information on option 106353acd3b1SBarry Smith 106453acd3b1SBarry Smith Output Parameter: 106553acd3b1SBarry Smith . flg - PETSC_TRUE if found, else PETSC_FALSE 106653acd3b1SBarry Smith 106753acd3b1SBarry Smith Level: intermediate 106853acd3b1SBarry Smith 106953acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 107053acd3b1SBarry Smith 107153acd3b1SBarry Smith Must follow a PetscOptionsTruthGroupBegin() 107253acd3b1SBarry Smith 107353acd3b1SBarry Smith Concepts: options database^logical group 107453acd3b1SBarry Smith 107553acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 107653acd3b1SBarry Smith PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 107753acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 107853acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 107953acd3b1SBarry Smith PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 108053acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 108153acd3b1SBarry Smith @*/ 108253acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroupEnd(const char opt[],const char text[],const char man[],PetscTruth *flg) 108353acd3b1SBarry Smith { 108453acd3b1SBarry Smith PetscErrorCode ierr; 10851ae3d29cSBarry Smith PetscOptions amsopt; 108653acd3b1SBarry Smith 108753acd3b1SBarry Smith PetscFunctionBegin; 10881ae3d29cSBarry Smith if (!PetscOptionsPublishCount) { 10891ae3d29cSBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr); 10901ae3d29cSBarry Smith ierr = PetscMalloc(sizeof(PetscTruth),&amsopt->data);CHKERRQ(ierr); 10911ae3d29cSBarry Smith *(PetscTruth*)amsopt->data = PETSC_FALSE; 10921ae3d29cSBarry Smith } 109317326d04SJed Brown *flg = PETSC_FALSE; 109417326d04SJed Brown ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr); 109561b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 109653acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr); 109753acd3b1SBarry Smith } 109853acd3b1SBarry Smith PetscFunctionReturn(0); 109953acd3b1SBarry Smith } 110053acd3b1SBarry Smith 110153acd3b1SBarry Smith #undef __FUNCT__ 110253acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsTruth" 110353acd3b1SBarry Smith /*@C 110453acd3b1SBarry Smith PetscOptionsTruth - Determines if a particular option is in the database with a true or false 110553acd3b1SBarry Smith 110653acd3b1SBarry Smith Collective on the communicator passed in PetscOptionsBegin() 110753acd3b1SBarry Smith 110853acd3b1SBarry Smith Input Parameters: 110953acd3b1SBarry Smith + opt - option name 111053acd3b1SBarry Smith . text - short string that describes the option 111153acd3b1SBarry Smith - man - manual page with additional information on option 111253acd3b1SBarry Smith 111353acd3b1SBarry Smith Output Parameter: 111453acd3b1SBarry Smith . flg - PETSC_TRUE or PETSC_FALSE 111553acd3b1SBarry Smith . set - PETSC_TRUE if found, else PETSC_FALSE 111653acd3b1SBarry Smith 111753acd3b1SBarry Smith Level: beginner 111853acd3b1SBarry Smith 111953acd3b1SBarry Smith Concepts: options database^logical 112053acd3b1SBarry Smith 112153acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 112253acd3b1SBarry Smith 112353acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 112453acd3b1SBarry Smith PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 112553acd3b1SBarry Smith PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 112653acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 112753acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 112853acd3b1SBarry Smith PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 112953acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 113053acd3b1SBarry Smith @*/ 113153acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruth(const char opt[],const char text[],const char man[],PetscTruth deflt,PetscTruth *flg,PetscTruth *set) 113253acd3b1SBarry Smith { 113353acd3b1SBarry Smith PetscErrorCode ierr; 113453acd3b1SBarry Smith PetscTruth iset; 1135aee2cecaSBarry Smith PetscOptions amsopt; 113653acd3b1SBarry Smith 113753acd3b1SBarry Smith PetscFunctionBegin; 1138b3506946SBarry Smith if (!PetscOptionsPublishCount) { 1139aee2cecaSBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr); 114071f08665SBarry Smith ierr = PetscMalloc(sizeof(PetscTruth),&amsopt->data);CHKERRQ(ierr); 114171f08665SBarry Smith *(PetscTruth*)amsopt->data = deflt; 1142af6d86caSBarry Smith } 114353acd3b1SBarry Smith ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,&iset);CHKERRQ(ierr); 114453acd3b1SBarry Smith if (!iset) { 114553acd3b1SBarry Smith if (flg) *flg = deflt; 114653acd3b1SBarry Smith } 114753acd3b1SBarry Smith if (set) *set = iset; 114861b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 114953acd3b1SBarry Smith const char *v = PetscTruths[deflt]; 115053acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: <%s> %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,v,text,man);CHKERRQ(ierr); 115153acd3b1SBarry Smith } 115253acd3b1SBarry Smith PetscFunctionReturn(0); 115353acd3b1SBarry Smith } 115453acd3b1SBarry Smith 115553acd3b1SBarry Smith #undef __FUNCT__ 115653acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsRealArray" 115753acd3b1SBarry Smith /*@C 115853acd3b1SBarry Smith PetscOptionsRealArray - Gets an array of double values for a particular 115953acd3b1SBarry Smith option in the database. The values must be separated with commas with 116053acd3b1SBarry Smith no intervening spaces. 116153acd3b1SBarry Smith 116253acd3b1SBarry Smith Collective on the communicator passed in PetscOptionsBegin() 116353acd3b1SBarry Smith 116453acd3b1SBarry Smith Input Parameters: 116553acd3b1SBarry Smith + opt - the option one is seeking 116653acd3b1SBarry Smith . text - short string describing option 116753acd3b1SBarry Smith . man - manual page for option 116853acd3b1SBarry Smith - nmax - maximum number of values 116953acd3b1SBarry Smith 117053acd3b1SBarry Smith Output Parameter: 117153acd3b1SBarry Smith + value - location to copy values 117253acd3b1SBarry Smith . nmax - actual number of values found 117353acd3b1SBarry Smith - set - PETSC_TRUE if found, else PETSC_FALSE 117453acd3b1SBarry Smith 117553acd3b1SBarry Smith Level: beginner 117653acd3b1SBarry Smith 117753acd3b1SBarry Smith Notes: 117853acd3b1SBarry Smith The user should pass in an array of doubles 117953acd3b1SBarry Smith 118053acd3b1SBarry Smith Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 118153acd3b1SBarry Smith 118253acd3b1SBarry Smith Concepts: options database^array of strings 118353acd3b1SBarry Smith 118453acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 118553acd3b1SBarry Smith PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 118653acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 118753acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 118853acd3b1SBarry Smith PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 118953acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 119053acd3b1SBarry Smith @*/ 119153acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscTruth *set) 119253acd3b1SBarry Smith { 119353acd3b1SBarry Smith PetscErrorCode ierr; 119453acd3b1SBarry Smith PetscInt i; 1195e26ddf31SBarry Smith PetscOptions amsopt; 119653acd3b1SBarry Smith 119753acd3b1SBarry Smith PetscFunctionBegin; 1198b3506946SBarry Smith if (!PetscOptionsPublishCount) { 1199e26ddf31SBarry Smith PetscReal *vals; 1200e26ddf31SBarry Smith 1201e26ddf31SBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr); 1202e26ddf31SBarry Smith ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr); 1203e26ddf31SBarry Smith vals = (PetscReal*)amsopt->data; 1204e26ddf31SBarry Smith for (i=0; i<*n; i++) vals[i] = value[i]; 1205e26ddf31SBarry Smith amsopt->arraylength = *n; 1206e26ddf31SBarry Smith } 120753acd3b1SBarry Smith ierr = PetscOptionsGetRealArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr); 120861b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1209a83599f4SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%G",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr); 121053acd3b1SBarry Smith for (i=1; i<*n; i++) { 1211a83599f4SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%G",value[i]);CHKERRQ(ierr); 121253acd3b1SBarry Smith } 121353acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr); 121453acd3b1SBarry Smith } 121553acd3b1SBarry Smith PetscFunctionReturn(0); 121653acd3b1SBarry Smith } 121753acd3b1SBarry Smith 121853acd3b1SBarry Smith 121953acd3b1SBarry Smith #undef __FUNCT__ 122053acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsIntArray" 122153acd3b1SBarry Smith /*@C 122253acd3b1SBarry Smith PetscOptionsIntArray - Gets an array of integers for a particular 122353acd3b1SBarry Smith option in the database. The values must be separated with commas with 122453acd3b1SBarry Smith no intervening spaces. 122553acd3b1SBarry Smith 122653acd3b1SBarry Smith Collective on the communicator passed in PetscOptionsBegin() 122753acd3b1SBarry Smith 122853acd3b1SBarry Smith Input Parameters: 122953acd3b1SBarry Smith + opt - the option one is seeking 123053acd3b1SBarry Smith . text - short string describing option 123153acd3b1SBarry Smith . man - manual page for option 1232f8a50e2bSBarry Smith - n - maximum number of values 123353acd3b1SBarry Smith 123453acd3b1SBarry Smith Output Parameter: 123553acd3b1SBarry Smith + value - location to copy values 1236f8a50e2bSBarry Smith . n - actual number of values found 123753acd3b1SBarry Smith - set - PETSC_TRUE if found, else PETSC_FALSE 123853acd3b1SBarry Smith 123953acd3b1SBarry Smith Level: beginner 124053acd3b1SBarry Smith 124153acd3b1SBarry Smith Notes: 124253acd3b1SBarry Smith The user should pass in an array of integers 124353acd3b1SBarry Smith 124453acd3b1SBarry Smith Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 124553acd3b1SBarry Smith 124653acd3b1SBarry Smith Concepts: options database^array of strings 124753acd3b1SBarry Smith 124853acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 124953acd3b1SBarry Smith PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 125053acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 125153acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 125253acd3b1SBarry Smith PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 125353acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList(), PetscOptionsRealArray() 125453acd3b1SBarry Smith @*/ 125553acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscTruth *set) 125653acd3b1SBarry Smith { 125753acd3b1SBarry Smith PetscErrorCode ierr; 125853acd3b1SBarry Smith PetscInt i; 1259e26ddf31SBarry Smith PetscOptions amsopt; 126053acd3b1SBarry Smith 126153acd3b1SBarry Smith PetscFunctionBegin; 1262b3506946SBarry Smith if (!PetscOptionsPublishCount) { 1263e26ddf31SBarry Smith PetscInt *vals; 1264e26ddf31SBarry Smith 1265e26ddf31SBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr); 1266e26ddf31SBarry Smith ierr = PetscMalloc((*n)*sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr); 1267e26ddf31SBarry Smith vals = (PetscInt*)amsopt->data; 1268e26ddf31SBarry Smith for (i=0; i<*n; i++) vals[i] = value[i]; 1269e26ddf31SBarry Smith amsopt->arraylength = *n; 1270e26ddf31SBarry Smith } 127153acd3b1SBarry Smith ierr = PetscOptionsGetIntArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr); 127261b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 127353acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr); 127453acd3b1SBarry Smith for (i=1; i<*n; i++) { 127553acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr); 127653acd3b1SBarry Smith } 127753acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr); 127853acd3b1SBarry Smith } 127953acd3b1SBarry Smith PetscFunctionReturn(0); 128053acd3b1SBarry Smith } 128153acd3b1SBarry Smith 128253acd3b1SBarry Smith #undef __FUNCT__ 128353acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsStringArray" 128453acd3b1SBarry Smith /*@C 128553acd3b1SBarry Smith PetscOptionsStringArray - Gets an array of string values for a particular 128653acd3b1SBarry Smith option in the database. The values must be separated with commas with 128753acd3b1SBarry Smith no intervening spaces. 128853acd3b1SBarry Smith 128953acd3b1SBarry Smith Collective on the communicator passed in PetscOptionsBegin() 129053acd3b1SBarry Smith 129153acd3b1SBarry Smith Input Parameters: 129253acd3b1SBarry Smith + opt - the option one is seeking 129353acd3b1SBarry Smith . text - short string describing option 129453acd3b1SBarry Smith . man - manual page for option 129553acd3b1SBarry Smith - nmax - maximum number of strings 129653acd3b1SBarry Smith 129753acd3b1SBarry Smith Output Parameter: 129853acd3b1SBarry Smith + value - location to copy strings 129953acd3b1SBarry Smith . nmax - actual number of strings found 130053acd3b1SBarry Smith - set - PETSC_TRUE if found, else PETSC_FALSE 130153acd3b1SBarry Smith 130253acd3b1SBarry Smith Level: beginner 130353acd3b1SBarry Smith 130453acd3b1SBarry Smith Notes: 130553acd3b1SBarry Smith The user should pass in an array of pointers to char, to hold all the 130653acd3b1SBarry Smith strings returned by this function. 130753acd3b1SBarry Smith 130853acd3b1SBarry Smith The user is responsible for deallocating the strings that are 130953acd3b1SBarry Smith returned. The Fortran interface for this routine is not supported. 131053acd3b1SBarry Smith 131153acd3b1SBarry Smith Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 131253acd3b1SBarry Smith 131353acd3b1SBarry Smith Concepts: options database^array of strings 131453acd3b1SBarry Smith 131553acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 131653acd3b1SBarry Smith PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 131753acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 131853acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 131953acd3b1SBarry Smith PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 132053acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 132153acd3b1SBarry Smith @*/ 132253acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscTruth *set) 132353acd3b1SBarry Smith { 132453acd3b1SBarry Smith PetscErrorCode ierr; 13251ae3d29cSBarry Smith PetscOptions amsopt; 132653acd3b1SBarry Smith 132753acd3b1SBarry Smith PetscFunctionBegin; 13281ae3d29cSBarry Smith if (!PetscOptionsPublishCount) { 13291ae3d29cSBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING_ARRAY,&amsopt);CHKERRQ(ierr); 13301ae3d29cSBarry Smith ierr = PetscMalloc((*nmax)*sizeof(char*),&amsopt->data);CHKERRQ(ierr); 13311ae3d29cSBarry Smith amsopt->arraylength = *nmax; 13321ae3d29cSBarry Smith } 133353acd3b1SBarry Smith ierr = PetscOptionsGetStringArray(PetscOptionsObject.prefix,opt,value,nmax,set);CHKERRQ(ierr); 133461b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 133553acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr); 133653acd3b1SBarry Smith } 133753acd3b1SBarry Smith PetscFunctionReturn(0); 133853acd3b1SBarry Smith } 133953acd3b1SBarry Smith 1340e2446a98SMatthew Knepley #undef __FUNCT__ 1341e2446a98SMatthew Knepley #define __FUNCT__ "PetscOptionsTruthArray" 1342e2446a98SMatthew Knepley /*@C 1343e2446a98SMatthew Knepley PetscOptionsTruthArray - Gets an array of logical values (true or false) for a particular 1344e2446a98SMatthew Knepley option in the database. The values must be separated with commas with 1345e2446a98SMatthew Knepley no intervening spaces. 1346e2446a98SMatthew Knepley 1347e2446a98SMatthew Knepley Collective on the communicator passed in PetscOptionsBegin() 1348e2446a98SMatthew Knepley 1349e2446a98SMatthew Knepley Input Parameters: 1350e2446a98SMatthew Knepley + opt - the option one is seeking 1351e2446a98SMatthew Knepley . text - short string describing option 1352e2446a98SMatthew Knepley . man - manual page for option 1353e2446a98SMatthew Knepley - nmax - maximum number of values 1354e2446a98SMatthew Knepley 1355e2446a98SMatthew Knepley Output Parameter: 1356e2446a98SMatthew Knepley + value - location to copy values 1357e2446a98SMatthew Knepley . nmax - actual number of values found 1358e2446a98SMatthew Knepley - set - PETSC_TRUE if found, else PETSC_FALSE 1359e2446a98SMatthew Knepley 1360e2446a98SMatthew Knepley Level: beginner 1361e2446a98SMatthew Knepley 1362e2446a98SMatthew Knepley Notes: 1363e2446a98SMatthew Knepley The user should pass in an array of doubles 1364e2446a98SMatthew Knepley 1365e2446a98SMatthew Knepley Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1366e2446a98SMatthew Knepley 1367e2446a98SMatthew Knepley Concepts: options database^array of strings 1368e2446a98SMatthew Knepley 1369e2446a98SMatthew Knepley .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1370e2446a98SMatthew Knepley PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 1371e2446a98SMatthew Knepley PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1372e2446a98SMatthew Knepley PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1373e2446a98SMatthew Knepley PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 1374e2446a98SMatthew Knepley PetscOptionsList(), PetscOptionsEList() 1375e2446a98SMatthew Knepley @*/ 1376e2446a98SMatthew Knepley PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthArray(const char opt[],const char text[],const char man[],PetscTruth value[],PetscInt *n,PetscTruth *set) 1377e2446a98SMatthew Knepley { 1378e2446a98SMatthew Knepley PetscErrorCode ierr; 1379e2446a98SMatthew Knepley PetscInt i; 13801ae3d29cSBarry Smith PetscOptions amsopt; 1381e2446a98SMatthew Knepley 1382e2446a98SMatthew Knepley PetscFunctionBegin; 13831ae3d29cSBarry Smith if (!PetscOptionsPublishCount) { 13841ae3d29cSBarry Smith PetscTruth *vals; 13851ae3d29cSBarry Smith 13861ae3d29cSBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL_ARRAY,&amsopt);CHKERRQ(ierr); 13871ae3d29cSBarry Smith ierr = PetscMalloc((*n)*sizeof(PetscTruth),&amsopt->data);CHKERRQ(ierr); 13881ae3d29cSBarry Smith vals = (PetscTruth*)amsopt->data; 13891ae3d29cSBarry Smith for (i=0; i<*n; i++) vals[i] = value[i]; 13901ae3d29cSBarry Smith amsopt->arraylength = *n; 13911ae3d29cSBarry Smith } 1392e2446a98SMatthew Knepley ierr = PetscOptionsGetTruthArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr); 1393e2446a98SMatthew Knepley if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1394e2446a98SMatthew Knepley ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr); 1395e2446a98SMatthew Knepley for (i=1; i<*n; i++) { 1396e2446a98SMatthew Knepley ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr); 1397e2446a98SMatthew Knepley } 1398e2446a98SMatthew Knepley ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr); 1399e2446a98SMatthew Knepley } 1400e2446a98SMatthew Knepley PetscFunctionReturn(0); 1401e2446a98SMatthew Knepley } 1402e2446a98SMatthew Knepley 140353acd3b1SBarry Smith 140453acd3b1SBarry Smith #undef __FUNCT__ 140553acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsHead" 140653acd3b1SBarry Smith /*@C 1407b52f573bSBarry Smith PetscOptionsHead - Puts a heading before listing any more published options. Used, for example, 140853acd3b1SBarry Smith in KSPSetFromOptions_GMRES(). 140953acd3b1SBarry Smith 141053acd3b1SBarry Smith Collective on the communicator passed in PetscOptionsBegin() 141153acd3b1SBarry Smith 141253acd3b1SBarry Smith Input Parameter: 141353acd3b1SBarry Smith . head - the heading text 141453acd3b1SBarry Smith 141553acd3b1SBarry Smith 141653acd3b1SBarry Smith Level: intermediate 141753acd3b1SBarry Smith 141853acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 141953acd3b1SBarry Smith 1420b52f573bSBarry Smith Can be followed by a call to PetscOptionsTail() in the same function. 142153acd3b1SBarry Smith 142253acd3b1SBarry Smith Concepts: options database^subheading 142353acd3b1SBarry Smith 142453acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 142553acd3b1SBarry Smith PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 142653acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 142753acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 142853acd3b1SBarry Smith PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 142953acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 143053acd3b1SBarry Smith @*/ 143153acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsHead(const char head[]) 143253acd3b1SBarry Smith { 143353acd3b1SBarry Smith PetscErrorCode ierr; 143453acd3b1SBarry Smith 143553acd3b1SBarry Smith PetscFunctionBegin; 143661b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 143753acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s\n",head);CHKERRQ(ierr); 143853acd3b1SBarry Smith } 143953acd3b1SBarry Smith PetscFunctionReturn(0); 144053acd3b1SBarry Smith } 144153acd3b1SBarry Smith 144253acd3b1SBarry Smith 144353acd3b1SBarry Smith 144453acd3b1SBarry Smith 144553acd3b1SBarry Smith 144653acd3b1SBarry Smith 1447