280 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs,
281 const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs
284 typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
288 using Teuchos::rcp_dynamic_cast;
289 TEUCHOS_TEST_FOR_EXCEPTION( !isInitialized_, std::logic_error,
290 "Error, setupInOutArgs_ must be called first!\n");
292 const RCP<const VectorBase<Scalar> > x_in = inArgs.get_x().assert_not_null();
293 Thyra::ConstDetachedVectorView<Scalar> x_in_view( *x_in );
299 if (acceptModelParams_) {
300 const RCP<const VectorBase<Scalar> > p_in =
301 inArgs.get_p(0).assert_not_null();
302 Thyra::ConstDetachedVectorView<Scalar> p_in_view( *p_in );
308 RCP<const MultiVectorBase<Scalar> > DxDp_in, DxdotDp_in;
309 if (acceptModelParams_) {
310 if (inArgs.get_p(1) != Teuchos::null)
312 rcp_dynamic_cast<const DMVPV>(inArgs.get_p(1))->getMultiVector();
313 if (inArgs.get_p(2) != Teuchos::null)
315 rcp_dynamic_cast<const DMVPV>(inArgs.get_p(2))->getMultiVector();
318 Scalar beta = inArgs.get_beta();
320 const RCP<VectorBase<Scalar> > f_out = outArgs.get_f();
321 const RCP<Thyra::LinearOpBase<Scalar> > W_out = outArgs.get_W_op();
322 RCP<Thyra::MultiVectorBase<Scalar> > DfDp_out;
323 if (acceptModelParams_) {
324 Thyra::ModelEvaluatorBase::Derivative<Scalar> DfDp = outArgs.get_DfDp(0);
325 DfDp_out = DfDp.getMultiVector();
328 if (inArgs.get_x_dot().is_null()) {
331 if (!is_null(f_out)) {
332 Thyra::DetachedVectorView<Scalar> f_out_view( *f_out );
333 f_out_view[0] = x_in_view[1];
334 f_out_view[1] = (f/L)*(f/L)*(a-x_in_view[0]);
336 if (!is_null(W_out)) {
337 RCP<Thyra::MultiVectorBase<Scalar> > matrix =
338 Teuchos::rcp_dynamic_cast<Thyra::MultiVectorBase<Scalar> >(W_out,
true);
339 Thyra::DetachedMultiVectorView<Scalar> matrix_view( *matrix );
340 matrix_view(0,0) = 0.0;
341 matrix_view(0,1) = +beta;
342 matrix_view(1,0) = -beta*(f/L)*(f/L);
343 matrix_view(1,1) = 0.0;
346 if (!is_null(DfDp_out)) {
347 Thyra::DetachedMultiVectorView<Scalar> DfDp_out_view( *DfDp_out );
348 DfDp_out_view(0,0) = 0.0;
349 DfDp_out_view(0,1) = 0.0;
350 DfDp_out_view(0,2) = 0.0;
351 DfDp_out_view(1,0) = (f/L)*(f/L);
352 DfDp_out_view(1,1) = (2.0*f/(L*L))*(a-x_in_view[0]);
353 DfDp_out_view(1,2) = -(2.0*f*f/(L*L*L))*(a-x_in_view[0]);
356 if (useDfDpAsTangent_ && !is_null(DxDp_in)) {
357 Thyra::ConstDetachedMultiVectorView<Scalar> DxDp( *DxDp_in );
358 DfDp_out_view(0,0) += DxDp(1,0);
359 DfDp_out_view(0,1) += DxDp(1,1);
360 DfDp_out_view(0,2) += DxDp(1,2);
361 DfDp_out_view(1,0) += -(f/L)*(f/L) * DxDp(0,0);
362 DfDp_out_view(1,1) += -(f/L)*(f/L) * DxDp(0,1);
363 DfDp_out_view(1,2) += -(f/L)*(f/L) * DxDp(0,2);
369 RCP<const VectorBase<Scalar> > x_dot_in;
370 x_dot_in = inArgs.get_x_dot().assert_not_null();
371 Scalar alpha = inArgs.get_alpha();
372 if (!is_null(f_out)) {
373 Thyra::DetachedVectorView<Scalar> f_out_view( *f_out );
374 Thyra::ConstDetachedVectorView<Scalar> x_dot_in_view( *x_dot_in );
375 f_out_view[0] = x_dot_in_view[0] - x_in_view[1];
376 f_out_view[1] = x_dot_in_view[1] - (f/L)*(f/L)*(a-x_in_view[0]);
378 if (!is_null(W_out)) {
379 RCP<Thyra::MultiVectorBase<Scalar> > matrix =
380 Teuchos::rcp_dynamic_cast<Thyra::MultiVectorBase<Scalar> >(W_out,
true);
381 Thyra::DetachedMultiVectorView<Scalar> matrix_view( *matrix );
382 matrix_view(0,0) = alpha;
383 matrix_view(0,1) = -beta;
384 matrix_view(1,0) = +beta*(f/L)*(f/L);
385 matrix_view(1,1) = alpha;
388 if (!is_null(DfDp_out)) {
389 Thyra::DetachedMultiVectorView<Scalar> DfDp_out_view( *DfDp_out );
390 DfDp_out_view(0,0) = 0.0;
391 DfDp_out_view(0,1) = 0.0;
392 DfDp_out_view(0,2) = 0.0;
393 DfDp_out_view(1,0) = -(f/L)*(f/L);
394 DfDp_out_view(1,1) = -(2.0*f/(L*L))*(a-x_in_view[0]);
395 DfDp_out_view(1,2) = +(2.0*f*f/(L*L*L))*(a-x_in_view[0]);
398 if (useDfDpAsTangent_ && !is_null(DxdotDp_in)) {
399 Thyra::ConstDetachedMultiVectorView<Scalar> DxdotDp( *DxdotDp_in );
400 DfDp_out_view(0,0) += DxdotDp(0,0);
401 DfDp_out_view(0,1) += DxdotDp(0,1);
402 DfDp_out_view(0,2) += DxdotDp(0,2);
403 DfDp_out_view(1,0) += DxdotDp(1,0);
404 DfDp_out_view(1,1) += DxdotDp(1,1);
405 DfDp_out_view(1,2) += DxdotDp(1,2);
407 if (useDfDpAsTangent_ && !is_null(DxDp_in)) {
408 Thyra::ConstDetachedMultiVectorView<Scalar> DxDp( *DxDp_in );
409 DfDp_out_view(0,0) += -DxDp(1,0);
410 DfDp_out_view(0,1) += -DxDp(1,1);
411 DfDp_out_view(0,2) += -DxDp(1,2);
412 DfDp_out_view(1,0) += (f/L)*(f/L) * DxDp(0,0);
413 DfDp_out_view(1,1) += (f/L)*(f/L) * DxDp(0,1);
414 DfDp_out_view(1,2) += (f/L)*(f/L) * DxDp(0,2);
420 if (acceptModelParams_) {
421 RCP<VectorBase<Scalar> > g_out = outArgs.get_g(0);
422 if (g_out != Teuchos::null)
423 Thyra::assign(g_out.ptr(), *x_in);
425 RCP<Thyra::MultiVectorBase<Scalar> > DgDp_out =
426 outArgs.get_DgDp(0,0).getMultiVector();
427 if (DgDp_out != Teuchos::null)
428 Thyra::assign(DgDp_out.ptr(), Scalar(0.0));
430 RCP<Thyra::MultiVectorBase<Scalar> > DgDx_out =
431 outArgs.get_DgDx(0).getMultiVector();
432 if (DgDx_out != Teuchos::null) {
433 Thyra::DetachedMultiVectorView<Scalar> DgDx_out_view( *DgDx_out );
434 DgDx_out_view(0,0) = 1.0;
435 DgDx_out_view(0,1) = 0.0;
436 DgDx_out_view(1,0) = 0.0;
437 DgDx_out_view(1,1) = 1.0;
497 if (isInitialized_) {
502 typedef Thyra::ModelEvaluatorBase MEB;
505 MEB::InArgsSetup<Scalar> inArgs;
506 inArgs.setModelEvalDescription(this->description());
507 inArgs.setSupports( MEB::IN_ARG_t );
508 inArgs.setSupports( MEB::IN_ARG_x );
509 inArgs.setSupports( MEB::IN_ARG_beta );
510 inArgs.setSupports( MEB::IN_ARG_x_dot );
511 inArgs.setSupports( MEB::IN_ARG_alpha );
512 if (acceptModelParams_) {
520 MEB::OutArgsSetup<Scalar> outArgs;
521 outArgs.setModelEvalDescription(this->description());
522 outArgs.setSupports( MEB::OUT_ARG_f );
523 outArgs.setSupports( MEB::OUT_ARG_W_op );
524 if (acceptModelParams_) {
525 outArgs.set_Np_Ng(Np_,Ng_);
526 outArgs.setSupports( MEB::OUT_ARG_DfDp,0,
527 MEB::DERIV_MV_JACOBIAN_FORM );
528 outArgs.setSupports( MEB::OUT_ARG_DgDp,0,0,
529 MEB::DERIV_MV_JACOBIAN_FORM );
530 outArgs.setSupports( MEB::OUT_ARG_DgDx,0,
531 MEB::DERIV_MV_GRADIENT_FORM );
537 nominalValues_ = inArgs_;
540 nominalValues_.set_t(t0_ic_);
541 const RCP<Thyra::VectorBase<Scalar> > x_ic = createMember(x_space_);
543 Thyra::DetachedVectorView<Scalar> x_ic_view( *x_ic );
544 x_ic_view[0] = a_+b_*sin((f_/L_)*t0_ic_+phi_);
545 x_ic_view[1] = b_*(f_/L_)*cos((f_/L_)*t0_ic_+phi_);
547 nominalValues_.set_x(x_ic);
548 if (acceptModelParams_) {
549 const RCP<Thyra::VectorBase<Scalar> > p_ic = createMember(p_space_);
551 Thyra::DetachedVectorView<Scalar> p_ic_view( *p_ic );
556 nominalValues_.set_p(0,p_ic);
558 const RCP<Thyra::VectorBase<Scalar> > x_dot_ic = createMember(x_space_);
560 Thyra::DetachedVectorView<Scalar> x_dot_ic_view( *x_dot_ic );
561 x_dot_ic_view[0] = b_*(f_/L_)*cos((f_/L_)*t0_ic_+phi_);
562 x_dot_ic_view[1] = -b_*(f_/L_)*(f_/L_)*sin((f_/L_)*t0_ic_+phi_);
564 nominalValues_.set_x_dot(x_dot_ic);
567 isInitialized_ =
true;
726 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs,
727 const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs
733 using Teuchos::rcp_dynamic_cast;
734 TEUCHOS_TEST_FOR_EXCEPTION( !this->isInitialized_, std::logic_error,
735 "Error, setupInOutArgs_ must be called first!\n");
737 const RCP<const VectorBase<Scalar> > x_in = inArgs.get_x().assert_not_null();
738 Thyra::ConstDetachedVectorView<Scalar> x_in_view( *x_in );
744 if (this->acceptModelParams_) {
745 const RCP<const VectorBase<Scalar> > p_in =
746 inArgs.get_p(0).assert_not_null();
747 Thyra::ConstDetachedVectorView<Scalar> p_in_view( *p_in );
753 Scalar beta = inArgs.get_beta();
755 const RCP<Thyra::LinearOpBase<Scalar> > W_out = outArgs.get_W_op();
756 if (inArgs.get_x_dot().is_null()) {
759 if (!is_null(W_out)) {
760 RCP<Thyra::MultiVectorBase<Scalar> > matrix =
761 Teuchos::rcp_dynamic_cast<Thyra::MultiVectorBase<Scalar> >(W_out,
true);
762 Thyra::DetachedMultiVectorView<Scalar> matrix_view( *matrix );
763 matrix_view(0,0) = 0.0;
764 matrix_view(1,0) = +beta;
765 matrix_view(0,1) = -beta*(f/L)*(f/L);
766 matrix_view(1,1) = 0.0;
772 RCP<const VectorBase<Scalar> > x_dot_in;
773 x_dot_in = inArgs.get_x_dot().assert_not_null();
774 Scalar alpha = inArgs.get_alpha();
775 if (!is_null(W_out)) {
776 RCP<Thyra::MultiVectorBase<Scalar> > matrix =
777 Teuchos::rcp_dynamic_cast<Thyra::MultiVectorBase<Scalar> >(W_out,
true);
778 Thyra::DetachedMultiVectorView<Scalar> matrix_view( *matrix );
779 matrix_view(0,0) = alpha;
780 matrix_view(1,0) = -beta;
781 matrix_view(0,1) = +beta*(f/L)*(f/L);
782 matrix_view(1,1) = alpha;