17d0a6c19SBarry Smith 21a1499c8SBarry Smith 353acd3b1SBarry Smith /* 43fc1eb6aSBarry Smith Implements the higher-level options database querying methods. These are self-documenting and can attach at runtime to 53fc1eb6aSBarry Smith GUI code to display the options and get values from the users. 653acd3b1SBarry Smith 753acd3b1SBarry Smith */ 853acd3b1SBarry Smith 9afcb2eb5SJed Brown #include <petsc-private/petscimpl.h> /*I "petscsys.h" I*/ 10665c2dedSJed Brown #include <petscviewer.h> 1153acd3b1SBarry Smith 122aa6d131SJed Brown #define ManSection(str) ((str) ? (str) : "None") 132aa6d131SJed Brown 1453acd3b1SBarry Smith /* 1553acd3b1SBarry Smith Keep a linked list of options that have been posted and we are waiting for 163fc1eb6aSBarry Smith user selection. See the manual page for PetscOptionsBegin() 1753acd3b1SBarry Smith 1853acd3b1SBarry Smith Eventually we'll attach this beast to a MPI_Comm 1953acd3b1SBarry Smith */ 20e55864a3SBarry Smith 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 */ 278c34d3f5SBarry Smith PetscErrorCode PetscOptionsBegin_Private(PetscOptions *PetscOptionsObject,MPI_Comm comm,const char prefix[],const char title[],const char mansec[]) 2853acd3b1SBarry Smith { 2953acd3b1SBarry Smith PetscErrorCode ierr; 3053acd3b1SBarry Smith 3153acd3b1SBarry Smith PetscFunctionBegin; 32e55864a3SBarry Smith PetscOptionsObject->next = 0; 33e55864a3SBarry Smith PetscOptionsObject->comm = comm; 34e55864a3SBarry Smith PetscOptionsObject->changedmethod = PETSC_FALSE; 35a297a907SKarl Rupp 36e55864a3SBarry Smith ierr = PetscStrallocpy(prefix,&PetscOptionsObject->prefix);CHKERRQ(ierr); 37e55864a3SBarry Smith ierr = PetscStrallocpy(title,&PetscOptionsObject->title);CHKERRQ(ierr); 3853acd3b1SBarry Smith 39e55864a3SBarry Smith ierr = PetscOptionsHasName(NULL,"-help",&PetscOptionsObject->printhelp);CHKERRQ(ierr); 40e55864a3SBarry Smith if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1) { 41e55864a3SBarry Smith if (!PetscOptionsObject->alreadyprinted) { 4253acd3b1SBarry Smith ierr = (*PetscHelpPrintf)(comm,"%s -------------------------------------------------\n",title);CHKERRQ(ierr); 4353acd3b1SBarry Smith } 4461b37b28SSatish Balay } 4553acd3b1SBarry Smith PetscFunctionReturn(0); 4653acd3b1SBarry Smith } 4753acd3b1SBarry Smith 483194b578SJed Brown #undef __FUNCT__ 493194b578SJed Brown #define __FUNCT__ "PetscObjectOptionsBegin_Private" 503194b578SJed Brown /* 513194b578SJed Brown Handles setting up the data structure in a call to PetscObjectOptionsBegin() 523194b578SJed Brown */ 538c34d3f5SBarry Smith PetscErrorCode PetscObjectOptionsBegin_Private(PetscOptions *PetscOptionsObject,PetscObject obj) 543194b578SJed Brown { 553194b578SJed Brown PetscErrorCode ierr; 563194b578SJed Brown char title[256]; 573194b578SJed Brown PetscBool flg; 583194b578SJed Brown 593194b578SJed Brown PetscFunctionBegin; 603194b578SJed Brown PetscValidHeader(obj,1); 61e55864a3SBarry Smith PetscOptionsObject->object = obj; 62e55864a3SBarry Smith PetscOptionsObject->alreadyprinted = obj->optionsprinted; 63a297a907SKarl Rupp 643194b578SJed Brown ierr = PetscStrcmp(obj->description,obj->class_name,&flg);CHKERRQ(ierr); 653194b578SJed Brown if (flg) { 668caf3d72SBarry Smith ierr = PetscSNPrintf(title,sizeof(title),"%s options",obj->class_name);CHKERRQ(ierr); 673194b578SJed Brown } else { 688caf3d72SBarry Smith ierr = PetscSNPrintf(title,sizeof(title),"%s (%s) options",obj->description,obj->class_name);CHKERRQ(ierr); 693194b578SJed Brown } 70e55864a3SBarry Smith ierr = PetscOptionsBegin_Private(PetscOptionsObject,obj->comm,obj->prefix,title,obj->mansec);CHKERRQ(ierr); 713194b578SJed Brown PetscFunctionReturn(0); 723194b578SJed Brown } 733194b578SJed Brown 7453acd3b1SBarry Smith /* 7553acd3b1SBarry Smith Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd() 7653acd3b1SBarry Smith */ 7753acd3b1SBarry Smith #undef __FUNCT__ 7853acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsCreate_Private" 798c34d3f5SBarry Smith static int PetscOptionsCreate_Private(PetscOptions *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscOptionType t,PetscOption *amsopt) 8053acd3b1SBarry Smith { 8153acd3b1SBarry Smith int ierr; 828c34d3f5SBarry Smith PetscOption next; 833be6e4c3SJed Brown PetscBool valid; 8453acd3b1SBarry Smith 8553acd3b1SBarry Smith PetscFunctionBegin; 863be6e4c3SJed Brown ierr = PetscOptionsValidKey(opt,&valid);CHKERRQ(ierr); 873be6e4c3SJed Brown if (!valid) SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_ARG_INCOMP,"The option '%s' is not a valid key",opt); 883be6e4c3SJed Brown 89b00a9115SJed Brown ierr = PetscNew(amsopt);CHKERRQ(ierr); 9053acd3b1SBarry Smith (*amsopt)->next = 0; 9153acd3b1SBarry Smith (*amsopt)->set = PETSC_FALSE; 926356e834SBarry Smith (*amsopt)->type = t; 9353acd3b1SBarry Smith (*amsopt)->data = 0; 9461b37b28SSatish Balay 9553acd3b1SBarry Smith ierr = PetscStrallocpy(text,&(*amsopt)->text);CHKERRQ(ierr); 9653acd3b1SBarry Smith ierr = PetscStrallocpy(opt,&(*amsopt)->option);CHKERRQ(ierr); 976356e834SBarry Smith ierr = PetscStrallocpy(man,&(*amsopt)->man);CHKERRQ(ierr); 9853acd3b1SBarry Smith 99e55864a3SBarry Smith if (!PetscOptionsObject->next) PetscOptionsObject->next = *amsopt; 100a297a907SKarl Rupp else { 101e55864a3SBarry Smith next = PetscOptionsObject->next; 10253acd3b1SBarry Smith while (next->next) next = next->next; 10353acd3b1SBarry Smith next->next = *amsopt; 10453acd3b1SBarry Smith } 10553acd3b1SBarry Smith PetscFunctionReturn(0); 10653acd3b1SBarry Smith } 10753acd3b1SBarry Smith 10853acd3b1SBarry Smith #undef __FUNCT__ 109aee2cecaSBarry Smith #define __FUNCT__ "PetscScanString" 110aee2cecaSBarry Smith /* 1113fc1eb6aSBarry Smith PetscScanString - Gets user input via stdin from process and broadcasts to all processes 1123fc1eb6aSBarry Smith 1133fc1eb6aSBarry Smith Collective on MPI_Comm 1143fc1eb6aSBarry Smith 1153fc1eb6aSBarry Smith Input Parameters: 1163fc1eb6aSBarry Smith + commm - communicator for the broadcast, must be PETSC_COMM_WORLD 1173fc1eb6aSBarry Smith . n - length of the string, must be the same on all processes 1183fc1eb6aSBarry Smith - str - location to store input 119aee2cecaSBarry Smith 120aee2cecaSBarry Smith Bugs: 121aee2cecaSBarry Smith . Assumes process 0 of the given communicator has access to stdin 122aee2cecaSBarry Smith 123aee2cecaSBarry Smith */ 1243fc1eb6aSBarry Smith static PetscErrorCode PetscScanString(MPI_Comm comm,size_t n,char str[]) 125aee2cecaSBarry Smith { 126330cf3c9SBarry Smith size_t i; 127aee2cecaSBarry Smith char c; 1283fc1eb6aSBarry Smith PetscMPIInt rank,nm; 129aee2cecaSBarry Smith PetscErrorCode ierr; 130aee2cecaSBarry Smith 131aee2cecaSBarry Smith PetscFunctionBegin; 132aee2cecaSBarry Smith ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); 133aee2cecaSBarry Smith if (!rank) { 134aee2cecaSBarry Smith c = (char) getchar(); 135aee2cecaSBarry Smith i = 0; 136aee2cecaSBarry Smith while (c != '\n' && i < n-1) { 137aee2cecaSBarry Smith str[i++] = c; 138aee2cecaSBarry Smith c = (char)getchar(); 139aee2cecaSBarry Smith } 140aee2cecaSBarry Smith str[i] = 0; 141aee2cecaSBarry Smith } 1424dc2109aSBarry Smith ierr = PetscMPIIntCast(n,&nm);CHKERRQ(ierr); 1433fc1eb6aSBarry Smith ierr = MPI_Bcast(str,nm,MPI_CHAR,0,comm);CHKERRQ(ierr); 144aee2cecaSBarry Smith PetscFunctionReturn(0); 145aee2cecaSBarry Smith } 146aee2cecaSBarry Smith 147ead66b60SBarry Smith #undef __FUNCT__ 148ead66b60SBarry Smith #define __FUNCT__ "PetscStrdup" 1495b02f95dSBarry Smith /* 1505b02f95dSBarry Smith This is needed because certain strings may be freed by SAWs, hence we cannot use PetscStrallocpy() 1515b02f95dSBarry Smith */ 1525b02f95dSBarry Smith static PetscErrorCode PetscStrdup(const char s[],char *t[]) 1535b02f95dSBarry Smith { 1545b02f95dSBarry Smith PetscErrorCode ierr; 1555b02f95dSBarry Smith size_t len; 1565b02f95dSBarry Smith char *tmp = 0; 1575b02f95dSBarry Smith 1585b02f95dSBarry Smith PetscFunctionBegin; 1595b02f95dSBarry Smith if (s) { 1605b02f95dSBarry Smith ierr = PetscStrlen(s,&len);CHKERRQ(ierr); 161ee48884fSBarry Smith tmp = (char*) malloc((len+1)*sizeof(char*)); 1625b02f95dSBarry Smith if (!tmp) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_MEM,"No memory to duplicate string"); 1635b02f95dSBarry Smith ierr = PetscStrcpy(tmp,s);CHKERRQ(ierr); 1645b02f95dSBarry Smith } 1655b02f95dSBarry Smith *t = tmp; 1665b02f95dSBarry Smith PetscFunctionReturn(0); 1675b02f95dSBarry Smith } 1685b02f95dSBarry Smith 1695b02f95dSBarry Smith 170aee2cecaSBarry Smith #undef __FUNCT__ 171aee2cecaSBarry Smith #define __FUNCT__ "PetscOptionsGetFromTextInput" 172aee2cecaSBarry Smith /* 1733cc1e11dSBarry Smith PetscOptionsGetFromTextInput - Presents all the PETSc Options processed by the program so the user may change them at runtime 174aee2cecaSBarry Smith 175aee2cecaSBarry Smith Notes: this isn't really practical, it is just to demonstrate the principle 176aee2cecaSBarry Smith 1777781c08eSBarry Smith A carriage return indicates no change from the default; but this like -ksp_monitor <stdout> the default is actually not stdout the default 1787781c08eSBarry Smith is to do nothing so to get it to use stdout you need to type stdout. This is kind of bug? 1797781c08eSBarry Smith 180aee2cecaSBarry Smith Bugs: 1817781c08eSBarry Smith + All processes must traverse through the exact same set of option queries due to the call to PetscScanString() 1823cc1e11dSBarry Smith . Internal strings have arbitrary length and string copies are not checked that they fit into string space 183aee2cecaSBarry Smith - Only works for PetscInt == int, PetscReal == double etc 184aee2cecaSBarry Smith 1853cc1e11dSBarry Smith Developer Notes: Normally the GUI that presents the options the user and retrieves the values would be running in a different 1863cc1e11dSBarry Smith address space and communicating with the PETSc program 1873cc1e11dSBarry Smith 188aee2cecaSBarry Smith */ 1898c34d3f5SBarry Smith PetscErrorCode PetscOptionsGetFromTextInput(PetscOptions *PetscOptionsObject) 1906356e834SBarry Smith { 1916356e834SBarry Smith PetscErrorCode ierr; 1928c34d3f5SBarry Smith PetscOption next = PetscOptionsObject->next; 1936356e834SBarry Smith char str[512]; 1947781c08eSBarry Smith PetscBool bid; 195a4404d99SBarry Smith PetscReal ir,*valr; 196330cf3c9SBarry Smith PetscInt *vald; 197330cf3c9SBarry Smith size_t i; 1986356e834SBarry Smith 199e55864a3SBarry Smith ierr = (*PetscPrintf)(PETSC_COMM_WORLD,"%s -------------------------------------------------\n",PetscOptionsObject->title);CHKERRQ(ierr); 2006356e834SBarry Smith while (next) { 2016356e834SBarry Smith switch (next->type) { 2026356e834SBarry Smith case OPTION_HEAD: 2036356e834SBarry Smith break; 204e26ddf31SBarry Smith case OPTION_INT_ARRAY: 205e55864a3SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1);CHKERRQ(ierr); 206e26ddf31SBarry Smith vald = (PetscInt*) next->data; 207e26ddf31SBarry Smith for (i=0; i<next->arraylength; i++) { 208e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,"%d",vald[i]);CHKERRQ(ierr); 209e26ddf31SBarry Smith if (i < next->arraylength-1) { 210e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr); 211e26ddf31SBarry Smith } 212e26ddf31SBarry Smith } 213e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s) ",next->text,next->man);CHKERRQ(ierr); 214e26ddf31SBarry Smith ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 215e26ddf31SBarry Smith if (str[0]) { 216e26ddf31SBarry Smith PetscToken token; 217e26ddf31SBarry Smith PetscInt n=0,nmax = next->arraylength,*dvalue = (PetscInt*)next->data,start,end; 218e26ddf31SBarry Smith size_t len; 219e26ddf31SBarry Smith char *value; 220ace3abfcSBarry Smith PetscBool foundrange; 221e26ddf31SBarry Smith 222e26ddf31SBarry Smith next->set = PETSC_TRUE; 223e26ddf31SBarry Smith value = str; 224e26ddf31SBarry Smith ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 225e26ddf31SBarry Smith ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 226e26ddf31SBarry Smith while (n < nmax) { 227e26ddf31SBarry Smith if (!value) break; 228e26ddf31SBarry Smith 229e26ddf31SBarry Smith /* look for form d-D where d and D are integers */ 230e26ddf31SBarry Smith foundrange = PETSC_FALSE; 231e26ddf31SBarry Smith ierr = PetscStrlen(value,&len);CHKERRQ(ierr); 232e26ddf31SBarry Smith if (value[0] == '-') i=2; 233e26ddf31SBarry Smith else i=1; 234330cf3c9SBarry Smith for (;i<len; i++) { 235e26ddf31SBarry Smith if (value[i] == '-') { 236e32f2f54SBarry Smith if (i == len-1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry %s\n",n,value); 237e26ddf31SBarry Smith value[i] = 0; 238cfbddea1SSatish Balay ierr = PetscOptionsStringToInt(value,&start);CHKERRQ(ierr); 239cfbddea1SSatish Balay ierr = PetscOptionsStringToInt(value+i+1,&end);CHKERRQ(ierr); 240e32f2f54SBarry 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); 241e32f2f54SBarry 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); 242e26ddf31SBarry Smith for (; start<end; start++) { 243e26ddf31SBarry Smith *dvalue = start; dvalue++;n++; 244e26ddf31SBarry Smith } 245e26ddf31SBarry Smith foundrange = PETSC_TRUE; 246e26ddf31SBarry Smith break; 247e26ddf31SBarry Smith } 248e26ddf31SBarry Smith } 249e26ddf31SBarry Smith if (!foundrange) { 250cfbddea1SSatish Balay ierr = PetscOptionsStringToInt(value,dvalue);CHKERRQ(ierr); 251e26ddf31SBarry Smith dvalue++; 252e26ddf31SBarry Smith n++; 253e26ddf31SBarry Smith } 254e26ddf31SBarry Smith ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 255e26ddf31SBarry Smith } 2568c74ee41SBarry Smith ierr = PetscTokenDestroy(&token);CHKERRQ(ierr); 257e26ddf31SBarry Smith } 258e26ddf31SBarry Smith break; 259e26ddf31SBarry Smith case OPTION_REAL_ARRAY: 260e55864a3SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1);CHKERRQ(ierr); 261e26ddf31SBarry Smith valr = (PetscReal*) next->data; 262e26ddf31SBarry Smith for (i=0; i<next->arraylength; i++) { 263e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,"%g",valr[i]);CHKERRQ(ierr); 264e26ddf31SBarry Smith if (i < next->arraylength-1) { 265e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr); 266e26ddf31SBarry Smith } 267e26ddf31SBarry Smith } 268e26ddf31SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s) ",next->text,next->man);CHKERRQ(ierr); 269e26ddf31SBarry Smith ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 270e26ddf31SBarry Smith if (str[0]) { 271e26ddf31SBarry Smith PetscToken token; 272e26ddf31SBarry Smith PetscInt n = 0,nmax = next->arraylength; 273e26ddf31SBarry Smith PetscReal *dvalue = (PetscReal*)next->data; 274e26ddf31SBarry Smith char *value; 275e26ddf31SBarry Smith 276e26ddf31SBarry Smith next->set = PETSC_TRUE; 277e26ddf31SBarry Smith value = str; 278e26ddf31SBarry Smith ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 279e26ddf31SBarry Smith ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 280e26ddf31SBarry Smith while (n < nmax) { 281e26ddf31SBarry Smith if (!value) break; 282cfbddea1SSatish Balay ierr = PetscOptionsStringToReal(value,dvalue);CHKERRQ(ierr); 283e26ddf31SBarry Smith dvalue++; 284e26ddf31SBarry Smith n++; 285e26ddf31SBarry Smith ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 286e26ddf31SBarry Smith } 2878c74ee41SBarry Smith ierr = PetscTokenDestroy(&token);CHKERRQ(ierr); 288e26ddf31SBarry Smith } 289e26ddf31SBarry Smith break; 2906356e834SBarry Smith case OPTION_INT: 291e55864a3SBarry 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); 2923fc1eb6aSBarry Smith ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 2933fc1eb6aSBarry Smith if (str[0]) { 294d25d7f95SJed Brown #if defined(PETSC_SIZEOF_LONG_LONG) 295d25d7f95SJed Brown long long lid; 296d25d7f95SJed Brown sscanf(str,"%lld",&lid); 2971a1499c8SBarry Smith if (lid > PETSC_MAX_INT || lid < PETSC_MIN_INT) SETERRQ3(PETSC_COMM_WORLD,PETSC_ERR_ARG_OUTOFRANGE,"Argument: -%s%s %lld",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1,lid); 298c272547aSJed Brown #else 299d25d7f95SJed Brown long lid; 300d25d7f95SJed Brown sscanf(str,"%ld",&lid); 3011a1499c8SBarry Smith if (lid > PETSC_MAX_INT || lid < PETSC_MIN_INT) SETERRQ3(PETSC_COMM_WORLD,PETSC_ERR_ARG_OUTOFRANGE,"Argument: -%s%s %ld",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1,lid); 302c272547aSJed Brown #endif 303a297a907SKarl Rupp 304d25d7f95SJed Brown next->set = PETSC_TRUE; 305d25d7f95SJed Brown *((PetscInt*)next->data) = (PetscInt)lid; 306aee2cecaSBarry Smith } 307aee2cecaSBarry Smith break; 308aee2cecaSBarry Smith case OPTION_REAL: 309e55864a3SBarry 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); 3103fc1eb6aSBarry Smith ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 3113fc1eb6aSBarry Smith if (str[0]) { 312ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE) 313a4404d99SBarry Smith sscanf(str,"%e",&ir); 314ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE) 315aee2cecaSBarry Smith sscanf(str,"%le",&ir); 316ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128) 317d9822059SBarry Smith ir = strtoflt128(str,0); 318d9822059SBarry Smith #else 319513dbe71SLisandro Dalcin SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Unknown scalar type"); 320a4404d99SBarry Smith #endif 321aee2cecaSBarry Smith next->set = PETSC_TRUE; 322aee2cecaSBarry Smith *((PetscReal*)next->data) = ir; 323aee2cecaSBarry Smith } 324aee2cecaSBarry Smith break; 3257781c08eSBarry Smith case OPTION_BOOL: 32683355fc5SBarry Smith ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <%s>: %s (%s) ",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1,*(PetscBool*)next->data ? "true": "false",next->text,next->man);CHKERRQ(ierr); 3277781c08eSBarry Smith ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 3287781c08eSBarry Smith if (str[0]) { 3297781c08eSBarry Smith ierr = PetscOptionsStringToBool(str,&bid);CHKERRQ(ierr); 3307781c08eSBarry Smith next->set = PETSC_TRUE; 3317781c08eSBarry Smith *((PetscBool*)next->data) = bid; 3327781c08eSBarry Smith } 3337781c08eSBarry Smith break; 334aee2cecaSBarry Smith case OPTION_STRING: 335e55864a3SBarry 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); 3363fc1eb6aSBarry Smith ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 3373fc1eb6aSBarry Smith if (str[0]) { 338aee2cecaSBarry Smith next->set = PETSC_TRUE; 33964facd6cSBarry Smith /* must use system malloc since SAWs may free this */ 3405b02f95dSBarry Smith ierr = PetscStrdup(str,(char**)&next->data);CHKERRQ(ierr); 3416356e834SBarry Smith } 3426356e834SBarry Smith break; 343a264d7a6SBarry Smith case OPTION_FLIST: 344e55864a3SBarry Smith ierr = PetscFunctionListPrintTypes(PETSC_COMM_WORLD,stdout,PetscOptionsObject->prefix,next->option,next->text,next->man,next->flist,(char*)next->data);CHKERRQ(ierr); 3453cc1e11dSBarry Smith ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr); 3463cc1e11dSBarry Smith if (str[0]) { 347e55864a3SBarry Smith PetscOptionsObject->changedmethod = PETSC_TRUE; 3483cc1e11dSBarry Smith next->set = PETSC_TRUE; 34964facd6cSBarry Smith /* must use system malloc since SAWs may free this */ 3505b02f95dSBarry Smith ierr = PetscStrdup(str,(char**)&next->data);CHKERRQ(ierr); 3513cc1e11dSBarry Smith } 3523cc1e11dSBarry Smith break; 353b432afdaSMatthew Knepley default: 354b432afdaSMatthew Knepley break; 3556356e834SBarry Smith } 3566356e834SBarry Smith next = next->next; 3576356e834SBarry Smith } 3586356e834SBarry Smith PetscFunctionReturn(0); 3596356e834SBarry Smith } 3606356e834SBarry Smith 361e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 362e04113cfSBarry Smith #include <petscviewersaws.h> 363d5649816SBarry Smith 364d5649816SBarry Smith static int count = 0; 365d5649816SBarry Smith 366b3506946SBarry Smith #undef __FUNCT__ 367e04113cfSBarry Smith #define __FUNCT__ "PetscOptionsSAWsDestroy" 368e04113cfSBarry Smith PetscErrorCode PetscOptionsSAWsDestroy(void) 369d5649816SBarry Smith { 3702657e9d9SBarry Smith PetscFunctionBegin; 371d5649816SBarry Smith PetscFunctionReturn(0); 372d5649816SBarry Smith } 373d5649816SBarry Smith 3749c1e0ce8SBarry Smith static const char *OptionsHeader = "<head>\n" 37523a1ff79SBarry Smith "<script type=\"text/javascript\" src=\"http://www.mcs.anl.gov/research/projects/saws/js/jquery-1.9.1.js\"></script>\n" 37623a1ff79SBarry Smith "<script type=\"text/javascript\" src=\"http://www.mcs.anl.gov/research/projects/saws/js/SAWs.js\"></script>\n" 377d1fc0251SBarry Smith "<script type=\"text/javascript\" src=\"js/PETSc.js\"></script>\n" 37864bbc9efSBarry Smith "<script>\n" 37964bbc9efSBarry Smith "jQuery(document).ready(function() {\n" 38064bbc9efSBarry Smith "PETSc.getAndDisplayDirectory(null,\"#variablesInfo\")\n" 38164bbc9efSBarry Smith "})\n" 38264bbc9efSBarry Smith "</script>\n" 38364bbc9efSBarry Smith "</head>\n"; 3841423471aSBarry Smith 3851423471aSBarry Smith /* Determines the size and style of the scroll region where PETSc options selectable from users are displayed */ 3861423471aSBarry Smith static const char *OptionsBodyBottom = "<div id=\"variablesInfo\" style=\"background-color:lightblue;height:auto;max-height:500px;overflow:scroll;\"></div>\n<br>\n</body>"; 38764bbc9efSBarry Smith 388d5649816SBarry Smith #undef __FUNCT__ 3897781c08eSBarry Smith #define __FUNCT__ "PetscOptionsSAWsInput" 390b3506946SBarry Smith /* 3917781c08eSBarry Smith PetscOptionsSAWsInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the SAWs 392b3506946SBarry Smith 393b3506946SBarry Smith Bugs: 394b3506946SBarry Smith + All processes must traverse through the exact same set of option queries do to the call to PetscScanString() 395b3506946SBarry Smith . Internal strings have arbitrary length and string copies are not checked that they fit into string space 396b3506946SBarry Smith - Only works for PetscInt == int, PetscReal == double etc 397b3506946SBarry Smith 398b3506946SBarry Smith 399b3506946SBarry Smith */ 400f7b25cf6SBarry Smith PetscErrorCode PetscOptionsSAWsInput(PetscOptions *PetscOptionsObject) 401b3506946SBarry Smith { 402b3506946SBarry Smith PetscErrorCode ierr; 4038c34d3f5SBarry Smith PetscOption next = PetscOptionsObject->next; 404d5649816SBarry Smith static int mancount = 0; 405b3506946SBarry Smith char options[16]; 4067aab2a10SBarry Smith PetscBool changedmethod = PETSC_FALSE; 407a23eb982SSurtai Han PetscBool stopasking = PETSC_FALSE; 40888a9752cSBarry Smith char manname[16],textname[16]; 4092657e9d9SBarry Smith char dir[1024]; 410b3506946SBarry Smith 411b3506946SBarry Smith /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */ 412b3506946SBarry Smith sprintf(options,"Options_%d",count++); 413a297a907SKarl Rupp 414e55864a3SBarry Smith PetscOptionsObject->pprefix = PetscOptionsObject->prefix; /* AMS will change this, so cannot pass prefix directly */ 4151bc75a8dSBarry Smith 416d50831c4SBarry Smith ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s","_title");CHKERRQ(ierr); 41783355fc5SBarry Smith PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject->title,1,SAWs_READ,SAWs_STRING)); 4187781c08eSBarry Smith ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s","prefix");CHKERRQ(ierr); 41983355fc5SBarry Smith PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject->pprefix,1,SAWs_READ,SAWs_STRING)); 4202657e9d9SBarry Smith PetscStackCallSAWs(SAWs_Register,("/PETSc/Options/ChangedMethod",&changedmethod,1,SAWs_WRITE,SAWs_BOOLEAN)); 421a23eb982SSurtai Han PetscStackCallSAWs(SAWs_Register,("/PETSc/Options/StopAsking",&stopasking,1,SAWs_WRITE,SAWs_BOOLEAN)); 422b3506946SBarry Smith 423b3506946SBarry Smith while (next) { 424d50831c4SBarry Smith sprintf(manname,"_man_%d",mancount); 4252657e9d9SBarry Smith ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",manname);CHKERRQ(ierr); 4267781c08eSBarry Smith PetscStackCallSAWs(SAWs_Register,(dir,&next->man,1,SAWs_READ,SAWs_STRING)); 427d50831c4SBarry Smith sprintf(textname,"_text_%d",mancount++); 4287781c08eSBarry Smith ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",textname);CHKERRQ(ierr); 4297781c08eSBarry Smith PetscStackCallSAWs(SAWs_Register,(dir,&next->text,1,SAWs_READ,SAWs_STRING)); 4309f32e415SBarry Smith 431b3506946SBarry Smith switch (next->type) { 432b3506946SBarry Smith case OPTION_HEAD: 433b3506946SBarry Smith break; 434b3506946SBarry Smith case OPTION_INT_ARRAY: 4357781c08eSBarry Smith ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 4362657e9d9SBarry Smith PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_INT)); 437b3506946SBarry Smith break; 438b3506946SBarry Smith case OPTION_REAL_ARRAY: 4397781c08eSBarry Smith ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 4402657e9d9SBarry Smith PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_DOUBLE)); 441b3506946SBarry Smith break; 442b3506946SBarry Smith case OPTION_INT: 4437781c08eSBarry Smith ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 4442657e9d9SBarry Smith PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_INT)); 445b3506946SBarry Smith break; 446b3506946SBarry Smith case OPTION_REAL: 4477781c08eSBarry Smith ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 4482657e9d9SBarry Smith PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_DOUBLE)); 449b3506946SBarry Smith break; 4507781c08eSBarry Smith case OPTION_BOOL: 4517781c08eSBarry Smith ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 4522657e9d9SBarry Smith PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_BOOLEAN)); 4531ae3d29cSBarry Smith break; 4547781c08eSBarry Smith case OPTION_BOOL_ARRAY: 4557781c08eSBarry Smith ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 4562657e9d9SBarry Smith PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_BOOLEAN)); 45771f08665SBarry Smith break; 458b3506946SBarry Smith case OPTION_STRING: 4597781c08eSBarry Smith ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 4607781c08eSBarry Smith PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING)); 4611ae3d29cSBarry Smith break; 4621ae3d29cSBarry Smith case OPTION_STRING_ARRAY: 4637781c08eSBarry Smith ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 4642657e9d9SBarry Smith PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_STRING)); 465b3506946SBarry Smith break; 466a264d7a6SBarry Smith case OPTION_FLIST: 467a264d7a6SBarry Smith { 468a264d7a6SBarry Smith PetscInt ntext; 4697781c08eSBarry Smith ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 4707781c08eSBarry Smith PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING)); 471a264d7a6SBarry Smith ierr = PetscFunctionListGet(next->flist,(const char***)&next->edata,&ntext);CHKERRQ(ierr); 472a264d7a6SBarry Smith PetscStackCallSAWs(SAWs_Set_Legal_Variable_Values,(dir,ntext,next->edata)); 473a264d7a6SBarry Smith } 474a264d7a6SBarry Smith break; 4751ae3d29cSBarry Smith case OPTION_ELIST: 476a264d7a6SBarry Smith { 477a264d7a6SBarry Smith PetscInt ntext = next->nlist; 4787781c08eSBarry Smith ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 4797781c08eSBarry Smith PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING)); 480ead66b60SBarry Smith ierr = PetscMalloc1((ntext+1),(char***)&next->edata);CHKERRQ(ierr); 4811ae3d29cSBarry Smith ierr = PetscMemcpy(next->edata,next->list,ntext*sizeof(char*));CHKERRQ(ierr); 482a264d7a6SBarry Smith PetscStackCallSAWs(SAWs_Set_Legal_Variable_Values,(dir,ntext,next->edata)); 483a264d7a6SBarry Smith } 484a264d7a6SBarry Smith break; 485b3506946SBarry Smith default: 486b3506946SBarry Smith break; 487b3506946SBarry Smith } 488b3506946SBarry Smith next = next->next; 489b3506946SBarry Smith } 490b3506946SBarry Smith 491b3506946SBarry Smith /* wait until accessor has unlocked the memory */ 49264bbc9efSBarry Smith PetscStackCallSAWs(SAWs_Push_Header,("index.html",OptionsHeader)); 49364bbc9efSBarry Smith PetscStackCallSAWs(SAWs_Push_Body,("index.html",2,OptionsBodyBottom)); 4947aab2a10SBarry Smith ierr = PetscSAWsBlock();CHKERRQ(ierr); 49564bbc9efSBarry Smith PetscStackCallSAWs(SAWs_Pop_Header,("index.html")); 49664bbc9efSBarry Smith PetscStackCallSAWs(SAWs_Pop_Body,("index.html",2)); 497b3506946SBarry Smith 49888a9752cSBarry Smith /* determine if any values have been set in GUI */ 49983355fc5SBarry Smith next = PetscOptionsObject->next; 50088a9752cSBarry Smith while (next) { 50188a9752cSBarry Smith ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr); 502f7b25cf6SBarry Smith PetscStackCallSAWs(SAWs_Selected,(dir,(int*)&next->set)); 50388a9752cSBarry Smith next = next->next; 50488a9752cSBarry Smith } 50588a9752cSBarry Smith 506b3506946SBarry Smith /* reset counter to -2; this updates the screen with the new options for the selected method */ 507f7b25cf6SBarry Smith if (changedmethod) PetscOptionsObject->count = -2; 508b3506946SBarry Smith 509a23eb982SSurtai Han if (stopasking) { 510a23eb982SSurtai Han PetscOptionsPublish = PETSC_FALSE; 51112655325SBarry Smith PetscOptionsObject->count = 0;//do not ask for same thing again 512a23eb982SSurtai Han } 513a23eb982SSurtai Han 5149a492a5cSBarry Smith PetscStackCallSAWs(SAWs_Delete,("/PETSc/Options")); 515b3506946SBarry Smith PetscFunctionReturn(0); 516b3506946SBarry Smith } 517b3506946SBarry Smith #endif 518b3506946SBarry Smith 5196356e834SBarry Smith #undef __FUNCT__ 52053acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsEnd_Private" 5218c34d3f5SBarry Smith PetscErrorCode PetscOptionsEnd_Private(PetscOptions *PetscOptionsObject) 52253acd3b1SBarry Smith { 52353acd3b1SBarry Smith PetscErrorCode ierr; 5248c34d3f5SBarry Smith PetscOption last; 5256356e834SBarry Smith char option[256],value[1024],tmp[32]; 526330cf3c9SBarry Smith size_t j; 52753acd3b1SBarry Smith 52853acd3b1SBarry Smith PetscFunctionBegin; 52983355fc5SBarry Smith if (PetscOptionsObject->next) { 53083355fc5SBarry Smith if (!PetscOptionsObject->count) { 531a264d7a6SBarry Smith #if defined(PETSC_HAVE_SAWS) 532f7b25cf6SBarry Smith ierr = PetscOptionsSAWsInput(PetscOptionsObject);CHKERRQ(ierr); 533b3506946SBarry Smith #else 534e55864a3SBarry Smith ierr = PetscOptionsGetFromTextInput(PetscOptionsObject);CHKERRQ(ierr); 535b3506946SBarry Smith #endif 536aee2cecaSBarry Smith } 537aee2cecaSBarry Smith } 5386356e834SBarry Smith 539e55864a3SBarry Smith ierr = PetscFree(PetscOptionsObject->title);CHKERRQ(ierr); 540e55864a3SBarry Smith ierr = PetscFree(PetscOptionsObject->prefix);CHKERRQ(ierr); 5416356e834SBarry Smith 542e26ddf31SBarry Smith /* reset counter to -2; this updates the screen with the new options for the selected method */ 543e55864a3SBarry Smith if (PetscOptionsObject->changedmethod) PetscOptionsObject->count = -2; 5447a72a596SBarry Smith /* reset alreadyprinted flag */ 545e55864a3SBarry Smith PetscOptionsObject->alreadyprinted = PETSC_FALSE; 546e55864a3SBarry Smith if (PetscOptionsObject->object) PetscOptionsObject->object->optionsprinted = PETSC_TRUE; 547e55864a3SBarry Smith PetscOptionsObject->object = NULL; 54853acd3b1SBarry Smith 549e55864a3SBarry Smith while (PetscOptionsObject->next) { 550e55864a3SBarry Smith if (PetscOptionsObject->next->set) { 551e55864a3SBarry Smith if (PetscOptionsObject->prefix) { 55253acd3b1SBarry Smith ierr = PetscStrcpy(option,"-");CHKERRQ(ierr); 553e55864a3SBarry Smith ierr = PetscStrcat(option,PetscOptionsObject->prefix);CHKERRQ(ierr); 554e55864a3SBarry Smith ierr = PetscStrcat(option,PetscOptionsObject->next->option+1);CHKERRQ(ierr); 5556356e834SBarry Smith } else { 556e55864a3SBarry Smith ierr = PetscStrcpy(option,PetscOptionsObject->next->option);CHKERRQ(ierr); 5576356e834SBarry Smith } 5586356e834SBarry Smith 559e55864a3SBarry Smith switch (PetscOptionsObject->next->type) { 5606356e834SBarry Smith case OPTION_HEAD: 5616356e834SBarry Smith break; 5626356e834SBarry Smith case OPTION_INT_ARRAY: 563e55864a3SBarry Smith sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject->next->data)[0]); 564e55864a3SBarry Smith for (j=1; j<PetscOptionsObject->next->arraylength; j++) { 565e55864a3SBarry Smith sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject->next->data)[j]); 5666356e834SBarry Smith ierr = PetscStrcat(value,",");CHKERRQ(ierr); 5676356e834SBarry Smith ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 5686356e834SBarry Smith } 5696356e834SBarry Smith break; 5706356e834SBarry Smith case OPTION_INT: 571e55864a3SBarry Smith sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject->next->data); 5726356e834SBarry Smith break; 5736356e834SBarry Smith case OPTION_REAL: 574e55864a3SBarry Smith sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject->next->data); 5756356e834SBarry Smith break; 5766356e834SBarry Smith case OPTION_REAL_ARRAY: 577e55864a3SBarry Smith sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject->next->data)[0]); 578e55864a3SBarry Smith for (j=1; j<PetscOptionsObject->next->arraylength; j++) { 579e55864a3SBarry Smith sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject->next->data)[j]); 5806356e834SBarry Smith ierr = PetscStrcat(value,",");CHKERRQ(ierr); 5816356e834SBarry Smith ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 5826356e834SBarry Smith } 5836356e834SBarry Smith break; 5847781c08eSBarry Smith case OPTION_BOOL: 585e55864a3SBarry Smith sprintf(value,"%d",*(int*)PetscOptionsObject->next->data); 5866356e834SBarry Smith break; 5877781c08eSBarry Smith case OPTION_BOOL_ARRAY: 588e55864a3SBarry Smith sprintf(value,"%d",(int)((PetscBool*)PetscOptionsObject->next->data)[0]); 589e55864a3SBarry Smith for (j=1; j<PetscOptionsObject->next->arraylength; j++) { 590e55864a3SBarry Smith sprintf(tmp,"%d",(int)((PetscBool*)PetscOptionsObject->next->data)[j]); 5911ae3d29cSBarry Smith ierr = PetscStrcat(value,",");CHKERRQ(ierr); 5921ae3d29cSBarry Smith ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 5931ae3d29cSBarry Smith } 5941ae3d29cSBarry Smith break; 595a264d7a6SBarry Smith case OPTION_FLIST: 5961ae3d29cSBarry Smith case OPTION_ELIST: 597e55864a3SBarry Smith ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr); 5986356e834SBarry Smith break; 5991ae3d29cSBarry Smith case OPTION_STRING: 600e55864a3SBarry Smith ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr); 601*d51da6bfSBarry Smith break; 6021ae3d29cSBarry Smith case OPTION_STRING_ARRAY: 603e55864a3SBarry Smith sprintf(value,"%s",((char**)PetscOptionsObject->next->data)[0]); 604e55864a3SBarry Smith for (j=1; j<PetscOptionsObject->next->arraylength; j++) { 605e55864a3SBarry Smith sprintf(tmp,"%s",((char**)PetscOptionsObject->next->data)[j]); 6061ae3d29cSBarry Smith ierr = PetscStrcat(value,",");CHKERRQ(ierr); 6071ae3d29cSBarry Smith ierr = PetscStrcat(value,tmp);CHKERRQ(ierr); 6081ae3d29cSBarry Smith } 6096356e834SBarry Smith break; 6106356e834SBarry Smith } 6116356e834SBarry Smith ierr = PetscOptionsSetValue(option,value);CHKERRQ(ierr); 6126356e834SBarry Smith } 613e55864a3SBarry Smith ierr = PetscFree(PetscOptionsObject->next->text);CHKERRQ(ierr); 614e55864a3SBarry Smith ierr = PetscFree(PetscOptionsObject->next->option);CHKERRQ(ierr); 615e55864a3SBarry Smith ierr = PetscFree(PetscOptionsObject->next->man);CHKERRQ(ierr); 616e55864a3SBarry Smith ierr = PetscFree(PetscOptionsObject->next->edata);CHKERRQ(ierr); 617c979a496SBarry Smith 61883355fc5SBarry Smith if ((PetscOptionsObject->next->type == OPTION_STRING) || (PetscOptionsObject->next->type == OPTION_FLIST) || (PetscOptionsObject->next->type == OPTION_ELIST)){ 61983355fc5SBarry Smith free(PetscOptionsObject->next->data); 620c979a496SBarry Smith } else { 62183355fc5SBarry Smith ierr = PetscFree(PetscOptionsObject->next->data);CHKERRQ(ierr); 622c979a496SBarry Smith } 6237781c08eSBarry Smith 62483355fc5SBarry Smith last = PetscOptionsObject->next; 62583355fc5SBarry Smith PetscOptionsObject->next = PetscOptionsObject->next->next; 6266356e834SBarry Smith ierr = PetscFree(last);CHKERRQ(ierr); 6276356e834SBarry Smith } 628e55864a3SBarry Smith PetscOptionsObject->next = 0; 62953acd3b1SBarry Smith PetscFunctionReturn(0); 63053acd3b1SBarry Smith } 63153acd3b1SBarry Smith 63253acd3b1SBarry Smith #undef __FUNCT__ 633e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsEnum_Private" 63453acd3b1SBarry Smith /*@C 63553acd3b1SBarry Smith PetscOptionsEnum - Gets the enum value for a particular option in the database. 63653acd3b1SBarry Smith 6373f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 63853acd3b1SBarry Smith 63953acd3b1SBarry Smith Input Parameters: 64053acd3b1SBarry Smith + opt - option name 64153acd3b1SBarry Smith . text - short string that describes the option 64253acd3b1SBarry Smith . man - manual page with additional information on option 64353acd3b1SBarry Smith . list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null 6440fdccdaeSBarry Smith - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 6450fdccdaeSBarry Smith $ PetscOptionsEnum(..., obj->value,&object->value,...) or 6460fdccdaeSBarry Smith $ value = defaultvalue 6470fdccdaeSBarry Smith $ PetscOptionsEnum(..., value,&value,&flg); 6480fdccdaeSBarry Smith $ if (flg) { 64953acd3b1SBarry Smith 65053acd3b1SBarry Smith Output Parameter: 65153acd3b1SBarry Smith + value - the value to return 652b32e0204SMatthew G Knepley - set - PETSC_TRUE if found, else PETSC_FALSE 65353acd3b1SBarry Smith 65453acd3b1SBarry Smith Level: beginner 65553acd3b1SBarry Smith 65653acd3b1SBarry Smith Concepts: options database 65753acd3b1SBarry Smith 65853acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 65953acd3b1SBarry Smith 66053acd3b1SBarry Smith list is usually something like PCASMTypes or some other predefined list of enum names 66153acd3b1SBarry Smith 66253acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 663acfcf0e5SJed Brown PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 664acfcf0e5SJed Brown PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 66553acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 66653acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 667acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 668a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList() 66953acd3b1SBarry Smith @*/ 6708c34d3f5SBarry Smith PetscErrorCode PetscOptionsEnum_Private(PetscOptions *PetscOptionsObject,const char opt[],const char text[],const char man[],const char *const *list,PetscEnum currentvalue,PetscEnum *value,PetscBool *set) 67153acd3b1SBarry Smith { 67253acd3b1SBarry Smith PetscErrorCode ierr; 67353acd3b1SBarry Smith PetscInt ntext = 0; 674aa5bb8c0SSatish Balay PetscInt tval; 675ace3abfcSBarry Smith PetscBool tflg; 67653acd3b1SBarry Smith 67753acd3b1SBarry Smith PetscFunctionBegin; 67853acd3b1SBarry Smith while (list[ntext++]) { 679e32f2f54SBarry Smith if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries"); 68053acd3b1SBarry Smith } 681e32f2f54SBarry Smith if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix"); 68253acd3b1SBarry Smith ntext -= 3; 683e55864a3SBarry Smith ierr = PetscOptionsEList_Private(PetscOptionsObject,opt,text,man,list,ntext,list[currentvalue],&tval,&tflg);CHKERRQ(ierr); 684aa5bb8c0SSatish Balay /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */ 685aa5bb8c0SSatish Balay if (tflg) *value = (PetscEnum)tval; 686aa5bb8c0SSatish Balay if (set) *set = tflg; 68753acd3b1SBarry Smith PetscFunctionReturn(0); 68853acd3b1SBarry Smith } 68953acd3b1SBarry Smith 69053acd3b1SBarry Smith /* -------------------------------------------------------------------------------------------------------------*/ 69153acd3b1SBarry Smith #undef __FUNCT__ 692e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsInt_Private" 69353acd3b1SBarry Smith /*@C 69453acd3b1SBarry Smith PetscOptionsInt - Gets the integer value for a particular option in the database. 69553acd3b1SBarry Smith 6963f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 69753acd3b1SBarry Smith 69853acd3b1SBarry Smith Input Parameters: 69953acd3b1SBarry Smith + opt - option name 70053acd3b1SBarry Smith . text - short string that describes the option 70153acd3b1SBarry Smith . man - manual page with additional information on option 7020fdccdaeSBarry Smith - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 7030fdccdaeSBarry Smith $ PetscOptionsInt(..., obj->value,&object->value,...) or 7040fdccdaeSBarry Smith $ value = defaultvalue 7050fdccdaeSBarry Smith $ PetscOptionsInt(..., value,&value,&flg); 7060fdccdaeSBarry Smith $ if (flg) { 70753acd3b1SBarry Smith 70853acd3b1SBarry Smith Output Parameter: 70953acd3b1SBarry Smith + value - the integer value to return 71053acd3b1SBarry Smith - flg - PETSC_TRUE if found, else PETSC_FALSE 71153acd3b1SBarry Smith 71253acd3b1SBarry Smith Level: beginner 71353acd3b1SBarry Smith 71453acd3b1SBarry Smith Concepts: options database^has int 71553acd3b1SBarry Smith 71653acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 71753acd3b1SBarry Smith 71853acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 719acfcf0e5SJed Brown PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 720acfcf0e5SJed Brown PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 72153acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 72253acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 723acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 724a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList() 72553acd3b1SBarry Smith @*/ 7268c34d3f5SBarry Smith PetscErrorCode PetscOptionsInt_Private(PetscOptions *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *set) 72753acd3b1SBarry Smith { 72853acd3b1SBarry Smith PetscErrorCode ierr; 7298c34d3f5SBarry Smith PetscOption amsopt; 73012655325SBarry Smith PetscBool wasset; 73153acd3b1SBarry Smith 73253acd3b1SBarry Smith PetscFunctionBegin; 733e55864a3SBarry Smith if (!PetscOptionsObject->count) { 734e55864a3SBarry Smith ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr); 7356356e834SBarry Smith ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr); 73612655325SBarry Smith *(PetscInt*)amsopt->data = currentvalue; 7373e211508SBarry Smith 73812655325SBarry Smith ierr = PetscOptionsGetInt(PetscOptionsObject->prefix,opt,¤tvalue,&wasset);CHKERRQ(ierr); 7393e211508SBarry Smith if (wasset) { 74012655325SBarry Smith *(PetscInt*)amsopt->data = currentvalue; 7413e211508SBarry Smith } 742af6d86caSBarry Smith } 743e55864a3SBarry Smith ierr = PetscOptionsGetInt(PetscOptionsObject->prefix,opt,value,set);CHKERRQ(ierr); 744e55864a3SBarry Smith if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 7451a1499c8SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%d>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,currentvalue,text,ManSection(man));CHKERRQ(ierr); 74653acd3b1SBarry Smith } 74753acd3b1SBarry Smith PetscFunctionReturn(0); 74853acd3b1SBarry Smith } 74953acd3b1SBarry Smith 75053acd3b1SBarry Smith #undef __FUNCT__ 751e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsString_Private" 75253acd3b1SBarry Smith /*@C 75353acd3b1SBarry Smith PetscOptionsString - Gets the string value for a particular option in the database. 75453acd3b1SBarry Smith 7553f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 75653acd3b1SBarry Smith 75753acd3b1SBarry Smith Input Parameters: 75853acd3b1SBarry Smith + opt - option name 75953acd3b1SBarry Smith . text - short string that describes the option 76053acd3b1SBarry Smith . man - manual page with additional information on option 7610fdccdaeSBarry Smith . currentvalue - the current value; caller is responsible for setting this value correctly. This is not used to set value 762bcbf2dc5SJed Brown - len - length of the result string including null terminator 76353acd3b1SBarry Smith 76453acd3b1SBarry Smith Output Parameter: 76553acd3b1SBarry Smith + value - the value to return 76653acd3b1SBarry Smith - flg - PETSC_TRUE if found, else PETSC_FALSE 76753acd3b1SBarry Smith 76853acd3b1SBarry Smith Level: beginner 76953acd3b1SBarry Smith 77053acd3b1SBarry Smith Concepts: options database^has int 77153acd3b1SBarry Smith 77253acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 77353acd3b1SBarry Smith 7747fccdfe4SBarry Smith Even if the user provided no string (for example -optionname -someotheroption) the flag is set to PETSC_TRUE (and the string is fulled with nulls). 7757fccdfe4SBarry Smith 77653acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 777acfcf0e5SJed Brown PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 778acfcf0e5SJed Brown PetscOptionsInt(), PetscOptionsReal(), PetscOptionsBool(), 77953acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 78053acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 781acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 782a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList() 78353acd3b1SBarry Smith @*/ 7848c34d3f5SBarry Smith PetscErrorCode PetscOptionsString_Private(PetscOptions *PetscOptionsObject,const char opt[],const char text[],const char man[],const char currentvalue[],char value[],size_t len,PetscBool *set) 78553acd3b1SBarry Smith { 78653acd3b1SBarry Smith PetscErrorCode ierr; 7878c34d3f5SBarry Smith PetscOption amsopt; 78853acd3b1SBarry Smith 78953acd3b1SBarry Smith PetscFunctionBegin; 7901a1499c8SBarry Smith if (!PetscOptionsObject->count) { 7911a1499c8SBarry Smith ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr); 79264facd6cSBarry Smith /* must use system malloc since SAWs may free this */ 7930fdccdaeSBarry Smith ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr); 794af6d86caSBarry Smith } 795e55864a3SBarry Smith ierr = PetscOptionsGetString(PetscOptionsObject->prefix,opt,value,len,set);CHKERRQ(ierr); 796e55864a3SBarry Smith if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 7971a1499c8SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%s>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,currentvalue,text,ManSection(man));CHKERRQ(ierr); 79853acd3b1SBarry Smith } 79953acd3b1SBarry Smith PetscFunctionReturn(0); 80053acd3b1SBarry Smith } 80153acd3b1SBarry Smith 80253acd3b1SBarry Smith #undef __FUNCT__ 803e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsReal_Private" 80453acd3b1SBarry Smith /*@C 80553acd3b1SBarry Smith PetscOptionsReal - Gets the PetscReal value for a particular option in the database. 80653acd3b1SBarry Smith 8073f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 80853acd3b1SBarry Smith 80953acd3b1SBarry Smith Input Parameters: 81053acd3b1SBarry Smith + opt - option name 81153acd3b1SBarry Smith . text - short string that describes the option 81253acd3b1SBarry Smith . man - manual page with additional information on option 8130fdccdaeSBarry Smith - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 8140fdccdaeSBarry Smith $ PetscOptionsReal(..., obj->value,&object->value,...) or 8150fdccdaeSBarry Smith $ value = defaultvalue 8160fdccdaeSBarry Smith $ PetscOptionsReal(..., value,&value,&flg); 8170fdccdaeSBarry Smith $ if (flg) { 81853acd3b1SBarry Smith 81953acd3b1SBarry Smith Output Parameter: 82053acd3b1SBarry Smith + value - the value to return 82153acd3b1SBarry Smith - flg - PETSC_TRUE if found, else PETSC_FALSE 82253acd3b1SBarry Smith 82353acd3b1SBarry Smith Level: beginner 82453acd3b1SBarry Smith 82553acd3b1SBarry Smith Concepts: options database^has int 82653acd3b1SBarry Smith 82753acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 82853acd3b1SBarry Smith 82953acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 830acfcf0e5SJed Brown PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 831acfcf0e5SJed Brown PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 83253acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 83353acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 834acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 835a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList() 83653acd3b1SBarry Smith @*/ 8378c34d3f5SBarry Smith PetscErrorCode PetscOptionsReal_Private(PetscOptions *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscReal currentvalue,PetscReal *value,PetscBool *set) 83853acd3b1SBarry Smith { 83953acd3b1SBarry Smith PetscErrorCode ierr; 8408c34d3f5SBarry Smith PetscOption amsopt; 84153acd3b1SBarry Smith 84253acd3b1SBarry Smith PetscFunctionBegin; 843e55864a3SBarry Smith if (!PetscOptionsObject->count) { 844e55864a3SBarry Smith ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr); 845538aa990SBarry Smith ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr); 846a297a907SKarl Rupp 8470fdccdaeSBarry Smith *(PetscReal*)amsopt->data = currentvalue; 848538aa990SBarry Smith } 8491a1499c8SBarry Smith ierr = PetscOptionsGetReal(PetscOptionsObject->prefix,opt,value,set);CHKERRQ(ierr); 8501a1499c8SBarry Smith if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 8511a1499c8SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%g>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,(double)currentvalue,text,ManSection(man));CHKERRQ(ierr); 85253acd3b1SBarry Smith } 85353acd3b1SBarry Smith PetscFunctionReturn(0); 85453acd3b1SBarry Smith } 85553acd3b1SBarry Smith 85653acd3b1SBarry Smith #undef __FUNCT__ 857e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsScalar_Private" 85853acd3b1SBarry Smith /*@C 85953acd3b1SBarry Smith PetscOptionsScalar - Gets the scalar value for a particular option in the database. 86053acd3b1SBarry Smith 8613f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 86253acd3b1SBarry Smith 86353acd3b1SBarry Smith Input Parameters: 86453acd3b1SBarry Smith + opt - option name 86553acd3b1SBarry Smith . text - short string that describes the option 86653acd3b1SBarry Smith . man - manual page with additional information on option 8670fdccdaeSBarry Smith - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 8680fdccdaeSBarry Smith $ PetscOptionsScalar(..., obj->value,&object->value,...) or 8690fdccdaeSBarry Smith $ value = defaultvalue 8700fdccdaeSBarry Smith $ PetscOptionsScalar(..., value,&value,&flg); 8710fdccdaeSBarry Smith $ if (flg) { 8720fdccdaeSBarry Smith 87353acd3b1SBarry Smith 87453acd3b1SBarry Smith Output Parameter: 87553acd3b1SBarry Smith + value - the value to return 87653acd3b1SBarry Smith - flg - PETSC_TRUE if found, else PETSC_FALSE 87753acd3b1SBarry Smith 87853acd3b1SBarry Smith Level: beginner 87953acd3b1SBarry Smith 88053acd3b1SBarry Smith Concepts: options database^has int 88153acd3b1SBarry Smith 88253acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 88353acd3b1SBarry Smith 88453acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 885acfcf0e5SJed Brown PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 886acfcf0e5SJed Brown PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 88753acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 88853acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 889acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 890a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList() 89153acd3b1SBarry Smith @*/ 8928c34d3f5SBarry Smith PetscErrorCode PetscOptionsScalar_Private(PetscOptions *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscScalar currentvalue,PetscScalar *value,PetscBool *set) 89353acd3b1SBarry Smith { 89453acd3b1SBarry Smith PetscErrorCode ierr; 89553acd3b1SBarry Smith 89653acd3b1SBarry Smith PetscFunctionBegin; 89753acd3b1SBarry Smith #if !defined(PETSC_USE_COMPLEX) 8980fdccdaeSBarry Smith ierr = PetscOptionsReal(opt,text,man,currentvalue,value,set);CHKERRQ(ierr); 89953acd3b1SBarry Smith #else 900e55864a3SBarry Smith ierr = PetscOptionsGetScalar(PetscOptionsObject->prefix,opt,value,set);CHKERRQ(ierr); 90153acd3b1SBarry Smith #endif 90253acd3b1SBarry Smith PetscFunctionReturn(0); 90353acd3b1SBarry Smith } 90453acd3b1SBarry Smith 90553acd3b1SBarry Smith #undef __FUNCT__ 906e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsName_Private" 90753acd3b1SBarry Smith /*@C 90890d69ab7SBarry 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 90990d69ab7SBarry Smith its value is set to false. 91053acd3b1SBarry Smith 9113f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 91253acd3b1SBarry Smith 91353acd3b1SBarry Smith Input Parameters: 91453acd3b1SBarry Smith + opt - option name 91553acd3b1SBarry Smith . text - short string that describes the option 91653acd3b1SBarry Smith - man - manual page with additional information on option 91753acd3b1SBarry Smith 91853acd3b1SBarry Smith Output Parameter: 91953acd3b1SBarry Smith . flg - PETSC_TRUE if found, else PETSC_FALSE 92053acd3b1SBarry Smith 92153acd3b1SBarry Smith Level: beginner 92253acd3b1SBarry Smith 92353acd3b1SBarry Smith Concepts: options database^has int 92453acd3b1SBarry Smith 92553acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 92653acd3b1SBarry Smith 92753acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 928acfcf0e5SJed Brown PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 929acfcf0e5SJed Brown PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 93053acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 93153acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 932acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 933a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList() 93453acd3b1SBarry Smith @*/ 9358c34d3f5SBarry Smith PetscErrorCode PetscOptionsName_Private(PetscOptions *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool *flg) 93653acd3b1SBarry Smith { 93753acd3b1SBarry Smith PetscErrorCode ierr; 9388c34d3f5SBarry Smith PetscOption amsopt; 93953acd3b1SBarry Smith 94053acd3b1SBarry Smith PetscFunctionBegin; 941e55864a3SBarry Smith if (!PetscOptionsObject->count) { 942e55864a3SBarry Smith ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 943ace3abfcSBarry Smith ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 944a297a907SKarl Rupp 945ace3abfcSBarry Smith *(PetscBool*)amsopt->data = PETSC_FALSE; 9461ae3d29cSBarry Smith } 947e55864a3SBarry Smith ierr = PetscOptionsHasName(PetscOptionsObject->prefix,opt,flg);CHKERRQ(ierr); 948e55864a3SBarry Smith if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 949e55864a3SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 95053acd3b1SBarry Smith } 95153acd3b1SBarry Smith PetscFunctionReturn(0); 95253acd3b1SBarry Smith } 95353acd3b1SBarry Smith 95453acd3b1SBarry Smith #undef __FUNCT__ 955e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsFList_Private" 95653acd3b1SBarry Smith /*@C 957a264d7a6SBarry Smith PetscOptionsFList - Puts a list of option values that a single one may be selected from 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 . list - the possible choices 9660fdccdaeSBarry Smith . currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with 9670fdccdaeSBarry Smith $ PetscOptionsFlist(..., obj->value,value,len,&flg); 9680fdccdaeSBarry Smith $ if (flg) { 9693cc1e11dSBarry Smith - len - the length of the character array value 97053acd3b1SBarry Smith 97153acd3b1SBarry Smith Output Parameter: 97253acd3b1SBarry Smith + value - the value to return 97353acd3b1SBarry Smith - set - PETSC_TRUE if found, else PETSC_FALSE 97453acd3b1SBarry Smith 97553acd3b1SBarry Smith Level: intermediate 97653acd3b1SBarry Smith 97753acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 97853acd3b1SBarry Smith 97953acd3b1SBarry Smith See PetscOptionsEList() for when the choices are given in a string array 98053acd3b1SBarry Smith 98153acd3b1SBarry Smith To get a listing of all currently specified options, 98288c29154SBarry Smith see PetscOptionsView() or PetscOptionsGetAll() 98353acd3b1SBarry Smith 984eabe10d7SBarry Smith Developer Note: This cannot check for invalid selection because of things like MATAIJ that are not included in the list 985eabe10d7SBarry Smith 98653acd3b1SBarry Smith Concepts: options database^list 98753acd3b1SBarry Smith 98853acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 989acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 99053acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 99153acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 992acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 993a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList(), PetscOptionsEnum() 99453acd3b1SBarry Smith @*/ 9958c34d3f5SBarry Smith PetscErrorCode PetscOptionsFList_Private(PetscOptions *PetscOptionsObject,const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char currentvalue[],char value[],size_t len,PetscBool *set) 99653acd3b1SBarry Smith { 99753acd3b1SBarry Smith PetscErrorCode ierr; 9988c34d3f5SBarry Smith PetscOption amsopt; 99953acd3b1SBarry Smith 100053acd3b1SBarry Smith PetscFunctionBegin; 10011a1499c8SBarry Smith if (!PetscOptionsObject->count) { 10021a1499c8SBarry Smith ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,ltext,man,OPTION_FLIST,&amsopt);CHKERRQ(ierr); 100364facd6cSBarry Smith /* must use system malloc since SAWs may free this */ 10040fdccdaeSBarry Smith ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr); 10053cc1e11dSBarry Smith amsopt->flist = list; 10063cc1e11dSBarry Smith } 10071a1499c8SBarry Smith ierr = PetscOptionsGetString(PetscOptionsObject->prefix,opt,value,len,set);CHKERRQ(ierr); 10081a1499c8SBarry Smith if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 10091a1499c8SBarry Smith ierr = PetscFunctionListPrintTypes(PetscOptionsObject->comm,stdout,PetscOptionsObject->prefix,opt,ltext,man,list,currentvalue);CHKERRQ(ierr);CHKERRQ(ierr); 101053acd3b1SBarry Smith } 101153acd3b1SBarry Smith PetscFunctionReturn(0); 101253acd3b1SBarry Smith } 101353acd3b1SBarry Smith 101453acd3b1SBarry Smith #undef __FUNCT__ 1015e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsEList_Private" 101653acd3b1SBarry Smith /*@C 101753acd3b1SBarry Smith PetscOptionsEList - Puts a list of option values that a single one may be selected from 101853acd3b1SBarry Smith 10193f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 102053acd3b1SBarry Smith 102153acd3b1SBarry Smith Input Parameters: 102253acd3b1SBarry Smith + opt - option name 102353acd3b1SBarry Smith . ltext - short string that describes the option 102453acd3b1SBarry Smith . man - manual page with additional information on option 1025a264d7a6SBarry Smith . list - the possible choices (one of these must be selected, anything else is invalid) 102653acd3b1SBarry Smith . ntext - number of choices 10270fdccdaeSBarry Smith - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with 10280fdccdaeSBarry Smith $ PetscOptionsElist(..., obj->value,&value,&flg); 10290fdccdaeSBarry Smith $ if (flg) { 10300fdccdaeSBarry Smith 103153acd3b1SBarry Smith 103253acd3b1SBarry Smith Output Parameter: 103353acd3b1SBarry Smith + value - the index of the value to return 103453acd3b1SBarry Smith - set - PETSC_TRUE if found, else PETSC_FALSE 103553acd3b1SBarry Smith 103653acd3b1SBarry Smith Level: intermediate 103753acd3b1SBarry Smith 103853acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 103953acd3b1SBarry Smith 1040a264d7a6SBarry Smith See PetscOptionsFList() for when the choices are given in a PetscFunctionList() 104153acd3b1SBarry Smith 104253acd3b1SBarry Smith Concepts: options database^list 104353acd3b1SBarry Smith 104453acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1045acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 104653acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 104753acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1048acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1049a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEnum() 105053acd3b1SBarry Smith @*/ 10518c34d3f5SBarry Smith PetscErrorCode PetscOptionsEList_Private(PetscOptions *PetscOptionsObject,const char opt[],const char ltext[],const char man[],const char *const *list,PetscInt ntext,const char currentvalue[],PetscInt *value,PetscBool *set) 105253acd3b1SBarry Smith { 105353acd3b1SBarry Smith PetscErrorCode ierr; 105453acd3b1SBarry Smith PetscInt i; 10558c34d3f5SBarry Smith PetscOption amsopt; 105653acd3b1SBarry Smith 105753acd3b1SBarry Smith PetscFunctionBegin; 10581a1499c8SBarry Smith if (!PetscOptionsObject->count) { 10591a1499c8SBarry Smith ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,ltext,man,OPTION_ELIST,&amsopt);CHKERRQ(ierr); 106064facd6cSBarry Smith /* must use system malloc since SAWs may free this */ 10610fdccdaeSBarry Smith ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr); 10621ae3d29cSBarry Smith amsopt->list = list; 10631ae3d29cSBarry Smith amsopt->nlist = ntext; 10641ae3d29cSBarry Smith } 10651a1499c8SBarry Smith ierr = PetscOptionsGetEList(PetscOptionsObject->prefix,opt,list,ntext,value,set);CHKERRQ(ierr); 10661a1499c8SBarry Smith if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 10671a1499c8SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%s> (choose one of)",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,currentvalue);CHKERRQ(ierr); 106853acd3b1SBarry Smith for (i=0; i<ntext; i++) { 1069e55864a3SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s",list[i]);CHKERRQ(ierr); 107053acd3b1SBarry Smith } 1071e55864a3SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," (%s)\n",ManSection(man));CHKERRQ(ierr); 107253acd3b1SBarry Smith } 107353acd3b1SBarry Smith PetscFunctionReturn(0); 107453acd3b1SBarry Smith } 107553acd3b1SBarry Smith 107653acd3b1SBarry Smith #undef __FUNCT__ 1077e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsBoolGroupBegin_Private" 107853acd3b1SBarry Smith /*@C 1079acfcf0e5SJed Brown PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for 1080d5649816SBarry Smith which at most a single value can be true. 108153acd3b1SBarry Smith 10823f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 108353acd3b1SBarry Smith 108453acd3b1SBarry Smith Input Parameters: 108553acd3b1SBarry Smith + opt - option name 108653acd3b1SBarry Smith . text - short string that describes the option 108753acd3b1SBarry Smith - man - manual page with additional information on option 108853acd3b1SBarry Smith 108953acd3b1SBarry Smith Output Parameter: 109053acd3b1SBarry Smith . flg - whether that option was set or not 109153acd3b1SBarry Smith 109253acd3b1SBarry Smith Level: intermediate 109353acd3b1SBarry Smith 109453acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 109553acd3b1SBarry Smith 1096acfcf0e5SJed Brown Must be followed by 0 or more PetscOptionsBoolGroup()s and PetscOptionsBoolGroupEnd() 109753acd3b1SBarry Smith 109853acd3b1SBarry Smith Concepts: options database^logical group 109953acd3b1SBarry Smith 110053acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1101acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 110253acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 110353acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1104acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1105a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList() 110653acd3b1SBarry Smith @*/ 11078c34d3f5SBarry Smith PetscErrorCode PetscOptionsBoolGroupBegin_Private(PetscOptions *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool *flg) 110853acd3b1SBarry Smith { 110953acd3b1SBarry Smith PetscErrorCode ierr; 11108c34d3f5SBarry Smith PetscOption amsopt; 111153acd3b1SBarry Smith 111253acd3b1SBarry Smith PetscFunctionBegin; 1113e55864a3SBarry Smith if (!PetscOptionsObject->count) { 111483355fc5SBarry Smith ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1115ace3abfcSBarry Smith ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1116a297a907SKarl Rupp 1117ace3abfcSBarry Smith *(PetscBool*)amsopt->data = PETSC_FALSE; 11181ae3d29cSBarry Smith } 111968b16fdaSBarry Smith *flg = PETSC_FALSE; 1120e55864a3SBarry Smith ierr = PetscOptionsGetBool(PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr); 1121e55864a3SBarry Smith if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1122e55864a3SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," Pick at most one of -------------\n");CHKERRQ(ierr); 1123e55864a3SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 112453acd3b1SBarry Smith } 112553acd3b1SBarry Smith PetscFunctionReturn(0); 112653acd3b1SBarry Smith } 112753acd3b1SBarry Smith 112853acd3b1SBarry Smith #undef __FUNCT__ 1129e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsBoolGroup_Private" 113053acd3b1SBarry Smith /*@C 1131acfcf0e5SJed Brown PetscOptionsBoolGroup - One in a series of logical queries on the options database for 1132d5649816SBarry Smith which at most a single value can be true. 113353acd3b1SBarry Smith 11343f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 113553acd3b1SBarry Smith 113653acd3b1SBarry Smith Input Parameters: 113753acd3b1SBarry Smith + opt - option name 113853acd3b1SBarry Smith . text - short string that describes the option 113953acd3b1SBarry Smith - man - manual page with additional information on option 114053acd3b1SBarry Smith 114153acd3b1SBarry Smith Output Parameter: 114253acd3b1SBarry Smith . flg - PETSC_TRUE if found, else PETSC_FALSE 114353acd3b1SBarry Smith 114453acd3b1SBarry Smith Level: intermediate 114553acd3b1SBarry Smith 114653acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 114753acd3b1SBarry Smith 1148acfcf0e5SJed Brown Must follow a PetscOptionsBoolGroupBegin() and preceded a PetscOptionsBoolGroupEnd() 114953acd3b1SBarry Smith 115053acd3b1SBarry Smith Concepts: options database^logical group 115153acd3b1SBarry Smith 115253acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1153acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 115453acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 115553acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1156acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1157a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList() 115853acd3b1SBarry Smith @*/ 11598c34d3f5SBarry Smith PetscErrorCode PetscOptionsBoolGroup_Private(PetscOptions *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool *flg) 116053acd3b1SBarry Smith { 116153acd3b1SBarry Smith PetscErrorCode ierr; 11628c34d3f5SBarry Smith PetscOption amsopt; 116353acd3b1SBarry Smith 116453acd3b1SBarry Smith PetscFunctionBegin; 1165e55864a3SBarry Smith if (!PetscOptionsObject->count) { 116683355fc5SBarry Smith ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1167ace3abfcSBarry Smith ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1168a297a907SKarl Rupp 1169ace3abfcSBarry Smith *(PetscBool*)amsopt->data = PETSC_FALSE; 11701ae3d29cSBarry Smith } 117117326d04SJed Brown *flg = PETSC_FALSE; 1172e55864a3SBarry Smith ierr = PetscOptionsGetBool(PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr); 1173e55864a3SBarry Smith if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1174e55864a3SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 117553acd3b1SBarry Smith } 117653acd3b1SBarry Smith PetscFunctionReturn(0); 117753acd3b1SBarry Smith } 117853acd3b1SBarry Smith 117953acd3b1SBarry Smith #undef __FUNCT__ 1180e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsBoolGroupEnd_Private" 118153acd3b1SBarry Smith /*@C 1182acfcf0e5SJed Brown PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for 1183d5649816SBarry Smith which at most a single value can be true. 118453acd3b1SBarry Smith 11853f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 118653acd3b1SBarry Smith 118753acd3b1SBarry Smith Input Parameters: 118853acd3b1SBarry Smith + opt - option name 118953acd3b1SBarry Smith . text - short string that describes the option 119053acd3b1SBarry Smith - man - manual page with additional information on option 119153acd3b1SBarry Smith 119253acd3b1SBarry Smith Output Parameter: 119353acd3b1SBarry Smith . flg - PETSC_TRUE if found, else PETSC_FALSE 119453acd3b1SBarry Smith 119553acd3b1SBarry Smith Level: intermediate 119653acd3b1SBarry Smith 119753acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 119853acd3b1SBarry Smith 1199acfcf0e5SJed Brown Must follow a PetscOptionsBoolGroupBegin() 120053acd3b1SBarry Smith 120153acd3b1SBarry Smith Concepts: options database^logical group 120253acd3b1SBarry Smith 120353acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1204acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 120553acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 120653acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1207acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1208a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList() 120953acd3b1SBarry Smith @*/ 12108c34d3f5SBarry Smith PetscErrorCode PetscOptionsBoolGroupEnd_Private(PetscOptions *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool *flg) 121153acd3b1SBarry Smith { 121253acd3b1SBarry Smith PetscErrorCode ierr; 12138c34d3f5SBarry Smith PetscOption amsopt; 121453acd3b1SBarry Smith 121553acd3b1SBarry Smith PetscFunctionBegin; 1216e55864a3SBarry Smith if (!PetscOptionsObject->count) { 121783355fc5SBarry Smith ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1218ace3abfcSBarry Smith ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1219a297a907SKarl Rupp 1220ace3abfcSBarry Smith *(PetscBool*)amsopt->data = PETSC_FALSE; 12211ae3d29cSBarry Smith } 122217326d04SJed Brown *flg = PETSC_FALSE; 1223e55864a3SBarry Smith ierr = PetscOptionsGetBool(PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr); 1224e55864a3SBarry Smith if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1225e55864a3SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 122653acd3b1SBarry Smith } 122753acd3b1SBarry Smith PetscFunctionReturn(0); 122853acd3b1SBarry Smith } 122953acd3b1SBarry Smith 123053acd3b1SBarry Smith #undef __FUNCT__ 1231e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsBool_Private" 123253acd3b1SBarry Smith /*@C 1233acfcf0e5SJed Brown PetscOptionsBool - Determines if a particular option is in the database with a true or false 123453acd3b1SBarry Smith 12353f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 123653acd3b1SBarry Smith 123753acd3b1SBarry Smith Input Parameters: 123853acd3b1SBarry Smith + opt - option name 123953acd3b1SBarry Smith . text - short string that describes the option 1240868c398cSBarry Smith . man - manual page with additional information on option 124194ae4db5SBarry Smith - currentvalue - the current value 124253acd3b1SBarry Smith 124353acd3b1SBarry Smith Output Parameter: 124453acd3b1SBarry Smith . flg - PETSC_TRUE or PETSC_FALSE 124553acd3b1SBarry Smith . set - PETSC_TRUE if found, else PETSC_FALSE 124653acd3b1SBarry Smith 124753acd3b1SBarry Smith Level: beginner 124853acd3b1SBarry Smith 124953acd3b1SBarry Smith Concepts: options database^logical 125053acd3b1SBarry Smith 125153acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 125253acd3b1SBarry Smith 125353acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 1254acfcf0e5SJed Brown PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 1255acfcf0e5SJed Brown PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 125653acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 125753acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1258acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1259a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList() 126053acd3b1SBarry Smith @*/ 12618c34d3f5SBarry Smith PetscErrorCode PetscOptionsBool_Private(PetscOptions *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool currentvalue,PetscBool *flg,PetscBool *set) 126253acd3b1SBarry Smith { 126353acd3b1SBarry Smith PetscErrorCode ierr; 1264ace3abfcSBarry Smith PetscBool iset; 12658c34d3f5SBarry Smith PetscOption amsopt; 126653acd3b1SBarry Smith 126753acd3b1SBarry Smith PetscFunctionBegin; 1268e55864a3SBarry Smith if (!PetscOptionsObject->count) { 1269e55864a3SBarry Smith ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr); 1270ace3abfcSBarry Smith ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr); 1271a297a907SKarl Rupp 127294ae4db5SBarry Smith *(PetscBool*)amsopt->data = currentvalue; 1273af6d86caSBarry Smith } 12741a1499c8SBarry Smith ierr = PetscOptionsGetBool(PetscOptionsObject->prefix,opt,flg,&iset);CHKERRQ(ierr); 127553acd3b1SBarry Smith if (set) *set = iset; 12761a1499c8SBarry Smith if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 127794ae4db5SBarry Smith const char *v = PetscBools[currentvalue]; 12781a1499c8SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s: <%s> %s (%s)\n",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,v,text,ManSection(man));CHKERRQ(ierr); 127953acd3b1SBarry Smith } 128053acd3b1SBarry Smith PetscFunctionReturn(0); 128153acd3b1SBarry Smith } 128253acd3b1SBarry Smith 128353acd3b1SBarry Smith #undef __FUNCT__ 1284e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsRealArray_Private" 128553acd3b1SBarry Smith /*@C 128653acd3b1SBarry Smith PetscOptionsRealArray - Gets an array of double values for a particular 128753acd3b1SBarry Smith option in the database. The values must be separated with commas with 128853acd3b1SBarry Smith no intervening spaces. 128953acd3b1SBarry Smith 12903f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 129153acd3b1SBarry Smith 129253acd3b1SBarry Smith Input Parameters: 129353acd3b1SBarry Smith + opt - the option one is seeking 129453acd3b1SBarry Smith . text - short string describing option 129553acd3b1SBarry Smith . man - manual page for option 129653acd3b1SBarry Smith - nmax - maximum number of values 129753acd3b1SBarry Smith 129853acd3b1SBarry Smith Output Parameter: 129953acd3b1SBarry Smith + value - location to copy values 130053acd3b1SBarry Smith . nmax - actual number of values found 130153acd3b1SBarry Smith - set - PETSC_TRUE if found, else PETSC_FALSE 130253acd3b1SBarry Smith 130353acd3b1SBarry Smith Level: beginner 130453acd3b1SBarry Smith 130553acd3b1SBarry Smith Notes: 130653acd3b1SBarry Smith The user should pass in an array of doubles 130753acd3b1SBarry Smith 130853acd3b1SBarry Smith Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 130953acd3b1SBarry Smith 131053acd3b1SBarry Smith Concepts: options database^array of strings 131153acd3b1SBarry Smith 131253acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1313acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 131453acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 131553acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1316acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1317a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList() 131853acd3b1SBarry Smith @*/ 13198c34d3f5SBarry Smith PetscErrorCode PetscOptionsRealArray_Private(PetscOptions *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool *set) 132053acd3b1SBarry Smith { 132153acd3b1SBarry Smith PetscErrorCode ierr; 132253acd3b1SBarry Smith PetscInt i; 13238c34d3f5SBarry Smith PetscOption amsopt; 132453acd3b1SBarry Smith 132553acd3b1SBarry Smith PetscFunctionBegin; 1326e55864a3SBarry Smith if (!PetscOptionsObject->count) { 1327e26ddf31SBarry Smith PetscReal *vals; 1328e26ddf31SBarry Smith 1329e55864a3SBarry Smith ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr); 1330e55864a3SBarry Smith ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr); 1331e26ddf31SBarry Smith vals = (PetscReal*)amsopt->data; 1332e26ddf31SBarry Smith for (i=0; i<*n; i++) vals[i] = value[i]; 1333e26ddf31SBarry Smith amsopt->arraylength = *n; 1334e26ddf31SBarry Smith } 1335e55864a3SBarry Smith ierr = PetscOptionsGetRealArray(PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr); 1336e55864a3SBarry Smith if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1337a519f713SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%g",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,(double)value[0]);CHKERRQ(ierr); 133853acd3b1SBarry Smith for (i=1; i<*n; i++) { 1339e55864a3SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%g",(double)value[i]);CHKERRQ(ierr); 134053acd3b1SBarry Smith } 1341e55864a3SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 134253acd3b1SBarry Smith } 134353acd3b1SBarry Smith PetscFunctionReturn(0); 134453acd3b1SBarry Smith } 134553acd3b1SBarry Smith 134653acd3b1SBarry Smith 134753acd3b1SBarry Smith #undef __FUNCT__ 1348e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsIntArray_Private" 134953acd3b1SBarry Smith /*@C 135053acd3b1SBarry Smith PetscOptionsIntArray - Gets an array of integers for a particular 1351b32a342fSShri Abhyankar option in the database. 135253acd3b1SBarry Smith 13533f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 135453acd3b1SBarry Smith 135553acd3b1SBarry Smith Input Parameters: 135653acd3b1SBarry Smith + opt - the option one is seeking 135753acd3b1SBarry Smith . text - short string describing option 135853acd3b1SBarry Smith . man - manual page for option 1359f8a50e2bSBarry Smith - n - maximum number of values 136053acd3b1SBarry Smith 136153acd3b1SBarry Smith Output Parameter: 136253acd3b1SBarry Smith + value - location to copy values 1363f8a50e2bSBarry Smith . n - actual number of values found 136453acd3b1SBarry Smith - set - PETSC_TRUE if found, else PETSC_FALSE 136553acd3b1SBarry Smith 136653acd3b1SBarry Smith Level: beginner 136753acd3b1SBarry Smith 136853acd3b1SBarry Smith Notes: 1369b32a342fSShri Abhyankar The array can be passed as 1370b32a342fSShri Abhyankar a comma seperated list: 0,1,2,3,4,5,6,7 13710fd488f5SShri Abhyankar a range (start-end+1): 0-8 13720fd488f5SShri Abhyankar a range with given increment (start-end+1:inc): 0-7:2 13730fd488f5SShri Abhyankar a combination of values and ranges seperated by commas: 0,1-8,8-15:2 1374b32a342fSShri Abhyankar 1375b32a342fSShri Abhyankar There must be no intervening spaces between the values. 137653acd3b1SBarry Smith 137753acd3b1SBarry Smith Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 137853acd3b1SBarry Smith 1379b32a342fSShri Abhyankar Concepts: options database^array of ints 138053acd3b1SBarry Smith 138153acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1382acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 138353acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 138453acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1385acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1386a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList(), PetscOptionsRealArray() 138753acd3b1SBarry Smith @*/ 13888c34d3f5SBarry Smith PetscErrorCode PetscOptionsIntArray_Private(PetscOptions *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool *set) 138953acd3b1SBarry Smith { 139053acd3b1SBarry Smith PetscErrorCode ierr; 139153acd3b1SBarry Smith PetscInt i; 13928c34d3f5SBarry Smith PetscOption amsopt; 139353acd3b1SBarry Smith 139453acd3b1SBarry Smith PetscFunctionBegin; 1395e55864a3SBarry Smith if (!PetscOptionsObject->count) { 1396e26ddf31SBarry Smith PetscInt *vals; 1397e26ddf31SBarry Smith 1398e55864a3SBarry Smith ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr); 1399854ce69bSBarry Smith ierr = PetscMalloc1(*n,(PetscInt**)&amsopt->data);CHKERRQ(ierr); 1400e26ddf31SBarry Smith vals = (PetscInt*)amsopt->data; 1401e26ddf31SBarry Smith for (i=0; i<*n; i++) vals[i] = value[i]; 1402e26ddf31SBarry Smith amsopt->arraylength = *n; 1403e26ddf31SBarry Smith } 1404e55864a3SBarry Smith ierr = PetscOptionsGetIntArray(PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr); 1405e55864a3SBarry Smith if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1406e55864a3SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%d",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,value[0]);CHKERRQ(ierr); 140753acd3b1SBarry Smith for (i=1; i<*n; i++) { 1408e55864a3SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%d",value[i]);CHKERRQ(ierr); 140953acd3b1SBarry Smith } 1410e55864a3SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 141153acd3b1SBarry Smith } 141253acd3b1SBarry Smith PetscFunctionReturn(0); 141353acd3b1SBarry Smith } 141453acd3b1SBarry Smith 141553acd3b1SBarry Smith #undef __FUNCT__ 1416e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsStringArray_Private" 141753acd3b1SBarry Smith /*@C 141853acd3b1SBarry Smith PetscOptionsStringArray - Gets an array of string values for a particular 141953acd3b1SBarry Smith option in the database. The values must be separated with commas with 142053acd3b1SBarry Smith no intervening spaces. 142153acd3b1SBarry Smith 14223f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 142353acd3b1SBarry Smith 142453acd3b1SBarry Smith Input Parameters: 142553acd3b1SBarry Smith + opt - the option one is seeking 142653acd3b1SBarry Smith . text - short string describing option 142753acd3b1SBarry Smith . man - manual page for option 142853acd3b1SBarry Smith - nmax - maximum number of strings 142953acd3b1SBarry Smith 143053acd3b1SBarry Smith Output Parameter: 143153acd3b1SBarry Smith + value - location to copy strings 143253acd3b1SBarry Smith . nmax - actual number of strings found 143353acd3b1SBarry Smith - set - PETSC_TRUE if found, else PETSC_FALSE 143453acd3b1SBarry Smith 143553acd3b1SBarry Smith Level: beginner 143653acd3b1SBarry Smith 143753acd3b1SBarry Smith Notes: 143853acd3b1SBarry Smith The user should pass in an array of pointers to char, to hold all the 143953acd3b1SBarry Smith strings returned by this function. 144053acd3b1SBarry Smith 144153acd3b1SBarry Smith The user is responsible for deallocating the strings that are 144253acd3b1SBarry Smith returned. The Fortran interface for this routine is not supported. 144353acd3b1SBarry Smith 144453acd3b1SBarry Smith Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 144553acd3b1SBarry Smith 144653acd3b1SBarry Smith Concepts: options database^array of strings 144753acd3b1SBarry Smith 144853acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1449acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 145053acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 145153acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1452acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1453a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList() 145453acd3b1SBarry Smith @*/ 14558c34d3f5SBarry Smith PetscErrorCode PetscOptionsStringArray_Private(PetscOptions *PetscOptionsObject,const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool *set) 145653acd3b1SBarry Smith { 145753acd3b1SBarry Smith PetscErrorCode ierr; 14588c34d3f5SBarry Smith PetscOption amsopt; 145953acd3b1SBarry Smith 146053acd3b1SBarry Smith PetscFunctionBegin; 1461e55864a3SBarry Smith if (!PetscOptionsObject->count) { 1462e55864a3SBarry Smith ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING_ARRAY,&amsopt);CHKERRQ(ierr); 1463854ce69bSBarry Smith ierr = PetscMalloc1(*nmax,(char**)&amsopt->data);CHKERRQ(ierr); 1464a297a907SKarl Rupp 14651ae3d29cSBarry Smith amsopt->arraylength = *nmax; 14661ae3d29cSBarry Smith } 1467e55864a3SBarry Smith ierr = PetscOptionsGetStringArray(PetscOptionsObject->prefix,opt,value,nmax,set);CHKERRQ(ierr); 1468e55864a3SBarry Smith if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1469e55864a3SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr); 147053acd3b1SBarry Smith } 147153acd3b1SBarry Smith PetscFunctionReturn(0); 147253acd3b1SBarry Smith } 147353acd3b1SBarry Smith 1474e2446a98SMatthew Knepley #undef __FUNCT__ 1475e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsBoolArray_Private" 1476e2446a98SMatthew Knepley /*@C 1477acfcf0e5SJed Brown PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular 1478e2446a98SMatthew Knepley option in the database. The values must be separated with commas with 1479e2446a98SMatthew Knepley no intervening spaces. 1480e2446a98SMatthew Knepley 14813f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 1482e2446a98SMatthew Knepley 1483e2446a98SMatthew Knepley Input Parameters: 1484e2446a98SMatthew Knepley + opt - the option one is seeking 1485e2446a98SMatthew Knepley . text - short string describing option 1486e2446a98SMatthew Knepley . man - manual page for option 1487e2446a98SMatthew Knepley - nmax - maximum number of values 1488e2446a98SMatthew Knepley 1489e2446a98SMatthew Knepley Output Parameter: 1490e2446a98SMatthew Knepley + value - location to copy values 1491e2446a98SMatthew Knepley . nmax - actual number of values found 1492e2446a98SMatthew Knepley - set - PETSC_TRUE if found, else PETSC_FALSE 1493e2446a98SMatthew Knepley 1494e2446a98SMatthew Knepley Level: beginner 1495e2446a98SMatthew Knepley 1496e2446a98SMatthew Knepley Notes: 1497e2446a98SMatthew Knepley The user should pass in an array of doubles 1498e2446a98SMatthew Knepley 1499e2446a98SMatthew Knepley Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1500e2446a98SMatthew Knepley 1501e2446a98SMatthew Knepley Concepts: options database^array of strings 1502e2446a98SMatthew Knepley 1503e2446a98SMatthew Knepley .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1504acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1505e2446a98SMatthew Knepley PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1506e2446a98SMatthew Knepley PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1507acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1508a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList() 1509e2446a98SMatthew Knepley @*/ 15108c34d3f5SBarry Smith PetscErrorCode PetscOptionsBoolArray_Private(PetscOptions *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set) 1511e2446a98SMatthew Knepley { 1512e2446a98SMatthew Knepley PetscErrorCode ierr; 1513e2446a98SMatthew Knepley PetscInt i; 15148c34d3f5SBarry Smith PetscOption amsopt; 1515e2446a98SMatthew Knepley 1516e2446a98SMatthew Knepley PetscFunctionBegin; 1517e55864a3SBarry Smith if (!PetscOptionsObject->count) { 1518ace3abfcSBarry Smith PetscBool *vals; 15191ae3d29cSBarry Smith 152083355fc5SBarry Smith ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL_ARRAY,&amsopt);CHKERRQ(ierr); 15211a1499c8SBarry Smith ierr = PetscMalloc1(*n,(PetscBool**)&amsopt->data);CHKERRQ(ierr); 1522ace3abfcSBarry Smith vals = (PetscBool*)amsopt->data; 15231ae3d29cSBarry Smith for (i=0; i<*n; i++) vals[i] = value[i]; 15241ae3d29cSBarry Smith amsopt->arraylength = *n; 15251ae3d29cSBarry Smith } 1526e55864a3SBarry Smith ierr = PetscOptionsGetBoolArray(PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr); 1527e55864a3SBarry Smith if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1528e55864a3SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%d",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,value[0]);CHKERRQ(ierr); 1529e2446a98SMatthew Knepley for (i=1; i<*n; i++) { 1530e55864a3SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%d",value[i]);CHKERRQ(ierr); 1531e2446a98SMatthew Knepley } 1532e55864a3SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr); 1533e2446a98SMatthew Knepley } 1534e2446a98SMatthew Knepley PetscFunctionReturn(0); 1535e2446a98SMatthew Knepley } 1536e2446a98SMatthew Knepley 15378cc676e6SMatthew G Knepley #undef __FUNCT__ 1538e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsViewer_Private" 15398cc676e6SMatthew G Knepley /*@C 1540d1da0b69SBarry Smith PetscOptionsViewer - Gets a viewer appropriate for the type indicated by the user 15418cc676e6SMatthew G Knepley 15428cc676e6SMatthew G Knepley Logically Collective on the communicator passed in PetscOptionsBegin() 15438cc676e6SMatthew G Knepley 15448cc676e6SMatthew G Knepley Input Parameters: 15458cc676e6SMatthew G Knepley + opt - option name 15468cc676e6SMatthew G Knepley . text - short string that describes the option 15478cc676e6SMatthew G Knepley - man - manual page with additional information on option 15488cc676e6SMatthew G Knepley 15498cc676e6SMatthew G Knepley Output Parameter: 15508cc676e6SMatthew G Knepley + viewer - the viewer 15518cc676e6SMatthew G Knepley - set - PETSC_TRUE if found, else PETSC_FALSE 15528cc676e6SMatthew G Knepley 15538cc676e6SMatthew G Knepley Level: beginner 15548cc676e6SMatthew G Knepley 15558cc676e6SMatthew G Knepley Concepts: options database^has int 15568cc676e6SMatthew G Knepley 15578cc676e6SMatthew G Knepley Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 15588cc676e6SMatthew G Knepley 15595a7113b9SPatrick Sanan See PetscOptionsGetViewer() for the format of the supplied viewer and its options 15608cc676e6SMatthew G Knepley 15618cc676e6SMatthew G Knepley .seealso: PetscOptionsGetViewer(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 15628cc676e6SMatthew G Knepley PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 15638cc676e6SMatthew G Knepley PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 15648cc676e6SMatthew G Knepley PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 15658cc676e6SMatthew G Knepley PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 15668cc676e6SMatthew G Knepley PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1567a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList() 15688cc676e6SMatthew G Knepley @*/ 15698c34d3f5SBarry Smith PetscErrorCode PetscOptionsViewer_Private(PetscOptions *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool *set) 15708cc676e6SMatthew G Knepley { 15718cc676e6SMatthew G Knepley PetscErrorCode ierr; 15728c34d3f5SBarry Smith PetscOption amsopt; 15738cc676e6SMatthew G Knepley 15748cc676e6SMatthew G Knepley PetscFunctionBegin; 15751a1499c8SBarry Smith if (!PetscOptionsObject->count) { 15761a1499c8SBarry Smith ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr); 157764facd6cSBarry Smith /* must use system malloc since SAWs may free this */ 15785b02f95dSBarry Smith ierr = PetscStrdup("",(char**)&amsopt->data);CHKERRQ(ierr); 15798cc676e6SMatthew G Knepley } 1580e55864a3SBarry Smith ierr = PetscOptionsGetViewer(PetscOptionsObject->comm,PetscOptionsObject->prefix,opt,viewer,format,set);CHKERRQ(ierr); 1581e55864a3SBarry Smith if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1582e55864a3SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," -%s%s <%s>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,"",text,ManSection(man));CHKERRQ(ierr); 15838cc676e6SMatthew G Knepley } 15848cc676e6SMatthew G Knepley PetscFunctionReturn(0); 15858cc676e6SMatthew G Knepley } 15868cc676e6SMatthew G Knepley 158753acd3b1SBarry Smith 158853acd3b1SBarry Smith #undef __FUNCT__ 158953acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsHead" 159053acd3b1SBarry Smith /*@C 1591b52f573bSBarry Smith PetscOptionsHead - Puts a heading before listing any more published options. Used, for example, 159253acd3b1SBarry Smith in KSPSetFromOptions_GMRES(). 159353acd3b1SBarry Smith 15943f9fe445SBarry Smith Logically Collective on the communicator passed in PetscOptionsBegin() 159553acd3b1SBarry Smith 159653acd3b1SBarry Smith Input Parameter: 159753acd3b1SBarry Smith . head - the heading text 159853acd3b1SBarry Smith 159953acd3b1SBarry Smith 160053acd3b1SBarry Smith Level: intermediate 160153acd3b1SBarry Smith 160253acd3b1SBarry Smith Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 160353acd3b1SBarry Smith 1604b52f573bSBarry Smith Can be followed by a call to PetscOptionsTail() in the same function. 160553acd3b1SBarry Smith 160653acd3b1SBarry Smith Concepts: options database^subheading 160753acd3b1SBarry Smith 160853acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1609acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 161053acd3b1SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 161153acd3b1SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1612acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1613a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList() 161453acd3b1SBarry Smith @*/ 16158c34d3f5SBarry Smith PetscErrorCode PetscOptionsHead(PetscOptions *PetscOptionsObject,const char head[]) 161653acd3b1SBarry Smith { 161753acd3b1SBarry Smith PetscErrorCode ierr; 161853acd3b1SBarry Smith 161953acd3b1SBarry Smith PetscFunctionBegin; 1620e55864a3SBarry Smith if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) { 1621e55864a3SBarry Smith ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s\n",head);CHKERRQ(ierr); 162253acd3b1SBarry Smith } 162353acd3b1SBarry Smith PetscFunctionReturn(0); 162453acd3b1SBarry Smith } 162553acd3b1SBarry Smith 162653acd3b1SBarry Smith 162753acd3b1SBarry Smith 162853acd3b1SBarry Smith 162953acd3b1SBarry Smith 163053acd3b1SBarry Smith 1631