ThyraDiagonalQuadraticResponseOnlyOptMain.cpp

00001 #include "MoochoPack_MoochoThyraSolver.hpp"
00002 #include "Thyra_DiagonalQuadraticResponseOnlyModelEvaluator.hpp"
00003 #include "Thyra_VectorStdOps.hpp"
00004 #include "Teuchos_GlobalMPISession.hpp"
00005 #include "Teuchos_CommandLineProcessor.hpp"
00006 #include "Teuchos_StandardCatchMacros.hpp"
00007 #include "Teuchos_VerboseObject.hpp"
00008 #include "Teuchos_XMLParameterListHelpers.hpp"
00009 #include "Teuchos_DefaultComm.hpp"
00010 
00011 
00012 int main( int argc, char* argv[] )
00013 {
00014   using Teuchos::rcp;
00015   using Teuchos::RCP;
00016   using Teuchos::OSTab;
00017   using Teuchos::CommandLineProcessor;
00018   typedef Thyra::Ordinal Ordinal;
00019   using MoochoPack::MoochoSolver;
00020   using MoochoPack::MoochoThyraSolver;
00021 
00022   Teuchos::GlobalMPISession mpiSession(&argc, &argv);
00023 
00024   Teuchos::Time timer("");
00025   
00026   bool dummySuccess = true;
00027 
00028   Teuchos::RCP<Teuchos::FancyOStream>
00029     out = Teuchos::VerboseObjectBase::getDefaultOStream();
00030 
00031   try {
00032  
00033     //
00034     // A) Create the solver objects that will insert their command-line
00035     // options
00036     //
00037 
00038     MoochoThyraSolver solver;
00039 
00040     //
00041     // B) Get options from the command line
00042     //
00043 
00044 
00045     CommandLineProcessor clp;
00046     clp.throwExceptions(false);
00047     clp.addOutputSetupOptions(true);
00048 
00049     int localDim = 4;
00050     clp.setOption("local-dim", &localDim);
00051 
00052     double ps = 100.0;
00053     clp.setOption("ps", &ps);
00054 
00055     double p0 = 0.0;
00056     clp.setOption("p0", &p0);
00057 
00058     double condNum = 1.0;
00059     clp.setOption("cond-num", &condNum);
00060 
00061     double nonlinearTermFactor = 1e-3;
00062     clp.setOption("nonlinear-term-factor", &nonlinearTermFactor);
00063 
00064     double g_offset = 10.0;
00065     clp.setOption("g-offset", &g_offset);
00066 
00067     solver.setupCLP(&clp);
00068 
00069     CommandLineProcessor::EParseCommandLineReturn
00070       parse_return = clp.parse(argc,argv,&std::cerr);
00071 
00072     if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
00073       return parse_return;
00074 
00075     solver.readParameters( out.get() );
00076 
00077     const RCP<const Teuchos::Comm<Ordinal> > comm =
00078       Teuchos::DefaultComm<Ordinal>::getComm();
00079  
00080     //
00081     // C) Create the Thyra::ModelEvaluator object
00082     //
00083  
00084     *out << "\nCreate Thyra::DiagonalQuadraticResponseOnlyModelEvaluator object ...\n";
00085  
00086     Teuchos::RCP<Thyra::DiagonalQuadraticResponseOnlyModelEvaluator<double> >
00087       thyraModel = Thyra::diagonalQuadraticResponseOnlyModelEvaluator<double> (localDim, comm);
00088 
00089     const RCP<Thyra::VectorBase<double> > ps_vec = createMember(thyraModel->get_p_space(0));
00090     Thyra::V_S<double>(ps_vec.ptr(), ps);
00091     thyraModel->setSolutionVector(ps_vec);
00092     
00093     // ToDo: Set p0
00094 
00095     // ToDo: Set up diagonal consistent with condNum
00096 
00097     thyraModel->setNonlinearTermFactor(nonlinearTermFactor);
00098 
00099     thyraModel->setScalarOffset(g_offset);
00100 
00101     //
00102     // D) Solve the NLP
00103     //
00104     
00105     // Set the model
00106     solver.setModel(thyraModel);
00107     
00108     // Read the initial guess if one exists
00109     solver.readInitialGuess(out.get());
00110     
00111     // Solve the NLP
00112     const MoochoSolver::ESolutionStatus solution_status = solver.solve();
00113     
00114     // Write the solution to file
00115     solver.writeFinalSolution(out.get());
00116     
00117     // Write the final parameters to file
00118     solver.writeParamsFile();
00119     
00120     //
00121     // E) Return the solution status (0 if successful)
00122     //
00123     
00124     if(solution_status == MoochoSolver::SOLVE_RETURN_SOLVED)
00125       *out << "\nEnd Result: TEST PASSED\n";
00126     else
00127       *out << "\nEnd Result: TEST FAILED\n";
00128     
00129     return solution_status;
00130     
00131   }
00132   TEUCHOS_STANDARD_CATCH_STATEMENTS(true, *out, dummySuccess)
00133     
00134   return MoochoSolver::SOLVE_RETURN_EXCEPTION;
00135 
00136 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends
Generated on Wed Apr 13 10:18:07 2011 for MOOCHO by  doxygen 1.6.3