Rythmos_StepperHelpers.hpp
00001
00002 #ifndef RYTHMOS_STEPPER_HELPERS_HPP
00003 #define RYTHMOS_STEPPER_HELPERS_HPP
00004
00005
00006 #include "Rythmos_StepperBase.hpp"
00007 #include "Teuchos_Assert.hpp"
00008
00009
00010 namespace Rythmos {
00011
00012
00016 template<class Scalar>
00017 void assertValidModel(
00018 const StepperBase<Scalar>& stepper,
00019 const Thyra::ModelEvaluator<Scalar>& model
00020 )
00021 {
00022
00023 typedef Thyra::ModelEvaluatorBase MEB;
00024
00025 TEUCHOS_ASSERT(stepper.acceptsModel());
00026
00027 const MEB::InArgs<Scalar> inArgs = model.createInArgs();
00028 const MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
00029
00030 TEUCHOS_ASSERT(inArgs.supports(MEB::IN_ARG_t));
00031 TEUCHOS_ASSERT(inArgs.supports(MEB::IN_ARG_x));
00032 TEUCHOS_ASSERT(outArgs.supports(MEB::OUT_ARG_f));
00033
00034 if (stepper.isImplicit()) {
00035 TEUCHOS_ASSERT(inArgs.supports(MEB::IN_ARG_x_dot));
00036 TEUCHOS_ASSERT(inArgs.supports(MEB::IN_ARG_alpha));
00037 TEUCHOS_ASSERT(inArgs.supports(MEB::IN_ARG_beta));
00038 TEUCHOS_ASSERT(outArgs.supports(MEB::OUT_ARG_W));
00039 }
00040
00041 }
00042
00043
00050 template<class Scalar>
00051 bool setDefaultInitialConditionFromNominalValues(
00052 const Thyra::ModelEvaluator<Scalar>& model,
00053 const Ptr<StepperBase<Scalar> >& stepper
00054 )
00055 {
00056
00057 typedef ScalarTraits<Scalar> ST;
00058 typedef Thyra::ModelEvaluatorBase MEB;
00059
00060 if (isInitialized(*stepper))
00061 return false;
00062
00063 MEB::InArgs<Scalar> initCond = model.getNominalValues();
00064
00065 if (!is_null(initCond.get_x())) {
00066
00067
00068
00069 #ifdef TEUCHOS_DEBUG
00070 THYRA_ASSERT_VEC_SPACES( "setInitialConditionIfExists(...)",
00071 *model.get_x_space(), *initCond.get_x()->space() );
00072 #endif
00073 if (is_null(initCond.get_x_dot())) {
00074 const RCP<Thyra::VectorBase<Scalar> > x_dot =
00075 createMember(model.get_x_space());
00076 assign(x_dot.ptr(), ST::zero());
00077 }
00078 else {
00079 #ifdef TEUCHOS_DEBUG
00080 THYRA_ASSERT_VEC_SPACES( "setInitialConditionIfExists(...)",
00081 *model.get_x_space(), *initCond.get_x_dot()->space() );
00082 #endif
00083 }
00084 stepper->setInitialCondition(initCond);
00085 return true;
00086 }
00087
00088
00089
00090 return false;
00091
00092 }
00093
00094
00102 template<class Scalar>
00103 void restart( StepperBase<Scalar> *stepper )
00104 {
00105 #ifdef TEUCHOS_DEBUG
00106 TEST_FOR_EXCEPT(0==stepper);
00107 #endif // TEUCHOS_DEBUG
00108 typedef Thyra::ModelEvaluatorBase MEB;
00109 const Rythmos::StepStatus<double>
00110 stepStatus = stepper->getStepStatus();
00111 const RCP<const Thyra::ModelEvaluator<Scalar> >
00112 model = stepper->getModel();
00113
00114 MEB::InArgs<double> initialCondition = model->createInArgs();
00115 initialCondition.setArgs(model->getNominalValues());
00116
00117 RCP<const Thyra::VectorBase<double> > x, x_dot;
00118 Rythmos::get_x_and_x_dot(*stepper,stepStatus.time,&x,&x_dot);
00119 initialCondition.set_x(x);
00120 initialCondition.set_x_dot(x_dot);
00121 initialCondition.set_t(stepStatus.time);
00122
00123
00124 stepper->setInitialCondition(initialCondition);
00125 }
00126
00127
00128 }
00129
00130
00131 #endif // RYTHMOS_STEPPER_HELPERS_HPP