12#include "Tempus_StepperLeapfrog.hpp" 
   18#include "../TestModels/HarmonicOscillatorModel.hpp" 
   22using Teuchos::ParameterList;
 
   25using Teuchos::rcp_const_cast;
 
   26using Teuchos::rcp_dynamic_cast;
 
   27using Teuchos::sublist;
 
   37  stepper->setModel(model);
 
   38  stepper->initialize();
 
   39  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
 
   43  stepper->setAppAction(modifier);
 
   44  bool useFSAL              = stepper->getUseFSAL();
 
   45  std::string ICConsistency = stepper->getICConsistency();
 
   46  bool ICConsistencyCheck   = stepper->getICConsistencyCheck();
 
   49  stepper->setAppAction(modifier);
 
   50  stepper->initialize();
 
   51  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
 
   52  stepper->setUseFSAL(useFSAL);
 
   53  stepper->initialize();
 
   54  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
 
   55  stepper->setICConsistency(ICConsistency);
 
   56  stepper->initialize();
 
   57  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
 
   58  stepper->setICConsistencyCheck(ICConsistencyCheck);
 
   59  stepper->initialize();
 
   60  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
 
   64      model, useFSAL, ICConsistency, ICConsistencyCheck, modifier));
 
   65  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
 
   68  TEUCHOS_ASSERT(stepper->getOrder() == 2);
 
 
   81class StepperLeapfrogModifierTest
 
   85  StepperLeapfrogModifierTest()
 
   86    : testBEGIN_STEP(false),
 
   87      testBEFORE_X_UPDATE(false),
 
   88      testBEFORE_EXPLICIT_EVAL(false),
 
   89      testBEFORE_XDOT_UPDATE(false),
 
   91      testCurrentValue(-0.99),
 
   92      testWorkingValue(-0.99),
 
   99  virtual ~StepperLeapfrogModifierTest() {}
 
  109      case StepperLeapfrogAppAction<double>::BEGIN_STEP: {
 
  110        testBEGIN_STEP   = 
true;
 
  111        auto x           = sh->getCurrentState()->getX();
 
  112        testCurrentValue = get_ele(*(x), 0);
 
  115      case StepperLeapfrogAppAction<double>::BEFORE_EXPLICIT_EVAL: {
 
  116        testBEFORE_EXPLICIT_EVAL = 
true;
 
  117        testDt                   = sh->getWorkingState()->getTimeStep() / 10.0;
 
  118        sh->getWorkingState()->setTimeStep(testDt);
 
  121      case StepperLeapfrogAppAction<double>::BEFORE_X_UPDATE: {
 
  122        testBEFORE_X_UPDATE = 
true;
 
  123        testName            = 
"Leapfrog - Modifier";
 
  124        stepper->setStepperName(testName);
 
  127      case StepperLeapfrogAppAction<double>::BEFORE_XDOT_UPDATE: {
 
  128        testBEFORE_XDOT_UPDATE = 
true;
 
  129        auto x                 = sh->getWorkingState()->getX();
 
  130        testWorkingValue       = get_ele(*(x), 0);
 
  133      case StepperLeapfrogAppAction<double>::END_STEP: {
 
  138        TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
 
  139                                   "Error - unknown action location.\n");
 
  143  bool testBEFORE_X_UPDATE;
 
  144  bool testBEFORE_EXPLICIT_EVAL;
 
  145  bool testBEFORE_XDOT_UPDATE;
 
  147  double testCurrentValue;
 
  148  double testWorkingValue;
 
  150  std::string testName;
 
  159  stepper->setModel(model);
 
  160  auto modifier = rcp(
new StepperLeapfrogModifierTest());
 
  161  stepper->setAppAction(modifier);
 
  162  stepper->initialize();
 
  166  timeStepControl->setInitTimeStep(15.0);
 
  167  timeStepControl->initialize();
 
  170  auto inArgsIC = model->getNominalValues();
 
  171  auto icX      = rcp_const_cast<Thyra::VectorBase<double> >(inArgsIC.get_x());
 
  173      rcp_const_cast<Thyra::VectorBase<double> >(inArgsIC.get_x_dot());
 
  175      rcp_const_cast<Thyra::VectorBase<double> >(inArgsIC.get_x_dot_dot());
 
  176  auto icState = Tempus::createSolutionStateX<double>(icX, icXDot, icXDotDot);
 
  177  icState->setTime(timeStepControl->getInitTime());
 
  178  icState->setIndex(timeStepControl->getInitIndex());
 
  179  icState->setTimeStep(15.0);
 
  180  icState->setOrder(stepper->getOrder());
 
  185  solutionHistory->setName(
"Forward States");
 
  187  solutionHistory->setStorageLimit(2);
 
  188  solutionHistory->addState(icState);
 
  191  stepper->setInitialConditions(solutionHistory);
 
  192  solutionHistory->initWorkingState();
 
  193  solutionHistory->getWorkingState()->setTimeStep(15.0);
 
  194  stepper->takeStep(solutionHistory);
 
  196  TEST_COMPARE(modifier->testBEGIN_STEP, ==, 
true);
 
  197  TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==, 
true);
 
  198  TEST_COMPARE(modifier->testBEFORE_X_UPDATE, ==, 
true);
 
  199  TEST_COMPARE(modifier->testBEFORE_XDOT_UPDATE, ==, 
true);
 
  200  TEST_COMPARE(modifier->testEND_STEP, ==, 
true);
 
  202  auto x = solutionHistory->getCurrentState()->getX();
 
  203  TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(x), 0), 1.0e-15);
 
  204  x = solutionHistory->getWorkingState()->getX();
 
  205  TEST_FLOATING_EQUALITY(modifier->testWorkingValue, get_ele(*(x), 0), 1.0e-15);
 
  206  auto Dt = solutionHistory->getWorkingState()->getTimeStep();
 
  207  TEST_FLOATING_EQUALITY(modifier->testDt, Dt, 1.0e-15);
 
  209  TEST_COMPARE(modifier->testName, ==, 
"Leapfrog - Modifier");
 
 
  213class StepperLeapfrogModifierXTest
 
  217  StepperLeapfrogModifierXTest()
 
  218    : testX_BEGIN_STEP(false),
 
  219      testX_BEFORE_EXPLICIT_EVAL(false),
 
  220      testX_BEFORE_X_UPDATE(false),
 
  221      testX_BEFORE_XDOT_UPDATE(false),
 
  222      testX_END_STEP(false),
 
  231  virtual ~StepperLeapfrogModifierXTest() {}
 
  241      case StepperLeapfrogModifierXBase<double>::X_BEGIN_STEP: {
 
  242        testX_BEGIN_STEP = 
true;
 
  243        testX            = get_ele(*(x), 0);
 
  246      case StepperLeapfrogModifierXBase<double>::X_BEFORE_EXPLICIT_EVAL: {
 
  247        testX_BEFORE_EXPLICIT_EVAL = 
true;
 
  251      case StepperLeapfrogModifierXBase<double>::X_BEFORE_X_UPDATE: {
 
  252        testX_BEFORE_X_UPDATE = 
true;
 
  256      case StepperLeapfrogModifierXBase<double>::X_BEFORE_XDOT_UPDATE: {
 
  257        testX_BEFORE_XDOT_UPDATE = 
true;
 
  258        testName                 = 
"Leapfrog - ModifierX";
 
  261      case StepperLeapfrogModifierXBase<double>::X_END_STEP: {
 
  262        testX_END_STEP = 
true;
 
  266        TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
 
  267                                   "Error - unknown action location.\n");
 
  270  bool testX_BEGIN_STEP;
 
  271  bool testX_BEFORE_EXPLICIT_EVAL;
 
  272  bool testX_BEFORE_X_UPDATE;
 
  273  bool testX_BEFORE_XDOT_UPDATE;
 
  278  std::string testName;
 
  287  stepper->setModel(model);
 
  288  auto modifierX = rcp(
new StepperLeapfrogModifierXTest());
 
  289  stepper->setAppAction(modifierX);
 
  290  stepper->initialize();
 
  294  timeStepControl->setInitTimeStep(15.0);
 
  295  timeStepControl->initialize();
 
  298  auto inArgsIC = model->getNominalValues();
 
  299  auto icX      = rcp_const_cast<Thyra::VectorBase<double> >(inArgsIC.get_x());
 
  301      rcp_const_cast<Thyra::VectorBase<double> >(inArgsIC.get_x_dot());
 
  303      rcp_const_cast<Thyra::VectorBase<double> >(inArgsIC.get_x_dot_dot());
 
  304  auto icState = Tempus::createSolutionStateX<double>(icX, icXDot, icXDotDot);
 
  305  icState->setTime(timeStepControl->getInitTime());
 
  306  icState->setIndex(timeStepControl->getInitIndex());
 
  307  icState->setTimeStep(15.0);
 
  308  icState->setOrder(stepper->getOrder());
 
  313  solutionHistory->setName(
"Forward States");
 
  315  solutionHistory->setStorageLimit(2);
 
  316  solutionHistory->addState(icState);
 
  319  stepper->setInitialConditions(solutionHistory);
 
  320  solutionHistory->initWorkingState();
 
  321  solutionHistory->getWorkingState()->setTimeStep(15.0);
 
  322  stepper->takeStep(solutionHistory);
 
  324  TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==, 
true);
 
  325  TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==, 
true);
 
  326  TEST_COMPARE(modifierX->testX_BEFORE_XDOT_UPDATE, ==, 
true);
 
  327  TEST_COMPARE(modifierX->testX_BEFORE_X_UPDATE, ==, 
true);
 
  328  TEST_COMPARE(modifierX->testX_END_STEP, ==, 
true);
 
  330  auto x = solutionHistory->getCurrentState()->getX();
 
  331  TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(x), 0), 1.0e-15);
 
  332  auto Dt = solutionHistory->getWorkingState()->getTimeStep();
 
  333  TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, 1.0e-15);
 
  334  auto time = solutionHistory->getWorkingState()->getTime();
 
  335  TEST_FLOATING_EQUALITY(modifierX->testTime, time, 1.0e-15);
 
  336  TEST_COMPARE(modifierX->testName, ==, 
"Leapfrog - ModifierX");
 
 
  341class StepperLeapfrogObserverTest
 
  345  StepperLeapfrogObserverTest()
 
  346    : testBEGIN_STEP(false),
 
  347      testBEFORE_EXPLICIT_EVAL(false),
 
  348      testBEFORE_X_UPDATE(false),
 
  349      testBEFORE_XDOT_UPDATE(false),
 
  351      testCurrentValue(-0.99),
 
  352      testWorkingValue(-0.99),
 
  358  virtual ~StepperLeapfrogObserverTest() {}
 
  361  virtual void observe(
 
  368      case StepperLeapfrogAppAction<double>::BEGIN_STEP: {
 
  369        testBEGIN_STEP   = 
true;
 
  370        auto x           = sh->getCurrentState()->getX();
 
  371        testCurrentValue = get_ele(*(x), 0);
 
  374      case StepperLeapfrogAppAction<double>::BEFORE_EXPLICIT_EVAL: {
 
  375        testBEFORE_EXPLICIT_EVAL = 
true;
 
  376        testDt                   = sh->getWorkingState()->getTimeStep();
 
  379      case StepperLeapfrogAppAction<double>::BEFORE_X_UPDATE: {
 
  380        testBEFORE_X_UPDATE = 
true;
 
  381        testName            = stepper->getStepperType();
 
  384      case StepperLeapfrogAppAction<double>::BEFORE_XDOT_UPDATE: {
 
  385        testBEFORE_XDOT_UPDATE = 
true;
 
  386        auto x                 = sh->getWorkingState()->getX();
 
  387        testWorkingValue       = get_ele(*(x), 0);
 
  390      case StepperLeapfrogAppAction<double>::END_STEP: {
 
  395        TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
 
  396                                   "Error - unknown action location.\n");
 
  400  bool testBEFORE_EXPLICIT_EVAL;
 
  401  bool testBEFORE_X_UPDATE;
 
  402  bool testBEFORE_XDOT_UPDATE;
 
  404  double testCurrentValue;
 
  405  double testWorkingValue;
 
  407  std::string testName;
 
  416  stepper->setModel(model);
 
  417  auto observer = rcp(
new StepperLeapfrogObserverTest());
 
  418  stepper->setAppAction(observer);
 
  419  stepper->initialize();
 
  424  timeStepControl->setInitTimeStep(dt);
 
  425  timeStepControl->initialize();
 
  428  auto inArgsIC = model->getNominalValues();
 
  429  auto icX      = rcp_const_cast<Thyra::VectorBase<double> >(inArgsIC.get_x());
 
  431      rcp_const_cast<Thyra::VectorBase<double> >(inArgsIC.get_x_dot());
 
  433      rcp_const_cast<Thyra::VectorBase<double> >(inArgsIC.get_x_dot_dot());
 
  434  auto icState = Tempus::createSolutionStateX<double>(icX, icXDot, icXDotDot);
 
  435  icState->setTime(timeStepControl->getInitTime());
 
  436  icState->setIndex(timeStepControl->getInitIndex());
 
  437  icState->setTimeStep(dt);
 
  438  icState->setOrder(stepper->getOrder());
 
  443  solutionHistory->setName(
"Forward States");
 
  445  solutionHistory->setStorageLimit(2);
 
  446  solutionHistory->addState(icState);
 
  449  stepper->setInitialConditions(solutionHistory);
 
  450  solutionHistory->initWorkingState();
 
  451  solutionHistory->getWorkingState()->setTimeStep(dt);
 
  452  stepper->takeStep(solutionHistory);
 
  455  TEST_COMPARE(observer->testBEGIN_STEP, ==, 
true);
 
  456  TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==, 
true);
 
  457  TEST_COMPARE(observer->testBEFORE_X_UPDATE, ==, 
true);
 
  458  TEST_COMPARE(observer->testBEFORE_XDOT_UPDATE, ==, 
true);
 
  459  TEST_COMPARE(observer->testEND_STEP, ==, 
true);
 
  461  auto x = solutionHistory->getCurrentState()->getX();
 
  462  TEST_FLOATING_EQUALITY(observer->testCurrentValue, get_ele(*(x), 0), 1.0e-15);
 
  463  x = solutionHistory->getWorkingState()->getX();
 
  464  TEST_FLOATING_EQUALITY(observer->testWorkingValue, get_ele(*(x), 0), 1.0e-15);
 
  465  TEST_FLOATING_EQUALITY(observer->testDt, dt, 1.0e-15);
 
  467  TEST_COMPARE(observer->testName, ==, 
"Leapfrog");
 
 
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
 
ACTION_LOCATION
Indicates the location of application action (see algorithm).
 
Base modifier for StepperLeapfrog.
 
Default modifier for StepperLeapfrog.
 
Base ModifierX for StepperLeapfrog.
 
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > >, const double, const double, const MODIFIER_TYPE modType)=0
Modify solution based on the MODIFIER_TYPE.
 
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
 
Base observer for StepperLeapfrog.
 
TimeStepControl manages the time step size. There several mechanisms that effect the time step size a...
 
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
 
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
 
@ STORAGE_TYPE_STATIC
Keep a fix number of states.