NLPThyraEpetraModelEval4DOptMain.cpp

00001 #include "NLPInterfacePack_NLPFirstOrderThyraModelEvaluator.hpp"
00002 #include "EpetraModelEval4DOpt.hpp"
00003 #include "MoochoPack_ThyraModelEvaluatorSolver.hpp"
00004 #include "Thyra_DefaultModelEvaluatorWithSolveFactory.hpp"
00005 #include "Thyra_DefaultRealLinearSolverBuilder.hpp"
00006 #include "Thyra_EpetraModelEvaluator.hpp"
00007 #include "Teuchos_GlobalMPISession.hpp"
00008 #include "Teuchos_VerboseObject.hpp"
00009 #include "Teuchos_CommandLineProcessor.hpp"
00010 #include "Teuchos_StandardCatchMacros.hpp"
00011 
00012 int main( int argc, char* argv[] )
00013 {
00014   using Teuchos::CommandLineProcessor;
00015   typedef AbstractLinAlgPack::value_type  Scalar;
00016   using MoochoPack::MoochoSolver;
00017   using MoochoPack::ThyraModelEvaluatorSolver;
00018 
00019   bool dummySuccess = true;
00020 
00021   Teuchos::GlobalMPISession mpiSession(&argc,&argv);
00022 
00023   Teuchos::RefCountPtr<Teuchos::FancyOStream>
00024     out = Teuchos::VerboseObjectBase::getDefaultOStream();
00025 
00026   try {
00027 
00028     Thyra::DefaultRealLinearSolverBuilder lowsfCreator;
00029     ThyraModelEvaluatorSolver             solver;
00030   
00031     //
00032     // Get options from the command line
00033     //
00034     
00035     Scalar       xt0         = 1.0;
00036     Scalar       xt1         = 1.0;
00037     Scalar       pt0         = 2.0;
00038     Scalar       pt1         = 0.0;
00039     Scalar       d           = 10.0;
00040     Scalar       x00         = 1.0;
00041     Scalar       x01         = 1.0;
00042     Scalar       p00         = 2.0;
00043     Scalar       p01         = 0.0;
00044     Scalar       pL0         = -1e+50;
00045     Scalar       pL1         = -1e+50;
00046     Scalar       pU0         = +1e+50;
00047     Scalar       pU1         = +1e+50;
00048 
00049     Scalar       xL0         = -1e+50;
00050     Scalar       xL1         = -1e+50;
00051     Scalar       xU0         = +1e+50;
00052     Scalar       xU1         = +1e+50;
00053 
00054     CommandLineProcessor  clp(false); // Don't throw exceptions
00055 
00056     lowsfCreator.setupCLP(&clp);
00057     solver.setupCLP(&clp);
00058 
00059     clp.setOption( "xt0", &xt0 );
00060     clp.setOption( "xt1", &xt1 );
00061     clp.setOption( "pt0", &pt0 );
00062     clp.setOption( "pt1", &pt1 );
00063     clp.setOption( "d", &d );
00064     clp.setOption( "x00", &x00 );
00065     clp.setOption( "x01", &x01 );
00066     clp.setOption( "p00", &p00 );
00067     clp.setOption( "p01", &p01 );
00068     clp.setOption( "pL0", &pL0 );
00069     clp.setOption( "pL1", &pL1 );
00070     clp.setOption( "pU0", &pU0 );
00071     clp.setOption( "pU1", &pU1 );
00072     clp.setOption( "xL0", &xL0 );
00073     clp.setOption( "xL1", &xL1 );
00074     clp.setOption( "xU0", &xU0 );
00075     clp.setOption( "xU1", &xU1 );
00076  
00077     CommandLineProcessor::EParseCommandLineReturn
00078       parse_return = clp.parse(argc,argv,&std::cerr);
00079 
00080     if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
00081       return parse_return;
00082 
00083     lowsfCreator.readParameters(out.get());
00084 
00085     //
00086     // Create the NLP
00087     //
00088     
00089     // Create the EpetraExt::ModelEvaluator object
00090 
00091     Teuchos::RefCountPtr<EpetraModelEval4DOpt>
00092       epetraModel = rcp(new EpetraModelEval4DOpt(xt0,xt1,pt0,pt1,d,x00,x01,p00,p01));
00093     epetraModel->set_p_bounds(pL0,pL1,pU0,pU1);
00094     epetraModel->set_x_bounds(xL0,xL1,xU0,xU1);
00095 
00096     // Create the Thyra::EpetraModelEvaluator object
00097 
00098     Teuchos::RefCountPtr<Thyra::LinearOpWithSolveFactoryBase<double> >
00099       lowsFactory = lowsfCreator.createLinearSolveStrategy("");
00100 
00101     Teuchos::RefCountPtr<Thyra::EpetraModelEvaluator>
00102       epetraThyraModel = rcp(new Thyra::EpetraModelEvaluator());
00103     
00104     epetraThyraModel->initialize(epetraModel,lowsFactory);
00105     
00106     //
00107     // Solve the NLP
00108     //
00109     
00110     // Set the model
00111     solver.setModel(epetraThyraModel);
00112 
00113     // Read the initial guess if one exists
00114     solver.readInitialGuess(out.get());
00115 
00116     // Solve the NLP
00117     const MoochoSolver::ESolutionStatus solution_status = solver.solve();
00118 
00119     // Write the parameters that where read
00120     lowsfCreator.writeParamsFile(*lowsFactory);
00121     
00122     //
00123     // Return the solution status (0 if sucessfull)
00124     //
00125 
00126     return solution_status;
00127 
00128   }
00129   TEUCHOS_STANDARD_CATCH_STATEMENTS(true,*out,dummySuccess)
00130 
00131   return MoochoSolver::SOLVE_RETURN_EXCEPTION;
00132 }

Generated on Thu Sep 18 12:36:38 2008 for MOOCHO by doxygen 1.3.9.1