Optika GUI Toolik Version of the Day
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 "Optika_GUI.hpp"
00029 #include "Teuchos_XMLParameterListHelpers.hpp"
00030 #include "Teuchos_VerboseObject.hpp"
00031 #include "Teuchos_ParameterEntryXMLConverterDB.hpp"
00032 
00033 using Teuchos::RCP;
00034 using Teuchos::ParameterList;
00035 using Teuchos::tuple;
00036 using Teuchos::StringValidator;
00037 using Teuchos::Array;
00038 using Teuchos::VerboseObjectBase;
00039 using Teuchos::FancyOStream;
00040 
00041 int main(int argc, char* argv[])
00042 {
00043  /*
00044   * Welcome to the Optika Package!
00045   *
00046   * This package was designed to assist in the rapid development of GUIs for 
00047   * existing and new projects using the Trilinos Framework. Using the 
00048   * ParameterList class found in the Teuchos package and the DependencySheet
00049   * class also provided by the Teuchos Package, Optika will allow you to use 
00050   * ParameterLists to define a set of values you wish to obtain from
00051   * the user. You may then pass this ParameterList to the function getInput. 
00052   * This function will dynamically generate a GUI based on your ParameterList, 
00053   * display the GUI to the user, obtain input from the user, and then store 
00054   * the users input back into the ParameterList. 
00055   *
00056   * Let's take a look at an example to see how this all works.
00057   *
00058   * Before you Start:
00059   * We recommend you have at least a basic understanding of what a RCP is. 
00060   * While not * crucial to the understanding of these examples, undestanding 
00061   * RCPs allow you to more easily read what is going on in the examples.
00062   */
00063 
00064 
00065   /* 
00066    * First we create an empty parameter list. We will use this to define
00067    * all of the parameters we wish to obtain from the user. This type of 
00068    * ParameterList is commonly known as the "Valid Parameter List".
00069    */
00070   RCP<ParameterList> My_List = RCP<ParameterList>(new ParameterList);
00071 
00072   /* 
00073    * Creating parameters in this list can be easily done using the set function.
00074    * The first argument is the name of the parameter. The second is the default
00075    * value for the parameter. The third is a short description of what the 
00076    * parameter is for.
00077    */
00078   My_List->set(
00079     "Max Iters", 
00080     1550, 
00081     "Determines the maximum number of iterations in the solver");
00082 
00083   My_List->set(
00084     "Tolerance", 
00085     1e-10,
00086     "The tolerance used for the convergence check");
00087   
00088   /* 
00089    * Validators are useful for restricting the set of values that may be used 
00090    * for a given parameter. For the "Solver" option, we will create a 
00091    * validator. Here we use a StringValidator and a tuple to specify which 
00092    * string values are valid for the "Solver" option.
00093    */
00094   RCP<StringValidator> solverValidator = 
00095      RCP<StringValidator>(new StringValidator(
00096       tuple<std::string>("GMRES", "CG", "TFQMR")));
00097 
00098   My_List->set(
00099     "Solver", 
00100     "GMRES", 
00101     "The type of solver to use.", 
00102     solverValidator);
00103 
00104   /* 
00105    * The Optika Package can also handle Teuchos Arrays.
00106    * Here we create a Array object of 10 doubles
00107    * representing an initial guess for a linear solver.
00108    */
00109   Array<double> doubleArray( 10, 0.0 );
00110   My_List->set(
00111     "Initial Guess", 
00112     doubleArray, 
00113     "The initial guess as an array object.");
00114 
00115   /* 
00116    * We can also create a hieiarchy of parameters by using sublists. Here we 
00117    * create a sublist called Prec_List. Prec_List will be contained within 
00118    * My_List.
00119    */
00120   ParameterList& Prec_List = My_List->sublist(
00121     "Preconditioner",
00122     false,
00123     "Sublist that defines the preconditioner.");
00124 
00125   /*
00126    * Now this Prec_List can be filled with other parameters:
00127    */
00128   Prec_List.set("Type", "ILU", "The tpye of preconditioner to use");
00129   Prec_List.set("Drop Tolerance", 1e-3
00130                 ,"The tolerance below which entries from the\n"
00131                 "factorization are left out of the factors.");
00132 
00133   /*
00134    * The getInput function starts up an Optika GUI and lets the user start to 
00135    * input parameter values. When the user  has completed their data entry, 
00136    * the function will finish right after all of the input values are stored 
00137    * in My_List.
00138    */
00139   Optika::getInput(My_List);
00140 
00141   /*
00142    * Here we can print out what the user entered in nice XML format.
00143    */
00144   RCP<FancyOStream> out = VerboseObjectBase::getDefaultOStream();
00145   writeParameterListToXmlOStream(*My_List, *out);
00146   
00147 
00148   /*
00149    * A Few Final Notes
00150    *
00151    * -After calling the getInput function, any parameter in My_List has the 
00152    *  potential to have been modified.
00153    *  That said, no new parameters or ParameterLists will have been added and 
00154    *  none will have been removed.
00155    *
00156    * -The GUI can only handle certain types of parameters. They are:
00157    *  int
00158    *  short
00159    *  double
00160    *  float
00161    *  bool
00162    *  std::string
00163    *  Array<int>
00164    *  Array<short>
00165    *  Array<double>
00166    *  Array<float>
00167    *  Array<string>
00168    * If you give it a ParameterList containing a parameter that is not of one 
00169    * of the types specified above, the parameter will still be displayed in 
00170    * the GUI. However, the user will not be able to modify it's value.
00171    *
00172    * That's it for now. Be sure check out the other examples to see some of 
00173    * the more advanced features of the Optika package. If you have any 
00174    * suggestions or feature requests, please send them to klnusbaum@gmail.com.
00175    */
00176   Teuchos::ParameterEntryXMLConverterDB::printKnownConverters(*out);
00177   return 0;
00178 }
00179 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines