SundanceNLPModelEvaluator.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 // 
00007 // Copyright (year first published) Sandia Corporation.  Under the terms 
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 
00009 // retains certain rights in this software.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //                                                                                 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA                                                                                
00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 
00026 // Sandia National Laboratories, Livermore, California, USA
00027 // 
00028 // ************************************************************************
00029 /* @HEADER@ */
00030 #ifndef SUNDANCE_SUNDANCENLPMODELEVALUATOR_H
00031 #define SUNDANCE_SUNDANCENLPMODELEVALUATOR_H
00032 
00033 #include "SundanceDefs.hpp"
00034 #include "SundanceDefs.hpp"
00035 
00036 #ifdef HAVE_SUNDANCE_MOOCHO
00037 
00038 #include "SundanceNonlinearProblem.hpp"
00039 #include "SundanceLinearProblem.hpp"
00040 #include "SundanceFunctional.hpp"
00041 #include "SundanceModelEvaluatorBase.hpp"
00042 
00043 
00044 namespace Thyra
00045 {
00046   class SundanceNLPModelEvaluator : public SundanceModelEvaluator
00047   {
00048   public:
00049     /** */
00050     SundanceNLPModelEvaluator(const VectorType<double>& vecType);
00051 
00052     /** */
00053     void initialize(const Expr& paramExpr,
00054                     const Expr& stateExpr,
00055                     const Expr& stateExprVal,
00056                     const NonlinearProblem& prob, 
00057                     const Array<LinearProblem>& sensProb,
00058                     const Functional& objective);
00059 
00060 
00061     /** */
00062     virtual Vector<double> getInitialState() const 
00063     {
00064       Vector<double> rtn = stateSpace().createMember();
00065       rtn.setToConstant(0.0);
00066       return rtn;
00067     }
00068 
00069     
00070     /** */
00071     virtual Vector<double> getInitialParameters() const ;
00072 
00073 
00074     /** */
00075     void setInitialParameters(const Array<double>& a);
00076 
00077     /** */
00078     void internalEvalModel(const Vector<double>& stateVec,
00079                            const Vector<double>& params,
00080                            Vector<double>& resid,
00081                            double& objFuncVal,
00082                            LinearOperator<double>& df_dx,
00083                            Array<Vector<double> >& df_dp,
00084                            Vector<double>& dg_dp_T,
00085                            Vector<double>& dg_dx_T) const ;
00086     
00087 
00088     /** */
00089     VectorSpace<double> paramSpace() const 
00090     {
00091       return paramSpace_;
00092     }        
00093            
00094     /** */
00095     VectorSpace<double> stateSpace() const 
00096     {
00097       VectorSpace<double> rtn = createW().domain();
00098       return rtn;
00099     }
00100            
00101     /** */
00102     VectorSpace<double> constraintSpace() const 
00103     {
00104       VectorSpace<double> rtn = createW().range();
00105       return rtn;
00106     }
00107            
00108     /** */
00109     LinearOperator<double> createW() const 
00110     {
00111       static LinearOperator<double> J = prob_.allocateJacobian();
00112       TEST_FOR_EXCEPTION(J.ptr().get()==0, RuntimeError,
00113                          "null Jacobian");
00114       return J;
00115     }
00116 
00117     /** */
00118     Array<double> parameters() const ;
00119 
00120     /** */
00121     Expr stateVariable() const {return stateExpr_;}
00122 
00123 
00124     /** */
00125     Expr solveForward(const ParameterList& fwdParams) const ;
00126 
00127 
00128     /** */
00129     Array<double> paramArray(const ParameterList& params,
00130                              const std::string& paramName) const ;
00131 
00132     /** */
00133     void setContinuationParameters(const Expr& contParams) {contParams_ = contParams;}
00134 
00135     /** */
00136     void setFinalContinuationValues(const Expr& finalContParams) 
00137     {finalContParams_ = finalContParams;}
00138 
00139     /** */
00140     Expr continuationParameters(int i) const {return contParams_[i];}
00141     /** */
00142     int numContinuationParameters() const {return contParams_.size();}
00143 
00144     /** */
00145     Expr finalContinuationValues(int i) const {return finalContParams_[i];}
00146     
00147 
00148   private:
00149     VectorSpace<double> paramSpace_;
00150 
00151     Array<double> initParams_;
00152 
00153     mutable Expr paramExpr_;
00154 
00155     mutable Expr stateExpr_;
00156 
00157     mutable NonlinearProblem prob_;
00158 
00159     Array<LinearProblem> sensProb_;
00160     
00161     Functional obj_;
00162     
00163     FunctionalEvaluator objEval_;
00164 
00165     Expr contParams_;
00166 
00167     Expr finalContParams_;
00168 
00169 
00170   };
00171 }
00172 
00173 
00174 #endif
00175 #endif

Site Contact