|
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 // 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 (bartlettra@ornl.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 #ifndef THYRA_EPETRA_MODEL_EVALUATOR_HPP 00043 #define THYRA_EPETRA_MODEL_EVALUATOR_HPP 00044 00045 #include "Thyra_ModelEvaluatorDefaultBase.hpp" 00046 #include "Thyra_EpetraThyraWrappers.hpp" 00047 #include "Thyra_LinearOpWithSolveFactoryBase.hpp" 00048 #include "EpetraExt_ModelEvaluator.h" 00049 #include "Epetra_Map.h" 00050 #include "Teuchos_Array.hpp" 00051 00052 00053 namespace Thyra { 00054 00055 00175 class EpetraModelEvaluator 00176 : public ModelEvaluatorDefaultBase<double>, 00177 virtual public Teuchos::ParameterListAcceptor 00178 { 00179 public: 00180 00183 00185 EpetraModelEvaluator(); 00186 00188 EpetraModelEvaluator( 00189 const RCP<const EpetraExt::ModelEvaluator> &epetraModel, 00190 const RCP<LinearOpWithSolveFactoryBase<double> > &W_factory 00191 ); 00192 00194 void initialize( 00195 const RCP<const EpetraExt::ModelEvaluator> &epetraModel, 00196 const RCP<LinearOpWithSolveFactoryBase<double> > &W_factory 00197 ); 00198 00200 RCP<const EpetraExt::ModelEvaluator> getEpetraModel() const; 00201 00207 void setNominalValues( const ModelEvaluatorBase::InArgs<double>& nominalValues ); 00208 00216 void setStateVariableScalingVec( 00217 const RCP<const Epetra_Vector> &stateVariableScalingVec 00218 ); 00219 00222 RCP<const Epetra_Vector> 00223 getStateVariableInvScalingVec() const; 00224 00227 RCP<const Epetra_Vector> 00228 getStateVariableScalingVec() const; 00229 00232 void setStateFunctionScalingVec( 00233 const RCP<const Epetra_Vector> &stateFunctionScalingVec 00234 ); 00235 00238 RCP<const Epetra_Vector> 00239 getStateFunctionScalingVec() const; 00240 00242 void uninitialize( 00243 RCP<const EpetraExt::ModelEvaluator> *epetraModel = NULL, 00244 RCP<LinearOpWithSolveFactoryBase<double> > *W_factory = NULL 00245 ); 00246 00248 const ModelEvaluatorBase::InArgs<double>& getFinalPoint() const; 00249 00251 bool finalPointWasSolved() const; 00252 00254 00257 00259 std::string description() const; 00260 00262 00265 00267 void setParameterList(RCP<Teuchos::ParameterList> const& paramList); 00269 RCP<Teuchos::ParameterList> getNonconstParameterList(); 00271 RCP<Teuchos::ParameterList> unsetParameterList(); 00273 RCP<const Teuchos::ParameterList> getParameterList() const; 00275 RCP<const Teuchos::ParameterList> getValidParameters() const; 00276 00278 00281 00283 int Np() const; 00285 int Ng() const; 00287 RCP<const VectorSpaceBase<double> > get_x_space() const; 00289 RCP<const VectorSpaceBase<double> > get_f_space() const; 00291 RCP<const VectorSpaceBase<double> > get_p_space(int l) const; 00293 RCP<const Teuchos::Array<std::string> > get_p_names(int l) const; 00295 RCP<const VectorSpaceBase<double> > get_g_space(int j) const; 00297 ModelEvaluatorBase::InArgs<double> getNominalValues() const; 00299 ModelEvaluatorBase::InArgs<double> getLowerBounds() const; 00301 ModelEvaluatorBase::InArgs<double> getUpperBounds() const; 00303 RCP<LinearOpBase<double> > create_W_op() const; 00305 RCP<PreconditionerBase<double> > create_W_prec() const; 00307 RCP<const LinearOpWithSolveFactoryBase<double> > get_W_factory() const; 00309 ModelEvaluatorBase::InArgs<double> createInArgs() const; 00311 void reportFinalPoint( 00312 const ModelEvaluatorBase::InArgs<double> &finalPoint 00313 ,const bool wasSolved 00314 ); 00315 00317 00318 // Made public to simplify implementation but this is harmless to be public. 00319 // Clients should not deal with this type. 00320 enum EStateFunctionScaling { STATE_FUNC_SCALING_NONE, STATE_FUNC_SCALING_ROW_SUM }; 00321 00322 private: 00323 00326 00328 RCP<LinearOpBase<double> > create_DfDp_op_impl(int l) const; 00330 RCP<LinearOpBase<double> > create_DgDx_dot_op_impl(int j) const; 00332 RCP<LinearOpBase<double> > create_DgDx_op_impl(int j) const; 00334 RCP<LinearOpBase<double> > create_DgDp_op_impl(int j, int l) const; 00336 ModelEvaluatorBase::OutArgs<double> createOutArgsImpl() const; 00338 void evalModelImpl( 00339 const ModelEvaluatorBase::InArgs<double> &inArgs, 00340 const ModelEvaluatorBase::OutArgs<double> &outArgs 00341 ) const; 00342 00344 00345 private: 00346 00347 // //////////////////// 00348 // Private types 00349 00350 typedef Teuchos::Array<RCP<const Epetra_Map> > p_map_t; 00351 typedef Teuchos::Array<RCP<const Epetra_Map> > g_map_t; 00352 typedef std::vector<bool> p_map_is_local_t; 00353 typedef std::vector<bool> g_map_is_local_t; 00354 00355 typedef Teuchos::Array<RCP<const VectorSpaceBase<double> > > 00356 p_space_t; 00357 typedef Teuchos::Array<RCP<const VectorSpaceBase<double> > > 00358 g_space_t; 00359 00360 // ///////////////////// 00361 // Private data members 00362 00363 RCP<const EpetraExt::ModelEvaluator> epetraModel_; 00364 00365 RCP<Teuchos::ParameterList> paramList_; 00366 00367 RCP<LinearOpWithSolveFactoryBase<double> > W_factory_; 00368 00369 RCP<const Epetra_Map> x_map_; 00370 p_map_t p_map_; 00371 g_map_t g_map_; 00372 p_map_is_local_t p_map_is_local_; 00373 p_map_is_local_t g_map_is_local_; 00374 RCP<const Epetra_Map> f_map_; 00375 00376 RCP<const VectorSpaceBase<double> > x_space_; 00377 p_space_t p_space_; 00378 RCP<const VectorSpaceBase<double> > f_space_; 00379 g_space_t g_space_; 00380 00381 mutable ModelEvaluatorBase::InArgs<double> nominalValues_; 00382 mutable ModelEvaluatorBase::InArgs<double> lowerBounds_; 00383 mutable ModelEvaluatorBase::InArgs<double> upperBounds_; 00384 mutable bool nominalValuesAndBoundsAreUpdated_; 00385 00386 ModelEvaluatorBase::InArgs<double> finalPoint_; 00387 00388 EStateFunctionScaling stateFunctionScaling_; 00389 mutable RCP<const Epetra_Vector> stateFunctionScalingVec_; 00390 00391 RCP<const Epetra_Vector> stateVariableScalingVec_; // S_x 00392 mutable RCP<const Epetra_Vector> invStateVariableScalingVec_; // inv(S_x) 00393 mutable EpetraExt::ModelEvaluator::InArgs epetraInArgsScaling_; 00394 mutable EpetraExt::ModelEvaluator::OutArgs epetraOutArgsScaling_; 00395 00396 mutable RCP<Epetra_Vector> x_unscaled_; 00397 mutable RCP<Epetra_Vector> x_dot_unscaled_; 00398 00399 mutable ModelEvaluatorBase::InArgs<double> prototypeInArgs_; 00400 mutable ModelEvaluatorBase::OutArgs<double> prototypeOutArgs_; 00401 mutable bool currentInArgsOutArgs_; 00402 00403 bool finalPointWasSolved_; 00404 00405 // ////////////////////////// 00406 // Private member functions 00407 00409 void convertInArgsFromEpetraToThyra( 00410 const EpetraExt::ModelEvaluator::InArgs &epetraInArgs, 00411 ModelEvaluatorBase::InArgs<double> *inArgs 00412 ) const; 00413 00415 void convertInArgsFromThyraToEpetra( 00416 const ModelEvaluatorBase::InArgs<double> &inArgs, 00417 EpetraExt::ModelEvaluator::InArgs *epetraInArgs 00418 ) const; 00419 00421 void convertOutArgsFromThyraToEpetra( 00422 // Thyra form of the outArgs 00423 const ModelEvaluatorBase::OutArgs<double> &outArgs, 00424 // Epetra form of the unscaled output arguments 00425 EpetraExt::ModelEvaluator::OutArgs *epetraUnscaledOutArgs, 00426 // The passed-in form of W 00427 RCP<LinearOpBase<double> > *W_op, 00428 RCP<EpetraLinearOp> *efwdW, 00429 // The actual Epetra object passed to the underylying EpetraExt::ModelEvaluator 00430 RCP<Epetra_Operator> *eW 00431 ) const; 00432 00434 void preEvalScalingSetup( 00435 EpetraExt::ModelEvaluator::InArgs *epetraInArgs, 00436 EpetraExt::ModelEvaluator::OutArgs *epetraUnscaledOutArgs, 00437 const RCP<Teuchos::FancyOStream> &out, 00438 const Teuchos::EVerbosityLevel verbLevel 00439 ) const; 00440 00442 void postEvalScalingSetup( 00443 const EpetraExt::ModelEvaluator::OutArgs &epetraUnscaledOutArgs, 00444 const RCP<Teuchos::FancyOStream> &out, 00445 const Teuchos::EVerbosityLevel verbLevel 00446 ) const; 00447 00449 void finishConvertingOutArgsFromEpetraToThyra( 00450 const EpetraExt::ModelEvaluator::OutArgs &epetraOutArgs, 00451 RCP<LinearOpBase<double> > &W_op, 00452 RCP<EpetraLinearOp> &efwdW, 00453 RCP<Epetra_Operator> &eW, 00454 const ModelEvaluatorBase::OutArgs<double> &outArgs // Output! 00455 ) const; 00456 // 2007/08/03: rabartl: Above, I pass many of the RCP objects by non-const 00457 // reference since I don't want the compiler to perform any implicit 00458 // conversions on this RCP objects. 00459 00461 void updateNominalValuesAndBounds() const; 00462 00464 void updateInArgsOutArgs() const; 00465 00467 RCP<EpetraLinearOp> create_epetra_W_op() const; 00468 00469 }; 00470 00471 00472 // 00473 // Utility functions 00474 // 00475 00476 00480 RCP<EpetraModelEvaluator> 00481 epetraModelEvaluator( 00482 const RCP<const EpetraExt::ModelEvaluator> &epetraModel, 00483 const RCP<LinearOpWithSolveFactoryBase<double> > &W_factory 00484 ); 00485 00486 00490 ModelEvaluatorBase::EDerivativeMultiVectorOrientation 00491 convert( const EpetraExt::ModelEvaluator::EDerivativeMultiVectorOrientation &mvOrientation ); 00492 00493 00497 EpetraExt::ModelEvaluator::EDerivativeMultiVectorOrientation 00498 convert( const ModelEvaluatorBase::EDerivativeMultiVectorOrientation &mvOrientation ); 00499 00500 00504 ModelEvaluatorBase::DerivativeProperties 00505 convert( const EpetraExt::ModelEvaluator::DerivativeProperties &derivativeProperties ); 00506 00507 00511 ModelEvaluatorBase::DerivativeSupport 00512 convert( const EpetraExt::ModelEvaluator::DerivativeSupport &derivativeSupport ); 00513 00514 00518 EpetraExt::ModelEvaluator::Derivative 00519 convert( 00520 const ModelEvaluatorBase::Derivative<double> &derivative, 00521 const RCP<const Epetra_Map> &fnc_map, 00522 const RCP<const Epetra_Map> &var_map 00523 ); 00524 00525 00526 } // namespace Thyra 00527 00528 00529 #endif // THYRA_EPETRA_MODEL_EVALUATOR_HPP
1.7.6.1