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 132aa6d131SJed Brown #define ManSection(str) ((str)?(str):"None") 142aa6d131SJed Brown 1553acd3b1SBarry Smith /* 1653acd3b1SBarry Smith Keep a linked list of options that have been posted and we are waiting for 173fc1eb6aSBarry Smith user selection. See the manual page for PetscOptionsBegin() 1853acd3b1SBarry Smith 1953acd3b1SBarry Smith Eventually we'll attach this beast to a MPI_Comm 2053acd3b1SBarry Smith */ 21f8d0b74dSMatthew Knepley PetscOptionsObjectType PetscOptionsObject; 2253acd3b1SBarry Smith PetscInt PetscOptionsPublishCount = 0; 2353acd3b1SBarry Smith 2453acd3b1SBarry Smith #undef __FUNCT__ 2553acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsBegin_Private" 2653acd3b1SBarry Smith /* 2753acd3b1SBarry Smith Handles setting up the data structure in a call to PetscOptionsBegin() 2853acd3b1SBarry Smith */ 2953acd3b1SBarry Smith PetscErrorCode PetscOptionsBegin_Private(MPI_Comm comm,const char prefix[],const char title[],const char mansec[]) 3053acd3b1SBarry Smith { 3153acd3b1SBarry Smith PetscErrorCode ierr; 3253acd3b1SBarry Smith 3353acd3b1SBarry Smith PetscFunctionBegin; 3453acd3b1SBarry Smith PetscOptionsObject.next = 0; 3553acd3b1SBarry Smith PetscOptionsObject.comm = comm; 366356e834SBarry Smith PetscOptionsObject.changedmethod = PETSC_FALSE; 37f8d0b74dSMatthew Knepley if (PetscOptionsObject.prefix) { 38503cfb0cSBarry Smith ierr = PetscFree(PetscOptionsObject.prefix);CHKERRQ(ierr); PetscOptionsObject.prefix = 0; 39f8d0b74dSMatthew Knepley } 4053acd3b1SBarry Smith ierr = PetscStrallocpy(prefix,&PetscOptionsObject.prefix);CHKERRQ(ierr); 41f8d0b74dSMatthew Knepley if (PetscOptionsObject.title) { 42503cfb0cSBarry Smith ierr = PetscFree(PetscOptionsObject.title);CHKERRQ(ierr); PetscOptionsObject.title = 0; 43f8d0b74dSMatthew Knepley } 4453acd3b1SBarry Smith ierr = PetscStrallocpy(title,&PetscOptionsObject.title);CHKERRQ(ierr); 4553acd3b1SBarry Smith 4653acd3b1SBarry Smith ierr = PetscOptionsHasName(PETSC_NULL,"-help",&PetscOptionsObject.printhelp);CHKERRQ(ierr); 4753acd3b1SBarry Smith if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) { 4861b37b28SSatish Balay if (!PetscOptionsObject.alreadyprinted) { 4953acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(comm,"%s -------------------------------------------------\n",title);CHKERRQ(ierr); 5053acd3b1SBarry Smith } 5161b37b28SSatish Balay } 5253acd3b1SBarry Smith PetscFunctionReturn(0); 5353acd3b1SBarry Smith } 5453acd3b1SBarry Smith 5553acd3b1SBarry Smith /* 5653acd3b1SBarry Smith Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd() 5753acd3b1SBarry Smith */ 5853acd3b1SBarry Smith #undef __FUNCT__ 5953acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsCreate_Private" 60e3ed6ec8SBarry Smith static int PetscOptionsCreate_Private(const char opt[],const char text[],const char man[],PetscOptionType t,PetscOptions *amsopt) 6153acd3b1SBarry Smith { 6253acd3b1SBarry Smith int ierr; 6353acd3b1SBarry Smith PetscOptions next; 6453acd3b1SBarry Smith 6553acd3b1SBarry Smith PetscFunctionBegin; 666e655a9bSJed Brown ierr = PetscNew(struct _n_PetscOptions,amsopt);CHKERRQ(ierr); 6753acd3b1SBarry Smith (*amsopt)->next = 0; 6853acd3b1SBarry Smith (*amsopt)->set = PETSC_FALSE; 696356e834SBarry Smith (*amsopt)->type = t; 7053acd3b1SBarry Smith (*amsopt)->data = 0; 7161b37b28SSatish Balay 7253acd3b1SBarry Smith ierr = PetscStrallocpy(text,&(*amsopt)->text);CHKERRQ(ierr); 7353acd3b1SBarry Smith ierr = PetscStrallocpy(opt,&(*amsopt)->option);CHKERRQ(ierr); 746356e834SBarry Smith ierr = PetscStrallocpy(man,&(*amsopt)->man);CHKERRQ(ierr); 7553acd3b1SBarry Smith 7653acd3b1SBarry Smith if (!PetscOptionsObject.next) { 7753acd3b1SBarry Smith PetscOptionsObject.next = *amsopt; 7853acd3b1SBarry Smith } else { 7953acd3b1SBarry Smith next = PetscOptionsObject.next; 8053acd3b1SBarry Smith while (next->next) next = next->next; 8153acd3b1SBarry Smith next->next = *amsopt; 8253acd3b1SBarry Smith } 8353acd3b1SBarry Smith PetscFunctionReturn(0); 8453acd3b1SBarry Smith } 8553acd3b1SBarry Smith 8653acd3b1SBarry Smith #undef __FUNCT__ 87aee2cecaSBarry Smith #define __FUNCT__ "PetscScanString" 88aee2cecaSBarry Smith /* 893fc1eb6aSBarry Smith PetscScanString - Gets user input via stdin from process and broadcasts to all processes 903fc1eb6aSBarry Smith 913fc1eb6aSBarry Smith Collective on MPI_Comm 923fc1eb6aSBarry Smith 933fc1eb6aSBarry Smith Input Parameters: 943fc1eb6aSBarry Smith + commm - communicator for the broadcast, must be PETSC_COMM_WORLD 953fc1eb6aSBarry Smith . n - length of the string, must be the same on all processes 963fc1eb6aSBarry Smith - str - location to store input 97aee2cecaSBarry Smith 98aee2cecaSBarry Smith Bugs: 99aee2cecaSBarry Smith . Assumes process 0 of the given communicator has access to stdin 100aee2cecaSBarry Smith 101aee2cecaSBarry Smith */ 1023fc1eb6aSBarry Smith static PetscErrorCode PetscScanString(MPI_Comm comm,size_t n,char str[]) 103aee2cecaSBarry Smith { 104330cf3c9SBarry Smith size_t i; 105aee2cecaSBarry Smith char c; 1063fc1eb6aSBarry Smith PetscMPIInt rank,nm; 107aee2cecaSBarry Smith PetscErrorCode ierr; 108aee2cecaSBarry Smith 109aee2cecaSBarry Smith PetscFunctionBegin; 110aee2cecaSBarry Smith ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); 111aee2cecaSBarry Smith if (!rank) { 112aee2cecaSBarry Smith c = (char) getchar(); 113aee2cecaSBarry Smith i = 0; 114aee2cecaSBarry Smith while ( c != '\n' && i < n-1) { 115aee2cecaSBarry Smith str[i++] = c; 116aee2cecaSBarry Smith c = (char) getchar(); 117aee2cecaSBarry Smith } 118aee2cecaSBarry Smith str[i] = 0; 119aee2cecaSBarry Smith } 1203fc1eb6aSBarry Smith nm = PetscMPIIntCast(n); 1213fc1eb6aSBarry Smith ierr = MPI_Bcast(str,nm,MPI_CHAR,0,comm);CHKERRQ(ierr); 122aee2cecaSBarry Smith PetscFunctionReturn(0); 123aee2cecaSBarry Smith } 124aee2cecaSBarry Smith 125aee2cecaSBarry Smith #undef __FUNCT__ 126aee2cecaSBarry Smith #define __FUNCT__ "PetscOptionsGetFromTextInput" 127aee2cecaSBarry Smith /* 1283cc1e11dSBarry Smith PetscOptionsGetFromTextInput - Presents all the PETSc Options processed by the program so the user may change them at runtime 129aee2cecaSBarry Smith 130aee2cecaSBarry Smith Notes: this isn't really practical, it is just to demonstrate the principle 131aee2cecaSBarry Smith 132aee2cecaSBarry Smith Bugs: 133aee2cecaSBarry Smith + All processes must traverse through the exact same set of option queries do to the call to PetscScanString() 1343cc1e11dSBarry Smith . Internal strings have arbitrary length and string copies are not checked that they fit into string space 135aee2cecaSBarry Smith - Only works for PetscInt == int, PetscReal == double etc 136aee2cecaSBarry Smith 1373cc1e11dSBarry Smith Developer Notes: Normally the GUI that presents the options the user and retrieves the values would be running in a different 1383cc1e11dSBarry Smith address space and communicating with the PETSc program 1393cc1e11dSBarry Smith 140aee2cecaSBarry Smith */ 141aee2cecaSBarry Smith PetscErrorCode PetscOptionsGetFromTextInput() 1426356e834SBarry Smith { 1436356e834SBarry Smith PetscErrorCode ierr; 1446356e834SBarry Smith PetscOptions next = PetscOptionsObject.next; 1456356e834SBarry Smith char str[512]; 146a4404d99SBarry Smith PetscInt id; 147a4404d99SBarry Smith PetscReal ir,*valr; 148330cf3c9SBarry Smith PetscInt *vald; 149330cf3c9SBarry Smith size_t i; 1506356e834SBarry Smith 151e26ddf31SBarry Smith ierr = (*PetscPrintf)(PETSC_COMM_WORLD,"%s -------------------------------------------------\n",PetscOptionsObject.title);CHKERRQ(ierr); 1526356e834SBarry Smith while (next) { 1536356e834SBarry Smith switch (next->type) { 1546356e834SBarry Smith case OPTION_HEAD: 1556356e834SBarry Smith break; 156e26ddf31SBarry Smith case OPTION_INT_ARRAY: 157e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1);CHKERRQ(ierr); 158e26ddf31SBarry Smith vald = (PetscInt*) next->data; 159e26ddf31SBarry Smith for (i=0; i<next->arraylength; i++) { 160e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,"%d",vald[i]);CHKERRQ(ierr); 161e26ddf31SBarry Smith if (i < next->arraylength-1) { 162e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr); 163e26ddf31SBarry Smith } 164e26ddf31SBarry Smith } 165e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s)",next->text,next->man);CHKERRQ(ierr); 166e26ddf31SBarry Smith ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 167e26ddf31SBarry Smith if (str[0]) { 168e26ddf31SBarry Smith PetscToken token; 169e26ddf31SBarry Smith PetscInt n=0,nmax = next->arraylength,*dvalue = (PetscInt*)next->data,start,end; 170e26ddf31SBarry Smith size_t len; 171e26ddf31SBarry Smith char* value; 172ace3abfcSBarry Smith PetscBool foundrange; 173e26ddf31SBarry Smith 174e26ddf31SBarry Smith next->set = PETSC_TRUE; 175e26ddf31SBarry Smith value = str; 176e26ddf31SBarry Smith ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 177e26ddf31SBarry Smith ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 178e26ddf31SBarry Smith while (n < nmax) { 179e26ddf31SBarry Smith if (!value) break; 180e26ddf31SBarry Smith 181e26ddf31SBarry Smith /* look for form d-D where d and D are integers */ 182e26ddf31SBarry Smith foundrange = PETSC_FALSE; 183e26ddf31SBarry Smith ierr = PetscStrlen(value,&len);CHKERRQ(ierr); 184e26ddf31SBarry Smith if (value[0] == '-') i=2; 185e26ddf31SBarry Smith else i=1; 186330cf3c9SBarry Smith for (;i<len; i++) { 187e26ddf31SBarry Smith if (value[i] == '-') { 188e32f2f54SBarry Smith if (i == len-1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry %s\n",n,value); 189e26ddf31SBarry Smith value[i] = 0; 190*cfbddea1SSatish Balay ierr = PetscOptionsStringToInt(value,&start);CHKERRQ(ierr); 191*cfbddea1SSatish Balay ierr = PetscOptionsStringToInt(value+i+1,&end);CHKERRQ(ierr); 192e32f2f54SBarry 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); 193e32f2f54SBarry 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); 194e26ddf31SBarry Smith for (;start<end; start++) { 195e26ddf31SBarry Smith *dvalue = start; dvalue++;n++; 196e26ddf31SBarry Smith } 197e26ddf31SBarry Smith foundrange = PETSC_TRUE; 198e26ddf31SBarry Smith break; 199e26ddf31SBarry Smith } 200e26ddf31SBarry Smith } 201e26ddf31SBarry Smith if (!foundrange) { 202*cfbddea1SSatish Balay ierr = PetscOptionsStringToInt(value,dvalue);CHKERRQ(ierr); 203e26ddf31SBarry Smith dvalue++; 204e26ddf31SBarry Smith n++; 205e26ddf31SBarry Smith } 206e26ddf31SBarry Smith ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 207e26ddf31SBarry Smith } 208e26ddf31SBarry Smith ierr = PetscTokenDestroy(token);CHKERRQ(ierr); 209e26ddf31SBarry Smith } 210e26ddf31SBarry Smith break; 211e26ddf31SBarry Smith case OPTION_REAL_ARRAY: 212e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1);CHKERRQ(ierr); 213e26ddf31SBarry Smith valr = (PetscReal*) next->data; 214e26ddf31SBarry Smith for (i=0; i<next->arraylength; i++) { 215e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,"%g",valr[i]);CHKERRQ(ierr); 216e26ddf31SBarry Smith if (i < next->arraylength-1) { 217e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr); 218e26ddf31SBarry Smith } 219e26ddf31SBarry Smith } 220e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s)",next->text,next->man);CHKERRQ(ierr); 221e26ddf31SBarry Smith ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 222e26ddf31SBarry Smith if (str[0]) { 223e26ddf31SBarry Smith PetscToken token; 224e26ddf31SBarry Smith PetscInt n=0,nmax = next->arraylength; 225e26ddf31SBarry Smith PetscReal *dvalue = (PetscReal*)next->data; 226e26ddf31SBarry Smith char* value; 227e26ddf31SBarry Smith 228e26ddf31SBarry Smith next->set = PETSC_TRUE; 229e26ddf31SBarry Smith value = str; 230e26ddf31SBarry Smith ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 231e26ddf31SBarry Smith ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 232e26ddf31SBarry Smith while (n < nmax) { 233e26ddf31SBarry Smith if (!value) break; 234*cfbddea1SSatish Balay ierr = PetscOptionsStringToReal(value,dvalue);CHKERRQ(ierr); 235e26ddf31SBarry Smith dvalue++; 236e26ddf31SBarry Smith n++; 237e26ddf31SBarry Smith ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 238e26ddf31SBarry Smith } 239e26ddf31SBarry Smith ierr = PetscTokenDestroy(token);CHKERRQ(ierr); 240e26ddf31SBarry Smith } 241e26ddf31SBarry Smith break; 2426356e834SBarry Smith case OPTION_INT: 243e26ddf31SBarry 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); 2443fc1eb6aSBarry Smith ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 2453fc1eb6aSBarry Smith if (str[0]) { 246c272547aSJed Brown #if defined(PETSC_USE_64BIT_INDICES) 247c272547aSJed Brown sscanf(str,"%lld",&id); 248c272547aSJed Brown #else 249aee2cecaSBarry Smith sscanf(str,"%d",&id); 250c272547aSJed Brown #endif 251aee2cecaSBarry Smith next->set = PETSC_TRUE; 252aee2cecaSBarry Smith *((PetscInt*)next->data) = id; 253aee2cecaSBarry Smith } 254aee2cecaSBarry Smith break; 255aee2cecaSBarry Smith case OPTION_REAL: 256e26ddf31SBarry 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); 2573fc1eb6aSBarry Smith ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 2583fc1eb6aSBarry Smith if (str[0]) { 259a4404d99SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE) 260a4404d99SBarry Smith sscanf(str,"%e",&ir); 261a4404d99SBarry Smith #else 262aee2cecaSBarry Smith sscanf(str,"%le",&ir); 263a4404d99SBarry Smith #endif 264aee2cecaSBarry Smith next->set = PETSC_TRUE; 265aee2cecaSBarry Smith *((PetscReal*)next->data) = ir; 266aee2cecaSBarry Smith } 267aee2cecaSBarry Smith break; 268aee2cecaSBarry Smith case OPTION_LOGICAL: 269aee2cecaSBarry Smith case OPTION_STRING: 270e26ddf31SBarry 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); 2713fc1eb6aSBarry Smith ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 2723fc1eb6aSBarry Smith if (str[0]) { 273aee2cecaSBarry Smith next->set = PETSC_TRUE; 274330cf3c9SBarry Smith ierr = PetscStrcpy((char*)next->data,str);CHKERRQ(ierr); 2756356e834SBarry Smith } 2766356e834SBarry Smith break; 2773cc1e11dSBarry Smith case OPTION_LIST: 2783cc1e11dSBarry Smith ierr = PetscFListPrintTypes(PETSC_COMM_WORLD,stdout,PetscOptionsObject.prefix,next->option,next->text,next->man,next->flist,(char*)next->data);CHKERRQ(ierr); 2793cc1e11dSBarry Smith ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 2803cc1e11dSBarry Smith if (str[0]) { 2813cc1e11dSBarry Smith PetscOptionsObject.changedmethod = PETSC_TRUE; 2823cc1e11dSBarry Smith next->set = PETSC_TRUE; 283330cf3c9SBarry Smith ierr = PetscStrcpy((char*)next->data,str);CHKERRQ(ierr); 2843cc1e11dSBarry Smith } 2853cc1e11dSBarry Smith break; 286b432afdaSMatthew Knepley default: 287b432afdaSMatthew Knepley break; 2886356e834SBarry Smith } 2896356e834SBarry Smith next = next->next; 2906356e834SBarry Smith } 2916356e834SBarry Smith PetscFunctionReturn(0); 2926356e834SBarry Smith } 2936356e834SBarry Smith 294b3506946SBarry Smith #if defined(PETSC_HAVE_AMS) 2951ae3d29cSBarry Smith #define CHKERRAMS(err) if (err) {char *msg; AMS_Explain_error((err), &(msg)); SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"AMS Error: %s",msg);} 2961ae3d29cSBarry 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);} 297d5649816SBarry Smith 298d5649816SBarry Smith static int count = 0; 299d5649816SBarry Smith 300b3506946SBarry Smith #undef __FUNCT__ 301d5649816SBarry Smith #define __FUNCT__ "PetscOptionsAMSDestroy" 302d5649816SBarry Smith PetscErrorCode PetscOptionsAMSDestroy(void) 303d5649816SBarry Smith { 304d5649816SBarry Smith PetscErrorCode ierr; 305d5649816SBarry Smith AMS_Comm acomm = -1; 306d5649816SBarry Smith AMS_Memory amem = -1; 307d5649816SBarry Smith char options[16]; 308d5649816SBarry Smith const char *string = "Exit"; 309d5649816SBarry Smith 310d5649816SBarry Smith /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */ 311d5649816SBarry Smith ierr = PetscViewerAMSGetAMSComm(PETSC_VIEWER_AMS_(PETSC_COMM_WORLD),&acomm);CHKERRQ(ierr); 312d5649816SBarry Smith sprintf(options,"Options_%d",count++); 313d5649816SBarry Smith ierr = AMS_Memory_create(acomm,options,&amem);CHKERRAMS(ierr); 314d5649816SBarry Smith ierr = AMS_Memory_add_field(amem,"Exit",&string,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,"Exit"); 315d5649816SBarry Smith 316d5649816SBarry Smith ierr = AMS_Memory_take_access(amem);CHKERRAMS(ierr); 317d5649816SBarry Smith ierr = AMS_Memory_publish(amem);CHKERRAMS(ierr); 318d5649816SBarry Smith ierr = AMS_Memory_grant_access(amem);CHKERRAMS(ierr); 319d5649816SBarry Smith /* wait until accessor has unlocked the memory */ 320d5649816SBarry Smith ierr = AMS_Memory_lock(amem,0);CHKERRAMS(ierr); 321d5649816SBarry Smith ierr = AMS_Memory_take_access(amem);CHKERRAMS(ierr); 322d5649816SBarry Smith ierr = AMS_Memory_grant_access(amem);CHKERRAMS(ierr); 323d5649816SBarry Smith ierr = AMS_Memory_destroy(amem);CHKERRAMS(ierr); 324d5649816SBarry Smith PetscFunctionReturn(0); 325d5649816SBarry Smith } 326d5649816SBarry Smith 327d5649816SBarry Smith #undef __FUNCT__ 328d5649816SBarry Smith #define __FUNCT__ "PetscOptionsAMSInput" 329b3506946SBarry Smith /* 330d5649816SBarry Smith PetscOptionsAMSInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the AMS 331b3506946SBarry Smith 332b3506946SBarry Smith Bugs: 333b3506946SBarry Smith + All processes must traverse through the exact same set of option queries do to the call to PetscScanString() 334b3506946SBarry Smith . Internal strings have arbitrary length and string copies are not checked that they fit into string space 335b3506946SBarry Smith - Only works for PetscInt == int, PetscReal == double etc 336b3506946SBarry Smith 337b3506946SBarry Smith 338b3506946SBarry Smith */ 339d5649816SBarry Smith PetscErrorCode PetscOptionsAMSInput() 340b3506946SBarry Smith { 341b3506946SBarry Smith PetscErrorCode ierr; 342b3506946SBarry Smith PetscOptions next = PetscOptionsObject.next; 343d5649816SBarry Smith static int mancount = 0; 344b3506946SBarry Smith char options[16]; 345b3506946SBarry Smith AMS_Comm acomm = -1; 346b3506946SBarry Smith AMS_Memory amem = -1; 347ace3abfcSBarry Smith PetscBool changedmethod = PETSC_FALSE; 3489f32e415SBarry Smith char manname[16]; 349b3506946SBarry Smith 350b3506946SBarry Smith /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */ 351b3506946SBarry Smith ierr = PetscViewerAMSGetAMSComm(PETSC_VIEWER_AMS_(PETSC_COMM_WORLD),&acomm);CHKERRQ(ierr); 352b3506946SBarry Smith sprintf(options,"Options_%d",count++); 3531ae3d29cSBarry Smith ierr = AMS_Memory_create(acomm,options,&amem);CHKERRAMS(ierr); 3541ae3d29cSBarry Smith ierr = AMS_Memory_take_access(amem);CHKERRAMS(ierr); 3551bc75a8dSBarry Smith PetscOptionsObject.pprefix = PetscOptionsObject.prefix; /* AMS will change this, so cannot pass prefix directly */ 3561bc75a8dSBarry Smith 3571ae3d29cSBarry 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); 3581ae3d29cSBarry Smith // ierr = AMS_Memory_add_field(amem,"mansec",&PetscOptionsObject.pprefix,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMS(ierr); 3591ae3d29cSBarry Smith ierr = AMS_Memory_add_field(amem,"ChangedMethod",&changedmethod,1,AMS_BOOLEAN,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,"ChangedMethod"); 360b3506946SBarry Smith 361b3506946SBarry Smith while (next) { 3621ae3d29cSBarry 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); 3631bc75a8dSBarry Smith ierr = PetscMalloc(sizeof(char*),&next->pman);CHKERRQ(ierr); 3641bc75a8dSBarry Smith *(char **)next->pman = next->man; 3659f32e415SBarry Smith sprintf(manname,"man_%d",mancount++); 3661ae3d29cSBarry Smith ierr = AMS_Memory_add_field(amem,manname,next->pman,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,manname); 3679f32e415SBarry Smith 368b3506946SBarry Smith switch (next->type) { 369b3506946SBarry Smith case OPTION_HEAD: 370b3506946SBarry Smith break; 371b3506946SBarry Smith case OPTION_INT_ARRAY: 3721ae3d29cSBarry 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); 373b3506946SBarry Smith break; 374b3506946SBarry Smith case OPTION_REAL_ARRAY: 3751ae3d29cSBarry 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); 376b3506946SBarry Smith break; 377b3506946SBarry Smith case OPTION_INT: 3781ae3d29cSBarry 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); 379b3506946SBarry Smith break; 380b3506946SBarry Smith case OPTION_REAL: 3811ae3d29cSBarry 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); 382b3506946SBarry Smith break; 383b3506946SBarry Smith case OPTION_LOGICAL: 3841ae3d29cSBarry 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); 3851ae3d29cSBarry Smith break; 3861ae3d29cSBarry Smith case OPTION_LOGICAL_ARRAY: 3871ae3d29cSBarry 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); 38871f08665SBarry Smith break; 389b3506946SBarry Smith case OPTION_STRING: 3901ae3d29cSBarry 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); 3911ae3d29cSBarry Smith break; 3921ae3d29cSBarry Smith case OPTION_STRING_ARRAY: 3931ae3d29cSBarry 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); 394b3506946SBarry Smith break; 395b3506946SBarry Smith case OPTION_LIST: 39671f08665SBarry Smith {PetscInt ntext; 39771f08665SBarry Smith char ldefault[128]; 39871f08665SBarry Smith ierr = PetscStrcpy(ldefault,"DEFAULT:");CHKERRQ(ierr); 39971f08665SBarry Smith ierr = PetscStrcat(ldefault,next->text);CHKERRQ(ierr); 4001ae3d29cSBarry Smith ierr = AMS_Memory_add_field(amem,ldefault,next->data,1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,ldefault); 40171f08665SBarry Smith ierr = PetscFListGet(next->flist,(char***)&next->edata,&ntext);CHKERRQ(ierr); 402d5649816SBarry 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); 4031ae3d29cSBarry Smith break;} 4041ae3d29cSBarry Smith case OPTION_ELIST: 405d5649816SBarry Smith {PetscInt ntext = next->nlist; 4061ae3d29cSBarry Smith char ldefault[128]; 4071ae3d29cSBarry Smith ierr = PetscStrcpy(ldefault,"DEFAULT:");CHKERRQ(ierr); 4081ae3d29cSBarry Smith ierr = PetscStrcat(ldefault,next->text);CHKERRQ(ierr); 4091ae3d29cSBarry Smith ierr = AMS_Memory_add_field(amem,ldefault,next->data,1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,ldefault); 4101ae3d29cSBarry Smith ierr = PetscMalloc((ntext+1)*sizeof(char**),&next->edata);CHKERRQ(ierr); 4111ae3d29cSBarry Smith ierr = PetscMemcpy(next->edata,next->list,ntext*sizeof(char*));CHKERRQ(ierr); 4121ae3d29cSBarry 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); 41371f08665SBarry Smith break;} 414b3506946SBarry Smith default: 415b3506946SBarry Smith break; 416b3506946SBarry Smith } 417b3506946SBarry Smith next = next->next; 418b3506946SBarry Smith } 419b3506946SBarry Smith 4201ae3d29cSBarry Smith ierr = AMS_Memory_publish(amem);CHKERRAMS(ierr); 4211ae3d29cSBarry Smith ierr = AMS_Memory_grant_access(amem);CHKERRAMS(ierr); 422b3506946SBarry Smith /* wait until accessor has unlocked the memory */ 4231ae3d29cSBarry Smith ierr = AMS_Memory_lock(amem,0);CHKERRAMS(ierr); 4241ae3d29cSBarry Smith ierr = AMS_Memory_take_access(amem);CHKERRAMS(ierr); 425b3506946SBarry Smith 426b3506946SBarry Smith /* reset counter to -2; this updates the screen with the new options for the selected method */ 427b3506946SBarry Smith if (changedmethod) PetscOptionsPublishCount = -2; 428b3506946SBarry Smith 4291ae3d29cSBarry Smith ierr = AMS_Memory_grant_access(amem);CHKERRAMS(ierr); 4301ae3d29cSBarry Smith ierr = AMS_Memory_destroy(amem);CHKERRAMS(ierr); 431b3506946SBarry Smith PetscFunctionReturn(0); 432b3506946SBarry Smith } 433b3506946SBarry Smith #endif 434b3506946SBarry Smith 4356356e834SBarry Smith #undef __FUNCT__ 43653acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsEnd_Private" 43753acd3b1SBarry Smith PetscErrorCode PetscOptionsEnd_Private(void) 43853acd3b1SBarry Smith { 43953acd3b1SBarry Smith PetscErrorCode ierr; 4406356e834SBarry Smith PetscOptions last; 4416356e834SBarry Smith char option[256],value[1024],tmp[32]; 442330cf3c9SBarry Smith size_t j; 44353acd3b1SBarry Smith 44453acd3b1SBarry Smith PetscFunctionBegin; 4456356e834SBarry Smith 4461bc75a8dSBarry Smith CHKMEMQ; 447aee2cecaSBarry Smith if (PetscOptionsObject.next) { 448b3506946SBarry Smith if (!PetscOptionsPublishCount) { 449b3506946SBarry Smith #if defined(PETSC_HAVE_AMS) 450d5649816SBarry Smith ierr = PetscOptionsAMSInput();CHKERRQ(ierr); 451b3506946SBarry Smith #else 45271f08665SBarry Smith ierr = PetscOptionsGetFromTextInput();CHKERRQ(ierr); 453b3506946SBarry Smith #endif 454aee2cecaSBarry Smith } 455aee2cecaSBarry Smith } 4566356e834SBarry Smith 457503cfb0cSBarry Smith ierr = PetscFree(PetscOptionsObject.title);CHKERRQ(ierr); PetscOptionsObject.title = 0; 458503cfb0cSBarry Smith ierr = PetscFree(PetscOptionsObject.prefix);CHKERRQ(ierr); PetscOptionsObject.prefix = 0; 4596356e834SBarry Smith 4606356e834SBarry Smith /* reset counter to -2; this updates the screen with the new options for the selected method */ 4616356e834SBarry Smith if (PetscOptionsObject.changedmethod) PetscOptionsPublishCount = -2; 46261b37b28SSatish Balay /* reset alreadyprinted flag */ 46361b37b28SSatish Balay PetscOptionsObject.alreadyprinted = PETSC_FALSE; 4646356e834SBarry Smith 4656356e834SBarry Smith while (PetscOptionsObject.next) { 4666356e834SBarry Smith if (PetscOptionsObject.next->set) { 4676356e834SBarry Smith if (PetscOptionsObject.prefix) { 4686356e834SBarry Smith ierr = PetscStrcpy(option,"-");CHKERRQ(ierr); 4696356e834SBarry Smith ierr = PetscStrcat(option,PetscOptionsObject.prefix);CHKERRQ(ierr); 4706356e834SBarry Smith ierr = PetscStrcat(option,PetscOptionsObject.next->option+1);CHKERRQ(ierr); 4716356e834SBarry Smith } else { 4726356e834SBarry Smith ierr = PetscStrcpy(option,PetscOptionsObject.next->option);CHKERRQ(ierr); 4736356e834SBarry Smith } 4746356e834SBarry Smith 4756356e834SBarry Smith switch (PetscOptionsObject.next->type) { 4766356e834SBarry Smith case OPTION_HEAD: 4776356e834SBarry Smith break; 478e26ddf31SBarry Smith case OPTION_INT_ARRAY: 479e26ddf31SBarry Smith sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[0]); 480e26ddf31SBarry Smith for (j=1; j<PetscOptionsObject.next->arraylength; j++) { 481e26ddf31SBarry Smith sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[j]); 482e26ddf31SBarry Smith ierr = PetscStrcat(value,",");CHKERRQ(ierr); 483e26ddf31SBarry Smith ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 484e26ddf31SBarry Smith } 485e26ddf31SBarry Smith break; 4866356e834SBarry Smith case OPTION_INT: 4877a72a596SBarry Smith sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject.next->data); 4886356e834SBarry Smith break; 4896356e834SBarry Smith case OPTION_REAL: 4907a72a596SBarry Smith sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject.next->data); 4916356e834SBarry Smith break; 4926356e834SBarry Smith case OPTION_REAL_ARRAY: 4937a72a596SBarry Smith sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[0]); 4946356e834SBarry Smith for (j=1; j<PetscOptionsObject.next->arraylength; j++) { 4957a72a596SBarry Smith sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[j]); 4966356e834SBarry Smith ierr = PetscStrcat(value,",");CHKERRQ(ierr); 4976356e834SBarry Smith ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 4986356e834SBarry Smith } 4996356e834SBarry Smith break; 5006356e834SBarry Smith case OPTION_LOGICAL: 50171f08665SBarry Smith sprintf(value,"%d",*(int*)PetscOptionsObject.next->data); 5026356e834SBarry Smith break; 5031ae3d29cSBarry Smith case OPTION_LOGICAL_ARRAY: 504ace3abfcSBarry Smith sprintf(value,"%d",(int)((PetscBool*)PetscOptionsObject.next->data)[0]); 5051ae3d29cSBarry Smith for (j=1; j<PetscOptionsObject.next->arraylength; j++) { 506ace3abfcSBarry Smith sprintf(tmp,"%d",(int)((PetscBool*)PetscOptionsObject.next->data)[j]); 5071ae3d29cSBarry Smith ierr = PetscStrcat(value,",");CHKERRQ(ierr); 5081ae3d29cSBarry Smith ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 5091ae3d29cSBarry Smith } 5101ae3d29cSBarry Smith break; 5116356e834SBarry Smith case OPTION_LIST: 5121ae3d29cSBarry Smith case OPTION_ELIST: 51371f08665SBarry Smith ierr = PetscStrcpy(value,*(char**)PetscOptionsObject.next->data);CHKERRQ(ierr); 5146356e834SBarry Smith break; 5151ae3d29cSBarry Smith case OPTION_STRING: 51671f08665SBarry Smith ierr = PetscStrcpy(value,*(char**)PetscOptionsObject.next->data);CHKERRQ(ierr); 5171ae3d29cSBarry Smith case OPTION_STRING_ARRAY: 5181ae3d29cSBarry Smith sprintf(value,"%s",((char**)PetscOptionsObject.next->data)[0]); 5191ae3d29cSBarry Smith for (j=1; j<PetscOptionsObject.next->arraylength; j++) { 5201ae3d29cSBarry Smith sprintf(tmp,"%s",((char**)PetscOptionsObject.next->data)[j]); 5211ae3d29cSBarry Smith ierr = PetscStrcat(value,",");CHKERRQ(ierr); 5221ae3d29cSBarry Smith ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 5231ae3d29cSBarry Smith } 5246356e834SBarry Smith break; 5256356e834SBarry Smith } 5266356e834SBarry Smith ierr = PetscOptionsSetValue(option,value);CHKERRQ(ierr); 5276356e834SBarry Smith } 528503cfb0cSBarry Smith ierr = PetscFree(PetscOptionsObject.next->text);CHKERRQ(ierr); 529503cfb0cSBarry Smith ierr = PetscFree(PetscOptionsObject.next->option);CHKERRQ(ierr); 5306356e834SBarry Smith ierr = PetscFree(PetscOptionsObject.next->man);CHKERRQ(ierr); 53105b42c5fSBarry Smith ierr = PetscFree(PetscOptionsObject.next->data);CHKERRQ(ierr); 53271f08665SBarry Smith ierr = PetscFree(PetscOptionsObject.next->edata);CHKERRQ(ierr); 5336356e834SBarry Smith last = PetscOptionsObject.next; 5346356e834SBarry Smith PetscOptionsObject.next = PetscOptionsObject.next->next; 5356356e834SBarry Smith ierr = PetscFree(last);CHKERRQ(ierr); 5361bc75a8dSBarry Smith CHKMEMQ; 5376356e834SBarry Smith } 5381bc75a8dSBarry Smith CHKMEMQ; 5396356e834SBarry Smith PetscOptionsObject.next = 0; 54053acd3b1SBarry Smith PetscFunctionReturn(0); 54153acd3b1SBarry Smith } 54253acd3b1SBarry Smith 54353acd3b1SBarry Smith #undef __FUNCT__ 54453acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsEnum" 54553acd3b1SBarry Smith /*@C 54653acd3b1SBarry Smith PetscOptionsEnum - Gets the enum value for a particular option in the database. 54753acd3b1SBarry Smith 5483f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 54953acd3b1SBarry Smith 55053acd3b1SBarry Smith Input Parameters: 55153acd3b1SBarry Smith + opt - option name 55253acd3b1SBarry Smith . text - short string that describes the option 55353acd3b1SBarry Smith . man - manual page with additional information on option 55453acd3b1SBarry Smith . list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null 55553acd3b1SBarry Smith - defaultv - the default (current) value 55653acd3b1SBarry Smith 55753acd3b1SBarry Smith Output Parameter: 55853acd3b1SBarry Smith + value - the value to return 55953acd3b1SBarry Smith - flg - PETSC_TRUE if found, else PETSC_FALSE 56053acd3b1SBarry Smith 56153acd3b1SBarry Smith Level: beginner 56253acd3b1SBarry Smith 56353acd3b1SBarry Smith Concepts: options database 56453acd3b1SBarry Smith 56553acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 56653acd3b1SBarry Smith 56753acd3b1SBarry Smith list is usually something like PCASMTypes or some other predefined list of enum names 56853acd3b1SBarry Smith 56953acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 570acfcf0e5SJed Brown PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 571acfcf0e5SJed Brown PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 57253acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 57353acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 574acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 57553acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 57653acd3b1SBarry Smith @*/ 577ace3abfcSBarry Smith PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const*list,PetscEnum defaultv,PetscEnum *value,PetscBool *set) 57853acd3b1SBarry Smith { 57953acd3b1SBarry Smith PetscErrorCode ierr; 58053acd3b1SBarry Smith PetscInt ntext = 0; 581aa5bb8c0SSatish Balay PetscInt tval; 582ace3abfcSBarry Smith PetscBool tflg; 58353acd3b1SBarry Smith 58453acd3b1SBarry Smith PetscFunctionBegin; 58553acd3b1SBarry Smith while (list[ntext++]) { 586e32f2f54SBarry Smith if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries"); 58753acd3b1SBarry Smith } 588e32f2f54SBarry Smith if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix"); 58953acd3b1SBarry Smith ntext -= 3; 590aa5bb8c0SSatish Balay ierr = PetscOptionsEList(opt,text,man,list,ntext,list[defaultv],&tval,&tflg);CHKERRQ(ierr); 591aa5bb8c0SSatish Balay /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */ 592aa5bb8c0SSatish Balay if (tflg) *value = (PetscEnum)tval; 593aa5bb8c0SSatish Balay if (set) *set = tflg; 59453acd3b1SBarry Smith PetscFunctionReturn(0); 59553acd3b1SBarry Smith } 59653acd3b1SBarry Smith 59753acd3b1SBarry Smith /* -------------------------------------------------------------------------------------------------------------*/ 59853acd3b1SBarry Smith #undef __FUNCT__ 59953acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsInt" 60053acd3b1SBarry Smith /*@C 60153acd3b1SBarry Smith PetscOptionsInt - Gets the integer value for a particular option in the database. 60253acd3b1SBarry Smith 6033f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 60453acd3b1SBarry Smith 60553acd3b1SBarry Smith Input Parameters: 60653acd3b1SBarry Smith + opt - option name 60753acd3b1SBarry Smith . text - short string that describes the option 60853acd3b1SBarry Smith . man - manual page with additional information on option 60953acd3b1SBarry Smith - defaultv - the default (current) value 61053acd3b1SBarry Smith 61153acd3b1SBarry Smith Output Parameter: 61253acd3b1SBarry Smith + value - the integer value to return 61353acd3b1SBarry Smith - flg - PETSC_TRUE if found, else PETSC_FALSE 61453acd3b1SBarry Smith 61553acd3b1SBarry Smith Level: beginner 61653acd3b1SBarry Smith 61753acd3b1SBarry Smith Concepts: options database^has int 61853acd3b1SBarry Smith 61953acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 62053acd3b1SBarry Smith 62153acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 622acfcf0e5SJed Brown PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 623acfcf0e5SJed Brown PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 62453acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 62553acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 626acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 62753acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 62853acd3b1SBarry Smith @*/ 629ace3abfcSBarry Smith PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt defaultv,PetscInt *value,PetscBool *set) 63053acd3b1SBarry Smith { 63153acd3b1SBarry Smith PetscErrorCode ierr; 6326356e834SBarry Smith PetscOptions amsopt; 63353acd3b1SBarry Smith 63453acd3b1SBarry Smith PetscFunctionBegin; 635b3506946SBarry Smith if (!PetscOptionsPublishCount) { 6366356e834SBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr); 6376356e834SBarry Smith ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr); 6386356e834SBarry Smith *(PetscInt*)amsopt->data = defaultv; 639af6d86caSBarry Smith } 64053acd3b1SBarry Smith ierr = PetscOptionsGetInt(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 64161b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 6422aa6d131SJed Brown ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%d>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr); 64353acd3b1SBarry Smith } 64453acd3b1SBarry Smith PetscFunctionReturn(0); 64553acd3b1SBarry Smith } 64653acd3b1SBarry Smith 64753acd3b1SBarry Smith #undef __FUNCT__ 64853acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsString" 64953acd3b1SBarry Smith /*@C 65053acd3b1SBarry Smith PetscOptionsString - Gets the string value for a particular option in the database. 65153acd3b1SBarry Smith 6523f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 65353acd3b1SBarry Smith 65453acd3b1SBarry Smith Input Parameters: 65553acd3b1SBarry Smith + opt - option name 65653acd3b1SBarry Smith . text - short string that describes the option 65753acd3b1SBarry Smith . man - manual page with additional information on option 658bcbf2dc5SJed Brown . defaultv - the default (current) value 659bcbf2dc5SJed Brown - len - length of the result string including null terminator 66053acd3b1SBarry Smith 66153acd3b1SBarry Smith Output Parameter: 66253acd3b1SBarry Smith + value - the value to return 66353acd3b1SBarry Smith - flg - PETSC_TRUE if found, else PETSC_FALSE 66453acd3b1SBarry Smith 66553acd3b1SBarry Smith Level: beginner 66653acd3b1SBarry Smith 66753acd3b1SBarry Smith Concepts: options database^has int 66853acd3b1SBarry Smith 66953acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 67053acd3b1SBarry Smith 67153acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 672acfcf0e5SJed Brown PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 673acfcf0e5SJed Brown PetscOptionsInt(), PetscOptionsReal(), PetscOptionsBool(), 67453acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 67553acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 676acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 67753acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 67853acd3b1SBarry Smith @*/ 679ace3abfcSBarry Smith PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsString(const char opt[],const char text[],const char man[],const char defaultv[],char value[],size_t len,PetscBool *set) 68053acd3b1SBarry Smith { 68153acd3b1SBarry Smith PetscErrorCode ierr; 682aee2cecaSBarry Smith PetscOptions amsopt; 68353acd3b1SBarry Smith 68453acd3b1SBarry Smith PetscFunctionBegin; 685b3506946SBarry Smith if (!PetscOptionsPublishCount) { 686aee2cecaSBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr); 68771f08665SBarry Smith ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr); 68871f08665SBarry Smith *(const char**)amsopt->data = defaultv; 689af6d86caSBarry Smith } 69053acd3b1SBarry Smith ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr); 69161b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 6922aa6d131SJed Brown ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr); 69353acd3b1SBarry Smith } 69453acd3b1SBarry Smith PetscFunctionReturn(0); 69553acd3b1SBarry Smith } 69653acd3b1SBarry Smith 69753acd3b1SBarry Smith #undef __FUNCT__ 69853acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsReal" 69953acd3b1SBarry Smith /*@C 70053acd3b1SBarry Smith PetscOptionsReal - Gets the PetscReal value for a particular option in the database. 70153acd3b1SBarry Smith 7023f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 70353acd3b1SBarry Smith 70453acd3b1SBarry Smith Input Parameters: 70553acd3b1SBarry Smith + opt - option name 70653acd3b1SBarry Smith . text - short string that describes the option 70753acd3b1SBarry Smith . man - manual page with additional information on option 70853acd3b1SBarry Smith - defaultv - the default (current) value 70953acd3b1SBarry Smith 71053acd3b1SBarry Smith Output Parameter: 71153acd3b1SBarry Smith + value - the value to return 71253acd3b1SBarry Smith - flg - PETSC_TRUE if found, else PETSC_FALSE 71353acd3b1SBarry Smith 71453acd3b1SBarry Smith Level: beginner 71553acd3b1SBarry Smith 71653acd3b1SBarry Smith Concepts: options database^has int 71753acd3b1SBarry Smith 71853acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 71953acd3b1SBarry Smith 72053acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 721acfcf0e5SJed Brown PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 722acfcf0e5SJed Brown PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 72353acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 72453acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 725acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 72653acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 72753acd3b1SBarry Smith @*/ 728ace3abfcSBarry Smith PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal defaultv,PetscReal *value,PetscBool *set) 72953acd3b1SBarry Smith { 73053acd3b1SBarry Smith PetscErrorCode ierr; 731538aa990SBarry Smith PetscOptions amsopt; 73253acd3b1SBarry Smith 73353acd3b1SBarry Smith PetscFunctionBegin; 734b3506946SBarry Smith if (!PetscOptionsPublishCount) { 735538aa990SBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr); 736538aa990SBarry Smith ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr); 737538aa990SBarry Smith *(PetscReal*)amsopt->data = defaultv; 738538aa990SBarry Smith } 73953acd3b1SBarry Smith ierr = PetscOptionsGetReal(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 74061b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 7412aa6d131SJed Brown ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%G>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr); 74253acd3b1SBarry Smith } 74353acd3b1SBarry Smith PetscFunctionReturn(0); 74453acd3b1SBarry Smith } 74553acd3b1SBarry Smith 74653acd3b1SBarry Smith #undef __FUNCT__ 74753acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsScalar" 74853acd3b1SBarry Smith /*@C 74953acd3b1SBarry Smith PetscOptionsScalar - Gets the scalar value for a particular option in the database. 75053acd3b1SBarry Smith 7513f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 75253acd3b1SBarry Smith 75353acd3b1SBarry Smith Input Parameters: 75453acd3b1SBarry Smith + opt - option name 75553acd3b1SBarry Smith . text - short string that describes the option 75653acd3b1SBarry Smith . man - manual page with additional information on option 75753acd3b1SBarry Smith - defaultv - the default (current) value 75853acd3b1SBarry Smith 75953acd3b1SBarry Smith Output Parameter: 76053acd3b1SBarry Smith + value - the value to return 76153acd3b1SBarry Smith - flg - PETSC_TRUE if found, else PETSC_FALSE 76253acd3b1SBarry Smith 76353acd3b1SBarry Smith Level: beginner 76453acd3b1SBarry Smith 76553acd3b1SBarry Smith Concepts: options database^has int 76653acd3b1SBarry Smith 76753acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 76853acd3b1SBarry Smith 76953acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 770acfcf0e5SJed Brown PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 771acfcf0e5SJed Brown PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 77253acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 77353acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 774acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 77553acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 77653acd3b1SBarry Smith @*/ 777ace3abfcSBarry Smith PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar defaultv,PetscScalar *value,PetscBool *set) 77853acd3b1SBarry Smith { 77953acd3b1SBarry Smith PetscErrorCode ierr; 78053acd3b1SBarry Smith 78153acd3b1SBarry Smith PetscFunctionBegin; 78253acd3b1SBarry Smith #if !defined(PETSC_USE_COMPLEX) 78353acd3b1SBarry Smith ierr = PetscOptionsReal(opt,text,man,defaultv,value,set);CHKERRQ(ierr); 78453acd3b1SBarry Smith #else 78553acd3b1SBarry Smith ierr = PetscOptionsGetScalar(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr); 78653acd3b1SBarry Smith #endif 78753acd3b1SBarry Smith PetscFunctionReturn(0); 78853acd3b1SBarry Smith } 78953acd3b1SBarry Smith 79053acd3b1SBarry Smith #undef __FUNCT__ 79153acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsName" 79253acd3b1SBarry Smith /*@C 79390d69ab7SBarry 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 79490d69ab7SBarry Smith its value is set to false. 79553acd3b1SBarry Smith 7963f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 79753acd3b1SBarry Smith 79853acd3b1SBarry Smith Input Parameters: 79953acd3b1SBarry Smith + opt - option name 80053acd3b1SBarry Smith . text - short string that describes the option 80153acd3b1SBarry Smith - man - manual page with additional information on option 80253acd3b1SBarry Smith 80353acd3b1SBarry Smith Output Parameter: 80453acd3b1SBarry Smith . flg - PETSC_TRUE if found, else PETSC_FALSE 80553acd3b1SBarry Smith 80653acd3b1SBarry Smith Level: beginner 80753acd3b1SBarry Smith 80853acd3b1SBarry Smith Concepts: options database^has int 80953acd3b1SBarry Smith 81053acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 81153acd3b1SBarry Smith 81253acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 813acfcf0e5SJed Brown PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 814acfcf0e5SJed Brown PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 81553acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 81653acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 817acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 81853acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 81953acd3b1SBarry Smith @*/ 820ace3abfcSBarry Smith PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsName(const char opt[],const char text[],const char man[],PetscBool *flg) 82153acd3b1SBarry Smith { 82253acd3b1SBarry Smith PetscErrorCode ierr; 8231ae3d29cSBarry Smith PetscOptions amsopt; 82453acd3b1SBarry Smith 82553acd3b1SBarry Smith PetscFunctionBegin; 8261ae3d29cSBarry Smith if (!PetscOptionsPublishCount) { 8271ae3d29cSBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr); 828ace3abfcSBarry Smith ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 829ace3abfcSBarry Smith *(PetscBool*)amsopt->data = PETSC_FALSE; 8301ae3d29cSBarry Smith } 83153acd3b1SBarry Smith ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr); 83261b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 8332aa6d131SJed Brown ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,ManSection(man));CHKERRQ(ierr); 83453acd3b1SBarry Smith } 83553acd3b1SBarry Smith PetscFunctionReturn(0); 83653acd3b1SBarry Smith } 83753acd3b1SBarry Smith 83853acd3b1SBarry Smith #undef __FUNCT__ 83953acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsList" 84053acd3b1SBarry Smith /*@C 84153acd3b1SBarry Smith PetscOptionsList - Puts a list of option values that a single one may be selected from 84253acd3b1SBarry Smith 8433f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 84453acd3b1SBarry Smith 84553acd3b1SBarry Smith Input Parameters: 84653acd3b1SBarry Smith + opt - option name 84753acd3b1SBarry Smith . text - short string that describes the option 84853acd3b1SBarry Smith . man - manual page with additional information on option 84953acd3b1SBarry Smith . list - the possible choices 8503cc1e11dSBarry Smith . defaultv - the default (current) value 8513cc1e11dSBarry Smith - len - the length of the character array value 85253acd3b1SBarry Smith 85353acd3b1SBarry Smith Output Parameter: 85453acd3b1SBarry Smith + value - the value to return 85553acd3b1SBarry Smith - set - PETSC_TRUE if found, else PETSC_FALSE 85653acd3b1SBarry Smith 85753acd3b1SBarry Smith Level: intermediate 85853acd3b1SBarry Smith 85953acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 86053acd3b1SBarry Smith 86153acd3b1SBarry Smith See PetscOptionsEList() for when the choices are given in a string array 86253acd3b1SBarry Smith 86353acd3b1SBarry Smith To get a listing of all currently specified options, 86453acd3b1SBarry Smith see PetscOptionsPrint() or PetscOptionsGetAll() 86553acd3b1SBarry Smith 86653acd3b1SBarry Smith Concepts: options database^list 86753acd3b1SBarry Smith 86853acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 869acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 87053acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 87153acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 872acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 87353acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 87453acd3b1SBarry Smith @*/ 875ace3abfcSBarry Smith PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsList(const char opt[],const char ltext[],const char man[],PetscFList list,const char defaultv[],char value[],size_t len,PetscBool *set) 87653acd3b1SBarry Smith { 87753acd3b1SBarry Smith PetscErrorCode ierr; 8783cc1e11dSBarry Smith PetscOptions amsopt; 87953acd3b1SBarry Smith 88053acd3b1SBarry Smith PetscFunctionBegin; 881b3506946SBarry Smith if (!PetscOptionsPublishCount) { 8823cc1e11dSBarry Smith ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_LIST,&amsopt);CHKERRQ(ierr); 88371f08665SBarry Smith ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr); 88471f08665SBarry Smith *(const char**)amsopt->data = defaultv; 8853cc1e11dSBarry Smith amsopt->flist = list; 8863cc1e11dSBarry Smith } 88753acd3b1SBarry Smith ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr); 88861b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 8893cc1e11dSBarry Smith ierr = PetscFListPrintTypes(PetscOptionsObject.comm,stdout,PetscOptionsObject.prefix,opt,ltext,man,list,defaultv);CHKERRQ(ierr);CHKERRQ(ierr); 89053acd3b1SBarry Smith } 89153acd3b1SBarry Smith PetscFunctionReturn(0); 89253acd3b1SBarry Smith } 89353acd3b1SBarry Smith 89453acd3b1SBarry Smith #undef __FUNCT__ 89553acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsEList" 89653acd3b1SBarry Smith /*@C 89753acd3b1SBarry Smith PetscOptionsEList - Puts a list of option values that a single one may be selected from 89853acd3b1SBarry Smith 8993f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 90053acd3b1SBarry Smith 90153acd3b1SBarry Smith Input Parameters: 90253acd3b1SBarry Smith + opt - option name 90353acd3b1SBarry Smith . ltext - short string that describes the option 90453acd3b1SBarry Smith . man - manual page with additional information on option 90553acd3b1SBarry Smith . list - the possible choices 90653acd3b1SBarry Smith . ntext - number of choices 90753acd3b1SBarry Smith - defaultv - the default (current) value 90853acd3b1SBarry Smith 90953acd3b1SBarry Smith Output Parameter: 91053acd3b1SBarry Smith + value - the index of the value to return 91153acd3b1SBarry Smith - set - PETSC_TRUE if found, else PETSC_FALSE 91253acd3b1SBarry Smith 91353acd3b1SBarry Smith Level: intermediate 91453acd3b1SBarry Smith 91553acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 91653acd3b1SBarry Smith 91753acd3b1SBarry Smith See PetscOptionsList() for when the choices are given in a PetscFList() 91853acd3b1SBarry Smith 91953acd3b1SBarry Smith Concepts: options database^list 92053acd3b1SBarry Smith 92153acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 922acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 92353acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 92453acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 925acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 92653acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 92753acd3b1SBarry Smith @*/ 928ace3abfcSBarry Smith PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsEList(const char opt[],const char ltext[],const char man[],const char *const*list,PetscInt ntext,const char defaultv[],PetscInt *value,PetscBool *set) 92953acd3b1SBarry Smith { 93053acd3b1SBarry Smith PetscErrorCode ierr; 93153acd3b1SBarry Smith PetscInt i; 9321ae3d29cSBarry Smith PetscOptions amsopt; 93353acd3b1SBarry Smith 93453acd3b1SBarry Smith PetscFunctionBegin; 9351ae3d29cSBarry Smith if (!PetscOptionsPublishCount) { 936d5649816SBarry Smith ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_ELIST,&amsopt);CHKERRQ(ierr); 9371ae3d29cSBarry Smith ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr); 9381ae3d29cSBarry Smith *(const char**)amsopt->data = defaultv; 9391ae3d29cSBarry Smith amsopt->list = list; 9401ae3d29cSBarry Smith amsopt->nlist = ntext; 9411ae3d29cSBarry Smith } 94253acd3b1SBarry Smith ierr = PetscOptionsGetEList(PetscOptionsObject.prefix,opt,list,ntext,value,set);CHKERRQ(ierr); 94361b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 94453acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%s> (choose one of)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv);CHKERRQ(ierr); 94553acd3b1SBarry Smith for (i=0; i<ntext; i++){ 94653acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s",list[i]);CHKERRQ(ierr); 94753acd3b1SBarry Smith } 9482aa6d131SJed Brown ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," (%s)\n",ManSection(man));CHKERRQ(ierr); 94953acd3b1SBarry Smith } 95053acd3b1SBarry Smith PetscFunctionReturn(0); 95153acd3b1SBarry Smith } 95253acd3b1SBarry Smith 95353acd3b1SBarry Smith #undef __FUNCT__ 954acfcf0e5SJed Brown #define __FUNCT__ "PetscOptionsBoolGroupBegin" 95553acd3b1SBarry Smith /*@C 956acfcf0e5SJed Brown PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for 957d5649816SBarry Smith which at most a single value can be true. 95853acd3b1SBarry Smith 9593f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 96053acd3b1SBarry Smith 96153acd3b1SBarry Smith Input Parameters: 96253acd3b1SBarry Smith + opt - option name 96353acd3b1SBarry Smith . text - short string that describes the option 96453acd3b1SBarry Smith - man - manual page with additional information on option 96553acd3b1SBarry Smith 96653acd3b1SBarry Smith Output Parameter: 96753acd3b1SBarry Smith . flg - whether that option was set or not 96853acd3b1SBarry Smith 96953acd3b1SBarry Smith Level: intermediate 97053acd3b1SBarry Smith 97153acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 97253acd3b1SBarry Smith 973acfcf0e5SJed Brown Must be followed by 0 or more PetscOptionsBoolGroup()s and PetscOptionsBoolGroupEnd() 97453acd3b1SBarry Smith 97553acd3b1SBarry Smith Concepts: options database^logical group 97653acd3b1SBarry Smith 97753acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 978acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 97953acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 98053acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 981acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 98253acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 98353acd3b1SBarry Smith @*/ 984acfcf0e5SJed Brown PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsBoolGroupBegin(const char opt[],const char text[],const char man[],PetscBool *flg) 98553acd3b1SBarry Smith { 98653acd3b1SBarry Smith PetscErrorCode ierr; 9871ae3d29cSBarry Smith PetscOptions amsopt; 98853acd3b1SBarry Smith 98953acd3b1SBarry Smith PetscFunctionBegin; 9901ae3d29cSBarry Smith if (!PetscOptionsPublishCount) { 9911ae3d29cSBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr); 992ace3abfcSBarry Smith ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 993ace3abfcSBarry Smith *(PetscBool*)amsopt->data = PETSC_FALSE; 9941ae3d29cSBarry Smith } 99568b16fdaSBarry Smith *flg = PETSC_FALSE; 996acfcf0e5SJed Brown ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr); 99761b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 99853acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," Pick at most one of -------------\n");CHKERRQ(ierr); 9992aa6d131SJed Brown ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,ManSection(man));CHKERRQ(ierr); 100053acd3b1SBarry Smith } 100153acd3b1SBarry Smith PetscFunctionReturn(0); 100253acd3b1SBarry Smith } 100353acd3b1SBarry Smith 100453acd3b1SBarry Smith #undef __FUNCT__ 1005acfcf0e5SJed Brown #define __FUNCT__ "PetscOptionsBoolGroup" 100653acd3b1SBarry Smith /*@C 1007acfcf0e5SJed Brown PetscOptionsBoolGroup - One in a series of logical queries on the options database for 1008d5649816SBarry Smith which at most a single value can be true. 100953acd3b1SBarry Smith 10103f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 101153acd3b1SBarry Smith 101253acd3b1SBarry Smith Input Parameters: 101353acd3b1SBarry Smith + opt - option name 101453acd3b1SBarry Smith . text - short string that describes the option 101553acd3b1SBarry Smith - man - manual page with additional information on option 101653acd3b1SBarry Smith 101753acd3b1SBarry Smith Output Parameter: 101853acd3b1SBarry Smith . flg - PETSC_TRUE if found, else PETSC_FALSE 101953acd3b1SBarry Smith 102053acd3b1SBarry Smith Level: intermediate 102153acd3b1SBarry Smith 102253acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 102353acd3b1SBarry Smith 1024acfcf0e5SJed Brown Must follow a PetscOptionsBoolGroupBegin() and preceded a PetscOptionsBoolGroupEnd() 102553acd3b1SBarry Smith 102653acd3b1SBarry Smith Concepts: options database^logical group 102753acd3b1SBarry Smith 102853acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1029acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 103053acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 103153acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1032acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 103353acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 103453acd3b1SBarry Smith @*/ 1035acfcf0e5SJed Brown PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsBoolGroup(const char opt[],const char text[],const char man[],PetscBool *flg) 103653acd3b1SBarry Smith { 103753acd3b1SBarry Smith PetscErrorCode ierr; 10381ae3d29cSBarry Smith PetscOptions amsopt; 103953acd3b1SBarry Smith 104053acd3b1SBarry Smith PetscFunctionBegin; 10411ae3d29cSBarry Smith if (!PetscOptionsPublishCount) { 10421ae3d29cSBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr); 1043ace3abfcSBarry Smith ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1044ace3abfcSBarry Smith *(PetscBool*)amsopt->data = PETSC_FALSE; 10451ae3d29cSBarry Smith } 104617326d04SJed Brown *flg = PETSC_FALSE; 1047acfcf0e5SJed Brown ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr); 104861b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 10492aa6d131SJed Brown ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,ManSection(man));CHKERRQ(ierr); 105053acd3b1SBarry Smith } 105153acd3b1SBarry Smith PetscFunctionReturn(0); 105253acd3b1SBarry Smith } 105353acd3b1SBarry Smith 105453acd3b1SBarry Smith #undef __FUNCT__ 1055acfcf0e5SJed Brown #define __FUNCT__ "PetscOptionsBoolGroupEnd" 105653acd3b1SBarry Smith /*@C 1057acfcf0e5SJed Brown PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for 1058d5649816SBarry Smith which at most a single value can be true. 105953acd3b1SBarry Smith 10603f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 106153acd3b1SBarry Smith 106253acd3b1SBarry Smith Input Parameters: 106353acd3b1SBarry Smith + opt - option name 106453acd3b1SBarry Smith . text - short string that describes the option 106553acd3b1SBarry Smith - man - manual page with additional information on option 106653acd3b1SBarry Smith 106753acd3b1SBarry Smith Output Parameter: 106853acd3b1SBarry Smith . flg - PETSC_TRUE if found, else PETSC_FALSE 106953acd3b1SBarry Smith 107053acd3b1SBarry Smith Level: intermediate 107153acd3b1SBarry Smith 107253acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 107353acd3b1SBarry Smith 1074acfcf0e5SJed Brown Must follow a PetscOptionsBoolGroupBegin() 107553acd3b1SBarry Smith 107653acd3b1SBarry Smith Concepts: options database^logical group 107753acd3b1SBarry Smith 107853acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1079acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 108053acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 108153acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1082acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 108353acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 108453acd3b1SBarry Smith @*/ 1085acfcf0e5SJed Brown PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsBoolGroupEnd(const char opt[],const char text[],const char man[],PetscBool *flg) 108653acd3b1SBarry Smith { 108753acd3b1SBarry Smith PetscErrorCode ierr; 10881ae3d29cSBarry Smith PetscOptions amsopt; 108953acd3b1SBarry Smith 109053acd3b1SBarry Smith PetscFunctionBegin; 10911ae3d29cSBarry Smith if (!PetscOptionsPublishCount) { 10921ae3d29cSBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr); 1093ace3abfcSBarry Smith ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1094ace3abfcSBarry Smith *(PetscBool*)amsopt->data = PETSC_FALSE; 10951ae3d29cSBarry Smith } 109617326d04SJed Brown *flg = PETSC_FALSE; 1097acfcf0e5SJed Brown ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr); 109861b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 10992aa6d131SJed Brown ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,ManSection(man));CHKERRQ(ierr); 110053acd3b1SBarry Smith } 110153acd3b1SBarry Smith PetscFunctionReturn(0); 110253acd3b1SBarry Smith } 110353acd3b1SBarry Smith 110453acd3b1SBarry Smith #undef __FUNCT__ 1105acfcf0e5SJed Brown #define __FUNCT__ "PetscOptionsBool" 110653acd3b1SBarry Smith /*@C 1107acfcf0e5SJed Brown PetscOptionsBool - Determines if a particular option is in the database with a true or false 110853acd3b1SBarry Smith 11093f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 111053acd3b1SBarry Smith 111153acd3b1SBarry Smith Input Parameters: 111253acd3b1SBarry Smith + opt - option name 111353acd3b1SBarry Smith . text - short string that describes the option 111453acd3b1SBarry Smith - man - manual page with additional information on option 111553acd3b1SBarry Smith 111653acd3b1SBarry Smith Output Parameter: 111753acd3b1SBarry Smith . flg - PETSC_TRUE or PETSC_FALSE 111853acd3b1SBarry Smith . set - PETSC_TRUE if found, else PETSC_FALSE 111953acd3b1SBarry Smith 112053acd3b1SBarry Smith Level: beginner 112153acd3b1SBarry Smith 112253acd3b1SBarry Smith Concepts: options database^logical 112353acd3b1SBarry Smith 112453acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 112553acd3b1SBarry Smith 112653acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 1127acfcf0e5SJed Brown PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 1128acfcf0e5SJed Brown PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 112953acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 113053acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1131acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 113253acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 113353acd3b1SBarry Smith @*/ 1134acfcf0e5SJed Brown PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsBool(const char opt[],const char text[],const char man[],PetscBool deflt,PetscBool *flg,PetscBool *set) 113553acd3b1SBarry Smith { 113653acd3b1SBarry Smith PetscErrorCode ierr; 1137ace3abfcSBarry Smith PetscBool iset; 1138aee2cecaSBarry Smith PetscOptions amsopt; 113953acd3b1SBarry Smith 114053acd3b1SBarry Smith PetscFunctionBegin; 1141b3506946SBarry Smith if (!PetscOptionsPublishCount) { 1142aee2cecaSBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr); 1143ace3abfcSBarry Smith ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1144ace3abfcSBarry Smith *(PetscBool*)amsopt->data = deflt; 1145af6d86caSBarry Smith } 1146acfcf0e5SJed Brown ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,&iset);CHKERRQ(ierr); 114753acd3b1SBarry Smith if (!iset) { 114853acd3b1SBarry Smith if (flg) *flg = deflt; 114953acd3b1SBarry Smith } 115053acd3b1SBarry Smith if (set) *set = iset; 115161b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1152ace3abfcSBarry Smith const char *v = PetscBools[deflt]; 11532aa6d131SJed Brown ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s: <%s> %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,v,text,ManSection(man));CHKERRQ(ierr); 115453acd3b1SBarry Smith } 115553acd3b1SBarry Smith PetscFunctionReturn(0); 115653acd3b1SBarry Smith } 115753acd3b1SBarry Smith 115853acd3b1SBarry Smith #undef __FUNCT__ 115953acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsRealArray" 116053acd3b1SBarry Smith /*@C 116153acd3b1SBarry Smith PetscOptionsRealArray - Gets an array of double values for a particular 116253acd3b1SBarry Smith option in the database. The values must be separated with commas with 116353acd3b1SBarry Smith no intervening spaces. 116453acd3b1SBarry Smith 11653f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 116653acd3b1SBarry Smith 116753acd3b1SBarry Smith Input Parameters: 116853acd3b1SBarry Smith + opt - the option one is seeking 116953acd3b1SBarry Smith . text - short string describing option 117053acd3b1SBarry Smith . man - manual page for option 117153acd3b1SBarry Smith - nmax - maximum number of values 117253acd3b1SBarry Smith 117353acd3b1SBarry Smith Output Parameter: 117453acd3b1SBarry Smith + value - location to copy values 117553acd3b1SBarry Smith . nmax - actual number of values found 117653acd3b1SBarry Smith - set - PETSC_TRUE if found, else PETSC_FALSE 117753acd3b1SBarry Smith 117853acd3b1SBarry Smith Level: beginner 117953acd3b1SBarry Smith 118053acd3b1SBarry Smith Notes: 118153acd3b1SBarry Smith The user should pass in an array of doubles 118253acd3b1SBarry Smith 118353acd3b1SBarry Smith Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 118453acd3b1SBarry Smith 118553acd3b1SBarry Smith Concepts: options database^array of strings 118653acd3b1SBarry Smith 118753acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1188acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 118953acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 119053acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1191acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 119253acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 119353acd3b1SBarry Smith @*/ 1194ace3abfcSBarry Smith PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool *set) 119553acd3b1SBarry Smith { 119653acd3b1SBarry Smith PetscErrorCode ierr; 119753acd3b1SBarry Smith PetscInt i; 1198e26ddf31SBarry Smith PetscOptions amsopt; 119953acd3b1SBarry Smith 120053acd3b1SBarry Smith PetscFunctionBegin; 1201b3506946SBarry Smith if (!PetscOptionsPublishCount) { 1202e26ddf31SBarry Smith PetscReal *vals; 1203e26ddf31SBarry Smith 1204e26ddf31SBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr); 1205e26ddf31SBarry Smith ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr); 1206e26ddf31SBarry Smith vals = (PetscReal*)amsopt->data; 1207e26ddf31SBarry Smith for (i=0; i<*n; i++) vals[i] = value[i]; 1208e26ddf31SBarry Smith amsopt->arraylength = *n; 1209e26ddf31SBarry Smith } 121053acd3b1SBarry Smith ierr = PetscOptionsGetRealArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr); 121161b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1212a83599f4SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%G",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr); 121353acd3b1SBarry Smith for (i=1; i<*n; i++) { 1214a83599f4SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%G",value[i]);CHKERRQ(ierr); 121553acd3b1SBarry Smith } 12162aa6d131SJed Brown ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 121753acd3b1SBarry Smith } 121853acd3b1SBarry Smith PetscFunctionReturn(0); 121953acd3b1SBarry Smith } 122053acd3b1SBarry Smith 122153acd3b1SBarry Smith 122253acd3b1SBarry Smith #undef __FUNCT__ 122353acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsIntArray" 122453acd3b1SBarry Smith /*@C 122553acd3b1SBarry Smith PetscOptionsIntArray - Gets an array of integers for a particular 122653acd3b1SBarry Smith option in the database. The values must be separated with commas with 122753acd3b1SBarry Smith no intervening spaces. 122853acd3b1SBarry Smith 12293f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 123053acd3b1SBarry Smith 123153acd3b1SBarry Smith Input Parameters: 123253acd3b1SBarry Smith + opt - the option one is seeking 123353acd3b1SBarry Smith . text - short string describing option 123453acd3b1SBarry Smith . man - manual page for option 1235f8a50e2bSBarry Smith - n - maximum number of values 123653acd3b1SBarry Smith 123753acd3b1SBarry Smith Output Parameter: 123853acd3b1SBarry Smith + value - location to copy values 1239f8a50e2bSBarry Smith . n - actual number of values found 124053acd3b1SBarry Smith - set - PETSC_TRUE if found, else PETSC_FALSE 124153acd3b1SBarry Smith 124253acd3b1SBarry Smith Level: beginner 124353acd3b1SBarry Smith 124453acd3b1SBarry Smith Notes: 124553acd3b1SBarry Smith The user should pass in an array of integers 124653acd3b1SBarry Smith 124753acd3b1SBarry Smith Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 124853acd3b1SBarry Smith 124953acd3b1SBarry Smith Concepts: options database^array of strings 125053acd3b1SBarry Smith 125153acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1252acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 125353acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 125453acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1255acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 125653acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList(), PetscOptionsRealArray() 125753acd3b1SBarry Smith @*/ 1258ace3abfcSBarry Smith PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool *set) 125953acd3b1SBarry Smith { 126053acd3b1SBarry Smith PetscErrorCode ierr; 126153acd3b1SBarry Smith PetscInt i; 1262e26ddf31SBarry Smith PetscOptions amsopt; 126353acd3b1SBarry Smith 126453acd3b1SBarry Smith PetscFunctionBegin; 1265b3506946SBarry Smith if (!PetscOptionsPublishCount) { 1266e26ddf31SBarry Smith PetscInt *vals; 1267e26ddf31SBarry Smith 1268e26ddf31SBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr); 1269e26ddf31SBarry Smith ierr = PetscMalloc((*n)*sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr); 1270e26ddf31SBarry Smith vals = (PetscInt*)amsopt->data; 1271e26ddf31SBarry Smith for (i=0; i<*n; i++) vals[i] = value[i]; 1272e26ddf31SBarry Smith amsopt->arraylength = *n; 1273e26ddf31SBarry Smith } 127453acd3b1SBarry Smith ierr = PetscOptionsGetIntArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr); 127561b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 127653acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr); 127753acd3b1SBarry Smith for (i=1; i<*n; i++) { 127853acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr); 127953acd3b1SBarry Smith } 12802aa6d131SJed Brown ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 128153acd3b1SBarry Smith } 128253acd3b1SBarry Smith PetscFunctionReturn(0); 128353acd3b1SBarry Smith } 128453acd3b1SBarry Smith 128553acd3b1SBarry Smith #undef __FUNCT__ 128653acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsStringArray" 128753acd3b1SBarry Smith /*@C 128853acd3b1SBarry Smith PetscOptionsStringArray - Gets an array of string values for a particular 128953acd3b1SBarry Smith option in the database. The values must be separated with commas with 129053acd3b1SBarry Smith no intervening spaces. 129153acd3b1SBarry Smith 12923f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 129353acd3b1SBarry Smith 129453acd3b1SBarry Smith Input Parameters: 129553acd3b1SBarry Smith + opt - the option one is seeking 129653acd3b1SBarry Smith . text - short string describing option 129753acd3b1SBarry Smith . man - manual page for option 129853acd3b1SBarry Smith - nmax - maximum number of strings 129953acd3b1SBarry Smith 130053acd3b1SBarry Smith Output Parameter: 130153acd3b1SBarry Smith + value - location to copy strings 130253acd3b1SBarry Smith . nmax - actual number of strings found 130353acd3b1SBarry Smith - set - PETSC_TRUE if found, else PETSC_FALSE 130453acd3b1SBarry Smith 130553acd3b1SBarry Smith Level: beginner 130653acd3b1SBarry Smith 130753acd3b1SBarry Smith Notes: 130853acd3b1SBarry Smith The user should pass in an array of pointers to char, to hold all the 130953acd3b1SBarry Smith strings returned by this function. 131053acd3b1SBarry Smith 131153acd3b1SBarry Smith The user is responsible for deallocating the strings that are 131253acd3b1SBarry Smith returned. The Fortran interface for this routine is not supported. 131353acd3b1SBarry Smith 131453acd3b1SBarry Smith Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 131553acd3b1SBarry Smith 131653acd3b1SBarry Smith Concepts: options database^array of strings 131753acd3b1SBarry Smith 131853acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1319acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 132053acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 132153acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1322acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 132353acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 132453acd3b1SBarry Smith @*/ 1325ace3abfcSBarry Smith PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool *set) 132653acd3b1SBarry Smith { 132753acd3b1SBarry Smith PetscErrorCode ierr; 13281ae3d29cSBarry Smith PetscOptions amsopt; 132953acd3b1SBarry Smith 133053acd3b1SBarry Smith PetscFunctionBegin; 13311ae3d29cSBarry Smith if (!PetscOptionsPublishCount) { 13321ae3d29cSBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING_ARRAY,&amsopt);CHKERRQ(ierr); 13331ae3d29cSBarry Smith ierr = PetscMalloc((*nmax)*sizeof(char*),&amsopt->data);CHKERRQ(ierr); 13341ae3d29cSBarry Smith amsopt->arraylength = *nmax; 13351ae3d29cSBarry Smith } 133653acd3b1SBarry Smith ierr = PetscOptionsGetStringArray(PetscOptionsObject.prefix,opt,value,nmax,set);CHKERRQ(ierr); 133761b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 13382aa6d131SJed Brown ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,ManSection(man));CHKERRQ(ierr); 133953acd3b1SBarry Smith } 134053acd3b1SBarry Smith PetscFunctionReturn(0); 134153acd3b1SBarry Smith } 134253acd3b1SBarry Smith 1343e2446a98SMatthew Knepley #undef __FUNCT__ 1344acfcf0e5SJed Brown #define __FUNCT__ "PetscOptionsBoolArray" 1345e2446a98SMatthew Knepley /*@C 1346acfcf0e5SJed Brown PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular 1347e2446a98SMatthew Knepley option in the database. The values must be separated with commas with 1348e2446a98SMatthew Knepley no intervening spaces. 1349e2446a98SMatthew Knepley 13503f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 1351e2446a98SMatthew Knepley 1352e2446a98SMatthew Knepley Input Parameters: 1353e2446a98SMatthew Knepley + opt - the option one is seeking 1354e2446a98SMatthew Knepley . text - short string describing option 1355e2446a98SMatthew Knepley . man - manual page for option 1356e2446a98SMatthew Knepley - nmax - maximum number of values 1357e2446a98SMatthew Knepley 1358e2446a98SMatthew Knepley Output Parameter: 1359e2446a98SMatthew Knepley + value - location to copy values 1360e2446a98SMatthew Knepley . nmax - actual number of values found 1361e2446a98SMatthew Knepley - set - PETSC_TRUE if found, else PETSC_FALSE 1362e2446a98SMatthew Knepley 1363e2446a98SMatthew Knepley Level: beginner 1364e2446a98SMatthew Knepley 1365e2446a98SMatthew Knepley Notes: 1366e2446a98SMatthew Knepley The user should pass in an array of doubles 1367e2446a98SMatthew Knepley 1368e2446a98SMatthew Knepley Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1369e2446a98SMatthew Knepley 1370e2446a98SMatthew Knepley Concepts: options database^array of strings 1371e2446a98SMatthew Knepley 1372e2446a98SMatthew Knepley .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1373acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1374e2446a98SMatthew Knepley PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1375e2446a98SMatthew Knepley PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1376acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1377e2446a98SMatthew Knepley PetscOptionsList(), PetscOptionsEList() 1378e2446a98SMatthew Knepley @*/ 1379acfcf0e5SJed Brown PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsBoolArray(const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set) 1380e2446a98SMatthew Knepley { 1381e2446a98SMatthew Knepley PetscErrorCode ierr; 1382e2446a98SMatthew Knepley PetscInt i; 13831ae3d29cSBarry Smith PetscOptions amsopt; 1384e2446a98SMatthew Knepley 1385e2446a98SMatthew Knepley PetscFunctionBegin; 13861ae3d29cSBarry Smith if (!PetscOptionsPublishCount) { 1387ace3abfcSBarry Smith PetscBool *vals; 13881ae3d29cSBarry Smith 13891ae3d29cSBarry Smith ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL_ARRAY,&amsopt);CHKERRQ(ierr); 1390ace3abfcSBarry Smith ierr = PetscMalloc((*n)*sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1391ace3abfcSBarry Smith vals = (PetscBool*)amsopt->data; 13921ae3d29cSBarry Smith for (i=0; i<*n; i++) vals[i] = value[i]; 13931ae3d29cSBarry Smith amsopt->arraylength = *n; 13941ae3d29cSBarry Smith } 1395acfcf0e5SJed Brown ierr = PetscOptionsGetBoolArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr); 1396e2446a98SMatthew Knepley if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 1397e2446a98SMatthew Knepley ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr); 1398e2446a98SMatthew Knepley for (i=1; i<*n; i++) { 1399e2446a98SMatthew Knepley ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr); 1400e2446a98SMatthew Knepley } 14012aa6d131SJed Brown ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1402e2446a98SMatthew Knepley } 1403e2446a98SMatthew Knepley PetscFunctionReturn(0); 1404e2446a98SMatthew Knepley } 1405e2446a98SMatthew Knepley 140653acd3b1SBarry Smith 140753acd3b1SBarry Smith #undef __FUNCT__ 140853acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsHead" 140953acd3b1SBarry Smith /*@C 1410b52f573bSBarry Smith PetscOptionsHead - Puts a heading before listing any more published options. Used, for example, 141153acd3b1SBarry Smith in KSPSetFromOptions_GMRES(). 141253acd3b1SBarry Smith 14133f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 141453acd3b1SBarry Smith 141553acd3b1SBarry Smith Input Parameter: 141653acd3b1SBarry Smith . head - the heading text 141753acd3b1SBarry Smith 141853acd3b1SBarry Smith 141953acd3b1SBarry Smith Level: intermediate 142053acd3b1SBarry Smith 142153acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 142253acd3b1SBarry Smith 1423b52f573bSBarry Smith Can be followed by a call to PetscOptionsTail() in the same function. 142453acd3b1SBarry Smith 142553acd3b1SBarry Smith Concepts: options database^subheading 142653acd3b1SBarry Smith 142753acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1428acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 142953acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 143053acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1431acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 143253acd3b1SBarry Smith PetscOptionsList(), PetscOptionsEList() 143353acd3b1SBarry Smith @*/ 14348738c821SJed Brown PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsHead(const char head[]) 143553acd3b1SBarry Smith { 143653acd3b1SBarry Smith PetscErrorCode ierr; 143753acd3b1SBarry Smith 143853acd3b1SBarry Smith PetscFunctionBegin; 143961b37b28SSatish Balay if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) { 144053acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s\n",head);CHKERRQ(ierr); 144153acd3b1SBarry Smith } 144253acd3b1SBarry Smith PetscFunctionReturn(0); 144353acd3b1SBarry Smith } 144453acd3b1SBarry Smith 144553acd3b1SBarry Smith 144653acd3b1SBarry Smith 144753acd3b1SBarry Smith 144853acd3b1SBarry Smith 144953acd3b1SBarry Smith 1450