MOOCHO/Thyra Adapter Software  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MoochoPack_MoochoThyraSolver.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef MOOCHOPACK_MOOCHO_THYRA_SOLVER_HPP
43 #define MOOCHOPACK_MOOCHO_THYRA_SOLVER_HPP
44 
45 #include "MoochoPack_MoochoSolver.hpp"
46 #include "Thyra_ModelEvaluator.hpp"
47 #include "Thyra_DirectionalFiniteDiffCalculator.hpp"
48 #include "Thyra_DefaultNominalBoundsOverrideModelEvaluator.hpp"
49 #include "Thyra_DefaultFinalPointCaptureModelEvaluator.hpp"
50 #include "Thyra_MultiVectorFileIOBase.hpp"
51 #include "Thyra_ParameterDrivenMultiVectorInput.hpp"
52 #include "Teuchos_StandardMemberCompositionMacros.hpp"
53 
54 namespace MoochoPack {
55 
57 using Teuchos::RCP;
58 
84  : virtual public Teuchos::ParameterListAcceptor
85 {
86 public:
87 
90 
92  enum ESolveMode {
95  };
96 
98 
101 
110  const std::string &paramsXmlFileName = ""
111  ,const std::string &extraParamsXmlString = ""
112  ,const std::string &paramsUsedXmlOutFileName = ""
113  ,const std::string &paramsXmlFileNameOption = "moocho-thyra-params-file"
114  ,const std::string &extraParamsXmlStringOption = "extra-moocho-thyra-params"
115  ,const std::string &paramsUsedXmlOutFileNameOption = "moocho-thyra-params-used-file"
116  );
117 
120 
124  STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,paramsXmlFileName);
125 
129  STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,extraParamsXmlString);
130 
134  STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,paramsUsedXmlOutFileName);
135 
139  STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,paramsXmlFileNameOption);
140 
144  STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,extraParamsXmlStringOption);
145 
149  STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,paramsUsedXmlOutFileNameOption);
150 
160 
174 
183  void setupCLP(
185  );
186 
206  void readParameters( std::ostream *out );
207 
209 
212 
214  void setParameterList(RCP<Teuchos::ParameterList> const& paramList);
223 
225 
227  //@
228 
230  void setSolveMode( const ESolveMode solveMode );
231 
233  ESolveMode getSolveMode() const;
234 
237 
239  const MoochoSolver& getSolver() const;
240 
242 
245 
247  void setModel(
248  const RCP<Thyra::ModelEvaluator<value_type> > &origModel,
249  const int p_idx = 0,
250  const int g_idx = 0
251  );
252 
255  getOrigModel() const;
256 
259  getOuterModel() const;
260 
262  void readInitialGuess(
263  std::ostream *out = NULL
264  );
265 
267  void setInitialGuess(
268  const RCP<const Thyra::ModelEvaluatorBase::InArgs<value_type> > &initialGuess
269  );
270 
272  void setInitialGuess(
274  );
275 
278 
281 
285  void writeFinalSolution(
286  std::ostream *out = NULL
287  ) const;
288 
303  void writeParamsFile(
304  const std::string &outputXmlFileName = ""
305  ) const;
306 
308 
309 public:
310 
311  // I am just making these public so that I can access them from
312  // the anonymous namespace in the *.cpp file
313  enum ENLPType { NLP_TYPE_FIRST_ORDER, NLP_TYPE_DIRECT };
314 
315 private:
316 
317  typedef value_type Scalar;
318 
319  MoochoSolver solver_;
320 
321  RCP<Thyra::ModelEvaluator<value_type> > origModel_;
322  int p_idx_;
323  int g_idx_;
324 
329 
330  RCP<Teuchos::ParameterList> paramList_;
331 
332  RCP<Thyra::DefaultNominalBoundsOverrideModelEvaluator<value_type> >
333  nominalModel_;
334 
335  RCP<Thyra::DefaultFinalPointCaptureModelEvaluator<value_type> >
336  finalPointModel_;
337 
338  RCP<Thyra::ModelEvaluator<value_type> > outerModel_;
339 
340  ESolveMode solveMode_;
341  ENLPType nlpType_;
342  bool nonlinearlyElimiateStates_;
343  bool use_finite_diff_for_obj_;
344  bool use_finite_diff_for_con_;
345  double fwd_newton_tol_;
346  int fwd_newton_max_iters_;
347  bool fwd_newton_dampening_;
348  int fwd_newton_max_ls_iters_;
349  bool useInvObjFunc_;
350  bool useParameterLumping_;
351  std::string outputFileTag_;
352  bool showModelEvaluatorTrace_;
353  std::string stateSoluFileBase_;
354  std::string paramSoluFileBase_;
355 
356 };
357 
358 } // namespace MoochoPack
359 
360 #endif // MOOCHOPACK_MOOCHO_THYRA_SOLVER_HPP
void setParameterList(RCP< Teuchos::ParameterList > const &paramList)
RCP< Teuchos::ParameterList > unsetParameterList()
const RCP< Thyra::ModelEvaluator< value_type > > getOrigModel() const
void readParameters(std::ostream *out)
Force the parameters to be read from a file or from the commandline arguments.
void setupCLP(Teuchos::CommandLineProcessor *clp)
Sets up the commandline for reading in the parameter list for this object (minus the options for Mooc...
RCP< const Teuchos::ParameterList > getValidParameters() const
MoochoThyraSolver(const std::string &paramsXmlFileName="", const std::string &extraParamsXmlString="", const std::string &paramsUsedXmlOutFileName="", const std::string &paramsXmlFileNameOption="moocho-thyra-params-file", const std::string &extraParamsXmlStringOption="extra-moocho-thyra-params", const std::string &paramsUsedXmlOutFileNameOption="moocho-thyra-params-used-file")
Construct with default settings.
MOOCHO NLP Solver class for models represented through Thyra::ModelEvaluator.
MoochoSolver::ESolutionStatus solve()
const RCP< Thyra::ModelEvaluator< value_type > > getOuterModel() const
void writeFinalSolution(std::ostream *out=NULL) const
Write the final solution to a file specified by the parameter list option ???.
RCP< Teuchos::ParameterList > getNonconstParameterList()
STANDARD_NONCONST_COMPOSITION_MEMBERS(Thyra::MultiVectorFileIOBase< value_type >, stateVectorIO)
MultiVectorFileIOBase object used to read and write state vectors to and from files.
void setSolveMode(const ESolveMode solveMode)
void writeParamsFile(const std::string &outputXmlFileName="") const
Write the parameters list for a this object to a file after the parameters are read in order to show ...
Solve an optimization problem for states and parameters.
void setModel(const RCP< Thyra::ModelEvaluator< value_type > > &origModel, const int p_idx=0, const int g_idx=0)
const Thyra::ModelEvaluatorBase::InArgs< value_type > & getFinalPoint() const
Return the final point.
void readInitialGuess(std::ostream *out=NULL)
RCP< const Teuchos::ParameterList > getParameterList() const
STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string, paramsXmlFileName)
The name an XML file that will be read to get XML parameters (if not "").
void setInitialGuess(const RCP< const Thyra::ModelEvaluatorBase::InArgs< value_type > > &initialGuess)