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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 #include "Optika_GUI.hpp"
00042 #include "Teuchos_XMLParameterListHelpers.hpp"
00043 #include "Teuchos_VerboseObject.hpp"
00044 #include "Teuchos_ParameterEntryXMLConverterDB.hpp"
00045 
00046 using Teuchos::RCP;
00047 using Teuchos::ParameterList;
00048 using Teuchos::tuple;
00049 using Teuchos::StringValidator;
00050 using Teuchos::Array;
00051 using Teuchos::VerboseObjectBase;
00052 using Teuchos::FancyOStream;
00053 
00054 int main(int argc, char* argv[])
00055 {
00056  /*
00057   * Welcome to the Optika Package!
00058   *
00059   * This package was designed to assist in the rapid development of GUIs for 
00060   * existing and new projects using the Trilinos Framework. Using the 
00061   * ParameterList class found in the Teuchos package and the DependencySheet
00062   * class also provided by the Teuchos Package, Optika will allow you to use 
00063   * ParameterLists to define a set of values you wish to obtain from
00064   * the user. You may then pass this ParameterList to the function getInput. 
00065   * This function will dynamically generate a GUI based on your ParameterList, 
00066   * display the GUI to the user, obtain input from the user, and then store 
00067   * the users input back into the ParameterList. 
00068   *
00069   * Let's take a look at an example to see how this all works.
00070   *
00071   * Before you Start:
00072   * We recommend you have at least a basic understanding of what a RCP is. 
00073   * While not * crucial to the understanding of these examples, undestanding 
00074   * RCPs allow you to more easily read what is going on in the examples.
00075   */
00076 
00077 
00078   /* 
00079    * First we create an empty parameter list. We will use this to define
00080    * all of the parameters we wish to obtain from the user. This type of 
00081    * ParameterList is commonly known as the "Valid Parameter List".
00082    */
00083   RCP<ParameterList> My_List = RCP<ParameterList>(new ParameterList);
00084 
00085   /* 
00086    * Creating parameters in this list can be easily done using the set function.
00087    * The first argument is the name of the parameter. The second is the default
00088    * value for the parameter. The third is a short description of what the 
00089    * parameter is for.
00090    */
00091   My_List->set(
00092     "Max Iters", 
00093     1550, 
00094     "Determines the maximum number of iterations in the solver");
00095 
00096   My_List->set(
00097     "Tolerance", 
00098     1e-10,
00099     "The tolerance used for the convergence check");
00100   
00101   /* 
00102    * Validators are useful for restricting the set of values that may be used 
00103    * for a given parameter. For the "Solver" option, we will create a 
00104    * validator. Here we use a StringValidator and a tuple to specify which 
00105    * string values are valid for the "Solver" option.
00106    */
00107   RCP<StringValidator> solverValidator = 
00108      RCP<StringValidator>(new StringValidator(
00109       tuple<std::string>("GMRES", "CG", "TFQMR")));
00110 
00111   My_List->set(
00112     "Solver", 
00113     "GMRES", 
00114     "The type of solver to use.", 
00115     solverValidator);
00116 
00117   /* 
00118    * The Optika Package can also handle Teuchos Arrays.
00119    * Here we create a Array object of 10 doubles
00120    * representing an initial guess for a linear solver.
00121    */
00122   Array<double> doubleArray( 10, 0.0 );
00123   My_List->set(
00124     "Initial Guess", 
00125     doubleArray, 
00126     "The initial guess as an array object.");
00127 
00128   /* 
00129    * We can also create a hieiarchy of parameters by using sublists. Here we 
00130    * create a sublist called Prec_List. Prec_List will be contained within 
00131    * My_List.
00132    */
00133   ParameterList& Prec_List = My_List->sublist(
00134     "Preconditioner",
00135     false,
00136     "Sublist that defines the preconditioner.");
00137 
00138   /*
00139    * Now this Prec_List can be filled with other parameters:
00140    */
00141   Prec_List.set("Type", "ILU", "The tpye of preconditioner to use");
00142   Prec_List.set("Drop Tolerance", 1e-3
00143                 ,"The tolerance below which entries from the\n"
00144                 "factorization are left out of the factors.");
00145 
00146   /*
00147    * The getInput function starts up an Optika GUI and lets the user start to 
00148    * input parameter values. When the user  has completed their data entry, 
00149    * the function will finish right after all of the input values are stored 
00150    * in My_List.
00151    */
00152   Optika::getInput(My_List);
00153 
00154   /*
00155    * Here we can print out what the user entered in nice XML format.
00156    */
00157   RCP<FancyOStream> out = VerboseObjectBase::getDefaultOStream();
00158   writeParameterListToXmlOStream(*My_List, *out);
00159   
00160 
00161   /*
00162    * A Few Final Notes
00163    *
00164    * -After calling the getInput function, any parameter in My_List has the 
00165    *  potential to have been modified.
00166    *  That said, no new parameters or ParameterLists will have been added and 
00167    *  none will have been removed.
00168    *
00169    * -The GUI can only handle certain types of parameters. They are:
00170    *  int
00171    *  short
00172    *  double
00173    *  float
00174    *  bool
00175    *  std::string
00176    *  Array<int>
00177    *  Array<short>
00178    *  Array<double>
00179    *  Array<float>
00180    *  Array<string>
00181    * If you give it a ParameterList containing a parameter that is not of one 
00182    * of the types specified above, the parameter will still be displayed in 
00183    * the GUI. However, the user will not be able to modify it's value.
00184    *
00185    * That's it for now. Be sure check out the other examples to see some of 
00186    * the more advanced features of the Optika package. If you have any 
00187    * suggestions or feature requests, please send them to klnusbaum@gmail.com.
00188    */
00189   Teuchos::ParameterEntryXMLConverterDB::printKnownConverters(*out);
00190   return 0;
00191 }
00192 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines