00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00302
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
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
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_;
00373 mutable RCP<const Epetra_Vector> invStateVariableScalingVec_;
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
00381
00382
00383
00384
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
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
00419 const ModelEvaluatorBase::OutArgs<double> &outArgs,
00420
00421 EpetraExt::ModelEvaluator::OutArgs *epetraUnscaledOutArgs,
00422
00423 RCP<LinearOpWithSolveBase<double> > *W,
00424 RCP<LinearOpBase<double> > *W_op,
00425
00426 RCP<const LinearOpBase<double> > *fwdW,
00427 RCP<EpetraLinearOp> *efwdW,
00428
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
00456 ) const;
00457
00458
00459
00460
00462 void updateNominalValuesAndBounds() const;
00463
00465 void updateInArgsOutArgs() const;
00466
00467 };
00468
00469
00470
00471
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 }
00525
00526
00527 #endif // THYRA_EPETRA_MODEL_EVALUATOR_HPP