EpetraExt  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EpetraExt_ModelEvaluator.cpp
Go to the documentation of this file.
1 //@HEADER
2 // ***********************************************************************
3 //
4 // EpetraExt: Epetra Extended - Linear Algebra Services Package
5 // Copyright (2011) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
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 Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 
43 #include "Teuchos_implicit_cast.hpp"
44 
45 
46 namespace EpetraExt {
47 
48 
49 //
50 // ModelEvaluator::InArgs
51 //
52 
53 
55  :modelEvalDescription_("WARNING! THIS INARGS OBJECT IS UNINITALIZED!")
56 {
57  std::fill_n(&supports_[0],NUM_E_IN_ARGS_MEMBERS,false);
58  t_ = 0.0;
59  alpha_ = 0.0;
60  beta_ = 0.0;
61 }
62 
63 
65 {
66  TEUCHOS_TEST_FOR_EXCEPTION(
67  int(arg)>=NUM_E_IN_ARGS_MEMBERS || int(arg) < 0,std::logic_error
68  ,"model = \'"<<modelEvalDescription_<<"\': Error, arg="<<toString(arg)<<" is invalid!"
69  );
70  return supports_[arg];
71 }
72 
74 {
75  assert_l(l);
76  return supports_p_sg_[l];
77 }
78 
80 {
81  assert_l(l);
82  return supports_p_mp_[l];
83 }
84 
86 {
87  TEUCHOS_TEST_FOR_EXCEPTION(
88  int(arg)>=NUM_E_IN_ARGS_MEMBERS || int(arg) < 0,std::logic_error
89  ,"model = \'"<<modelEvalDescription_<<"\':Error, arg="<<toString(arg)<<" is invalid!"
90  );
91  supports_[arg] = supports;
92 }
93 
94 void ModelEvaluator::InArgs::_setSupports(EInArgs_p_sg arg, int l, bool supports)
95 {
96  assert_l(l);
97  supports_p_sg_[l] = supports;
98 }
99 
100 void ModelEvaluator::InArgs::_setSupports(EInArgs_p_mp arg, int l, bool supports)
101 {
102  assert_l(l);
103  supports_p_mp_[l] = supports;
104 }
105 
106 
107 void ModelEvaluator::InArgs::assert_supports(EInArgsMembers arg) const
108 {
109  TEUCHOS_TEST_FOR_EXCEPTION(
110  !supports_[arg], std::logic_error
111  ,"EpetraExt::ModelEvaluator::InArgs::assert_supports(arg): model = \'"<<modelEvalDescription_<<"\': Error, "
112  "The argument arg = " << toString(arg) << " is not supported!"
113  );
114 }
115 
116 void ModelEvaluator::InArgs::assert_supports(EInArgs_p_sg arg, int l) const
117 {
118  assert_l(l);
119  TEUCHOS_TEST_FOR_EXCEPTION(
120  !supports_p_sg_[l], std::logic_error
121  ,"EpetraExt::ModelEvaluator::InArgs::assert_supports(IN_ARG_p_sg,l): "
122  "model = \'"<<modelEvalDescription_<<"\': Error,"
123  "The argument p_sg(l) with index l = " << l << " is not supported!"
124  );
125 }
126 
127 void ModelEvaluator::InArgs::assert_supports(EInArgs_p_mp arg, int l) const
128 {
129  assert_l(l);
130  TEUCHOS_TEST_FOR_EXCEPTION(
131  !supports_p_mp_[l], std::logic_error
132  ,"EpetraExt::ModelEvaluator::InArgs::assert_supports(IN_ARG_p_mp,l): "
133  "model = \'"<<modelEvalDescription_<<"\': Error,"
134  "The argument p_mp(l) with index l = " << l << " is not supported!"
135  );
136 }
137 
138 
139 void ModelEvaluator::InArgs::assert_l(int l) const
140 {
141  TEUCHOS_TEST_FOR_EXCEPTION(
142  !( 0 <= l && l < Np() ), std::logic_error
143  ,"EpetraExt::ModelEvaluator::InArgs::assert_l(l): model = \'"<<modelEvalDescription_<<"\': Error, "
144  "The parameter l = " << l << " is not in the range [0,"<<Np()-1<<"]!"
145  );
146 }
147 
148 
149 //
150 // ModelEvaluator::OutArgs
151 //
152 
153 
155  :modelEvalDescription_("WARNING! THIS OUTARGS OBJECT IS UNINITALIZED!"),
156  isFailed_( false )
157 {
158  std::fill_n(&supports_[0],NUM_E_OUT_ARGS_MEMBERS,false);
159 }
160 
161 
163 {
164  TEUCHOS_TEST_FOR_EXCEPTION(
165  int(arg)>=NUM_E_OUT_ARGS_MEMBERS || int(arg) < 0,std::logic_error
166  ,"model = \'"<<modelEvalDescription_<<"\': Error, arg="<<toString(arg)<<" is invalid!"
167  );
168  return supports_[arg];
169 }
170 
171 
174 {
175  assert_l(l);
176  return supports_DfDp_[l];
177 }
178 
179 
182 {
183  assert_j(j);
184  return supports_DgDx_dot_[j];
185 }
186 
187 
190 {
191  assert_j(j);
192  return supports_DgDx_[j];
193 }
194 
195 
198 {
199  assert_j(j);
200  assert_l(l);
201  return supports_DgDp_[ j*Np() + l ];
202 }
203 
205 {
206  assert_j(j);
207  return supports_g_sg_[j];
208 }
209 
212 {
213  assert_l(l);
214  return supports_DfDp_sg_[l];
215 }
216 
217 
220 {
221  assert_j(j);
222  return supports_DgDx_dot_sg_[j];
223 }
224 
225 
228 {
229  assert_j(j);
230  return supports_DgDx_sg_[j];
231 }
232 
235 {
236  assert_j(j);
237  assert_l(l);
238  return supports_DgDp_sg_[ j*Np() + l ];
239 }
240 
242 {
243  assert_j(j);
244  return supports_g_mp_[j];
245 }
246 
249 {
250  assert_l(l);
251  return supports_DfDp_mp_[l];
252 }
253 
254 
257 {
258  assert_j(j);
259  return supports_DgDx_dot_mp_[j];
260 }
261 
262 
265 {
266  assert_j(j);
267  return supports_DgDx_mp_[j];
268 }
269 
272 {
273  assert_j(j);
274  assert_l(l);
275  return supports_DgDp_mp_[ j*Np() + l ];
276 }
277 
278 
280 {
281  using Teuchos::implicit_cast;
282  bool areSet = false;
283  switch(arg) {
284  case OUT_ARG_f: {
285  if (!is_null(f_)) areSet = true;
286  if (!is_null(W_)) areSet = true;
287  for ( int l = 0; l < implicit_cast<int>(DfDp_.size()); ++l )
288  if(!DfDp_[l].isEmpty()) areSet = true;
289  break;
290  }
291  default:
292  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
293  "ModelEvaluator::OutArgs::funcOrDerivesAreSet(arg): Error, we can not handle"
294  " the argument " << toString(arg) << "yet!");
295  }
296  return areSet;
297 }
298 
300 {
301  isFailed_ = true;
302  // TODO: Set objects to NaN?
303 }
304 
306 {
307  return isFailed_;
308 }
309 
310 
311 void ModelEvaluator::OutArgs::_setModelEvalDescription( const std::string &modelEvalDescription )
312 {
313  modelEvalDescription_ = modelEvalDescription;
314 }
315 
316 
318 {
319  if(Np) {
320  supports_DfDp_.resize(Np);
321  DfDp_.resize(Np);
322  std::fill_n(DfDp_.begin(),Np,Derivative());
323  DfDp_properties_.resize(Np);
324  std::fill_n(DfDp_properties_.begin(),Np,DerivativeProperties());
325 
326  supports_DfDp_sg_.resize(Np);
327  DfDp_sg_.resize(Np);
328  std::fill_n(DfDp_sg_.begin(),Np,SGDerivative());
329  DfDp_sg_properties_.resize(Np);
330  std::fill_n(DfDp_sg_properties_.begin(),Np,DerivativeProperties());
331 
332  supports_DfDp_mp_.resize(Np);
333  DfDp_mp_.resize(Np);
334  std::fill_n(DfDp_mp_.begin(),Np,MPDerivative());
335  DfDp_mp_properties_.resize(Np);
336  std::fill_n(DfDp_mp_properties_.begin(),Np,DerivativeProperties());
337  }
338  if(Ng) {
339  g_.resize(Ng);
340  supports_DgDx_dot_.resize(Ng);
341  DgDx_dot_.resize(Ng);
342  std::fill_n(DgDx_dot_.begin(),Ng,Derivative());
343  DgDx_dot_properties_.resize(Ng);
344  std::fill_n(DgDx_dot_properties_.begin(),Ng,DerivativeProperties());
345  supports_DgDx_.resize(Ng);
346  DgDx_.resize(Ng);
347  std::fill_n(DgDx_.begin(),Ng,Derivative());
348  DgDx_properties_.resize(Ng);
349  std::fill_n(DgDx_properties_.begin(),Ng,DerivativeProperties());
350 
351  g_sg_.resize(Ng);
352  supports_g_sg_.resize(Ng);
353  supports_DgDx_dot_sg_.resize(Ng);
354  DgDx_dot_sg_.resize(Ng);
355  std::fill_n(DgDx_dot_sg_.begin(),Ng,SGDerivative());
356  DgDx_dot_sg_properties_.resize(Ng);
357  std::fill_n(DgDx_dot_sg_properties_.begin(),Ng,DerivativeProperties());
358  supports_DgDx_sg_.resize(Ng);
359  DgDx_sg_.resize(Ng);
360  std::fill_n(DgDx_sg_.begin(),Ng,SGDerivative());
361  DgDx_sg_properties_.resize(Ng);
362  std::fill_n(DgDx_sg_properties_.begin(),Ng,DerivativeProperties());
363 
364  g_mp_.resize(Ng);
365  supports_g_mp_.resize(Ng);
366  supports_DgDx_dot_mp_.resize(Ng);
367  DgDx_dot_mp_.resize(Ng);
368  std::fill_n(DgDx_dot_mp_.begin(),Ng,MPDerivative());
369  DgDx_dot_mp_properties_.resize(Ng);
370  std::fill_n(DgDx_dot_mp_properties_.begin(),Ng,DerivativeProperties());
371  supports_DgDx_mp_.resize(Ng);
372  DgDx_mp_.resize(Ng);
373  std::fill_n(DgDx_mp_.begin(),Ng,MPDerivative());
374  DgDx_mp_properties_.resize(Ng);
375  std::fill_n(DgDx_mp_properties_.begin(),Ng,DerivativeProperties());
376  }
377  if(Np && Ng) {
378  const int NpNg = Np*Ng;
379  supports_DgDp_.resize(NpNg);
380  DgDp_.resize(NpNg);
381  std::fill_n(DgDp_.begin(),NpNg,Derivative());
382  DgDp_properties_.resize(NpNg);
383  std::fill_n(DgDp_properties_.begin(),NpNg,DerivativeProperties());
384 
385  supports_DgDp_sg_.resize(NpNg);
386  DgDp_sg_.resize(NpNg);
387  std::fill_n(DgDp_sg_.begin(),NpNg,SGDerivative());
388  DgDp_sg_properties_.resize(NpNg);
389  std::fill_n(DgDp_sg_properties_.begin(),NpNg,DerivativeProperties());
390 
391  supports_DgDp_mp_.resize(NpNg);
392  DgDp_mp_.resize(NpNg);
393  std::fill_n(DgDp_mp_.begin(),NpNg,MPDerivative());
394  DgDp_mp_properties_.resize(NpNg);
395  std::fill_n(DgDp_mp_properties_.begin(),NpNg,DerivativeProperties());
396  }
397 }
398 
400 {
401  TEUCHOS_TEST_FOR_EXCEPTION(
402  int(arg)>=NUM_E_OUT_ARGS_MEMBERS || int(arg) < 0,std::logic_error
403  ,"model = \'"<<modelEvalDescription_<<"\': Error, arg="<<toString(arg)<<" is invalid!"
404  );
405  supports_[arg] = supports;
406 }
407 
408 
410 {
411  assert_l(l);
412  supports_DfDp_[l] = supports;
413 }
414 
415 
417 {
418  assert_j(j);
419  supports_DgDx_dot_[j] = supports;
420 }
421 
422 
424 {
425  assert_j(j);
426  supports_DgDx_[j] = supports;
427 }
428 
429 
430 void ModelEvaluator::OutArgs::_setSupports( EOutArgsDgDp arg, int j, int l, const DerivativeSupport& supports )
431 {
432  assert_j(j);
433  assert_l(l);
434  supports_DgDp_[ j*Np() + l ] = supports;
435 }
436 
437 void ModelEvaluator::OutArgs::_setSupports( EOutArgs_g_sg arg, int j, bool supports )
438 {
439  assert_j(j);
440  supports_g_sg_[j] = supports;
441 }
442 
444 {
445  assert_l(l);
446  supports_DfDp_sg_[l] = supports;
447 }
448 
449 
451 {
452  assert_j(j);
453  supports_DgDx_dot_sg_[j] = supports;
454 }
455 
456 
458 {
459  assert_j(j);
460  supports_DgDx_sg_[j] = supports;
461 }
462 
464 {
465  assert_j(j);
466  assert_l(l);
467  supports_DgDp_sg_[ j*Np() + l ] = supports;
468 }
469 
470 void ModelEvaluator::OutArgs::_setSupports( EOutArgs_g_mp arg, int j, bool supports )
471 {
472  assert_j(j);
473  supports_g_mp_[j] = supports;
474 }
475 
477 {
478  assert_l(l);
479  supports_DfDp_mp_[l] = supports;
480 }
481 
482 
484 {
485  assert_j(j);
486  supports_DgDx_dot_mp_[j] = supports;
487 }
488 
489 
491 {
492  assert_j(j);
493  supports_DgDx_mp_[j] = supports;
494 }
495 
497 {
498  assert_j(j);
499  assert_l(l);
500  supports_DgDp_mp_[ j*Np() + l ] = supports;
501 }
502 
503 
505 {
506  W_properties_ = W_properties;
507 }
508 
510 {
511  WPrec_properties_ = WPrec_properties;
512 }
513 
515 {
516  assert_supports(OUT_ARG_DfDp,l);
517  DfDp_properties_[l] = properties;
518 }
519 
520 
522 {
523  assert_supports(OUT_ARG_DgDx_dot,j);
524  DgDx_dot_properties_[j] = properties;
525 }
526 
527 
529 {
530  assert_supports(OUT_ARG_DgDx,j);
531  DgDx_properties_[j] = properties;
532 }
533 
534 
536 {
537  assert_supports(OUT_ARG_DgDp,j,l);
538  DgDp_properties_[ j*Np() + l ] = properties;
539 }
540 
542 {
543  assert_supports(OUT_ARG_DfDp_sg,l);
544  DfDp_sg_properties_[l] = properties;
545 }
546 
547 
549 {
550  assert_supports(OUT_ARG_DgDx_dot_sg,j);
551  DgDx_dot_sg_properties_[j] = properties;
552 }
553 
554 
556 {
557  assert_supports(OUT_ARG_DgDx_sg,j);
558  DgDx_sg_properties_[j] = properties;
559 }
560 
562 {
563  assert_supports(OUT_ARG_DgDp_sg,j,l);
564  DgDp_sg_properties_[ j*Np() + l ] = properties;
565 }
566 
567 
569 {
570  assert_supports(OUT_ARG_DfDp_mp,l);
571  DfDp_mp_properties_[l] = properties;
572 }
573 
574 
576 {
577  assert_supports(OUT_ARG_DgDx_dot_mp,j);
578  DgDx_dot_mp_properties_[j] = properties;
579 }
580 
581 
583 {
584  assert_supports(OUT_ARG_DgDx_mp,j);
585  DgDx_mp_properties_[j] = properties;
586 }
587 
589 {
590  assert_supports(OUT_ARG_DgDp_mp,j,l);
591  DgDp_mp_properties_[ j*Np() + l ] = properties;
592 }
593 
594 
595 void ModelEvaluator::OutArgs::assert_supports(EOutArgsMembers arg) const
596 {
597  TEUCHOS_TEST_FOR_EXCEPTION(
598  !supports_[arg], std::logic_error
599  ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(arg): "
600  "model = \'"<<modelEvalDescription_<<"\': Error, "
601  "The argument arg = " << toString(arg) << " is not supported!"
602  );
603 }
604 
605 
606 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDfDp arg, int l) const
607 {
608  assert_l(l);
609  TEUCHOS_TEST_FOR_EXCEPTION(
610  supports_DfDp_[l].none(), std::logic_error
611  ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DfDp,l): "
612  "model = \'"<<modelEvalDescription_<<"\': Error,"
613  "The argument DfDp(l) with index l = " << l << " is not supported!"
614  );
615 }
616 
617 
618 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDgDx_dot arg, int j) const
619 {
620  assert_j(j);
621  TEUCHOS_TEST_FOR_EXCEPTION(
622  supports_DgDx_dot_[j].none(), std::logic_error
623  ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DgDx_dot,j): "
624  "model = \'"<<modelEvalDescription_<<"\': Error,"
625  "The argument DgDx_dot(j) with index j = " << j << " is not supported!"
626  );
627 }
628 
629 
630 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDgDx arg, int j) const
631 {
632  assert_j(j);
633  TEUCHOS_TEST_FOR_EXCEPTION(
634  supports_DgDx_[j].none(), std::logic_error
635  ,"TEpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DgDx,j): "
636  "model = \'"<<modelEvalDescription_<<"\': Error,"
637  "The argument DgDx(j) with index j = " << j << " is not supported!"
638  );
639 }
640 
641 
642 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDgDp arg, int j, int l) const
643 {
644  assert_j(j);
645  assert_l(l);
646  TEUCHOS_TEST_FOR_EXCEPTION(
647  supports_DgDp_[ j*Np() + l ].none(), std::logic_error
648  ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DgDp,j,l): "
649  "model = \'"<<modelEvalDescription_<<"\': Error,"
650  "The argument DgDp(j,l) with indexes j = " << j << " and l = " << l << " is not supported!"
651  );
652 }
653 
654 void ModelEvaluator::OutArgs::assert_supports(EOutArgs_g_sg arg, int j) const
655 {
656  assert_j(j);
657  TEUCHOS_TEST_FOR_EXCEPTION(
658  !supports_g_sg_[j], std::logic_error
659  ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_g_sg,j): "
660  "model = \'"<<modelEvalDescription_<<"\': Error,"
661  "The argument g_sg(j) with index j = " << j << " is not supported!"
662  );
663 }
664 
665 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDfDp_sg arg, int l) const
666 {
667  assert_l(l);
668  TEUCHOS_TEST_FOR_EXCEPTION(
669  supports_DfDp_sg_[l].none(), std::logic_error
670  ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DfDp_sg,l): "
671  "model = \'"<<modelEvalDescription_<<"\': Error,"
672  "The argument DfDp_sg(l) with index l = " << l << " is not supported!"
673  );
674 }
675 
676 
677 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDgDx_dot_sg arg, int j) const
678 {
679  assert_j(j);
680  TEUCHOS_TEST_FOR_EXCEPTION(
681  supports_DgDx_dot_sg_[j].none(), std::logic_error
682  ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DgDx_dot_sg,j): "
683  "model = \'"<<modelEvalDescription_<<"\': Error,"
684  "The argument DgDx_dot_sg(j) with index j = " << j << " is not supported!"
685  );
686 }
687 
688 
689 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDgDx_sg arg, int j) const
690 {
691  assert_j(j);
692  TEUCHOS_TEST_FOR_EXCEPTION(
693  supports_DgDx_sg_[j].none(), std::logic_error
694  ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DgDx_sg,j): "
695  "model = \'"<<modelEvalDescription_<<"\': Error,"
696  "The argument DgDx_sg(j) with index j = " << j << " is not supported!"
697  );
698 }
699 
700 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDgDp_sg arg, int j, int l) const
701 {
702  assert_j(j);
703  assert_l(l);
704  TEUCHOS_TEST_FOR_EXCEPTION(
705  supports_DgDp_sg_[ j*Np() + l ].none(), std::logic_error
706  ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DgDp_sg,j,l): "
707  "model = \'"<<modelEvalDescription_<<"\': Error,"
708  "The argument DgDp_sg(j,l) with indexes j = " << j << " and l = " << l << " is not supported!"
709  );
710 }
711 
712 void ModelEvaluator::OutArgs::assert_supports(EOutArgs_g_mp arg, int j) const
713 {
714  assert_j(j);
715  TEUCHOS_TEST_FOR_EXCEPTION(
716  !supports_g_mp_[j], std::logic_error
717  ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_g_mp,j): "
718  "model = \'"<<modelEvalDescription_<<"\': Error,"
719  "The argument g_mp(j) with index j = " << j << " is not supported!"
720  );
721 }
722 
723 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDfDp_mp arg, int l) const
724 {
725  assert_l(l);
726  TEUCHOS_TEST_FOR_EXCEPTION(
727  supports_DfDp_mp_[l].none(), std::logic_error
728  ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DfDp_mp,l): "
729  "model = \'"<<modelEvalDescription_<<"\': Error,"
730  "The argument DfDp_mp(l) with index l = " << l << " is not supported!"
731  );
732 }
733 
734 
735 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDgDx_dot_mp arg, int j) const
736 {
737  assert_j(j);
738  TEUCHOS_TEST_FOR_EXCEPTION(
739  supports_DgDx_dot_mp_[j].none(), std::logic_error
740  ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DgDx_dot_mp,j): "
741  "model = \'"<<modelEvalDescription_<<"\': Error,"
742  "The argument DgDx_dot_mp(j) with index j = " << j << " is not supported!"
743  );
744 }
745 
746 
747 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDgDx_mp arg, int j) const
748 {
749  assert_j(j);
750  TEUCHOS_TEST_FOR_EXCEPTION(
751  supports_DgDx_mp_[j].none(), std::logic_error
752  ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DgDx_mp,j): "
753  "model = \'"<<modelEvalDescription_<<"\': Error,"
754  "The argument DgDx_mp(j) with index j = " << j << " is not supported!"
755  );
756 }
757 
758 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDgDp_mp arg, int j, int l) const
759 {
760  assert_j(j);
761  assert_l(l);
762  TEUCHOS_TEST_FOR_EXCEPTION(
763  supports_DgDp_mp_[ j*Np() + l ].none(), std::logic_error
764  ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DgDp_mp,j,l): "
765  "model = \'"<<modelEvalDescription_<<"\': Error,"
766  "The argument DgDp_mp(j,l) with indexes j = " << j << " and l = " << l << " is not supported!"
767  );
768 }
769 
770 
771 void ModelEvaluator::OutArgs::assert_l(int l) const
772 {
773  TEUCHOS_TEST_FOR_EXCEPTION(
774  Np()==0, std::logic_error
775  ,"EpetraExt::ModelEvaluator::OutArgs::assert_l(l): model = \'"<<modelEvalDescription_<<"\': Error, "
776  "no auxiliary parameters subvectors p(l) are supported!!"
777  );
778  TEUCHOS_TEST_FOR_EXCEPTION(
779  !( 0 <= l && l < Np() ), std::logic_error
780  ,"EpetraExt::ModelEvaluator::OutArgs::assert_l(l): "
781  "model = \'"<<modelEvalDescription_<<"\': Error, "
782  "The parameter subvector p(l) index l = " << l << " is not in the range [0,"<<Np()-1<<"]!"
783  );
784 }
785 
786 
787 void ModelEvaluator::OutArgs::assert_j(int j) const
788 {
789  TEUCHOS_TEST_FOR_EXCEPTION(
790  Ng()==0, std::logic_error
791  ,"EpetraExt::ModelEvaluator::OutArgs::assert_j(j): model = \'"<<modelEvalDescription_<<"\': Error, "
792  "no auxiliary functions g(j) are supported!!"
793  );
794  TEUCHOS_TEST_FOR_EXCEPTION(
795  !( 0 <= j && j < Ng() ), std::logic_error
796  ,"EpetraExt::ModelEvaluator::OutArgs::assert_j(j): model = \'"<<modelEvalDescription_<<"\': Error, "
797  "The auxiliary function g(j) index j = " << j << " is not in the range [0,"<<Ng()-1<<"]!"
798  );
799 }
800 
801 
802 //
803 // ModelEvaluator
804 //
805 
806 
807 // Destructor
808 
809 
811 {}
812 
813 
814 // Vector maps
815 
816 
817 Teuchos::RefCountPtr<const Epetra_Map>
819 { return Teuchos::null; }
820 
821 Teuchos::RefCountPtr<const Teuchos::Array<std::string> >
823 { return Teuchos::null; }
824 
825 Teuchos::RefCountPtr<const Epetra_Map>
827 { return Teuchos::null; }
828 
829 
830 // Initial guesses for variables/parameters
831 
832 
833 Teuchos::RefCountPtr<const Epetra_Vector>
835 { return Teuchos::null; }
836 
837 Teuchos::RefCountPtr<const Epetra_Vector>
839 { return Teuchos::null; }
840 
841 Teuchos::RefCountPtr<const Epetra_Vector>
843 { return Teuchos::null; }
844 
846 { return 0.0; }
847 
848 
849 // Bounds for variables/parameters
850 
851 
853 {
854  return 1e+50;
855 }
856 
857 
858 Teuchos::RefCountPtr<const Epetra_Vector>
860 { return Teuchos::null; }
861 
862 
863 Teuchos::RefCountPtr<const Epetra_Vector>
865 { return Teuchos::null; }
866 
867 
868 Teuchos::RefCountPtr<const Epetra_Vector>
870 { return Teuchos::null; }
871 
872 
873 Teuchos::RefCountPtr<const Epetra_Vector>
875 { return Teuchos::null; }
876 
877 
879 { return 0.0; }
880 
881 
883 { return 0.0; }
884 
885 
886 // Factory functions for creating derivative objects
887 
888 
889 Teuchos::RefCountPtr<Epetra_Operator>
891 { return Teuchos::null; }
892 
893 Teuchos::RefCountPtr<EpetraExt::ModelEvaluator::Preconditioner>
895 { return Teuchos::null; }
896 
897 Teuchos::RefCountPtr<Epetra_Operator>
899 { return Teuchos::null; }
900 
901 Teuchos::RefCountPtr<Epetra_Operator>
903 { return Teuchos::null; }
904 
905 Teuchos::RefCountPtr<Epetra_Operator>
907 { return Teuchos::null; }
908 
909 Teuchos::RefCountPtr<Epetra_Operator>
910 ModelEvaluator::create_DgDp_op( int j, int l ) const
911 { return Teuchos::null; }
912 
913 } // namespace EpetraExt
914 
915 
916 //
917 // Helper functions
918 //
919 
920 
923  )
924 {
925  switch(orientation) {
927  return "DERIV_MV_BY_COL";
929  return "DERIV_TRANS_MV_BY_ROW";
930  default:
931  TEUCHOS_TEST_FOR_EXCEPT(true);
932  }
933  return ""; // Should never be called
934 }
935 
936 
938 {
939  switch(inArg) {
941  return "IN_ARG_x_dot";
943  return "IN_ARG_x";
945  return "IN_ARG_x_dot_poly";
947  return "IN_ARG_x_poly";
949  return "IN_ARG_x_dot_sg";
951  return "IN_ARG_x_sg";
953  return "IN_ARG_x_dot_mp";
955  return "IN_ARG_x_mp";
957  return "IN_ARG_t";
959  return "IN_ARG_alpha";
961  return "IN_ARG_beta";
962  default:
963  TEUCHOS_TEST_FOR_EXCEPT("Invalid inArg!");
964  }
965  return ""; // Will never be executed!
966 }
967 
968 
970 {
971  switch(outArg) {
973  return "OUT_ARG_f";
975  return "OUT_ARG_W";
977  return "OUT_ARG_WPrec";
979  return "OUT_ARG_f_poly";
981  return "OUT_ARG_f_sg";
983  return "OUT_ARG_W_sg";
985  return "OUT_ARG_f_mp";
987  return "OUT_ARG_W_mp";
988  default:
989  TEUCHOS_TEST_FOR_EXCEPT("Invalid outArg!");
990  }
991  return ""; // Will never be executed!
992 }
993 
994 
995 Teuchos::RefCountPtr<Epetra_Operator>
997  const std::string &modelEvalDescription,
998  const ModelEvaluator::Derivative &deriv,
999  const std::string &derivName
1000  )
1001 {
1002  TEUCHOS_TEST_FOR_EXCEPTION(
1003  deriv.getMultiVector().get() != NULL, std::logic_error
1004  ,"For model \'" << modelEvalDescription << "\' the derivative \'"
1005  << derivName << "\' is of type Epetra_MultiVector and not of type Epetra_Operator!"
1006  );
1007  return deriv.getLinearOp();
1008 }
1009 
1010 
1011 Teuchos::RefCountPtr<Epetra_MultiVector>
1013  const std::string &modelEvalDescription,
1014  const ModelEvaluator::Derivative &deriv,
1015  const std::string &derivName,
1017  )
1018 {
1019  TEUCHOS_TEST_FOR_EXCEPTION(
1020  deriv.getLinearOp().get() != NULL, std::logic_error
1021  ,"For model \'" << modelEvalDescription << "\' the derivative \'"
1022  << derivName << "\' is of type Epetra_Operator and not of type Epetra_MultiVector!"
1023  );
1024  Teuchos::RefCountPtr<Epetra_MultiVector>
1025  mv = deriv.getMultiVector();
1026  if(mv.get()) {
1027  TEUCHOS_TEST_FOR_EXCEPTION(
1028  deriv.getMultiVectorOrientation()!=mvOrientation, std::logic_error
1029  ,"For model \'" << modelEvalDescription << "\' the derivative \'"
1030  << derivName << "\' if not the orientation \'" << toString(mvOrientation)
1031  << "\'"
1032  );
1033  }
1034  return mv;
1035 }
1036 
1037 
1038 Teuchos::RefCountPtr<Epetra_Operator>
1040  const int l,
1041  const ModelEvaluator::OutArgs &outArgs
1042  )
1043 {
1044  std::ostringstream derivName; derivName << "DfDp("<<l<<")";
1045  return getLinearOp(
1046  outArgs.modelEvalDescription()
1047  ,outArgs.get_DfDp(l)
1048  ,derivName.str()
1049  );
1050 }
1051 
1052 
1053 Teuchos::RefCountPtr<Epetra_MultiVector>
1055  const int l,
1056  const ModelEvaluator::OutArgs &outArgs
1057  )
1058 {
1059  std::ostringstream derivName; derivName << "DfDp("<<l<<")";
1060  return getMultiVector(
1061  outArgs.modelEvalDescription()
1062  ,outArgs.get_DfDp(l)
1063  ,derivName.str()
1065  );
1066 }
1067 
1068 
1069 Teuchos::RefCountPtr<Epetra_MultiVector>
1071  const int j,
1072  const ModelEvaluator::OutArgs &outArgs,
1074  )
1075 {
1076  std::ostringstream derivName; derivName << "DgDx_dot("<<j<<")";
1077  return getMultiVector(
1078  outArgs.modelEvalDescription(),
1079  outArgs.get_DgDx_dot(j),
1080  derivName.str(),
1081  mvOrientation
1082  );
1083 }
1084 
1085 
1086 Teuchos::RefCountPtr<Epetra_MultiVector>
1088  const int j,
1089  const ModelEvaluator::OutArgs &outArgs,
1091  )
1092 {
1093  std::ostringstream derivName; derivName << "DgDx("<<j<<")";
1094  return getMultiVector(
1095  outArgs.modelEvalDescription(),
1096  outArgs.get_DgDx(j),
1097  derivName.str(),
1098  mvOrientation
1099  );
1100 }
1101 
1102 
1103 Teuchos::RefCountPtr<Epetra_MultiVector>
1105  const int j,
1106  const int l,
1107  const ModelEvaluator::OutArgs &outArgs,
1109  )
1110 {
1111  std::ostringstream derivName; derivName << "DgDp("<<j<<","<<l<<")";
1112  return getMultiVector(
1113  outArgs.modelEvalDescription(),
1114  outArgs.get_DgDp(j,l),
1115  derivName.str(),
1116  mvOrientation
1117  );
1118 }
Simple aggregate class that stores a derivative object as a general linear operator or as a multi-vec...
Teuchos::RefCountPtr< Epetra_MultiVector > get_DgDx_dot_mv(const int j, const ModelEvaluator::OutArgs &outArgs, const ModelEvaluator::EDerivativeMultiVectorOrientation mvOrientation)
bool supports(EOutArgsMembers arg) const
virtual Teuchos::RefCountPtr< const Epetra_Vector > get_x_lower_bounds() const
void _setSupports(EOutArgsMembers arg, bool supports)
void _set_DfDp_properties(int l, const DerivativeProperties &properties)
Teuchos::RefCountPtr< Epetra_MultiVector > getMultiVector() const
virtual double get_t_upper_bound() const
bool funcOrDerivesAreSet(EOutArgsMembers arg) const
Return true if the function or its derivatives are set.
void _set_DgDp_mp_properties(int j, int l, const DerivativeProperties &properties)
Teuchos::RefCountPtr< Epetra_MultiVector > get_DgDp_mv(const int j, const int l, const ModelEvaluator::OutArgs &outArgs, const ModelEvaluator::EDerivativeMultiVectorOrientation mvOrientation)
Teuchos::RefCountPtr< Epetra_MultiVector > getMultiVector(const std::string &modelEvalDescription, const ModelEvaluator::Derivative &deriv, const std::string &derivName, const ModelEvaluator::EDerivativeMultiVectorOrientation mvOrientation)
void setFailed() const
Set that the evaluation as a whole failed.
Simple aggregate class that stores a derivative object as a general linear operator or as a multi-vec...
Simple aggregate class that stores a derivative object as a general linear operator or as a multi-vec...
Multi-point &quot;W&quot; operator.
Stochastic Galerkin solution vector polynomial.
virtual Teuchos::RefCountPtr< const Epetra_Map > get_p_map(int l) const
.
virtual Teuchos::RefCountPtr< const Teuchos::Array< std::string > > get_p_names(int l) const
Get the names of the parameters associated with parameter subvector l if available.
virtual Teuchos::RefCountPtr< EpetraExt::ModelEvaluator::Preconditioner > create_WPrec() const
virtual Teuchos::RefCountPtr< const Epetra_Vector > get_p_init(int l) const
virtual Teuchos::RefCountPtr< const Epetra_Map > get_g_map(int j) const
.
virtual Teuchos::RefCountPtr< const Epetra_Vector > get_p_upper_bounds(int l) const
void _set_DgDx_mp_properties(int j, const DerivativeProperties &properties)
Derivative get_DgDp(int j, int l) const
Preconditioner operator (approx Jacobian)
bool supports(EInArgsMembers arg) const
void _set_WPrec_properties(const DerivativeProperties &WPrec_properties)
void _set_DgDx_dot_mp_properties(int j, const DerivativeProperties &properties)
void _set_DgDx_dot_properties(int j, const DerivativeProperties &properties)
virtual Teuchos::RefCountPtr< Epetra_Operator > create_W() const
If supported, create a Epetra_Operator object for W to be evaluated.
void _set_DgDx_dot_sg_properties(int j, const DerivativeProperties &properties)
Multi-point time derivative vector.
EDerivativeMultiVectorOrientation getMultiVectorOrientation() const
bool isFailed() const
Return if the evaluation failed or not.
void _set_DfDp_mp_properties(int l, const DerivativeProperties &properties)
Solution vector Taylor polynomial.
Stochastic Galerkin time derivative vector polynomial.
virtual double getInfBound() const
Return the value of an infinite bound.
void _set_DgDp_properties(int j, int l, const DerivativeProperties &properties)
Stochastic Galerkin residual vector polynomial.
virtual double get_t_lower_bound() const
Stochastic Galerkin &quot;W&quot; operator polyomial.
Teuchos::RefCountPtr< Epetra_MultiVector > get_DfDp_mv(const int l, const ModelEvaluator::OutArgs &outArgs)
Teuchos::RefCountPtr< Epetra_Operator > get_DfDp_op(const int l, const ModelEvaluator::OutArgs &outArgs)
Teuchos::RefCountPtr< Epetra_Operator > getLinearOp(const std::string &modelEvalDescription, const ModelEvaluator::Derivative &deriv, const std::string &derivName)
virtual Teuchos::RefCountPtr< Epetra_Operator > create_DgDx_dot_op(int j) const
virtual double get_t_init() const
Teuchos::RefCountPtr< Epetra_Operator > getLinearOp() const
virtual Teuchos::RefCountPtr< Epetra_Operator > create_DfDp_op(int l) const
virtual Teuchos::RefCountPtr< const Epetra_Vector > get_p_lower_bounds(int l) const
Time derivative vector Taylor polynomial.
virtual Teuchos::RefCountPtr< Epetra_Operator > create_DgDx_op(int j) const
virtual Teuchos::RefCountPtr< const Epetra_Vector > get_x_dot_init() const
void _set_DgDx_properties(int j, const DerivativeProperties &properties)
virtual Teuchos::RefCountPtr< const Epetra_Vector > get_x_upper_bounds() const
void _set_DgDp_sg_properties(int j, int l, const DerivativeProperties &properties)
virtual Teuchos::RefCountPtr< const Epetra_Vector > get_x_init() const
void _setSupports(EInArgsMembers arg, bool supports)
void _set_DgDx_sg_properties(int j, const DerivativeProperties &properties)
void _set_W_properties(const DerivativeProperties &W_properties)
Teuchos::RefCountPtr< Epetra_MultiVector > get_DgDx_mv(const int j, const ModelEvaluator::OutArgs &outArgs, const ModelEvaluator::EDerivativeMultiVectorOrientation mvOrientation)
virtual Teuchos::RefCountPtr< Epetra_Operator > create_DgDp_op(int j, int l) const
void _set_DfDp_sg_properties(int l, const DerivativeProperties &properties)
std::string toString(const int &x)
void _setModelEvalDescription(const std::string &modelEvalDescription)