Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_ModelEvaluatorHelpers.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_HELPERS_HPP
43 #define THYRA_MODEL_EVALUATOR_HELPERS_HPP
44 
45 
46 #include "Thyra_ModelEvaluator.hpp"
47 
48 
49 namespace Thyra {
50 
51 
59 template<class Scalar>
60 RCP<ModelEvaluatorBase::InArgs<Scalar> >
61 clone( const ModelEvaluatorBase::InArgs<Scalar> &inArgs );
62 
63 
65 template<class Scalar>
66 ModelEvaluatorBase::Derivative<Scalar>
67 derivativeGradient(
68  const RCP<MultiVectorBase<Scalar> > &grad
69  );
70 
71 
73 template<class Scalar>
74 ModelEvaluatorBase::DerivativeMultiVector<Scalar>
75 create_DfDp_mv(
76  const ModelEvaluator<Scalar>& model,
77  int l,
79  );
80 
81 
83 template<class Scalar>
84 ModelEvaluatorBase::DerivativeMultiVector<Scalar>
85 create_DgDx_dot_mv(
86  const ModelEvaluator<Scalar>& model,
87  int j,
89  );
90 
91 
93 template<class Scalar>
94 ModelEvaluatorBase::DerivativeMultiVector<Scalar>
95 create_DgDx_mv(
96  const ModelEvaluator<Scalar>& model,
97  int j,
99  );
100 
101 
103 template<class Scalar>
104 ModelEvaluatorBase::DerivativeMultiVector<Scalar>
105 create_DgDp_mv(
106  const ModelEvaluator<Scalar>& model,
107  int j,
108  int l,
110  );
111 
112 
114 template<class Scalar>
115 ModelEvaluatorBase::DerivativeMultiVector<Scalar>
116 get_dmv(
117  const ModelEvaluatorBase::Derivative<Scalar> &deriv
118  ,const std::string &derivName
119  );
120 
121 
123 template<class Scalar>
124 RCP<MultiVectorBase<Scalar> >
125 get_mv(
126  const ModelEvaluatorBase::Derivative<Scalar> &deriv
127  ,const std::string &derivName
129  );
130 
131 
137 template<class Scalar>
138 void assertDerivSpaces(
139  const std::string &modelEvalDescription,
140  const ModelEvaluatorBase::Derivative<Scalar> &deriv,
141  const std::string &deriv_name,
142  const VectorSpaceBase<Scalar> &fnc_space,
143  const std::string &fnc_space_name,
144  const VectorSpaceBase<Scalar> &var_space,
145  const std::string &var_space_name
146  );
147 
148 
153 template<class Scalar>
154 void assertInArgsOutArgsSetup(
155  const std::string &modelEvalDescription,
156  const ModelEvaluatorBase::InArgs<Scalar> &inArgs,
157  const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
158  );
159 
160 
165 template<class Scalar>
166 void assertInArgsEvalObjects(
167  const ModelEvaluator<Scalar> &model,
168  const ModelEvaluatorBase::InArgs<Scalar> &inArgs
169  );
170 
171 
176 template<class Scalar>
177 void assertOutArgsEvalObjects(
178  const ModelEvaluator<Scalar> &model,
179  const ModelEvaluatorBase::OutArgs<Scalar> &outArgs,
180  const ModelEvaluatorBase::InArgs<Scalar> *inArgs = 0
181  );
182 
183 
185 template<class Scalar>
186 void eval_f(
187  const ModelEvaluator<Scalar> &model
188  ,const VectorBase<Scalar> &x
189  ,VectorBase<Scalar> *f
190  );
191 
192 
194 template<class Scalar>
195 void eval_f_W(
196  const ModelEvaluator<Scalar> &model
197  ,const VectorBase<Scalar> &x
198  ,VectorBase<Scalar> *f
199  ,LinearOpWithSolveBase<Scalar> *W
200  );
201 
202 
204 template<class Scalar>
205 void eval_f(
206  const ModelEvaluator<Scalar> &model
207  ,const VectorBase<Scalar> &x
208  ,const Scalar &t
209  ,VectorBase<Scalar> *f
210  );
211 
212 
214 template<class Scalar>
215 void eval_g(
216  const ModelEvaluator<Scalar> &model,
217  const int l,
218  const VectorBase<Scalar> &p_l,
219  const int j,
220  const Ptr<VectorBase<Scalar> > &g_j
221  );
222 
223 
225 template<class Scalar>
226 void eval_g(
227  const ModelEvaluator<Scalar> &model,
228  const int l,
229  const VectorBase<Scalar> &p_l,
230  const Scalar &t,
231  const int j,
232  VectorBase<Scalar> *g_j
233  );
234 
235 
237 template<class Scalar>
238 void eval_g_DgDp(
239  const ModelEvaluator<Scalar> &model,
240  const int l,
241  const VectorBase<Scalar> &p_l,
242  const int j,
243  const Ptr<VectorBase<Scalar> > &g_j,
244  const ModelEvaluatorBase::Derivative<Scalar> &DgDp_j_l
245  );
246 
247 
249 template<class Scalar>
250 void eval_f(
251  const ModelEvaluator<Scalar> &model
252  ,const VectorBase<Scalar> &x_dot
253  ,const VectorBase<Scalar> &x
254  ,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
255  ,VectorBase<Scalar> *f
256  );
257 
258 
261 template<class Scalar>
262 void eval_f_W(
263  const ModelEvaluator<Scalar> &model
264  ,const VectorBase<Scalar> &x_dot
265  ,const VectorBase<Scalar> &x
266  ,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
267  ,const Scalar &alpha
268  ,const Scalar &beta
269  ,VectorBase<Scalar> *f
270  ,LinearOpWithSolveBase<Scalar> *W
271  );
272 
273 
274 #ifdef HAVE_THYRA_ME_POLYNOMIAL
275 
276 
278 template<class Scalar>
279 void eval_f_poly(
280  const ModelEvaluator<Scalar> &model
281  ,const Teuchos::Polynomial< VectorBase<Scalar> > &x_poly
282  ,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
283  ,Teuchos::Polynomial< VectorBase<Scalar> > *f_poly
284  );
285 
286 
288 template<class Scalar>
289 void eval_f_poly(
290  const ModelEvaluator<Scalar> &model
291  ,const Teuchos::Polynomial< VectorBase<Scalar> > &x_dot_poly
292  ,const VectorBase<Scalar> &x_poly
293  ,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
294  ,Teuchos::Polynomial< VectorBase<Scalar> > *f_poly
295  );
296 
297 
298 #endif // HAVE_THYRA_ME_POLYNOMIAL
299 
300 
301 } // namespace Thyra
302 
303 
304 //
305 // Implementations
306 //
307 
308 
309 #include "Thyra_AssertOp.hpp"
310 #include "Teuchos_Utils.hpp"
311 
312 
313 template<class Scalar>
315 Thyra::clone( const ModelEvaluatorBase::InArgs<Scalar> &inArgs )
316 {
317  RCP<ModelEvaluatorBase::InArgs<Scalar> >
318  newInArgs = Teuchos::rcp(new ModelEvaluatorBase::InArgs<Scalar>);
319  *newInArgs = inArgs;
320  return newInArgs;
321 }
322 
323 
324 template<class Scalar>
326 Thyra::derivativeGradient(
327  const RCP<MultiVectorBase<Scalar> > &grad
328  )
329 {
330  return ModelEvaluatorBase::Derivative<Scalar>(
331  grad,
332  ModelEvaluatorBase::DERIV_MV_GRADIENT_FORM
333  );
334 }
335 
336 
337 template<class Scalar>
339 Thyra::create_DfDp_mv(
340  const ModelEvaluator<Scalar>& model,
341  int l,
342  ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
343  )
344 {
345  TEUCHOS_TEST_FOR_EXCEPT(!(orientation==ModelEvaluatorBase::DERIV_MV_BY_COL));
346  return createMembers( model.get_f_space(), model.get_p_space(l)->dim() );
347 }
348 
349 
350 template<class Scalar>
352 Thyra::create_DgDx_dot_mv(
353  const ModelEvaluator<Scalar>& model,
354  int j,
355  ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
356  )
357 {
358  typedef ModelEvaluatorBase MEB;
359  switch(orientation) {
360  case MEB::DERIV_MV_BY_COL:
361  return
362  MEB::DerivativeMultiVector<Scalar>(
363  createMembers( model.get_g_space(j), model.get_x_space()->dim() )
364  ,MEB::DERIV_MV_BY_COL
365  );
366  case MEB::DERIV_TRANS_MV_BY_ROW:
367  return
368  MEB::DerivativeMultiVector<Scalar>(
369  createMembers( model.get_x_space(), model.get_g_space(j)->dim() )
370  ,MEB::DERIV_TRANS_MV_BY_ROW
371  );
372  default:
374  }
375  TEUCHOS_UNREACHABLE_RETURN(MEB::DerivativeMultiVector<Scalar>());
376 }
377 
378 
379 template<class Scalar>
381 Thyra::create_DgDx_mv(
382  const ModelEvaluator<Scalar>& model,
383  int j,
384  ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
385  )
386 {
387  return create_DgDx_dot_mv(model,j,orientation);
388 }
389 
390 
391 template<class Scalar>
393 Thyra::create_DgDp_mv(
394  const ModelEvaluator<Scalar>& model,
395  int j,
396  int l,
397  ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
398  )
399 {
400  typedef ModelEvaluatorBase MEB;
401  switch(orientation) {
402  case MEB::DERIV_MV_BY_COL:
403  return
404  MEB::DerivativeMultiVector<Scalar>(
405  createMembers( model.get_g_space(j), model.get_p_space(l)->dim() )
406  ,MEB::DERIV_MV_BY_COL
407  );
408  case MEB::DERIV_TRANS_MV_BY_ROW:
409  return
410  MEB::DerivativeMultiVector<Scalar>(
411  createMembers( model.get_p_space(l), model.get_g_space(j)->dim() )
412  ,MEB::DERIV_TRANS_MV_BY_ROW
413  );
414  default:
416  }
417  TEUCHOS_UNREACHABLE_RETURN(MEB::DerivativeMultiVector<Scalar>());
418 }
419 
420 
421 template<class Scalar>
423 Thyra::get_dmv(
424  const ModelEvaluatorBase::Derivative<Scalar> &deriv
425  ,const std::string &derivName
426  )
427 {
429  deriv.getLinearOp().get()!=NULL, std::logic_error
430  ,"Error, LinearOpBase type not expected for " << derivName <<"!"
431  );
432  return deriv.getDerivativeMultiVector();
433 }
434 
435 
436 template<class Scalar>
438 Thyra::get_mv(
439  const ModelEvaluatorBase::Derivative<Scalar> &deriv
440  ,const std::string &derivName
441  ,ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
442  )
443 {
444  typedef ModelEvaluatorBase MEB;
446  deriv.getLinearOp().get()!=NULL, std::logic_error
447  ,"Error, LinearOpBase type not expected for " << derivName <<"!"
448  );
449  MEB::DerivativeMultiVector<Scalar>
450  dmv = deriv.getDerivativeMultiVector();
451  RCP<MultiVectorBase<Scalar> >
452  mv = dmv.getMultiVector();
453  if( mv.get() ) {
455  dmv.getOrientation() != orientation, std::logic_error
456  ,"Error, the orientation " << toString(dmv.getOrientation()) << " is not the"
457  " expected orientation of " << toString(orientation)
458  << " for " << derivName << "!"
459  );
460  }
461  return mv;
462 }
463 
464 
465 template<class Scalar>
466 void Thyra::assertDerivSpaces(
467  const std::string &modelEvalDescription,
468  const ModelEvaluatorBase::Derivative<Scalar> &deriv,
469  const std::string &deriv_name,
470  const VectorSpaceBase<Scalar> &fnc_space,
471  const std::string &fnc_space_name,
472  const VectorSpaceBase<Scalar> &var_space,
473  const std::string &var_space_name
474  )
475 {
476  typedef ModelEvaluatorBase MEB;
477  if (!is_null(deriv.getLinearOp())) {
478  const RCP<const LinearOpBase<Scalar> > lo = deriv.getLinearOp();
479  if (!is_null(lo->range())) {
481  modelEvalDescription,
482  *lo->range(), deriv_name + ".range()",
483  fnc_space, fnc_space_name
484  );
486  modelEvalDescription,
487  *lo->domain(), deriv_name + ".domain()",
488  var_space, var_space_name
489  );
490  }
491  }
492  else if(!is_null(deriv.getMultiVector())) {
493  const RCP<const LinearOpBase<Scalar> > mv = deriv.getMultiVector();
494  switch(deriv.getMultiVectorOrientation()) {
495  case MEB::DERIV_MV_BY_COL: {
497  modelEvalDescription,
498  *mv->range(), deriv_name + ".range()",
499  fnc_space, fnc_space_name
500  );
502  modelEvalDescription,
503  *mv->domain(), deriv_name + ".domain()",
504  var_space, var_space_name
505  );
506  break;
507  }
508  case MEB::DERIV_TRANS_MV_BY_ROW: {
510  modelEvalDescription,
511  *mv->range(), deriv_name + "^T.range()",
512  var_space, var_space_name
513  );
515  modelEvalDescription,
516  *mv->domain(), deriv_name + "^T.domain()",
517  fnc_space, fnc_space_name
518  );
519  break;
520  }
521 #ifdef TEUCHOS_DEBUG
522  default:
524 #endif
525  }
526  }
527 }
528 
529 
530 template<class Scalar>
531 void Thyra::assertInArgsOutArgsSetup(
532  const std::string &modelEvalDescription,
533  const ModelEvaluatorBase::InArgs<Scalar> &inArgs,
534  const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
535  )
536 {
537 
538  typedef ModelEvaluatorBase MEB;
539 
540  const int Ng = outArgs.Ng();
541  const int Np = outArgs.Np();
542 
543  // Description
544  TEUCHOS_ASSERT_EQUALITY(inArgs.modelEvalDescription(), modelEvalDescription);
545  TEUCHOS_ASSERT_EQUALITY(outArgs.modelEvalDescription(), modelEvalDescription);
546 
547  // Np
549  inArgs.Np() != outArgs.Np(), std::logic_error,
550  "Error: The underlying model " << modelEvalDescription << " incorrectly\n"
551  "set inArgs.Np() = "<<inArgs.Np()<<" != outArgs.Np() = "
552  <<outArgs.Np()<<"!"
553  );
554 
555  // x_dot
557  inArgs.supports(MEB::IN_ARG_x_dot) && !inArgs.supports(MEB::IN_ARG_x),
558  std::logic_error,
559  "Error: The underlying model " << modelEvalDescription << " supports\n"
560  "x_dot but does not support x!"
561  );
562 
563  // t
565  inArgs.supports(MEB::IN_ARG_x_dot) && !inArgs.supports(MEB::IN_ARG_t),
566  std::logic_error,
567  "Error: The underlying model " << modelEvalDescription << " supports\n"
568  "x_dot but does not support t!"
569  );
570 
571  // W and W_op
573  (
574  ( outArgs.supports(MEB::OUT_ARG_W) || outArgs.supports(MEB::OUT_ARG_W_op) )
575  &&
576  !inArgs.supports(MEB::IN_ARG_x)
577  ),
578  std::logic_error,
579  "Error: The underlying model " << modelEvalDescription << " says that\n"
580  "it supports W and/or W_op but it does not support x!"
581  );
583  (
584  ( outArgs.supports(MEB::OUT_ARG_W) || outArgs.supports(MEB::OUT_ARG_W_op) )
585  &&
586  inArgs.supports(MEB::IN_ARG_x_dot)
587  &&
588  !( inArgs.supports(MEB::IN_ARG_alpha) && inArgs.supports(MEB::IN_ARG_beta) )
589  ),
590  std::logic_error,
591  "Error: The underlying model " << modelEvalDescription << " supports W and/or W_op\n"
592  "and x_dot but it does not support alpha and beta as InArgs! \n"
593  "If the model supports W and x_dot, then it can be interpreted as an implicit \n"
594  "ODE/DAE and therefore D(f)/D(x_dot) must be non-zero and therefore alpha must \n"
595  "be supported. If, however, the model can be interpreted as an explicit ODE \n"
596  "then x_dot should not be supported at all."
597  );
598 
599  for ( int l = 0; l < Np; ++l ) {
600 
601  // DfDp(l): OutArgs checks this automatically!
602 
603  for ( int j = 0; j < Ng; ++j ) {
604 
605  // DgDx_dot(j)
607  ( !outArgs.supports(MEB::OUT_ARG_DgDx_dot,j).none()
608  && !inArgs.supports(MEB::IN_ARG_x_dot) ),
609  std::logic_error,
610  "Error: The underlying model " << modelEvalDescription << " says that\n"
611  "it supports DgDx_dot("<<j<<") but it does not support x_dot!"
612  );
613 
614  // DgDx(j)
616  ( !outArgs.supports(MEB::OUT_ARG_DgDx,j).none()
617  && !inArgs.supports(MEB::IN_ARG_x) ),
618  std::logic_error,
619  "Error: The underlying model " << modelEvalDescription << " says that\n"
620  "it supports DgDx("<<j<<") but it does not support x!"
621  );
622 
623  // DgDp(j,l): OutArgs checks this automatically!
624 
625  }
626 
627  }
628 
629 }
630 
631 
632 template<class Scalar>
633 void Thyra::assertInArgsEvalObjects(
634  const ModelEvaluator<Scalar> &model,
635  const ModelEvaluatorBase::InArgs<Scalar> &inArgs
636  )
637 {
638 
639  typedef ModelEvaluatorBase MEB;
640 
641  const std::string description = model.description();
642  const int Np = inArgs.Np();
643 
644  model.createInArgs().assertSameSupport(inArgs);
645 
646  // x_dot
647  if ( inArgs.supports(MEB::IN_ARG_x_dot) && !is_null(inArgs.get_x_dot()) ) {
649  description, *inArgs.get_x_dot()->space(), *model.get_x_space() );
650  }
651 
652  // x
653  if ( inArgs.supports(MEB::IN_ARG_x) && !is_null(inArgs.get_x()) ) {
655  description, *inArgs.get_x()->space(), *model.get_x_space() );
656  }
657 
658  // p(l)
659  for ( int l = 0; l < Np; ++l ) {
660  if (!is_null(inArgs.get_p(l))) {
662  description, *inArgs.get_p(l)->space(), *model.get_p_space(l) );
663  }
664  }
665 
666 }
667 
668 
669 template<class Scalar>
670 void Thyra::assertOutArgsEvalObjects(
671  const ModelEvaluator<Scalar> &model,
672  const ModelEvaluatorBase::OutArgs<Scalar> &outArgs,
673  const ModelEvaluatorBase::InArgs<Scalar> *inArgs
674  )
675 {
676 
677  typedef ScalarTraits<Scalar> ST;
678  typedef Teuchos::Utils TU;
679  typedef ModelEvaluatorBase MEB;
680 
681  const std::string description = model.description();
682  const int Ng = outArgs.Ng();
683  const int Np = outArgs.Np();
684 
685  if (inArgs) {
686  TEUCHOS_ASSERT_EQUALITY(outArgs.Np(), inArgs->Np());
687  }
688 
689  model.createOutArgs().assertSameSupport(outArgs);
690 
691  // f
692  if ( outArgs.supports(MEB::OUT_ARG_f) && !is_null(outArgs.get_f()) ) {
694  description, *outArgs.get_f()->space(), *model.get_f_space() );
695  }
696 
697  // W
698  if ( outArgs.supports(MEB::OUT_ARG_W) && !is_null(outArgs.get_W()) ) {
699  if (!is_null(outArgs.get_W()->range())) {
701  description, *outArgs.get_W()->range(), *model.get_f_space() );
703  description, *outArgs.get_W()->domain(), *model.get_x_space() );
704  }
705  }
706 
707  // W_op
708  if ( outArgs.supports(MEB::OUT_ARG_W_op) && !is_null(outArgs.get_W_op()) ) {
709  if (!is_null(outArgs.get_W_op()->range())) {
711  description, *outArgs.get_W_op()->range(), *model.get_f_space() );
713  description, *outArgs.get_W_op()->domain(), *model.get_x_space() );
714  }
715  }
716 
717  // alpha and beta (not really in outArgs but can only be validated if W or
718  // W_op is set)
719  if (
720  inArgs
721  &&
722  (
723  ( outArgs.supports(MEB::OUT_ARG_W) && !is_null(outArgs.get_W()) )
724  ||
725  ( outArgs.supports(MEB::OUT_ARG_W_op) && !is_null(outArgs.get_W_op()) )
726  )
727  )
728  {
729  if ( inArgs->supports(MEB::IN_ARG_alpha) && inArgs->supports(MEB::IN_ARG_beta) ) {
730  // 08/25/08 tscoffe: In the block-composed linear operator case for
731  // Rythmos::ImplicitRKModelEvaluator, I need to specify that a given
732  // block is all zeros and I'm depending on the underlying model to
733  // intelligently fill the block with zeros if both alpha and beta are
734  // zero.
735  //TEUCHOS_TEST_FOR_EXCEPT( inArgs->get_alpha() == ST::zero() && inArgs->get_beta() == ST::zero() );
736  }
737  else if ( inArgs->supports(MEB::IN_ARG_beta) ) {
738  TEUCHOS_TEST_FOR_EXCEPT( inArgs->get_beta() == ST::zero() );
739  }
740  }
741 
742  // DfDp(l)
743  if (outArgs.supports(MEB::OUT_ARG_f)) {
744  for ( int l = 0; l < Np; ++l ) {
745  if (!outArgs.supports(MEB::OUT_ARG_DfDp,l).none()) {
747  description,
748  outArgs.get_DfDp(l), "DfDp("+TU::toString(l)+")",
749  *model.get_f_space(), "f_space",
750  *model.get_p_space(l), "p_space("+TU::toString(l)+")"
751  );
752  }
753  }
754  }
755 
756  // g(l)
757  for ( int j = 0; j < Ng; ++j ) {
758  if (!is_null(outArgs.get_g(j))) {
760  description, *outArgs.get_g(j)->space(), *model.get_g_space(j) );
761  }
762  }
763 
764  // DgDx_dot(j)
765  for ( int j = 0; j < Ng; ++j ) {
766  if (!outArgs.supports(MEB::OUT_ARG_DgDx_dot,j).none()) {
768  description,
769  outArgs.get_DgDx_dot(j), "DgDx_dot("+TU::toString(j)+")",
770  *model.get_g_space(j), "g_space("+TU::toString(j)+")",
771  *model.get_x_space(), "x_space"
772  );
773  }
774  }
775 
776  // DgDx(j)
777  for ( int j = 0; j < Ng; ++j ) {
778  if (!outArgs.supports(MEB::OUT_ARG_DgDx,j).none()) {
780  description,
781  outArgs.get_DgDx(j), "DgDx("+TU::toString(j)+")",
782  *model.get_g_space(j), "g_space("+TU::toString(j)+")",
783  *model.get_x_space(), "x_space"
784  );
785  }
786  }
787 
788  // Assert DgDp(j,l)
789  for ( int j = 0; j < Ng; ++j ) {
790  for ( int l = 0; l < Np; ++l ) {
791  if (!outArgs.supports(MEB::OUT_ARG_DgDp,j,l).none()) {
792  const std::string j_str = TU::toString(j);
793  const std::string l_str = TU::toString(l);
795  description,
796  outArgs.get_DgDp(j,l), "DgDp("+j_str+","+l_str+")",
797  *model.get_g_space(j), "g_space("+j_str+")",
798  *model.get_p_space(l), "p_space("+l_str+")"
799  );
800  }
801  }
802  }
803 
804 }
805 
806 
807 template<class Scalar>
808 void Thyra::eval_f(
809  const ModelEvaluator<Scalar> &model
810  ,const VectorBase<Scalar> &x
811  ,VectorBase<Scalar> *f
812  )
813 {
814  typedef ModelEvaluatorBase MEB;
815  MEB::InArgs<Scalar> inArgs = model.createInArgs();
816  MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
817  inArgs.set_x(Teuchos::rcp(&x,false));
818  outArgs.set_f(Teuchos::rcp(f,false));
819  model.evalModel(inArgs,outArgs);
820 }
821 
822 
823 template<class Scalar>
824 void Thyra::eval_f_W(
825  const ModelEvaluator<Scalar> &model
826  ,const VectorBase<Scalar> &x
827  ,VectorBase<Scalar> *f
828  ,LinearOpWithSolveBase<Scalar> *W
829  )
830 {
831 
832  typedef ModelEvaluatorBase MEB;
833 
834  MEB::InArgs<Scalar> inArgs = model.createInArgs();
835  MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
836 
837  inArgs.set_x(Teuchos::rcp(&x,false));
838 
839  if (f) outArgs.set_f(Teuchos::rcp(f,false));
840  if (W) outArgs.set_W(Teuchos::rcp(W,false));
841 
842  model.evalModel(inArgs,outArgs);
843 
844 }
845 
846 
847 template<class Scalar>
848 void Thyra::eval_f(
849  const ModelEvaluator<Scalar> &model
850  ,const VectorBase<Scalar> &x
851  ,const Scalar &t
852  ,VectorBase<Scalar> *f
853  )
854 {
855  typedef ModelEvaluatorBase MEB;
856  MEB::InArgs<Scalar> inArgs = model.createInArgs();
857  MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
858  inArgs.set_x(Teuchos::rcp(&x,false));
859  if(inArgs.supports(MEB::IN_ARG_t)) inArgs.set_t(t);
860  outArgs.set_f(Teuchos::rcp(f,false));
861  model.evalModel(inArgs,outArgs);
862 }
863 
864 
865 template<class Scalar>
866 void Thyra::eval_g(
867  const ModelEvaluator<Scalar> &model,
868  const int l,
869  const VectorBase<Scalar> &p_l,
870  const int j,
871  const Ptr<VectorBase<Scalar> > &g_j
872  )
873 {
874  typedef ModelEvaluatorBase MEB;
875  MEB::InArgs<Scalar> inArgs = model.createInArgs();
876  MEB::OutArgs<Scalar> outArgs= model.createOutArgs();
877  inArgs.set_p(l, Teuchos::rcpFromRef(p_l));
878  outArgs.set_g(j, Teuchos::rcpFromRef(*g_j));
879  model.evalModel(inArgs,outArgs);
880 }
881 
882 
883 template<class Scalar>
884 void Thyra::eval_g(
885  const ModelEvaluator<Scalar> &model,
886  const int l,
887  const VectorBase<Scalar> &p_l,
888  const Scalar &t,
889  const int j,
890  VectorBase<Scalar> *g_j
891  )
892 {
893  typedef ModelEvaluatorBase MEB;
894  MEB::InArgs<Scalar> inArgs = model.createInArgs();
895  MEB::OutArgs<Scalar> outArgs= model.createOutArgs();
896  inArgs.set_p(l,Teuchos::rcp(&p_l,false));
897  inArgs.set_t(t);
898  outArgs.set_g(j,Teuchos::rcp(g_j,false));
899  model.evalModel(inArgs,outArgs);
900 }
901 
902 
903 template<class Scalar>
904 void Thyra::eval_g_DgDp(
905  const ModelEvaluator<Scalar> &model,
906  const int l,
907  const VectorBase<Scalar> &p_l,
908  const int j,
909  const Ptr<VectorBase<Scalar> > &g_j,
910  const ModelEvaluatorBase::Derivative<Scalar> &DgDp_j_l
911  )
912 {
913  typedef ModelEvaluatorBase MEB;
914  MEB::InArgs<Scalar> inArgs = model.createInArgs();
915  MEB::OutArgs<Scalar> outArgs= model.createOutArgs();
916  inArgs.set_p(l, Teuchos::rcpFromRef(p_l));
917  if (!is_null(g_j)) {
918  outArgs.set_g(j, Teuchos::rcpFromPtr(g_j));
919  }
920  if (!DgDp_j_l.isEmpty()) {
921  outArgs.set_DgDp(j, l, DgDp_j_l);
922  }
923  model.evalModel(inArgs,outArgs);
924 }
925 
926 
927 template<class Scalar>
928 void Thyra::eval_f(
929  const ModelEvaluator<Scalar> &model
930  ,const VectorBase<Scalar> &x_dot
931  ,const VectorBase<Scalar> &x
932  ,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
933  ,VectorBase<Scalar> *f
934  )
935 {
936 
937  typedef ModelEvaluatorBase MEB;
938 
939  MEB::InArgs<Scalar> inArgs = model.createInArgs();
940  MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
941 
942  inArgs.set_x_dot(Teuchos::rcp(&x_dot,false));
943  inArgs.set_x(Teuchos::rcp(&x,false));
944  if(inArgs.supports(MEB::IN_ARG_t))
945  inArgs.set_t(t);
946 
947  outArgs.set_f(Teuchos::rcp(f,false));
948 
949  model.evalModel(inArgs,outArgs);
950 
951 }
952 
953 
954 template<class Scalar>
955 void Thyra::eval_f_W(
956  const ModelEvaluator<Scalar> &model
957  ,const VectorBase<Scalar> &x_dot
958  ,const VectorBase<Scalar> &x
959  ,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
960  ,const Scalar &alpha
961  ,const Scalar &beta
962  ,VectorBase<Scalar> *f
963  ,LinearOpWithSolveBase<Scalar> *W
964  )
965 {
966 
967  typedef ModelEvaluatorBase MEB;
968 
969  MEB::InArgs<Scalar> inArgs = model.createInArgs();
970  MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
971 
972  inArgs.set_x_dot(Teuchos::rcp(&x_dot,false));
973  inArgs.set_x(Teuchos::rcp(&x,false));
974  if(inArgs.supports(MEB::IN_ARG_t))
975  inArgs.set_t(t);
976  inArgs.set_alpha(alpha);
977  inArgs.set_beta(beta);
978 
979  if(f) outArgs.set_f(Teuchos::rcp(f,false));
980  if(W) outArgs.set_W(Teuchos::rcp(W,false));
981 
982  model.evalModel(inArgs,outArgs);
983 
984 }
985 
986 
987 #ifdef HAVE_THYRA_ME_POLYNOMIAL
988 
989 
990 template<class Scalar>
991 void Thyra::eval_f_poly(
992  const ModelEvaluator<Scalar> &model
993  ,const Teuchos::Polynomial< VectorBase<Scalar> > &x_poly
994  ,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
995  ,Teuchos::Polynomial< VectorBase<Scalar> > *f_poly
996  )
997 {
998 
999  typedef ModelEvaluatorBase MEB;
1000 
1001  MEB::InArgs<Scalar> inArgs = model.createInArgs();
1002  MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
1003 
1004  inArgs.set_x_poly(Teuchos::rcp(&x_poly,false));
1005  if(inArgs.supports(MEB::IN_ARG_t))
1006  inArgs.set_t(t);
1007 
1008  outArgs.set_f_poly(Teuchos::rcp(f_poly,false));
1009 
1010  model.evalModel(inArgs,outArgs);
1011 
1012 }
1013 
1014 
1015 template<class Scalar>
1016 void Thyra::eval_f_poly(
1017  const ModelEvaluator<Scalar> &model
1018  ,const Teuchos::Polynomial< VectorBase<Scalar> > &x_dot_poly
1019  ,const VectorBase<Scalar> &x_poly
1020  ,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
1021  ,Teuchos::Polynomial< VectorBase<Scalar> > *f_poly
1022  )
1023 {
1024 
1025  typedef ModelEvaluatorBase MEB;
1026 
1027  MEB::InArgs<Scalar> inArgs = model.createInArgs();
1028  MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
1029 
1030  inArgs.set_x_dot_poly(Teuchos::rcp(&x_dot_poly,false));
1031  inArgs.set_x_poly(Teuchos::rcp(&x_poly,false));
1032  if(inArgs.supports(MEB::IN_ARG_t))
1033  inArgs.set_t(t);
1034 
1035  outArgs.set_f_poly(Teuchos::rcp(f_poly,false));
1036 
1037  model.evalModel(inArgs,outArgs);
1038 
1039 }
1040 
1041 
1042 #endif // HAVE_THYRA_ME_POLYNOMIAL
1043 
1044 
1045 #endif // THYRA_MODEL_EVALUATOR_HELPERS_HPP
#define THYRA_ASSERT_VEC_SPACES(FUNC_NAME, VS1, VS2)
This is a very useful macro that should be used to validate that two vector spaces are compatible...
bool is_null(const boost::shared_ptr< T > &p)
std::string toString(ModelEvaluatorBase::EInArgsMembers)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Simple aggregate class that stores a derivative object as a general linear operator or as a multi-vec...
Simple aggregate class for a derivative object represented as a column-wise multi-vector or its trans...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
TEUCHOSCORE_LIB_DLL_EXPORT std::string toString(const EVerbosityLevel verbLevel)
ModelEvaluatorBase::DerivativeMultiVector< Scalar > create_DgDx_dot_mv(const ModelEvaluator< Scalar > &model, int j, ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation)
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
void assertDerivSpaces(const std::string &modelEvalDescription, const ModelEvaluatorBase::Derivative< Scalar > &deriv, const std::string &deriv_name, const VectorSpaceBase< Scalar > &fnc_space, const std::string &fnc_space_name, const VectorSpaceBase< Scalar > &var_space, const std::string &var_space_name)
Assert that that Thyra objects imbedded in a Derivative object matches its function and variable spac...
#define THYRA_ASSERT_VEC_SPACES_NAMES(FUNC_NAME, VS1, VS1_NAME, VS2, VS2_NAME)
Helper assertion macro.
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
RCP< MultiVectorBase< Scalar > > createMembers(const RCP< const VectorSpaceBase< Scalar > > &vs, int numMembers, const std::string &label="")
Create a set of vector members (a MultiVectorBase) from the vector space.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)