|
MOOCHO/Thyra Adapter Software Version of the Day
|
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 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 #ifndef MOOCHOPACK_MOOCHO_THYRA_SOLVER_HPP 00043 #define MOOCHOPACK_MOOCHO_THYRA_SOLVER_HPP 00044 00045 #include "MoochoPack_MoochoSolver.hpp" 00046 #include "Thyra_ModelEvaluator.hpp" 00047 #include "Thyra_DirectionalFiniteDiffCalculator.hpp" 00048 #include "Thyra_DefaultNominalBoundsOverrideModelEvaluator.hpp" 00049 #include "Thyra_DefaultFinalPointCaptureModelEvaluator.hpp" 00050 #include "Thyra_MultiVectorFileIOBase.hpp" 00051 #include "Thyra_ParameterDrivenMultiVectorInput.hpp" 00052 #include "Teuchos_StandardMemberCompositionMacros.hpp" 00053 00054 namespace MoochoPack { 00055 00057 using Teuchos::RCP; 00058 00083 class MoochoThyraSolver 00084 : virtual public Teuchos::ParameterListAcceptor 00085 { 00086 public: 00087 00090 00092 enum ESolveMode { 00093 SOLVE_MODE_FORWARD 00094 ,SOLVE_MODE_OPTIMIZE 00095 }; 00096 00098 00101 00109 MoochoThyraSolver( 00110 const std::string ¶msXmlFileName = "" 00111 ,const std::string &extraParamsXmlString = "" 00112 ,const std::string ¶msUsedXmlOutFileName = "" 00113 ,const std::string ¶msXmlFileNameOption = "moocho-thyra-params-file" 00114 ,const std::string &extraParamsXmlStringOption = "extra-moocho-thyra-params" 00115 ,const std::string ¶msUsedXmlOutFileNameOption = "moocho-thyra-params-used-file" 00116 ); 00117 00119 ~MoochoThyraSolver(); 00120 00124 STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,paramsXmlFileName); 00125 00129 STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,extraParamsXmlString); 00130 00134 STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,paramsUsedXmlOutFileName); 00135 00139 STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,paramsXmlFileNameOption); 00140 00144 STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,extraParamsXmlStringOption); 00145 00149 STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,paramsUsedXmlOutFileNameOption); 00150 00159 STANDARD_NONCONST_COMPOSITION_MEMBERS( Thyra::MultiVectorFileIOBase<value_type>, stateVectorIO ); 00160 00173 STANDARD_NONCONST_COMPOSITION_MEMBERS( Thyra::MultiVectorFileIOBase<value_type>, parameterVectorIO ); 00174 00183 void setupCLP( 00184 Teuchos::CommandLineProcessor *clp 00185 ); 00186 00206 void readParameters( std::ostream *out ); 00207 00209 00212 00214 void setParameterList(RCP<Teuchos::ParameterList> const& paramList); 00216 RCP<Teuchos::ParameterList> getNonconstParameterList(); 00218 RCP<Teuchos::ParameterList> unsetParameterList(); 00220 RCP<const Teuchos::ParameterList> getParameterList() const; 00222 RCP<const Teuchos::ParameterList> getValidParameters() const; 00223 00225 00227 //@ 00228 00230 void setSolveMode( const ESolveMode solveMode ); 00231 00233 ESolveMode getSolveMode() const; 00234 00236 MoochoSolver& getSolver(); 00237 00239 const MoochoSolver& getSolver() const; 00240 00242 00245 00247 void setModel( 00248 const RCP<Thyra::ModelEvaluator<value_type> > &origModel, 00249 const int p_idx = 0, 00250 const int g_idx = 0 00251 ); 00252 00254 const RCP<Thyra::ModelEvaluator<value_type> > 00255 getOrigModel() const; 00256 00258 const RCP<Thyra::ModelEvaluator<value_type> > 00259 getOuterModel() const; 00260 00262 void readInitialGuess( 00263 std::ostream *out = NULL 00264 ); 00265 00267 void setInitialGuess( 00268 const RCP<const Thyra::ModelEvaluatorBase::InArgs<value_type> > &initialGuess 00269 ); 00270 00272 void setInitialGuess( 00273 const Thyra::ModelEvaluatorBase::InArgs<value_type> &initialGuess 00274 ); 00275 00277 MoochoSolver::ESolutionStatus solve(); 00278 00280 const Thyra::ModelEvaluatorBase::InArgs<value_type>& getFinalPoint() const; 00281 00285 void writeFinalSolution( 00286 std::ostream *out = NULL 00287 ) const; 00288 00303 void writeParamsFile( 00304 const std::string &outputXmlFileName = "" 00305 ) const; 00306 00308 00309 public: 00310 00311 // I am just making these public so that I can access them from 00312 // the anonymous namespace in the *.cpp file 00313 enum ENLPType { NLP_TYPE_FIRST_ORDER, NLP_TYPE_DIRECT }; 00314 00315 private: 00316 00317 typedef value_type Scalar; 00318 00319 MoochoSolver solver_; 00320 00321 RCP<Thyra::ModelEvaluator<value_type> > origModel_; 00322 int p_idx_; 00323 int g_idx_; 00324 00325 mutable Thyra::ParameterDrivenMultiVectorInput<value_type> x_reader_; 00326 mutable Thyra::ParameterDrivenMultiVectorInput<value_type> p_reader_; 00327 mutable Thyra::ParameterDrivenMultiVectorInput<value_type> p_l_reader_; 00328 mutable Thyra::ParameterDrivenMultiVectorInput<value_type> p_u_reader_; 00329 00330 RCP<Teuchos::ParameterList> paramList_; 00331 00332 RCP<Thyra::DefaultNominalBoundsOverrideModelEvaluator<value_type> > 00333 nominalModel_; 00334 00335 RCP<Thyra::DefaultFinalPointCaptureModelEvaluator<value_type> > 00336 finalPointModel_; 00337 00338 RCP<Thyra::ModelEvaluator<value_type> > outerModel_; 00339 00340 ESolveMode solveMode_; 00341 ENLPType nlpType_; 00342 bool nonlinearlyElimiateStates_; 00343 bool use_finite_diff_for_obj_; 00344 bool use_finite_diff_for_con_; 00345 double fwd_newton_tol_; 00346 int fwd_newton_max_iters_; 00347 bool fwd_newton_dampening_; 00348 int fwd_newton_max_ls_iters_; 00349 bool useInvObjFunc_; 00350 bool useParameterLumping_; 00351 std::string outputFileTag_; 00352 bool showModelEvaluatorTrace_; 00353 std::string stateSoluFileBase_; 00354 std::string paramSoluFileBase_; 00355 00356 }; 00357 00358 } // namespace MoochoPack 00359 00360 #endif // MOOCHOPACK_MOOCHO_THYRA_SOLVER_HPP
1.7.4