MOOCHO (Single Doxygen Collection) Version of the Day
ThyraDiagonalQuadraticResponseOnlyOptMain.cpp
Go to the documentation of this file.
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 "MoochoPack_MoochoThyraSolver.hpp"
00045 #include "Thyra_DiagonalQuadraticResponseOnlyModelEvaluator.hpp"
00046 #include "Thyra_VectorStdOps.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 #include "Teuchos_DefaultComm.hpp"
00053 
00054 
00055 int main( int argc, char* argv[] )
00056 {
00057   using Teuchos::rcp;
00058   using Teuchos::RCP;
00059   using Teuchos::OSTab;
00060   using Teuchos::CommandLineProcessor;
00061   typedef Thyra::Ordinal Ordinal;
00062   using MoochoPack::MoochoSolver;
00063   using MoochoPack::MoochoThyraSolver;
00064 
00065   Teuchos::GlobalMPISession mpiSession(&argc, &argv);
00066 
00067   Teuchos::Time timer("");
00068   
00069   bool dummySuccess = true;
00070 
00071   Teuchos::RCP<Teuchos::FancyOStream>
00072     out = Teuchos::VerboseObjectBase::getDefaultOStream();
00073 
00074   try {
00075  
00076     //
00077     // A) Create the solver objects that will insert their command-line
00078     // options
00079     //
00080 
00081     MoochoThyraSolver solver;
00082 
00083     //
00084     // B) Get options from the command line
00085     //
00086 
00087 
00088     CommandLineProcessor clp;
00089     clp.throwExceptions(false);
00090     clp.addOutputSetupOptions(true);
00091 
00092     int localDim = 4;
00093     clp.setOption("local-dim", &localDim);
00094 
00095     double ps = 100.0;
00096     clp.setOption("ps", &ps);
00097 
00098     double p0 = 0.0;
00099     clp.setOption("p0", &p0);
00100 
00101     double condNum = 1.0;
00102     clp.setOption("cond-num", &condNum);
00103 
00104     double nonlinearTermFactor = 1e-3;
00105     clp.setOption("nonlinear-term-factor", &nonlinearTermFactor);
00106 
00107     double g_offset = 10.0;
00108     clp.setOption("g-offset", &g_offset);
00109 
00110     solver.setupCLP(&clp);
00111 
00112     CommandLineProcessor::EParseCommandLineReturn
00113       parse_return = clp.parse(argc,argv,&std::cerr);
00114 
00115     if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
00116       return parse_return;
00117 
00118     solver.readParameters( out.get() );
00119 
00120     const RCP<const Teuchos::Comm<Ordinal> > comm =
00121       Teuchos::DefaultComm<Ordinal>::getComm();
00122  
00123     //
00124     // C) Create the Thyra::ModelEvaluator object
00125     //
00126  
00127     *out << "\nCreate Thyra::DiagonalQuadraticResponseOnlyModelEvaluator object ...\n";
00128  
00129     Teuchos::RCP<Thyra::DiagonalQuadraticResponseOnlyModelEvaluator<double> >
00130       thyraModel = Thyra::diagonalQuadraticResponseOnlyModelEvaluator<double> (localDim, comm);
00131 
00132     const RCP<Thyra::VectorBase<double> > ps_vec = createMember(thyraModel->get_p_space(0));
00133     Thyra::V_S<double>(ps_vec.ptr(), ps);
00134     thyraModel->setSolutionVector(ps_vec);
00135     
00136     // ToDo: Set p0
00137 
00138     // ToDo: Set up diagonal consistent with condNum
00139 
00140     thyraModel->setNonlinearTermFactor(nonlinearTermFactor);
00141 
00142     thyraModel->setScalarOffset(g_offset);
00143 
00144     //
00145     // D) Solve the NLP
00146     //
00147     
00148     // Set the model
00149     solver.setModel(thyraModel);
00150     
00151     // Read the initial guess if one exists
00152     solver.readInitialGuess(out.get());
00153     
00154     // Solve the NLP
00155     const MoochoSolver::ESolutionStatus solution_status = solver.solve();
00156     
00157     // Write the solution to file
00158     solver.writeFinalSolution(out.get());
00159     
00160     // Write the final parameters to file
00161     solver.writeParamsFile();
00162     
00163     //
00164     // E) Return the solution status (0 if successful)
00165     //
00166     
00167     if(solution_status == MoochoSolver::SOLVE_RETURN_SOLVED)
00168       *out << "\nEnd Result: TEST PASSED\n";
00169     else
00170       *out << "\nEnd Result: TEST FAILED\n";
00171     
00172     return solution_status;
00173     
00174   }
00175   TEUCHOS_STANDARD_CATCH_STATEMENTS(true, *out, dummySuccess)
00176     
00177   return MoochoSolver::SOLVE_RETURN_EXCEPTION;
00178 
00179 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines