MOOCHO Version of the Day
EpetraExtDiagonalQuadraticResponseOnlyOptMain.cpp
00001 /*
00002 // @HEADER
00003 // ***********************************************************************
00004 // 
00005 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00006 //                  Copyright (2003) Sandia Corporation
00007 // 
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 // 
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00039 // 
00040 // ***********************************************************************
00041 // @HEADER
00042 */
00043 
00044 #include "EpetraExt_DiagonalQuadraticResponseOnlyModelEvaluator.hpp"
00045 #include "MoochoPack_MoochoThyraSolver.hpp"
00046 #include "Thyra_EpetraModelEvaluator.hpp"
00047 #include "Teuchos_GlobalMPISession.hpp"
00048 #include "Teuchos_CommandLineProcessor.hpp"
00049 #include "Teuchos_StandardCatchMacros.hpp"
00050 #include "Teuchos_VerboseObject.hpp"
00051 #include "Teuchos_XMLParameterListHelpers.hpp"
00052 #ifdef HAVE_MPI
00053 #  include "Epetra_MpiComm.h"
00054 #else
00055 #  include "Epetra_SerialComm.h"
00056 #endif
00057 
00058 
00059 int main( int argc, char* argv[] )
00060 {
00061   using Teuchos::rcp;
00062   using Teuchos::RCP;
00063   using Teuchos::OSTab;
00064   using MoochoPack::MoochoSolver;
00065   using MoochoPack::MoochoThyraSolver;
00066   using Teuchos::CommandLineProcessor;
00067 
00068   Teuchos::GlobalMPISession mpiSession(&argc, &argv);
00069 
00070   Teuchos::Time timer("");
00071   
00072   bool dummySuccess = true;
00073 
00074   Teuchos::RCP<Teuchos::FancyOStream>
00075     out = Teuchos::VerboseObjectBase::getDefaultOStream();
00076 
00077   try {
00078  
00079     //
00080     // A) Create the solver objects that will insert their command-line
00081     // options
00082     //
00083 
00084     MoochoThyraSolver solver;
00085 
00086     //
00087     // B) Get options from the command line
00088     //
00089 
00090     int localDim = 4;
00091     double pt = 0.0;
00092     double p0 = 0.1;
00093     double scale = 0.1;
00094 
00095     CommandLineProcessor clp;
00096     clp.throwExceptions(false);
00097     clp.addOutputSetupOptions(true);
00098 
00099     clp.setOption("local-dim", &localDim);
00100     clp.setOption("pt", &pt);
00101     clp.setOption("p0", &p0);
00102     clp.setOption("scale", &scale);
00103 
00104     solver.setupCLP(&clp);
00105 
00106     CommandLineProcessor::EParseCommandLineReturn
00107       parse_return = clp.parse(argc,argv,&std::cerr);
00108 
00109     if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
00110       return parse_return;
00111 
00112     solver.readParameters( out.get() );
00113 
00114     Teuchos::RCP<Epetra_Comm> comm = Teuchos::null;
00115 
00116 #ifdef HAVE_MPI
00117     MPI_Comm mpiComm = MPI_COMM_WORLD;
00118     comm = Teuchos::rcp(new Epetra_MpiComm(mpiComm));
00119 #else
00120     comm = Teuchos::rcp(new Epetra_SerialComm());
00121 #endif
00122  
00123     //
00124     // C) Create the Thyra::ModelEvaluator object
00125     //
00126  
00127     *out << "\nCreate EpetraExt::DiagonalQuadraticResponseOnlyModelEvaluator object ...\n";
00128  
00129     Teuchos::RCP<EpetraExt::DiagonalQuadraticResponseOnlyModelEvaluator>
00130       epetraModel = EpetraExt::diagonalQuadraticResponseOnlyModelEvaluator(
00131         comm, localDim, pt, p0, scale);
00132       
00133     *out << "\nCreate the Thyra::EpetraModelEvaluator wrapper object ...\n";
00134     
00135     Teuchos::RCP<Thyra::EpetraModelEvaluator>
00136       epetraThyraModel(new Thyra::EpetraModelEvaluator()); // Sets default options!
00137     epetraThyraModel->initialize(epetraModel, Teuchos::null);
00138     
00139     //
00140     // D) Solve the NLP
00141     //
00142     
00143     // Set the model
00144     solver.setModel(epetraThyraModel);
00145     
00146     // Read the initial guess if one exists
00147     solver.readInitialGuess(out.get());
00148     
00149     // Solve the NLP
00150     const MoochoSolver::ESolutionStatus solution_status = solver.solve();
00151     
00152     // Write the solution to file
00153     solver.writeFinalSolution(out.get());
00154     
00155     // Write the final parameters to file
00156     solver.writeParamsFile();
00157     
00158     //
00159     // E) Return the solution status (0 if successful)
00160     //
00161     
00162     if(solution_status == MoochoSolver::SOLVE_RETURN_SOLVED)
00163       *out << "\nEnd Result: TEST PASSED\n";
00164     else
00165       *out << "\nEnd Result: TEST FAILED\n";
00166     
00167     return solution_status;
00168     
00169   }
00170   TEUCHOS_STANDARD_CATCH_STATEMENTS(true, *out, dummySuccess)
00171     
00172   return MoochoSolver::SOLVE_RETURN_EXCEPTION;
00173 
00174 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends