|
Thyra Package Browser (Single Doxygen Collection) Version of the Day
|
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 00162 class EpetraModelEvaluator 00163 : public ModelEvaluatorDefaultBase<double>, 00164 virtual public Teuchos::ParameterListAcceptor 00165 { 00166 public: 00167 00170 00172 EpetraModelEvaluator(); 00173 00175 EpetraModelEvaluator( 00176 const RCP<const EpetraExt::ModelEvaluator> &epetraModel, 00177 const RCP<LinearOpWithSolveFactoryBase<double> > &W_factory 00178 ); 00179 00181 void initialize( 00182 const RCP<const EpetraExt::ModelEvaluator> &epetraModel, 00183 const RCP<LinearOpWithSolveFactoryBase<double> > &W_factory 00184 ); 00185 00187 RCP<const EpetraExt::ModelEvaluator> getEpetraModel() const; 00188 00194 void setNominalValues( const ModelEvaluatorBase::InArgs<double>& nominalValues ); 00195 00203 void setStateVariableScalingVec( 00204 const RCP<const Epetra_Vector> &stateVariableScalingVec 00205 ); 00206 00209 RCP<const Epetra_Vector> 00210 getStateVariableInvScalingVec() const; 00211 00214 RCP<const Epetra_Vector> 00215 getStateVariableScalingVec() const; 00216 00219 void setStateFunctionScalingVec( 00220 const RCP<const Epetra_Vector> &stateFunctionScalingVec 00221 ); 00222 00225 RCP<const Epetra_Vector> 00226 getStateFunctionScalingVec() const; 00227 00229 void uninitialize( 00230 RCP<const EpetraExt::ModelEvaluator> *epetraModel = NULL, 00231 RCP<LinearOpWithSolveFactoryBase<double> > *W_factory = NULL 00232 ); 00233 00235 const ModelEvaluatorBase::InArgs<double>& getFinalPoint() const; 00236 00238 bool finalPointWasSolved() const; 00239 00241 00244 00246 std::string description() const; 00247 00249 00252 00254 void setParameterList(RCP<Teuchos::ParameterList> const& paramList); 00256 RCP<Teuchos::ParameterList> getNonconstParameterList(); 00258 RCP<Teuchos::ParameterList> unsetParameterList(); 00260 RCP<const Teuchos::ParameterList> getParameterList() const; 00262 RCP<const Teuchos::ParameterList> getValidParameters() const; 00263 00265 00268 00270 int Np() const; 00272 int Ng() const; 00274 RCP<const VectorSpaceBase<double> > get_x_space() const; 00276 RCP<const VectorSpaceBase<double> > get_f_space() const; 00278 RCP<const VectorSpaceBase<double> > get_p_space(int l) const; 00280 RCP<const Teuchos::Array<std::string> > get_p_names(int l) const; 00282 RCP<const VectorSpaceBase<double> > get_g_space(int j) const; 00284 ModelEvaluatorBase::InArgs<double> getNominalValues() const; 00286 ModelEvaluatorBase::InArgs<double> getLowerBounds() const; 00288 ModelEvaluatorBase::InArgs<double> getUpperBounds() const; 00290 RCP<LinearOpWithSolveBase<double> > create_W() const; 00292 RCP<LinearOpBase<double> > create_W_op() const; 00294 RCP<const LinearOpWithSolveFactoryBase<double> > get_W_factory() const; 00296 ModelEvaluatorBase::InArgs<double> createInArgs() const; 00298 void reportFinalPoint( 00299 const ModelEvaluatorBase::InArgs<double> &finalPoint 00300 ,const bool wasSolved 00301 ); 00302 00304 00305 // Made public to simplify implementation but this is harmless to be public. 00306 // Clients should not deal with this type. 00307 enum EStateFunctionScaling { STATE_FUNC_SCALING_NONE, STATE_FUNC_SCALING_ROW_SUM }; 00308 00309 private: 00310 00313 00315 RCP<LinearOpBase<double> > create_DfDp_op_impl(int l) const; 00317 RCP<LinearOpBase<double> > create_DgDx_dot_op_impl(int j) const; 00319 RCP<LinearOpBase<double> > create_DgDx_op_impl(int j) const; 00321 RCP<LinearOpBase<double> > create_DgDp_op_impl(int j, int l) const; 00323 ModelEvaluatorBase::OutArgs<double> createOutArgsImpl() const; 00325 void evalModelImpl( 00326 const ModelEvaluatorBase::InArgs<double> &inArgs, 00327 const ModelEvaluatorBase::OutArgs<double> &outArgs 00328 ) const; 00329 00331 00332 private: 00333 00334 // //////////////////// 00335 // Private types 00336 00337 typedef Teuchos::Array<RCP<const Epetra_Map> > p_map_t; 00338 typedef Teuchos::Array<RCP<const Epetra_Map> > g_map_t; 00339 typedef std::vector<bool> p_map_is_local_t; 00340 typedef std::vector<bool> g_map_is_local_t; 00341 00342 typedef Teuchos::Array<RCP<const VectorSpaceBase<double> > > 00343 p_space_t; 00344 typedef Teuchos::Array<RCP<const VectorSpaceBase<double> > > 00345 g_space_t; 00346 00347 // ///////////////////// 00348 // Private data members 00349 00350 RCP<const EpetraExt::ModelEvaluator> epetraModel_; 00351 00352 RCP<Teuchos::ParameterList> paramList_; 00353 00354 RCP<LinearOpWithSolveFactoryBase<double> > W_factory_; 00355 00356 RCP<const Epetra_Map> x_map_; 00357 p_map_t p_map_; 00358 g_map_t g_map_; 00359 p_map_is_local_t p_map_is_local_; 00360 p_map_is_local_t g_map_is_local_; 00361 RCP<const Epetra_Map> f_map_; 00362 00363 RCP<const VectorSpaceBase<double> > x_space_; 00364 p_space_t p_space_; 00365 RCP<const VectorSpaceBase<double> > f_space_; 00366 g_space_t g_space_; 00367 00368 mutable ModelEvaluatorBase::InArgs<double> nominalValues_; 00369 mutable ModelEvaluatorBase::InArgs<double> lowerBounds_; 00370 mutable ModelEvaluatorBase::InArgs<double> upperBounds_; 00371 mutable bool nominalValuesAndBoundsAreUpdated_; 00372 00373 ModelEvaluatorBase::InArgs<double> finalPoint_; 00374 00375 EStateFunctionScaling stateFunctionScaling_; 00376 mutable RCP<const Epetra_Vector> stateFunctionScalingVec_; 00377 00378 RCP<const Epetra_Vector> stateVariableScalingVec_; // S_x 00379 mutable RCP<const Epetra_Vector> invStateVariableScalingVec_; // inv(S_x) 00380 mutable EpetraExt::ModelEvaluator::InArgs epetraInArgsScaling_; 00381 mutable EpetraExt::ModelEvaluator::OutArgs epetraOutArgsScaling_; 00382 00383 mutable RCP<Epetra_Vector> x_unscaled_; 00384 mutable RCP<Epetra_Vector> x_dot_unscaled_; 00385 00386 mutable ModelEvaluatorBase::InArgs<double> prototypeInArgs_; 00387 mutable ModelEvaluatorBase::OutArgs<double> prototypeOutArgs_; 00388 mutable bool currentInArgsOutArgs_; 00389 00390 bool finalPointWasSolved_; 00391 00392 // ////////////////////////// 00393 // Private member functions 00394 00396 void convertInArgsFromEpetraToThyra( 00397 const EpetraExt::ModelEvaluator::InArgs &epetraInArgs, 00398 ModelEvaluatorBase::InArgs<double> *inArgs 00399 ) const; 00400 00402 void convertInArgsFromThyraToEpetra( 00403 const ModelEvaluatorBase::InArgs<double> &inArgs, 00404 EpetraExt::ModelEvaluator::InArgs *epetraInArgs 00405 ) const; 00406 00408 void convertOutArgsFromThyraToEpetra( 00409 // Thyra form of the outArgs 00410 const ModelEvaluatorBase::OutArgs<double> &outArgs, 00411 // Epetra form of the unscaled output arguments 00412 EpetraExt::ModelEvaluator::OutArgs *epetraUnscaledOutArgs, 00413 // The passed-in form(s) of W 00414 RCP<LinearOpWithSolveBase<double> > *W, 00415 RCP<LinearOpBase<double> > *W_op, 00416 // The wrapped Thyra forward operators 00417 RCP<const LinearOpBase<double> > *fwdW, 00418 RCP<EpetraLinearOp> *efwdW, 00419 // The actual Epetra object passed to the underylying EpetraExt::ModelEvaluator 00420 RCP<Epetra_Operator> *eW 00421 ) const; 00422 00424 void preEvalScalingSetup( 00425 EpetraExt::ModelEvaluator::InArgs *epetraInArgs, 00426 EpetraExt::ModelEvaluator::OutArgs *epetraUnscaledOutArgs, 00427 const RCP<Teuchos::FancyOStream> &out, 00428 const Teuchos::EVerbosityLevel verbLevel 00429 ) const; 00430 00432 void postEvalScalingSetup( 00433 const EpetraExt::ModelEvaluator::OutArgs &epetraUnscaledOutArgs, 00434 const RCP<Teuchos::FancyOStream> &out, 00435 const Teuchos::EVerbosityLevel verbLevel 00436 ) const; 00437 00439 void finishConvertingOutArgsFromEpetraToThyra( 00440 const EpetraExt::ModelEvaluator::OutArgs &epetraOutArgs, 00441 RCP<LinearOpWithSolveBase<double> > &W, 00442 RCP<LinearOpBase<double> > &W_op, 00443 RCP<const LinearOpBase<double> > &fwdW, 00444 RCP<EpetraLinearOp> &efwdW, 00445 RCP<Epetra_Operator> &eW, 00446 const ModelEvaluatorBase::OutArgs<double> &outArgs // Output! 00447 ) const; 00448 // 2007/08/03: rabartl: Above, I pass many of the RCP objects by non-const 00449 // reference since I don't want the compiler to perform any implicit 00450 // conversions on this RCP objects. 00451 00453 void updateNominalValuesAndBounds() const; 00454 00456 void updateInArgsOutArgs() const; 00457 00459 RCP<EpetraLinearOp> create_epetra_W_op() const; 00460 00461 }; 00462 00463 00464 // 00465 // Utility functions 00466 // 00467 00468 00472 RCP<EpetraModelEvaluator> 00473 epetraModelEvaluator( 00474 const RCP<const EpetraExt::ModelEvaluator> &epetraModel, 00475 const RCP<LinearOpWithSolveFactoryBase<double> > &W_factory 00476 ); 00477 00478 00482 ModelEvaluatorBase::EDerivativeMultiVectorOrientation 00483 convert( const EpetraExt::ModelEvaluator::EDerivativeMultiVectorOrientation &mvOrientation ); 00484 00485 00489 EpetraExt::ModelEvaluator::EDerivativeMultiVectorOrientation 00490 convert( const ModelEvaluatorBase::EDerivativeMultiVectorOrientation &mvOrientation ); 00491 00492 00496 ModelEvaluatorBase::DerivativeProperties 00497 convert( const EpetraExt::ModelEvaluator::DerivativeProperties &derivativeProperties ); 00498 00499 00503 ModelEvaluatorBase::DerivativeSupport 00504 convert( const EpetraExt::ModelEvaluator::DerivativeSupport &derivativeSupport ); 00505 00506 00510 EpetraExt::ModelEvaluator::Derivative 00511 convert( 00512 const ModelEvaluatorBase::Derivative<double> &derivative, 00513 const RCP<const Epetra_Map> &fnc_map, 00514 const RCP<const Epetra_Map> &var_map 00515 ); 00516 00517 00518 } // namespace Thyra 00519 00520 00521 #endif // THYRA_EPETRA_MODEL_EVALUATOR_HPP
1.7.4