30 #ifndef RYTHMOS_TIME_DISCRETIZED_BACKWARD_EULER_MODEL_EVALUATOR_HPP
31 #define RYTHMOS_TIME_DISCRETIZED_BACKWARD_EULER_MODEL_EVALUATOR_HPP
34 #include "Rythmos_Types.hpp"
35 #include "Thyra_StateFuncModelEvaluatorBase.hpp"
36 #include "Thyra_ProductVectorBase.hpp"
37 #include "Thyra_DefaultProductVectorSpace.hpp"
38 #include "Thyra_DefaultBlockedLinearOp.hpp"
39 #include "Thyra_DefaultBlockedTriangularLinearOpWithSolveFactory.hpp"
49 template<
class Scalar>
51 :
virtual public Thyra::StateFuncModelEvaluatorBase<Scalar>
68 const RCP<
const Thyra::ModelEvaluator<Scalar> > &daeModel,
69 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &initCond,
70 const Scalar finalTime,
71 const int numTimeSteps,
72 const RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> > &W_bar_factory = Teuchos::null
81 RCP<const Thyra::VectorSpaceBase<Scalar> >
get_x_space()
const;
83 RCP<const Thyra::VectorSpaceBase<Scalar> >
get_f_space()
const;
85 RCP<Thyra::LinearOpBase<Scalar> >
create_W_op()
const;
87 RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> >
get_W_factory()
const;
91 Thyra::ModelEvaluatorBase::InArgs<Scalar>
createInArgs()
const;
101 Thyra::ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl()
const;
104 const Thyra::ModelEvaluatorBase::InArgs<Scalar>& inArgs,
105 const Thyra::ModelEvaluatorBase::OutArgs<Scalar>& outArgs
112 RCP<const Thyra::ModelEvaluator<Scalar> > daeModel_;
113 Thyra::ModelEvaluatorBase::InArgs<Scalar> initCond_;
120 RCP<const Thyra::ProductVectorSpaceBase<Scalar> > x_bar_space_;
121 RCP<const Thyra::ProductVectorSpaceBase<Scalar> > f_bar_space_;
122 RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> > W_bar_factory_;
131 template<
class Scalar>
132 RCP<TimeDiscretizedBackwardEulerModelEvaluator<Scalar> >
134 const RCP<
const Thyra::ModelEvaluator<Scalar> > &daeModel,
135 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &initCond,
136 const Scalar finalTime,
137 const int numTimeSteps,
138 const RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> > &W_bar_factory
141 RCP<TimeDiscretizedBackwardEulerModelEvaluator<Scalar> >
143 model->initialize(daeModel,initCond,finalTime,numTimeSteps,W_bar_factory);
155 template<
class Scalar>
167 template<
class Scalar>
169 const RCP<
const Thyra::ModelEvaluator<Scalar> > &daeModel,
170 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &initCond,
171 const Scalar finalTime,
172 const int numTimeSteps,
173 const RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> > &W_bar_factory
177 TEUCHOS_TEST_FOR_EXCEPT(is_null(daeModel));
178 TEUCHOS_TEST_FOR_EXCEPT(is_null(initCond.get_x()));
179 TEUCHOS_TEST_FOR_EXCEPT(is_null(initCond.get_x_dot()));
180 TEUCHOS_TEST_FOR_EXCEPT(finalTime <= initCond.get_t());
181 TEUCHOS_TEST_FOR_EXCEPT(numTimeSteps <= 0);
184 daeModel_ = daeModel;
185 initCond_ = initCond;
186 finalTime_ = finalTime;
187 numTimeSteps_ = numTimeSteps;
189 initTime_ = initCond.get_t();
190 delta_t_ = (finalTime_ - initTime_) / numTimeSteps_;
192 x_bar_space_ = productVectorSpace(daeModel_->get_x_space(),numTimeSteps_);
193 f_bar_space_ = productVectorSpace(daeModel_->get_f_space(),numTimeSteps_);
195 if (!is_null(W_bar_factory)) {
196 W_bar_factory_ = W_bar_factory;
200 Thyra::defaultBlockedTriangularLinearOpWithSolveFactory<Scalar>(
201 daeModel_->get_W_factory()
211 template<
class Scalar>
212 RCP<const Thyra::VectorSpaceBase<Scalar> >
219 template<
class Scalar>
220 RCP<const Thyra::VectorSpaceBase<Scalar> >
227 template<
class Scalar>
228 RCP<Thyra::LinearOpBase<Scalar> >
232 RCP<Thyra::PhysicallyBlockedLinearOpBase<Scalar> >
233 W_op_bar = Thyra::defaultBlockedLinearOp<Scalar>();
234 W_op_bar->beginBlockFill( f_bar_space_, x_bar_space_ );
235 for (
int k = 0; k < numTimeSteps_; ++k ) {
236 W_op_bar->setNonconstBlock( k, k, daeModel_->create_W_op() );
238 W_op_bar->setNonconstBlock( k, k-1, daeModel_->create_W_op() );
240 W_op_bar->endBlockFill();
245 template<
class Scalar>
246 RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> >
249 return W_bar_factory_;
253 template<
class Scalar>
254 Thyra::ModelEvaluatorBase::InArgs<Scalar>
257 typedef Thyra::ModelEvaluatorBase MEB;
258 TEUCHOS_TEST_FOR_EXCEPT(
true);
259 return MEB::InArgs<Scalar>();
263 template<
class Scalar>
264 Thyra::ModelEvaluatorBase::InArgs<Scalar>
267 typedef Thyra::ModelEvaluatorBase MEB;
268 MEB::InArgsSetup<Scalar> inArgs;
269 inArgs.setModelEvalDescription(this->description());
270 inArgs.setSupports(MEB::IN_ARG_x);
278 template<
class Scalar>
279 Thyra::ModelEvaluatorBase::OutArgs<Scalar>
282 typedef Thyra::ModelEvaluatorBase MEB;
283 MEB::OutArgs<Scalar> daeOutArgs = daeModel_->createOutArgs();
284 MEB::OutArgsSetup<Scalar> outArgs;
285 outArgs.setModelEvalDescription(this->description());
286 outArgs.setSupports(MEB::OUT_ARG_f);
287 outArgs.setSupports(MEB::OUT_ARG_W_op);
288 outArgs.set_W_properties(daeOutArgs.get_W_properties());
293 template<
class Scalar>
294 void TimeDiscretizedBackwardEulerModelEvaluator<Scalar>::evalModelImpl(
295 const Thyra::ModelEvaluatorBase::InArgs<Scalar>& inArgs_bar,
296 const Thyra::ModelEvaluatorBase::OutArgs<Scalar>& outArgs_bar
301 using Teuchos::rcp_dynamic_cast;
303 typedef Thyra::ModelEvaluatorBase MEB;
304 typedef Thyra::VectorBase<Scalar> VB;
305 typedef Thyra::ProductVectorBase<Scalar> PVB;
306 typedef Thyra::BlockedLinearOpBase<Scalar> BLWB;
314 TEUCHOS_TEST_FOR_EXCEPTION( delta_t_ <= 0.0, std::logic_error,
315 "Error, you have not initialized this object correctly!" );
321 const RCP<const PVB> x_bar = rcp_dynamic_cast<
const PVB>(inArgs_bar.get_x(),
true);
322 const RCP<PVB> f_bar = rcp_dynamic_cast<PVB>(outArgs_bar.get_f(),
true);
323 RCP<BLWB> W_op_bar = rcp_dynamic_cast<BLWB>(outArgs_bar.get_W_op(),
true);
329 MEB::InArgs<Scalar> daeInArgs = daeModel_->createInArgs();
330 MEB::OutArgs<Scalar> daeOutArgs = daeModel_->createOutArgs();
331 const RCP<VB> x_dot_i = createMember(daeModel_->get_x_space());
332 daeInArgs.setArgs(initCond_);
334 Scalar t_i = initTime_;
336 const Scalar oneOverDeltaT = 1.0/delta_t_;
338 for (
int i = 0; i < numTimeSteps_; ++i ) {
341 const RCP<const Thyra::VectorBase<Scalar> >
342 x_i = x_bar->getVectorBlock(i),
343 x_im1 = ( i==0 ? initCond_.get_x() : x_bar->getVectorBlock(i-1) );
344 V_VmV( x_dot_i.ptr(), *x_i, *x_im1 );
345 Vt_S( x_dot_i.ptr(), oneOverDeltaT );
346 daeInArgs.set_x_dot( x_dot_i );
347 daeInArgs.set_x( x_i );
348 daeInArgs.set_t( t_i );
349 daeInArgs.set_alpha( oneOverDeltaT );
350 daeInArgs.set_beta( 1.0 );
354 daeOutArgs.set_f( f_bar->getNonconstVectorBlock(i) );
355 if (!is_null(W_op_bar))
356 daeOutArgs.set_W_op(W_op_bar->getNonconstBlock(i,i).assert_not_null());
359 daeModel_->evalModel( daeInArgs, daeOutArgs );
360 daeOutArgs.set_f(Teuchos::null);
361 daeOutArgs.set_W_op(Teuchos::null);
364 if ( !is_null(W_op_bar) && i > 0 ) {
365 daeInArgs.set_alpha( -oneOverDeltaT );
366 daeInArgs.set_beta( 0.0 );
367 daeOutArgs.set_W_op(W_op_bar->getNonconstBlock(i,i-1).assert_not_null());
368 daeModel_->evalModel( daeInArgs, daeOutArgs );
369 daeOutArgs.set_W_op(Teuchos::null);
387 #endif // RYTHMOS_TIME_DISCRETIZED_BACKWARD_EULER_MODEL_EVALUATOR_HPP
RCP< TimeDiscretizedBackwardEulerModelEvaluator< Scalar > > timeDiscretizedBackwardEulerModelEvaluator(const RCP< const Thyra::ModelEvaluator< Scalar > > &daeModel, const Thyra::ModelEvaluatorBase::InArgs< Scalar > &initCond, const Scalar finalTime, const int numTimeSteps, const RCP< Thyra::LinearOpWithSolveFactoryBase< Scalar > > &W_bar_factory)
Non-member constructor.
RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const
RCP< const Thyra::LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
RCP< Thyra::LinearOpBase< Scalar > > create_W_op() const
TimeDiscretizedBackwardEulerModelEvaluator()
void initialize(const RCP< const Thyra::ModelEvaluator< Scalar > > &daeModel, const Thyra::ModelEvaluatorBase::InArgs< Scalar > &initCond, const Scalar finalTime, const int numTimeSteps, const RCP< Thyra::LinearOpWithSolveFactoryBase< Scalar > > &W_bar_factory=Teuchos::null)
Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const