14 #include "Thyra_VectorStdOps.hpp" 
   16 #include "Tempus_IntegratorBasic.hpp" 
   17 #include "Tempus_IntegratorObserverSubcycling.hpp" 
   19 #include "Tempus_StepperFactory.hpp" 
   20 #include "Tempus_StepperForwardEuler.hpp" 
   21 #include "Tempus_StepperBackwardEuler.hpp" 
   22 #include "Tempus_StepperSubcycling.hpp" 
   23 #include "Tempus_StepperOperatorSplit.hpp" 
   27 #include "../TestModels/SinCosModel.hpp" 
   28 #include "../TestModels/VanDerPol_IMEX_ExplicitModel.hpp" 
   29 #include "../TestModels/VanDerPol_IMEX_ImplicitModel.hpp" 
   30 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp" 
   35 namespace Tempus_Test {
 
   37 using Teuchos::getParametersFromXmlFile;
 
   41 using Teuchos::rcp_const_cast;
 
   42 using Teuchos::rcp_dynamic_cast;
 
   43 using Teuchos::sublist;
 
   55       getParametersFromXmlFile(
"Tempus_Subcycling_SinCos.xml");
 
   70         Tempus::createIntegratorBasic<double>(tempusPL, model);
 
   74         integrator->getStepper()->getValidParameters();
 
   76     bool pass = haveSameValuesSorted(*stepperPL, *defaultPL, 
true);
 
   79       out << 
"stepperPL -------------- \n" 
   80           << *stepperPL << std::endl;
 
   81       out << 
"defaultPL -------------- \n" 
   82           << *defaultPL << std::endl;
 
   90         Tempus::createIntegratorBasic<double>(model,
 
   91                                               std::string(
"Forward Euler"));
 
   95         integrator->getStepper()->getValidParameters();
 
   97     bool pass = haveSameValuesSorted(*stepperPL, *defaultPL, 
true);
 
  100       out << 
"stepperPL -------------- \n" 
  101           << *stepperPL << std::endl;
 
  102       out << 
"defaultPL -------------- \n" 
  103           << *defaultPL << std::endl;
 
  122   stepper->setSubcyclingStepper(stepperFE);
 
  124   stepper->setSubcyclingMinTimeStep(0.1);
 
  125   stepper->setSubcyclingInitTimeStep(0.1);
 
  126   stepper->setSubcyclingMaxTimeStep(0.1);
 
  127   stepper->setSubcyclingMaxFailures(10);
 
  128   stepper->setSubcyclingMaxConsecFailures(5);
 
  129   stepper->setSubcyclingScreenOutputIndexInterval(1);
 
  130   stepper->setSubcyclingIntegratorObserver(
 
  132   stepper->setSubcyclingPrintDtChanges(
true);
 
  137   stepper->setSubcyclingTimeStepControlStrategy(subStrategy);
 
  141   timeStepControl->setInitIndex(0);
 
  142   timeStepControl->setFinalIndex(10);
 
  143   timeStepControl->setInitTime(0.0);
 
  144   timeStepControl->setFinalTime(1.0);
 
  145   timeStepControl->setInitTimeStep(dt);
 
  149   strategy->initialize();
 
  150   timeStepControl->setTimeStepControlStrategy(strategy);
 
  152   timeStepControl->initialize();
 
  155   auto inArgsIC   = stepper->getModel()->getNominalValues();
 
  158   icState->setTime(timeStepControl->getInitTime());
 
  159   icState->setIndex(timeStepControl->getInitIndex());
 
  160   icState->setTimeStep(0.0);                           
 
  165   solutionHistory->setName(
"Forward States");
 
  167   solutionHistory->setStorageLimit(2);
 
  168   solutionHistory->addState(icState);
 
  171   stepper->setInitialConditions(solutionHistory);
 
  172   stepper->initialize();
 
  176       Tempus::createIntegratorBasic<double>();
 
  177   integrator->setStepper(stepper);
 
  178   integrator->setTimeStepControl(timeStepControl);
 
  179   integrator->setSolutionHistory(solutionHistory);
 
  180   integrator->setScreenOutputIndexInterval(1);
 
  182   integrator->initialize();
 
  185   bool integratorStatus = integrator->advanceTime();
 
  189   double time      = integrator->getTime();
 
  190   double timeFinal = 1.0;
 
  196       model->getExactSolution(time).get_x();
 
  200   Thyra::V_StVpStV(xdiff.
ptr(), 1.0, *x_exact, -1.0, *(x));
 
  203   out << 
"  Stepper = " << stepper->description() << std::endl;
 
  204   out << 
"  =========================" << std::endl;
 
  205   out << 
"  Exact solution   : " << get_ele(*(x_exact), 0) << 
"   " 
  206       << get_ele(*(x_exact), 1) << std::endl;
 
  207   out << 
"  Computed solution: " << get_ele(*(x), 0) << 
"   " 
  208       << get_ele(*(x), 1) << std::endl;
 
  209   out << 
"  Difference       : " << get_ele(*(xdiff), 0) << 
"   " 
  210       << get_ele(*(xdiff), 1) << std::endl;
 
  211   out << 
"  =========================" << std::endl;
 
  221   std::vector<RCP<Thyra::VectorBase<double>>> solutions;
 
  222   std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
 
  223   std::vector<double> StepSize;
 
  228   const int nTimeStepSizes       = 2;
 
  229   std::string output_file_string = 
"Tempus_Subcycling_SinCos";
 
  230   std::string output_file_name   = output_file_string + 
".dat";
 
  231   std::string err_out_file_name  = output_file_string + 
"-Error.dat";
 
  233   for (
int n = 0; n < nTimeStepSizes; n++) {
 
  243     stepper->setSubcyclingStepper(stepperFE);
 
  245     stepper->setSubcyclingMinTimeStep(dt / 10.0);
 
  246     stepper->setSubcyclingInitTimeStep(dt / 10.0);
 
  247     stepper->setSubcyclingMaxTimeStep(dt);
 
  248     stepper->setSubcyclingMaxFailures(10);
 
  249     stepper->setSubcyclingMaxConsecFailures(5);
 
  250     stepper->setSubcyclingScreenOutputIndexInterval(1);
 
  257     strategy->setMinEta(0.02);
 
  258     strategy->setMaxEta(0.04);
 
  259     strategy->initialize();
 
  260     stepper->setSubcyclingTimeStepControlStrategy(strategy);
 
  264     timeStepControl->setInitIndex(0);
 
  265     timeStepControl->setInitTime(0.0);
 
  266     timeStepControl->setFinalTime(1.0);
 
  267     timeStepControl->setMinTimeStep(dt);
 
  268     timeStepControl->setInitTimeStep(dt);
 
  269     timeStepControl->setMaxTimeStep(dt);
 
  270     timeStepControl->initialize();
 
  273     auto inArgsIC = stepper->getModel()->getNominalValues();
 
  277     icState->setTime(timeStepControl->getInitTime());
 
  278     icState->setIndex(timeStepControl->getInitIndex());
 
  279     icState->setTimeStep(0.0);                           
 
  284     solutionHistory->setName(
"Forward States");
 
  286     solutionHistory->setStorageLimit(2);
 
  287     solutionHistory->addState(icState);
 
  290     stepper->setInitialConditions(solutionHistory);
 
  291     stepper->initialize();
 
  294     integrator = Tempus::createIntegratorBasic<double>();
 
  295     integrator->setStepper(stepper);
 
  296     integrator->setTimeStepControl(timeStepControl);
 
  297     integrator->setSolutionHistory(solutionHistory);
 
  298     integrator->setScreenOutputIndexInterval(10);
 
  300     integrator->initialize();
 
  303     bool integratorStatus = integrator->advanceTime();
 
  307     time             = integrator->getTime();
 
  308     double timeFinal = 1.0;
 
  314         model->getExactSolution(time).get_x();
 
  345     StepSize.push_back(dt);
 
  346     auto solution = Thyra::createMember(model->get_x_space());
 
  347     Thyra::copy(*(integrator->getX()), solution.ptr());
 
  348     solutions.push_back(solution);
 
  349     if (n == nTimeStepSizes - 1) {  
 
  350       StepSize.push_back(0.0);
 
  351       auto solutionExact = Thyra::createMember(model->get_x_space());
 
  352       Thyra::copy(*(model->getExactSolution(time).get_x()),
 
  353                   solutionExact.ptr());
 
  354       solutions.push_back(solutionExact);
 
  359   if (nTimeStepSizes > 1) {
 
  361     double xDotSlope = 0.0;
 
  362     std::vector<double> xErrorNorm;
 
  363     std::vector<double> xDotErrorNorm;
 
  367                     solutions, xErrorNorm, xSlope, solutionsDot, xDotErrorNorm,
 
  384   std::vector<RCP<Thyra::VectorBase<double>>> solutions;
 
  385   std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
 
  386   std::vector<double> StepSize;
 
  387   std::vector<double> xErrorNorm;
 
  388   std::vector<double> xDotErrorNorm;
 
  389   const int nTimeStepSizes = 4;  
 
  392   for (
int n = 0; n < nTimeStepSizes; n++) {
 
  395     if (n == nTimeStepSizes - 1) dt /= 10.0;
 
  400         tmpModel->getValidParameters());
 
  401     pl->
set(
"Coeff epsilon", 0.1);
 
  413     stepperFE->setUseFSAL(
false);
 
  414     stepperFE->initialize();
 
  415     stepperSC->setSubcyclingStepper(stepperFE);
 
  417     stepperSC->setSubcyclingMinTimeStep(0.00001);
 
  418     stepperSC->setSubcyclingInitTimeStep(dt / 10.0);
 
  419     stepperSC->setSubcyclingMaxTimeStep(dt / 10.0);
 
  420     stepperSC->setSubcyclingMaxFailures(10);
 
  421     stepperSC->setSubcyclingMaxConsecFailures(5);
 
  422     stepperSC->setSubcyclingScreenOutputIndexInterval(1);
 
  428     strategySC->setMinEta(0.000001);
 
  429     strategySC->setMaxEta(0.01);
 
  430     strategySC->initialize();
 
  431     stepperSC->setSubcyclingTimeStepControlStrategy(strategySC);
 
  439     stepper->addStepper(stepperSC);
 
  440     stepper->addStepper(stepperBE);
 
  444     timeStepControl->setInitIndex(0);
 
  445     timeStepControl->setInitTime(0.0);
 
  447     timeStepControl->setFinalTime(2.0);
 
  448     timeStepControl->setMinTimeStep(0.000001);
 
  449     timeStepControl->setInitTimeStep(dt);
 
  450     timeStepControl->setMaxTimeStep(dt);
 
  462     timeStepControl->initialize();
 
  465     auto inArgsIC = stepper->getModel()->getNominalValues();
 
  470     icState->setTime(timeStepControl->getInitTime());
 
  471     icState->setIndex(timeStepControl->getInitIndex());
 
  472     icState->setTimeStep(0.0);  
 
  473     icState->setOrder(stepper->getOrder());
 
  478     solutionHistory->setName(
"Forward States");
 
  481     solutionHistory->setStorageLimit(3);
 
  482     solutionHistory->addState(icState);
 
  485     stepperSC->setInitialConditions(solutionHistory);
 
  486     stepper->initialize();
 
  489     integrator = Tempus::createIntegratorBasic<double>();
 
  490     integrator->setStepper(stepper);
 
  491     integrator->setTimeStepControl(timeStepControl);
 
  492     integrator->setSolutionHistory(solutionHistory);
 
  493     integrator->setScreenOutputIndexInterval(10);
 
  495     integrator->initialize();
 
  498     bool integratorStatus = integrator->advanceTime();
 
  502     time             = integrator->getTime();
 
  503     double timeFinal = 2.0;
 
  504     double tol       = 100.0 * std::numeric_limits<double>::epsilon();
 
  508     StepSize.push_back(dt);
 
  509     auto solution = Thyra::createMember(implicitModel->get_x_space());
 
  510     Thyra::copy(*(integrator->getX()), solution.ptr());
 
  511     solutions.push_back(solution);
 
  512     auto solutionDot = Thyra::createMember(implicitModel->get_x_space());
 
  513     Thyra::copy(*(integrator->getXDot()), solutionDot.ptr());
 
  514     solutionsDot.push_back(solutionDot);
 
  518     if ((n == 0) || (n == nTimeStepSizes - 1)) {
 
  519       std::string fname = 
"Tempus_Subcycling_VanDerPol-Ref.dat";
 
  520       if (n == 0) fname = 
"Tempus_Subcycling_VanDerPol.dat";
 
  528   double xDotSlope                     = 0.0;
 
  531   writeOrderError(
"Tempus_Subcycling_VanDerPol-Error.dat", stepper, StepSize,
 
  532                   solutions, xErrorNorm, xSlope, solutionsDot, xDotErrorNorm,
 
Teuchos::RCP< SolutionState< Scalar > > createSolutionStateX(const Teuchos::RCP< Thyra::VectorBase< Scalar > > &x, const Teuchos::RCP< Thyra::VectorBase< Scalar > > &xdot=Teuchos::null, const Teuchos::RCP< Thyra::VectorBase< Scalar > > &xdotdot=Teuchos::null)
Nonmember constructor from non-const solution vectors, x. 
van der Pol model formulated for IMEX-RK. 
StepControlStrategy class for TimeStepControl. 
void writeOrderError(const std::string filename, Teuchos::RCP< Tempus::Stepper< Scalar >> stepper, std::vector< Scalar > &StepSize, std::vector< Teuchos::RCP< Thyra::VectorBase< Scalar >>> &solutions, std::vector< Scalar > &xErrorNorm, Scalar &xSlope, std::vector< Teuchos::RCP< Thyra::VectorBase< Scalar >>> &solutionsDot, std::vector< Scalar > &xDotErrorNorm, Scalar &xDotSlope, std::vector< Teuchos::RCP< Thyra::VectorBase< Scalar >>> &solutionsDotDot, std::vector< Scalar > &xDotDotErrorNorm, Scalar &xDotDotSlope, Teuchos::FancyOStream &out)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation  with a...
void writeSolution(const std::string filename, Teuchos::RCP< const Tempus::SolutionHistory< Scalar >> solutionHistory)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
OperatorSplit stepper loops through the Stepper list. 
Teuchos::RCP< StepperForwardEuler< Scalar > > createStepperForwardEuler(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList. 
TEUCHOS_UNIT_TEST(BackwardEuler, SinCos_ASA)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
static void summarize(Ptr< const Comm< int > > comm, std::ostream &out=std::cout, const bool alwaysWriteLocal=false, const bool writeGlobalStats=true, const bool writeZeroTimers=true, const ECounterSetOp setOp=Intersection, const std::string &filter="", const bool ignoreZeroTimers=false)
TimeStepControl manages the time step size. There several mechanisms that effect the time step size a...
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Keep a fix number of states. 
StepControlStrategy class for TimeStepControl. 
Teuchos::RCP< StepperBackwardEuler< Scalar > > createStepperBackwardEuler(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList. 
van der Pol model formulated for IMEX. 
IntegratorObserverSubcycling class for time integrators. This basic class has simple no-op functions...
Grow the history as needed. 
Solution state for integrators and steppers.