MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ThyraDiagonalQuadraticResponseOnlyOptMain.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 
45 #include "Thyra_DiagonalQuadraticResponseOnlyModelEvaluator.hpp"
46 #include "Thyra_VectorStdOps.hpp"
52 #include "Teuchos_DefaultComm.hpp"
53 
54 
55 int main( int argc, char* argv[] )
56 {
57  using Teuchos::rcp;
58  using Teuchos::RCP;
59  using Teuchos::OSTab;
61  typedef Thyra::Ordinal Ordinal;
64 
65  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
66 
67  Teuchos::Time timer("");
68 
69  bool dummySuccess = true;
70 
72  out = Teuchos::VerboseObjectBase::getDefaultOStream();
73 
74  try {
75 
76  //
77  // A) Create the solver objects that will insert their command-line
78  // options
79  //
80 
81  MoochoThyraSolver solver;
82 
83  //
84  // B) Get options from the command line
85  //
86 
87 
88  CommandLineProcessor clp;
89  clp.throwExceptions(false);
90  clp.addOutputSetupOptions(true);
91 
92  int localDim = 4;
93  clp.setOption("local-dim", &localDim);
94 
95  double ps = 100.0;
96  clp.setOption("ps", &ps);
97 
98  double p0 = 0.0;
99  clp.setOption("p0", &p0);
100 
101  double condNum = 1.0;
102  clp.setOption("cond-num", &condNum);
103 
104  double nonlinearTermFactor = 1e-3;
105  clp.setOption("nonlinear-term-factor", &nonlinearTermFactor);
106 
107  double g_offset = 10.0;
108  clp.setOption("g-offset", &g_offset);
109 
110  solver.setupCLP(&clp);
111 
112  CommandLineProcessor::EParseCommandLineReturn
113  parse_return = clp.parse(argc,argv,&std::cerr);
114 
115  if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
116  return parse_return;
117 
118  solver.readParameters( out.get() );
119 
120  const RCP<const Teuchos::Comm<Ordinal> > comm =
122 
123  //
124  // C) Create the Thyra::ModelEvaluator object
125  //
126 
127  *out << "\nCreate Thyra::DiagonalQuadraticResponseOnlyModelEvaluator object ...\n";
128 
130  thyraModel = Thyra::diagonalQuadraticResponseOnlyModelEvaluator<double> (localDim, comm);
131 
132  const RCP<Thyra::VectorBase<double> > ps_vec = createMember(thyraModel->get_p_space(0));
133  Thyra::V_S<double>(ps_vec.ptr(), ps);
134  thyraModel->setSolutionVector(ps_vec);
135 
136  // ToDo: Set p0
137 
138  // ToDo: Set up diagonal consistent with condNum
139 
140  thyraModel->setNonlinearTermFactor(nonlinearTermFactor);
141 
142  thyraModel->setScalarOffset(g_offset);
143 
144  //
145  // D) Solve the NLP
146  //
147 
148  // Set the model
149  solver.setModel(thyraModel);
150 
151  // Read the initial guess if one exists
152  solver.readInitialGuess(out.get());
153 
154  // Solve the NLP
155  const MoochoSolver::ESolutionStatus solution_status = solver.solve();
156 
157  // Write the solution to file
158  solver.writeFinalSolution(out.get());
159 
160  // Write the final parameters to file
161  solver.writeParamsFile();
162 
163  //
164  // E) Return the solution status (0 if successful)
165  //
166 
167  if(solution_status == MoochoSolver::SOLVE_RETURN_SOLVED)
168  *out << "\nEnd Result: TEST PASSED\n";
169  else
170  *out << "\nEnd Result: TEST FAILED\n";
171 
172  return solution_status;
173 
174  }
175  TEUCHOS_STANDARD_CATCH_STATEMENTS(true, *out, dummySuccess)
176 
177  return MoochoSolver::SOLVE_RETURN_EXCEPTION;
178 
179 }
T * get() const
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
MOOCHO NLP Solver class for models represented through Thyra::ModelEvaluator.
basic_OSTab< char > OSTab
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
std::ostream * out
Universal interface to a MOOCHO solver.
int main(int argc, char *argv[])