/usr/include/trilinos/Thyra_ModelEvaluatorHelpers.hpp is in libtrilinos-dev 10.4.0.dfsg-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 | // @HEADER
// ***********************************************************************
//
// Thyra: Interfaces and Support for Abstract Numerical Algorithms
// Copyright (2004) Sandia Corporation
//
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
//
// ***********************************************************************
// @HEADER
#ifndef THYRA_MODEL_EVALUATOR_HELPERS_HPP
#define THYRA_MODEL_EVALUATOR_HELPERS_HPP
#include "Thyra_ModelEvaluator.hpp"
namespace Thyra {
/** \brief Create a clone of an InArgs object.
*
* Warning! This function only creates a shallow copy of the underlying input
* objects. Therefore, be careful if you try to modify any of these.
*
* \relates ModelEvaluatorDefaultBase
*/
template<class Scalar>
RCP<ModelEvaluatorBase::InArgs<Scalar> >
clone( const ModelEvaluatorBase::InArgs<Scalar> &inArgs );
/** \relates ModelEvaluatorDefaultBase */
template<class Scalar>
ModelEvaluatorBase::Derivative<Scalar>
derivativeGradient(
const RCP<MultiVectorBase<Scalar> > &grad
);
/** \relates ModelEvaluatorDefaultBase */
template<class Scalar>
ModelEvaluatorBase::DerivativeMultiVector<Scalar>
create_DfDp_mv(
const ModelEvaluator<Scalar>& model,
int l,
ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
);
/** \relates ModelEvaluatorDefaultBase */
template<class Scalar>
ModelEvaluatorBase::DerivativeMultiVector<Scalar>
create_DgDx_dot_mv(
const ModelEvaluator<Scalar>& model,
int j,
ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
);
/** \relates ModelEvaluatorDefaultBase */
template<class Scalar>
ModelEvaluatorBase::DerivativeMultiVector<Scalar>
create_DgDx_mv(
const ModelEvaluator<Scalar>& model,
int j,
ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
);
/** \relates ModelEvaluatorDefaultBase */
template<class Scalar>
ModelEvaluatorBase::DerivativeMultiVector<Scalar>
create_DgDp_mv(
const ModelEvaluator<Scalar>& model,
int j,
int l,
ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
);
/** \relates ModelEvaluatorDefaultBase */
template<class Scalar>
ModelEvaluatorBase::DerivativeMultiVector<Scalar>
get_dmv(
const ModelEvaluatorBase::Derivative<Scalar> &deriv
,const std::string &derivName
);
/** \relates ModelEvaluatorDefaultBase */
template<class Scalar>
RCP<MultiVectorBase<Scalar> >
get_mv(
const ModelEvaluatorBase::Derivative<Scalar> &deriv
,const std::string &derivName
,ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
);
/** \brief Assert that that Thyra objects imbedded in a Derivative object
* matches its function and variable spaces.
*
* \relates ModelEvaluatorDefaultBase
*/
template<class Scalar>
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
);
/** \brief Assert that an InArgs and OutArgs object are setup consistently.
*
* \relates ModelEvaluatorDefaultBase
*/
template<class Scalar>
void assertInArgsOutArgsSetup(
const std::string &modelEvalDescription,
const ModelEvaluatorBase::InArgs<Scalar> &inArgs,
const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
);
/** \brief Assert that the objects in an InArgs object match a given model.
*
* \relates ModelEvaluatorDefaultBase
*/
template<class Scalar>
void assertInArgsEvalObjects(
const ModelEvaluator<Scalar> &model,
const ModelEvaluatorBase::InArgs<Scalar> &inArgs
);
/** \brief Assert that the objects in an OutArgs object match a given model.
*
* \relates ModelEvaluatorDefaultBase
*/
template<class Scalar>
void assertOutArgsEvalObjects(
const ModelEvaluator<Scalar> &model,
const ModelEvaluatorBase::OutArgs<Scalar> &outArgs,
const ModelEvaluatorBase::InArgs<Scalar> *inArgs = 0
);
/** \brief Evaluate <tt>f(x)</tt>. */
template<class Scalar>
void eval_f(
const ModelEvaluator<Scalar> &model
,const VectorBase<Scalar> &x
,VectorBase<Scalar> *f
);
/** \brief Evaluate <tt>f(x)</tt> and <tt>W(x) = DfDx(x)</tt>. */
template<class Scalar>
void eval_f_W(
const ModelEvaluator<Scalar> &model
,const VectorBase<Scalar> &x
,VectorBase<Scalar> *f
,LinearOpWithSolveBase<Scalar> *W
);
/** \brief Evaluate <tt>f(x,t)</tt>. */
template<class Scalar>
void eval_f(
const ModelEvaluator<Scalar> &model
,const VectorBase<Scalar> &x
,const Scalar &t
,VectorBase<Scalar> *f
);
/** \brief Evaluate <tt>g(j)(p))</tt>. */
template<class Scalar>
void eval_g(
const ModelEvaluator<Scalar> &model,
const int l,
const VectorBase<Scalar> &p_l,
const int j,
const Ptr<VectorBase<Scalar> > &g_j
);
/** \brief Deprecated . */
template<class Scalar>
void eval_g(
const ModelEvaluator<Scalar> &model,
const int l,
const VectorBase<Scalar> &p_l,
const int j,
VectorBase<Scalar> *g_j
)
{
eval_g(model, l, p_l, j, Teuchos::ptr(g_j));
}
/** \brief Evaluate <tt>g(j)(p,t))</tt>. */
template<class Scalar>
void eval_g(
const ModelEvaluator<Scalar> &model,
const int l,
const VectorBase<Scalar> &p_l,
const Scalar &t,
const int j,
VectorBase<Scalar> *g_j
);
/** \brief Evaluate <tt>g(j)(p))</tt> and/or D(g)/D(p). */
template<class Scalar>
void eval_g_DgDp(
const ModelEvaluator<Scalar> &model,
const int l,
const VectorBase<Scalar> &p_l,
const int j,
const Ptr<VectorBase<Scalar> > &g_j,
const ModelEvaluatorBase::Derivative<Scalar> &DgDp_j_l
);
/** \brief Evaluate <tt>f(x_dot,x,t)</tt>. */
template<class Scalar>
void eval_f(
const ModelEvaluator<Scalar> &model
,const VectorBase<Scalar> &x_dot
,const VectorBase<Scalar> &x
,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
,VectorBase<Scalar> *f
);
/** \brief Evaluate <tt>f(x_dot,x,t)</tt> and <tt>W(x_dot,x,t,alpha,beta) =
* alpha*DfDx_dot(x_dot,x,t) + beta*DfDx(x_dot,x,t)</tt>. */
template<class Scalar>
void eval_f_W(
const ModelEvaluator<Scalar> &model
,const VectorBase<Scalar> &x_dot
,const VectorBase<Scalar> &x
,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
,const Scalar &alpha
,const Scalar &beta
,VectorBase<Scalar> *f
,LinearOpWithSolveBase<Scalar> *W
);
#ifdef HAVE_THYRA_ME_POLYNOMIAL
/** \brief . */
template<class Scalar>
void eval_f_poly(
const ModelEvaluator<Scalar> &model
,const Teuchos::Polynomial< VectorBase<Scalar> > &x_poly
,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
,Teuchos::Polynomial< VectorBase<Scalar> > *f_poly
);
/** \brief . */
template<class Scalar>
void eval_f_poly(
const ModelEvaluator<Scalar> &model
,const Teuchos::Polynomial< VectorBase<Scalar> > &x_dot_poly
,const VectorBase<Scalar> &x_poly
,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
,Teuchos::Polynomial< VectorBase<Scalar> > *f_poly
);
#endif // HAVE_THYRA_ME_POLYNOMIAL
} // namespace Thyra
//
// Implementations
//
#include "Thyra_AssertOp.hpp"
#include "Teuchos_Utils.hpp"
template<class Scalar>
Teuchos::RCP<Thyra::ModelEvaluatorBase::InArgs<Scalar> >
Thyra::clone( const ModelEvaluatorBase::InArgs<Scalar> &inArgs )
{
RCP<ModelEvaluatorBase::InArgs<Scalar> >
newInArgs = Teuchos::rcp(new ModelEvaluatorBase::InArgs<Scalar>);
*newInArgs = inArgs;
return newInArgs;
}
template<class Scalar>
Thyra::ModelEvaluatorBase::Derivative<Scalar>
Thyra::derivativeGradient(
const RCP<MultiVectorBase<Scalar> > &grad
)
{
return ModelEvaluatorBase::Derivative<Scalar>(
grad,
ModelEvaluatorBase::DERIV_MV_GRADIENT_FORM
);
}
template<class Scalar>
Thyra::ModelEvaluatorBase::DerivativeMultiVector<Scalar>
Thyra::create_DfDp_mv(
const ModelEvaluator<Scalar>& model,
int l,
ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
)
{
TEST_FOR_EXCEPT(!(orientation==ModelEvaluatorBase::DERIV_MV_BY_COL));
return createMembers( model.get_f_space(), model.get_p_space(l)->dim() );
}
template<class Scalar>
Thyra::ModelEvaluatorBase::DerivativeMultiVector<Scalar>
Thyra::create_DgDx_dot_mv(
const ModelEvaluator<Scalar>& model,
int j,
ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
)
{
typedef ModelEvaluatorBase MEB;
switch(orientation) {
case MEB::DERIV_MV_BY_COL:
return
MEB::DerivativeMultiVector<Scalar>(
createMembers( model.get_g_space(j), model.get_x_space()->dim() )
,MEB::DERIV_MV_BY_COL
);
case MEB::DERIV_TRANS_MV_BY_ROW:
return
MEB::DerivativeMultiVector<Scalar>(
createMembers( model.get_x_space(), model.get_g_space(j)->dim() )
,MEB::DERIV_TRANS_MV_BY_ROW
);
default:
TEST_FOR_EXCEPT(true);
}
return MEB::DerivativeMultiVector<Scalar>(); // Never executed!
}
template<class Scalar>
Thyra::ModelEvaluatorBase::DerivativeMultiVector<Scalar>
Thyra::create_DgDx_mv(
const ModelEvaluator<Scalar>& model,
int j,
ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
)
{
return create_DgDx_dot_mv(model,j,orientation);
}
template<class Scalar>
Thyra::ModelEvaluatorBase::DerivativeMultiVector<Scalar>
Thyra::create_DgDp_mv(
const ModelEvaluator<Scalar>& model,
int j,
int l,
ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
)
{
typedef ModelEvaluatorBase MEB;
switch(orientation) {
case MEB::DERIV_MV_BY_COL:
return
MEB::DerivativeMultiVector<Scalar>(
createMembers( model.get_g_space(j), model.get_p_space(l)->dim() )
,MEB::DERIV_MV_BY_COL
);
case MEB::DERIV_TRANS_MV_BY_ROW:
return
MEB::DerivativeMultiVector<Scalar>(
createMembers( model.get_p_space(l), model.get_g_space(j)->dim() )
,MEB::DERIV_TRANS_MV_BY_ROW
);
default:
TEST_FOR_EXCEPT(true);
}
return MEB::DerivativeMultiVector<Scalar>(); // Never executed!
}
template<class Scalar>
Thyra::ModelEvaluatorBase::DerivativeMultiVector<Scalar>
Thyra::get_dmv(
const ModelEvaluatorBase::Derivative<Scalar> &deriv
,const std::string &derivName
)
{
TEST_FOR_EXCEPTION(
deriv.getLinearOp().get()!=NULL, std::logic_error
,"Error, LinearOpBase type not expected for " << derivName <<"!"
);
return deriv.getDerivativeMultiVector();
}
template<class Scalar>
Teuchos::RCP<Thyra::MultiVectorBase<Scalar> >
Thyra::get_mv(
const ModelEvaluatorBase::Derivative<Scalar> &deriv
,const std::string &derivName
,ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
)
{
typedef ModelEvaluatorBase MEB;
TEST_FOR_EXCEPTION(
deriv.getLinearOp().get()!=NULL, std::logic_error
,"Error, LinearOpBase type not expected for " << derivName <<"!"
);
MEB::DerivativeMultiVector<Scalar>
dmv = deriv.getDerivativeMultiVector();
RCP<MultiVectorBase<Scalar> >
mv = dmv.getMultiVector();
if( mv.get() ) {
TEST_FOR_EXCEPTION(
dmv.getOrientation() != orientation, std::logic_error
,"Error, the orientation " << toString(dmv.getOrientation()) << " is not the"
" expected orientation of " << toString(orientation)
<< " for " << derivName << "!"
);
}
return mv;
}
template<class Scalar>
void Thyra::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
)
{
typedef ModelEvaluatorBase MEB;
if (!is_null(deriv.getLinearOp())) {
const RCP<const LinearOpBase<Scalar> > lo = deriv.getLinearOp();
if (!is_null(lo->range())) {
THYRA_ASSERT_VEC_SPACES_NAMES(
modelEvalDescription,
*lo->range(), deriv_name + ".range()",
fnc_space, fnc_space_name
);
THYRA_ASSERT_VEC_SPACES_NAMES(
modelEvalDescription,
*lo->domain(), deriv_name + ".domain()",
var_space, var_space_name
);
}
}
else if(!is_null(deriv.getMultiVector())) {
const RCP<const LinearOpBase<Scalar> > mv = deriv.getMultiVector();
switch(deriv.getMultiVectorOrientation()) {
case MEB::DERIV_MV_BY_COL: {
THYRA_ASSERT_VEC_SPACES_NAMES(
modelEvalDescription,
*mv->range(), deriv_name + ".range()",
fnc_space, fnc_space_name
);
THYRA_ASSERT_VEC_SPACES_NAMES(
modelEvalDescription,
*mv->domain(), deriv_name + ".domain()",
var_space, var_space_name
);
break;
}
case MEB::DERIV_TRANS_MV_BY_ROW: {
THYRA_ASSERT_VEC_SPACES_NAMES(
modelEvalDescription,
*mv->range(), deriv_name + "^T.range()",
var_space, var_space_name
);
THYRA_ASSERT_VEC_SPACES_NAMES(
modelEvalDescription,
*mv->domain(), deriv_name + "^T.domain()",
fnc_space, fnc_space_name
);
break;
}
#ifdef TEUCHOS_DEBUG
default:
TEST_FOR_EXCEPT(true);
#endif
}
}
}
template<class Scalar>
void Thyra::assertInArgsOutArgsSetup(
const std::string &modelEvalDescription,
const ModelEvaluatorBase::InArgs<Scalar> &inArgs,
const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
)
{
typedef ModelEvaluatorBase MEB;
const int Ng = outArgs.Ng();
const int Np = outArgs.Np();
// Description
TEUCHOS_ASSERT_EQUALITY(inArgs.modelEvalDescription(), modelEvalDescription);
TEUCHOS_ASSERT_EQUALITY(outArgs.modelEvalDescription(), modelEvalDescription);
// Np
TEST_FOR_EXCEPTION(
inArgs.Np() != outArgs.Np(), std::logic_error,
"Error: The underlying model " << modelEvalDescription << " incorrectly\n"
"set inArgs.Np() = "<<inArgs.Np()<<" != outArgs.Np() = "
<<outArgs.Np()<<"!"
);
// x_dot
TEST_FOR_EXCEPTION(
inArgs.supports(MEB::IN_ARG_x_dot) && !inArgs.supports(MEB::IN_ARG_x),
std::logic_error,
"Error: The underlying model " << modelEvalDescription << " supports\n"
"x_dot but does not support x!"
);
// t
TEST_FOR_EXCEPTION(
inArgs.supports(MEB::IN_ARG_x_dot) && !inArgs.supports(MEB::IN_ARG_t),
std::logic_error,
"Error: The underlying model " << modelEvalDescription << " supports\n"
"x_dot but does not support t!"
);
// W and W_op
TEST_FOR_EXCEPTION(
(
( outArgs.supports(MEB::OUT_ARG_W) || outArgs.supports(MEB::OUT_ARG_W_op) )
&&
!inArgs.supports(MEB::IN_ARG_x)
),
std::logic_error,
"Error: The underlying model " << modelEvalDescription << " says that\n"
"it supports W and/or W_op but it does not support x!"
);
TEST_FOR_EXCEPTION(
(
( outArgs.supports(MEB::OUT_ARG_W) || outArgs.supports(MEB::OUT_ARG_W_op) )
&&
inArgs.supports(MEB::IN_ARG_x_dot)
&&
!( inArgs.supports(MEB::IN_ARG_alpha) && inArgs.supports(MEB::IN_ARG_beta) )
),
std::logic_error,
"Error: The underlying model " << modelEvalDescription << " supports W and/or W_op\n"
"and x_dot but it does not support alpha and beta as InArgs!"
);
for ( int l = 0; l < Np; ++l ) {
// DfDp(l): OutArgs checks this automatically!
for ( int j = 0; j < Ng; ++j ) {
// DgDx_dot(j)
TEST_FOR_EXCEPTION(
( !outArgs.supports(MEB::OUT_ARG_DgDx_dot,j).none()
&& !inArgs.supports(MEB::IN_ARG_x_dot) ),
std::logic_error,
"Error: The underlying model " << modelEvalDescription << " says that\n"
"it supports DgDx_dot("<<j<<") but it does not support x_dot!"
);
// DgDx(j)
TEST_FOR_EXCEPTION(
( !outArgs.supports(MEB::OUT_ARG_DgDx,j).none()
&& !inArgs.supports(MEB::IN_ARG_x) ),
std::logic_error,
"Error: The underlying model " << modelEvalDescription << " says that\n"
"it supports DgDx("<<j<<") but it does not support x!"
);
// DgDp(j,l): OutArgs checks this automatically!
}
}
}
template<class Scalar>
void Thyra::assertInArgsEvalObjects(
const ModelEvaluator<Scalar> &model,
const ModelEvaluatorBase::InArgs<Scalar> &inArgs
)
{
typedef ModelEvaluatorBase MEB;
const std::string description = model.description();
const int Np = inArgs.Np();
model.createInArgs().assertSameSupport(inArgs);
// x_dot
if ( inArgs.supports(MEB::IN_ARG_x_dot) && !is_null(inArgs.get_x_dot()) ) {
THYRA_ASSERT_VEC_SPACES(
description, *inArgs.get_x_dot()->space(), *model.get_x_space() );
}
// x
if ( inArgs.supports(MEB::IN_ARG_x) && !is_null(inArgs.get_x()) ) {
THYRA_ASSERT_VEC_SPACES(
description, *inArgs.get_x()->space(), *model.get_x_space() );
}
// p(l)
for ( int l = 0; l < Np; ++l ) {
if (!is_null(inArgs.get_p(l))) {
THYRA_ASSERT_VEC_SPACES(
description, *inArgs.get_p(l)->space(), *model.get_p_space(l) );
}
}
}
template<class Scalar>
void Thyra::assertOutArgsEvalObjects(
const ModelEvaluator<Scalar> &model,
const ModelEvaluatorBase::OutArgs<Scalar> &outArgs,
const ModelEvaluatorBase::InArgs<Scalar> *inArgs
)
{
typedef ScalarTraits<Scalar> ST;
typedef Teuchos::Utils TU;
typedef ModelEvaluatorBase MEB;
const std::string description = model.description();
const int Ng = outArgs.Ng();
const int Np = outArgs.Np();
if (inArgs) {
TEUCHOS_ASSERT_EQUALITY(outArgs.Np(), inArgs->Np());
}
model.createOutArgs().assertSameSupport(outArgs);
// f
if ( outArgs.supports(MEB::OUT_ARG_f) && !is_null(outArgs.get_f()) ) {
THYRA_ASSERT_VEC_SPACES(
description, *outArgs.get_f()->space(), *model.get_f_space() );
}
// W
if ( outArgs.supports(MEB::OUT_ARG_W) && !is_null(outArgs.get_W()) ) {
if (!is_null(outArgs.get_W()->range())) {
THYRA_ASSERT_VEC_SPACES(
description, *outArgs.get_W()->range(), *model.get_f_space() );
THYRA_ASSERT_VEC_SPACES(
description, *outArgs.get_W()->domain(), *model.get_x_space() );
}
}
// W_op
if ( outArgs.supports(MEB::OUT_ARG_W_op) && !is_null(outArgs.get_W_op()) ) {
if (!is_null(outArgs.get_W_op()->range())) {
THYRA_ASSERT_VEC_SPACES(
description, *outArgs.get_W_op()->range(), *model.get_f_space() );
THYRA_ASSERT_VEC_SPACES(
description, *outArgs.get_W_op()->domain(), *model.get_x_space() );
}
}
// alpha and beta (not really in outArgs but can only be validated if W or
// W_op is set)
if (
inArgs
&&
(
( outArgs.supports(MEB::OUT_ARG_W) && !is_null(outArgs.get_W()) )
||
( outArgs.supports(MEB::OUT_ARG_W_op) && !is_null(outArgs.get_W_op()) )
)
)
{
if ( inArgs->supports(MEB::IN_ARG_alpha) && inArgs->supports(MEB::IN_ARG_beta) ) {
// 08/25/08 tscoffe: In the block-composed linear operator case for
// Rythmos::ImplicitRKModelEvaluator, I need to specify that a given
// block is all zeros and I'm depending on the underlying model to
// intelligently fill the block with zeros if both alpha and beta are
// zero.
//TEST_FOR_EXCEPT( inArgs->get_alpha() == ST::zero() && inArgs->get_beta() == ST::zero() );
}
else if ( inArgs->supports(MEB::IN_ARG_beta) ) {
TEST_FOR_EXCEPT( inArgs->get_beta() == ST::zero() );
}
}
// DfDp(l)
if (outArgs.supports(MEB::OUT_ARG_f)) {
for ( int l = 0; l < Np; ++l ) {
if (!outArgs.supports(MEB::OUT_ARG_DfDp,l).none()) {
assertDerivSpaces(
description,
outArgs.get_DfDp(l), "DfDp("+TU::toString(l)+")",
*model.get_f_space(), "f_space",
*model.get_p_space(l), "p_space("+TU::toString(l)+")"
);
}
}
}
// g(l)
for ( int j = 0; j < Ng; ++j ) {
if (!is_null(outArgs.get_g(j))) {
THYRA_ASSERT_VEC_SPACES(
description, *outArgs.get_g(j)->space(), *model.get_g_space(j) );
}
}
// DgDx_dot(j)
for ( int j = 0; j < Ng; ++j ) {
if (!outArgs.supports(MEB::OUT_ARG_DgDx_dot,j).none()) {
assertDerivSpaces(
description,
outArgs.get_DgDx_dot(j), "DgDx_dot("+TU::toString(j)+")",
*model.get_g_space(j), "g_space("+TU::toString(j)+")",
*model.get_x_space(), "x_space"
);
}
}
// DgDx(j)
for ( int j = 0; j < Ng; ++j ) {
if (!outArgs.supports(MEB::OUT_ARG_DgDx,j).none()) {
assertDerivSpaces(
description,
outArgs.get_DgDx(j), "DgDx("+TU::toString(j)+")",
*model.get_g_space(j), "g_space("+TU::toString(j)+")",
*model.get_x_space(), "x_space"
);
}
}
// Assert DgDp(j,l)
for ( int j = 0; j < Ng; ++j ) {
for ( int l = 0; l < Np; ++l ) {
if (!outArgs.supports(MEB::OUT_ARG_DgDp,j,l).none()) {
const std::string j_str = TU::toString(j);
const std::string l_str = TU::toString(l);
assertDerivSpaces(
description,
outArgs.get_DgDp(j,l), "DgDp("+j_str+","+l_str+")",
*model.get_g_space(j), "g_space("+j_str+")",
*model.get_p_space(l), "p_space("+l_str+")"
);
}
}
}
}
template<class Scalar>
void Thyra::eval_f(
const ModelEvaluator<Scalar> &model
,const VectorBase<Scalar> &x
,VectorBase<Scalar> *f
)
{
typedef ModelEvaluatorBase MEB;
MEB::InArgs<Scalar> inArgs = model.createInArgs();
MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
inArgs.set_x(Teuchos::rcp(&x,false));
outArgs.set_f(Teuchos::rcp(f,false));
model.evalModel(inArgs,outArgs);
}
template<class Scalar>
void Thyra::eval_f_W(
const ModelEvaluator<Scalar> &model
,const VectorBase<Scalar> &x
,VectorBase<Scalar> *f
,LinearOpWithSolveBase<Scalar> *W
)
{
typedef ModelEvaluatorBase MEB;
MEB::InArgs<Scalar> inArgs = model.createInArgs();
MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
inArgs.set_x(Teuchos::rcp(&x,false));
if (f) outArgs.set_f(Teuchos::rcp(f,false));
if (W) outArgs.set_W(Teuchos::rcp(W,false));
model.evalModel(inArgs,outArgs);
}
template<class Scalar>
void Thyra::eval_f(
const ModelEvaluator<Scalar> &model
,const VectorBase<Scalar> &x
,const Scalar &t
,VectorBase<Scalar> *f
)
{
typedef ModelEvaluatorBase MEB;
MEB::InArgs<Scalar> inArgs = model.createInArgs();
MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
inArgs.set_x(Teuchos::rcp(&x,false));
if(inArgs.supports(MEB::IN_ARG_t)) inArgs.set_t(t);
outArgs.set_f(Teuchos::rcp(f,false));
model.evalModel(inArgs,outArgs);
}
template<class Scalar>
void Thyra::eval_g(
const ModelEvaluator<Scalar> &model,
const int l,
const VectorBase<Scalar> &p_l,
const int j,
const Ptr<VectorBase<Scalar> > &g_j
)
{
typedef ModelEvaluatorBase MEB;
MEB::InArgs<Scalar> inArgs = model.createInArgs();
MEB::OutArgs<Scalar> outArgs= model.createOutArgs();
inArgs.set_p(l, Teuchos::rcpFromRef(p_l));
outArgs.set_g(j, Teuchos::rcpFromRef(*g_j));
model.evalModel(inArgs,outArgs);
}
template<class Scalar>
void Thyra::eval_g(
const ModelEvaluator<Scalar> &model,
const int l,
const VectorBase<Scalar> &p_l,
const Scalar &t,
const int j,
VectorBase<Scalar> *g_j
)
{
typedef ModelEvaluatorBase MEB;
MEB::InArgs<Scalar> inArgs = model.createInArgs();
MEB::OutArgs<Scalar> outArgs= model.createOutArgs();
inArgs.set_p(l,Teuchos::rcp(&p_l,false));
inArgs.set_t(t);
outArgs.set_g(j,Teuchos::rcp(g_j,false));
model.evalModel(inArgs,outArgs);
}
template<class Scalar>
void Thyra::eval_g_DgDp(
const ModelEvaluator<Scalar> &model,
const int l,
const VectorBase<Scalar> &p_l,
const int j,
const Ptr<VectorBase<Scalar> > &g_j,
const ModelEvaluatorBase::Derivative<Scalar> &DgDp_j_l
)
{
typedef ModelEvaluatorBase MEB;
MEB::InArgs<Scalar> inArgs = model.createInArgs();
MEB::OutArgs<Scalar> outArgs= model.createOutArgs();
inArgs.set_p(l, Teuchos::rcpFromRef(p_l));
if (!is_null(g_j)) {
outArgs.set_g(j, Teuchos::rcpFromPtr(g_j));
}
if (!DgDp_j_l.isEmpty()) {
outArgs.set_DgDp(j, l, DgDp_j_l);
}
model.evalModel(inArgs,outArgs);
}
template<class Scalar>
void Thyra::eval_f(
const ModelEvaluator<Scalar> &model
,const VectorBase<Scalar> &x_dot
,const VectorBase<Scalar> &x
,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
,VectorBase<Scalar> *f
)
{
typedef ModelEvaluatorBase MEB;
MEB::InArgs<Scalar> inArgs = model.createInArgs();
MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
inArgs.set_x_dot(Teuchos::rcp(&x_dot,false));
inArgs.set_x(Teuchos::rcp(&x,false));
if(inArgs.supports(MEB::IN_ARG_t))
inArgs.set_t(t);
outArgs.set_f(Teuchos::rcp(f,false));
model.evalModel(inArgs,outArgs);
}
template<class Scalar>
void Thyra::eval_f_W(
const ModelEvaluator<Scalar> &model
,const VectorBase<Scalar> &x_dot
,const VectorBase<Scalar> &x
,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
,const Scalar &alpha
,const Scalar &beta
,VectorBase<Scalar> *f
,LinearOpWithSolveBase<Scalar> *W
)
{
typedef ModelEvaluatorBase MEB;
MEB::InArgs<Scalar> inArgs = model.createInArgs();
MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
inArgs.set_x_dot(Teuchos::rcp(&x_dot,false));
inArgs.set_x(Teuchos::rcp(&x,false));
if(inArgs.supports(MEB::IN_ARG_t))
inArgs.set_t(t);
inArgs.set_alpha(alpha);
inArgs.set_beta(beta);
if(f) outArgs.set_f(Teuchos::rcp(f,false));
if(W) outArgs.set_W(Teuchos::rcp(W,false));
model.evalModel(inArgs,outArgs);
}
#ifdef HAVE_THYRA_ME_POLYNOMIAL
template<class Scalar>
void Thyra::eval_f_poly(
const ModelEvaluator<Scalar> &model
,const Teuchos::Polynomial< VectorBase<Scalar> > &x_poly
,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
,Teuchos::Polynomial< VectorBase<Scalar> > *f_poly
)
{
typedef ModelEvaluatorBase MEB;
MEB::InArgs<Scalar> inArgs = model.createInArgs();
MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
inArgs.set_x_poly(Teuchos::rcp(&x_poly,false));
if(inArgs.supports(MEB::IN_ARG_t))
inArgs.set_t(t);
outArgs.set_f_poly(Teuchos::rcp(f_poly,false));
model.evalModel(inArgs,outArgs);
}
template<class Scalar>
void Thyra::eval_f_poly(
const ModelEvaluator<Scalar> &model
,const Teuchos::Polynomial< VectorBase<Scalar> > &x_dot_poly
,const VectorBase<Scalar> &x_poly
,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
,Teuchos::Polynomial< VectorBase<Scalar> > *f_poly
)
{
typedef ModelEvaluatorBase MEB;
MEB::InArgs<Scalar> inArgs = model.createInArgs();
MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
inArgs.set_x_dot_poly(Teuchos::rcp(&x_dot_poly,false));
inArgs.set_x_poly(Teuchos::rcp(&x_poly,false));
if(inArgs.supports(MEB::IN_ARG_t))
inArgs.set_t(t);
outArgs.set_f_poly(Teuchos::rcp(f_poly,false));
model.evalModel(inArgs,outArgs);
}
#endif // HAVE_THYRA_ME_POLYNOMIAL
#endif // THYRA_MODEL_EVALUATOR_HELPERS_HPP
|