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"
60const std::string StateFunctionScaling_name =
"State Function Scaling";
66stateFunctionScalingValidator;
67const 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>
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)
133 :nominalValuesAndBoundsAreUpdated_(
false), stateFunctionScaling_(STATE_FUNC_SCALING_NONE),
134 currentInArgsOutArgs_(
false), finalPointWasSolved_(
false)
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!");
272const ModelEvaluatorBase::InArgs<double>&
290 std::ostringstream
oss;
291 oss <<
"Thyra::EpetraModelEvaluator{";
292 oss <<
"epetraModel=";
297 oss <<
",W_factory=";
323 Teuchos::readVerboseObjectSublist(&*
paramList_,
this);
358 using Teuchos::tuple;
359 using Teuchos::rcp_implicit_cast;
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"
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"
393 Teuchos::setupVerboseObjectSublist(&*
pl);
467ModelEvaluatorBase::InArgs<double>
475ModelEvaluatorBase::InArgs<double>
483ModelEvaluatorBase::InArgs<double>
501 return Teuchos::null;
521 const ModelEvaluatorBase::InArgs<double> &
finalPoint,
566ModelEvaluatorBase::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;
611 if (
inArgs.supports(Thyra::ModelEvaluatorBase::IN_ARG_x_dot)) {
613 inArgs.set_x_dot(Teuchos::null);
617 typedef double Scalar;
644 *out <<
"\nSetting-up/creating input arguments ...\n";
654 EpetraExt::unscaleModelVars(
661 OSTab(out).o() <<
"\nTime to setup InArgs = "<<
timer.totalElapsedTime()<<
" sec\n";
668 *out <<
"\nSetting-up/creating output arguments ...\n";
700 <<
"\nTime to setup OutArgs = "
701 <<
timer.totalElapsedTime() <<
" sec\n";
708 *out <<
"\nEvaluating the Epetra output functions ...\n";
716 <<
"\nTime to evaluate Epetra output functions = "
717 <<
timer.totalElapsedTime() <<
" sec\n";
728 *out <<
"\nCompute scale factors if needed ...\n";
738 <<
"\nTime to compute scale factors = "
739 <<
timer.totalElapsedTime() <<
" sec\n";
746 *out <<
"\nScale the output objects ...\n";
751 EpetraExt::scaleModelFuncs(
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 = "
770 <<
timer.totalElapsedTime() <<
" sec\n";
778 *out <<
"\nFinish processing and wrapping the output objects ...\n";
789 <<
"\nTime to finish processing and wrapping the output objects = "
790 <<
timer.totalElapsedTime() <<
" sec\n";
806 ModelEvaluatorBase::InArgs<double> *
inArgs
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)) {
827 if(
inArgs->supports(MEB::IN_ARG_x_dot_mp)) {
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))
840 if(
inArgs->supports(MEB::IN_ARG_t)) {
848 const ModelEvaluatorBase::InArgs<double> &
inArgs,
854 using Teuchos::rcp_const_cast;
855#ifdef HAVE_THYRA_ME_POLYNOMIAL
895#ifdef HAVE_THYRA_ME_POLYNOMIAL
922 for (
unsigned int i=0;
i<=
x_poly->degree();
i++) {
950 const ModelEvaluatorBase::OutArgs<double> &
outArgs,
959 using Teuchos::rcp_const_cast;
960 using Teuchos::rcp_dynamic_cast;
1023 if (nonnull(
efwdW)) {
1122#ifdef HAVE_THYRA_ME_POLYNOMIAL
1130 for (
unsigned int i=0;
i<=
f_poly->degree();
i++) {
1152 typedef EpetraExt::ModelEvaluator
EME;
1159 EpetraExt::ModelEvaluator::InArgs
1161 EpetraExt::ModelEvaluator::OutArgs
1191 <<
"\nCreating a temporary Epetra W to compute scale factors"
1192 <<
" for f(...) ...\n";
1216 using Teuchos::rcp_const_cast;
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;
1250 <<
"min(invRowSums) = " << minVal <<
"\n"
1251 <<
"max(invRowSums) = " << maxVal <<
"\n"
1252 <<
"avg(invRowSums) = " <<
avgVal <<
"\n";
1275 const EpetraExt::ModelEvaluator::OutArgs &,
1279 const ModelEvaluatorBase::OutArgs<double> &
1283 using Teuchos::rcp_dynamic_cast;
1286 if (nonnull(
efwdW)) {
1287 efwdW->setFullyInitialized(
true);
1291 if (nonnull(
W_op)) {
1309 typedef EpetraExt::ModelEvaluator
EME;
1316 EpetraExt::gatherModelNominalValues(
1321 EpetraExt::gatherModelBounds(
1342 EpetraExt::scaleModelVars(
1348 EpetraExt::scaleModelBounds(
1379 typedef EpetraExt::ModelEvaluator
EME;
1398#ifdef HAVE_THYRA_ME_POLYNOMIAL
1462 outArgs.set_DgDx_dot_mp_properties(
j,
1491#ifdef HAVE_THYRA_ME_POLYNOMIAL
1506 return Thyra::partialNonconstEpetraLinearOp(
1522Thyra::epetraModelEvaluator(
1523 const RCP<const EpetraExt::ModelEvaluator> &epetraModel,
1524 const RCP<LinearOpWithSolveFactoryBase<double> > &W_factory
1527 return Teuchos::rcp(
new EpetraModelEvaluator(epetraModel,W_factory));
1531Thyra::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;
1548EpetraExt::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;
1565Thyra::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);
1603Thyra::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);
1619EpetraExt::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(
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();
1650EpetraExt::ModelEvaluator::MPDerivative
1652 const ModelEvaluatorBase::MPDerivative &
derivative,
1659 return EpetraExt::ModelEvaluator::MPDerivative(
1663 else if(
derivative.getDerivativeMultiVector().getMultiVector().
get()) {
1664 return EpetraExt::ModelEvaluator::MPDerivative(
1665 EpetraExt::ModelEvaluator::MPDerivativeMultiVector(
1666 derivative.getDerivativeMultiVector().getMultiVector()
1671 return EpetraExt::ModelEvaluator::MPDerivative();
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
void resize(size_type new_size, const value_type &x=value_type())
bool shares_resource(const RCP< T2 > &r_ptr) const
const RCP< T > & assert_not_null() const
RCP< Teuchos::ParameterList > unsetParameterList()
RCP< Teuchos::ParameterList > getNonconstParameterList()
bool finalPointWasSolved() const
void setStateFunctionScalingVec(const RCP< const Epetra_Vector > &stateFunctionScalingVec)
Set the state function scaling vector s_f (see above).
RCP< const Epetra_Vector > getStateFunctionScalingVec() const
Get the state function scaling vector s_f (see above).
RCP< LinearOpBase< double > > create_DgDx_op_impl(int j) const
RCP< const Epetra_Vector > invStateVariableScalingVec_
void updateNominalValuesAndBounds() const
EpetraExt::ModelEvaluator::InArgs epetraInArgsScaling_
ModelEvaluatorBase::InArgs< double > nominalValues_
std::string description() const
void initialize(const RCP< const EpetraExt::ModelEvaluator > &epetraModel, const RCP< LinearOpWithSolveFactoryBase< double > > &W_factory)
RCP< const VectorSpaceBase< double > > f_space_
ModelEvaluatorBase::InArgs< double > finalPoint_
RCP< const VectorSpaceBase< double > > get_f_space() const
RCP< LinearOpBase< double > > create_DgDp_op_impl(int j, int l) const
void setStateVariableScalingVec(const RCP< const Epetra_Vector > &stateVariableScalingVec)
Set the state variable scaling vector s_x (see above).
RCP< LinearOpBase< double > > create_W_op() const
ModelEvaluatorBase::InArgs< double > getUpperBounds() const
void setNominalValues(const ModelEvaluatorBase::InArgs< double > &nominalValues)
Set the nominal values.
p_map_is_local_t g_map_is_local_
RCP< PreconditionerBase< double > > create_W_prec() const
Returns null currently.
RCP< const Epetra_Map > x_map_
RCP< const EpetraExt::ModelEvaluator > epetraModel_
bool nominalValuesAndBoundsAreUpdated_
RCP< const LinearOpWithSolveFactoryBase< double > > get_W_factory() const
RCP< LinearOpBase< double > > create_DgDx_dot_op_impl(int j) const
ModelEvaluatorBase::InArgs< double > getNominalValues() const
RCP< LinearOpBase< double > > create_DfDp_op_impl(int l) const
p_map_is_local_t p_map_is_local_
ModelEvaluatorBase::InArgs< double > lowerBounds_
EpetraExt::ModelEvaluator::OutArgs epetraOutArgsScaling_
void postEvalScalingSetup(const EpetraExt::ModelEvaluator::OutArgs &epetraUnscaledOutArgs, const RCP< Teuchos::FancyOStream > &out, const Teuchos::EVerbosityLevel verbLevel) const
ModelEvaluatorBase::OutArgs< double > prototypeOutArgs_
void updateInArgsOutArgs() const
RCP< const Teuchos::ParameterList > getParameterList() const
void reportFinalPoint(const ModelEvaluatorBase::InArgs< double > &finalPoint, const bool wasSolved)
ModelEvaluatorBase::InArgs< double > createInArgs() const
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
void setParameterList(RCP< Teuchos::ParameterList > const ¶mList)
RCP< const VectorSpaceBase< double > > get_g_space(int j) const
void preEvalScalingSetup(EpetraExt::ModelEvaluator::InArgs *epetraInArgs, EpetraExt::ModelEvaluator::OutArgs *epetraUnscaledOutArgs, const RCP< Teuchos::FancyOStream > &out, const Teuchos::EVerbosityLevel verbLevel) const
RCP< const VectorSpaceBase< double > > x_space_
RCP< const EpetraExt::ModelEvaluator > getEpetraModel() const
ModelEvaluatorBase::OutArgs< double > createOutArgsImpl() const
bool currentInArgsOutArgs_
void uninitialize(RCP< const EpetraExt::ModelEvaluator > *epetraModel=NULL, RCP< LinearOpWithSolveFactoryBase< double > > *W_factory=NULL)
ModelEvaluatorBase::InArgs< double > prototypeInArgs_
void convertInArgsFromThyraToEpetra(const ModelEvaluatorBase::InArgs< double > &inArgs, EpetraExt::ModelEvaluator::InArgs *epetraInArgs) const
RCP< const VectorSpaceBase< double > > get_x_space() const
RCP< const Epetra_Map > f_map_
RCP< const Epetra_Vector > getStateVariableInvScalingVec() const
Get the state variable scaling vector s_x (see above).
ModelEvaluatorBase::InArgs< double > getLowerBounds() const
EStateFunctionScaling stateFunctionScaling_
void convertInArgsFromEpetraToThyra(const EpetraExt::ModelEvaluator::InArgs &epetraInArgs, ModelEvaluatorBase::InArgs< double > *inArgs) const
void convertOutArgsFromThyraToEpetra(const ModelEvaluatorBase::OutArgs< double > &outArgs, EpetraExt::ModelEvaluator::OutArgs *epetraUnscaledOutArgs, RCP< LinearOpBase< double > > *W_op, RCP< EpetraLinearOp > *efwdW, RCP< Epetra_Operator > *eW) const
@ STATE_FUNC_SCALING_NONE
@ STATE_FUNC_SCALING_ROW_SUM
RCP< const Epetra_Vector > getStateVariableScalingVec() const
Get the inverse state variable scaling vector inv_s_x (see above).
bool finalPointWasSolved_
void evalModelImpl(const ModelEvaluatorBase::InArgs< double > &inArgs, const ModelEvaluatorBase::OutArgs< double > &outArgs) const
RCP< const Teuchos::ParameterList > getValidParameters() const
Teuchos::ArrayView< const std::string > get_g_names(int j) const
RCP< const Epetra_Vector > stateFunctionScalingVec_
RCP< LinearOpWithSolveFactoryBase< double > > W_factory_
ModelEvaluatorBase::InArgs< double > upperBounds_
RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
RCP< EpetraLinearOp > create_epetra_W_op() const
RCP< Teuchos::ParameterList > paramList_
RCP< const VectorSpaceBase< double > > get_p_space(int l) const
const ModelEvaluatorBase::InArgs< double > & getFinalPoint() const
ModelEvaluatorBase::EDerivativeMultiVectorOrientation convert(const EpetraExt::ModelEvaluator::EDerivativeMultiVectorOrientation &mvOrientation)
RCP< const Epetra_Vector > stateVariableScalingVec_
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 > > create_VectorSpace(const RCP< const Epetra_Map > &epetra_map)
Create an VectorSpaceBase object given an Epetra_Map object.
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< 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.
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(index, lower_inclusive, upper_exclusive)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
bool is_null(const boost::shared_ptr< T > &p)
TypeTo implicit_cast(const TypeFrom &t)
std::string typeName(const T &t)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
TEUCHOSCORE_LIB_DLL_EXPORT bool includesVerbLevel(const EVerbosityLevel verbLevel, const EVerbosityLevel requestedVerbLevel, const bool isDefaultLevel=false)
EpetraExt::ModelEvaluator::MPDerivative convert(const ModelEvaluatorBase::MPDerivative &derivative, const RCP< const Epetra_Map > &fnc_map, const RCP< const Epetra_Map > &var_map)