Optika GUI Toolik  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
example/BasicExample/main.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Optika: A Tool For Developing Parameter Obtaining GUIs
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the
8 // U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com)
38 //
39 // ***********************************************************************
40 // @HEADER
41 #include "Optika_GUI.hpp"
45 
46 using Teuchos::RCP;
48 using Teuchos::tuple;
50 using Teuchos::Array;
53 
54 int main(int argc, char* argv[])
55 {
56  /*
57  * Welcome to the Optika Package!
58  *
59  * This package was designed to assist in the rapid development of GUIs for
60  * existing and new projects using the Trilinos Framework. Using the
61  * ParameterList class found in the Teuchos package and the DependencySheet
62  * class also provided by the Teuchos Package, Optika will allow you to use
63  * ParameterLists to define a set of values you wish to obtain from
64  * the user. You may then pass this ParameterList to the function getInput.
65  * This function will dynamically generate a GUI based on your ParameterList,
66  * display the GUI to the user, obtain input from the user, and then store
67  * the users input back into the ParameterList.
68  *
69  * Let's take a look at an example to see how this all works.
70  *
71  * Before you Start:
72  * We recommend you have at least a basic understanding of what a RCP is.
73  * While not * crucial to the understanding of these examples, undestanding
74  * RCPs allow you to more easily read what is going on in the examples.
75  */
76 
77 
78  /*
79  * First we create an empty parameter list. We will use this to define
80  * all of the parameters we wish to obtain from the user. This type of
81  * ParameterList is commonly known as the "Valid Parameter List".
82  */
84 
85  /*
86  * Creating parameters in this list can be easily done using the set function.
87  * The first argument is the name of the parameter. The second is the default
88  * value for the parameter. The third is a short description of what the
89  * parameter is for.
90  */
91  My_List->set(
92  "Max Iters",
93  1550,
94  "Determines the maximum number of iterations in the solver");
95 
96  My_List->set(
97  "Tolerance",
98  1e-10,
99  "The tolerance used for the convergence check");
100 
101  /*
102  * Validators are useful for restricting the set of values that may be used
103  * for a given parameter. For the "Solver" option, we will create a
104  * validator. Here we use a StringValidator and a tuple to specify which
105  * string values are valid for the "Solver" option.
106  */
107  RCP<StringValidator> solverValidator =
109  tuple<std::string>("GMRES", "CG", "TFQMR")));
110 
111  My_List->set(
112  "Solver",
113  "GMRES",
114  "The type of solver to use.",
115  solverValidator);
116 
117  /*
118  * The Optika Package can also handle Teuchos Arrays.
119  * Here we create a Array object of 10 doubles
120  * representing an initial guess for a linear solver.
121  */
122  Array<double> doubleArray( 10, 0.0 );
123  My_List->set(
124  "Initial Guess",
125  doubleArray,
126  "The initial guess as an array object.");
127 
128  /*
129  * We can also create a hieiarchy of parameters by using sublists. Here we
130  * create a sublist called Prec_List. Prec_List will be contained within
131  * My_List.
132  */
133  ParameterList& Prec_List = My_List->sublist(
134  "Preconditioner",
135  false,
136  "Sublist that defines the preconditioner.");
137 
138  /*
139  * Now this Prec_List can be filled with other parameters:
140  */
141  Prec_List.set("Type", "ILU", "The tpye of preconditioner to use");
142  Prec_List.set("Drop Tolerance", 1e-3
143  ,"The tolerance below which entries from the\n"
144  "factorization are left out of the factors.");
145 
146  /*
147  * The getInput function starts up an Optika GUI and lets the user start to
148  * input parameter values. When the user has completed their data entry,
149  * the function will finish right after all of the input values are stored
150  * in My_List.
151  */
152  Optika::getInput(My_List);
153 
154  /*
155  * Here we can print out what the user entered in nice XML format.
156  */
157  RCP<FancyOStream> out = VerboseObjectBase::getDefaultOStream();
158  writeParameterListToXmlOStream(*My_List, *out);
159 
160 
161  /*
162  * A Few Final Notes
163  *
164  * -After calling the getInput function, any parameter in My_List has the
165  * potential to have been modified.
166  * That said, no new parameters or ParameterLists will have been added and
167  * none will have been removed.
168  *
169  * -The GUI can only handle certain types of parameters. They are:
170  * int
171  * short
172  * double
173  * float
174  * bool
175  * std::string
176  * Array<int>
177  * Array<short>
178  * Array<double>
179  * Array<float>
180  * Array<string>
181  * If you give it a ParameterList containing a parameter that is not of one
182  * of the types specified above, the parameter will still be displayed in
183  * the GUI. However, the user will not be able to modify it's value.
184  *
185  * That's it for now. Be sure check out the other examples to see some of
186  * the more advanced features of the Optika package. If you have any
187  * suggestions or feature requests, please send them to klnusbaum@gmail.com.
188  */
190  return 0;
191 }
192 
int main(int argc, char *argv[])
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
A collection of functions and an Object that serve as the primary interface to the Optika package all...
RCP< ParameterList > sublist(const RCP< ParameterList > &paramList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
void getInput(RCP< ParameterList > validParameters, RCP< DependencySheet > dependencySheet, void(*customFunc)(RCP< const ParameterList >))
Retreives the input for a Teuchos Parameter List using a GUI. Note the Parameter List will be edited...
Definition: Optika_GUI.cpp:47
static void printKnownConverters(std::ostream &out)
basic_FancyOStream< char > FancyOStream