Thyra  Version of the Day
Thyra_ModelEvaluatorBase_decl.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef THYRA_MODEL_EVALUATOR_BASE_DECL_HPP
43 #define THYRA_MODEL_EVALUATOR_BASE_DECL_HPP
44 
45 
46 #include "Thyra_LinearOpWithSolveBase.hpp"
47 #include "Teuchos_Describable.hpp"
48 #include "Teuchos_Assert.hpp"
49 
50 #ifdef HAVE_THYRA_ME_POLYNOMIAL
51 # include "Teuchos_Polynomial.hpp"
52 #endif
53 
54 namespace Stokhos {
55  class ProductEpetraVector;
56  class ProductEpetraMultiVector;
57  class ProductEpetraOperator;
58 }
59 
60 namespace Thyra {
61 
62 
83  : virtual public Teuchos::Describable,
84  virtual public Teuchos::VerboseObject<ModelEvaluatorBase>
85 {
86 public:
87 
90 
104  };
106  static const int NUM_E_IN_ARGS_MEMBERS=11;
107 
111  };
112 
123  template<class Scalar>
124  class InArgs : public Teuchos::Describable {
125  public:
127  typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
129  InArgs();
132  int Np() const;
134  bool supports(EInArgsMembers arg) const;
136  void set_x_dot( const RCP<const VectorBase<Scalar> > &x_dot );
138  RCP<const VectorBase<Scalar> > get_x_dot() const;
140  void set_x( const RCP<const VectorBase<Scalar> > &x );
142  RCP<const VectorBase<Scalar> > get_x() const;
143 
144 #ifdef HAVE_THYRA_ME_POLYNOMIAL
145 
146  void set_x_poly(
147  const RCP<const Teuchos::Polynomial< VectorBase<Scalar> > > &x_poly );
149  RCP<const Teuchos::Polynomial< VectorBase<Scalar> > > get_x_poly() const;
151  void set_x_dot_poly(
152  const RCP<const Teuchos::Polynomial< VectorBase<Scalar> > > &x_dot_poly );
154  RCP<const Teuchos::Polynomial< VectorBase<Scalar> > > get_x_dot_poly() const;
155 #endif // HAVE_THYRA_ME_POLYNOMIAL
156 
157  void set_p( int l, const RCP<const VectorBase<Scalar> > &p_l );
159  RCP<const VectorBase<Scalar> > get_p(int l) const;
160 
161 
163  void set_x_dot_mp( const RCP<const Stokhos::ProductEpetraVector > &x_dot_mp );
165  RCP<const Stokhos::ProductEpetraVector > get_x_dot_mp() const;
166 
168  void set_x_mp( const RCP<const Stokhos::ProductEpetraVector > &x_mp );
170  RCP<const Stokhos::ProductEpetraVector > get_x_mp() const;
171 
172  void set_p_mp( int l, const RCP<const Stokhos::ProductEpetraVector > &p_mp_l );
173  RCP<const Stokhos::ProductEpetraVector > get_p_mp(int l) const;
175  bool supports(EInArgs_p_mp arg, int l) const;
176 
177 
179  void set_t( ScalarMag t );
181  ScalarMag get_t() const;
183  void set_alpha( Scalar alpha );
185  Scalar get_alpha() const;
187  void set_beta( Scalar beta );
189  Scalar get_beta() const;
191  void set_step_size( Scalar step_size);
193  Scalar get_step_size() const;
195  void set_stage_number( Scalar stage_number);
197  Scalar get_stage_number() const;
200  void setArgs(
201  const InArgs<Scalar>& inArgs, bool ignoreUnsupported = false,
202  bool cloneObjects = false
203  );
205  void assertSameSupport( const InArgs<Scalar> &inArgs ) const;
207  std::string modelEvalDescription() const;
209  std::string description() const;
212  void describe(
213  Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel
214  ) const;
215  protected:
217  void _setModelEvalDescription( const std::string &modelEvalDescription );
219  void _set_Np(int Np);
221  void _setSupports( EInArgsMembers arg, bool supports );
223  void _setSupports( EInArgs_p_mp arg, int l, bool supports );
225  void _setSupports( const InArgs<Scalar>& inputInArgs, const int Np );
228  private:
229  // types
230  typedef Teuchos::Array<RCP<const VectorBase<Scalar> > > p_t;
231  // data
232  std::string modelEvalDescription_;
233  RCP<const VectorBase<Scalar> > x_dot_;
234  RCP<const VectorBase<Scalar> > x_;
235  RCP<const Stokhos::ProductEpetraVector > x_dot_mp_;
236  RCP<const Stokhos::ProductEpetraVector > x_mp_;
237  Teuchos::Array< RCP< const Stokhos::ProductEpetraVector > > p_mp_;
238 #ifdef HAVE_THYRA_ME_POLYNOMIAL
239  RCP<const Teuchos::Polynomial< VectorBase<Scalar> > > x_dot_poly_;
240  RCP<const Teuchos::Polynomial< VectorBase<Scalar> > > x_poly_;
241 #endif // HAVE_THYRA_ME_POLYNOMIAL
242  p_t p_;
243  ScalarMag t_;
244  Scalar alpha_;
245  Scalar beta_;
246  Scalar step_size_;
247  Scalar stage_number_;
248  bool supports_[NUM_E_IN_ARGS_MEMBERS];
249  Teuchos::Array<bool> supports_p_mp_; //Np
250  // functions
251  void assert_supports(EInArgsMembers arg) const;
252  void assert_supports(EInArgs_p_mp arg, int l) const;
253  void assert_l(int l) const;
254  };
255 
257  enum EEvalType {
258  EVAL_TYPE_EXACT = 0,
261  };
262 
269  template<class ObjType>
270  class Evaluation : public RCP<ObjType> {
271  public:
273  Evaluation(Teuchos::ENull)
274  : evalType_(EVAL_TYPE_EXACT) {}
276  Evaluation() : evalType_(EVAL_TYPE_EXACT) {}
278  Evaluation( const RCP<ObjType> &obj )
279  : RCP<ObjType>(obj), evalType_(EVAL_TYPE_EXACT) {}
281  Evaluation( const RCP<ObjType> &obj, EEvalType evalType )
282  : RCP<ObjType>(obj), evalType_(evalType) {}
284  EEvalType getType() const { return evalType_; }
286  void reset( const RCP<ObjType> &obj, EEvalType evalType )
287  { this->operator=(obj); evalType_ = evalType; }
288  private:
289  EEvalType evalType_;
290  };
291 
298  };
299 
303  };
304 
308  public:
311  :supportsLinearOp_(false), supportsMVByCol_(false), supportsTransMVByRow_(false)
312  {}
315  :supportsLinearOp_(true), supportsMVByCol_(false), supportsTransMVByRow_(false)
316  {}
319  :supportsLinearOp_(false), supportsMVByCol_(mvOrientation==DERIV_MV_BY_COL)
320  ,supportsTransMVByRow_(mvOrientation==DERIV_TRANS_MV_BY_ROW)
321  {}
324  { supportsLinearOp_ = true; return *this; }
327  {
328  switch(mvOrientation) {
329  case DERIV_MV_BY_COL: supportsMVByCol_ = true; break;
330  case DERIV_TRANS_MV_BY_ROW: supportsTransMVByRow_ = true; break;
331  default: TEUCHOS_TEST_FOR_EXCEPT(true);
332  }
333  return *this;
334  }
336  bool none() const
337  { return ( !supportsLinearOp_ && !supportsMVByCol_ && !supportsTransMVByRow_ ); }
340  { return supportsLinearOp_; }
342  bool supports(EDerivativeMultiVectorOrientation mvOrientation) const
343  {
344  switch(mvOrientation) {
345  case DERIV_MV_BY_COL: return supportsMVByCol_;
346  case DERIV_TRANS_MV_BY_ROW: return supportsTransMVByRow_;
347  default: TEUCHOS_TEST_FOR_EXCEPT(true);
348  }
349  return false; // Will never be called!
350  }
352  bool isSameSupport(const DerivativeSupport &derivSupport) const
353  {
354  return (
355  supportsLinearOp_ == derivSupport.supportsLinearOp_
356  && supportsMVByCol_ == derivSupport.supportsMVByCol_
357  && supportsTransMVByRow_ == derivSupport.supportsTransMVByRow_
358  );
359  }
361  std::string description() const;
362  private:
363  bool supportsLinearOp_;
364  bool supportsMVByCol_;
365  bool supportsTransMVByRow_;
366  public:
367  };
368 
374  };
375 
377  enum ERankStatus {
381  };
382 
396  {}
399  EDerivativeLinearity in_linearity, ERankStatus in_rank,
400  bool in_supportsAdjoint
401  )
402  :linearity(in_linearity),rank(in_rank),
403  supportsAdjoint(in_supportsAdjoint)
404  {}
405  };
406 
410  template<class Scalar>
412  public:
415  :orientation_(DERIV_MV_BY_COL)
416  {}
419  const RCP<MultiVectorBase<Scalar> > &mv
421  ) : mv_(mv.assert_not_null()), orientation_(orientation) {}
424  { orientation_ = orientation; };
427  { mv_.assert_not_null(); return *this; }
429  RCP<MultiVectorBase<Scalar> > getMultiVector() const
430  { return mv_; }
433  { return orientation_; }
435  std::string description() const;
437  void describe(
438  Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel
439  ) const;
440  private:
441  RCP<MultiVectorBase<Scalar> > mv_;
443  };
444 
448  template<class Scalar>
449  class Derivative {
450  public:
454  Derivative( const RCP<LinearOpBase<Scalar> > &lo )
455  : lo_(lo.assert_not_null()) {}
458  const RCP<MultiVectorBase<Scalar> > &mv,
460  ) : dmv_(mv,orientation) {}
463  : dmv_(dmv) {}
465  bool isEmpty() const
466  { return ( lo_.get()==NULL && dmv_.getMultiVector().get()==NULL ); }
469  { dmv_.assert_not_null(); lo_.assert_not_null(); return *this; }
471  RCP<LinearOpBase<Scalar> > getLinearOp() const
472  { return lo_; }
474  RCP<MultiVectorBase<Scalar> > getMultiVector() const
475  { return dmv_.getMultiVector(); }
478  { return dmv_.getOrientation(); }
481  { return dmv_; }
485  bool isSupportedBy( const DerivativeSupport &derivSupport ) const
486  {
487  // If there is not derivative support then we will return false!
488  if (derivSupport.none())
489  return false;
490  if (!is_null(getMultiVector())) {
491  return derivSupport.supports(getMultiVectorOrientation());
492  }
493  else if(!is_null(getLinearOp())) {
494  return derivSupport.supports(DERIV_LINEAR_OP);
495  }
496  // If nothing is set then of course we support that!
497  return true;
498  }
500  std::string description() const;
502  void describe(
503  Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel
504  ) const;
505  private:
506  RCP<LinearOpBase<Scalar> > lo_;
508  };
509 
514  public:
517  :orientation_(DERIV_MV_BY_COL)
518  {}
521  const RCP<Stokhos::ProductEpetraMultiVector > &mv
523  ,const Teuchos::Array<int> &paramIndexes = Teuchos::Array<int>()
524  ) : mv_(mv.assert_not_null()), orientation_(orientation), paramIndexes_(paramIndexes) {}
527  { orientation_ = orientation; };
530  { mv_.assert_not_null(); return *this; }
532  RCP<Stokhos::ProductEpetraMultiVector > getMultiVector() const
533  { return mv_; }
536  { return orientation_; }
538  const Teuchos::Array<int>& getParamIndexes() const
539  { return paramIndexes_; }
541  std::string description() const {return "\n";}
543  void describe(
544  Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel
545  ) const {}
546  private:
547  RCP<Stokhos::ProductEpetraMultiVector > mv_;
549  Teuchos::Array<int> paramIndexes_;
550  };
551 
555  class MPDerivative {
556  public:
560  MPDerivative( const RCP<Stokhos::ProductEpetraOperator > &lo )
561  : lo_(lo.assert_not_null()) {}
564  const RCP<Stokhos::ProductEpetraMultiVector > &mv,
566  ) : dmv_(mv,orientation) {}
569  : dmv_(dmv) {}
571  bool isEmpty() const
572  { return ( lo_.get()==NULL && dmv_.getMultiVector().get()==NULL ); }
575  { dmv_.assert_not_null(); lo_.assert_not_null(); return *this; }
577  RCP<Stokhos::ProductEpetraOperator > getLinearOp() const
578  { return lo_; }
580  RCP<Stokhos::ProductEpetraMultiVector > getMultiVector() const
581  { return dmv_.getMultiVector(); }
584  { return dmv_.getOrientation(); }
587  { return dmv_; }
591  bool isSupportedBy( const DerivativeSupport &derivSupport ) const
592  {
593  // If there is not derivative support then we will return false!
594  if (derivSupport.none())
595  return false;
596  if (!is_null(getMultiVector())) {
597  return derivSupport.supports(getMultiVectorOrientation());
598  }
599  else if(!is_null(getLinearOp())) {
600  return derivSupport.supports(DERIV_LINEAR_OP);
601  }
602  // If nothing is set then of course we support that!
603  return true;
604  }
606  std::string description() const {return "\n";}
608  void describe(
609  Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel
610  ) const {}
611  private:
612  RCP<Stokhos::ProductEpetraOperator > lo_;
614  };
615 
625  };
627  static const int NUM_E_OUT_ARGS_MEMBERS=7;
628 
632  };
633 
637  };
638 
642  };
643 
647  };
648 
652  };
653 
657  };
658 
662  };
663 
667  };
668 
672  };
673 
694  template<class Scalar>
695  class OutArgs : public Teuchos::Describable {
696  public:
698  OutArgs();
701  int Np() const;
704  int Ng() const;
706  bool supports(EOutArgsMembers arg) const;
709  const DerivativeSupport& supports(EOutArgsDfDp arg, int l) const;
712  const DerivativeSupport& supports(EOutArgsDgDx_dot arg, int j) const;
715  const DerivativeSupport& supports(EOutArgsDgDx arg, int j) const;
718  const DerivativeSupport& supports(EOutArgsDgDp arg, int j, int l) const;
720  void set_f( const Evaluation<VectorBase<Scalar> > &f );
724  void set_g( int j, const Evaluation<VectorBase<Scalar> > &g_j );
726  Evaluation<VectorBase<Scalar> > get_g(int j) const;
728  void set_W( const RCP<LinearOpWithSolveBase<Scalar> > &W );
730  RCP<LinearOpWithSolveBase<Scalar> > get_W() const;
731 
732  const DerivativeSupport& supports(EOutArgsDfDp_mp arg, int l) const;
733  bool supports(EOutArgs_g_mp arg, int j) const;
734  const DerivativeSupport& supports(EOutArgsDgDx_dot_mp arg, int j) const;
735  const DerivativeSupport& supports(EOutArgsDgDx_mp arg, int j) const;
736  const DerivativeSupport& supports(EOutArgsDgDp_mp arg, int j, int l) const;
738  void set_f_mp( const RCP<Stokhos::ProductEpetraVector> &f_mp );
740  RCP<Stokhos::ProductEpetraVector> get_f_mp() const;
742  void set_g_mp( int j, const RCP<Stokhos::ProductEpetraVector> &g_mp_j );
744  RCP<Stokhos::ProductEpetraVector> get_g_mp(int j) const;
746  void set_W_mp( const RCP<Stokhos::ProductEpetraOperator> &W_mp );
748  RCP<Stokhos::ProductEpetraOperator> get_W_mp() const;
749 
751  void set_W_op( const RCP<LinearOpBase<Scalar> > &W_op );
753  RCP<LinearOpBase<Scalar> > get_W_op() const;
755  void set_W_prec( const RCP<PreconditionerBase<Scalar> > &W_prec );
757  RCP<PreconditionerBase<Scalar> > get_W_prec() const;
762  void set_DfDp(int l, const Derivative<Scalar> &DfDp_l);
764  Derivative<Scalar> get_DfDp(int l) const;
769  void set_DgDx_dot(int j, const Derivative<Scalar> &DgDx_dot_j);
771  Derivative<Scalar> get_DgDx_dot(int j) const;
776  void set_DgDx(int j, const Derivative<Scalar> &DgDx_j);
778  Derivative<Scalar> get_DgDx(int j) const;
783  void set_DgDp( int j, int l, const Derivative<Scalar> &DgDp_j_l );
785  Derivative<Scalar> get_DgDp(int j, int l) const;
788  DerivativeProperties get_DgDp_properties(int j, int l) const;
789 
790  void set_DfDp_mp(int l, const MPDerivative &DfDp_mp_l);
791  MPDerivative get_DfDp_mp(int l) const;
792  DerivativeProperties get_DfDp_mp_properties(int l) const;
793  void set_DgDx_dot_mp(int j, const MPDerivative &DgDx_dot_mp_j);
794  MPDerivative get_DgDx_dot_mp(int j) const;
795  DerivativeProperties get_DgDx_dot_mp_properties(int j) const;
796  void set_DgDx_mp(int j, const MPDerivative &DgDx_mp_j);
797  MPDerivative get_DgDx_mp(int j) const;
798  DerivativeProperties get_DgDx_mp_properties(int j) const;
799  void set_DgDp_mp( int j, int l, const MPDerivative &DgDp_mp_j_l );
800  MPDerivative get_DgDp_mp(int j, int l) const;
801  DerivativeProperties get_DgDp_mp_properties(int j, int l) const;
802 
803 #ifdef HAVE_THYRA_ME_POLYNOMIAL
804 
805  void set_f_poly( const RCP<Teuchos::Polynomial< VectorBase<Scalar> > > &f_poly );
807  RCP<Teuchos::Polynomial< VectorBase<Scalar> > > get_f_poly() const;
808 #endif // HAVE_THYRA_ME_POLYNOMIAL
809 
814  void setArgs( const OutArgs<Scalar>& outArgs, bool ignoreUnsupported = false );
826  void setFailed() const;
832  bool isFailed() const;
834  bool isEmpty() const;
836  void assertSameSupport( const OutArgs<Scalar> &outArgs ) const;
838  std::string modelEvalDescription() const;
840  std::string description() const;
843  void describe(
844  Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel
845  ) const;
846  protected:
848  void _setModelEvalDescription( const std::string &modelEvalDescription );
850  void _set_Np_Ng(int Np, int Ng);
852  void _setSupports( EOutArgsMembers arg, bool supports );
854  void _setSupports( EOutArgsDfDp arg, int l, const DerivativeSupport& );
856  void _setSupports( EOutArgsDgDx_dot arg, int j, const DerivativeSupport& );
858  void _setSupports( EOutArgsDgDx arg, int j, const DerivativeSupport& );
860  void _setSupports( EOutArgsDgDp arg, int j, int l, const DerivativeSupport& );
861 
862  void _setSupports( EOutArgs_g_mp arg, int j, bool supports );
863  void _setSupports( EOutArgsDfDp_mp arg, int l, const DerivativeSupport& );
864  void _setSupports( EOutArgsDgDx_dot_mp arg, int j, const DerivativeSupport& );
865  void _setSupports( EOutArgsDgDx_mp arg, int j, const DerivativeSupport& );
866  void _setSupports( EOutArgsDgDp_mp arg, int j, int l, const DerivativeSupport& );
867 
869  void _set_W_properties( const DerivativeProperties &properties );
871  void _set_DfDp_properties( int l, const DerivativeProperties &properties );
873  void _set_DgDx_dot_properties( int j, const DerivativeProperties &properties );
875  void _set_DgDx_properties( int j, const DerivativeProperties &properties );
877  void _set_DgDp_properties( int j, int l, const DerivativeProperties &properties );
878 
879  void _set_DfDp_mp_properties( int l, const DerivativeProperties &properties );
880  void _set_DgDx_dot_mp_properties( int j, const DerivativeProperties &properties );
881  void _set_DgDx_mp_properties( int j, const DerivativeProperties &properties );
882  void _set_DgDp_mp_properties( int j, int l, const DerivativeProperties &properties );
883 
885  void _setSupports( const OutArgs<Scalar>& inputOutArgs );
890  private:
891  // types
892  typedef Teuchos::Array<Evaluation<VectorBase<Scalar> > > g_t;
893  typedef Teuchos::Array<Derivative<Scalar> > deriv_t;
894  typedef Teuchos::Array<DerivativeProperties> deriv_properties_t;
895  typedef Teuchos::Array<DerivativeSupport> supports_t;
896  // data
897  std::string modelEvalDescription_;
898  bool supports_[NUM_E_OUT_ARGS_MEMBERS];
899  supports_t supports_DfDp_; // Np
900  supports_t supports_DgDx_dot_; // Ng
901  supports_t supports_DgDx_; // Ng
902  supports_t supports_DgDp_; // Ng x Np
904  g_t g_; // Ng
905  RCP<LinearOpWithSolveBase<Scalar> > W_;
906  RCP<LinearOpBase<Scalar> > W_op_;
907  RCP<PreconditionerBase<Scalar> > W_prec_;
908  DerivativeProperties W_properties_;
909  deriv_t DfDp_; // Np
910  deriv_properties_t DfDp_properties_; // Np
911  deriv_t DgDx_dot_; // Ng
912  deriv_t DgDx_; // Ng
913  deriv_properties_t DgDx_dot_properties_; // Ng
914  deriv_properties_t DgDx_properties_; // Ng
915  deriv_t DgDp_; // Ng x Np
916  deriv_properties_t DgDp_properties_; // Ng x Np
917 
918  Teuchos::Array<bool> supports_g_mp_; //Ng
919  supports_t supports_DfDp_mp_; // Np_mp
920  supports_t supports_DgDx_dot_mp_; // Ng_mp
921  supports_t supports_DgDx_mp_; // Ng_mp
922  supports_t supports_DgDp_mp_; // Ng_mp x Np_mp
923  Teuchos::Array< RCP< Stokhos::ProductEpetraVector > > g_mp_;
924  RCP<Stokhos::ProductEpetraVector> f_mp_;
925  RCP<Stokhos::ProductEpetraOperator> W_mp_;
926  Teuchos::Array<MPDerivative> DfDp_mp_;
927  Teuchos::Array<MPDerivative> DgDx_dot_mp_;
928  Teuchos::Array<MPDerivative> DgDx_mp_;
929  Teuchos::Array<MPDerivative> DgDp_mp_;
930  deriv_properties_t DfDp_mp_properties_;
931  deriv_properties_t DgDx_dot_mp_properties_;
932  deriv_properties_t DgDx_mp_properties_;
933  deriv_properties_t DgDp_mp_properties_;
934 
935 #ifdef HAVE_THYRA_ME_POLYNOMIAL
936  RCP<Teuchos::Polynomial< VectorBase<Scalar> > > f_poly_;
937 #endif // HAVE_THYRA_ME_POLYNOMIAL
938  mutable bool isFailed_;
939  // functions
940  void assert_supports(EOutArgsMembers arg) const;
941  void assert_supports(
942  EOutArgsDfDp arg, int l,
943  const Derivative<Scalar> &deriv = Derivative<Scalar>()
944  ) const;
945  void assert_supports(
946  EOutArgsDgDx_dot arg, int j,
947  const Derivative<Scalar> &deriv = Derivative<Scalar>()
948  ) const;
949  void assert_supports(
950  EOutArgsDgDx arg, int j,
951  const Derivative<Scalar> &deriv = Derivative<Scalar>()
952  ) const;
953  void assert_supports(
954  EOutArgsDgDp arg, int j, int l,
955  const Derivative<Scalar> &deriv = Derivative<Scalar>()
956  ) const;
957 
958  void assert_supports(EOutArgs_g_mp arg, int j) const;
959  void assert_supports(
960  EOutArgsDfDp_mp arg, int l,
961  const MPDerivative &deriv = MPDerivative()
962  ) const;
963  void assert_supports(
964  EOutArgsDgDx_dot_mp arg, int j,
965  const MPDerivative &deriv = MPDerivative()
966  ) const;
967  void assert_supports(
968  EOutArgsDgDx_mp arg, int j,
969  const MPDerivative &deriv = MPDerivative()
970  ) const;
971  void assert_supports(
972  EOutArgsDgDp_mp arg, int j, int l,
973  const MPDerivative &deriv = MPDerivative()
974  ) const;
975 
976  void assert_l(int l) const;
977  void assert_j(int j) const;
978  };
979 
981 
982 // Added since at least gcc 3.3.4 does not do the right thing here!
983 #ifdef HAVE_PROTECTED_NESTED_TEMPLATE_CLASS_ACCESS
984 protected:
985 #endif
986 
989 
997  template<class Scalar>
998  class InArgsSetup : public InArgs<Scalar> {
999  public:
1001  InArgsSetup();
1003  InArgsSetup( const InArgs<Scalar>& );
1005  void setModelEvalDescription( const std::string &modelEvalDescription );
1007  void set_Np(int Np);
1009  void setSupports( EInArgsMembers arg, bool supports = true );
1011  void setSupports( const InArgs<Scalar>& inputInArgs, const int Np = -1 );
1014 
1015  void setSupports( EInArgs_p_mp arg, int l, bool supports);
1016  };
1017 
1025  template<class Scalar>
1026  class OutArgsSetup : public OutArgs<Scalar> {
1027  public:
1029  OutArgsSetup();
1031  OutArgsSetup( const OutArgs<Scalar>& );
1033  void setModelEvalDescription( const std::string &modelEvalDescription );
1035  void set_Np_Ng(int Np, int Ng);
1037  void setSupports( EOutArgsMembers arg, bool supports = true );
1039  void setSupports(EOutArgsDfDp arg, int l, const DerivativeSupport& );
1041  void setSupports(EOutArgsDgDx_dot arg, int j, const DerivativeSupport& );
1043  void setSupports(EOutArgsDgDx arg, int j, const DerivativeSupport& );
1045  void setSupports(EOutArgsDgDp arg, int j, int l, const DerivativeSupport& );
1046 
1047  void setSupports( EOutArgs_g_mp arg, int j, bool supports);
1048  void setSupports(EOutArgsDfDp_mp arg, int l, const DerivativeSupport& );
1049  void setSupports(EOutArgsDgDx_dot_mp arg, int j, const DerivativeSupport& );
1050  void setSupports(EOutArgsDgDx_mp arg, int j, const DerivativeSupport& );
1051  void setSupports(EOutArgsDgDp_mp arg, int j, int l, const DerivativeSupport& );
1052 
1054  void set_W_properties( const DerivativeProperties &properties );
1056  void set_DfDp_properties( int l, const DerivativeProperties &properties );
1058  void set_DgDx_dot_properties( int j, const DerivativeProperties &properties );
1060  void set_DgDx_properties( int j, const DerivativeProperties &properties );
1062  void set_DgDp_properties( int j, int l, const DerivativeProperties &properties );
1063 
1064  void set_DfDp_mp_properties( int l, const DerivativeProperties &properties );
1065  void set_DgDx_dot_mp_properties( int j, const DerivativeProperties &properties );
1066  void set_DgDx_mp_properties( int j, const DerivativeProperties &properties );
1067  void set_DgDp_mp_properties( int j, int l, const DerivativeProperties &properties );
1068 
1070  void setSupports( const OutArgs<Scalar>& inputOutArgs );
1075  };
1076 
1078 
1081 
1084 
1086 
1087 private:
1088  // Not defined and not to be called
1090  ModelEvaluatorBase& operator=(const ModelEvaluatorBase&);
1091 
1092 }; // ModelEvaluatorBase
1093 
1094 
1097 
1098 
1101 
1102 
1104 std::string toString(
1106  );
1107 
1108 
1111 getOtherDerivativeMultiVectorOrientation(
1113  );
1114 
1115 
1116 } // namespace Thyra
1117 
1118 
1119 // //////////////////////////////////
1120 // Inline Defintions
1121 
1122 
1123 //
1124 // Thyra_MEB_helper_functions_grp
1125 //
1126 
1127 
1128 inline
1129 std::string Thyra::toString(ModelEvaluatorBase::EInArgsMembers arg)
1130 {
1131  switch(arg) {
1132  case ModelEvaluatorBase::IN_ARG_x_dot:
1133  return "IN_ARG_x_dot";
1134  case ModelEvaluatorBase::IN_ARG_x:
1135  return "IN_ARG_x";
1136  case ModelEvaluatorBase::IN_ARG_x_dot_poly:
1137  return "IN_ARG_x_dot_poly";
1138  case ModelEvaluatorBase::IN_ARG_x_poly:
1139  return "IN_ARG_x_poly";
1140  case ModelEvaluatorBase::IN_ARG_x_dot_mp:
1141  return "IN_ARG_x_dot_mp";
1142  case ModelEvaluatorBase::IN_ARG_x_mp:
1143  return "IN_ARG_x_mp";
1144  case ModelEvaluatorBase::IN_ARG_t:
1145  return "IN_ARG_t";
1146  case ModelEvaluatorBase::IN_ARG_alpha:
1147  return "IN_ARG_alpha";
1148  case ModelEvaluatorBase::IN_ARG_beta:
1149  return "IN_ARG_beta";
1150  case ModelEvaluatorBase::IN_ARG_step_size:
1151  return "IN_ARG_step_size";
1152  case ModelEvaluatorBase::IN_ARG_stage_number:
1153  return "IN_ARG_stage_number";
1154 #ifdef TEUCHOS_DEBUG
1155  default:
1156  TEUCHOS_TEST_FOR_EXCEPT(true);
1157 #endif
1158  }
1159  return ""; // Will never be executed!
1160 }
1161 
1162 
1163 inline
1164 std::string Thyra::toString(ModelEvaluatorBase::EOutArgsMembers arg)
1165 {
1166  switch(arg) {
1167  case ModelEvaluatorBase::OUT_ARG_f:
1168  return "OUT_ARG_f";
1169  case ModelEvaluatorBase::OUT_ARG_W:
1170  return "OUT_ARG_W";
1171  case ModelEvaluatorBase::OUT_ARG_f_mp:
1172  return "OUT_ARG_f_mp";
1173  case ModelEvaluatorBase::OUT_ARG_W_mp:
1174  return "OUT_ARG_W_mp";
1175  case ModelEvaluatorBase::OUT_ARG_W_op:
1176  return "OUT_ARG_W_op";
1177  case ModelEvaluatorBase::OUT_ARG_W_prec:
1178  return "OUT_ARG_W_prec";
1179  case ModelEvaluatorBase::OUT_ARG_f_poly:
1180  return "OUT_ARG_f_poly";
1181 #ifdef TEUCHOS_DEBUG
1182  default:
1183  TEUCHOS_TEST_FOR_EXCEPT(true);
1184 #endif
1185  }
1186  return ""; // Will never be executed!
1187 }
1188 
1189 
1190 inline
1191 std::string Thyra::toString(
1192  ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
1193  )
1194 {
1195  switch(orientation) {
1196  case ModelEvaluatorBase::DERIV_MV_BY_COL:
1197  return "DERIV_MV_BY_COL";
1198  case ModelEvaluatorBase::DERIV_TRANS_MV_BY_ROW:
1199  return "DERIV_TRANS_MV_BY_ROW";
1200 #ifdef TEUCHOS_DEBUG
1201  default:
1202  TEUCHOS_TEST_FOR_EXCEPT(true);
1203 #endif
1204  }
1205  return ""; // Should never execute this!
1206 }
1207 
1208 
1209 inline
1211 Thyra::getOtherDerivativeMultiVectorOrientation(
1212  ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
1213  )
1214 {
1215  switch(orientation) {
1216  case ModelEvaluatorBase::DERIV_MV_BY_COL:
1217  return ModelEvaluatorBase::DERIV_TRANS_MV_BY_ROW;
1218  case ModelEvaluatorBase::DERIV_TRANS_MV_BY_ROW:
1219  return ModelEvaluatorBase::DERIV_MV_BY_COL;
1220 #ifdef TEUCHOS_DEBUG
1221  default:
1222  TEUCHOS_TEST_FOR_EXCEPT(true);
1223 #endif
1224  }
1225  return ModelEvaluatorBase::DERIV_MV_BY_COL; // Should never execute this!
1226 }
1227 
1228 
1229 #endif // THYRA_MODEL_EVALUATOR_BASE_DECL_HPP
Protected subclass of InArgs that only ModelEvaluator subclasses can access to set up the selection o...
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
RCP< const Stokhos::ProductEpetraVector > get_x_dot_mp() const
Precondition: supports(IN_ARG_x_dotmp)==true.
bool isSupportedBy(const DerivativeSupport &derivSupport) const
Returns true if the form of the derivative contained here is supported by deriveSupport.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Scalar get_step_size() const
Precondition: supports(IN_ARG_step_size)==true.
void set_DgDx_properties(int j, const DerivativeProperties &properties)
MPDerivative(const RCP< Stokhos::ProductEpetraOperator > &lo)
RCP< LinearOpWithSolveBase< Scalar > > get_W() const
Precondition: supports(OUT_ARG_W)==true.
void set_DfDp_properties(int l, const DerivativeProperties &properties)
Base class for all linear operators that can support a high-level solve operation.
void set_step_size(Scalar step_size)
Precondition: supports(IN_ARG_step_size)==true.
void setArgs(const OutArgs< Scalar > &outArgs, bool ignoreUnsupported=false)
Set all arguments fron outArgs into *this.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Create a more detailed description along about this object and the ModelEvaluator that created it...
bool supports(EInArgsMembers arg) const
Determines if an input argument is supported or not.
bool isSupportedBy(const DerivativeSupport &derivSupport) const
Returns true if the form of the derivative contained here is supported by deriveSupport.
void _set_DfDp_properties(int l, const DerivativeProperties &properties)
Concrete aggregate class for all output arguments computable by a ModelEvaluator subclass object...
void set_g(int j, const Evaluation< VectorBase< Scalar > > &g_j)
Precondition: supports(OUT_ARG_g)==true.
DerivativeProperties get_DgDp_properties(int j, int l) const
Return the know properties of DgDp(j,l) (precondition: supports(OUT_ARG_DgDp,j,l)==true).
MPDerivative(const RCP< Stokhos::ProductEpetraMultiVector > &mv, const EDerivativeMultiVectorOrientation orientation=DERIV_MV_BY_COL)
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
void setModelEvalDescription(const std::string &modelEvalDescription)
void set_W_mp(const RCP< Stokhos::ProductEpetraOperator > &W_mp)
Precondition: supports(OUT_ARG_W_mp)==true.
void _set_DgDx_dot_properties(int j, const DerivativeProperties &properties)
void set_W_prec(const RCP< PreconditionerBase< Scalar > > &W_prec)
Precondition: supports(OUT_ARG_W_op)==true.
Derivative< Scalar > get_DfDp(int l) const
Precondition: supports(OUT_ARG_DfDp,l)==true.
Scalar get_beta() const
Precondition: supports(IN_ARG_beta)==true.
Derivative< Scalar > get_DgDp(int j, int l) const
Precondition: supports(OUT_ARG_DgDp,j,l)==true.
RCP< LinearOpBase< Scalar > > getLinearOp() const
void changeOrientation(const EDerivativeMultiVectorOrientation orientation)
void set_x_dot_mp(const RCP< const Stokhos::ProductEpetraVector > &x_dot_mp)
Precondition: supports(IN_ARG_x_dot_mp)==true.
Simple aggregate class that stores a derivative object as a general linear operator or as a multi-vec...
DerivativeMultiVector(const RCP< MultiVectorBase< Scalar > > &mv, const EDerivativeMultiVectorOrientation orientation=DERIV_MV_BY_COL)
Scalar get_stage_number() const
Precondition: supports(IN_ARG_stage_number)==true.
RCP< const VectorBase< Scalar > > get_x() const
Precondition: supports(IN_ARG_x)==true.
Jacobian form DhDz (nz columns of h_space vectors)
bool supports(EDerivativeMultiVectorOrientation mvOrientation) const
DerivativeProperties get_DfDp_properties(int l) const
Return the know properties of DfDp(l) (precondition: supports(OUT_ARG_DfDp,l)==true).
RCP< const Stokhos::ProductEpetraVector > get_x_mp() const
Precondition: supports(IN_ARG_x_mp)==true.
Derivative< Scalar > get_DgDx(int j) const
Precondition: supports(OUT_ARG_DgDx,j)==true.
void _setSupports(EOutArgsMembers arg, bool supports)
MPDerivative(const MPDerivativeMultiVector &dmv)
MPDerivativeMultiVector getDerivativeMultiVector() const
Derivative(const RCP< MultiVectorBase< Scalar > > &mv, const EDerivativeMultiVectorOrientation orientation=DERIV_MV_BY_COL)
Evaluation(const RCP< ObjType > &obj)
Implicit conversion from RCP<ObjType>.
Simple interface class to access a precreated preconditioner as one or more linear operators objects ...
Scalar get_alpha() const
Precondition: supports(IN_ARG_alph)==true.
RCP< Stokhos::ProductEpetraVector > get_f_mp() const
Precondition: supports(OUT_ARG_f_mp)==true.
EDerivativeMultiVectorOrientation getMultiVectorOrientation() const
ScalarMag get_t() const
.Precondition: supports(IN_ARG_t)==true
DerivativeSupport & plus(EDerivativeMultiVectorOrientation mvOrientation)
Simple aggregate class for a derivative object represented as a column-wise multi-vector or its trans...
void changeOrientation(const EDerivativeMultiVectorOrientation orientation)
Gradient form DhDz^T (nh columns of z_space vectors)
Evaluation(const RCP< ObjType > &obj, EEvalType evalType)
RCP< const VectorBase< Scalar > > get_p(int l) const
Get p(l) where 0 <= l && l < this->Np().
void set_W_properties(const DerivativeProperties &properties)
Derivative< Scalar > get_DgDx_dot(int j) const
Precondition: supports(OUT_ARG_DgDx_dot,j)==true.
void setSupports(EInArgsMembers arg, bool supports=true)
RCP< Stokhos::ProductEpetraOperator > getLinearOp() const
void set_stage_number(Scalar stage_number)
Precondition: supports(IN_ARG_stage_number)==true.
void set_x(const RCP< const VectorBase< Scalar > > &x)
Precondition: supports(IN_ARG_x)==true.
Simple aggregate class for a derivative object represented as a column-wise multi-vector or its trans...
Interface for a collection of column vectors called a multi-vector.
void setArgs(const InArgs< Scalar > &inArgs, bool ignoreUnsupported=false, bool cloneObjects=false)
Set non-null arguments (does not overwrite non-NULLs with NULLs) .
void set_DgDp(int j, int l, const Derivative< Scalar > &DgDp_j_l)
Precondition: supports(OUT_ARG_DgDp,j,l)==true.
void setFailed() const
Set that the evaluation as a whole failed.
RCP< const VectorBase< Scalar > > get_x_dot() const
Precondition: supports(IN_ARG_x_dot)==true.
void set_DgDp_properties(int j, int l, const DerivativeProperties &properties)
Teuchos::ScalarTraits< Scalar >::magnitudeType ScalarMag
RCP< PreconditionerBase< Scalar > > get_W_prec() const
Precondition: supports(OUT_ARG_W_op)==true.
DerivativeSupport(EDerivativeMultiVectorOrientation mvOrientation)
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Derivative(const DerivativeMultiVector< Scalar > &dmv)
void _setModelEvalDescription(const std::string &modelEvalDescription)
bool supports(EOutArgsMembers arg) const
Determine if an input argument is supported or not.
Abstract interface for finite-dimensional dense vectors.
Simple public strict containing properties of a derivative object.
void _setSupports(EInArgsMembers arg, bool supports)
bool isFailed() const
Return if the evaluation failed or not.
RCP< Stokhos::ProductEpetraOperator > get_W_mp() const
Precondition: supports(OUT_ARG_W_mp)==true.
Evaluation< VectorBase< Scalar > > get_g(int j) const
Precondition: supports(OUT_ARG_g)==true..
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Create a more detailed description along about this object and the ModelEvaluator that created it...
void set_x_dot(const RCP< const VectorBase< Scalar > > &x_dot)
Precondition: supports(IN_ARG_x_dot)==true.
Base class for all linear operators.
Derivative(const RCP< LinearOpBase< Scalar > > &lo)
void set_DgDx_dot_properties(int j, const DerivativeProperties &properties)
void _set_DgDx_properties(int j, const DerivativeProperties &properties)
void set_g_mp(int j, const RCP< Stokhos::ProductEpetraVector > &g_mp_j)
Precondition: supports(OUT_ARG_g_mp)==true.
DerivativeProperties(EDerivativeLinearity in_linearity, ERankStatus in_rank, bool in_supportsAdjoint)
int Ng() const
Return the number of axillary response functions g(j)(...) supported (Ng >= 0).
Base subclass for ModelEvaluator that defines some basic types.
void set_t(ScalarMag t)
Precondition: supports(IN_ARG_t)==true.
void set_x_mp(const RCP< const Stokhos::ProductEpetraVector > &x_mp)
Precondition: supports(IN_ARG_x_mp)==true.
void set_DgDx_dot(int j, const Derivative< Scalar > &DgDx_dot_j)
Precondition: supports(OUT_ARG_DgDx_dot,j)==true.
int Np() const
Return the number of parameter subvectors p(l) supported (Np >= 0).
void set_p(int l, const RCP< const VectorBase< Scalar > > &p_l)
Set p(l) where 0 <= l && l < this->Np().
void setSupports(EOutArgsMembers arg, bool supports=true)
const Derivative< Scalar > & assert_not_null() const
void _set_DgDp_properties(int j, int l, const DerivativeProperties &properties)
void set_W(const RCP< LinearOpWithSolveBase< Scalar > > &W)
Precondition: supports(OUT_ARG_W)==true.
RCP< Stokhos::ProductEpetraMultiVector > getMultiVector() const
DerivativeProperties get_DgDx_properties(int j) const
Return the know properties of DgDx(j) (precondition: supports(OUT_ARG_DgDx,j)==true).
DerivativeProperties get_DgDx_dot_properties(int j) const
Return the know properties of DgDx_dot(j) (precondition: supports(OUT_ARG_DgDx_dot,j)==true).
void set_alpha(Scalar alpha)
Precondition: supports(IN_ARG_alpha)==true.
RCP< MultiVectorBase< Scalar > > getMultiVector() const
RCP< LinearOpBase< Scalar > > get_W_op() const
Precondition: supports(OUT_ARG_W_op)==true.
Evaluation< VectorBase< Scalar > > get_f() const
Precondition: supports(OUT_ARG_f)==true.
void _set_W_properties(const DerivativeProperties &properties)
void set_DfDp(int l, const Derivative< Scalar > &DfDp_l)
Precondition: supports(OUT_ARG_DfDp,l)==true.
void set_f_mp(const RCP< Stokhos::ProductEpetraVector > &f_mp)
Precondition: supports(OUT_ARG_f_mp)==true.
Determines the forms of a general derivative that are supported.
EDerivativeMultiVectorOrientation getOrientation() const
void assertSameSupport(const OutArgs< Scalar > &outArgs) const
Assert that two OutArgs objects have the same support.
const char * toString(EConj conj)
Return a string name for a EOpTransp value. `*.
void set_f(const Evaluation< VectorBase< Scalar > > &f)
Precondition: supports(OUT_ARG_f)==true.
DerivativeMultiVector< Scalar > getDerivativeMultiVector() const
void assertSameSupport(const InArgs< Scalar > &inArgs) const
Assert that two InArgs objects have the same support.
void set_beta(Scalar beta)
Precondition: supports(IN_ARG_beta)==true.
void set_DgDx(int j, const Derivative< Scalar > &DgDx_j)
Precondition: supports(OUT_ARG_DgDx,j)==true.
void setModelEvalDescription(const std::string &modelEvalDescription)
Type to embed evaluation accuracy with an RCP-managed object.
Simple aggregate class that stores a derivative object as a general linear operator or as a multi-vec...
RCP< Stokhos::ProductEpetraMultiVector > getMultiVector() const
MPDerivativeMultiVector(const RCP< Stokhos::ProductEpetraMultiVector > &mv, const EDerivativeMultiVectorOrientation orientation=DERIV_MV_BY_COL, const Teuchos::Array< int > &paramIndexes=Teuchos::Array< int >())
RCP< Stokhos::ProductEpetraVector > get_g_mp(int j) const
Precondition: supports(OUT_ARG_g_mp)==true..
void set_W_op(const RCP< LinearOpBase< Scalar > > &W_op)
Precondition: supports(OUT_ARG_W_op)==true.
void _setModelEvalDescription(const std::string &modelEvalDescription)
EDerivativeMultiVectorOrientation getMultiVectorOrientation() const
Protected subclass of OutArgs that only ModelEvaluator subclasses can access to set up the selection ...
DerivativeProperties get_W_properties() const
Return the known properties of W (precondition: supports(OUT_ARG_f)==true).
int Np() const
Return the number of parameter subvectors p(l) supported (Np >= 0).
const DerivativeMultiVector< Scalar > & assert_not_null() const
bool isSameSupport(const DerivativeSupport &derivSupport) const
void reset(const RCP< ObjType > &obj, EEvalType evalType)
Concrete aggregate class for all output arguments computable by a ModelEvaluator subclass object...