Thyra  Version of the Day
Thyra_ModelEvaluatorBase_def.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_DEF_HPP
43 #define THYRA_MODEL_EVALUATOR_BASE_DEF_HPP
44 
45 
46 #include "Thyra_ModelEvaluatorBase_decl.hpp"
47 #include "Thyra_MultiVectorBase.hpp"
48 #include "Thyra_VectorBase.hpp"
49 #include "Thyra_MultiVectorStdOps.hpp"
50 #include "Thyra_VectorStdOps.hpp"
51 
52 
53 namespace Thyra {
54 
55 
56 namespace ModelEvaluatorHelperPack {
57 
58 
59 template<class Scalar>
60 inline
61 RCP<const Thyra::VectorBase<Scalar> >
62 condCloneVec(
63  const RCP<const Thyra::VectorBase<Scalar> > &vec,
64  bool cloneObject
65  )
66 {
67  if(cloneObject)
68  return vec->clone_v();
69  return vec;
70 }
71 
72 inline
73 RCP<const Stokhos::ProductEpetraVector >
74 condCloneVec_mp(
75  const RCP<const Stokhos::ProductEpetraVector > &vec,
76  bool cloneObject
77  )
78 {
79  if(cloneObject)
80  {
81  printf("Warning: clone_v not implemented for ProductEpetraVector: %s %d\n",__FILE__,__LINE__);
82  //return vec->clone_v(); //JF clone_v not implemented for ProductEpetraVector
83  }
84  return vec;
85 }
86 
87 } // namespace ModelEvaluatorHelperPack
88 
89 
90 //
91 // ModelEvaluatorBase::InArgs
92 //
93 
94 
95 template<class Scalar>
97  :modelEvalDescription_("WARNING! THIS INARGS OBJECT IS UNINITALIZED!")
98 {
99  typedef Teuchos::ScalarTraits<Scalar> ST;
100  typedef Teuchos::ScalarTraits<typename ST::magnitudeType> SMT;
101  std::fill_n(&supports_[0],NUM_E_IN_ARGS_MEMBERS,false);
102  t_ = SMT::zero();
103  alpha_ = ST::zero();
104  beta_ = ST::zero();
105  step_size_ = ST::zero();
106  stage_number_ = ST::one();
107 }
108 
109 
110 template<class Scalar>
112 { return p_.size(); }
113 
114 template<class Scalar>
116 {
117  TEUCHOS_TEST_FOR_EXCEPTION(
118  int(arg)>=NUM_E_IN_ARGS_MEMBERS || int(arg) < 0,std::logic_error
119  ,"model = \'"<<modelEvalDescription_
120  <<"\': Error, arg="<<toString(arg)<<" is invalid!"
121  );
122  return supports_[arg];
123 }
124 
125 template<class Scalar>
127 {
128  assert_l(l);
129  return supports_p_mp_[l];
130 }
131 
132 template<class Scalar>
134  const RCP<const VectorBase<Scalar> > &x_dot
135  )
136 { assert_supports(IN_ARG_x_dot); x_dot_ = x_dot; }
137 
138 
139 template<class Scalar>
140 RCP<const VectorBase<Scalar> >
142 { assert_supports(IN_ARG_x_dot); return x_dot_; }
143 
144 
145 template<class Scalar>
147  const RCP<const VectorBase<Scalar> > &x
148  )
149 { assert_supports(IN_ARG_x); x_ = x; }
150 
151 
152 template<class Scalar>
153 RCP<const VectorBase<Scalar> >
155 { assert_supports(IN_ARG_x); return x_; }
156 
157 
158 template<class Scalar>
160  const RCP<const Stokhos::ProductEpetraVector > &x_dot_mp
161  )
162 { assert_supports(IN_ARG_x_dot_mp); x_dot_mp_ = x_dot_mp; }
163 
164 
165 template<class Scalar>
166 RCP<const Stokhos::ProductEpetraVector >
168 { assert_supports(IN_ARG_x_dot_mp); return x_dot_mp_; }
169 
170 
171 template<class Scalar>
173  const RCP<const Stokhos::ProductEpetraVector > &x_mp
174  )
175 { assert_supports(IN_ARG_x_mp); x_mp_ = x_mp; }
176 
177 
178 template<class Scalar>
179 RCP<const Stokhos::ProductEpetraVector >
181 { assert_supports(IN_ARG_x_mp); return x_mp_; }
182 
183 
184 #ifdef HAVE_THYRA_ME_POLYNOMIAL
185 
186 template<class Scalar>
188  const RCP<const Teuchos::Polynomial< VectorBase<Scalar> > > &x_dot_poly
189  )
190 { assert_supports(IN_ARG_x_dot_poly); x_dot_poly_ = x_dot_poly; }
191 
192 
193 template<class Scalar>
194 RCP<const Teuchos::Polynomial< VectorBase<Scalar> > >
196 { assert_supports(IN_ARG_x_dot_poly); return x_dot_poly_; }
197 
198 
199 template<class Scalar>
200 void ModelEvaluatorBase::InArgs<Scalar>::set_x_poly(
201  const RCP<const Teuchos::Polynomial< VectorBase<Scalar> > > &x_poly
202  )
203 { assert_supports(IN_ARG_x_poly); x_poly_ = x_poly; }
204 
205 
206 template<class Scalar>
207 RCP<const Teuchos::Polynomial< VectorBase<Scalar> > >
208 ModelEvaluatorBase::InArgs<Scalar>::get_x_poly() const
209 { assert_supports(IN_ARG_x_poly); return x_poly_; }
210 
211 
212 #endif // HAVE_THYRA_ME_POLYNOMIAL
213 
214 template<class Scalar>
216  int l, const RCP<const VectorBase<Scalar> > &p_l
217  )
218 { assert_l(l); p_[l] = p_l; }
219 
220 
221 template<class Scalar>
222 RCP<const VectorBase<Scalar> >
224 { assert_l(l); return p_[l]; }
225 
226 
227 template<class Scalar>
229  int l, const RCP<const Stokhos::ProductEpetraVector > &p_mp_l
230  )
231 { assert_supports(IN_ARG_p_mp, l); p_mp_[l] = p_mp_l; }
232 
233 template<class Scalar>
234 RCP<const Stokhos::ProductEpetraVector >
236 { assert_supports(IN_ARG_p_mp, l); return p_mp_[l]; }
237 
238 
239 template<class Scalar>
241 { assert_supports(IN_ARG_t); t_ = t; }
242 
243 
244 template<class Scalar>
247 { assert_supports(IN_ARG_t); return t_; }
248 
249 
250 template<class Scalar>
252 { assert_supports(IN_ARG_alpha); alpha_ = alpha; }
253 
254 
255 template<class Scalar>
257 { assert_supports(IN_ARG_alpha); return alpha_; }
258 
259 
260 template<class Scalar>
262 { assert_supports(IN_ARG_beta); beta_ = beta; }
263 
264 
265 template<class Scalar>
267 { assert_supports(IN_ARG_beta); return beta_; }
268 
269 template<class Scalar>
271 { assert_supports(IN_ARG_step_size); step_size_ = step_size; }
272 
273 template<class Scalar>
275 { assert_supports(IN_ARG_step_size); return step_size_; }
276 
277 template<class Scalar>
279 { assert_supports(IN_ARG_stage_number); return stage_number_; }
280 
281 
282 template<class Scalar>
284 { assert_supports(IN_ARG_stage_number); stage_number_ = stage_number; }
285 
286 
287 template<class Scalar>
289  const InArgs<Scalar>& inArgs, bool ignoreUnsupported, bool cloneObjects
290  )
291 {
292  using ModelEvaluatorHelperPack::condCloneVec;
293  using ModelEvaluatorHelperPack::condCloneVec_mp;
294  if( inArgs.supports(IN_ARG_x_dot) && nonnull(inArgs.get_x_dot()) ) {
295  if(supports(IN_ARG_x_dot) || !ignoreUnsupported)
296  set_x_dot(condCloneVec(inArgs.get_x_dot(),cloneObjects));
297  }
298  if( inArgs.supports(IN_ARG_x_dot_mp) && nonnull(inArgs.get_x_dot_mp()) ) {
299  if(supports(IN_ARG_x_dot_mp) || !ignoreUnsupported)
300  set_x_dot_mp(condCloneVec_mp(inArgs.get_x_dot_mp(),cloneObjects));
301  }
302  if( inArgs.supports(IN_ARG_x) && nonnull(inArgs.get_x()) ) {
303  if(supports(IN_ARG_x) || !ignoreUnsupported)
304  set_x(condCloneVec(inArgs.get_x(),cloneObjects));
305  }
306  if( inArgs.supports(IN_ARG_x_mp) && nonnull(inArgs.get_x_mp()) ) {
307  if(supports(IN_ARG_x_mp) || !ignoreUnsupported)
308  set_x_mp(condCloneVec_mp(inArgs.get_x_mp(),cloneObjects));
309  }
310 #ifdef HAVE_THYRA_ME_POLYNOMIAL
311  if( inArgs.supports(IN_ARG_x_dot_poly) && nonnull(inArgs.get_x_dot_poly()) ) {
312  if(supports(IN_ARG_x_dot_poly) || !ignoreUnsupported) {
313  TEUCHOS_TEST_FOR_EXCEPT(
314  cloneObjects && "Have not implemented cloning for x_dot_poly yet!" );
315  set_x_dot_poly(inArgs.get_x_dot_poly());
316  }
317  }
318  if( inArgs.supports(IN_ARG_x_poly) && nonnull(inArgs.get_x_poly()) ) {
319  if(supports(IN_ARG_x_poly) || !ignoreUnsupported) {
320  TEUCHOS_TEST_FOR_EXCEPT(
321  cloneObjects && "Have not implemented cloning for x_poly yet!" );
322  set_x_poly(inArgs.get_x_poly());
323  }
324  }
325 #endif // HAVE_THYRA_ME_POLYNOMIAL
326  const int min_Np = TEUCHOS_MIN(this->Np(),inArgs.Np());
327  for (int l = 0; l < min_Np; ++l) {
328  if (nonnull(inArgs.get_p(l)))
329  set_p(l,condCloneVec(inArgs.get_p(l),cloneObjects));
330  }
331  for (int l = 0; l < min_Np; ++l) {
332  if (inArgs.supports(IN_ARG_p_mp,l)) {
333  if (nonnull(inArgs.get_p_mp(l)))
334  set_p_mp(l,condCloneVec_mp(inArgs.get_p_mp(l),cloneObjects));
335  }
336  }
337  if (inArgs.supports(IN_ARG_t)) {
338  if(supports(IN_ARG_t) || !ignoreUnsupported)
339  set_t(inArgs.get_t());
340  }
341  if (inArgs.supports(IN_ARG_alpha)) {
342  if(supports(IN_ARG_alpha) || !ignoreUnsupported)
343  set_alpha(inArgs.get_alpha());
344  }
345  if (inArgs.supports(IN_ARG_beta)) {
346  if(supports(IN_ARG_beta) || !ignoreUnsupported)
347  set_beta(inArgs.get_beta());
348  }
349  if (inArgs.supports(IN_ARG_step_size)) {
350  if(supports(IN_ARG_step_size) || !ignoreUnsupported)
351  set_step_size(inArgs.get_step_size());
352  }
353  if (inArgs.supports(IN_ARG_stage_number)) {
354  if(supports(IN_ARG_stage_number) || !ignoreUnsupported)
355  set_stage_number(inArgs.get_stage_number());
356  }
357 }
358 
359 
360 template<class Scalar>
362  const InArgs<Scalar> &inArgs
363  ) const
364 {
365  for ( int inArg_i = 0; inArg_i < NUM_E_IN_ARGS_MEMBERS; ++inArg_i ) {
366  const EInArgsMembers inArg_arg = static_cast<EInArgsMembers>(inArg_i);
367  const std::string inArg_name = toString(inArg_arg);
368  TEUCHOS_TEST_FOR_EXCEPTION(
369  supports(inArg_arg) != inArgs.supports(inArg_arg), std::logic_error,
370  "Error, the input argument "<<inArg_name<<" with support "<<inArgs.supports(inArg_arg)<<"\n"
371  "in the InArgs object for the model:\n\n"
372  " "<<inArgs.modelEvalDescription()<<"\n\n"
373  "is not the same the argument "<<inArg_name<<" with support "<<supports(inArg_arg)<<"\n"
374  "in the InArgs object for the model:\n\n"
375  " "<<modelEvalDescription()<<"\n\n"
376  "and these two InArgs objects are not compatible!"
377  );
378  }
379  TEUCHOS_ASSERT_EQUALITY( this->Np(), inArgs.Np() );
380 }
381 
382 
383 template<class Scalar>
385 {
386  return modelEvalDescription_;
387 }
388 
389 
390 template<class Scalar>
392 {
393  typedef Teuchos::ScalarTraits<Scalar> ST;
394  std::ostringstream oss;
395  oss
396  << "Thyra::ModelEvaluatorBase::InArgs<"<<ST::name()<<">"
397  << "{"
398  << "model="<<modelEvalDescription_
399  << ",Np="<<Np()
400  << "}";
401  return oss.str();
402 }
403 
404 
405 template<class Scalar>
407  Teuchos::FancyOStream &out_arg, const Teuchos::EVerbosityLevel verbLevel
408  ) const
409 {
410  using std::endl;
411  typedef Teuchos::ScalarTraits<Scalar> ST;
412  using Teuchos::OSTab;
413  using Teuchos::describe;
414  using Teuchos::includesVerbLevel;
415  typedef RCP<const VectorBase<Scalar> > CV_ptr;
416 
417  if(verbLevel == Teuchos::VERB_NONE)
418  return;
419 
420  RCP<Teuchos::FancyOStream>
421  out = Teuchos::rcp(&out_arg,false);
422  const bool dump_x = includesVerbLevel(verbLevel,Teuchos::VERB_HIGH);
423  const Teuchos::EVerbosityLevel x_verbLevel =
424  dump_x?Teuchos::VERB_EXTREME:verbLevel;
425  const bool print_x_nrm = includesVerbLevel(verbLevel,Teuchos::VERB_LOW);
426  const bool dump_p = includesVerbLevel(verbLevel,Teuchos::VERB_MEDIUM);
427  const Teuchos::EVerbosityLevel p_verbLevel =
428  dump_p?Teuchos::VERB_EXTREME:verbLevel;
429  const bool print_p_nrm = includesVerbLevel(verbLevel,Teuchos::VERB_LOW);
430  OSTab tab(out);
431 
432  *out <<"Thyra::ModelEvaluatorBase::InArgs<"<<ST::name()<<">:\n";
433  tab.incrTab();
434 
435  *out <<"model = " << modelEvalDescription_ << "\n";
436  *out <<"Np = " << Np() << "\n";
437 
438  CV_ptr x_dot;
439  if ( this->supports(IN_ARG_x_dot) && !is_null(x_dot=get_x_dot()) ) {
440  *out << "x_dot = " << Teuchos::describe(*x_dot,x_verbLevel);
441  if (print_x_nrm)
442  *out << "||x_dot|| = " << norm(*x_dot) << endl;
443  }
444 
445  CV_ptr x;
446  if ( this->supports(IN_ARG_x) && !is_null(x=get_x()) ) {
447  *out << "x = " << Teuchos::describe(*x,x_verbLevel);
448  if (print_x_nrm)
449  *out << "||x|| = " << norm(*x) << endl;
450  }
451 
452  if (print_x_nrm) {
453  for( int l = 0; l < Np(); ++l ) {
454  CV_ptr p_l;
455  if ( !is_null(p_l = this->get_p(l)) ) {
456  *out << "p("<<l<<") = " << Teuchos::describe(*p_l,p_verbLevel);
457  if (print_p_nrm)
458  *out << "||p("<<l<<")|| = " << norm(*p_l) << endl;
459  }
460  }
461  }
462 
463  if (includesVerbLevel(verbLevel,Teuchos::VERB_MEDIUM)) {
464  if (this->supports(IN_ARG_t)) {
465  *out << "t = " << t_ << endl;
466  }
467  if (this->supports(IN_ARG_alpha)) {
468  *out << "alpha = " << alpha_ << endl;
469  }
470  if (this->supports(IN_ARG_beta)) {
471  *out << "beta = " << beta_ << endl;
472  }
473  if (this->supports(IN_ARG_step_size)) {
474  *out << "step_size = " << step_size_ << endl;
475  }
476  if (this->supports(IN_ARG_stage_number)) {
477  *out << "stage_number = " << stage_number_ << endl;
478  }
479  }
480 
481 }
482 
483 
484 template<class Scalar>
486  const std::string &modelEvalDescription_in
487  )
488 {
489  modelEvalDescription_ = modelEvalDescription_in;
490 }
491 
492 
493 template<class Scalar>
495 {
496  p_.resize(Np_in);
497  p_mp_.resize(Np_in);
498  supports_p_mp_.resize(Np_in);
499 }
500 
501 
502 template<class Scalar>
504  EInArgsMembers arg, bool supports_in
505  )
506 {
507  TEUCHOS_TEST_FOR_EXCEPTION(
508  int(arg)>=NUM_E_IN_ARGS_MEMBERS || int(arg) < 0,std::logic_error
509  ,"model = \'"<<modelEvalDescription_
510  <<"\': Error, arg="<<toString(arg)<<" is invalid!");
511  supports_[arg] = supports_in;
512 }
513 
514 template<class Scalar>
516  EInArgs_p_mp arg, int l, bool supports_in
517  )
518 {
519  assert_l(l);
520  supports_p_mp_[l] = supports_in;
521 }
522 
523 
524 template<class Scalar>
526  const InArgs<Scalar>& inArgs, const int Np_in
527  )
528 {
529  std::copy(
530  &inArgs.supports_[0],
531  &inArgs.supports_[0] + NUM_E_IN_ARGS_MEMBERS, &supports_[0] );
532  this->_set_Np( Np_in >= 0 ? Np_in : inArgs.Np() );
533 }
534 
535 
536 template<class Scalar>
538  EInArgsMembers arg
539  )
540 {
541  switch(arg) {
542  case IN_ARG_x: {
543  this->_setSupports(IN_ARG_x_dot,false);
544  this->_setSupports(IN_ARG_x_dot_poly,false);
545  this->_setSupports(IN_ARG_alpha,false);
546  this->_setSupports(IN_ARG_beta,false);
547  this->_setSupports(IN_ARG_step_size,false);
548  this->_setSupports(IN_ARG_stage_number,false);
549  break;
550  }
551  default:
552  TEUCHOS_TEST_FOR_EXCEPTION(
553  true ,std::logic_error,
554  "Error, can not handle args other than IN_ARG_x yet!"
555  );
556  break;
557  }
558  this->_setSupports(arg,false);
559 }
560 
561 
562 template<class Scalar>
564  EInArgsMembers arg
565  ) const
566 {
567  TEUCHOS_TEST_FOR_EXCEPTION(
568  !supports_[arg], std::logic_error
569  ,"Thyra::ModelEvaluatorBase::InArgs<"
570  << Teuchos::ScalarTraits<Scalar>::name() <<">::assert_supports(arg): "
571  "model = \'"<<modelEvalDescription_<<"\': Error, "
572  "The argument arg = " << toString(arg) << " is not supported!"
573  );
574 }
575 
576 template<class Scalar>
578  EInArgs_p_mp arg, int l
579  ) const
580 {
581  assert_l(l);
582  TEUCHOS_TEST_FOR_EXCEPTION(
583  !supports_p_mp_[l], std::logic_error
584  ,"Thyra::ModelEvaluatorBase::InArgs<"
585  << Teuchos::ScalarTraits<Scalar>::name() <<">::assert_supports(IN_ARG_p_mp,1): "
586  "model = \'"<<modelEvalDescription_<<"\': Error, "
587  "The argument p_mp(l) with index l = " << l << " is not supported!"
588  );
589 }
590 
591 
592 template<class Scalar>
593 void ModelEvaluatorBase::InArgs<Scalar>::assert_l(int l) const
594 {
595  TEUCHOS_TEST_FOR_EXCEPTION(
596  !( 0 <= l && l < Np() ), std::logic_error
597  ,"Thyra::ModelEvaluatorBase::InArgs<Scalar>::assert_l(l):\n\n"
598  " model = \'"<<modelEvalDescription_<<"\':\n\n"
599  "Error, The parameter l = " << l << " is not in the range [0,"<<Np()<<")!"
600  );
601 }
602 
603 
604 //
605 // ModelEvaluatorBase::DerivativeMultiVector
606 //
607 
608 
609 template<class Scalar>
611 {
612  using std::endl;
613  std::ostringstream oss;
614  oss << "DerivativeMultiVector{";
615  if (is_null(getMultiVector())) {
616  oss << "NULL";
617  }
618  else {
619  oss
620  << "multiVec=" << getMultiVector()->description()
621  << ",orientation=" << toString(getOrientation());
622  }
623  oss << "}";
624  return oss.str();
625 }
626 
627 
628 template<class Scalar>
630  Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel
631  ) const
632 {
633  using std::endl;
634  using Teuchos::describe;
635  Teuchos::OSTab tab1(out);
636  out << "DerivativeMultiVector\n";
637  Teuchos::OSTab tab2(out);
638  out
639  << "multiVec = "
640  << describe(*getMultiVector(),verbLevel)
641  << "orientation = "
642  << toString(getOrientation()) << endl;
643 }
644 
645 
646 // 2007/06/12: rabartl: The above description() and describe(...) functions
647 // have to be defined here and not in the class DerivativeMultiVector since it
648 // relies on the non-member function
649 // toString(ModelEvaluatorBase::EDerivativeMultiVectorOrientation) which is
650 // defined after the class definition for ModelEvaluatorBase. This was caught
651 // by the intel compiler. I am not sure why this worked with gcc.
652 
653 
654 //
655 // ModelEvaluatorBase::Derivative
656 //
657 
658 
659 template<class Scalar>
660 std::string
662 {
663  using std::endl;
664  std::ostringstream oss;
665  oss << "Derivative{";
666  if (isEmpty()) {
667  oss << "NULL";
668  }
669  else if (!is_null(getLinearOp())) {
670  oss << "linearOp=" << getLinearOp()->description();
671  }
672  else {
673  oss << "derivMultiVec=" << getDerivativeMultiVector().description();
674  }
675  oss << "}";
676  return oss.str();
677 }
678 
679 
680 template<class Scalar>
682  Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel
683  ) const
684 {
685  using std::endl;
686  using Teuchos::describe;
687  Teuchos::OSTab tab1(out);
688  out << "Derivative:";
689  if (isEmpty()) {
690  out << " NULL\n";
691  }
692  else if (!is_null(getLinearOp())) {
693  out
694  << endl
695  << "linearOp = " << describe(*getLinearOp(),verbLevel);
696  }
697  else {
698  out
699  << endl
700  << "derivMultiVec = ";
701  getDerivativeMultiVector().describe(out,verbLevel);
702  }
703 }
704 
705 
706 //
707 // ModelEvaluatorBase::OutArgs
708 //
709 
710 
711 template<class Scalar>
713  :modelEvalDescription_("WARNING! THIS OUTARGS OBJECT IS UNINITALIZED!"),
714  isFailed_(false)
715 { std::fill_n(&supports_[0],NUM_E_OUT_ARGS_MEMBERS,false); }
716 
717 
718 template<class Scalar>
720 { return DfDp_.size(); }
721 
722 
723 template<class Scalar>
725 { return g_.size(); }
726 
727 
728 template<class Scalar>
730  EOutArgsMembers arg
731  ) const
732 {
733  TEUCHOS_TEST_FOR_EXCEPTION(
734  int(arg)>=NUM_E_OUT_ARGS_MEMBERS || int(arg) < 0,std::logic_error
735  ,"model = \'"<<modelEvalDescription_
736  <<"\': Error, arg="<<toString(arg)<<" is invalid!"
737  );
738  return supports_[arg];
739 }
740 
741 
742 template<class Scalar>
745  EOutArgsDfDp arg, int l
746  ) const
747 {
748  assert_l(l);
749  return supports_DfDp_[l];
750 }
751 
752 
753 template<class Scalar>
756  EOutArgsDgDx_dot arg, int j
757  ) const
758 {
759  assert_j(j);
760  return supports_DgDx_dot_[j];
761 }
762 
763 
764 template<class Scalar>
767  EOutArgsDgDx arg, int j
768  ) const
769 {
770  assert_j(j);
771  return supports_DgDx_[j];
772 }
773 
774 
775 template<class Scalar>
778  EOutArgsDgDp arg, int j, int l
779  ) const
780 {
781  assert_j(j);
782  assert_l(l);
783  return supports_DgDp_[ j*Np() + l ];
784 }
785 
786 
787 template<class Scalar>
788 bool
790  EOutArgs_g_mp arg, int j
791  ) const
792 {
793  assert_j(j);
794  return supports_g_mp_[j];
795 }
796 
797 template<class Scalar>
800  EOutArgsDfDp_mp arg, int l
801  ) const
802 {
803  assert_l(l);
804  return supports_DfDp_mp_[l];
805 }
806 
807 
808 template<class Scalar>
809 const ModelEvaluatorBase::DerivativeSupport&
810 ModelEvaluatorBase::OutArgs<Scalar>::supports(
811  EOutArgsDgDx_dot_mp arg, int j
812  ) const
813 {
814  assert_j(j);
815  return supports_DgDx_dot_mp_[j];
816 }
817 
818 
819 template<class Scalar>
820 const ModelEvaluatorBase::DerivativeSupport&
821 ModelEvaluatorBase::OutArgs<Scalar>::supports(
822  EOutArgsDgDx_mp arg, int j
823  ) const
824 {
825  assert_j(j);
826  return supports_DgDx_mp_[j];
827 }
828 
829 
830 template<class Scalar>
831 const ModelEvaluatorBase::DerivativeSupport&
832 ModelEvaluatorBase::OutArgs<Scalar>::supports(
833  EOutArgsDgDp_mp arg, int j, int l
834  ) const
835 {
836  assert_j(j);
837  assert_l(l);
838  return supports_DgDp_mp_[ j*Np() + l ];
839 }
840 
841 
842 
843 template<class Scalar>
845  const Evaluation<VectorBase<Scalar> > &f
846  )
847 {
848  assert_supports(OUT_ARG_f);
849  f_ = f;
850 }
851 
852 
853 template<class Scalar>
856 {
857  assert_supports(OUT_ARG_f);
858  return f_;
859 }
860 
861 
862 template<class Scalar>
864  int j, const Evaluation<VectorBase<Scalar> > &g_j
865  )
866 {
867  assert_j(j);
868  g_[j] = g_j;
869 }
870 
871 
872 template<class Scalar>
875 {
876  assert_j(j);
877  return g_[j];
878 }
879 
880 
881 template<class Scalar>
883  const RCP<Stokhos::ProductEpetraVector > &f_mp
884  )
885 {
886  assert_supports(OUT_ARG_f_mp);
887  f_mp_ = f_mp;
888 }
889 
890 
891 template<class Scalar>
892 RCP<Stokhos::ProductEpetraVector >
894 {
895  assert_supports(OUT_ARG_f_mp);
896  return f_mp_;
897 }
898 
899 
900 template<class Scalar>
902  int j, const RCP<Stokhos::ProductEpetraVector> &g_mp_j
903  )
904 {
905  assert_supports(OUT_ARG_g_mp,j);
906  g_mp_[j] = g_mp_j;
907 }
908 
909 
910 template<class Scalar>
911 RCP<Stokhos::ProductEpetraVector>
913 {
914  assert_supports(OUT_ARG_g_mp,j);
915  return g_mp_[j];
916 }
917 
918 
919 template<class Scalar>
921  const RCP<LinearOpWithSolveBase<Scalar> > &W
922  )
923 {
924  assert_supports(OUT_ARG_W);
925  W_ = W;
926 }
927 
928 
929 template<class Scalar>
930 RCP<LinearOpWithSolveBase<Scalar> >
932 {
933  assert_supports(OUT_ARG_W);
934  return W_;
935 }
936 
937 
938 template<class Scalar>
940  const RCP<Stokhos::ProductEpetraOperator> &W_mp
941  )
942 {
943  assert_supports(OUT_ARG_W_mp);
944  W_mp_ = W_mp;
945 }
946 
947 
948 template<class Scalar>
949 RCP<Stokhos::ProductEpetraOperator>
951 {
952  assert_supports(OUT_ARG_W_mp);
953  return W_mp_;
954 }
955 
956 
957 template<class Scalar>
959  const RCP<LinearOpBase<Scalar> > &W_op
960  )
961 {
962  assert_supports(OUT_ARG_W_op);
963  W_op_ = W_op;
964 }
965 
966 
967 template<class Scalar>
968 RCP<LinearOpBase<Scalar> >
970 {
971  assert_supports(OUT_ARG_W_op);
972  return W_op_;
973 }
974 
975 
976 template<class Scalar>
978  const RCP<PreconditionerBase<Scalar> > &W_prec
979  )
980 {
981  assert_supports(OUT_ARG_W_prec);
982  W_prec_ = W_prec;
983 }
984 
985 
986 template<class Scalar>
987 RCP<PreconditionerBase<Scalar> >
989 {
990  assert_supports(OUT_ARG_W_prec);
991  return W_prec_;
992 }
993 
994 
995 template<class Scalar>
998 {
999  assert_supports(OUT_ARG_f);
1000  return W_properties_;
1001 }
1002 
1003 
1004 template<class Scalar>
1006  int l, const Derivative<Scalar> &DfDp_l
1007  )
1008 {
1009  assert_supports(OUT_ARG_DfDp,l,DfDp_l);
1010  DfDp_[l] = DfDp_l;
1011 }
1012 
1013 
1014 template<class Scalar>
1017 {
1018  assert_supports(OUT_ARG_DfDp,l);
1019  return DfDp_[l];
1020 }
1021 
1022 
1023 template<class Scalar>
1026 {
1027  assert_supports(OUT_ARG_DfDp,l);
1028  return DfDp_properties_[l];
1029 }
1030 
1031 
1032 template<class Scalar>
1034  int l, const MPDerivative &DfDp_mp_l
1035  )
1036 {
1037  assert_supports(OUT_ARG_DfDp_mp,l,DfDp_mp_l);
1038  DfDp_mp_[l] = DfDp_mp_l;
1039 }
1040 
1041 
1042 template<class Scalar>
1045 {
1046  assert_supports(OUT_ARG_DfDp_mp,l);
1047  return DfDp_mp_[l];
1048 }
1049 
1050 
1051 template<class Scalar>
1052 ModelEvaluatorBase::DerivativeProperties
1053 ModelEvaluatorBase::OutArgs<Scalar>::get_DfDp_mp_properties(int l) const
1054 {
1055  assert_supports(OUT_ARG_DfDp_mp,l);
1056  return DfDp_mp_properties_[l];
1057 }
1058 
1059 
1060 template<class Scalar>
1062  int j, const Derivative<Scalar> &DgDx_dot_j
1063  )
1064 {
1065  assert_supports(OUT_ARG_DgDx_dot,j,DgDx_dot_j);
1066  DgDx_dot_[j] = DgDx_dot_j;
1067 }
1068 
1069 
1070 template<class Scalar>
1073 {
1074  assert_supports(OUT_ARG_DgDx_dot,j);
1075  return DgDx_dot_[j];
1076 }
1077 
1078 
1079 template<class Scalar>
1082 {
1083  assert_supports(OUT_ARG_DgDx_dot,j);
1084  return DgDx_dot_properties_[j];
1085 }
1086 
1087 
1088 template<class Scalar>
1090  int j, const MPDerivative &DgDx_dot_mp_j
1091  )
1092 {
1093  assert_supports(OUT_ARG_DgDx_dot_mp,j,DgDx_dot_mp_j);
1094  DgDx_dot_mp_[j] = DgDx_dot_mp_j;
1095 }
1096 
1097 
1098 template<class Scalar>
1101 {
1102  assert_supports(OUT_ARG_DgDx_dot_mp,j);
1103  return DgDx_dot_mp_[j];
1104 }
1105 
1106 
1107 template<class Scalar>
1108 ModelEvaluatorBase::DerivativeProperties
1109 ModelEvaluatorBase::OutArgs<Scalar>::get_DgDx_dot_mp_properties(int j) const
1110 {
1111  assert_supports(OUT_ARG_DgDx_dot_mp,j);
1112  return DgDx_dot_mp_properties_[j];
1113 }
1114 
1115 
1116 template<class Scalar>
1118  int j, const Derivative<Scalar> &DgDx_j
1119  )
1120 {
1121  assert_supports(OUT_ARG_DgDx,j,DgDx_j);
1122  DgDx_[j] = DgDx_j;
1123 }
1124 
1125 
1126 template<class Scalar>
1129 {
1130  assert_supports(OUT_ARG_DgDx,j);
1131  return DgDx_[j];
1132 }
1133 
1134 
1135 template<class Scalar>
1138 {
1139  assert_supports(OUT_ARG_DgDx,j);
1140  return DgDx_properties_[j];
1141 }
1142 
1143 
1144 template<class Scalar>
1146  int j, const MPDerivative &DgDx_mp_j
1147  )
1148 {
1149  assert_supports(OUT_ARG_DgDx_mp,j,DgDx_mp_j);
1150  DgDx_mp_[j] = DgDx_mp_j;
1151 }
1152 
1153 
1154 template<class Scalar>
1157 {
1158  assert_supports(OUT_ARG_DgDx_mp,j);
1159  return DgDx_mp_[j];
1160 }
1161 
1162 
1163 template<class Scalar>
1164 ModelEvaluatorBase::DerivativeProperties
1165 ModelEvaluatorBase::OutArgs<Scalar>::get_DgDx_mp_properties(int j) const
1166 {
1167  assert_supports(OUT_ARG_DgDx_mp,j);
1168  return DgDx_mp_properties_[j];
1169 }
1170 
1171 
1172 template<class Scalar>
1174  int j, int l, const Derivative<Scalar> &DgDp_j_l
1175  )
1176 {
1177  assert_supports(OUT_ARG_DgDp,j,l,DgDp_j_l);
1178  DgDp_[ j*Np() + l ] = DgDp_j_l;
1179 }
1180 
1181 
1182 template<class Scalar>
1185 {
1186  assert_supports(OUT_ARG_DgDp,j,l);
1187  return DgDp_[ j*Np() + l ];
1188 }
1189 
1190 
1191 template<class Scalar>
1194 {
1195  assert_supports(OUT_ARG_DgDp,j,l);
1196  return DgDp_properties_[ j*Np() + l ];
1197 }
1198 
1199 
1200 template<class Scalar>
1202  int j, int l, const MPDerivative &DgDp_mp_j_l
1203  )
1204 {
1205  assert_supports(OUT_ARG_DgDp_mp,j,l,DgDp_mp_j_l);
1206  DgDp_mp_[ j*Np() + l ] = DgDp_mp_j_l;
1207 }
1208 
1209 
1210 template<class Scalar>
1213 {
1214  assert_supports(OUT_ARG_DgDp_mp,j,l);
1215  return DgDp_mp_[ j*Np() + l ];
1216 }
1217 
1218 
1219 template<class Scalar>
1220 ModelEvaluatorBase::DerivativeProperties
1221 ModelEvaluatorBase::OutArgs<Scalar>::get_DgDp_mp_properties(int j, int l) const
1222 {
1223  assert_supports(OUT_ARG_DgDp_mp,j,l);
1224  return DgDp_mp_properties_[ j*Np() + l ];
1225 }
1226 
1227 
1228 #ifdef HAVE_THYRA_ME_POLYNOMIAL
1229 
1230 
1231 template<class Scalar>
1232 void ModelEvaluatorBase::OutArgs<Scalar>::set_f_poly(
1233  const RCP<Teuchos::Polynomial< VectorBase<Scalar> > > &f_poly
1234  )
1235 {
1236  f_poly_ = f_poly;
1237 }
1238 
1239 
1240 template<class Scalar>
1241 RCP<Teuchos::Polynomial< VectorBase<Scalar> > >
1242 ModelEvaluatorBase::OutArgs<Scalar>::get_f_poly() const
1243 {
1244  return f_poly_;
1245 }
1246 
1247 
1248 #endif // HAVE_THYRA_ME_POLYNOMIAL
1249 
1250 
1251 template<class Scalar>
1253  const OutArgs<Scalar>& inputOutArgs, bool ignoreUnsupported
1254  )
1255 {
1256  typedef ModelEvaluatorBase MEB;
1257  const int min_Np = TEUCHOS_MIN(this->Np(),inputOutArgs.Np());
1258  const int min_Ng = TEUCHOS_MIN(this->Ng(),inputOutArgs.Ng());
1259  // f
1260  if ( inputOutArgs.supports(OUT_ARG_f) && nonnull(inputOutArgs.get_f()) ) {
1261  if ( supports(OUT_ARG_f) || !ignoreUnsupported )
1262  set_f(inputOutArgs.get_f());
1263  }
1264  if ( inputOutArgs.supports(OUT_ARG_f_mp) && nonnull(inputOutArgs.get_f_mp()) ) {
1265  if ( supports(OUT_ARG_f_mp) || !ignoreUnsupported )
1266  set_f_mp(inputOutArgs.get_f_mp());
1267  }
1268 #ifdef HAVE_THYRA_ME_POLYNOMIAL
1269  // f_poly
1270  if ( inputOutArgs.supports(OUT_ARG_f_poly) && nonnull(inputOutArgs.get_f_poly()) ) {
1271  if ( supports(OUT_ARG_f_poly) || !ignoreUnsupported )
1272  set_f_poly(inputOutArgs.get_f_poly());
1273  }
1274 #endif // HAVE_THYRA_ME_POLYNOMIAL
1275  // g(j)
1276  for ( int j = 0; j < min_Ng; ++j ) {
1277  if ( nonnull(inputOutArgs.get_g(j)) )
1278  set_g(j,inputOutArgs.get_g(j));
1279  }
1280  for ( int j = 0; j < min_Ng; ++j ) {
1281  if ( inputOutArgs.supports(OUT_ARG_g_mp,j) && nonnull(inputOutArgs.get_g_mp(j)) ) {
1282  if ( supports(OUT_ARG_g_mp,j) || !ignoreUnsupported )
1283  set_g_mp(j,inputOutArgs.get_g_mp(j));
1284  }
1285  }
1286  // W
1287  if( inputOutArgs.supports(OUT_ARG_W) && nonnull(inputOutArgs.get_W()) ) {
1288  if ( supports(OUT_ARG_W) || !ignoreUnsupported )
1289  set_W(inputOutArgs.get_W());
1290  }
1291  if( inputOutArgs.supports(OUT_ARG_W_mp) && nonnull(inputOutArgs.get_W_mp()) ) {
1292  if ( supports(OUT_ARG_W_mp) || !ignoreUnsupported )
1293  set_W_mp(inputOutArgs.get_W_mp());
1294  }
1295  // W_op
1296  if( inputOutArgs.supports(OUT_ARG_W_op) && nonnull(inputOutArgs.get_W_op()) ) {
1297  if ( supports(OUT_ARG_W_op) || !ignoreUnsupported )
1298  set_W_op(inputOutArgs.get_W_op());
1299  }
1300  // W_prec
1301  if( inputOutArgs.supports(OUT_ARG_W_prec) && nonnull(inputOutArgs.get_W_prec()) ) {
1302  if ( supports(OUT_ARG_W_prec) || !ignoreUnsupported )
1303  set_W_prec(inputOutArgs.get_W_prec());
1304  }
1305  // DfDp(l)
1306  for ( int l = 0; l < min_Np; ++l ) {
1307  MEB::Derivative<Scalar> DfDp_l;
1308  if ( !inputOutArgs.supports(OUT_ARG_DfDp,l).none()
1309  && !(DfDp_l=inputOutArgs.get_DfDp(l)).isEmpty() )
1310  {
1311  if ( DfDp_l.isSupportedBy(supports(OUT_ARG_DfDp,l)) || !ignoreUnsupported )
1312  set_DfDp(l,DfDp_l);
1313  }
1314  }
1315  for ( int l = 0; l < min_Np; ++l ) {
1316  MEB::MPDerivative DfDp_mp_l;
1317  if ( !inputOutArgs.supports(OUT_ARG_DfDp_mp,l).none()
1318  && !(DfDp_mp_l=inputOutArgs.get_DfDp_mp(l)).isEmpty() )
1319  {
1320  if ( DfDp_mp_l.isSupportedBy(supports(OUT_ARG_DfDp_mp,l)) || !ignoreUnsupported )
1321  set_DfDp_mp(l,DfDp_mp_l);
1322  }
1323  }
1324  // DgDx_dot(j) and DgDx(j)
1325  for ( int j = 0; j < min_Ng; ++j ) {
1326  // DgDx_dot(j)
1327  MEB::Derivative<Scalar> DgDx_dot_j;
1328  if ( !inputOutArgs.supports(OUT_ARG_DgDx_dot,j).none()
1329  && !(DgDx_dot_j=inputOutArgs.get_DgDx_dot(j)).isEmpty() )
1330  {
1331  if( DgDx_dot_j.isSupportedBy(supports(OUT_ARG_DgDx_dot,j)) || !ignoreUnsupported )
1332  set_DgDx_dot(j,DgDx_dot_j);
1333  }
1334  // DgDx(j)
1335  MEB::Derivative<Scalar> DgDx_j;
1336  if ( !inputOutArgs.supports(OUT_ARG_DgDx,j).none()
1337  && !(DgDx_j=inputOutArgs.get_DgDx(j)).isEmpty() ) {
1338  if ( DgDx_j.isSupportedBy(supports(OUT_ARG_DgDx,j)) || !ignoreUnsupported )
1339  set_DgDx(j,DgDx_j);
1340  }
1341  }
1342  for ( int j = 0; j < min_Ng; ++j ) {
1343  // DgDx_dot(j)
1344  MEB::MPDerivative DgDx_dot_mp_j;
1345  if ( !inputOutArgs.supports(OUT_ARG_DgDx_dot_mp,j).none()
1346  && !(DgDx_dot_mp_j=inputOutArgs.get_DgDx_dot_mp(j)).isEmpty() )
1347  {
1348  if( DgDx_dot_mp_j.isSupportedBy(supports(OUT_ARG_DgDx_dot_mp,j)) || !ignoreUnsupported )
1349  set_DgDx_dot_mp(j,DgDx_dot_mp_j);
1350  }
1351  // DgDx(j)
1352  MEB::MPDerivative DgDx_mp_j;
1353  if ( !inputOutArgs.supports(OUT_ARG_DgDx_mp,j).none()
1354  && !(DgDx_mp_j=inputOutArgs.get_DgDx_mp(j)).isEmpty() ) {
1355  if ( DgDx_mp_j.isSupportedBy(supports(OUT_ARG_DgDx_mp,j)) || !ignoreUnsupported )
1356  set_DgDx_mp(j,DgDx_mp_j);
1357  }
1358  }
1359  // DgDp(j,l)
1360  for ( int l = 0; l < min_Np; ++l ) {
1361  for ( int j = 0; j < min_Ng; ++j ) {
1362  MEB::Derivative<Scalar> DgDp_j_l;
1363  if ( !inputOutArgs.supports(OUT_ARG_DgDp,j,l).none()
1364  && !(DgDp_j_l=inputOutArgs.get_DgDp(j,l)).isEmpty() )
1365  {
1366  if ( DgDp_j_l.isSupportedBy(supports(OUT_ARG_DgDp,j,l)) || !ignoreUnsupported )
1367  set_DgDp(j,l,DgDp_j_l);
1368  }
1369  }
1370  }
1371  for ( int l = 0; l < min_Np; ++l ) {
1372  for ( int j = 0; j < min_Ng; ++j ) {
1373  MEB::MPDerivative DgDp_mp_j_l;
1374  if ( !inputOutArgs.supports(OUT_ARG_DgDp_mp,j,l).none()
1375  && !(DgDp_mp_j_l=inputOutArgs.get_DgDp_mp(j,l)).isEmpty() )
1376  {
1377  if ( DgDp_mp_j_l.isSupportedBy(supports(OUT_ARG_DgDp_mp,j,l)) || !ignoreUnsupported )
1378  set_DgDp_mp(j,l,DgDp_mp_j_l);
1379  }
1380  }
1381  }
1382  // ToDo: Add more args as needed!
1383 }
1384 
1385 
1386 template<class Scalar>
1388 {
1389  typedef Teuchos::ScalarTraits<Scalar> ST;
1390  isFailed_ = true;
1391  if( this->supports(OUT_ARG_f) && nonnull(this->get_f()) ) {
1392  assign(this->get_f().ptr(),ST::nan());
1393  }
1394  for( int j = 0; j < this->Ng(); ++j ) {
1395  if (nonnull(this->get_g(j)))
1396  assign(this->get_g(j).ptr(),ST::nan());
1397  }
1398  // ToDo: Set other objects to NaN as well!
1399 }
1400 
1401 
1402 template<class Scalar>
1404 {
1405  return isFailed_;
1406 }
1407 
1408 
1409 template<class Scalar>
1411 {
1412  if (!is_null(f_))
1413  return false;
1414  if (!is_null(W_))
1415  return false;
1416  if (!is_null(W_op_))
1417  return false;
1418  for ( int l = 0; l < Np(); ++l ) {
1419  if (!DfDp_[l].isEmpty())
1420  return false;
1421  }
1422 #ifdef HAVE_THYRA_ME_POLYNOMIAL
1423  if (!is_null(f_poly_))
1424  return false;
1425 #endif // HAVE_THYRA_ME_POLYNOMIAL
1426  for ( int j = 0; j < Ng(); ++j ) {
1427  if (!is_null(g_[j]))
1428  return false;
1429  if (!DgDx_dot_[j].isEmpty())
1430  return false;
1431  if (!DgDx_[j].isEmpty())
1432  return false;
1433  for ( int l = 0; l < Np(); ++l ) {
1434  if (!DgDp_[j*Np()+l].isEmpty())
1435  return false;
1436  }
1437  }
1438  return true;
1439 }
1440 
1441 
1442 template<class Scalar>
1444  const OutArgs<Scalar> &outArgs
1445  ) const
1446 {
1447 
1448  for ( int outArg_i = 0; outArg_i < NUM_E_OUT_ARGS_MEMBERS; ++outArg_i ) {
1449  const EOutArgsMembers outArg_arg = static_cast<EOutArgsMembers>(outArg_i);
1450  const std::string outArg_name = toString(outArg_arg);
1451  TEUCHOS_TEST_FOR_EXCEPTION(
1452  supports(outArg_arg) != outArgs.supports(outArg_arg), std::logic_error,
1453  "Error, the output argument "<<outArg_name<<" with support "<<outArgs.supports(outArg_arg)<<"\n"
1454  "in the OutArgs object for the model:\n\n"
1455  " "<<outArgs.modelEvalDescription()<<"\n\n"
1456  "is not the same the argument "<<outArg_name<<" with support "<<supports(outArg_arg)<<"\n"
1457  "in the OutArgs object for the model:\n\n"
1458  " "<<modelEvalDescription()<<"\n\n"
1459  "and these two OutArgs objects are not compatible!"
1460  );
1461  }
1462 
1463  const int l_Np = this->Np();
1464  const int l_Ng = this->Ng();
1465  TEUCHOS_ASSERT_EQUALITY( l_Np, outArgs.Np() );
1466  TEUCHOS_ASSERT_EQUALITY( l_Ng, outArgs.Ng() );
1467 
1468  if (supports(OUT_ARG_f)) {
1469  for ( int l = 0; l < l_Np; ++l ) {
1470  TEUCHOS_TEST_FOR_EXCEPTION(
1471  !supports(OUT_ARG_DfDp,l).isSameSupport(outArgs.supports(OUT_ARG_DfDp,l)),
1472  std::logic_error,
1473  "Error, the support for DfDp("<<l<<") is not the same for the models\n\n"
1474  " "<<outArgs.modelEvalDescription()<<"\n\n"
1475  "and:\n\n"
1476  " "<<modelEvalDescription()<<"\n\n"
1477  "and these two OutArgs objects are not compatible!"
1478  );
1479  }
1480  }
1481 
1482  for ( int j = 0; j < l_Ng; ++j ) {
1483  TEUCHOS_TEST_FOR_EXCEPTION(
1484  !supports(OUT_ARG_DgDx_dot,j).isSameSupport(outArgs.supports(OUT_ARG_DgDx_dot,j)),
1485  std::logic_error,
1486  "Error, the support for DgDx_dot("<<j<<") is not the same for the models\n\n"
1487  " "<<outArgs.modelEvalDescription()<<"\n\n"
1488  "and:\n\n"
1489  " "<<modelEvalDescription()<<"\n\n"
1490  "and these two OutArgs objects are not compatible!"
1491  );
1492  TEUCHOS_TEST_FOR_EXCEPTION(
1493  !supports(OUT_ARG_DgDx,j).isSameSupport(outArgs.supports(OUT_ARG_DgDx,j)),
1494  std::logic_error,
1495  "Error, the support for DgDx("<<j<<") is not the same for the models\n\n"
1496  " "<<outArgs.modelEvalDescription()<<"\n\n"
1497  "and:\n\n"
1498  " "<<modelEvalDescription()<<"\n\n"
1499  "and these two OutArgs objects are not compatible!"
1500  );
1501  for ( int l = 0; l < l_Np; ++l ) {
1502  TEUCHOS_TEST_FOR_EXCEPTION(
1503  !supports(OUT_ARG_DgDp,j,l).isSameSupport(outArgs.supports(OUT_ARG_DgDp,j,l)),
1504  std::logic_error,
1505  "Error, the support for DgDp("<<j<<","<<l<<") is not the same for the models\n\n"
1506  " "<<outArgs.modelEvalDescription()<<"\n\n"
1507  "and:\n\n"
1508  " "<<modelEvalDescription()<<"\n\n"
1509  "and these two OutArgs objects are not compatible!"
1510  );
1511  }
1512  }
1513 }
1514 
1515 
1516 template<class Scalar>
1518 {
1519  return modelEvalDescription_;
1520 }
1521 
1522 
1523 template<class Scalar>
1525 {
1526  typedef Teuchos::ScalarTraits<Scalar> ST;
1527  std::ostringstream oss;
1528  oss
1529  << "Thyra::ModelEvaluatorBase::OutArgs<"<<ST::name()<<">"
1530  << "{"
1531  << "model="<<modelEvalDescription_
1532  << ",Np="<<Np()
1533  << ",Ng="<<Ng()
1534  << "}";
1535  return oss.str();
1536 }
1537 
1538 
1539 template<class Scalar>
1541  Teuchos::FancyOStream &out_arg, const Teuchos::EVerbosityLevel verbLevel
1542  ) const
1543 {
1544 
1545  using Teuchos::OSTab;
1546  using Teuchos::describe;
1547  typedef Teuchos::ScalarTraits<Scalar> ST;
1548  typedef RCP<const VectorBase<Scalar> > CV_ptr;
1549  typedef RCP<const LinearOpBase<Scalar> > CLO_ptr;
1550  typedef RCP<const LinearOpWithSolveBase<Scalar> > CLOWS_ptr;
1551  typedef ModelEvaluatorBase MEB;
1552  typedef MEB::Derivative<Scalar> Deriv;
1553 
1554  if( verbLevel == Teuchos::VERB_NONE && verbLevel == Teuchos::VERB_DEFAULT )
1555  return;
1556 
1557  RCP<Teuchos::FancyOStream>
1558  out = Teuchos::rcp(&out_arg,false);
1559  OSTab tab(out);
1560 
1561  *out <<"Thyra::ModelEvaluatorBase::OutArgs<"<<ST::name()<<">:\n";
1562  tab.incrTab();
1563 
1564  *out <<"model = " << modelEvalDescription_ << "\n";
1565  *out <<"Np = " << Np() << "\n";
1566  *out <<"Ng = " << Ng() << "\n";
1567 
1568  CV_ptr f;
1569  if (this->supports(OUT_ARG_f) && !is_null(f=get_f()) ) {
1570  *out << "f = " << Teuchos::describe(*f,verbLevel);
1571  }
1572 
1573  for( int j = 0; j < Ng(); ++j ) {
1574  CV_ptr g_j;
1575  if (!is_null(g_j=this->get_g(j)))
1576  *out << "g("<<j<<") = " << Teuchos::describe(*g_j,verbLevel);
1577  }
1578 
1579  CLOWS_ptr W;
1580  if ( this->supports(OUT_ARG_W) && !is_null(W=get_W()) ) {
1581  *out << "W = " << Teuchos::describe(*W,verbLevel);
1582  }
1583 
1584  CLO_ptr W_op;
1585  if ( this->supports(OUT_ARG_W_op) && !is_null(W_op=get_W_op()) ) {
1586  *out << "W_op = " << Teuchos::describe(*W_op,verbLevel);
1587  }
1588 
1589  for( int l = 0; l < Np(); ++l ) {
1590  Deriv DfDp_l;
1591  if (
1592  !this->supports(OUT_ARG_DfDp,l).none()
1593  && !(DfDp_l=get_DfDp(l)).isEmpty()
1594  )
1595  {
1596  *out << "DfDp("<<l<<") = ";
1597  DfDp_l.describe(*out,verbLevel);
1598  }
1599  }
1600 
1601  for( int j = 0; j < Ng(); ++j ) {
1602 
1603  Deriv DgDx_dot_j;
1604  if (
1605  !this->supports(OUT_ARG_DgDx_dot,j).none()
1606  && !(DgDx_dot_j=get_DgDx_dot(j)).isEmpty()
1607  )
1608  {
1609  *out << "DgDx_dot("<<j<<") = ";
1610  DgDx_dot_j.describe(*out,verbLevel);
1611  }
1612 
1613  Deriv DgDx_j;
1614  if (
1615  !this->supports(OUT_ARG_DgDx,j).none()
1616  && !(DgDx_j=get_DgDx(j)).isEmpty()
1617  )
1618  {
1619  *out << "DgDx("<<j<<") = ";
1620  DgDx_j.describe(*out,verbLevel);
1621  }
1622 
1623  for( int l = 0; l < Np(); ++l ) {
1624 
1625  Deriv DgDp_j_l;
1626  if (
1627  !this->supports(OUT_ARG_DgDp,j,l).none()
1628  && !(DgDp_j_l=get_DgDp(j,l)).isEmpty()
1629  )
1630  {
1631  *out << "DgDp("<<j<<","<<l<<") = ";
1632  DgDp_j_l.describe(*out,verbLevel);
1633  }
1634  }
1635 
1636  }
1637 
1638  // ToDo: Add output for more objects?
1639 
1640 }
1641 
1642 
1643 // protected
1644 
1645 
1646 template<class Scalar>
1648  const std::string &modelEvalDescription_in
1649  )
1650 {
1651  modelEvalDescription_ = modelEvalDescription_in;
1652 }
1653 
1654 template<class Scalar>
1656 {
1657  if(Np_in) {
1658  supports_DfDp_.resize(Np_in);
1659  DfDp_.resize(Np_in); std::fill_n(DfDp_.begin(),Np_in,Derivative<Scalar>());
1660  DfDp_properties_.resize(Np_in); std::fill_n(DfDp_properties_.begin(),Np_in,DerivativeProperties());
1661 
1662  supports_DfDp_mp_.resize(Np_in);
1663  DfDp_mp_.resize(Np_in); std::fill_n(DfDp_mp_.begin(),Np_in,MPDerivative());
1664  DfDp_mp_properties_.resize(Np_in); std::fill_n(DfDp_mp_properties_.begin(),Np_in,DerivativeProperties());
1665  }
1666  if(Ng_in) {
1667  g_.resize(Ng_in); std::fill_n(g_.begin(),Ng_in,Teuchos::null);
1668  supports_DgDx_dot_.resize(Ng_in);
1669  DgDx_dot_.resize(Ng_in); std::fill_n(DgDx_dot_.begin(),Ng_in,Derivative<Scalar>());
1670  DgDx_dot_properties_.resize(Ng_in); std::fill_n(DgDx_dot_properties_.begin(),Ng_in,DerivativeProperties());
1671  supports_DgDx_.resize(Ng_in);
1672  DgDx_.resize(Ng_in); std::fill_n(DgDx_.begin(),Ng_in,Derivative<Scalar>());
1673  DgDx_properties_.resize(Ng_in); std::fill_n(DgDx_properties_.begin(),Ng_in,DerivativeProperties());
1674 
1675  g_mp_.resize(Ng_in); std::fill_n(g_mp_.begin(),Ng_in,Teuchos::null);
1676  supports_g_mp_.resize(Ng_in);
1677  supports_DgDx_dot_mp_.resize(Ng_in);
1678  DgDx_dot_mp_.resize(Ng_in); std::fill_n(DgDx_dot_mp_.begin(),Ng_in,MPDerivative());
1679  DgDx_dot_mp_properties_.resize(Ng_in); std::fill_n(DgDx_dot_mp_properties_.begin(),Ng_in,DerivativeProperties());
1680  supports_DgDx_mp_.resize(Ng_in);
1681  DgDx_mp_.resize(Ng_in); std::fill_n(DgDx_mp_.begin(),Ng_in,MPDerivative());
1682  DgDx_mp_properties_.resize(Ng_in); std::fill_n(DgDx_mp_properties_.begin(),Ng_in,DerivativeProperties());
1683  }
1684  if(Np_in && Ng_in) {
1685  const int NpNg = Np_in*Ng_in;
1686  supports_DgDp_.resize(NpNg);
1687  DgDp_.resize(NpNg); std::fill_n(DgDp_.begin(),NpNg,Derivative<Scalar>());
1688  DgDp_properties_.resize(NpNg); std::fill_n(DgDp_properties_.begin(),NpNg,DerivativeProperties());
1689 
1690  supports_DgDp_mp_.resize(NpNg);
1691  DgDp_mp_.resize(NpNg); std::fill_n(DgDp_mp_.begin(),NpNg,MPDerivative());
1692  DgDp_mp_properties_.resize(NpNg); std::fill_n(DgDp_mp_properties_.begin(),NpNg,DerivativeProperties());
1693  }
1694 }
1695 
1696 
1697 template<class Scalar>
1699  EOutArgsMembers arg, bool supports_in )
1700 {
1701  TEUCHOS_TEST_FOR_EXCEPTION(
1702  int(arg)>=NUM_E_OUT_ARGS_MEMBERS || int(arg) < 0,std::logic_error
1703  ,"model = \'"<<modelEvalDescription_
1704  <<"\': Error, arg="<<toString(arg)<<" is invalid!"
1705  );
1706  supports_[arg] = supports_in;
1707 }
1708 
1709 
1710 template<class Scalar>
1712  EOutArgsDfDp arg, int l, const DerivativeSupport& supports_in
1713  )
1714 {
1715  assert_supports(OUT_ARG_f);
1716  assert_l(l);
1717  supports_DfDp_[l] = supports_in;
1718 }
1719 
1720 
1721 template<class Scalar>
1723  EOutArgsDgDx_dot arg, int j, const DerivativeSupport& supports_in
1724  )
1725 {
1726  assert_j(j);
1727  supports_DgDx_dot_[j] = supports_in;
1728 }
1729 
1730 
1731 template<class Scalar>
1733  EOutArgsDgDx arg, int j, const DerivativeSupport& supports_in
1734  )
1735 {
1736  assert_j(j);
1737  supports_DgDx_[j] = supports_in;
1738 }
1739 
1740 
1741 template<class Scalar>
1743  EOutArgsDgDp arg, int j, int l, const DerivativeSupport& supports_in
1744  )
1745 {
1746  assert_j(j);
1747  assert_l(l);
1748  supports_DgDp_[ j*Np()+ l ] = supports_in;
1749 }
1750 
1751 
1752 template<class Scalar>
1754  EOutArgs_g_mp arg, int j, bool supports_in
1755  )
1756 {
1757  //assert_supports(OUT_ARG_g_mp,j);
1758  assert_j(j);
1759  supports_g_mp_[j] = supports_in;
1760 }
1761 
1762 
1763 template<class Scalar>
1765  EOutArgsDfDp_mp arg, int l, const DerivativeSupport& supports_in
1766  )
1767 {
1768  assert_supports(OUT_ARG_f_mp); //JF this is not in epetraext ME
1769  assert_l(l);
1770  supports_DfDp_mp_[l] = supports_in;
1771 }
1772 
1773 
1774 template<class Scalar>
1775 void ModelEvaluatorBase::OutArgs<Scalar>::_setSupports(
1776  EOutArgsDgDx_dot_mp arg, int j, const DerivativeSupport& supports_in
1777  )
1778 {
1779  assert_j(j);
1780  supports_DgDx_dot_mp_[j] = supports_in;
1781 }
1782 
1783 
1784 template<class Scalar>
1785 void ModelEvaluatorBase::OutArgs<Scalar>::_setSupports(
1786  EOutArgsDgDx_mp arg, int j, const DerivativeSupport& supports_in
1787  )
1788 {
1789  assert_j(j);
1790  supports_DgDx_mp_[j] = supports_in;
1791 }
1792 
1793 
1794 template<class Scalar>
1795 void ModelEvaluatorBase::OutArgs<Scalar>::_setSupports(
1796  EOutArgsDgDp_mp arg, int j, int l, const DerivativeSupport& supports_in
1797  )
1798 {
1799  assert_j(j);
1800  assert_l(l);
1801  supports_DgDp_mp_[ j*Np()+ l ] = supports_in;
1802 }
1803 
1804 
1805 template<class Scalar>
1807  const DerivativeProperties &properties
1808  )
1809 {
1810  W_properties_ = properties;
1811 }
1812 
1813 
1814 template<class Scalar>
1816  int l, const DerivativeProperties &properties
1817  )
1818 {
1819  assert_supports(OUT_ARG_DfDp,l);
1820  DfDp_properties_[l] = properties;
1821 }
1822 
1823 
1824 template<class Scalar>
1826  int j, const DerivativeProperties &properties
1827  )
1828 {
1829  assert_supports(OUT_ARG_DgDx_dot,j);
1830  DgDx_dot_properties_[j] = properties;
1831 }
1832 
1833 
1834 template<class Scalar>
1836  int j, const DerivativeProperties &properties
1837  )
1838 {
1839  assert_supports(OUT_ARG_DgDx,j);
1840  DgDx_properties_[j] = properties;
1841 }
1842 
1843 
1844 template<class Scalar>
1846  int j, int l, const DerivativeProperties &properties
1847  )
1848 {
1849  assert_supports(OUT_ARG_DgDp,j,l);
1850  DgDp_properties_[ j*Np()+ l ] = properties;
1851 }
1852 
1853 
1854 template<class Scalar>
1856  int l, const DerivativeProperties &properties
1857  )
1858 {
1859  assert_supports(OUT_ARG_DfDp_mp,l);
1860  DfDp_mp_properties_[l] = properties;
1861 }
1862 
1863 
1864 template<class Scalar>
1866  int j, const DerivativeProperties &properties
1867  )
1868 {
1869  assert_supports(OUT_ARG_DgDx_dot_mp,j);
1870  DgDx_dot_mp_properties_[j] = properties;
1871 }
1872 
1873 
1874 template<class Scalar>
1875 void ModelEvaluatorBase::OutArgs<Scalar>::_set_DgDx_mp_properties(
1876  int j, const DerivativeProperties &properties
1877  )
1878 {
1879  assert_supports(OUT_ARG_DgDx_mp,j);
1880  DgDx_mp_properties_[j] = properties;
1881 }
1882 
1883 
1884 template<class Scalar>
1885 void ModelEvaluatorBase::OutArgs<Scalar>::_set_DgDp_mp_properties(
1886  int j, int l, const DerivativeProperties &properties
1887  )
1888 {
1889  assert_supports(OUT_ARG_DgDp_mp,j,l);
1890  DgDp_mp_properties_[ j*Np()+ l ] = properties;
1891 }
1892 
1893 
1894 template<class Scalar>
1896  const OutArgs<Scalar>& inputOutArgs
1897  )
1898 {
1899  typedef ModelEvaluatorBase MEB;
1900  const int l_Np = TEUCHOS_MIN(this->Np(),inputOutArgs.Np());
1901  const int l_Ng = TEUCHOS_MIN(this->Ng(),inputOutArgs.Ng());
1902  std::copy(
1903  &inputOutArgs.supports_[0],
1904  &inputOutArgs.supports_[0] + NUM_E_OUT_ARGS_MEMBERS, &supports_[0] );
1905  for( int l = 0; l < l_Np; ++l ) {
1906  DerivativeSupport ds = inputOutArgs.supports(MEB::OUT_ARG_DfDp,l);
1907  if (!ds.none()) {
1908  this->_setSupports(MEB::OUT_ARG_DfDp,l,ds);
1909  this->_set_DfDp_properties(l,inputOutArgs.get_DfDp_properties(l));
1910  }
1911  }
1912  for( int l = 0; l < l_Np; ++l ) {
1913  DerivativeSupport ds = inputOutArgs.supports(MEB::OUT_ARG_DfDp_mp,l);
1914  if (!ds.none()) {
1915  this->_setSupports(MEB::OUT_ARG_DfDp_mp,l,ds);
1916  this->_set_DfDp_mp_properties(l,inputOutArgs.get_DfDp_mp_properties(l));
1917  }
1918  }
1919  for( int j = 0; j < l_Ng; ++j ) {
1920  DerivativeSupport ds = inputOutArgs.supports(MEB::OUT_ARG_DgDx_dot,j);
1921  this->_setSupports(MEB::OUT_ARG_DgDx_dot,j,ds);
1922  if(!ds.none()) this->_set_DgDx_dot_properties(j,inputOutArgs.get_DgDx_dot_properties(j));
1923  }
1924  for( int j = 0; j < l_Ng; ++j ) {
1925  DerivativeSupport ds = inputOutArgs.supports(MEB::OUT_ARG_DgDx_dot_mp,j);
1926  this->_setSupports(MEB::OUT_ARG_DgDx_dot_mp,j,ds);
1927  if(!ds.none()) this->_set_DgDx_dot_mp_properties(j,inputOutArgs.get_DgDx_dot_mp_properties(j));
1928  }
1929  for( int j = 0; j < l_Ng; ++j ) {
1930  DerivativeSupport ds = inputOutArgs.supports(MEB::OUT_ARG_DgDx,j);
1931  this->_setSupports(MEB::OUT_ARG_DgDx,j,ds);
1932  if(!ds.none()) this->_set_DgDx_properties(j,inputOutArgs.get_DgDx_properties(j));
1933  }
1934  for( int j = 0; j < l_Ng; ++j ) {
1935  DerivativeSupport ds = inputOutArgs.supports(MEB::OUT_ARG_DgDx_mp,j);
1936  this->_setSupports(MEB::OUT_ARG_DgDx_mp,j,ds);
1937  if(!ds.none()) this->_set_DgDx_mp_properties(j,inputOutArgs.get_DgDx_mp_properties(j));
1938  }
1939  for( int j = 0; j < l_Ng; ++j ) for( int l = 0; l < l_Np; ++l ) {
1940  DerivativeSupport ds = inputOutArgs.supports(MEB::OUT_ARG_DgDp,j,l);
1941  this->_setSupports(MEB::OUT_ARG_DgDp,j,l,ds);
1942  if(!ds.none()) this->_set_DgDp_properties(j,l,inputOutArgs.get_DgDp_properties(j,l));
1943  }
1944  for( int j = 0; j < l_Ng; ++j ) for( int l = 0; l < l_Np; ++l ) {
1945  DerivativeSupport ds = inputOutArgs.supports(MEB::OUT_ARG_DgDp_mp,j,l);
1946  this->_setSupports(MEB::OUT_ARG_DgDp_mp,j,l,ds);
1947  if(!ds.none()) this->_set_DgDp_mp_properties(j,l,inputOutArgs.get_DgDp_mp_properties(j,l));
1948  }
1949  if(this->supports(OUT_ARG_W) || this->supports(OUT_ARG_W_op))
1950  this->_set_W_properties(inputOutArgs.get_W_properties());
1951  if(this->supports(OUT_ARG_W_mp))
1952  this->_set_W_properties(inputOutArgs.get_W_properties()); //JF should this be W_mp_properties?
1953 }
1954 
1955 
1956 template<class Scalar>
1958  EInArgsMembers arg
1959  )
1960 {
1961  switch(arg) {
1962  case IN_ARG_x: {
1963  const int l_Ng = this->Ng();
1964  for( int j = 0; j < l_Ng; ++j ) {
1965  this->_setSupports(OUT_ARG_DgDx_dot,j,DerivativeSupport());
1966  this->_setSupports(OUT_ARG_DgDx,j,DerivativeSupport());
1967  }
1968  break;
1969  }
1970  case IN_ARG_x_mp: {
1971  const int l_Ng = this->Ng();
1972  for( int j = 0; j < l_Ng; ++j ) {
1973  this->_setSupports(OUT_ARG_DgDx_dot_mp,j,DerivativeSupport());
1974  this->_setSupports(OUT_ARG_DgDx_mp,j,DerivativeSupport());
1975  }
1976  break;
1977  }
1978  default:
1979  TEUCHOS_TEST_FOR_EXCEPTION(
1980  true ,std::logic_error,
1981  "Error, can not handle args other than IN_ARG_x yet!"
1982  );
1983  break;
1984  }
1985 }
1986 
1987 
1988 template<class Scalar>
1990  EOutArgsMembers arg
1991  )
1992 {
1993  switch(arg) {
1994  case OUT_ARG_f: {
1995  this->_setSupports(OUT_ARG_W,false);
1996  this->_setSupports(OUT_ARG_W_op,false);
1997  this->_setSupports(OUT_ARG_f_poly,false);
1998  const int l_Np = this->Np();
1999  for( int l = 0; l < l_Np; ++l )
2000  this->_setSupports(OUT_ARG_DfDp,l,DerivativeSupport());
2001  break;
2002  }
2003  case OUT_ARG_f_mp: {
2004  this->_setSupports(OUT_ARG_W_mp,false);
2005  this->_setSupports(OUT_ARG_W_op,false);
2006  this->_setSupports(OUT_ARG_f_poly,false);
2007  const int l_Np = this->Np();
2008  for( int l = 0; l < l_Np; ++l )
2009  this->_setSupports(OUT_ARG_DfDp_mp,l,DerivativeSupport());
2010  break;
2011  }
2012  default:
2013  TEUCHOS_TEST_FOR_EXCEPTION(
2014  true ,std::logic_error,
2015  "Error, can not handle args other than OUT_ARG_f yet!"
2016  );
2017  break;
2018  }
2019  this->_setSupports(arg,false);
2020 }
2021 
2022 
2023 // private
2024 
2025 
2026 template<class Scalar>
2028 {
2029  TEUCHOS_TEST_FOR_EXCEPTION(
2030  !this->supports(arg), std::logic_error
2031  ,"Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(arg):\n\n"
2032  "model = \'"<<modelEvalDescription_<<"\':\n\n"
2033  "Error, The argument arg = " << toString(arg) << " is not supported!"
2034  );
2035 }
2036 
2037 
2038 template<class Scalar>
2040  EOutArgsDfDp arg, int l, const Derivative<Scalar> &deriv
2041  ) const
2042 {
2043  const DerivativeSupport derivSupport = this->supports(arg,l);
2044  TEUCHOS_TEST_FOR_EXCEPTION(
2045  !deriv.isSupportedBy(derivSupport), std::logic_error,
2046  "Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(OUT_ARG_DfDp,l):\n\n"
2047  "model = \'"<<modelEvalDescription_<<"\':\n\n"
2048  "Error, The argument DfDp("<<l<<") = " << deriv.description() << "\n"
2049  "is not supported!\n\n"
2050  "The supported types include " << derivSupport.description() << "!"
2051  );
2052 }
2053 
2054 
2055 template<class Scalar>
2056 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(
2057  EOutArgsDgDx_dot arg, int j, const Derivative<Scalar> &deriv
2058  ) const
2059 {
2060  const DerivativeSupport derivSupport = this->supports(arg,j);
2061  TEUCHOS_TEST_FOR_EXCEPTION(
2062  !deriv.isSupportedBy(derivSupport), std::logic_error,
2063  "Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(OUT_ARG_DgDx_dot,j):\n\n"
2064  "model = \'"<<modelEvalDescription_<<"\':\n\n"
2065  "Error, The argument DgDx_dot("<<j<<") = " << deriv.description() << "\n"
2066  "is not supported!\n\n"
2067  "The supported types include " << derivSupport.description() << "!"
2068  );
2069 }
2070 
2071 
2072 template<class Scalar>
2073 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(
2074  EOutArgsDgDx arg, int j, const Derivative<Scalar> &deriv
2075  ) const
2076 {
2077  const DerivativeSupport derivSupport = this->supports(arg,j);
2078  TEUCHOS_TEST_FOR_EXCEPTION(
2079  !deriv.isSupportedBy(derivSupport), std::logic_error,
2080  "Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(OUT_ARG_DgDx,j):\n\n"
2081  "model = \'"<<modelEvalDescription_<<"\':\n\n"
2082  "Error, The argument DgDx("<<j<<") = " << deriv.description() << "\n"
2083  "is not supported!\n\n"
2084  "The supported types include " << derivSupport.description() << "!"
2085  );
2086 }
2087 
2088 
2089 template<class Scalar>
2090 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(
2091  EOutArgsDgDp arg, int j, int l, const Derivative<Scalar> &deriv
2092  ) const
2093 {
2094  const DerivativeSupport derivSupport = this->supports(arg,j,l);
2095  TEUCHOS_TEST_FOR_EXCEPTION(
2096  !deriv.isSupportedBy(derivSupport), std::logic_error,
2097  "Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(OUT_ARG_DgDp,j,l):\n\n"
2098  "model = \'"<<modelEvalDescription_<<"\':\n\n"
2099  "Error, The argument DgDp("<<j<<","<<l<<") = " << deriv.description() << "\n"
2100  "is not supported!\n\n"
2101  "The supported types include " << derivSupport.description() << "!"
2102  );
2103 }
2104 
2105 
2106 template<class Scalar>
2107 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(
2108  EOutArgs_g_mp arg, int j
2109  ) const
2110 {
2111  assert_j(j);
2112  TEUCHOS_TEST_FOR_EXCEPTION(
2113  !supports_g_mp_[j], std::logic_error,
2114  "Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(OUT_ARG_g_mp,j):\n\n"
2115  "model = \'"<<modelEvalDescription_<<"\':\n\n"
2116  "Error, The argument g_mp("<<j<<") \n"
2117  "is not supported!\n\n"
2118  );
2119 }
2120 
2121 
2122 template<class Scalar>
2123 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(
2124  EOutArgsDfDp_mp arg, int l, const MPDerivative &deriv
2125  ) const
2126 {
2127  const DerivativeSupport derivSupport = this->supports(arg,l);
2128  TEUCHOS_TEST_FOR_EXCEPTION(
2129  !deriv.isSupportedBy(derivSupport), std::logic_error,
2130  "Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(OUT_ARG_DfDp_mp,l):\n\n"
2131  "model = \'"<<modelEvalDescription_<<"\':\n\n"
2132  "Error, The argument DfDp_mp("<<l<<") = " << deriv.description() << "\n"
2133  "is not supported!\n\n"
2134  "The supported types include " << derivSupport.description() << "!"
2135  );
2136 }
2137 
2138 
2139 template<class Scalar>
2140 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(
2141  EOutArgsDgDx_dot_mp arg, int j, const MPDerivative &deriv
2142  ) const
2143 {
2144  const DerivativeSupport derivSupport = this->supports(arg,j);
2145  TEUCHOS_TEST_FOR_EXCEPTION(
2146  !deriv.isSupportedBy(derivSupport), std::logic_error,
2147  "Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(OUT_ARG_DgDx_dot_mp,j):\n\n"
2148  "model = \'"<<modelEvalDescription_<<"\':\n\n"
2149  "Error, The argument DgDx_dot_mp("<<j<<") = " << deriv.description() << "\n"
2150  "is not supported!\n\n"
2151  "The supported types include " << derivSupport.description() << "!"
2152  );
2153 }
2154 
2155 
2156 template<class Scalar>
2157 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(
2158  EOutArgsDgDx_mp arg, int j, const MPDerivative &deriv
2159  ) const
2160 {
2161  const DerivativeSupport derivSupport = this->supports(arg,j);
2162  TEUCHOS_TEST_FOR_EXCEPTION(
2163  !deriv.isSupportedBy(derivSupport), std::logic_error,
2164  "Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(OUT_ARG_DgDx_mp,j):\n\n"
2165  "model = \'"<<modelEvalDescription_<<"\':\n\n"
2166  "Error, The argument DgDx_mp("<<j<<") = " << deriv.description() << "\n"
2167  "is not supported!\n\n"
2168  "The supported types include " << derivSupport.description() << "!"
2169  );
2170 }
2171 
2172 
2173 template<class Scalar>
2174 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(
2175  EOutArgsDgDp_mp arg, int j, int l, const MPDerivative &deriv
2176  ) const
2177 {
2178  const DerivativeSupport derivSupport = this->supports(arg,j,l);
2179  TEUCHOS_TEST_FOR_EXCEPTION(
2180  !deriv.isSupportedBy(derivSupport), std::logic_error,
2181  "Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(OUT_ARG_DgDp_mp,j,l):\n\n"
2182  "model = \'"<<modelEvalDescription_<<"\':\n\n"
2183  "Error, The argument DgDp_mp("<<j<<","<<l<<") = " << deriv.description() << "\n"
2184  "is not supported!\n\n"
2185  "The supported types include " << derivSupport.description() << "!"
2186  );
2187 }
2188 
2189 
2190 template<class Scalar>
2191 void ModelEvaluatorBase::OutArgs<Scalar>::assert_l(int l) const
2192 {
2193  TEUCHOS_TEST_FOR_EXCEPTION(
2194  !( 0 <= l && l < Np() ), std::logic_error
2195  ,"Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_l(l):\n\n"
2196  "model = \'"<<modelEvalDescription_<<"\':\n\n"
2197  "Error, The parameter subvector p("<<l<<")"
2198  " is not in the range [0,"<<Np()<<")!"
2199  );
2200 }
2201 
2202 
2203 template<class Scalar>
2204 void ModelEvaluatorBase::OutArgs<Scalar>::assert_j(int j) const
2205 {
2206  TEUCHOS_TEST_FOR_EXCEPTION(
2207  !( 0 <= j && j < Ng() ), std::logic_error
2208  ,"Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_j(j):\n\n"
2209  "model = \'"<<modelEvalDescription_<<"\':\n\n"
2210  "Error, The auxiliary function g("<<j<<")"
2211  " is not in the range [0,"<<Ng()<<")!"
2212  );
2213 }
2214 
2215 
2216 //
2217 // ModelEvaluatorBase::InArgsSetup
2218 //
2219 
2220 
2221 template<class Scalar>
2223 {}
2224 
2225 
2226 template<class Scalar>
2228  :InArgs<Scalar>(inArgs)
2229 {}
2230 
2231 
2232 template<class Scalar>
2234  const std::string &modelEvalDescription_in )
2235 {
2236  this->_setModelEvalDescription(modelEvalDescription_in);
2237 }
2238 
2239 
2240 template<class Scalar>
2242 { this->_set_Np(Np_in); }
2243 
2244 
2245 template<class Scalar>
2247 { this->_setSupports(arg,supports_in); }
2248 
2249 
2250 template<class Scalar>
2251 void ModelEvaluatorBase::InArgsSetup<Scalar>::setSupports( EInArgs_p_mp arg, int l, bool supports_in )
2252 { this->_setSupports(arg,l,supports_in); }
2253 
2254 
2255 template<class Scalar>
2257  const InArgs<Scalar>& inArgs, const int Np_in
2258  )
2259 {
2260  this->_setSupports(inArgs, Np_in);
2261 }
2262 
2263 
2264 template<class Scalar>
2266  EInArgsMembers arg
2267  )
2268 {
2269  this->_setUnsupportsAndRelated(arg);
2270 }
2271 
2272 
2273 //
2274 // ModelEvaluatorBase::OutArgsSetup
2275 //
2276 
2277 
2278 template<class Scalar>
2280 {}
2281 
2282 
2283 template<class Scalar>
2285  const OutArgs<Scalar>& inputOutArgs
2286  )
2287  :OutArgs<Scalar>(inputOutArgs)
2288 {}
2289 
2290 
2291 template<class Scalar>
2293  const std::string &modelEvalDescription_in
2294  )
2295 { this->_setModelEvalDescription(modelEvalDescription_in); }
2296 
2297 
2298 template<class Scalar>
2300 { this->_set_Np_Ng(Np_in, Ng_in); }
2301 
2302 
2303 template<class Scalar>
2305  EOutArgsMembers arg, bool supports_in
2306  )
2307 { this->_setSupports(arg,supports_in); }
2308 
2309 
2310 template<class Scalar>
2312  EOutArgsDfDp arg, int l, const DerivativeSupport& supports_in
2313  )
2314 { this->_setSupports(arg,l,supports_in); }
2315 
2316 
2317 template<class Scalar>
2319  EOutArgsDgDx_dot arg, int j, const DerivativeSupport& supports_in
2320  )
2321 { this->_setSupports(arg,j,supports_in); }
2322 
2323 
2324 template<class Scalar>
2326  EOutArgsDgDx arg, int j, const DerivativeSupport& supports_in
2327  )
2328 { this->_setSupports(arg,j,supports_in); }
2329 
2330 
2331 template<class Scalar>
2333  EOutArgsDgDp arg, int j, int l, const DerivativeSupport& supports_in
2334  )
2335 { this->_setSupports(arg,j,l,supports_in); }
2336 
2337 
2338 template<class Scalar>
2340  EOutArgs_g_mp arg, int j, bool supports_in
2341  )
2342 { this->_setSupports(arg,j,supports_in); }
2343 
2344 
2345 template<class Scalar>
2347  EOutArgsDfDp_mp arg, int l, const DerivativeSupport& supports_in
2348  )
2349 { this->_setSupports(arg,l,supports_in); }
2350 
2351 
2352 template<class Scalar>
2354  EOutArgsDgDx_dot_mp arg, int j, const DerivativeSupport& supports_in
2355  )
2356 { this->_setSupports(arg,j,supports_in); }
2357 
2358 
2359 template<class Scalar>
2361  EOutArgsDgDx_mp arg, int j, const DerivativeSupport& supports_in
2362  )
2363 { this->_setSupports(arg,j,supports_in); }
2364 
2365 
2366 template<class Scalar>
2368  EOutArgsDgDp_mp arg, int j, int l, const DerivativeSupport& supports_in
2369  )
2370 { this->_setSupports(arg,j,l,supports_in); }
2371 
2372 
2373 template<class Scalar>
2375  const DerivativeProperties &properties
2376  )
2377 { this->_set_W_properties(properties); }
2378 
2379 
2380 template<class Scalar>
2382  int l, const DerivativeProperties &properties
2383  )
2384 { this->_set_DfDp_properties(l,properties); }
2385 
2386 
2387 template<class Scalar>
2389  int j, const DerivativeProperties &properties
2390  )
2391 { this->_set_DgDx_dot_properties(j,properties); }
2392 
2393 
2394 template<class Scalar>
2396  int j, const DerivativeProperties &properties
2397  )
2398 { this->_set_DgDx_properties(j,properties); }
2399 
2400 
2401 template<class Scalar>
2403  int j, int l, const DerivativeProperties &properties
2404  )
2405 { this->_set_DgDp_properties(j,l,properties); }
2406 
2407 
2408 template<class Scalar>
2410  int l, const DerivativeProperties &properties
2411  )
2412 { this->_set_DfDp_mp_properties(l,properties); }
2413 
2414 
2415 template<class Scalar>
2417  int j, const DerivativeProperties &properties
2418  )
2419 { this->_set_DgDx_dot_mp_properties(j,properties); }
2420 
2421 
2422 template<class Scalar>
2423 void ModelEvaluatorBase::OutArgsSetup<Scalar>::set_DgDx_mp_properties(
2424  int j, const DerivativeProperties &properties
2425  )
2426 { this->_set_DgDx_mp_properties(j,properties); }
2427 
2428 
2429 template<class Scalar>
2430 void ModelEvaluatorBase::OutArgsSetup<Scalar>::set_DgDp_mp_properties(
2431  int j, int l, const DerivativeProperties &properties
2432  )
2433 { this->_set_DgDp_mp_properties(j,l,properties); }
2434 
2435 
2436 template<class Scalar>
2438  const OutArgs<Scalar>& inputOutArgs
2439  )
2440 { this->_setSupports(inputOutArgs); }
2441 
2442 
2443 template<class Scalar>
2445  EInArgsMembers arg
2446  )
2447 { this->_setUnsupportsAndRelated(arg); }
2448 
2449 
2450 template<class Scalar>
2452  EOutArgsMembers arg
2453  )
2454 { this->_setUnsupportsAndRelated(arg); }
2455 
2456 
2457 } // namespace Thyra
2458 
2459 
2460 
2461 //
2462 // Explicit instantiation macro
2463 //
2464 // Must be expanded from within the Thyra namespace!
2465 //
2466 
2467 
2468 #define THYRA_MODEL_EVALUATOR_BASE_INSTANT(SCALAR) \
2469  \
2470  template class ModelEvaluatorBase::InArgs<SCALAR >; \
2471  \
2472  template std::string \
2473  ModelEvaluatorBase::Derivative<SCALAR >::description() const; \
2474  \
2475  template \
2476  void ModelEvaluatorBase::Derivative<SCALAR >::describe( \
2477  Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel \
2478  ) const; \
2479  \
2480  template class ModelEvaluatorBase::OutArgs<SCALAR >; \
2481  \
2482  template class ModelEvaluatorBase::InArgsSetup<SCALAR >; \
2483  \
2484  template class ModelEvaluatorBase::OutArgsSetup<SCALAR >;
2485 
2486 
2487 #endif // THYRA_MODEL_EVALUATOR_BASE_DEF_HPP
Protected subclass of InArgs that only ModelEvaluator subclasses can access to set up the selection o...
RCP< const Stokhos::ProductEpetraVector > get_x_dot_mp() const
Precondition: supports(IN_ARG_x_dotmp)==true.
Scalar get_step_size() const
Precondition: supports(IN_ARG_step_size)==true.
void set_DgDx_properties(int j, const DerivativeProperties &properties)
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.
std::string toString(ModelEvaluatorBase::EInArgsMembers)
bool supports(EInArgsMembers arg) const
Determines if an input argument is supported or not.
Concrete aggregate class for all output arguments computable by a ModelEvaluator subclass object...
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).
void setModelEvalDescription(const std::string &modelEvalDescription)
void assign(const Ptr< MultiVectorBase< Scalar > > &V, Scalar alpha)
V = alpha.
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.
Simple aggregate class that stores a derivative object as a general linear operator or as a multi-vec...
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.
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.
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.
ScalarMag get_t() const
.Precondition: supports(IN_ARG_t)==true
Simple aggregate class for a derivative object represented as a column-wise multi-vector or its trans...
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< 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< double >::magnitudeType ScalarMag
RCP< PreconditionerBase< Scalar > > get_W_prec() const
Precondition: supports(OUT_ARG_W_op)==true.
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.
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..
Base class for all linear operators.
void set_DgDx_dot_properties(int j, const DerivativeProperties &properties)
int Ng() const
Return the number of axillary response functions g(j)(...) supported (Ng >= 0).
Base subclass for ModelEvaluator that defines some basic types.
int Np() const
Return the number of parameter subvectors p(l) supported (Np >= 0).
void setSupports(EOutArgsMembers arg, bool supports=true)
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).
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.
Teuchos::ScalarTraits< Scalar >::magnitudeType norm(const VectorBase< Scalar > &v)
Natural norm: result = sqrt(<v,v>).
Determines the forms of a general derivative that are supported.
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::ProductEpetraVector > get_g_mp(int j) const
Precondition: supports(OUT_ARG_g_mp)==true..
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).
Concrete aggregate class for all output arguments computable by a ModelEvaluator subclass object...