29 #ifndef Rythmos_STEPPER_VALIDATOR_H
30 #define Rythmos_STEPPER_VALIDATOR_H
32 #include "Teuchos_ParameterList.hpp"
33 #include "Teuchos_ParameterListAcceptor.hpp"
34 #include "Teuchos_Describable.hpp"
35 #include "Teuchos_VerboseObject.hpp"
36 #include "Rythmos_IntegratorBuilder.hpp"
37 #include "Thyra_StateFuncModelEvaluatorBase.hpp"
38 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp"
39 #include "Thyra_ModelEvaluator.hpp"
41 #include "Rythmos_StepperBase.hpp"
42 #include "Rythmos_Types.hpp"
43 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
44 #include "Thyra_DetachedVectorView.hpp"
45 #include "Thyra_DefaultSpmdVectorSpace.hpp"
46 #include "Thyra_DefaultSerialDenseLinearOpWithSolveFactory.hpp"
47 #include "Rythmos_TimeStepNonlinearSolver.hpp"
49 #include "Teuchos_StandardCatchMacros.hpp"
62 template<
class Scalar>
64 :
virtual public Teuchos::Describable
65 ,
virtual public Teuchos::ParameterListAcceptor
66 ,
virtual public Teuchos::VerboseObject<StepperValidator<Scalar> >
107 Teuchos::FancyOStream &out,
108 const Teuchos::EVerbosityLevel verbLevel
116 void defaultInitializeAll_();
117 RCP<StepperBase<Scalar> > getStepper_(
118 const RCP<Thyra::ModelEvaluator<Scalar> >& model,
119 const Thyra::ModelEvaluatorBase::InArgs<Scalar>& initialCondition,
120 const RCP<Thyra::NonlinearSolverBase<Scalar> >& nlSolver
122 bool isImplicitStepper_()
const;
123 Thyra::ModelEvaluatorBase::InArgs<Scalar> getSomeIC_(
124 const Thyra::ModelEvaluator<Scalar>& model)
const;
128 void validateIC_()
const;
131 void validateStates_()
const;
134 void validateGetIC_()
const;
137 void validateGetIC2_()
const;
140 void validateGetNodes_()
const;
143 RCP<IntegratorBuilder<Scalar> > integratorBuilder_;
144 RCP<ParameterList> paramList_;
145 mutable std::string stepperName_;
152 template<
class Scalar>
153 RCP<StepperValidator<Scalar> > stepperValidator()
161 template<
class Scalar>
162 class StepperValidatorMockModel
163 :
public Thyra::StateFuncModelEvaluatorBase<Scalar>,
164 public Teuchos::ParameterListAcceptorDefaultBase
168 StepperValidatorMockModel();
170 virtual ~StepperValidatorMockModel();
172 RCP<const std::vector<Thyra::ModelEvaluatorBase::InArgs<Scalar> > > getPassedInArgs()
const;
178 RCP<const Thyra::VectorSpaceBase<Scalar> > get_x_space()
const;
180 RCP<const Thyra::VectorSpaceBase<Scalar> > get_f_space()
const;
182 Thyra::ModelEvaluatorBase::InArgs<Scalar> getNominalValues()
const;
184 RCP<Thyra::LinearOpWithSolveBase<Scalar> > create_W()
const;
186 RCP<Thyra::LinearOpBase<Scalar> > create_W_op()
const;
188 RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> > get_W_factory()
const;
190 Thyra::ModelEvaluatorBase::InArgs<Scalar> createInArgs()
const;
193 RCP<const Thyra::VectorSpaceBase<Scalar> > get_p_space(
int l)
const;
195 RCP<const Teuchos::Array<std::string> > get_p_names(
int l)
const;
197 RCP<const Thyra::VectorSpaceBase<Scalar> > get_g_space(
int j)
const;
205 void setParameterList(RCP<ParameterList>
const& paramList);
208 RCP<const ParameterList> getValidParameters()
const;
218 Thyra::ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl()
const;
222 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs_bar,
223 const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs_bar
228 void defaultInitializeAll_();
231 mutable RCP<std::vector<Thyra::ModelEvaluatorBase::InArgs<Scalar> > > passedInArgs_;
234 Thyra::ModelEvaluatorBase::InArgs<Scalar> inArgs_;
235 Thyra::ModelEvaluatorBase::OutArgs<Scalar> outArgs_;
236 Thyra::ModelEvaluatorBase::InArgs<Scalar> nominalValues_;
237 RCP<const Thyra::VectorSpaceBase<Scalar> > x_space_;
238 RCP<const Thyra::VectorSpaceBase<Scalar> > f_space_;
239 RCP<const Thyra::VectorSpaceBase<Scalar> > p_space_;
250 template<
class Scalar>
251 RCP<StepperValidatorMockModel<Scalar> > stepperValidatorMockModel()
253 return(rcp(
new StepperValidatorMockModel<Scalar>()));
256 template<
class Scalar>
257 RCP<StepperValidatorMockModel<Scalar> > stepperValidatorMockModel(
261 RCP<StepperValidatorMockModel<Scalar> > model = rcp(
new StepperValidatorMockModel<Scalar>());
262 RCP<ParameterList> pl = Teuchos::parameterList();
263 pl->set(
"Is Implicit",isImplicit);
264 model->setParameterList(pl);
271 template<
class Scalar>
272 StepperValidatorMockModel<Scalar>::StepperValidatorMockModel()
274 this->defaultInitializeAll_();
280 x_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(dim_);
281 f_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(dim_);
283 p_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(np_);
284 passedInArgs_ = rcp(
new std::vector<Thyra::ModelEvaluatorBase::InArgs<Scalar> >);
288 template<
class Scalar>
289 void StepperValidatorMockModel<Scalar>::defaultInitializeAll_()
291 passedInArgs_ = Teuchos::null;
293 isInitialized_ =
false;
297 x_space_ = Teuchos::null;
298 f_space_ = Teuchos::null;
299 p_space_ = Teuchos::null;
306 template<
class Scalar>
307 StepperValidatorMockModel<Scalar>::~StepperValidatorMockModel()
310 template<
class Scalar>
311 void StepperValidatorMockModel<Scalar>::initialize_()
313 if (!isInitialized_) {
315 Thyra::ModelEvaluatorBase::InArgsSetup<Scalar> inArgs;
316 inArgs.setModelEvalDescription(this->description());
317 inArgs.setSupports( Thyra::ModelEvaluatorBase::IN_ARG_t );
318 inArgs.setSupports( Thyra::ModelEvaluatorBase::IN_ARG_x );
319 inArgs.setSupports( Thyra::ModelEvaluatorBase::IN_ARG_beta );
320 #ifdef HAVE_THYRA_ME_POLYNOMIAL
322 inArgs.setSupports( Thyra::ModelEvaluatorBase::IN_ARG_x_poly );
323 #endif // HAVE_THYRA_ME_POLYNOMIAL
326 inArgs.setSupports( Thyra::ModelEvaluatorBase::IN_ARG_x_dot );
327 inArgs.setSupports( Thyra::ModelEvaluatorBase::IN_ARG_alpha );
331 Thyra::ModelEvaluatorBase::OutArgsSetup<Scalar> outArgs;
332 outArgs.setModelEvalDescription(this->description());
333 outArgs.setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_f );
334 outArgs.setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_W_op );
335 #ifdef HAVE_THYRA_ME_POLYNOMIAL
337 outArgs.setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_f_poly );
338 #endif // HAVE_THYRA_ME_POLYNOMIAL
339 outArgs.set_Np_Ng(Np_,Ng_);
342 nominalValues_ = inArgs_;
343 nominalValues_.set_t(Scalar(1.0));
344 const RCP<VectorBase<Scalar> > x_ic = Thyra::createMember(x_space_);
345 Thyra::V_S(Teuchos::outArg(*x_ic),Scalar(2.0));
346 nominalValues_.set_x(x_ic);
347 const RCP<VectorBase<Scalar> > p_ic = Thyra::createMember(p_space_);
348 Thyra::V_S(Teuchos::outArg(*p_ic),Scalar(3.0));
349 nominalValues_.set_p(0,p_ic);
350 isInitialized_ =
true;
355 template<
class Scalar>
356 RCP<const std::vector<Thyra::ModelEvaluatorBase::InArgs<Scalar> > > StepperValidatorMockModel<Scalar>::getPassedInArgs()
const
358 return passedInArgs_;
362 template<
class Scalar>
363 RCP<const Thyra::VectorSpaceBase<Scalar> > StepperValidatorMockModel<Scalar>::get_x_space()
const
365 TEUCHOS_TEST_FOR_EXCEPT(!isInitialized_);
370 template<
class Scalar>
371 RCP<const Thyra::VectorSpaceBase<Scalar> > StepperValidatorMockModel<Scalar>::get_f_space()
const
373 TEUCHOS_TEST_FOR_EXCEPT(!isInitialized_);
378 template<
class Scalar>
379 Thyra::ModelEvaluatorBase::InArgs<Scalar> StepperValidatorMockModel<Scalar>::getNominalValues()
const
381 TEUCHOS_TEST_FOR_EXCEPT(!isInitialized_);
382 return nominalValues_;
386 template<
class Scalar>
387 RCP<Thyra::LinearOpWithSolveBase<Scalar> > StepperValidatorMockModel<Scalar>::create_W()
const
389 RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> > W_factory = this->get_W_factory();
390 RCP<Thyra::LinearOpBase<Scalar> > matrix = this->create_W_op();
397 RCP<Thyra::MultiVectorBase<Scalar> > multivec = Teuchos::rcp_dynamic_cast<Thyra::MultiVectorBase<Scalar> >(matrix,
true);
399 RCP<Thyra::VectorBase<Scalar> > vec = Thyra::createMember(x_space_);
401 Thyra::DetachedVectorView<Scalar> vec_view( *vec );
404 V_V(multivec->col(0).ptr(),*vec);
407 RCP<Thyra::LinearOpWithSolveBase<Scalar> > W =
408 Thyra::linearOpWithSolve<Scalar>(
416 template<
class Scalar>
417 RCP<Thyra::LinearOpBase<Scalar> > StepperValidatorMockModel<Scalar>::create_W_op()
const
419 RCP<Thyra::MultiVectorBase<Scalar> > matrix = Thyra::createMembers(x_space_, dim_);
424 template<
class Scalar>
425 RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> > StepperValidatorMockModel<Scalar>::get_W_factory()
const
427 RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> > W_factory =
428 Thyra::defaultSerialDenseLinearOpWithSolveFactory<Scalar>();
433 template<
class Scalar>
434 Thyra::ModelEvaluatorBase::InArgs<Scalar> StepperValidatorMockModel<Scalar>::createInArgs()
const
436 TEUCHOS_TEST_FOR_EXCEPT(!isInitialized_);
441 template<
class Scalar>
442 RCP<const Thyra::VectorSpaceBase<Scalar> > StepperValidatorMockModel<Scalar>::get_p_space(
int l)
const
444 TEUCHOS_TEST_FOR_EXCEPT(!isInitialized_);
449 template<
class Scalar>
450 RCP<const Teuchos::Array<std::string> > StepperValidatorMockModel<Scalar>::get_p_names(
int l)
const
452 RCP<Teuchos::Array<std::string> > p_strings =
453 Teuchos::rcp(
new Teuchos::Array<std::string>());
454 p_strings->push_back(
"Model Coefficient");
459 template<
class Scalar>
460 RCP<const Thyra::VectorSpaceBase<Scalar> > StepperValidatorMockModel<Scalar>::get_g_space(
int j)
const
462 return Teuchos::null;
466 template<
class Scalar>
467 void StepperValidatorMockModel<Scalar>::setParameterList(RCP<ParameterList>
const& paramList)
469 TEUCHOS_TEST_FOR_EXCEPT( is_null(paramList) );
470 paramList->validateParameters(*this->getValidParameters());
471 Teuchos::readVerboseObjectSublist(&*paramList,
this);
472 bool test_isImplicit = paramList->get(
"Is Implicit",
false);
473 if (isImplicit_ != test_isImplicit) {
474 isImplicit_ = test_isImplicit;
475 isInitialized_ =
false;
478 setMyParamList(paramList);
480 template<
class Scalar>
481 RCP<const ParameterList> StepperValidatorMockModel<Scalar>::getValidParameters()
const
483 static RCP<const ParameterList> validPL;
484 if (is_null(validPL)) {
485 RCP<ParameterList> pl = Teuchos::parameterList();
486 pl->set(
"Is Implicit",
false);
487 Teuchos::setupVerboseObjectSublist(&*pl);
492 template<
class Scalar>
493 Thyra::ModelEvaluatorBase::OutArgs<Scalar> StepperValidatorMockModel<Scalar>::createOutArgsImpl()
const
495 TEUCHOS_TEST_FOR_EXCEPT(!isInitialized_);
499 template<
class Scalar>
500 void StepperValidatorMockModel<Scalar>::evalModelImpl(
501 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs,
502 const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs
505 typedef Teuchos::ScalarTraits<Scalar> ST;
506 passedInArgs_->push_back(inArgs);
508 RCP<VectorBase<Scalar> > f_out = outArgs.get_f();
509 if (!is_null(f_out)) {
510 Thyra::V_S(Teuchos::outArg(*f_out),ST::zero());
512 #ifdef HAVE_THYRA_ME_POLYNOMIAL
513 if (outArgs.supports(Thyra::ModelEvaluatorBase::OUT_ARG_f_poly)) {
514 RCP<Teuchos::Polynomial<VectorBase<Scalar> > > f_poly_out = outArgs.get_f_poly();
515 if (!is_null(f_poly_out)) {
519 #endif // HAVE_THYRA_ME_POLYNOMIAL
528 template<
class Scalar>
529 StepperValidator<Scalar>::StepperValidator()
531 this->defaultInitializeAll_();
534 template<
class Scalar>
535 void StepperValidator<Scalar>::defaultInitializeAll_()
537 integratorBuilder_ = Teuchos::null;
538 paramList_ = Teuchos::null;
542 template<
class Scalar>
543 StepperValidator<Scalar>::~StepperValidator()
546 template<
class Scalar>
551 TEUCHOS_ASSERT( !is_null(integratorBuilder) );
552 integratorBuilder_ = integratorBuilder;
555 template<
class Scalar>
560 RCP<const ParameterList> pl = integratorBuilder_->getParameterList();
562 pl = integratorBuilder_->getValidParameters();
564 const Teuchos::ParameterList& stepperSelectionPL = pl->sublist(
"Stepper Settings").sublist(
"Stepper Selection");
565 stepperName_ = stepperSelectionPL.get<std::string>(
"Stepper Type");
568 Array<bool> success_array;
569 bool local_success =
true;
572 local_success =
true;
576 TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose,std::cerr,local_success);
577 success_array.push_back(local_success);
583 local_success =
true;
585 this->validateStates_();
587 TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose,std::cerr,local_success);
588 success_array.push_back(local_success);
592 local_success =
true;
594 this->validateGetIC_();
596 TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose,std::cerr,local_success);
597 success_array.push_back(local_success);
601 local_success =
true;
603 this->validateGetIC2_();
605 TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose,std::cerr,local_success);
606 success_array.push_back(local_success);
610 local_success =
true;
612 this->validateGetNodes_();
614 TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose,std::cerr,local_success);
615 success_array.push_back(local_success);
620 bool global_success =
true;
621 for (
int i=0 ; i < Teuchos::as<int>(success_array.size()) ; ++i) {
622 global_success = global_success && success_array[i];
625 TEUCHOS_TEST_FOR_EXCEPTION( !global_success, std::logic_error,
626 "Error! StepperValidator: The stepper " << stepperName_
627 <<
" did not pass stepper validation.");
630 template<
class Scalar>
633 TEUCHOS_TEST_FOR_EXCEPT(
true);
636 template<
class Scalar>
639 TEUCHOS_TEST_FOR_EXCEPT(
true);
640 return Teuchos::null;
643 template<
class Scalar>
646 TEUCHOS_TEST_FOR_EXCEPT(
true);
647 return Teuchos::null;
650 template<
class Scalar>
653 TEUCHOS_TEST_FOR_EXCEPT(
true);
654 return Teuchos::null;
657 template<
class Scalar>
660 TEUCHOS_TEST_FOR_EXCEPT(
true);
664 template<
class Scalar>
666 Teuchos::FancyOStream &out,
667 const Teuchos::EVerbosityLevel verbLevel
670 TEUCHOS_TEST_FOR_EXCEPT(
true);
673 template<
class Scalar>
675 const RCP<Thyra::ModelEvaluator<Scalar> >& model,
676 const Thyra::ModelEvaluatorBase::InArgs<Scalar>& initialCondition,
677 const RCP<Thyra::NonlinearSolverBase<Scalar> >& nlSolver
680 RCP<IntegratorBase<Scalar> > integrator = integratorBuilder_->create(model,initialCondition,nlSolver);
681 RCP<StepperBase<Scalar> > stepper = integrator->getNonconstStepper();
685 template<
class Scalar>
686 bool StepperValidator<Scalar>::isImplicitStepper_()
const
688 RCP<const StepperBuilder<Scalar> > sb = integratorBuilder_->getStepperBuilder();
689 RCP<StepperBase<Scalar> > stepper = sb->create(stepperName_);
690 return stepper->isImplicit();
693 template<
class Scalar>
694 Thyra::ModelEvaluatorBase::InArgs<Scalar> StepperValidator<Scalar>::getSomeIC_(
695 const Thyra::ModelEvaluator<Scalar>& model
699 Thyra::ModelEvaluatorBase::InArgs<Scalar> model_ic = model.createInArgs();
700 if (model_ic.supports(Thyra::ModelEvaluatorBase::IN_ARG_t)) {
701 Scalar time = Scalar(0.125);
702 model_ic.set_t(time);
704 if (model_ic.supports(Thyra::ModelEvaluatorBase::IN_ARG_x)) {
705 RCP<VectorBase<Scalar> > x_ic = Thyra::createMember(*(model.get_x_space()));
707 Thyra::DetachedVectorView<Scalar> x_ic_view( *x_ic );
708 x_ic_view[0] = Scalar(10.0);
710 model_ic.set_x(x_ic);
712 for (
int i=0 ; i<model_ic.Np() ; ++i) {
713 RCP<VectorBase<Scalar> > p_ic = Thyra::createMember(*(model.get_p_space(i)));
715 Thyra::DetachedVectorView<Scalar> p_ic_view( *p_ic );
716 p_ic_view[i] = Scalar(11.0+i);
718 model_ic.set_p(i,p_ic);
720 if (model_ic.supports(Thyra::ModelEvaluatorBase::IN_ARG_x_dot)) {
721 RCP<VectorBase<Scalar> > xdot_ic = Thyra::createMember(*(model.get_x_space()));
723 Thyra::DetachedVectorView<Scalar> xdot_ic_view( *xdot_ic );
724 xdot_ic_view[0] = Scalar(12.0);
726 model_ic.set_x_dot(xdot_ic);
732 template<
class Scalar>
733 void StepperValidator<Scalar>::validateIC_()
const
737 bool isImplicit = this->isImplicitStepper_();
738 RCP<StepperValidatorMockModel<Scalar> > model =
739 stepperValidatorMockModel<Scalar>(isImplicit);
741 Thyra::ModelEvaluatorBase::InArgs<Scalar> stepper_ic = this->getSomeIC_(*model);
743 RCP<Thyra::NonlinearSolverBase<Scalar> > nlSolver;
745 nlSolver = Rythmos::timeStepNonlinearSolver<Scalar>();
747 RCP<StepperBase<Scalar> > stepper = this->getStepper_(model,stepper_ic,nlSolver);
748 Scalar dt = Scalar(0.1);
749 stepper->takeStep(dt,STEP_TYPE_FIXED);
752 RCP<const std::vector<Thyra::ModelEvaluatorBase::InArgs<Scalar> > >
753 passedInArgs_ptr = model->getPassedInArgs();
754 const std::vector<Thyra::ModelEvaluatorBase::InArgs<Scalar> >&
755 passedInArgs = *passedInArgs_ptr;
756 bool valid_t =
false;
759 if ( (passedInArgs[0].get_t() == stepper_ic.get_t() ) ||
760 (passedInArgs[0].get_t() == stepper_ic.get_t()+dt) )
764 TEUCHOS_TEST_FOR_EXCEPTION( !valid_t, std::logic_error,
765 "Error! StepperValidator::validateIC: Time did not get correctly set on"
766 " the model through StepperBase::setInitialCondition!"
770 RCP<const VectorBase<Scalar> > p_out = passedInArgs[0].get_p(0);
771 TEUCHOS_TEST_FOR_EXCEPTION( is_null(p_out), std::logic_error,
772 "Error! StepperValidator::validateIC: Parameter 0 did not get set on the"
773 " model through StepperBase::setInitialCondition!"
776 Thyra::ConstDetachedVectorView<Scalar> p_out_view( *p_out );
777 TEUCHOS_TEST_FOR_EXCEPTION( p_out_view[0] != Scalar(11.0), std::logic_error,
778 "Error! StepperValidator::validateIC: Parameter 0 did not get set correctly on the model through StepperBase::setInitialCondition!"
787 template<
class Scalar>
788 void StepperValidator<Scalar>::validateStates_()
const
791 RCP<const StepperBuilder<Scalar> > sb =
792 integratorBuilder_->getStepperBuilder();
793 RCP<StepperBase<Scalar> > stepper = sb->create(stepperName_);
796 TimeRange<Scalar> tr = stepper->getTimeRange();
797 TEUCHOS_TEST_FOR_EXCEPTION( tr.isValid(), std::logic_error,
798 "Error! StepperValidator::validateStates: Uninitialized "
799 "stepper returned a valid time range!"
801 const StepStatus<Scalar> ss = stepper->getStepStatus();
802 TEUCHOS_TEST_FOR_EXCEPTION( ss.stepStatus != STEP_STATUS_UNINITIALIZED,
804 "Error! StepperValidator::validateStates: Uninitialized "
805 "stepper returned a valid step status!"
808 bool isImplicit = stepper->isImplicit();
809 RCP<StepperValidatorMockModel<Scalar> > model =
810 stepperValidatorMockModel<Scalar>(isImplicit);
811 Thyra::ModelEvaluatorBase::InArgs<Scalar> stepper_ic =
812 this->getSomeIC_(*model);
813 stepper->setInitialCondition(stepper_ic);
816 TimeRange<Scalar> tr = stepper->getTimeRange();
817 TEUCHOS_TEST_FOR_EXCEPTION( compareTimeValues(tr.lower(),tr.upper()) != 0,
819 "Error! StepperValidator::validateStates: Stepper with "
820 "initial condition returned a non zero time range!"
832 RCP<Thyra::NonlinearSolverBase<Scalar> > nlSolver;
834 nlSolver = timeStepNonlinearSolver<Scalar>();
836 stepper = this->getStepper_(model,stepper_ic,nlSolver);
839 TimeRange<Scalar> tr = stepper->getTimeRange();
840 TEUCHOS_TEST_FOR_EXCEPTION( compareTimeValues(tr.lower(),tr.upper()) != 0,
842 "Error! StepperValidator::validateStates: Fully initialized "
843 "stepper returned a non zero time range!"
852 Scalar dt = Scalar(0.1);
853 stepper->takeStep(dt,STEP_TYPE_FIXED);
856 TimeRange<Scalar> tr = stepper->getTimeRange();
857 TEUCHOS_TEST_FOR_EXCEPTION( compareTimeValues(tr.lower(),tr.upper()) >= 0,
859 "Error! StepperValidator::validateStates: Stepper returned "
860 "a zero (or invalid) time range after taking a step!"
862 const StepStatus<Scalar> ss = stepper->getStepStatus();
863 TEUCHOS_TEST_FOR_EXCEPTION( ss.stepStatus != STEP_STATUS_CONVERGED,
865 "Error! StepperValidator::validateStates: Stepper did not "
866 "return converged step status after taking a step!"
871 template<
class Scalar>
872 void StepperValidator<Scalar>::validateGetIC_()
const
875 typedef typename ScalarTraits<Scalar>::magnitudeType ScalarMag;
877 bool isImplicit = this->isImplicitStepper_();
878 RCP<StepperValidatorMockModel<Scalar> > model =
879 stepperValidatorMockModel<Scalar>(isImplicit);
881 Thyra::ModelEvaluatorBase::InArgs<Scalar> stepper_ic = this->getSomeIC_(*model);
883 RCP<Thyra::NonlinearSolverBase<Scalar> > nlSolver;
885 nlSolver = Rythmos::timeStepNonlinearSolver<Scalar>();
887 RCP<StepperBase<Scalar> > stepper = this->getStepper_(model,stepper_ic,nlSolver);
890 Array<Scalar> time_vec;
891 Array<RCP<const VectorBase<Scalar> > > x_vec;
892 Array<RCP<const VectorBase<Scalar> > > xdot_vec;
893 Array<ScalarMag> accuracy_vec;
894 time_vec.push_back(stepper_ic.get_t());
895 stepper->getPoints(time_vec,&x_vec,&xdot_vec,&accuracy_vec);
897 Thyra::ConstDetachedVectorView<Scalar> x_view( *x_vec[0] );
898 TEUCHOS_TEST_FOR_EXCEPTION( compareTimeValues<Scalar>(x_view[0],Scalar(10.0)) != 0,
900 "Error! StepperValidator::validateGetIC: Stepper did not return the initial"
901 " condition for X through getPoints prior to taking a step!"
904 if (isImplicit && !is_null(xdot_vec[0])) {
905 Thyra::ConstDetachedVectorView<Scalar> xdot_view( *xdot_vec[0] );
906 TEUCHOS_TEST_FOR_EXCEPTION( compareTimeValues<Scalar>(xdot_view[0],Scalar(12.0)) != 0,
908 "Error! StepperValidator::validateGetIC: Stepper did not return the initial"
909 " condition for XDOT through getPoints prior to taking a step!"
915 Scalar dt = Scalar(0.1);
916 stepper->takeStep(dt,STEP_TYPE_FIXED);
917 Array<Scalar> time_vec;
918 Array<RCP<const VectorBase<Scalar> > > x_vec;
919 Array<RCP<const VectorBase<Scalar> > > xdot_vec;
920 Array<ScalarMag> accuracy_vec;
921 time_vec.push_back(stepper_ic.get_t());
922 stepper->getPoints(time_vec,&x_vec,&xdot_vec,&accuracy_vec);
924 Thyra::ConstDetachedVectorView<Scalar> x_view( *x_vec[0] );
925 TEUCHOS_TEST_FOR_EXCEPTION( compareTimeValues<Scalar>(x_view[0],Scalar(10.0)) != 0,
927 "Error! StepperValidator::validateGetIC: Stepper did not return the initial"
928 " condition for X through getPoints after taking a step!"
931 if (isImplicit && !is_null(xdot_vec[0])) {
932 Thyra::ConstDetachedVectorView<Scalar> xdot_view( *xdot_vec[0] );
933 TEUCHOS_TEST_FOR_EXCEPTION( compareTimeValues<Scalar>(xdot_view[0],Scalar(12.0)) != 0,
935 "Error! StepperValidator::validateGetIC: Stepper did not return the initial"
936 " condition for XDOT through getPoints after taking a step!"
943 template<
class Scalar>
944 void StepperValidator<Scalar>::validateGetIC2_()
const
949 bool isImplicit = this->isImplicitStepper_();
950 RCP<StepperValidatorMockModel<Scalar> > model =
951 stepperValidatorMockModel<Scalar>(isImplicit);
953 Thyra::ModelEvaluatorBase::InArgs<Scalar> stepper_ic = this->getSomeIC_(*model);
955 RCP<Thyra::NonlinearSolverBase<Scalar> > nlSolver;
957 nlSolver = Rythmos::timeStepNonlinearSolver<Scalar>();
959 RCP<StepperBase<Scalar> > stepper = this->getStepper_(model,stepper_ic,nlSolver);
961 Thyra::ModelEvaluatorBase::InArgs<Scalar> new_ic = stepper->getInitialCondition();
965 TEUCHOS_ASSERT( new_ic.get_t() == stepper_ic.get_t() );
966 TEUCHOS_ASSERT( new_ic.get_x() == stepper_ic.get_x() );
967 for (
int i=0 ; i<stepper_ic.Np() ; ++i) {
968 TEUCHOS_ASSERT( new_ic.get_p(i) == stepper_ic.get_p(i) );
971 TEUCHOS_ASSERT( new_ic.get_x_dot() == stepper_ic.get_x_dot() );
977 template<
class Scalar>
978 void StepperValidator<Scalar>::validateGetNodes_()
const
983 RCP<const StepperBuilder<Scalar> > sb = integratorBuilder_->getStepperBuilder();
984 RCP<StepperBase<Scalar> > stepper = sb->create(stepperName_);
986 stepper->getNodes(&nodes);
987 TEUCHOS_TEST_FOR_EXCEPTION( nodes.size() != 0, std::logic_error,
988 "Error! StepperValidator::validateGetNodes: Uninitialized stepper returned non-empty node list!"
992 bool isImplicit = this->isImplicitStepper_();
993 RCP<StepperValidatorMockModel<Scalar> > model =
994 stepperValidatorMockModel<Scalar>(isImplicit);
995 Thyra::ModelEvaluatorBase::InArgs<Scalar> stepper_ic = this->getSomeIC_(*model);
996 RCP<Thyra::NonlinearSolverBase<Scalar> > nlSolver;
998 nlSolver = Rythmos::timeStepNonlinearSolver<Scalar>();
1000 RCP<StepperBase<Scalar> > stepper = this->getStepper_(model,stepper_ic,nlSolver);
1002 Array<Scalar> nodes;
1003 stepper->getNodes(&nodes);
1004 TEUCHOS_TEST_FOR_EXCEPTION( nodes.size() == 0, std::logic_error,
1005 "Error! StepperValidator::validateGetNodes: Initialized stepper returned empty node list!"
1007 TEUCHOS_TEST_FOR_EXCEPTION( nodes.size() > 1, std::logic_error,
1008 "Error! StepperValidator::validateGetNodes: Initialized stepper returned node list with more than one node!"
1012 Scalar dt = Scalar(0.1);
1013 stepper->takeStep(dt,STEP_TYPE_FIXED);
1015 Array<Scalar> nodes;
1016 stepper->getNodes(&nodes);
1017 TEUCHOS_TEST_FOR_EXCEPTION( nodes.size() == 0, std::logic_error,
1018 "Error! StepperValidator::validateGetNodes: After taking a step, stepper returned empty node list!"
1020 TEUCHOS_TEST_FOR_EXCEPTION( nodes.size() == 1, std::logic_error,
1021 "Error! StepperValidator::validateGetNodes: After taking a step, stepper returned node list with only one node!"
1023 TEUCHOS_TEST_FOR_EXCEPTION( nodes.size() > 2, std::logic_error,
1024 "Error! StepperValidator::validateGetNodes: After taking a step, stepper returned node list with more than two nodes!"
1031 #endif //Rythmos_STEPPER_VALIDATOR_H
std::string description() const
Concrete integrator builder class.
RCP< Teuchos::ParameterList > unsetParameterList()
Class for validating steppers.
RCP< const Teuchos::ParameterList > getValidParameters() const
RCP< Teuchos::ParameterList > getNonconstParameterList()
void setParameterList(RCP< Teuchos::ParameterList > const ¶mList)
void validateStepper() const
Validate the stepper by the StepperBuilder.
void setIntegratorBuilder(const RCP< IntegratorBuilder< Scalar > > &integratorBuilder)
Set a Integrator Builder object.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const