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     CommandLineProcessor  clp(false); // Don't throw exceptions
00056 
00057     lowsfCreator.setupCLP(&clp);
00058     solver.setupCLP(&clp);
00059 
00060     clp.setOption( "xt0", &xt0 );
00061     clp.setOption( "xt1", &xt1 );
00062     clp.setOption( "pt0", &pt0 );
00063     clp.setOption( "pt1", &pt1 );
00064     clp.setOption( "d", &d );
00065     clp.setOption( "x00", &x00 );
00066     clp.setOption( "x01", &x01 );
00067     clp.setOption( "p00", &p00 );
00068     clp.setOption( "p01", &p01 );
00069     clp.setOption( "pL0", &pL0 );
00070     clp.setOption( "pL1", &pL1 );
00071     clp.setOption( "pU0", &pU0 );
00072     clp.setOption( "pU1", &pU1 );
00073     clp.setOption( "xL0", &xL0 );
00074     clp.setOption( "xL1", &xL1 );
00075     clp.setOption( "xU0", &xU0 );
00076     clp.setOption( "xU1", &xU1 );
00077     clp.setOption( "support-derivs", "no-support-derivs", &supportDerivs );
00078  
00079     CommandLineProcessor::EParseCommandLineReturn
00080       parse_return = clp.parse(argc,argv,&std::cerr);
00081 
00082     if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
00083       return parse_return;
00084 
00085     lowsfCreator.readParameters(out.get());
00086     solver.readParameters(out.get());
00087 
00088     //
00089     // Create the NLP
00090     //
00091     
00092     // Create the EpetraExt::ModelEvaluator object
00093 
00094     Teuchos::RCP<EpetraModelEval4DOpt>
00095       epetraModel = rcp(new EpetraModelEval4DOpt(xt0,xt1,pt0,pt1,d,x00,x01,p00,p01));
00096     epetraModel->setSupportDerivs(supportDerivs);
00097     epetraModel->set_p_bounds(pL0,pL1,pU0,pU1);
00098     epetraModel->set_x_bounds(xL0,xL1,xU0,xU1);
00099 
00100     // Create the Thyra::EpetraModelEvaluator object
00101 
00102     Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<double> >
00103       lowsFactory = lowsfCreator.createLinearSolveStrategy("");
00104 
00105     Teuchos::RCP<Thyra::EpetraModelEvaluator>
00106       epetraThyraModel = rcp(new Thyra::EpetraModelEvaluator());
00107     
00108     epetraThyraModel->initialize(epetraModel,lowsFactory);
00109     
00110     //
00111     // Solve the NLP
00112     //
00113     
00114     // Set the model
00115     solver.setModel(epetraThyraModel);
00116 
00117     // Read the initial guess if one exists
00118     solver.readInitialGuess(out.get());
00119 
00120     // Solve the NLP
00121     const MoochoSolver::ESolutionStatus solution_status = solver.solve();
00122 
00123     // Write the final solution if requested
00124     solver.writeFinalSolution(out.get());
00125 
00126     // Write the parameters that where read
00127     lowsfCreator.writeParamsFile(*lowsFactory);
00128     solver.writeParamsFile();
00129     
00130     //
00131     // Return the solution status (0 if sucessfull)
00132     //
00133 
00134     return solution_status;
00135 
00136   }
00137   TEUCHOS_STANDARD_CATCH_STATEMENTS(true,*out,dummySuccess)
00138 
00139   return MoochoSolver::SOLVE_RETURN_EXCEPTION;
00140 
00141 }

Generated on Wed May 12 21:57:50 2010 for MOOCHO by  doxygen 1.4.7