30 #ifndef RYTHMOS_STEPPER_AS_MODEL_EVALUATOR_HPP
31 #define RYTHMOS_STEPPER_AS_MODEL_EVALUATOR_HPP
34 #include "Thyra_ResponseOnlyModelEvaluatorBase.hpp"
35 #include "Thyra_ModelEvaluatorDelegatorBase.hpp"
37 #include "Rythmos_StepperBase.hpp"
38 #include "Rythmos_IntegratorBase.hpp"
39 #include "Teuchos_StandardMemberCompositionMacros.hpp"
40 #include "Teuchos_Assert.hpp"
52 template<
class Scalar>
54 :
virtual public Thyra::ResponseOnlyModelEvaluatorBase<Scalar>
68 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &initialCondition
81 RCP<const Thyra::VectorSpaceBase<Scalar> >
84 RCP<const Thyra::VectorSpaceBase<Scalar> >
87 Thyra::ModelEvaluatorBase::InArgs<Scalar>
createInArgs()
const;
97 Thyra::ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl()
const;
100 const Thyra::ModelEvaluatorBase::InArgs<Scalar>& inArgs,
101 const Thyra::ModelEvaluatorBase::OutArgs<Scalar>& outArgs
111 typedef Array<RCP<const Thyra::VectorSpaceBase<Scalar> > > SpaceArray_t;
117 RCP<StepperBase<Scalar> > stepper_;
118 RCP<IntegratorBase<Scalar> > integrator_;
119 Thyra::ModelEvaluatorBase::InArgs<Scalar> initialCondition_;
124 SpaceArray_t g_space_;
125 SpaceArray_t p_space_;
127 mutable Thyra::ModelEvaluatorBase::InArgs<Scalar> currentInitialCondition_;
133 template<
class Scalar>
134 RCP<StepperAsModelEvaluator<Scalar> >
135 stepperAsModelEvaluator(
138 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &initialCondition
142 RCP<StepperAsModelEvaluator<Scalar> >
144 stepperAsModelEvaluator->initialize(stepper,integrator,initialCondition);
145 return stepperAsModelEvaluator;
156 template<
class Scalar>
162 template<
class Scalar>
166 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &initialCondition
170 #ifdef HAVE_RYTHMOS_DEBUG
171 TEUCHOS_TEST_FOR_EXCEPT(is_null(stepper));
172 TEUCHOS_TEST_FOR_EXCEPT(is_null(stepper->getModel()));
173 TEUCHOS_TEST_FOR_EXCEPT(is_null(integrator));
176 integrator_ = integrator;
177 initialCondition_ = initialCondition;
178 currentInitialCondition_ = initialCondition;
180 const RCP<const Thyra::ModelEvaluator<Scalar> >
181 stepperModel = stepper_->getModel();
183 Np_ = stepperModel->Np();
185 for (
int l = 0; l < Np_; ++l ) {
186 p_space_.push_back(stepperModel->get_p_space(l));
191 g_space_.push_back(stepper_->getModel()->get_x_space());
199 template<
class Scalar>
206 template<
class Scalar>
213 template<
class Scalar>
214 RCP<const Thyra::VectorSpaceBase<Scalar> >
217 #ifdef HAVE_RYTHMOS_DEBUG
218 TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE( l, 0, Np_ );
224 template<
class Scalar>
225 RCP<const Thyra::VectorSpaceBase<Scalar> >
228 #ifdef HAVE_RYTHMOS_DEBUG
229 TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE( j, 0, Ng_ );
235 template<
class Scalar>
236 Thyra::ModelEvaluatorBase::InArgs<Scalar>
239 typedef Thyra::ModelEvaluatorBase MEB;
240 MEB::InArgsSetup<Scalar> inArgs;
241 inArgs.setModelEvalDescription(this->description());
243 inArgs.setSupports(MEB::IN_ARG_t);
251 template<
class Scalar>
252 Thyra::ModelEvaluatorBase::OutArgs<Scalar>
255 typedef Thyra::ModelEvaluatorBase MEB;
256 MEB::OutArgsSetup<Scalar> outArgs;
257 outArgs.setModelEvalDescription(this->description());
258 outArgs.set_Np_Ng(Np_,Ng_);
263 template<
class Scalar>
264 void StepperAsModelEvaluator<Scalar>::evalModelImpl(
265 const Thyra::ModelEvaluatorBase::InArgs<Scalar>& inArgs,
266 const Thyra::ModelEvaluatorBase::OutArgs<Scalar>& outArgs
271 using Teuchos::describe;
272 typedef Teuchos::VerboseObjectTempState<InterpolationBufferBase<Scalar> > VOTSSB;
274 THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_BEGIN(
275 "Rythmos::StepperAsModelEvaluator", inArgs, outArgs, Teuchos::null
277 VOTSSB integrator_outputTempState(integrator_,out,incrVerbLevel(verbLevel,-1));
282 const Scalar finalTime = inArgs.get_t();
283 for (
int l = 0; l < Np_; ++l ) {
284 currentInitialCondition_.set_p(l,inArgs.get_p(l));
289 RCP<Thyra::VectorBase<Scalar> >
290 g_out = outArgs.get_g(0);
292 TEUCHOS_TEST_FOR_EXCEPT_MSG(
293 is_null(g_out),
"You must ask for g(0) when you call this function!"
296 #ifdef HAVE_RYTHMOS_DEBUG
298 THYRA_ASSERT_VEC_SPACES(
299 "StepperAsModelEvaluator<Scalar>::evalModel(...)",
300 *g_out->space(), *stepper_->get_x_space() );
306 stepper_->setInitialCondition(currentInitialCondition_);
307 integrator_->setStepper(stepper_,finalTime);
311 if (!is_null(g_out)) {
314 Array<Scalar> time_vec = Teuchos::tuple<Scalar>(finalTime);
315 Array<RCP<const Thyra::VectorBase<Scalar> > > x_vec;
316 integrator_->getFwdPoints( time_vec, &x_vec, 0, 0 );
318 Thyra::V_V( g_out.ptr(), *x_vec[0] );
322 THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END();
330 #endif // RYTHMOS_STEPPER_AS_MODEL_EVALUATOR_HPP
Base class for defining stepper functionality.
Abstract interface for time integrators.
Concrete Thyra::ModelEvaluator subclass that takes a parameterized stepper and turns it into a model ...
RCP< const Thyra::VectorSpaceBase< Scalar > > get_p_space(int l) const
void initialize(const RCP< StepperBase< Scalar > > &stepper, const RCP< IntegratorBase< Scalar > > &integrator, const Thyra::ModelEvaluatorBase::InArgs< Scalar > &initialCondition)
StepperAsModelEvaluator()
Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
RCP< const Thyra::VectorSpaceBase< Scalar > > get_g_space(int j) const