MoochoPack_MoochoThyraSolver.hpp

00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00005 //                  Copyright (2003) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef MOOCHOPACK_MOOCHO_THYRA_SOLVER_HPP
00030 #define MOOCHOPACK_MOOCHO_THYRA_SOLVER_HPP
00031 
00032 #include "MoochoPack_MoochoSolver.hpp"
00033 #include "Thyra_ModelEvaluator.hpp"
00034 #include "Thyra_DirectionalFiniteDiffCalculator.hpp"
00035 #include "Thyra_DefaultNominalBoundsOverrideModelEvaluator.hpp"
00036 #include "Thyra_DefaultFinalPointCaptureModelEvaluator.hpp"
00037 #include "Thyra_MultiVectorFileIOBase.hpp"
00038 #include "Thyra_ParameterDrivenMultiVectorInput.hpp"
00039 #include "Teuchos_StandardMemberCompositionMacros.hpp"
00040 
00041 namespace MoochoPack {
00042 
00044 using Teuchos::RCP;
00045 
00070 class MoochoThyraSolver
00071   : virtual public Teuchos::ParameterListAcceptor
00072 {
00073 public:
00074 
00077 
00079   enum ESolveMode {
00080     SOLVE_MODE_FORWARD    
00081     ,SOLVE_MODE_OPTIMIZE  
00082   };
00083 
00085 
00088 
00096   MoochoThyraSolver(
00097     const std::string    &paramsXmlFileName                = ""
00098     ,const std::string   &extraParamsXmlString             = ""
00099     ,const std::string   &paramsUsedXmlOutFileName         = ""
00100     ,const std::string   &paramsXmlFileNameOption          = "moocho-thyra-params-file"
00101     ,const std::string   &extraParamsXmlStringOption       = "extra-moocho-thyra-params"
00102     ,const std::string   &paramsUsedXmlOutFileNameOption   = "moocho-thyra-params-used-file"
00103     );
00104   
00106   ~MoochoThyraSolver();
00107   
00111   STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,paramsXmlFileName);
00112     
00116   STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,extraParamsXmlString);
00117 
00121   STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,paramsUsedXmlOutFileName);
00122 
00126   STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,paramsXmlFileNameOption);
00127 
00131   STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,extraParamsXmlStringOption);
00132 
00136   STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,paramsUsedXmlOutFileNameOption);
00137 
00146   STANDARD_NONCONST_COMPOSITION_MEMBERS( Thyra::MultiVectorFileIOBase<value_type>, stateVectorIO );
00147 
00160   STANDARD_NONCONST_COMPOSITION_MEMBERS( Thyra::MultiVectorFileIOBase<value_type>, parameterVectorIO );
00161   
00170   void setupCLP(
00171     Teuchos::CommandLineProcessor *clp
00172     );
00173 
00193   void readParameters( std::ostream *out );
00194 
00196 
00199 
00201   void setParameterList(RCP<Teuchos::ParameterList> const& paramList);
00203   RCP<Teuchos::ParameterList> getNonconstParameterList();
00205   RCP<Teuchos::ParameterList> unsetParameterList();
00207   RCP<const Teuchos::ParameterList> getParameterList() const;
00209   RCP<const Teuchos::ParameterList> getValidParameters() const;
00210 
00212 
00214   //@
00215 
00217   void setSolveMode( const ESolveMode solveMode );
00218 
00220   ESolveMode getSolveMode() const;
00221   
00223   MoochoSolver& getSolver();
00224   
00226   const MoochoSolver& getSolver() const;
00227 
00229 
00232   
00234   void setModel(
00235     const RCP<Thyra::ModelEvaluator<value_type> > &origModel,
00236     const int p_idx  = 0,
00237     const int g_idx  = 0
00238     );
00239   
00241   const RCP<Thyra::ModelEvaluator<value_type> >
00242   getOrigModel() const;
00243   
00245   const RCP<Thyra::ModelEvaluator<value_type> >
00246   getOuterModel() const;
00247     
00249   void readInitialGuess(
00250     std::ostream *out = NULL
00251     );
00252     
00254   void setInitialGuess(
00255     const RCP<const Thyra::ModelEvaluatorBase::InArgs<value_type> > &initialGuess
00256     );
00257     
00259   void setInitialGuess(
00260     const Thyra::ModelEvaluatorBase::InArgs<value_type> &initialGuess
00261     );
00262   
00264   MoochoSolver::ESolutionStatus solve();
00265     
00267   const Thyra::ModelEvaluatorBase::InArgs<value_type>& getFinalPoint() const;
00268   
00272   void writeFinalSolution(
00273     std::ostream *out = NULL
00274     ) const;
00275 
00290   void writeParamsFile(
00291     const std::string &outputXmlFileName  = "" 
00292     ) const;
00293 
00295 
00296 public:
00297 
00298   // I am just making these public so that I can access them from
00299   // the anonymous namespace in the *.cpp file
00300   enum ENLPType { NLP_TYPE_FIRST_ORDER, NLP_TYPE_DIRECT };
00301 
00302 private:
00303 
00304   typedef value_type Scalar;
00305 
00306   MoochoSolver solver_;
00307  
00308   RCP<Thyra::ModelEvaluator<value_type> > origModel_;
00309   int p_idx_;
00310   int g_idx_;
00311 
00312   mutable Thyra::ParameterDrivenMultiVectorInput<value_type> x_reader_;
00313   mutable Thyra::ParameterDrivenMultiVectorInput<value_type> p_reader_;
00314   mutable Thyra::ParameterDrivenMultiVectorInput<value_type> p_l_reader_;
00315   mutable Thyra::ParameterDrivenMultiVectorInput<value_type> p_u_reader_;
00316 
00317   RCP<Teuchos::ParameterList> paramList_;
00318  
00319   RCP<Thyra::DefaultNominalBoundsOverrideModelEvaluator<value_type> >
00320   nominalModel_;
00321  
00322   RCP<Thyra::DefaultFinalPointCaptureModelEvaluator<value_type> >
00323   finalPointModel_;
00324 
00325   RCP<Thyra::ModelEvaluator<value_type> > outerModel_;
00326 
00327   ESolveMode solveMode_;
00328   ENLPType nlpType_;
00329   bool nonlinearlyElimiateStates_;
00330   bool use_finite_diff_for_obj_;
00331   bool use_finite_diff_for_con_;
00332   double fwd_newton_tol_;
00333   int fwd_newton_max_iters_;
00334   bool fwd_newton_dampening_;
00335   int fwd_newton_max_ls_iters_;
00336   bool useInvObjFunc_;
00337   bool useParameterLumping_;
00338   std::string outputFileTag_;
00339   bool showModelEvaluatorTrace_;
00340   std::string stateSoluFileBase_;
00341   std::string paramSoluFileBase_;
00342 
00343 };
00344 
00345 } // namespace MoochoPack
00346 
00347 #endif  // MOOCHOPACK_MOOCHO_THYRA_SOLVER_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Generated on Wed Apr 13 10:09:53 2011 for MOOCHO/Thyra Adapter Software by  doxygen 1.6.3