29 #ifndef RYTHMOS_FORWARD_SENSITIVITY_STEPPER_HPP
30 #define RYTHMOS_FORWARD_SENSITIVITY_STEPPER_HPP
33 #include "Rythmos_StepperBase.hpp"
34 #include "Rythmos_StepperHelpers.hpp"
35 #include "Rythmos_ForwardSensitivityModelEvaluatorBase.hpp"
36 #include "Rythmos_ForwardSensitivityImplicitModelEvaluator.hpp"
37 #include "Rythmos_ForwardSensitivityExplicitModelEvaluator.hpp"
38 #include "Rythmos_StateAndForwardSensitivityModelEvaluator.hpp"
39 #include "Rythmos_SolverAcceptingStepperBase.hpp"
40 #include "Rythmos_IntegratorBase.hpp"
41 #include "Rythmos_SingleResidualModelEvaluatorBase.hpp"
42 #include "Thyra_ModelEvaluatorHelpers.hpp"
43 #include "Thyra_LinearNonlinearSolver.hpp"
44 #include "Thyra_ProductVectorBase.hpp"
45 #include "Thyra_AssertOp.hpp"
46 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp"
47 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
48 #include "Teuchos_ConstNonconstObjectContainer.hpp"
49 #include "Teuchos_Assert.hpp"
50 #include "Teuchos_as.hpp"
208 template<
class Scalar>
211 virtual public Teuchos::ParameterListAcceptorDefaultBase
216 typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType
ScalarMag;
278 const RCP<
const Thyra::ModelEvaluator<Scalar> > &stateModel,
280 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &stateBasePoint,
282 const RCP<Thyra::NonlinearSolverBase<Scalar> > &stateTimeStepSolver,
284 const RCP<Thyra::NonlinearSolverBase<Scalar> > &sensTimeStepSolver = Teuchos::null
312 const RCP<
const Thyra::ModelEvaluator<Scalar> >& stateModel,
313 const RCP<
const Thyra::VectorSpaceBase<Scalar> >& p_space,
314 const Thyra::ModelEvaluatorBase::InArgs<Scalar>& stateBasePoint,
316 const RCP<Thyra::NonlinearSolverBase<Scalar> >& stateTimeStepSolver,
318 const RCP<Thyra::NonlinearSolverBase<Scalar> >& sensTimeStepSolver = Teuchos::null
357 const RCP<
const Thyra::ModelEvaluator<Scalar> > &stateModel,
359 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &stateBasePoint,
361 const RCP<Thyra::NonlinearSolverBase<Scalar> > &stateTimeStepSolver,
363 const Scalar &finalTime,
365 const RCP<Thyra::NonlinearSolverBase<Scalar> > &sensTimeStepSolver = Teuchos::null
374 RCP<const Thyra::ModelEvaluator<Scalar> >
380 RCP<StepperBase<Scalar> >
386 RCP<const ForwardSensitivityModelEvaluatorBase<Scalar> >
395 RCP<const StateAndForwardSensitivityModelEvaluator<Scalar> >
418 const RCP<
const Thyra::ModelEvaluator<Scalar> >& model
423 const RCP<Thyra::ModelEvaluator<Scalar> >& model
432 RCP<const Thyra::ModelEvaluator<Scalar> >
getModel()
const;
459 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &state_and_sens_ic
466 Scalar
takeStep( Scalar dt, StepSizeType stepType );
482 RCP<const Thyra::VectorSpaceBase<Scalar> >
487 const Array<Scalar>& time_vec,
488 const Array<Teuchos::RCP<
const Thyra::VectorBase<Scalar> > >& x_vec,
489 const Array<Teuchos::RCP<
const Thyra::VectorBase<Scalar> > >& xdot_vec
497 const Array<Scalar>& time_vec,
498 Array<RCP<
const Thyra::VectorBase<Scalar> > >* x_vec,
499 Array<RCP<
const Thyra::VectorBase<Scalar> > >* xdot_vec,
500 Array<ScalarMag>* accuracy_vec
504 void getNodes(Array<Scalar>* time_vec)
const;
519 const RCP<
const Thyra::ModelEvaluator<Scalar> > &stateModel,
521 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &stateBasePoint,
523 const RCP<Thyra::NonlinearSolverBase<Scalar> > &stateTimeStepSolver,
525 const RCP<Thyra::NonlinearSolverBase<Scalar> > &sensTimeStepSolver = Teuchos::null
529 stateModel, p_index, stateBasePoint, stateStepper, stateTimeStepSolver,
530 sensStepper, sensTimeStepSolver
540 typedef Teuchos::ConstNonconstObjectContainer<Thyra::ModelEvaluator<Scalar> > CNCME;
545 bool forceUpToDateW_;
547 Thyra::ModelEvaluatorBase::InArgs<Scalar> stateBasePoint_;
548 RCP<StepperBase<Scalar> > stateStepper_;
549 RCP<Thyra::NonlinearSolverBase<Scalar> > stateTimeStepSolver_;
550 RCP<IntegratorBase<Scalar> > stateIntegrator_;
552 Thyra::ModelEvaluatorBase::InArgs<Scalar> stateAndSensBasePoint_;
553 RCP<StepperBase<Scalar> > sensStepper_;
554 RCP<Thyra::NonlinearSolverBase<Scalar> > sensTimeStepSolver_;
556 bool isSingleResidualStepper_;
557 RCP<ForwardSensitivityModelEvaluatorBase<Scalar> > sensModel_;
558 RCP<StateAndForwardSensitivityModelEvaluator<Scalar> > stateAndSensModel_;
559 Thyra::ModelEvaluatorBase::InArgs<Scalar> stateBasePoint_t_;
561 static const std::string forceUpToDateW_name_;
562 static const bool forceUpToDateW_default_;
573 void initializeCommon(
574 const RCP<
const Thyra::ModelEvaluator<Scalar> > &stateModel,
576 const RCP<
const Thyra::VectorSpaceBase<Scalar> > &p_space,
577 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &stateBasePoint,
579 const RCP<Thyra::NonlinearSolverBase<Scalar> > &stateTimeStepSolver,
581 const RCP<Thyra::NonlinearSolverBase<Scalar> > &sensTimeStepSolver
584 Scalar takeSyncedStep( Scalar dt, StepSizeType stepType );
586 Scalar takeDecoupledStep( Scalar dt, StepSizeType stepType );
614 template<
class Scalar>
616 RCP<ForwardSensitivityStepper<Scalar> >
627 template<
class Scalar>
629 RCP<ForwardSensitivityStepper<Scalar> >
631 const RCP<
const Thyra::ModelEvaluator<Scalar> > &stateModel,
633 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &stateBasePoint,
635 const RCP<Thyra::NonlinearSolverBase<Scalar> > &stateTimeStepSolver,
637 const RCP<Thyra::NonlinearSolverBase<Scalar> > &sensTimeStepSolver = Teuchos::null
640 RCP<ForwardSensitivityStepper<Scalar> >
642 fwdSensStepper->initializeSyncedSteppers(
643 stateModel, p_index, stateBasePoint, stateStepper, stateTimeStepSolver );
644 return fwdSensStepper;
653 template<
class Scalar>
668 template<
class Scalar>
670 Thyra::ModelEvaluatorBase::InArgs<Scalar>
673 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &state_ic,
674 const RCP<
const Thyra::MultiVectorBase<Scalar> > S_init = Teuchos::null,
675 const RCP<
const Thyra::MultiVectorBase<Scalar> > S_dot_init = Teuchos::null
679 using Teuchos::outArg;
681 typedef Thyra::ModelEvaluatorBase MEB;
683 RCP<const Thyra::VectorBase<Scalar> > s_bar_init;
684 if (nonnull(S_init)) {
685 s_bar_init = create_s_bar_given_S(*fwdSensStepper.
getFwdSensModel(), S_init);
688 RCP<Thyra::VectorBase<Scalar> > s_bar_init_loc =
690 assign( outArg(*s_bar_init_loc), 0.0 );
691 s_bar_init = s_bar_init_loc;
694 RCP<const Thyra::VectorBase<Scalar> > s_bar_dot_init;
695 if (nonnull(S_dot_init)) {
696 s_bar_dot_init = create_s_bar_given_S(*fwdSensStepper.
getFwdSensModel(), S_dot_init);
699 RCP<Thyra::VectorBase<Scalar> > s_bar_dot_init_loc =
701 assign( outArg(*s_bar_dot_init_loc), 0.0 );
702 s_bar_dot_init = s_bar_dot_init_loc;
705 RCP<const Rythmos::StateAndForwardSensitivityModelEvaluator<Scalar> >
709 state_and_sens_ic = fwdSensStepper.
getModel()->createInArgs();
712 state_and_sens_ic.setArgs(state_ic);
714 state_and_sens_ic.set_x(
715 stateAndSensModel->create_x_bar_vec(state_ic.get_x(), s_bar_init)
718 state_and_sens_ic.set_x_dot(
719 stateAndSensModel->create_x_bar_vec(state_ic.get_x_dot(), s_bar_dot_init)
722 return state_and_sens_ic;
732 template<
class Scalar>
734 Thyra::ModelEvaluatorBase::InArgs<Scalar>
737 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &state_and_sens_ic
741 using Thyra::productVectorBase;
742 typedef Thyra::ModelEvaluatorBase MEB;
748 state_ic.setArgs(state_and_sens_ic);
750 productVectorBase(state_and_sens_ic.get_x())->getVectorBlock(0));
752 productVectorBase(state_and_sens_ic.get_x_dot())->getVectorBlock(0));
767 template<
class Scalar>
769 =
"Force Up-To-Date Jacobian";
771 template<
class Scalar>
779 template<
class Scalar>
781 :forceUpToDateW_(false),
782 isSingleResidualStepper_(false)
786 template<
class Scalar>
788 const RCP<
const Thyra::ModelEvaluator<Scalar> > &stateModel,
790 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &stateBasePoint,
792 const RCP<Thyra::NonlinearSolverBase<Scalar> > &stateTimeStepSolver,
794 const RCP<Thyra::NonlinearSolverBase<Scalar> > &sensTimeStepSolver
798 initializeCommon( stateModel, p_index, Teuchos::null, stateBasePoint, stateStepper,
799 stateTimeStepSolver, sensStepper, sensTimeStepSolver );
803 template<
class Scalar>
805 const RCP<
const Thyra::ModelEvaluator<Scalar> >& stateModel,
806 const RCP<
const Thyra::VectorSpaceBase<Scalar> >& p_space,
807 const Thyra::ModelEvaluatorBase::InArgs<Scalar>& stateBasePoint,
809 const RCP<Thyra::NonlinearSolverBase<Scalar> >& stateTimeStepSolver,
811 const RCP<Thyra::NonlinearSolverBase<Scalar> >& sensTimeStepSolver
814 initializeCommon(stateModel, -1, p_space, stateBasePoint, stateStepper,
815 stateTimeStepSolver, sensStepper, sensTimeStepSolver );
819 template<
class Scalar>
821 const RCP<
const Thyra::ModelEvaluator<Scalar> > &stateModel,
823 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &stateBasePoint,
825 const RCP<Thyra::NonlinearSolverBase<Scalar> > &stateTimeStepSolver,
827 const Scalar &finalTime,
829 const RCP<Thyra::NonlinearSolverBase<Scalar> > &sensTimeStepSolver
832 TEUCHOS_ASSERT(nonnull(stateIntegrator));
833 initializeCommon( stateModel, p_index, Teuchos::null, stateBasePoint, stateStepper,
834 stateTimeStepSolver, sensStepper, sensTimeStepSolver );
835 stateIntegrator_ = stateIntegrator;
836 finalTime_ = finalTime;
840 template<
class Scalar>
843 return stateModel_.isConst();
847 template<
class Scalar>
848 RCP<const Thyra::ModelEvaluator<Scalar> >
851 return stateModel_.getConstObj();
855 template<
class Scalar>
856 RCP<StepperBase<Scalar> >
859 return stateStepper_;
863 template<
class Scalar>
864 RCP<const ForwardSensitivityModelEvaluatorBase<Scalar> >
871 template<
class Scalar>
872 RCP<const StateAndForwardSensitivityModelEvaluator<Scalar> >
875 return stateAndSensModel_;
882 template<
class Scalar>
884 RCP<Teuchos::ParameterList>
const& paramList
887 TEUCHOS_TEST_FOR_EXCEPT(is_null(paramList));
888 paramList->validateParameters(*getValidParameters());
889 this->setMyParamList(paramList);
890 forceUpToDateW_ = paramList->get(forceUpToDateW_name_,forceUpToDateW_default_);
891 Teuchos::readVerboseObjectSublist(&*paramList,
this);
895 template<
class Scalar>
896 RCP<const Teuchos::ParameterList>
899 static RCP<const ParameterList> validPL;
900 if (is_null(validPL) ) {
901 RCP<ParameterList> pl = Teuchos::parameterList();
902 pl->set( forceUpToDateW_name_, forceUpToDateW_default_,
903 "If set to true, then the Jacobian matrix W used in the\n"
904 "state timestep equation will be forced to be up to date\n"
905 "with the final value for x for the nonlinear solve. If\n"
906 "you are willing to live with slightly less accurate sensitivities\n"
907 "then set this to false."
909 Teuchos::setupVerboseObjectSublist(&*pl);
918 template<
class Scalar>
924 template<
class Scalar>
926 const RCP<
const Thyra::ModelEvaluator<Scalar> >&
929 TEUCHOS_TEST_FOR_EXCEPT_MSG(
true,
930 "Error, this stepper subclass does not accept a model"
931 " as defined by the StepperBase interface!");
935 template<
class Scalar>
937 const RCP<Thyra::ModelEvaluator<Scalar> >&
940 TEUCHOS_TEST_FOR_EXCEPT_MSG(
true,
941 "Error, this stepper subclass does not accept a model"
942 " as defined by the StepperBase interface!");
946 template<
class Scalar>
947 RCP<const Thyra::ModelEvaluator<Scalar> >
950 return stateAndSensModel_;
954 template<
class Scalar>
955 RCP<Thyra::ModelEvaluator<Scalar> >
958 return stateAndSensModel_;
962 template<
class Scalar>
964 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &state_and_sens_ic
968 typedef Thyra::ModelEvaluatorBase MEB;
970 stateAndSensBasePoint_ = state_and_sens_ic;
974 TEUCHOS_TEST_FOR_EXCEPTION(
975 is_null(state_and_sens_ic.get_x()), std::logic_error,
976 "Error, the initial condition for x_bar = [ x; s_bar ] can not be null!" );
978 const RCP<const Thyra::ProductVectorBase<Scalar> >
979 x_bar_init = Thyra::productVectorBase<Scalar>(
980 state_and_sens_ic.get_x()
983 RCP<const Thyra::ProductVectorBase<Scalar> > x_bar_dot_init;
984 if (state_and_sens_ic.supports(MEB::IN_ARG_x_dot)) {
985 x_bar_dot_init = Thyra::productVectorBase<Scalar>(
986 state_and_sens_ic.get_x_dot()
992 Thyra::ModelEvaluatorBase::InArgs<Scalar>
993 state_and_sens_ic_no_x = state_and_sens_ic;
994 state_and_sens_ic_no_x.set_x(Teuchos::null);
995 if (state_and_sens_ic_no_x.supports(MEB::IN_ARG_x_dot)) {
996 state_and_sens_ic_no_x.set_x_dot(Teuchos::null);
1001 MEB::InArgs<Scalar> state_ic = stateModel_->createInArgs();
1002 state_ic.setArgs(state_and_sens_ic_no_x,
true,
true);
1003 state_ic.set_x(x_bar_init->getVectorBlock(0)->clone_v());
1004 if (state_ic.supports(MEB::IN_ARG_x_dot)) {
1006 !is_null(x_bar_dot_init)
1007 ? x_bar_dot_init->getVectorBlock(0)->clone_v()
1011 stateStepper_->setInitialCondition(state_ic);
1021 MEB::InArgs<Scalar> sens_ic = sensModel_->createInArgs();
1022 sens_ic.setArgs(state_and_sens_ic_no_x,
true,
true);
1023 sens_ic.set_x(x_bar_init->getVectorBlock(1)->clone_v());
1024 if (sens_ic.supports(MEB::IN_ARG_x_dot)) {
1026 !is_null(x_bar_dot_init)
1027 ? x_bar_dot_init->getVectorBlock(1)->clone_v()
1031 sensStepper_->setInitialCondition(sens_ic);
1036 template<
class Scalar>
1037 Thyra::ModelEvaluatorBase::InArgs<Scalar>
1040 return stateAndSensBasePoint_;
1044 template<
class Scalar>
1047 Scalar dt, StepSizeType stepType
1051 RYTHMOS_FUNC_TIME_MONITOR(
"Rythmos:ForwardSensitivityStepper::takeStep");
1053 if (!is_null(stateIntegrator_)) {
1054 return takeDecoupledStep(dt,stepType);
1057 return takeSyncedStep(dt,stepType);
1062 template<
class Scalar>
1075 stepStatus.
time = sensStepStatus.
time;
1079 if (is_null(stateIntegrator_)) {
1081 stateStepStatus = stateStepper_->getStepStatus();
1082 if (!is_null(stateStepStatus.
solution) && !is_null(sensStepStatus.
solution))
1083 stepStatus.
solution = stateAndSensModel_->create_x_bar_vec(
1087 stepStatus.
solutionDot = stateAndSensModel_->create_x_bar_vec(
1100 template<
class Scalar>
1101 RCP<const Thyra::VectorSpaceBase<Scalar> >
1104 return stateAndSensModel_->get_x_space();
1108 template<
class Scalar>
1110 const Array<Scalar>& ,
1111 const Array<Teuchos::RCP<
const Thyra::VectorBase<Scalar> > >& ,
1112 const Array<Teuchos::RCP<
const Thyra::VectorBase<Scalar> > >&
1115 TEUCHOS_TEST_FOR_EXCEPT(
"Not implemented addPoints(...) yet but we could if we wanted!");
1119 template<
class Scalar>
1123 return sensStepper_->getTimeRange();
1127 template<
class Scalar>
1129 const Array<Scalar>& time_vec,
1130 Array<RCP<
const Thyra::VectorBase<Scalar> > >* x_bar_vec,
1131 Array<RCP<
const Thyra::VectorBase<Scalar> > >* x_bar_dot_vec,
1132 Array<ScalarMag>* accuracy_vec
1138 #ifdef HAVE_RYTHMOS_DEBUG
1139 TEUCHOS_TEST_FOR_EXCEPT( as<int>(time_vec.size()) == 0 );
1142 const int numTimePoints = time_vec.size();
1148 x_bar_dot_vec->clear();
1150 Array<RCP<const Thyra::VectorBase<Scalar> > >
1153 if (!is_null(stateIntegrator_)) {
1154 stateIntegrator_->getPoints(
1156 x_bar_vec ? &x_vec: 0,
1157 x_bar_dot_vec ? &x_dot_vec: 0,
1162 stateStepper_->getPoints(
1164 x_bar_vec ? &x_vec: 0,
1165 x_bar_dot_vec ? &x_dot_vec: 0,
1170 Array<RCP<const Thyra::VectorBase<Scalar> > >
1171 s_bar_vec, s_bar_dot_vec;
1173 sensStepper_->getPoints(
1175 x_bar_vec ? &s_bar_vec: 0,
1176 x_bar_dot_vec ? &s_bar_dot_vec: 0,
1181 for (
int i = 0; i < numTimePoints; ++i ) {
1182 x_bar_vec->push_back(
1183 stateAndSensModel_->create_x_bar_vec(x_vec[i],s_bar_vec[i])
1188 if ( x_bar_dot_vec ) {
1189 for (
int i = 0; i < numTimePoints; ++i ) {
1190 x_bar_dot_vec->push_back(
1191 stateAndSensModel_->create_x_bar_vec(x_dot_vec[i],s_bar_dot_vec[i])
1199 template<
class Scalar>
1201 Array<Scalar>* time_vec
1204 TEUCHOS_ASSERT( time_vec != NULL );
1206 if (is_null(stateIntegrator_) && is_null(stateStepper_)) {
1209 if (!is_null(stateIntegrator_)) {
1210 stateIntegrator_->getNodes(time_vec);
1213 stateStepper_->getNodes(time_vec);
1218 template<
class Scalar>
1223 TEUCHOS_TEST_FOR_EXCEPT(
"Not implemented yet but we can!");
1227 template<
class Scalar>
1230 return sensStepper_->getOrder();
1238 template<
class Scalar>
1240 const RCP<
const Thyra::ModelEvaluator<Scalar> >& stateModel,
1242 const RCP<
const Thyra::VectorSpaceBase<Scalar> > &p_space,
1243 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &stateBasePoint,
1245 const RCP<Thyra::NonlinearSolverBase<Scalar> > &stateTimeStepSolver,
1247 const RCP<Thyra::NonlinearSolverBase<Scalar> > &sensTimeStepSolver
1251 using Teuchos::rcp_implicit_cast;
1252 using Teuchos::rcp_dynamic_cast;
1254 typedef Thyra::ModelEvaluatorBase MEB;
1260 TEUCHOS_ASSERT( p_index >= 0 || nonnull(p_space) );
1261 if (nonnull(p_space)) {
1262 TEUCHOS_ASSERT_EQUALITY(p_index, -1);
1265 TEUCHOS_ASSERT(is_null(p_space));
1267 TEUCHOS_TEST_FOR_EXCEPT( is_null(stateModel) );
1268 TEUCHOS_TEST_FOR_EXCEPT( is_null(stateStepper) );
1269 if (stateStepper->isImplicit()) {
1270 TEUCHOS_TEST_FOR_EXCEPT( is_null(stateTimeStepSolver) );
1277 RCP<ForwardSensitivityModelEvaluatorBase<Scalar> > sensModel;
1278 MEB::InArgs<Scalar> stateModelInArgs = stateModel->createInArgs();
1279 if (stateModelInArgs.supports(MEB::IN_ARG_x_dot)) {
1281 sensModel = Teuchos::rcp(
new ForwardSensitivityImplicitModelEvaluator<Scalar>);
1285 sensModel = Teuchos::rcp(
new ForwardSensitivityExplicitModelEvaluator<Scalar>);
1289 sensModel->initializeStructure(stateModel, p_index);
1292 sensModel->initializeStructureInitCondOnly(stateModel, p_space);
1299 stateModel_.initialize(stateModel);
1301 stateBasePoint_ = stateBasePoint;
1303 stateStepper_ = stateStepper;
1305 stateTimeStepSolver_ = stateTimeStepSolver;
1307 sensModel_ = sensModel;
1309 stateAndSensModel_ = Teuchos::rcp(
new StateAndForwardSensitivityModelEvaluator<Scalar>);
1310 stateAndSensModel_->initializeStructure(sensModel_);
1312 if (!is_null(sensStepper)) {
1313 sensStepper_ = sensStepper;
1316 sensStepper_ = stateStepper_->cloneStepperAlgorithm();
1317 TEUCHOS_TEST_FOR_EXCEPTION(
1318 is_null(sensStepper_), std::logic_error,
1319 "Error, if the client does not pass in a stepper for the senitivity\n"
1320 "equations then the stateStepper object must support cloning to create\n"
1321 "the sensitivity stepper!"
1325 if (!is_null(sensTimeStepSolver)) {
1326 sensTimeStepSolver_ = sensTimeStepSolver;
1329 RCP<Thyra::LinearNonlinearSolver<Scalar> >
1330 linearNonlinearSolver(
new Thyra::LinearNonlinearSolver<Scalar>);
1332 sensTimeStepSolver_ = linearNonlinearSolver;
1339 isSingleResidualStepper_ =
true;
1342 setStepperModel(Teuchos::inOutArg(*stateStepper_),stateModel_);
1343 if (stateStepper_->isImplicit()) {
1344 rcp_dynamic_cast<SolverAcceptingStepperBase<Scalar> >(
1345 stateStepper_,
true)->setSolver(stateTimeStepSolver_);
1347 sensStepper_->setModel(sensModel_);
1348 if (sensStepper_->isImplicit()) {
1349 rcp_dynamic_cast<SolverAcceptingStepperBase<Scalar> >(
1350 sensStepper_,
true)->setSolver(sensTimeStepSolver_);
1353 stateBasePoint_t_ = stateModel_->createInArgs();
1361 template<
class Scalar>
1362 Scalar ForwardSensitivityStepper<Scalar>::takeSyncedStep(
1363 Scalar dt, StepSizeType stepType
1367 RYTHMOS_FUNC_TIME_MONITOR_DIFF(
"Rythmos:ForwardSensitivityStepper::takeStep: synced",
1371 typedef Teuchos::ScalarTraits<Scalar> ST;
1372 typedef Teuchos::VerboseObjectTempState<InterpolationBufferBase<Scalar> > VOTSIBB;
1374 RCP<Teuchos::FancyOStream> out = this->getOStream();
1375 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
1376 const bool lowTrace =
1377 ( !is_null(out) && as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW) );
1378 const bool mediumTrace =
1379 ( !is_null(out) && as<int>(verbLevel) >= as<int>(Teuchos::VERB_MEDIUM) );
1380 Teuchos::OSTab tab(out);
1384 <<
"\nEntering " << TypeNameTraits<ForwardSensitivityStepper<Scalar> >::name()
1385 <<
"::takeSyncedStep("<<dt<<
","<<toString(stepType)<<
") ...\n";
1394 <<
"\nTaking state step using stepper : "
1395 << stateStepper_->description() <<
"\n";
1398 Scalar state_dt = -1.0;
1400 RYTHMOS_FUNC_TIME_MONITOR(
"Rythmos:ForwardSensitivityStepper::takeStep: stateStep");
1401 VOTSIBB stateStepper_outputTempState(stateStepper_,out,verbLevel);
1402 state_dt = stateStepper_->takeStep(dt,stepType);
1405 if (state_dt < Scalar(-ST::one())) {
1407 *out <<
"\nThe state stepper has failed so return a failed timestep!\n";
1412 RYTHMOS_FUNC_TIME_MONITOR(
"Rythmos:ForwardSensitivityStepper::takeStep: updateSensModel");
1414 sensModel_->initializePointState(Teuchos::inOutArg(*stateStepper_),forceUpToDateW_);
1424 <<
"\nTaking sensitivity step using stepper : "
1425 << sensStepper_->description() <<
"\n";
1428 Scalar sens_dt = -1.0;
1430 RYTHMOS_FUNC_TIME_MONITOR(
"Rythmos:ForwardSensitivityStepper::takeStep: sensStep");
1434 sensStepper_->setStepControlData(*stateStepper_);
1435 VOTSIBB sensStepper_outputTempState(sensStepper_,out,verbLevel);
1436 sens_dt = sensStepper_->takeStep(state_dt,STEP_TYPE_FIXED);
1440 const StepStatus<Scalar> sensStepStatus = sensStepper_->getStepStatus();
1441 *out <<
"\nSensitivity step status:\n" << sensStepStatus;
1444 TEUCHOS_TEST_FOR_EXCEPTION(
1445 sens_dt != state_dt, std::logic_error,
1446 "Error, the sensitivity step failed for some reason. We should\n"
1447 "just return a negative step size and reject the step but currently\n"
1448 "there is no way to roll back the state timestep it for back to\n"
1449 "the status before this function was called!"
1462 <<
"\nLeaving " << TypeNameTraits<ForwardSensitivityStepper<Scalar> >::name()
1463 <<
"::takeSyncedStep("<<dt<<
","<<toString(stepType)<<
") ...\n";
1471 template<
class Scalar>
1472 Scalar ForwardSensitivityStepper<Scalar>::takeDecoupledStep(
1473 Scalar dt, StepSizeType stepType
1477 RYTHMOS_FUNC_TIME_MONITOR(
"Rythmos:ForwardSensitivityStepper::takeStep: decoupled");
1480 typedef Teuchos::VerboseObjectTempState<InterpolationBufferBase<Scalar> > VOTSIBB;
1482 RCP<Teuchos::FancyOStream> out = this->getOStream();
1483 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
1484 const bool lowTrace =
1485 ( !is_null(out) && as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW) );
1486 const bool mediumTrace =
1487 ( !is_null(out) && as<int>(verbLevel) >= as<int>(Teuchos::VERB_MEDIUM) );
1488 Teuchos::OSTab tab(out);
1492 <<
"\nEntering " << TypeNameTraits<ForwardSensitivityStepper<Scalar> >::name()
1493 <<
"::takeDecoupledStep("<<dt<<
","<<toString(stepType)<<
") ...\n";
1502 <<
"\nTaking sensitivity step using stepper : "
1503 << sensStepper_->description() <<
"\n";
1506 Scalar sens_dt = -1.0;
1507 VOTSIBB sensStepper_outputTempState(sensStepper_,out,verbLevel);
1508 sens_dt = sensStepper_->takeStep(dt,stepType);
1511 const StepStatus<Scalar> sensStepStatus = sensStepper_->getStepStatus();
1512 *out <<
"\nSensitivity step status:\n" << sensStepStatus;
1523 <<
"\nLeaving " << TypeNameTraits<ForwardSensitivityStepper<Scalar> >::name()
1524 <<
"::takeDecoupledStep("<<dt<<
","<<toString(stepType)<<
") ...\n";
1535 #endif //RYTHMOS_FORWARD_SENSITIVITY_STEPPER_HPP
void initialize(const RCP< const Thyra::ModelEvaluator< Scalar > > &stateModel, const int p_index, const Thyra::ModelEvaluatorBase::InArgs< Scalar > &stateBasePoint, const RCP< StepperBase< Scalar > > &stateStepper, const RCP< Thyra::NonlinearSolverBase< Scalar > > &stateTimeStepSolver, const RCP< StepperBase< Scalar > > &sensStepper=Teuchos::null, const RCP< Thyra::NonlinearSolverBase< Scalar > > &sensTimeStepSolver=Teuchos::null)
Deprecated.
RCP< Thyra::ModelEvaluator< Scalar > > getNonconstModel()
RCP< const Thyra::ModelEvaluator< Scalar > > getModel() const
Returns getStateAndFwdSensModel().
const StepStatus< Scalar > getStepStatus() const
Base class for defining stepper functionality.
Abstract interface for time integrators.
RCP< StepperBase< Scalar > > getNonconstStateStepper()
Return the state stepper that was passed into an initialize function.
RCP< const Teuchos::ParameterList > extraParameters
bool stateModelIsConst() const
Return if the state model is const-only or not.
Foward sensitivity stepper concrete subclass.
void setInitialCondition(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &state_and_sens_ic)
Sets the full initial condition for x_bar = [ x; s_bar] and x_bar_dot = [ x_dot; s_bar_dot ] as well...
void initializeSyncedSteppers(const RCP< const Thyra::ModelEvaluator< Scalar > > &stateModel, const int p_index, const Thyra::ModelEvaluatorBase::InArgs< Scalar > &stateBasePoint, const RCP< StepperBase< Scalar > > &stateStepper, const RCP< Thyra::NonlinearSolverBase< Scalar > > &stateTimeStepSolver, const RCP< StepperBase< Scalar > > &sensStepper=Teuchos::null, const RCP< Thyra::NonlinearSolverBase< Scalar > > &sensTimeStepSolver=Teuchos::null)
Intialize for synced state and sens steppers.
RCP< ForwardSensitivityStepper< Scalar > > forwardSensitivityStepper()
Nonmember constructor.
bool acceptsModel() const
Returns false.
RCP< const ForwardSensitivityModelEvaluatorBase< Scalar > > getFwdSensModel() const
Return the forward sensitivity model evaluator object that got created internally when the initialize...
RCP< ForwardSensitivityStepper< Scalar > > forwardSensitivityStepper(const RCP< const Thyra::ModelEvaluator< Scalar > > &stateModel, const int p_index, const Thyra::ModelEvaluatorBase::InArgs< Scalar > &stateBasePoint, const RCP< StepperBase< Scalar > > &stateStepper, const RCP< Thyra::NonlinearSolverBase< Scalar > > &stateTimeStepSolver, const RCP< StepperBase< Scalar > > &sensStepper=Teuchos::null, const RCP< Thyra::NonlinearSolverBase< Scalar > > &sensTimeStepSolver=Teuchos::null)
Nonmember constructor.
void initializeSyncedSteppersInitCondOnly(const RCP< const Thyra::ModelEvaluator< Scalar > > &stateModel, const RCP< const Thyra::VectorSpaceBase< Scalar > > &p_space, const Thyra::ModelEvaluatorBase::InArgs< Scalar > &stateBasePoint, const RCP< StepperBase< Scalar > > &stateStepper, const RCP< Thyra::NonlinearSolverBase< Scalar > > &stateTimeStepSolver, const RCP< StepperBase< Scalar > > &sensStepper=Teuchos::null, const RCP< Thyra::NonlinearSolverBase< Scalar > > &sensTimeStepSolver=Teuchos::null)
Intialize for synced state and sens steppers for an initial-condition only parametrized sensitivity p...
void removeNodes(Array< Scalar > &time_vec)
RCP< const Thyra::VectorBase< Scalar > > solutionDot
Thyra::ModelEvaluatorBase::InArgs< Scalar > createStateAndSensInitialCondition(const ForwardSensitivityStepper< Scalar > &fwdSensStepper, const Thyra::ModelEvaluatorBase::InArgs< Scalar > &state_ic, const RCP< const Thyra::MultiVectorBase< Scalar > > S_init=Teuchos::null, const RCP< const Thyra::MultiVectorBase< Scalar > > S_dot_init=Teuchos::null)
Set up default initial conditions for the state and sensitivity stepper with default zero initial con...
Thyra::ModelEvaluatorBase::InArgs< Scalar > extractStateInitialCondition(const ForwardSensitivityStepper< Scalar > &fwdSensStepper, const Thyra::ModelEvaluatorBase::InArgs< Scalar > &state_and_sens_ic)
Extract out the initial condition for just the state model given the initial condition for the state ...
void setModel(const RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Throws exception.
RCP< const Teuchos::ParameterList > getValidParameters() const
RCP< const Thyra::ModelEvaluator< Scalar > > getStateModel() const
Return the state model that was passed into an initialize function.
ForwardSensitivityStepper()
Constructs to uninitialized.
EStepLETStatus stepLETStatus
Scalar takeStep(Scalar dt, StepSizeType stepType)
Teuchos::ScalarTraits< Scalar >::magnitudeType ScalarMag
RCP< const Thyra::VectorBase< Scalar > > solution
void setParameterList(RCP< Teuchos::ParameterList > const ¶mList)
TimeRange< Scalar > getTimeRange() const
void getNodes(Array< Scalar > *time_vec) const
RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
Returns the space for x_bar and x_bar_dot.
void setNonconstModel(const RCP< Thyra::ModelEvaluator< Scalar > > &model)
Throws exception.
RCP< const StateAndForwardSensitivityModelEvaluator< Scalar > > getStateAndFwdSensModel() const
Return the state and forward sensitivity model evaluator object that got created internally when the ...
void addPoints(const Array< Scalar > &time_vec, const Array< Teuchos::RCP< const Thyra::VectorBase< Scalar > > > &x_vec, const Array< Teuchos::RCP< const Thyra::VectorBase< Scalar > > > &xdot_vec)
int getParameterIndex(const ForwardSensitivityStepper< Scalar > &fwdSensStepper)
Return the index of the parameter subvector in the underlying state model.
void getPoints(const Array< Scalar > &time_vec, Array< RCP< const Thyra::VectorBase< Scalar > > > *x_vec, Array< RCP< const Thyra::VectorBase< Scalar > > > *xdot_vec, Array< ScalarMag > *accuracy_vec) const
Thyra::ModelEvaluatorBase::InArgs< Scalar > getInitialCondition() const
void initializeDecoupledSteppers(const RCP< const Thyra::ModelEvaluator< Scalar > > &stateModel, const int p_index, const Thyra::ModelEvaluatorBase::InArgs< Scalar > &stateBasePoint, const RCP< StepperBase< Scalar > > &stateStepper, const RCP< Thyra::NonlinearSolverBase< Scalar > > &stateTimeStepSolver, const RCP< IntegratorBase< Scalar > > &stateIntegrator, const Scalar &finalTime, const RCP< StepperBase< Scalar > > &sensStepper=Teuchos::null, const RCP< Thyra::NonlinearSolverBase< Scalar > > &sensTimeStepSolver=Teuchos::null)
Intialize for decoupled state and sens steppers.