MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EpetraExtDiagonalQuadraticResponseOnlyOptMain.cpp
Go to the documentation of this file.
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
6 // Copyright (2003) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
39 //
40 // ***********************************************************************
41 // @HEADER
42 */
43 
46 #include "Thyra_EpetraModelEvaluator.hpp"
52 #ifdef HAVE_MPI
53 # include "Epetra_MpiComm.h"
54 #else
55 # include "Epetra_SerialComm.h"
56 #endif
57 
58 
59 int main( int argc, char* argv[] )
60 {
61  using Teuchos::rcp;
62  using Teuchos::RCP;
63  using Teuchos::OSTab;
67 
68  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
69 
70  Teuchos::Time timer("");
71 
72  bool dummySuccess = true;
73 
75  out = Teuchos::VerboseObjectBase::getDefaultOStream();
76 
77  try {
78 
79  //
80  // A) Create the solver objects that will insert their command-line
81  // options
82  //
83 
84  MoochoThyraSolver solver;
85 
86  //
87  // B) Get options from the command line
88  //
89 
90  int localDim = 4;
91  double pt = 0.0;
92  double p0 = 0.1;
93  double scale = 0.1;
94 
95  CommandLineProcessor clp;
96  clp.throwExceptions(false);
97  clp.addOutputSetupOptions(true);
98 
99  clp.setOption("local-dim", &localDim);
100  clp.setOption("pt", &pt);
101  clp.setOption("p0", &p0);
102  clp.setOption("scale", &scale);
103 
104  solver.setupCLP(&clp);
105 
106  CommandLineProcessor::EParseCommandLineReturn
107  parse_return = clp.parse(argc,argv,&std::cerr);
108 
109  if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
110  return parse_return;
111 
112  solver.readParameters( out.get() );
113 
115 
116 #ifdef HAVE_MPI
117  MPI_Comm mpiComm = MPI_COMM_WORLD;
118  comm = Teuchos::rcp(new Epetra_MpiComm(mpiComm));
119 #else
120  comm = Teuchos::rcp(new Epetra_SerialComm());
121 #endif
122 
123  //
124  // C) Create the Thyra::ModelEvaluator object
125  //
126 
127  *out << "\nCreate EpetraExt::DiagonalQuadraticResponseOnlyModelEvaluator object ...\n";
128 
130  epetraModel = EpetraExt::diagonalQuadraticResponseOnlyModelEvaluator(
131  comm, localDim, pt, p0, scale);
132 
133  *out << "\nCreate the Thyra::EpetraModelEvaluator wrapper object ...\n";
134 
136  epetraThyraModel(new Thyra::EpetraModelEvaluator()); // Sets default options!
137  epetraThyraModel->initialize(epetraModel, Teuchos::null);
138 
139  //
140  // D) Solve the NLP
141  //
142 
143  // Set the model
144  solver.setModel(epetraThyraModel);
145 
146  // Read the initial guess if one exists
147  solver.readInitialGuess(out.get());
148 
149  // Solve the NLP
150  const MoochoSolver::ESolutionStatus solution_status = solver.solve();
151 
152  // Write the solution to file
153  solver.writeFinalSolution(out.get());
154 
155  // Write the final parameters to file
156  solver.writeParamsFile();
157 
158  //
159  // E) Return the solution status (0 if successful)
160  //
161 
162  if(solution_status == MoochoSolver::SOLVE_RETURN_SOLVED)
163  *out << "\nEnd Result: TEST PASSED\n";
164  else
165  *out << "\nEnd Result: TEST FAILED\n";
166 
167  return solution_status;
168 
169  }
170  TEUCHOS_STANDARD_CATCH_STATEMENTS(true, *out, dummySuccess)
171 
172  return MoochoSolver::SOLVE_RETURN_EXCEPTION;
173 
174 }
T * get() const
MOOCHO NLP Solver class for models represented through Thyra::ModelEvaluator.
int main(int argc, char *argv[])
basic_OSTab< char > OSTab
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
int MPI_Comm
Definition: RTOp_mpi.h:67
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
std::ostream * out
Universal interface to a MOOCHO solver.
#define MPI_COMM_WORLD
Definition: RTOp_mpi.h:68