example/BasicExample/main.cpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //         Optika: A Tool For Developing Parameter Obtaining GUIs
00005 //                Copyright (2009) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the 
00008 // U.S. Government retains certain rights in this software.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 #include "Teuchos_ParameterList.hpp"
00029 #include "Teuchos_StandardParameterEntryValidators.hpp"
00030 #include "Teuchos_Array.hpp"  
00031 #include "Teuchos_Version.hpp"
00032 #include "Optika_GUI.hpp"
00033 #include "Teuchos_XMLParameterListHelpers.hpp"
00034 #include "Teuchos_FancyOStream.hpp"
00035 #include "Teuchos_VerboseObject.hpp"
00036 
00037 int main(int argc, char* argv[])
00038 {
00039  /*
00040   * Welcome to the Optika Package!
00041   *
00042   * This package was designed to assist in the rapid development of GUIs for existing and new 
00043   * projects using the Trilinos Framework. Using the ParameterList class found in the Teuchos 
00044   * package and the new Dependency Sheet class provided by the Optika Package, this package
00045   * will allow you to use ParameterLists to define a set of values you wish to obtain from
00046   * the user. You may then pass this ParameterList to the function getInput. This function 
00047   * will dynamically generate a GUI based on your ParameterList, display the GUI to the user, 
00048   * obtain input from the user, and then store the users input back into the ParameterList. 
00049   * Let's take a look at an example to see how this all works.
00050   *
00051   * Before you Start:
00052   * We recommend you have at least a basic understanding of what a Teuchos::RCP is. While not
00053   * crucial to the understanding of these examples, undestanding RCPs allow you to more
00054   * easily understand what is going on in the examples.
00055   */
00056 
00057   /* 
00058    * First we create an empty parameter list. We will use this to define
00059    * all of the parameters we wish to obtain from the user. This type of 
00060    * ParameterList is commonly known as the "Valid Parameter List".
00061    */
00062   Teuchos::RCP<Teuchos::ParameterList> My_List = Teuchos::RCP<Teuchos::ParameterList>(new Teuchos::ParameterList);
00063 
00064   /* 
00065    * Creating parameters in this list can be easily done using the set function.
00066    * The first argument is the name of the parameter. The second is the default
00067    * value for the parameter. The third is a short description of what the parameter 
00068    * is for.
00069    */
00070   My_List->set("Max Iters", 1550, "Determines the maximum number of iterations in the solver");
00071   My_List->set("Tolerance", 1e-10, "The tolerance used for the convergence check");
00072   
00073   /* 
00074    * Validators are useful for restricting the set of values that may be used for a
00075    * given parameter. For the "Solver" option, we will create a validator. Here we use a 
00076    * StringValidator and a tuple to specify which string values
00077    * are valid for the "Solver" option.
00078    */
00079   Teuchos::RCP<Optika::StringValidator> solverValidator = 
00080      Teuchos::RCP<Optika::StringValidator>(new Optika::StringValidator(Teuchos::tuple<std::string>("GMRES", "CG", "TFQMR")));
00081   My_List->set( "Solver", "GMRES", "The type of solver to use.", solverValidator);
00082 
00083   /* 
00084    * The Optika Package can also handle Teuchos Arrays.
00085    * Here we create a Teuchos::Array object of 10 doubles
00086    * representing an initial guess for a linear solver.
00087    */
00088   Teuchos::Array<double> doubleArray( 10, 0.0 );
00089   My_List->set("Initial Guess", doubleArray, "The initial guess as a RCP to an array object.");
00090 
00091   /* 
00092    * We can also create a hieiarchy of parameters by using sublists. Here we create a sublist
00093    * called Prec_List. Prec_List will be contained within My_List.
00094    */
00095   Teuchos::ParameterList&
00096     Prec_List = My_List->sublist("Preconditioner",false,"Sublist that defines the preconditioner.");
00097 
00098   /*
00099    * Now this Prec_List can be filled with other parameters:
00100    */
00101   Prec_List.set("Type", "ILU", "The tpye of preconditioner to use");
00102   Prec_List.set("Drop Tolerance", 1e-3
00103                 ,"The tolerance below which entries from the\n""factorization are left out of the factors.");
00104 
00105   /*
00106    * The getInput function starts up an Optika GUI and lets the user start to input parameter values. When the user
00107    * has completed their data entry, the function will finish right after all of the input values are stored in My_List.
00108    */
00109   Optika::getInput(My_List);
00110 
00111   /*
00112    * Here we can print out what the user entered in nice XML format.
00113    */
00114   Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
00115   Teuchos::writeParameterListToXmlOStream(*My_List, *out);
00116   
00117 
00118   /*
00119    * A Few Final Notes
00120    *
00121    * -After calling the getInput function, any parameter in My_List has the potential to have been modified.
00122    *  That said, no new parameters or ParameterLists will have been added and none will have been removed.
00123    *
00124    * -The GUI can only handle certain types of parameters. They are:
00125    *  int
00126    *  short
00127    *  double
00128    *  float
00129    *  bool
00130    *  std::string
00131    *  Teuchos::Array<int>
00132    *  Teuchos::Array<short>
00133    *  Teuchos::Array<double>
00134    *  Teuchos::Array<float>
00135    *  Teuchos::Array<string>
00136    * If you give it a ParameterList containing a parameter that is not of one of the types specified above,
00137    * the parameter will still be displayed in the GUI. However, the user will not be able to modify it's value.
00138    *
00139    * That's it for now. Be sure check out the other examples to see some of the more advanced 
00140    * features of the Optika package. If you have any suggestions or feature requests, please send them to
00141    * klnusbaum@gmail.com.
00142    */
00143   return 0;
00144 }
00145 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Generated on Wed Apr 13 10:05:58 2011 for Optika GUI Toolik by  doxygen 1.6.3