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> getNonconstParameterList();
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   RCP<const LinearOpWithSolveFactoryBase<double> > get_W_factory() const;
00294   ModelEvaluatorBase::InArgs<double> createInArgs() const;
00296   void reportFinalPoint(
00297     const ModelEvaluatorBase::InArgs<double>      &finalPoint
00298     ,const bool                                   wasSolved
00299     );
00300 
00302 
00303   // Made public to simplify implementation but this is harmless to be public.
00304   // Clients should not deal with this type.
00305   enum EStateFunctionScaling { STATE_FUNC_SCALING_NONE, STATE_FUNC_SCALING_ROW_SUM };
00306 
00307 private:
00308 
00311 
00313   RCP<LinearOpBase<double> > create_DfDp_op_impl(int l) const;
00315   RCP<LinearOpBase<double> > create_DgDx_dot_op_impl(int j) const;
00317   RCP<LinearOpBase<double> > create_DgDx_op_impl(int j) const;
00319   RCP<LinearOpBase<double> > create_DgDp_op_impl(int j, int l) const;
00321   ModelEvaluatorBase::OutArgs<double> createOutArgsImpl() const;
00323   void evalModelImpl(
00324     const ModelEvaluatorBase::InArgs<double> &inArgs,
00325     const ModelEvaluatorBase::OutArgs<double> &outArgs
00326     ) const;
00327 
00329 
00330 private:
00331 
00332   // ////////////////////
00333   // Private types
00334 
00335   typedef Teuchos::Array<RCP<const Epetra_Map> > p_map_t;
00336   typedef Teuchos::Array<RCP<const Epetra_Map> > g_map_t;
00337   typedef std::vector<bool> p_map_is_local_t;
00338   typedef std::vector<bool> g_map_is_local_t;
00339 
00340   typedef Teuchos::Array<RCP<const VectorSpaceBase<double> > >
00341   p_space_t;
00342   typedef Teuchos::Array<RCP<const VectorSpaceBase<double> > >
00343   g_space_t;
00344 
00345   // /////////////////////
00346   // Private data members
00347 
00348   RCP<const EpetraExt::ModelEvaluator> epetraModel_;
00349 
00350   RCP<Teuchos::ParameterList> paramList_;
00351 
00352   RCP<LinearOpWithSolveFactoryBase<double> > W_factory_;
00353 
00354   RCP<const Epetra_Map> x_map_;
00355   p_map_t p_map_;
00356   g_map_t g_map_;
00357   p_map_is_local_t p_map_is_local_;
00358   p_map_is_local_t g_map_is_local_;
00359   RCP<const Epetra_Map> f_map_;
00360 
00361   RCP<const VectorSpaceBase<double> > x_space_;
00362   p_space_t p_space_;
00363   RCP<const VectorSpaceBase<double> > f_space_;
00364   g_space_t g_space_;
00365 
00366   mutable ModelEvaluatorBase::InArgs<double> nominalValues_;
00367   mutable ModelEvaluatorBase::InArgs<double> lowerBounds_;
00368   mutable ModelEvaluatorBase::InArgs<double> upperBounds_;
00369   mutable bool nominalValuesAndBoundsAreUpdated_;
00370 
00371   ModelEvaluatorBase::InArgs<double> finalPoint_;
00372 
00373   EStateFunctionScaling stateFunctionScaling_;
00374   mutable RCP<const Epetra_Vector> stateFunctionScalingVec_;
00375 
00376   RCP<const Epetra_Vector> stateVariableScalingVec_; // S_x
00377   mutable RCP<const Epetra_Vector> invStateVariableScalingVec_; // inv(S_x)
00378   mutable EpetraExt::ModelEvaluator::InArgs epetraInArgsScaling_;
00379   mutable EpetraExt::ModelEvaluator::OutArgs epetraOutArgsScaling_;
00380   
00381   mutable RCP<Epetra_Vector> x_unscaled_;
00382   mutable RCP<Epetra_Vector> x_dot_unscaled_;
00383 
00384   mutable ModelEvaluatorBase::InArgs<double> prototypeInArgs_;
00385   mutable ModelEvaluatorBase::OutArgs<double> prototypeOutArgs_;
00386   mutable bool currentInArgsOutArgs_;
00387 
00388   bool finalPointWasSolved_;
00389 
00390   // //////////////////////////
00391   // Private member functions
00392 
00394   void convertInArgsFromEpetraToThyra(
00395     const EpetraExt::ModelEvaluator::InArgs &epetraInArgs,
00396     ModelEvaluatorBase::InArgs<double> *inArgs
00397     ) const;
00398 
00400   void convertInArgsFromThyraToEpetra(
00401     const ModelEvaluatorBase::InArgs<double> &inArgs,
00402     EpetraExt::ModelEvaluator::InArgs *epetraInArgs
00403     ) const;
00404 
00406   void convertOutArgsFromThyraToEpetra(
00407     // Thyra form of the outArgs
00408     const ModelEvaluatorBase::OutArgs<double> &outArgs,
00409     // Epetra form of the unscaled output arguments 
00410     EpetraExt::ModelEvaluator::OutArgs *epetraUnscaledOutArgs,
00411     // The passed-in form(s) of W
00412     RCP<LinearOpWithSolveBase<double> > *W,
00413     RCP<LinearOpBase<double> > *W_op,
00414     // The wrapped Thyra forward operators
00415     RCP<const LinearOpBase<double> > *fwdW,
00416     RCP<EpetraLinearOp> *efwdW,
00417     // The actual Epetra object passed to the underylying EpetraExt::ModelEvaluator
00418     RCP<Epetra_Operator> *eW
00419     ) const;
00420 
00422   void preEvalScalingSetup(
00423     EpetraExt::ModelEvaluator::InArgs *epetraInArgs,
00424     EpetraExt::ModelEvaluator::OutArgs *epetraUnscaledOutArgs,
00425     const RCP<Teuchos::FancyOStream> &out,
00426     const Teuchos::EVerbosityLevel verbLevel
00427     ) const;
00428 
00430   void postEvalScalingSetup(
00431     const EpetraExt::ModelEvaluator::OutArgs &epetraUnscaledOutArgs,
00432     const RCP<Teuchos::FancyOStream> &out,
00433     const Teuchos::EVerbosityLevel verbLevel
00434     ) const;
00435 
00437   void finishConvertingOutArgsFromEpetraToThyra(
00438     const EpetraExt::ModelEvaluator::OutArgs &epetraOutArgs,
00439     RCP<LinearOpWithSolveBase<double> > &W,
00440     RCP<LinearOpBase<double> > &W_op,
00441     RCP<const LinearOpBase<double> > &fwdW,
00442     RCP<EpetraLinearOp> &efwdW,
00443     RCP<Epetra_Operator> &eW,
00444     const ModelEvaluatorBase::OutArgs<double> &outArgs // Output!
00445     ) const;
00446   // 2007/08/03: rabartl: Above, I pass many of the RCP objects by non-const
00447   // reference since I don't want the compiler to perform any implicit
00448   // conversions on this RCP objects.
00449 
00451   void updateNominalValuesAndBounds() const;
00452 
00454   void updateInArgsOutArgs() const;
00455 
00457   RCP<EpetraLinearOp> create_epetra_W_op() const;
00458   
00459 };
00460 
00461 
00462 //
00463 // Utility functions
00464 //
00465 
00466 
00470 RCP<EpetraModelEvaluator>
00471 epetraModelEvaluator(
00472   const RCP<const EpetraExt::ModelEvaluator> &epetraModel,
00473   const RCP<LinearOpWithSolveFactoryBase<double> > &W_factory
00474   );
00475 
00476 
00480 ModelEvaluatorBase::EDerivativeMultiVectorOrientation
00481 convert( const EpetraExt::ModelEvaluator::EDerivativeMultiVectorOrientation &mvOrientation );
00482 
00483 
00487 EpetraExt::ModelEvaluator::EDerivativeMultiVectorOrientation
00488 convert( const ModelEvaluatorBase::EDerivativeMultiVectorOrientation &mvOrientation );
00489 
00490 
00494 ModelEvaluatorBase::DerivativeProperties
00495 convert( const EpetraExt::ModelEvaluator::DerivativeProperties &derivativeProperties );
00496 
00497 
00501 ModelEvaluatorBase::DerivativeSupport
00502 convert( const EpetraExt::ModelEvaluator::DerivativeSupport &derivativeSupport );
00503 
00504 
00508 EpetraExt::ModelEvaluator::Derivative
00509 convert(
00510   const ModelEvaluatorBase::Derivative<double> &derivative,
00511   const RCP<const Epetra_Map> &fnc_map,
00512   const RCP<const Epetra_Map> &var_map
00513   );
00514 
00515 
00516 } // namespace Thyra
00517 
00518 
00519 #endif // THYRA_EPETRA_MODEL_EVALUATOR_HPP

Generated on Wed May 12 21:42:59 2010 for EpetraExt/Thyra Adapters by  doxygen 1.4.7