example/CustomFunctionExample/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    * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
00038    * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!              ATTENTION              !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00039    * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00040    * !!!!   PLEASE VIEW THE BASIC EXAMPLE FIRST BEFORE READING THIS EXAMPLE. IT PROVIDES FUNDAMENTAL    !!!! 
00041    * !!!!   KNOWLEDGE THAT WILL BE VERY HELPFUL IN UNDERSTANDING THIS EXAMPLE.                          !!!!
00042    * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00043    * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00044    */ 
00045 
00046 /*
00047  * Don't worry about this little guy right now. We'll come back to it later.
00048  * We just needed to prototype it.
00049  */
00050 void customFunction(Teuchos::RCP<const Teuchos::ParameterList> currentParams);
00051 
00052 int main(int argc, char* argv[])
00053 {
00054   /*
00055    * Sometimes, you would rather have a slightly different workflow than the one Optika offers by default.
00056    * This is why Optika also offers a second, tighter workflow that goes like this:
00057    *  1. Construct a Parameter List of inputs.
00058    *  2. Create a function which will run given the inputs.
00059    *  3. Call getInput() like normal, except also pass the memory address of the function.
00060    *  4. Everytime the user clicks the submit button on the GUI, your custom function will run.
00061    *  5. The user may click quit when they are finished and control will be returned to you.
00062    * This alternative workflow allows the user to quickly tweak and re-try different parameter
00063    * configurations.
00064    */
00065 
00066   /*
00067    * We start off like normal. I'm actually just going to repeat what we did in the BasicExample
00068    */
00069   Teuchos::RCP<Teuchos::ParameterList> My_List = Teuchos::RCP<Teuchos::ParameterList>(new Teuchos::ParameterList);
00070 
00071   My_List->set("Max Iters", 1550, "Determines the maximum number of iterations in the solver");
00072   My_List->set("Tolerance", 1e-10, "The tolerance used for the convergence check");
00073   
00074   Teuchos::RCP<Optika::StringValidator> solverValidator = 
00075      Teuchos::RCP<Optika::StringValidator>(new Optika::StringValidator(Teuchos::tuple<std::string>("GMRES", "CG", "TFQMR")));
00076   My_List->set( "Solver", "GMRES", "The type of solver to use.", solverValidator);
00077 
00078   Teuchos::Array<double> doubleArray( 10, 0.0 );
00079   My_List->set("Initial Guess", doubleArray, "The initial guess as a RCP to an array object.");
00080 
00081   Teuchos::ParameterList&
00082     Prec_List = My_List->sublist("Preconditioner",false,"Sublist that defines the preconditioner.");
00083 
00084   Prec_List.set("Type", "ILU", "The tpye of preconditioner to use");
00085   Prec_List.set("Drop Tolerance", 1e-3
00086                 ,"The tolerance below which entries from the\n""factorization are left out of the factors.");
00087   /*
00088    * Here is where things get switched up a bit. Along with the list, we pass along the address of the
00089    * "customFunction". Let's skip down a bit and take a look at the function.
00090    */
00091   Optika::getInput(My_List, &customFunction);
00092 
00093   Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
00094   Teuchos::writeParameterListToXmlOStream(*My_List, *out);
00095   
00096   return 0;
00097 }
00098 
00099 /*
00100  * The custom function must always have this signature (returning void and taking a single RCP<const ParameterList> parameter).
00101  * When the user clicks submit the function will be called. The current values for the parameter list are what will be 
00102  * given as the argument. Here we simply read what some of the settings the user has selected and print them out.
00103  * But in theory, you could do anything you want with the parameters at this point.
00104  * The GUI will terminate once the user exits (by some means of closing the GUI window), and control will be returned back
00105  * to what ever function called getInput() (in this case the main()).
00106  */
00107 void customFunction(Teuchos::RCP<const Teuchos::ParameterList> currentParams){
00108   std::cout << "The Solver Choosen was: " << currentParams->get<std::string>("Solver") << "\n";
00109   std::cout << "The Tolerence choosen was: " << currentParams->get<double>("Tolerance") << "\n"; 
00110   std::cout << "The Preconditioner type was set to: " << currentParams->sublist("Preconditioner").get<std::string>("Type") << "\n";
00111 }
00112 
 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