Thyra_EpetraModelEvaluator.hpp

00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //    Thyra: Interfaces and Support for Abstract Numerical Algorithms
00005 //                 Copyright (2004) 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 Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef THYRA_EPETRA_MODEL_EVALUATOR_HPP
00030 #define THYRA_EPETRA_MODEL_EVALUATOR_HPP
00031 
00032 #include "Thyra_ModelEvaluatorDefaultBase.hpp"
00033 #include "Thyra_EpetraThyraWrappers.hpp"
00034 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
00035 #include "EpetraExt_ModelEvaluator.h"
00036 #include "Epetra_Map.h"
00037 #include "Teuchos_Array.hpp"
00038 
00039 
00040 namespace Thyra {
00041 
00042 
00160 class EpetraModelEvaluator
00161   : public ModelEvaluatorDefaultBase<double>,
00162     virtual public Teuchos::ParameterListAcceptor
00163 {
00164 public:
00165 
00168 
00170   EpetraModelEvaluator();
00171 
00173   EpetraModelEvaluator(
00174     const RCP<const EpetraExt::ModelEvaluator> &epetraModel,
00175     const RCP<LinearOpWithSolveFactoryBase<double> > &W_factory
00176     );
00177 
00179   void initialize(
00180     const RCP<const EpetraExt::ModelEvaluator> &epetraModel,
00181     const RCP<LinearOpWithSolveFactoryBase<double> > &W_factory
00182     );
00183 
00185   RCP<const EpetraExt::ModelEvaluator> getEpetraModel() const;
00186 
00192   void setNominalValues( const ModelEvaluatorBase::InArgs<double>& nominalValues );
00193   
00201   void setStateVariableScalingVec(
00202     const RCP<const Epetra_Vector> &stateVariableScalingVec
00203     );
00204   
00207   RCP<const Epetra_Vector>
00208   getStateVariableInvScalingVec() const;
00209   
00212   RCP<const Epetra_Vector>
00213   getStateVariableScalingVec() const;
00214   
00217   void setStateFunctionScalingVec(
00218     const RCP<const Epetra_Vector> &stateFunctionScalingVec
00219     );
00220   
00223   RCP<const Epetra_Vector>
00224   getStateFunctionScalingVec() const;
00225 
00227   void uninitialize(
00228     RCP<const EpetraExt::ModelEvaluator> *epetraModel = NULL,
00229     RCP<LinearOpWithSolveFactoryBase<double> > *W_factory = NULL
00230     );
00231   
00233   const ModelEvaluatorBase::InArgs<double>& getFinalPoint() const;
00234 
00236   bool finalPointWasSolved() const;
00237 
00239 
00242 
00244   std::string description() const;
00245 
00247 
00250 
00252   void setParameterList(RCP<Teuchos::ParameterList> const& paramList);
00254   RCP<Teuchos::ParameterList> getParameterList();
00256   RCP<Teuchos::ParameterList> unsetParameterList();
00258   RCP<const Teuchos::ParameterList> getParameterList() const;
00260   RCP<const Teuchos::ParameterList> getValidParameters() const;
00261 
00263 
00266 
00268   int Np() const;
00270   int Ng() const;
00272   RCP<const VectorSpaceBase<double> > get_x_space() const;
00274   RCP<const VectorSpaceBase<double> > get_f_space() const;
00276   RCP<const VectorSpaceBase<double> > get_p_space(int l) const;
00278   RCP<const Teuchos::Array<std::string> > get_p_names(int l) const;
00280   RCP<const VectorSpaceBase<double> > get_g_space(int j) const;
00282   ModelEvaluatorBase::InArgs<double> getNominalValues() const;
00284   ModelEvaluatorBase::InArgs<double> getLowerBounds() const;
00286   ModelEvaluatorBase::InArgs<double> getUpperBounds() const;
00288   RCP<LinearOpWithSolveBase<double> > create_W() const;
00290   RCP<LinearOpBase<double> > create_W_op() const;
00292   ModelEvaluatorBase::InArgs<double> createInArgs() const;
00294   void reportFinalPoint(
00295     const ModelEvaluatorBase::InArgs<double>      &finalPoint
00296     ,const bool                                   wasSolved
00297     );
00298 
00300 
00301   // Made public to simplify implementation but this is harmless to be public.
00302   // Clients should not deal with this type.
00303   enum EStateFunctionScaling { STATE_FUNC_SCALING_NONE, STATE_FUNC_SCALING_ROW_SUM };
00304 
00305 private:
00306 
00309 
00311   RCP<LinearOpBase<double> > create_DfDp_op_impl(int l) const;
00313   RCP<LinearOpBase<double> > create_DgDx_dot_op_impl(int j) const;
00315   RCP<LinearOpBase<double> > create_DgDx_op_impl(int j) const;
00317   RCP<LinearOpBase<double> > create_DgDp_op_impl(int j, int l) const;
00319   ModelEvaluatorBase::OutArgs<double> createOutArgsImpl() const;
00321   void evalModelImpl(
00322     const ModelEvaluatorBase::InArgs<double> &inArgs,
00323     const ModelEvaluatorBase::OutArgs<double> &outArgs
00324     ) const;
00325 
00327 
00328 private:
00329 
00330   // ////////////////////
00331   // Private types
00332 
00333   typedef Teuchos::Array<RCP<const Epetra_Map> > p_map_t;
00334   typedef Teuchos::Array<RCP<const Epetra_Map> > g_map_t;
00335   typedef std::vector<bool> p_map_is_local_t;
00336   typedef std::vector<bool> g_map_is_local_t;
00337 
00338   typedef Teuchos::Array<RCP<const VectorSpaceBase<double> > >
00339   p_space_t;
00340   typedef Teuchos::Array<RCP<const VectorSpaceBase<double> > >
00341   g_space_t;
00342 
00343   // /////////////////////
00344   // Private data members
00345 
00346   RCP<const EpetraExt::ModelEvaluator> epetraModel_;
00347 
00348   RCP<Teuchos::ParameterList> paramList_;
00349 
00350   RCP<const Epetra_Map> x_map_;
00351   p_map_t p_map_;
00352   g_map_t g_map_;
00353   p_map_is_local_t p_map_is_local_;
00354   p_map_is_local_t g_map_is_local_;
00355   RCP<const Epetra_Map> f_map_;
00356 
00357   RCP<const VectorSpaceBase<double> > x_space_;
00358   p_space_t p_space_;
00359   RCP<const VectorSpaceBase<double> > f_space_;
00360   g_space_t g_space_;
00361 
00362   mutable ModelEvaluatorBase::InArgs<double> nominalValues_;
00363   mutable ModelEvaluatorBase::InArgs<double> lowerBounds_;
00364   mutable ModelEvaluatorBase::InArgs<double> upperBounds_;
00365   mutable bool nominalValuesAndBoundsAreUpdated_;
00366 
00367   ModelEvaluatorBase::InArgs<double> finalPoint_;
00368 
00369   EStateFunctionScaling stateFunctionScaling_;
00370   mutable RCP<const Epetra_Vector> stateFunctionScalingVec_;
00371 
00372   RCP<const Epetra_Vector> stateVariableScalingVec_; // S_x
00373   mutable RCP<const Epetra_Vector> invStateVariableScalingVec_; // inv(S_x)
00374   mutable EpetraExt::ModelEvaluator::InArgs epetraInArgsScaling_;
00375   mutable EpetraExt::ModelEvaluator::OutArgs epetraOutArgsScaling_;
00376   
00377   mutable RCP<Epetra_Vector> x_unscaled_;
00378   mutable RCP<Epetra_Vector> x_dot_unscaled_;
00379 
00380   // 2007/09/19: rabartl: Below, for some reason, the SGI MipsPro compiler on
00381   // sasg5000 say that these members are "inaccessable" in the *member*
00382   // function updateInArgsOutArgs() if you leave them as private!  Since this
00383   // compiles just fine on every other compiler, I am just going to let this
00384   // go :-)
00385 
00386 #ifdef __sgi
00387 public:
00388 #endif // __sgi
00389 
00390   RCP<LinearOpWithSolveFactoryBase<double> > W_factory_;
00391   mutable ModelEvaluatorBase::InArgs<double> prototypeInArgs_;
00392   mutable ModelEvaluatorBase::OutArgs<double> prototypeOutArgs_;
00393   mutable bool currentInArgsOutArgs_;
00394 
00395 #ifdef __sgi
00396 private:
00397 #endif // __sgi
00398 
00399   bool finalPointWasSolved_;
00400 
00401   // //////////////////////////
00402   // Private member functions
00403 
00405   void convertInArgsFromEpetraToThyra(
00406     const EpetraExt::ModelEvaluator::InArgs &epetraInArgs,
00407     ModelEvaluatorBase::InArgs<double> *inArgs
00408     ) const;
00409 
00411   void convertInArgsFromThyraToEpetra(
00412     const ModelEvaluatorBase::InArgs<double> &inArgs,
00413     EpetraExt::ModelEvaluator::InArgs *epetraInArgs
00414     ) const;
00415 
00417   void convertOutArgsFromThyraToEpetra(
00418     // Thyra form of the outArgs
00419     const ModelEvaluatorBase::OutArgs<double> &outArgs,
00420     // Epetra form of the unscaled output arguments 
00421     EpetraExt::ModelEvaluator::OutArgs *epetraUnscaledOutArgs,
00422     // The passed-in form(s) of W
00423     RCP<LinearOpWithSolveBase<double> > *W,
00424     RCP<LinearOpBase<double> > *W_op,
00425     // The wrapped Thyra forward operators
00426     RCP<const LinearOpBase<double> > *fwdW,
00427     RCP<EpetraLinearOp> *efwdW,
00428     // The actual Epetra object passed to the underylying EpetraExt::ModelEvaluator
00429     RCP<Epetra_Operator> *eW
00430     ) const;
00431 
00433   void preEvalScalingSetup(
00434     EpetraExt::ModelEvaluator::InArgs *epetraInArgs,
00435     EpetraExt::ModelEvaluator::OutArgs *epetraUnscaledOutArgs,
00436     const RCP<Teuchos::FancyOStream> &out,
00437     const Teuchos::EVerbosityLevel verbLevel
00438     ) const;
00439 
00441   void postEvalScalingSetup(
00442     const EpetraExt::ModelEvaluator::OutArgs &epetraUnscaledOutArgs,
00443     const RCP<Teuchos::FancyOStream> &out,
00444     const Teuchos::EVerbosityLevel verbLevel
00445     ) const;
00446 
00448   void finishConvertingOutArgsFromEpetraToThyra(
00449     const EpetraExt::ModelEvaluator::OutArgs &epetraOutArgs,
00450     RCP<LinearOpWithSolveBase<double> > &W,
00451     RCP<LinearOpBase<double> > &W_op,
00452     RCP<const LinearOpBase<double> > &fwdW,
00453     RCP<EpetraLinearOp> &efwdW,
00454     RCP<Epetra_Operator> &eW,
00455     const ModelEvaluatorBase::OutArgs<double> &outArgs // Output!
00456     ) const;
00457   // 2007/08/03: rabartl: Above, I pass many of the RCP objects by non-const
00458   // reference since I don't want the compiler to perform any implicit
00459   // conversions on this RCP objects.
00460 
00462   void updateNominalValuesAndBounds() const;
00463 
00465   void updateInArgsOutArgs() const;
00466   
00467 };
00468 
00469 
00470 //
00471 // Utility functions
00472 //
00473 
00474 
00478 RCP<EpetraModelEvaluator>
00479 epetraModelEvaluator(
00480   const RCP<const EpetraExt::ModelEvaluator> &epetraModel,
00481   const RCP<LinearOpWithSolveFactoryBase<double> > &W_factory
00482   );
00483 
00484 
00488 ModelEvaluatorBase::EDerivativeMultiVectorOrientation
00489 convert( const EpetraExt::ModelEvaluator::EDerivativeMultiVectorOrientation &mvOrientation );
00490 
00491 
00495 EpetraExt::ModelEvaluator::EDerivativeMultiVectorOrientation
00496 convert( const ModelEvaluatorBase::EDerivativeMultiVectorOrientation &mvOrientation );
00497 
00498 
00502 ModelEvaluatorBase::DerivativeProperties
00503 convert( const EpetraExt::ModelEvaluator::DerivativeProperties &derivativeProperties );
00504 
00505 
00509 ModelEvaluatorBase::DerivativeSupport
00510 convert( const EpetraExt::ModelEvaluator::DerivativeSupport &derivativeSupport );
00511 
00512 
00516 EpetraExt::ModelEvaluator::Derivative
00517 convert(
00518   const ModelEvaluatorBase::Derivative<double> &derivative,
00519   const RCP<const Epetra_Map> &fnc_map,
00520   const RCP<const Epetra_Map> &var_map
00521   );
00522 
00523 
00524 } // namespace Thyra
00525 
00526 
00527 #endif // THYRA_EPETRA_MODEL_EVALUATOR_HPP

Generated on Tue Oct 20 12:47:19 2009 for EpetraExt/Thyra Adapters by doxygen 1.4.7