NLPThyraEpetraModelEval4DOptMain.cpp

00001 #include "NLPInterfacePack_NLPFirstOrderThyraModelEvaluator.hpp"
00002 #include "EpetraModelEval4DOpt.hpp"
00003 #include "MoochoPack_MoochoThyraSolver.hpp"
00004 #include "Stratimikos_DefaultLinearSolverBuilder.hpp"
00005 #include "Thyra_EpetraModelEvaluator.hpp"
00006 #include "Teuchos_GlobalMPISession.hpp"
00007 #include "Teuchos_VerboseObject.hpp"
00008 #include "Teuchos_CommandLineProcessor.hpp"
00009 #include "Teuchos_StandardCatchMacros.hpp"
00010 
00011 int main( int argc, char* argv[] )
00012 {
00013   using Teuchos::CommandLineProcessor;
00014   typedef AbstractLinAlgPack::value_type  Scalar;
00015   using MoochoPack::MoochoSolver;
00016   using MoochoPack::MoochoThyraSolver;
00017 
00018   bool dummySuccess = true;
00019 
00020   Teuchos::GlobalMPISession mpiSession(&argc,&argv);
00021 
00022   Teuchos::RCP<Teuchos::FancyOStream>
00023     out = Teuchos::VerboseObjectBase::getDefaultOStream();
00024 
00025   try {
00026 
00027     Stratimikos::DefaultLinearSolverBuilder lowsfCreator;
00028     MoochoThyraSolver                     solver;
00029   
00030     //
00031     // Get options from the command line
00032     //
00033     
00034     Scalar       xt0         = 1.0;
00035     Scalar       xt1         = 1.0;
00036     Scalar       pt0         = 2.0;
00037     Scalar       pt1         = 0.0;
00038     Scalar       d           = 10.0;
00039     Scalar       x00         = 1.0;
00040     Scalar       x01         = 1.0;
00041     Scalar       p00         = 2.0;
00042     Scalar       p01         = 0.0;
00043     Scalar       pL0         = -1e+50;
00044     Scalar       pL1         = -1e+50;
00045     Scalar       pU0         = +1e+50;
00046     Scalar       pU1         = +1e+50;
00047 
00048     Scalar       xL0         = -1e+50;
00049     Scalar       xL1         = -1e+50;
00050     Scalar       xU0         = +1e+50;
00051     Scalar       xU1         = +1e+50;
00052 
00053     bool supportDerivs = true;
00054 
00055     std::string extraXmlFile = "";
00056 
00057     CommandLineProcessor  clp(false); // Don't throw exceptions
00058 
00059     lowsfCreator.setupCLP(&clp);
00060     solver.setupCLP(&clp);
00061 
00062     clp.setOption( "xt0", &xt0 );
00063     clp.setOption( "xt1", &xt1 );
00064     clp.setOption( "pt0", &pt0 );
00065     clp.setOption( "pt1", &pt1 );
00066     clp.setOption( "d", &d );
00067     clp.setOption( "x00", &x00 );
00068     clp.setOption( "x01", &x01 );
00069     clp.setOption( "p00", &p00 );
00070     clp.setOption( "p01", &p01 );
00071     clp.setOption( "pL0", &pL0 );
00072     clp.setOption( "pL1", &pL1 );
00073     clp.setOption( "pU0", &pU0 );
00074     clp.setOption( "pU1", &pU1 );
00075     clp.setOption( "xL0", &xL0 );
00076     clp.setOption( "xL1", &xL1 );
00077     clp.setOption( "xU0", &xU0 );
00078     clp.setOption( "xU1", &xU1 );
00079     clp.setOption( "support-derivs", "no-support-derivs", &supportDerivs );
00080     clp.setOption("extra-xml-file",&extraXmlFile,"File with extra XML text that will modify the initial XML read in");
00081  
00082     std::string line("");
00083     if(extraXmlFile.length()) {
00084       std::ifstream myfile(extraXmlFile.c_str());
00085       if (myfile.is_open())
00086       {
00087         getline (myfile,line);
00088         solver.extraParamsXmlStringOption(line);
00089         std::cout << line << "\n";
00090         myfile.close();
00091       }
00092     }
00093 
00094     CommandLineProcessor::EParseCommandLineReturn
00095       parse_return = clp.parse(argc,argv,&std::cerr);
00096 
00097     if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
00098       return parse_return;
00099 
00100     lowsfCreator.readParameters(out.get());
00101     solver.readParameters(out.get());
00102 
00103     //
00104     // Create the NLP
00105     //
00106     
00107     // Create the EpetraExt::ModelEvaluator object
00108 
00109     Teuchos::RCP<EpetraModelEval4DOpt>
00110       epetraModel = Teuchos::rcp(new EpetraModelEval4DOpt(xt0,xt1,pt0,pt1,d,x00,x01,p00,p01));
00111     epetraModel->setSupportDerivs(supportDerivs);
00112     epetraModel->set_p_bounds(pL0,pL1,pU0,pU1);
00113     epetraModel->set_x_bounds(xL0,xL1,xU0,xU1);
00114 
00115     // Create the Thyra::EpetraModelEvaluator object
00116 
00117     Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<double> >
00118       lowsFactory = lowsfCreator.createLinearSolveStrategy("");
00119 
00120     Teuchos::RCP<Thyra::EpetraModelEvaluator>
00121       epetraThyraModel = Teuchos::rcp(new Thyra::EpetraModelEvaluator());
00122     
00123     epetraThyraModel->initialize(epetraModel,lowsFactory);
00124     
00125     //
00126     // Solve the NLP
00127     //
00128     
00129     // Set the model
00130     solver.setModel(epetraThyraModel);
00131 
00132     // Read the initial guess if one exists
00133     solver.readInitialGuess(out.get());
00134 
00135     // Solve the NLP
00136     const MoochoSolver::ESolutionStatus solution_status = solver.solve();
00137 
00138     // Write the final solution if requested
00139     solver.writeFinalSolution(out.get());
00140 
00141     // Write the parameters that where read
00142     lowsfCreator.writeParamsFile(*lowsFactory);
00143     solver.writeParamsFile();
00144     
00145     //
00146     // Return the solution status (0 if sucessfull)
00147     //
00148 
00149     return solution_status;
00150 
00151   }
00152   TEUCHOS_STANDARD_CATCH_STATEMENTS(true,*out,dummySuccess)
00153 
00154   return MoochoSolver::SOLVE_RETURN_EXCEPTION;
00155 
00156 }
 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