43 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
46 #include "Thyra_DetachedMultiVectorView.hpp"
47 #include "Thyra_ModelEvaluatorDelegatorBase.hpp"
48 #include "EpetraExt_ModelEvaluatorScalingTools.h"
49 #include "Epetra_RowMatrix.h"
60 const std::string StateFunctionScaling_name =
"State Function Scaling";
66 stateFunctionScalingValidator;
67 const std::string StateFunctionScaling_default =
"None";
73 const EpetraExt::ModelEvaluator::OutArgs &epetraOutArgs
77 const RCP<Epetra_Operator>
78 eW = epetraOutArgs.get_W();
79 const RCP<Epetra_RowMatrix>
80 ermW = Teuchos::rcp_dynamic_cast<Epetra_RowMatrix>(eW,
false);
82 is_null(ermW), std::logic_error,
83 "Thyra::EpetraModelEvaluator::evalModel(...): Error, if\n"
84 "scaling is turned on, the underlying Epetra_Operator created\n"
85 "an initialized by the underlying epetra model evaluator\n"
86 "\"" << epetraOutArgs.modelEvalDescription() <<
"\"\n"
87 "must support the Epetra_RowMatrix interface through a dynamic cast.\n"
97 const EpetraExt::ModelEvaluator &epetraModel
102 eW = epetraModel.create_W();
105 "Error, the call to create_W() returned null on the "
106 "EpetraExt::ModelEvaluator object "
107 "\"" << epetraModel.description() <<
"\". This may mean that "
108 "the underlying model does not support more than one copy of "
124 :nominalValuesAndBoundsAreUpdated_(false), stateFunctionScaling_(STATE_FUNC_SCALING_NONE),
125 currentInArgsOutArgs_(false), finalPointWasSolved_(false)
131 const RCP<LinearOpWithSolveFactoryBase<double> > &W_factory
133 :nominalValuesAndBoundsAreUpdated_(false), stateFunctionScaling_(STATE_FUNC_SCALING_NONE),
134 currentInArgsOutArgs_(false), finalPointWasSolved_(false)
142 const RCP<LinearOpWithSolveFactoryBase<double> > &W_factory
159 EpetraExt::ModelEvaluator::InArgs inArgs =
epetraModel_->createInArgs();
162 for(
int l = 0; l < implicit_cast<int>(
p_space_.
size()); ++l ) {
167 is_null(p_map_l), std::logic_error,
168 "Error, the the map p["<<l<<
"] for the model \""
169 <<epetraModel->description()<<
"\" can not be null!");
176 EpetraExt::ModelEvaluator::OutArgs outArgs =
epetraModel_->createOutArgs();
179 for(
int j = 0; j < implicit_cast<int>(
g_space_.
size()); ++j ) {
204 const ModelEvaluatorBase::InArgs<double>& nominalValues
217 typedef ModelEvaluatorBase MEB;
258 RCP<LinearOpWithSolveFactoryBase<double> > *W_factory
272 const ModelEvaluatorBase::InArgs<double>&
290 std::ostringstream oss;
291 oss <<
"Thyra::EpetraModelEvaluator{";
292 oss <<
"epetraModel=";
297 oss <<
",W_factory=";
319 *
paramList_, StateFunctionScaling_name, StateFunctionScaling_default
323 Teuchos::readVerboseObjectSublist(&*
paramList_,
this);
326 #endif // TEUCHOS_DEBUG
358 using Teuchos::tuple;
359 using Teuchos::rcp_implicit_cast;
365 stateFunctionScalingValidator =
rcp(
366 new StringToIntegralParameterEntryValidator<EStateFunctionScaling>(
372 "Do not scale the state function f(...) in this class.",
374 "Scale the state function f(...) and all its derivatives\n"
375 "using the row sum scaling from the initial Jacobian\n"
376 "W=d(f)/d(x). Note, this only works with Epetra_CrsMatrix\n"
379 tuple<EStateFunctionScaling>(
383 StateFunctionScaling_name
386 pl->
set(StateFunctionScaling_name,StateFunctionScaling_default,
387 "Determines if and how the state function f(...) and all of its\n"
388 "derivatives are scaled. The scaling is done explicitly so there should\n"
389 "be no impact on the meaning of inner products or tolerances for\n"
391 rcp_implicit_cast<const PEV>(stateFunctionScalingValidator)
393 Teuchos::setupVerboseObjectSublist(&*pl);
467 ModelEvaluatorBase::InArgs<double>
475 ModelEvaluatorBase::InArgs<double>
483 ModelEvaluatorBase::InArgs<double>
521 const ModelEvaluatorBase::InArgs<double> &finalPoint,
566 ModelEvaluatorBase::OutArgs<double>
577 const ModelEvaluatorBase::InArgs<double>& inArgs_in,
578 const ModelEvaluatorBase::OutArgs<double>& outArgs
583 using Teuchos::rcp_const_cast;
584 using Teuchos::rcp_dynamic_cast;
587 typedef EpetraExt::ModelEvaluator EME;
605 inArgs.setArgs(inArgs_in);
611 if (inArgs.supports(Thyra::ModelEvaluatorBase::IN_ARG_x_dot)) {
612 if (
is_null(inArgs_in.get_x_dot()))
617 typedef double Scalar;
618 THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_BEGIN(
623 const bool firstTimeStateFuncScaling
630 VOTSLOWSF W_factory_outputTempState(
W_factory_,out,verbLevel);
644 *out <<
"\nSetting-up/creating input arguments ...\n";
648 EME::InArgs epetraScaledInArgs =
epetraModel_->createInArgs();
653 EME::InArgs epetraInArgs =
epetraModel_->createInArgs();
654 EpetraExt::unscaleModelVars(
668 *out <<
"\nSetting-up/creating output arguments ...\n";
673 EME::OutArgs epetraUnscaledOutArgs =
epetraModel_->createOutArgs();
685 &epetraUnscaledOutArgs,
693 if (firstTimeStateFuncScaling) {
700 <<
"\nTime to setup OutArgs = "
708 *out <<
"\nEvaluating the Epetra output functions ...\n";
711 epetraModel_->evalModel(epetraInArgs,epetraUnscaledOutArgs);
716 <<
"\nTime to evaluate Epetra output functions = "
728 *out <<
"\nCompute scale factors if needed ...\n";
731 if (firstTimeStateFuncScaling) {
738 <<
"\nTime to compute scale factors = "
746 *out <<
"\nScale the output objects ...\n";
749 EME::OutArgs epetraOutArgs =
epetraModel_->createOutArgs();
750 bool allFuncsWhereScaled =
false;
751 EpetraExt::scaleModelFuncs(
753 &epetraOutArgs, &allFuncsWhereScaled,
759 !allFuncsWhereScaled, std::logic_error,
760 "Error, we can not currently handle epetra output objects that could not be"
761 " scaled. Special code will have to be added to handle this (i.e. using"
762 " implicit diagonal and multiplied linear operators to implicitly do"
769 <<
"\nTime to scale the output objects = "
778 *out <<
"\nFinish processing and wrapping the output objects ...\n";
782 epetraOutArgs, W_op, efwdW, eW,
789 <<
"\nTime to finish processing and wrapping the output objects = "
796 THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END();
805 const EpetraExt::ModelEvaluator::InArgs &epetraInArgs,
806 ModelEvaluatorBase::InArgs<double> *inArgs
811 typedef ModelEvaluatorBase MEB;
815 if(inArgs->supports(MEB::IN_ARG_x)) {
819 if(inArgs->supports(MEB::IN_ARG_x_dot)) {
823 if(inArgs->supports(MEB::IN_ARG_x_mp)) {
824 inArgs->set_x_mp( epetraInArgs.get_x_mp() );
827 if(inArgs->supports(MEB::IN_ARG_x_dot_mp)) {
828 inArgs->set_x_dot_mp( epetraInArgs.get_x_dot_mp() );
831 const int l_Np = inArgs->Np();
832 for(
int l = 0; l < l_Np; ++l ) {
835 for(
int l = 0; l < l_Np; ++l ) {
836 if(inArgs->supports(MEB::IN_ARG_p_mp, l))
837 inArgs->set_p_mp( l, epetraInArgs.get_p_mp(l) );
840 if(inArgs->supports(MEB::IN_ARG_t)) {
841 inArgs->set_t(epetraInArgs.get_t());
848 const ModelEvaluatorBase::InArgs<double> &inArgs,
849 EpetraExt::ModelEvaluator::InArgs *epetraInArgs
854 using Teuchos::rcp_const_cast;
855 #ifdef HAVE_THYRA_ME_POLYNOMIAL
857 #endif // HAVE_THYRA_ME_POLYNOMIAL
863 if( inArgs.supports(IN_ARG_x_dot) && (x_dot = inArgs.get_x_dot()).
get() ) {
865 epetraInArgs->set_x_dot(e_x_dot);
868 if( inArgs.supports(IN_ARG_x_dot_mp) && (x_dot_mp = inArgs.get_x_dot_mp()).
get() ) {
869 epetraInArgs->set_x_dot_mp(x_dot_mp);
873 if( inArgs.supports(IN_ARG_x) && (x = inArgs.get_x()).
get() ) {
875 epetraInArgs->set_x(e_x);
878 if( inArgs.supports(IN_ARG_x_mp) && (x_mp = inArgs.get_x_mp()).
get() ) {
879 epetraInArgs->set_x_mp(x_mp);
883 for(
int l = 0; l < inArgs.Np(); ++l ) {
884 p_l = inArgs.get_p(l);
888 for(
int l = 0; l < inArgs.Np(); ++l ) {
889 if (inArgs.supports(IN_ARG_p_mp,l)) {
890 p_mp_l = inArgs.get_p_mp(l);
891 if(p_mp_l.
get()) epetraInArgs->set_p_mp(l,p_mp_l);
895 #ifdef HAVE_THYRA_ME_POLYNOMIAL
900 inArgs.supports(IN_ARG_x_dot_poly)
901 && (x_dot_poly = inArgs.get_x_dot_poly()).
get()
905 rcp(
new Polynomial<Epetra_Vector>(x_dot_poly->degree()));
906 for (
unsigned int i=0; i<=x_dot_poly->degree(); i++) {
907 epetra_ptr = rcp_const_cast<Epetra_Vector>(
909 epetra_x_dot_poly->setCoefficientPtr(i,epetra_ptr);
911 epetraInArgs->set_x_dot_poly(epetra_x_dot_poly);
916 inArgs.supports(IN_ARG_x_poly)
917 && (x_poly = inArgs.get_x_poly()).
get()
921 rcp(
new Polynomial<Epetra_Vector>(x_poly->degree()));
922 for (
unsigned int i=0; i<=x_poly->degree(); i++) {
923 epetra_ptr = rcp_const_cast<Epetra_Vector>(
925 epetra_x_poly->setCoefficientPtr(i,epetra_ptr);
927 epetraInArgs->set_x_poly(epetra_x_poly);
930 #endif // HAVE_THYRA_ME_POLYNOMIAL
932 if( inArgs.supports(IN_ARG_t) )
933 epetraInArgs->set_t(inArgs.get_t());
935 if( inArgs.supports(IN_ARG_alpha) )
936 epetraInArgs->set_alpha(inArgs.get_alpha());
938 if( inArgs.supports(IN_ARG_beta) )
939 epetraInArgs->set_beta(inArgs.get_beta());
941 if( inArgs.supports(IN_ARG_step_size) )
942 epetraInArgs->set_step_size(inArgs.get_step_size());
944 if( inArgs.supports(IN_ARG_stage_number) )
945 epetraInArgs->set_stage_number(inArgs.get_stage_number());
950 const ModelEvaluatorBase::OutArgs<double> &outArgs,
951 EpetraExt::ModelEvaluator::OutArgs *epetraUnscaledOutArgs_inout,
952 RCP<LinearOpBase<double> > *W_op_out,
959 using Teuchos::rcp_const_cast;
960 using Teuchos::rcp_dynamic_cast;
975 EpetraExt::ModelEvaluator::OutArgs &epetraUnscaledOutArgs = *epetraUnscaledOutArgs_inout;
983 if( outArgs.supports(OUT_ARG_f) && (f = outArgs.get_f()).
get() )
986 if( outArgs.supports(OUT_ARG_f_mp) && (f_mp = outArgs.get_f_mp()).
get() )
987 epetraUnscaledOutArgs.set_f_mp(f_mp);
993 for(
int j = 0; j < outArgs.Ng(); ++j ) {
994 g_j = outArgs.get_g(j);
998 for(
int j = 0; j < outArgs.Ng(); ++j ) {
999 if (outArgs.supports(OUT_ARG_g_mp,j)) {
1000 g_mp_j = outArgs.get_g_mp(j);
1001 if(g_mp_j.
get()) epetraUnscaledOutArgs.set_g_mp(j,g_mp_j);
1009 if( outArgs.supports(OUT_ARG_W_mp) && (W_mp = outArgs.get_W_mp()).
get() )
1010 epetraUnscaledOutArgs.set_W_mp(W_mp);
1016 if (outArgs.supports(OUT_ARG_W_op) &&
nonnull(W_op = outArgs.get_W_op())) {
1028 eW = efwdW->epetra_op();
1029 epetraUnscaledOutArgs.set_W(eW);
1038 Derivative<double> DfDp_l;
1039 for(
int l = 0; l < outArgs.Np(); ++l ) {
1040 if( !outArgs.supports(OUT_ARG_DfDp,l).none()
1041 && !(DfDp_l = outArgs.get_DfDp(l)).isEmpty() )
1046 MPDerivative DfDp_mp_l;
1047 for(
int l = 0; l < outArgs.Np(); ++l ) {
1048 if( !outArgs.supports(OUT_ARG_DfDp_mp,l).none()
1049 && !(DfDp_mp_l = outArgs.get_DfDp_mp(l)).isEmpty() )
1058 Derivative<double> DgDx_dot_j;
1059 for(
int j = 0; j < outArgs.Ng(); ++j ) {
1060 if( !outArgs.supports(OUT_ARG_DgDx_dot,j).none()
1061 && !(DgDx_dot_j = outArgs.get_DgDx_dot(j)).isEmpty() )
1066 MPDerivative DgDx_dot_mp_j;
1067 for(
int j = 0; j < outArgs.Ng(); ++j ) {
1068 if( !outArgs.supports(OUT_ARG_DgDx_dot_mp,j).none()
1069 && !(DgDx_dot_mp_j = outArgs.get_DgDx_dot_mp(j)).isEmpty() )
1078 Derivative<double> DgDx_j;
1079 for(
int j = 0; j < outArgs.Ng(); ++j ) {
1080 if( !outArgs.supports(OUT_ARG_DgDx,j).none()
1081 && !(DgDx_j = outArgs.get_DgDx(j)).isEmpty() )
1086 MPDerivative DgDx_mp_j;
1087 for(
int j = 0; j < outArgs.Ng(); ++j ) {
1088 if( !outArgs.supports(OUT_ARG_DgDx_mp,j).none()
1089 && !(DgDx_mp_j = outArgs.get_DgDx_mp(j)).isEmpty() )
1098 DerivativeSupport DgDp_j_l_support;
1099 Derivative<double> DgDp_j_l;
1100 for (
int j = 0; j < outArgs.Ng(); ++j ) {
1101 for (
int l = 0; l < outArgs.Np(); ++l ) {
1102 if (!(DgDp_j_l_support = outArgs.supports(OUT_ARG_DgDp,j,l)).none()
1103 && !(DgDp_j_l = outArgs.get_DgDp(j,l)).isEmpty() )
1109 DerivativeSupport DgDp_mp_j_l_support;
1110 MPDerivative DgDp_mp_j_l;
1111 for (
int j = 0; j < outArgs.Ng(); ++j ) {
1112 for (
int l = 0; l < outArgs.Np(); ++l ) {
1113 if (!(DgDp_mp_j_l_support = outArgs.supports(OUT_ARG_DgDp_mp,j,l)).none()
1114 && !(DgDp_mp_j_l = outArgs.get_DgDp_mp(j,l)).isEmpty() )
1122 #ifdef HAVE_THYRA_ME_POLYNOMIAL
1126 if( outArgs.supports(OUT_ARG_f_poly) && (f_poly = outArgs.get_f_poly()).
get() )
1130 for (
unsigned int i=0; i<=f_poly->degree(); i++) {
1133 f_poly->getCoefficient(i)));
1134 epetra_f_poly->setCoefficientPtr(i,epetra_ptr);
1136 epetraUnscaledOutArgs.set_f_poly(epetra_f_poly);
1139 #endif // HAVE_THYRA_ME_POLYNOMIAL
1145 EpetraExt::ModelEvaluator::InArgs *epetraInArgs_inout,
1146 EpetraExt::ModelEvaluator::OutArgs *epetraUnscaledOutArgs_inout,
1152 typedef EpetraExt::ModelEvaluator EME;
1154 #ifdef TEUCHOS_DEBUG
1159 EpetraExt::ModelEvaluator::InArgs
1160 &epetraInArgs = *epetraInArgs_inout;
1161 EpetraExt::ModelEvaluator::OutArgs
1162 &epetraUnscaledOutArgs = *epetraUnscaledOutArgs_inout;
1168 epetraUnscaledOutArgs.supports(EME::OUT_ARG_f)
1170 epetraUnscaledOutArgs.funcOrDerivesAreSet(EME::OUT_ARG_f)
1174 epetraUnscaledOutArgs.supports(EME::OUT_ARG_W)
1176 is_null(epetraUnscaledOutArgs.get_W())
1191 <<
"\nCreating a temporary Epetra W to compute scale factors"
1192 <<
" for f(...) ...\n";
1193 epetraUnscaledOutArgs.set_W(create_and_assert_W(*
epetraModel_));
1194 if( epetraInArgs.supports(EME::IN_ARG_beta) )
1195 epetraInArgs.set_beta(1.0);
1196 if( epetraInArgs.supports(EME::IN_ARG_alpha) )
1197 epetraInArgs.set_alpha(0.0);
1198 if( epetraInArgs.supports(EME::IN_ARG_step_size) )
1199 epetraInArgs.set_step_size(0.0);
1200 if( epetraInArgs.supports(EME::IN_ARG_stage_number) )
1201 epetraInArgs.set_stage_number(1.0);
1208 const EpetraExt::ModelEvaluator::OutArgs &epetraUnscaledOutArgs,
1216 using Teuchos::rcp_const_cast;
1227 ermW = get_Epetra_RowMatrix(epetraUnscaledOutArgs);
1234 invRowSums =
rcp(
new Epetra_Vector(ermW->OperatorRangeMap()));
1238 ermW->InvRowSums(*invRowSums);
1242 <<
"\nComputed inverse row sum scaling from W that"
1243 " will be used to scale f(...) and its derivatives:\n";
1244 double minVal = 0, maxVal = 0, avgVal = 0;
1245 invRowSums->MinValue(&minVal);
1246 invRowSums->MaxValue(&maxVal);
1247 invRowSums->MeanValue(&avgVal);
1250 <<
"min(invRowSums) = " << minVal <<
"\n"
1251 <<
"max(invRowSums) = " << maxVal <<
"\n"
1252 <<
"avg(invRowSums) = " << avgVal <<
"\n";
1275 const EpetraExt::ModelEvaluator::OutArgs &,
1276 RCP<LinearOpBase<double> > &W_op,
1279 const ModelEvaluatorBase::OutArgs<double> &
1283 using Teuchos::rcp_dynamic_cast;
1287 efwdW->setFullyInitialized(
true);
1292 if (W_op.shares_resource(efwdW)) {
1296 rcp_dynamic_cast<
EpetraLinearOp>(W_op,
true)->setFullyInitialized(
true);
1309 typedef EpetraExt::ModelEvaluator EME;
1315 EME::InArgs epetraOrigNominalValues;
1316 EpetraExt::gatherModelNominalValues(
1319 EME::InArgs epetraOrigLowerBounds;
1320 EME::InArgs epetraOrigUpperBounds;
1321 EpetraExt::gatherModelBounds(
1322 *
epetraModel_, &epetraOrigLowerBounds, &epetraOrigUpperBounds );
1331 if( epetraOrigNominalValues.supports(EME::IN_ARG_x_dot) ) {
1334 if( epetraOrigNominalValues.supports(EME::IN_ARG_x) ) {
1341 EME::InArgs epetraScaledNominalValues =
epetraModel_->createInArgs();
1342 EpetraExt::scaleModelVars(
1346 EME::InArgs epetraScaledLowerBounds =
epetraModel_->createInArgs();
1347 EME::InArgs epetraScaledUpperBounds =
epetraModel_->createInArgs();
1348 EpetraExt::scaleModelBounds(
1349 epetraOrigLowerBounds, epetraOrigUpperBounds,
epetraModel_->getInfBound(),
1351 &epetraScaledLowerBounds, &epetraScaledUpperBounds
1379 typedef EpetraExt::ModelEvaluator EME;
1381 const EpetraExt::ModelEvaluator &epetraModel = *
epetraModel_;
1382 EME::InArgs epetraInArgs = epetraModel.createInArgs();
1383 EME::OutArgs epetraOutArgs = epetraModel.createOutArgs();
1384 const int l_Np = epetraOutArgs.Np();
1385 const int l_Ng = epetraOutArgs.Ng();
1391 InArgsSetup<double> inArgs;
1392 inArgs.setModelEvalDescription(this->
description());
1393 inArgs.set_Np(epetraInArgs.Np());
1394 inArgs.setSupports(IN_ARG_x_dot, epetraInArgs.supports(EME::IN_ARG_x_dot));
1395 inArgs.setSupports(IN_ARG_x, epetraInArgs.supports(EME::IN_ARG_x));
1396 inArgs.setSupports(IN_ARG_x_dot_mp, epetraInArgs.supports(EME::IN_ARG_x_dot_mp));
1397 inArgs.setSupports(IN_ARG_x_mp, epetraInArgs.supports(EME::IN_ARG_x_mp));
1398 #ifdef HAVE_THYRA_ME_POLYNOMIAL
1399 inArgs.setSupports(IN_ARG_x_dot_poly,
1400 epetraInArgs.supports(EME::IN_ARG_x_dot_poly));
1401 inArgs.setSupports(IN_ARG_x_poly, epetraInArgs.supports(EME::IN_ARG_x_poly));
1402 #endif // HAVE_THYRA_ME_POLYNOMIAL
1403 inArgs.setSupports(IN_ARG_t, epetraInArgs.supports(EME::IN_ARG_t));
1404 inArgs.setSupports(IN_ARG_alpha, epetraInArgs.supports(EME::IN_ARG_alpha));
1405 inArgs.setSupports(IN_ARG_beta, epetraInArgs.supports(EME::IN_ARG_beta));
1406 inArgs.setSupports(IN_ARG_step_size, epetraInArgs.supports(EME::IN_ARG_step_size));
1407 inArgs.setSupports(IN_ARG_stage_number, epetraInArgs.supports(EME::IN_ARG_stage_number));
1408 for(
int l=0; l<l_Np; ++l) {
1409 inArgs.setSupports(IN_ARG_p_mp, l, epetraInArgs.supports(EME::IN_ARG_p_mp, l));
1417 OutArgsSetup<double> outArgs;
1418 outArgs.setModelEvalDescription(this->
description());
1419 outArgs.set_Np_Ng(l_Np, l_Ng);
1421 outArgs.setSupports(OUT_ARG_f, epetraOutArgs.supports(EME::OUT_ARG_f));
1422 outArgs.setSupports(OUT_ARG_f_mp, epetraOutArgs.supports(EME::OUT_ARG_f_mp));
1423 if (outArgs.supports(OUT_ARG_f)) {
1425 outArgs.setSupports(OUT_ARG_W_op, epetraOutArgs.supports(EME::OUT_ARG_W));
1426 outArgs.set_W_properties(
convert(epetraOutArgs.get_W_properties()));
1428 for(
int l=0; l<l_Np; ++l) {
1429 outArgs.setSupports(OUT_ARG_DfDp, l,
1430 convert(epetraOutArgs.supports(EME::OUT_ARG_DfDp, l)));
1431 if(!outArgs.supports(OUT_ARG_DfDp, l).none())
1432 outArgs.set_DfDp_properties(l,
1433 convert(epetraOutArgs.get_DfDp_properties(l)));
1434 if (outArgs.supports(OUT_ARG_f_mp))
1436 outArgs.setSupports(OUT_ARG_DfDp_mp, l,
1437 convert(epetraOutArgs.supports(EME::OUT_ARG_DfDp_mp, l)));
1438 if(!outArgs.supports(OUT_ARG_DfDp_mp, l).none())
1439 outArgs.set_DfDp_mp_properties(l,
1440 convert(epetraOutArgs.get_DfDp_mp_properties(l)));
1445 for(
int j=0; j<l_Ng; ++j) {
1446 if (inArgs.supports(IN_ARG_x_dot))
1447 outArgs.setSupports(OUT_ARG_DgDx_dot, j,
1448 convert(epetraOutArgs.supports(EME::OUT_ARG_DgDx_dot, j)));
1449 if(!outArgs.supports(OUT_ARG_DgDx_dot, j).none())
1450 outArgs.set_DgDx_dot_properties(j,
1451 convert(epetraOutArgs.get_DgDx_dot_properties(j)));
1452 if (inArgs.supports(IN_ARG_x))
1453 outArgs.setSupports(OUT_ARG_DgDx, j,
1454 convert(epetraOutArgs.supports(EME::OUT_ARG_DgDx, j)));
1455 if(!outArgs.supports(OUT_ARG_DgDx, j).none())
1456 outArgs.set_DgDx_properties(j,
1457 convert(epetraOutArgs.get_DgDx_properties(j)));
1458 if (inArgs.supports(IN_ARG_x_dot_mp))
1459 outArgs.setSupports(OUT_ARG_DgDx_dot_mp, j,
1460 convert(epetraOutArgs.supports(EME::OUT_ARG_DgDx_dot_mp, j)));
1461 if(!outArgs.supports(OUT_ARG_DgDx_dot_mp, j).none())
1462 outArgs.set_DgDx_dot_mp_properties(j,
1463 convert(epetraOutArgs.get_DgDx_dot_mp_properties(j)));
1464 if (inArgs.supports(IN_ARG_x_mp))
1465 outArgs.setSupports(OUT_ARG_DgDx_mp, j,
1466 convert(epetraOutArgs.supports(EME::OUT_ARG_DgDx_mp, j)));
1467 if(!outArgs.supports(OUT_ARG_DgDx_mp, j).none())
1468 outArgs.set_DgDx_mp_properties(j,
1469 convert(epetraOutArgs.get_DgDx_mp_properties(j)));
1472 for(
int j=0; j < l_Ng; ++j)
for(
int l=0; l < l_Np; ++l) {
1473 const EME::DerivativeSupport epetra_DgDp_j_l_support =
1474 epetraOutArgs.supports(EME::OUT_ARG_DgDp, j, l);
1475 outArgs.setSupports(OUT_ARG_DgDp, j, l,
1476 convert(epetra_DgDp_j_l_support));
1477 if(!outArgs.supports(OUT_ARG_DgDp, j, l).none())
1478 outArgs.set_DgDp_properties(j, l,
1479 convert(epetraOutArgs.get_DgDp_properties(j, l)));
1480 const EME::DerivativeSupport epetra_DgDp_mp_j_l_support =
1481 epetraOutArgs.supports(EME::OUT_ARG_DgDp_mp, j, l);
1482 outArgs.setSupports(OUT_ARG_DgDp_mp, j, l,
1483 convert(epetra_DgDp_mp_j_l_support));
1484 if(!outArgs.supports(OUT_ARG_DgDp_mp, j, l).none())
1485 outArgs.set_DgDp_mp_properties(j, l,
1486 convert(epetraOutArgs.get_DgDp_mp_properties(j, l)));
1488 for(
int j=0; j<l_Ng; ++j) {
1489 outArgs.setSupports(OUT_ARG_g_mp, j, epetraOutArgs.supports(EME::OUT_ARG_g_mp, j));
1491 #ifdef HAVE_THYRA_ME_POLYNOMIAL
1492 outArgs.setSupports(OUT_ARG_f_poly,
1493 epetraOutArgs.supports(EME::OUT_ARG_f_poly));
1494 #endif // HAVE_THYRA_ME_POLYNOMIAL
1506 return Thyra::partialNonconstEpetraLinearOp(
1522 Thyra::epetraModelEvaluator(
1523 const RCP<const EpetraExt::ModelEvaluator> &epetraModel,
1524 const RCP<LinearOpWithSolveFactoryBase<double> > &W_factory
1527 return Teuchos::rcp(
new EpetraModelEvaluator(epetraModel,W_factory));
1531 Thyra::ModelEvaluatorBase::EDerivativeMultiVectorOrientation
1533 const EpetraExt::ModelEvaluator::EDerivativeMultiVectorOrientation &mvOrientation
1536 switch(mvOrientation) {
1537 case EpetraExt::ModelEvaluator::DERIV_MV_BY_COL :
1538 return ModelEvaluatorBase::DERIV_MV_BY_COL;
1539 case EpetraExt::ModelEvaluator::DERIV_TRANS_MV_BY_ROW :
1540 return ModelEvaluatorBase::DERIV_TRANS_MV_BY_ROW;
1548 EpetraExt::ModelEvaluator::EDerivativeMultiVectorOrientation
1550 const ModelEvaluatorBase::EDerivativeMultiVectorOrientation &mvOrientation
1553 switch(mvOrientation) {
1554 case ModelEvaluatorBase::DERIV_MV_BY_COL :
1555 return EpetraExt::ModelEvaluator::DERIV_MV_BY_COL;
1556 case ModelEvaluatorBase::DERIV_TRANS_MV_BY_ROW :
1557 return EpetraExt::ModelEvaluator::DERIV_TRANS_MV_BY_ROW;
1565 Thyra::ModelEvaluatorBase::DerivativeProperties
1567 const EpetraExt::ModelEvaluator::DerivativeProperties &derivativeProperties
1570 ModelEvaluatorBase::EDerivativeLinearity linearity;
1571 switch(derivativeProperties.linearity) {
1572 case EpetraExt::ModelEvaluator::DERIV_LINEARITY_UNKNOWN:
1573 linearity = ModelEvaluatorBase::DERIV_LINEARITY_UNKNOWN;
1575 case EpetraExt::ModelEvaluator::DERIV_LINEARITY_CONST:
1576 linearity = ModelEvaluatorBase::DERIV_LINEARITY_CONST;
1578 case EpetraExt::ModelEvaluator::DERIV_LINEARITY_NONCONST:
1579 linearity = ModelEvaluatorBase::DERIV_LINEARITY_NONCONST;
1584 ModelEvaluatorBase::ERankStatus rank;
1585 switch(derivativeProperties.rank) {
1586 case EpetraExt::ModelEvaluator::DERIV_RANK_UNKNOWN:
1587 rank = ModelEvaluatorBase::DERIV_RANK_UNKNOWN;
1589 case EpetraExt::ModelEvaluator::DERIV_RANK_FULL:
1590 rank = ModelEvaluatorBase::DERIV_RANK_FULL;
1592 case EpetraExt::ModelEvaluator::DERIV_RANK_DEFICIENT:
1593 rank = ModelEvaluatorBase::DERIV_RANK_DEFICIENT;
1598 return ModelEvaluatorBase::DerivativeProperties(
1599 linearity,rank,derivativeProperties.supportsAdjoint);
1603 Thyra::ModelEvaluatorBase::DerivativeSupport
1605 const EpetraExt::ModelEvaluator::DerivativeSupport &derivativeSupport
1608 ModelEvaluatorBase::DerivativeSupport ds;
1609 if(derivativeSupport.supports(EpetraExt::ModelEvaluator::DERIV_LINEAR_OP))
1610 ds.plus(ModelEvaluatorBase::DERIV_LINEAR_OP);
1611 if(derivativeSupport.supports(EpetraExt::ModelEvaluator::DERIV_MV_BY_COL))
1612 ds.plus(ModelEvaluatorBase::DERIV_MV_BY_COL);
1613 if(derivativeSupport.supports(EpetraExt::ModelEvaluator::DERIV_TRANS_MV_BY_ROW))
1614 ds.plus(ModelEvaluatorBase::DERIV_TRANS_MV_BY_ROW);
1619 EpetraExt::ModelEvaluator::Derivative
1621 const ModelEvaluatorBase::Derivative<double> &derivative,
1622 const RCP<const Epetra_Map> &fnc_map,
1623 const RCP<const Epetra_Map> &var_map
1626 typedef ModelEvaluatorBase MEB;
1627 if(derivative.getLinearOp().get()) {
1628 return EpetraExt::ModelEvaluator::Derivative(
1629 Teuchos::rcp_const_cast<Epetra_Operator>(
1630 Teuchos::dyn_cast<const EpetraLinearOp>(*derivative.getLinearOp()).epetra_op()
1634 else if(derivative.getDerivativeMultiVector().getMultiVector().get()) {
1635 return EpetraExt::ModelEvaluator::Derivative(
1636 EpetraExt::ModelEvaluator::DerivativeMultiVector(
1638 ( derivative.getDerivativeMultiVector().getOrientation() == MEB::DERIV_MV_BY_COL
1642 ,derivative.getDerivativeMultiVector().getMultiVector()
1644 ,
convert(derivative.getDerivativeMultiVector().getOrientation())
1648 return EpetraExt::ModelEvaluator::Derivative();
1650 EpetraExt::ModelEvaluator::MPDerivative
1652 const ModelEvaluatorBase::MPDerivative &derivative,
1658 if(derivative.getLinearOp().get()) {
1659 return EpetraExt::ModelEvaluator::MPDerivative(
1660 derivative.getLinearOp()
1663 else if(derivative.getDerivativeMultiVector().getMultiVector().get()) {
1664 return EpetraExt::ModelEvaluator::MPDerivative(
1665 EpetraExt::ModelEvaluator::MPDerivativeMultiVector(
1666 derivative.getDerivativeMultiVector().getMultiVector()
1667 ,
convert(derivative.getDerivativeMultiVector().getOrientation())
1671 return EpetraExt::ModelEvaluator::MPDerivative();
RCP< Epetra_MultiVector > get_Epetra_MultiVector(const Epetra_Map &map, const RCP< MultiVectorBase< double > > &mv)
Get a non-const Epetra_MultiVector view from a non-const MultiVectorBase object if possible...
const ModelEvaluatorBase::InArgs< double > & getFinalPoint() const
ModelEvaluatorBase::InArgs< double > getLowerBounds() const
void setNominalValues(const ModelEvaluatorBase::InArgs< double > &nominalValues)
Set the nominal values.
void updateInArgsOutArgs() const
void convertInArgsFromEpetraToThyra(const EpetraExt::ModelEvaluator::InArgs &epetraInArgs, ModelEvaluatorBase::InArgs< double > *inArgs) const
Concrete LinearOpBase adapter subclass for Epetra_Operator object.
RCP< const EpetraExt::ModelEvaluator > getEpetraModel() const
RCP< const Epetra_Map > x_map_
std::string typeName(const T &t)
void reportFinalPoint(const ModelEvaluatorBase::InArgs< double > &finalPoint, const bool wasSolved)
bool is_null(const boost::shared_ptr< T > &p)
void preEvalScalingSetup(EpetraExt::ModelEvaluator::InArgs *epetraInArgs, EpetraExt::ModelEvaluator::OutArgs *epetraUnscaledOutArgs, const RCP< Teuchos::FancyOStream > &out, const Teuchos::EVerbosityLevel verbLevel) const
ModelEvaluatorBase::OutArgs< double > createOutArgsImpl() const
RCP< LinearOpBase< double > > create_DgDx_dot_op_impl(int j) const
RCP< const Teuchos::ParameterList > getValidParameters() const
RCP< LinearOpBase< double > > create_W_op() const
ModelEvaluatorBase::InArgs< double > getNominalValues() const
RCP< Teuchos::ParameterList > getNonconstParameterList()
p_map_is_local_t g_map_is_local_
RCP< LinearOpWithSolveFactoryBase< double > > W_factory_
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
RCP< const VectorSpaceBase< double > > create_VectorSpace(const RCP< const Epetra_Map > &epetra_map)
Create an VectorSpaceBase object given an Epetra_Map object.
EStateFunctionScaling stateFunctionScaling_
void convertOutArgsFromThyraToEpetra(const ModelEvaluatorBase::OutArgs< double > &outArgs, EpetraExt::ModelEvaluator::OutArgs *epetraUnscaledOutArgs, RCP< LinearOpBase< double > > *W_op, RCP< EpetraLinearOp > *efwdW, RCP< Epetra_Operator > *eW) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
RCP< PreconditionerBase< double > > create_W_prec() const
Returns null currently.
void setStateVariableScalingVec(const RCP< const Epetra_Vector > &stateVariableScalingVec)
Set the state variable scaling vector s_x (see above).
ModelEvaluatorBase::InArgs< double > createInArgs() const
basic_OSTab< char > OSTab
EpetraExt::ModelEvaluator::OutArgs epetraOutArgsScaling_
void convertInArgsFromThyraToEpetra(const ModelEvaluatorBase::InArgs< double > &inArgs, EpetraExt::ModelEvaluator::InArgs *epetraInArgs) const
RCP< const VectorSpaceBase< double > > x_space_
RCP< const Epetra_Vector > getStateVariableScalingVec() const
Get the inverse state variable scaling vector inv_s_x (see above).
ModelEvaluatorBase::OutArgs< double > prototypeOutArgs_
#define TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(index, lower_inclusive, upper_exclusive)
void start(bool reset=false)
RCP< const Teuchos::ParameterList > getParameterList() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
RCP< const LinearOpWithSolveFactoryBase< double > > get_W_factory() const
EpetraExt::ModelEvaluator::MPDerivative convert(const ModelEvaluatorBase::MPDerivative &derivative, const RCP< const Epetra_Map > &fnc_map, const RCP< const Epetra_Map > &var_map)
RCP< const Epetra_Vector > getStateVariableInvScalingVec() const
Get the state variable scaling vector s_x (see above).
RCP< VectorBase< double > > create_Vector(const RCP< Epetra_Vector > &epetra_v, const RCP< const VectorSpaceBase< double > > &space=Teuchos::null)
Create a non-const VectorBase object from a non-const Epetra_Vector object.
RCP< const VectorSpaceBase< double > > f_space_
ModelEvaluatorBase::InArgs< double > getUpperBounds() const
ModelEvaluatorBase::InArgs< double > finalPoint_
void setStateFunctionScalingVec(const RCP< const Epetra_Vector > &stateFunctionScalingVec)
Set the state function scaling vector s_f (see above).
RCP< LinearOpBase< double > > create_DgDx_op_impl(int j) const
bool finalPointWasSolved() const
ModelEvaluatorBase::InArgs< double > lowerBounds_
RCP< const Epetra_Vector > getStateFunctionScalingVec() const
Get the state function scaling vector s_f (see above).
RCP< Epetra_Vector > get_Epetra_Vector(const Epetra_Map &map, const RCP< VectorBase< double > > &v)
Get a non-const Epetra_Vector view from a non-const VectorBase object if possible.
RCP< EpetraLinearOp > create_epetra_W_op() const
void initialize(const RCP< const EpetraExt::ModelEvaluator > &epetraModel, const RCP< LinearOpWithSolveFactoryBase< double > > &W_factory)
RCP< const VectorSpaceBase< double > > get_f_space() const
void updateNominalValuesAndBounds() const
RCP< LinearOpBase< double > > create_DfDp_op_impl(int l) const
RCP< const VectorSpaceBase< double > > get_x_space() const
RCP< const VectorSpaceBase< double > > get_g_space(int j) const
EpetraExt::ModelEvaluator::InArgs epetraInArgsScaling_
RCP< const VectorSpaceBase< double > > get_p_space(int l) const
bool currentInArgsOutArgs_
void resize(size_type new_size, const value_type &x=value_type())
bool finalPointWasSolved_
RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
void setParameterList(RCP< Teuchos::ParameterList > const ¶mList)
TEUCHOSCORE_LIB_DLL_EXPORT bool includesVerbLevel(const EVerbosityLevel verbLevel, const EVerbosityLevel requestedVerbLevel, const bool isDefaultLevel=false)
TypeTo implicit_cast(const TypeFrom &t)
const RCP< T > & assert_not_null() const
RCP< LinearOpBase< double > > create_DgDp_op_impl(int j, int l) const
std::string description() const
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
RCP< const Epetra_Vector > stateFunctionScalingVec_
ModelEvaluatorBase::EDerivativeMultiVectorOrientation convert(const EpetraExt::ModelEvaluator::EDerivativeMultiVectorOrientation &mvOrientation)
void postEvalScalingSetup(const EpetraExt::ModelEvaluator::OutArgs &epetraUnscaledOutArgs, const RCP< Teuchos::FancyOStream > &out, const Teuchos::EVerbosityLevel verbLevel) const
void uninitialize(RCP< const EpetraExt::ModelEvaluator > *epetraModel=NULL, RCP< LinearOpWithSolveFactoryBase< double > > *W_factory=NULL)
bool nonnull(const boost::shared_ptr< T > &p)
Teuchos::ArrayView< const std::string > get_g_names(int j) const
void evalModelImpl(const ModelEvaluatorBase::InArgs< double > &inArgs, const ModelEvaluatorBase::OutArgs< double > &outArgs) const
bool nominalValuesAndBoundsAreUpdated_
void finishConvertingOutArgsFromEpetraToThyra(const EpetraExt::ModelEvaluator::OutArgs &epetraOutArgs, RCP< LinearOpBase< double > > &W_op, RCP< EpetraLinearOp > &efwdW, RCP< Epetra_Operator > &eW, const ModelEvaluatorBase::OutArgs< double > &outArgs) const
ModelEvaluatorBase::InArgs< double > prototypeInArgs_
RCP< const Epetra_Map > f_map_
double totalElapsedTime(bool readCurrentTime=false) const
RCP< const Epetra_Vector > stateVariableScalingVec_
RCP< const EpetraExt::ModelEvaluator > epetraModel_
RCP< Teuchos::ParameterList > paramList_
ModelEvaluatorBase::InArgs< double > nominalValues_
#define TEUCHOS_ASSERT(assertion_test)
p_map_is_local_t p_map_is_local_
RCP< Teuchos::ParameterList > unsetParameterList()
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
RCP< const Epetra_Vector > invStateVariableScalingVec_
ModelEvaluatorBase::InArgs< double > upperBounds_