Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_UnitTest_Utils.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ****************************************************************************
3 // Tempus: Copyright (2017) Sandia Corporation
4 //
5 // Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
6 // ****************************************************************************
7 // @HEADER
8 
9 #ifndef Tempus_UnitTest_Utils_hpp
10 #define Tempus_UnitTest_Utils_hpp
11 
12 #include "NOX_Thyra.H"
13 
14 #include "Tempus_StepperFactory.hpp"
16 
17 #include "Tempus_SolutionHistory.hpp"
18 
19 #include "Tempus_StepperIMEX_RK.hpp"
20 #include "Tempus_StepperIMEX_RK_Partition.hpp"
21 
29 
30 #include "../TestModels/SinCosModel.hpp"
31 #include "../TestModels/VanDerPolModel.hpp"
32 
33 namespace Tempus_Unit_Test {
34 
35 using Teuchos::RCP;
36 using Teuchos::rcp;
37 using Teuchos::rcp_const_cast;
38 using Teuchos::rcp_dynamic_cast;
40 
42 
45 void testFactoryConstruction(std::string stepperType,
46  const Teuchos::RCP<const Thyra::ModelEvaluator<double> >& model)
47 {
49 
50  // Test using stepperType
51  // Passing in model.
52  auto stepper = sf->createStepper(stepperType, model);
53  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
54  // With setting model.
55  stepper = sf->createStepper(stepperType);
56  stepper->setModel(model);
57  stepper->initialize();
58  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
59 
60  // Test using ParameterList.
61  // Passing in model.
62  auto stepperPL = rcp_const_cast<ParameterList>(stepper->getValidParameters());
63  stepper = sf->createStepper(stepperPL, model);
64  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
65  // With setting model.
66  stepper = sf->createStepper(stepperPL);
67  stepper->setModel(model);
68  stepper->initialize();
69  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
70 }
71 
72 
76  const RCP<Tempus::StepperExplicitRK<double> >& stepper)
77 {
78  auto model = rcp(new Tempus_Test::SinCosModel<double>());
79  stepper->setModel(model);
80  stepper->initialize();
81  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
82 
83  // Default values for construction.
84  auto modifier = rcp(new Tempus::StepperRKModifierDefault<double>());
85  auto modifierX = rcp(new Tempus::StepperRKModifierXDefault<double>());
86  auto observer = rcp(new Tempus::StepperRKObserverDefault<double>());
87  bool useFSAL = stepper->getUseFSAL();
88  std::string ICConsistency = stepper->getICConsistency();
89  bool ICConsistencyCheck = stepper->getICConsistencyCheck();
90  bool useEmbedded = stepper->getUseEmbedded();
91 
92  // Test the set functions.
93  stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
94  stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
95  stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
96  stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
97  stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
98  stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
99  stepper->setUseEmbedded(useEmbedded); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
100 
101 
102  std::string stepperType = stepper->getStepperType();
103  // Full argument list construction.
104  if (stepperType == "RK Explicit 3 Stage 3rd order") {
106  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
107  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
108  } else if (stepperType == "RK Explicit 3 Stage 3rd order by Heun") {
110  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
111  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
112  } else if (stepperType == "RK Explicit 3 Stage 3rd order TVD") {
114  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
115  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
116  } else if (stepperType == "RK Explicit 3/8 Rule") {
118  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
119  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
120  } else if (stepperType == "RK Explicit 4 Stage 3rd order by Runge") {
122  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
123  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
124  } else if (stepperType == "RK Explicit 4 Stage") {
126  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
127  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
128  } else if (stepperType == "RK Explicit 5 Stage 3rd order by Kinnmark and Gray") {
130  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
131  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
132  } else if (stepperType == "Bogacki-Shampine 3(2) Pair") {
134  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
135  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
136  } else if (stepperType == "RK Forward Euler") {
138  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
139  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
140  } else if (stepperType == "Merson 4(5) Pair") {
142  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
143  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
144  } else if (stepperType == "RK Explicit Midpoint") {
146  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
147  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
148  } else if (stepperType == "RK Explicit Trapezoidal") {
150  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
151  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
152  }
153  else TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Error - unknown stepperType = "+stepperType);
154 }
155 
156 
160  const RCP<Tempus::StepperDIRK<double> >& stepper)
161 {
162  auto model = rcp(new Tempus_Test::SinCosModel<double>());
163  stepper->setModel(model);
164  stepper->initialize();
165  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
166 
167  // Default values for construction.
168  auto modifier = rcp(new Tempus::StepperRKModifierDefault<double>());
169  auto modifierX = rcp(new Tempus::StepperRKModifierXDefault<double>());
170  auto observer = rcp(new Tempus::StepperRKObserverDefault<double>());
171  auto solver = rcp(new Thyra::NOXNonlinearSolver());
172  solver->setParameterList(Tempus::defaultSolverParameters());
173 
174  bool useFSAL = stepper->getUseFSAL();
175  std::string ICConsistency = stepper->getICConsistency();
176  bool ICConsistencyCheck = stepper->getICConsistencyCheck();
177  bool useEmbedded = stepper->getUseEmbedded();
178  bool zeroInitialGuess = stepper->getZeroInitialGuess();
179 
180  // Test the set functions.
181  stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
182  stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
183  stepper->setSolver(solver); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
184  stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
185  stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
186  stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
187  stepper->setUseEmbedded(useEmbedded); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
188  stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
189 
190 
191  std::string stepperType = stepper->getStepperType();
192  // Full argument list construction.
193  if (stepperType == "RK Backward Euler") {
195  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
196  useEmbedded, zeroInitialGuess, modifier));
197  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
198  } else if (stepperType == "SDIRK 2 Stage 2nd order") {
199  double gamma = 0.2928932188134524;
201  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
202  useEmbedded, zeroInitialGuess, modifier, gamma));
203  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
204  } else if (stepperType == "SDIRK 3 Stage 2nd order") {
206  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
207  useEmbedded, zeroInitialGuess, modifier));
208  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
209  } else if (stepperType == "SDIRK 2 Stage 3rd order") {
210  std::string gammaType = "3rd Order A-stable";
211  double gamma = 0.7886751345948128;
213  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
214  useEmbedded, zeroInitialGuess, modifier, gammaType, gamma));
215  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
216  } else if (stepperType == "EDIRK 2 Stage 3rd order") {
218  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
219  useEmbedded, zeroInitialGuess, modifier));
220  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
221  } else if (stepperType == "DIRK 1 Stage Theta Method") {
222  double theta = 0.5;
224  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
225  useEmbedded, zeroInitialGuess, modifier, theta));
226  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
227  } else if (stepperType == "EDIRK 2 Stage Theta Method") {
228  double theta = 0.5;
230  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
231  useEmbedded, zeroInitialGuess, modifier, theta));
232  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
233  s->setTheta(theta);
234  s->initialize();
235  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
236  } else if (stepperType == "RK Trapezoidal Rule") {
238  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
239  useEmbedded, zeroInitialGuess, modifier));
240  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
241  } else if (stepperType == "RK Implicit Midpoint") {
243  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
244  useEmbedded, zeroInitialGuess, modifier));
245  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
246  } else if (stepperType == "SSPDIRK22") {
248  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
249  useEmbedded, zeroInitialGuess, modifier));
250  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
251  } else if (stepperType == "SSPDIRK32") {
253  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
254  useEmbedded, zeroInitialGuess, modifier));
255  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
256  } else if (stepperType == "SSPDIRK23") {
258  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
259  useEmbedded, zeroInitialGuess, modifier));
260  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
261  } else if (stepperType == "SSPDIRK33") {
263  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
264  useEmbedded, zeroInitialGuess, modifier));
265  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
266  } else if (stepperType == "RK Implicit 1 Stage 1st order Radau IA") {
268  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
269  useEmbedded, zeroInitialGuess, modifier));
270  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
271  } else if (stepperType == "RK Implicit 2 Stage 2nd order Lobatto IIIB") {
273  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
274  useEmbedded, zeroInitialGuess, modifier));
275  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
276  } else if (stepperType == "SDIRK 5 Stage 4th order") {
278  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
279  useEmbedded, zeroInitialGuess, modifier));
280  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
281  } else if (stepperType == "SDIRK 3 Stage 4th order") {
283  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
284  useEmbedded, zeroInitialGuess, modifier));
285  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
286  } else if (stepperType == "SDIRK 5 Stage 5th order") {
288  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
289  useEmbedded, zeroInitialGuess, modifier));
290  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
291  } else if (stepperType == "SDIRK 2(1) Pair") {
293  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
294  useEmbedded, zeroInitialGuess, modifier));
295  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
296  } else TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Error - unknown stepperType = "+stepperType);
297 
298 }
299 
300 
304  : virtual public Tempus::StepperRKModifierBase<double>
305 {
306 public:
307 
310  : testBEGIN_STEP(false),
311  testBEGIN_STAGE(false),
312  testBEFORE_SOLVE(false),
313  testAFTER_SOLVE(false),
315  testEND_STAGE(false),
316  testEND_STEP(false),
317  testCurrentValue(-0.99),
318  testWorkingValue(-0.99),
319  testDt(-1.5),
320  testName("")
321  {}
322 
325 
327  virtual void modify(
331  {
332  switch(actLoc) {
334  {
335  testBEGIN_STEP = true;
336  auto x = sh->getCurrentState()->getX();
337  testCurrentValue = get_ele(*(x), 0);
338  testName = stepper->getStepperType() + " - Modifier";
339  stepper->setStepperName(testName);
340  break;
341  }
343  {
344  testBEGIN_STAGE = true;
345  break;
346  }
348  {
349  testBEFORE_SOLVE = true;
350  testDt = sh->getWorkingState()->getTimeStep()/10.0;
351  break;
352  }
354  {
355  testAFTER_SOLVE = true;
356  break;
357  }
359  {
361  break;
362  }
364  {
365  testEND_STAGE = true;
366  break;
367  }
369  {
370  testEND_STEP = true;
371  auto x = sh->getWorkingState()->getX();
372  testWorkingValue = get_ele(*(x), 0);
373  break;
374  }
375  default:
376  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
377  "Error - unknown action location.\n");
378  }
379  }
380 
390  double testDt;
391  std::string testName;
392 };
393 
394 
398  : virtual public Tempus::StepperRKObserverBase<double>
399 {
400 public:
401 
404  : testBEGIN_STEP(false),
405  testBEGIN_STAGE(false),
406  testBEFORE_SOLVE(false),
407  testAFTER_SOLVE(false),
409  testEND_STAGE(false),
410  testEND_STEP(false),
411  testCurrentValue(-0.99),
412  testWorkingValue(-0.99),
413  testDt(-1.5),
414  testName("")
415  {}
416 
419 
421  virtual void observe(
425  {
426  switch(actLoc) {
428  {
429  testBEGIN_STEP = true;
430  auto x = sh->getCurrentState()->getX();
431  testCurrentValue = get_ele(*(x), 0);
432  break;
433  }
435  {
436  testBEGIN_STAGE = true;
437  break;
438  }
440  {
441  testBEFORE_SOLVE = true;
442  testDt = sh->getWorkingState()->getTimeStep()/10.0;
443  break;
444  }
446  {
447  testAFTER_SOLVE = true;
448  testName = stepper->getStepperType() + " - Observer";
449  break;
450  }
452  {
454  break;
455  }
457  {
458  testEND_STAGE = true;
459  break;
460  }
462  {
463  testEND_STEP = true;
464  auto x = sh->getWorkingState()->getX();
465  testWorkingValue = get_ele(*(x), 0);
466  break;
467  }
468  default:
469  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
470  "Error - unknown action location.\n");
471  }
472  }
473 
483  double testDt;
484  std::string testName;
485 };
486 
487 
489  : virtual public Tempus::StepperRKModifierXBase<double>
490 {
491 public:
492 
495  : testX_BEGIN_STEP(false),
496  testX_BEGIN_STAGE(false),
497  testX_BEFORE_SOLVE(false),
498  testX_AFTER_SOLVE(false),
500  testXDOT_END_STAGE(false),
501  testX_END_STEP(false),
502  testX(-0.99),
503  testEndStageX(-0.99),
504  testDt(-1.5),
505  testTime(-1.5),
506  testStageNumber(-1),
507  testStageX(-0.99)
508  {}
509 
512 
514  virtual void modify(
516  const double time, const double dt,
517  const int stageNumber,
519  {
520  switch(modType) {
522  {
523  testX_BEGIN_STEP = true;
524  testX = get_ele(*(x), 0);
525  break;
526  }
528  {
529  testX_BEGIN_STAGE = true;
530  break;
531  }
533  {
534  testX_BEFORE_SOLVE = true;
535  testDt = dt;
536  break;
537  }
539  {
540  testX_AFTER_SOLVE = true;
541  break;
542  }
544  {
546  testStageNumber = stageNumber;
547  testStageX = get_ele(*(x), 0); // x should be the stage value.
548  break;
549  }
551  {
552  testXDOT_END_STAGE = true;
553  testEndStageX = get_ele(*(x), 0);
554  break;
555  }
557  {
558  testX_END_STEP = true;
559  testTime = time;
560  break;
561  }
562  default:
563  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
564  "Error - unknown action location.\n");
565  }
566  }
567 
575  double testX;
577  double testDt;
578  double testTime;
580  double testStageX;
581 };
582 
583 
588  const Teuchos::RCP<const Thyra::ModelEvaluator<double> >& model,
589  Teuchos::FancyOStream &out, bool &success)
590 {
591  auto testNameOrig = stepper->getStepperType();
592 
593  // Test Modifier.
594  {
595  stepper->setModel(model);
596  auto modifier = rcp(new StepperRKModifierTest());
597  stepper->setAppAction(modifier);
598  stepper->initialize();
599  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
600  auto testName = testNameOrig + " - Modifier";
601 
602  // Create a SolutionHistory.
603  auto solutionHistory = Tempus::createSolutionHistoryME(model);
604 
605  // Take one time step.
606  stepper->setInitialConditions(solutionHistory);
607  solutionHistory->initWorkingState();
608  double dt = 0.1;
609  solutionHistory->getWorkingState()->setTimeStep(dt);
610  stepper->takeStep(solutionHistory);
611 
612  // Testing that each ACTION_LOCATION has been called.
613  TEST_COMPARE(modifier->testBEGIN_STEP, ==, true);
614  TEST_COMPARE(modifier->testBEGIN_STAGE, ==, true);
615  TEST_COMPARE(modifier->testBEFORE_SOLVE, ==, true);
616  TEST_COMPARE(modifier->testAFTER_SOLVE, ==, true);
617  TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==, true);
618  TEST_COMPARE(modifier->testEND_STAGE, ==, true);
619  TEST_COMPARE(modifier->testEND_STEP, ==, true);
620 
621  // Testing that values can be set through the modifier.
622  auto x = solutionHistory->getCurrentState()->getX();
623  TEST_FLOATING_EQUALITY(modifier->testCurrentValue,get_ele(*(x), 0),1.0e-14);
624  x = solutionHistory->getWorkingState()->getX();
625  TEST_FLOATING_EQUALITY(modifier->testWorkingValue,get_ele(*(x), 0),1.0e-14);
626  auto Dt = solutionHistory->getWorkingState()->getTimeStep();
627  TEST_FLOATING_EQUALITY(modifier->testDt, Dt/10.0, 1.0e-14);
628 
629  TEST_COMPARE(modifier->testName, ==, testName);
630  }
631 
632  // Test Observer.
633  {
634  stepper->setModel(model);
635  auto observer = rcp(new StepperRKObserverTest());
636  stepper->setAppAction(observer);
637  stepper->setStepperName(testNameOrig);
638  stepper->initialize();
639  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
640 
641  // Create a SolutionHistory.
642  auto solutionHistory = Tempus::createSolutionHistoryME(model);
643 
644  // Take one time step.
645  stepper->setInitialConditions(solutionHistory);
646  solutionHistory->initWorkingState();
647  double dt = 0.1;
648  solutionHistory->getWorkingState()->setTimeStep(dt);
649  stepper->takeStep(solutionHistory);
650 
651  // Testing that each ACTION_LOCATION has been called.
652  TEST_COMPARE(observer->testBEGIN_STEP, ==, true);
653  TEST_COMPARE(observer->testBEGIN_STAGE, ==, true);
654  TEST_COMPARE(observer->testBEFORE_SOLVE, ==, true);
655  TEST_COMPARE(observer->testAFTER_SOLVE, ==, true);
656  TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==, true);
657  TEST_COMPARE(observer->testEND_STAGE, ==, true);
658  TEST_COMPARE(observer->testEND_STEP, ==, true);
659 
660  // Testing that values can be observed through the observer.
661  auto x = solutionHistory->getCurrentState()->getX();
662  TEST_FLOATING_EQUALITY(observer->testCurrentValue,get_ele(*(x), 0),1.0e-14);
663  x = solutionHistory->getWorkingState()->getX();
664  TEST_FLOATING_EQUALITY(observer->testWorkingValue,get_ele(*(x), 0),1.0e-14);
665  auto Dt = solutionHistory->getWorkingState()->getTimeStep();
666  TEST_FLOATING_EQUALITY(observer->testDt, Dt/10.0, 1.0e-14);
667 
668  auto testName = testNameOrig + " - Observer";
669  TEST_COMPARE(observer->testName, ==, testName);
670  }
671 
672  // Test ModifierX.
673  {
674  stepper->setModel(model);
675  auto modifierX = rcp(new StepperRKModifierXTest());
676  stepper->setAppAction(modifierX);
677  stepper->setStepperName(testNameOrig);
678  stepper->initialize();
679  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
680 
681  // Create a SolutionHistory.
682  auto solutionHistory = Tempus::createSolutionHistoryME(model);
683 
684  // Take one time step.
685  stepper->setInitialConditions(solutionHistory);
686  solutionHistory->initWorkingState();
687  double dt = 0.1;
688  solutionHistory->getWorkingState()->setTimeStep(dt);
689  stepper->takeStep(solutionHistory);
690 
691  // Testing that each ACTION_LOCATION has been called.
692  TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==, true);
693  TEST_COMPARE(modifierX->testX_BEGIN_STAGE, ==, true);
694  TEST_COMPARE(modifierX->testX_BEFORE_SOLVE, ==, true);
695  TEST_COMPARE(modifierX->testX_AFTER_SOLVE, ==, true);
696  TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==, true);
697  TEST_COMPARE(modifierX->testXDOT_END_STAGE, ==, true);
698  TEST_COMPARE(modifierX->testX_END_STEP, ==, true);
699 
700  const double relTol = 1.0e-14;
701  // Testing that values can be set through the modifierX.
702  auto x = solutionHistory->getCurrentState()->getX();
703  TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(x), 0), relTol);
704  auto Dt = solutionHistory->getWorkingState()->getTimeStep();
705  TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, relTol);
706 
707  auto time = solutionHistory->getWorkingState()->getTime();
708  TEST_FLOATING_EQUALITY(modifierX->testTime, time, relTol);
709 
710  // Stage Number should be -1 outside stage loop.
711  TEST_COMPARE(stepper->getStageNumber(), ==, -1);
712  // The last stage number through X_BEFORE_EXPLICIT_EVAL should be
713  // the number of stages minus one.
714  TEST_COMPARE(modifierX->testStageNumber,==,stepper->getNumberOfStages()-1);
715 
716  if (rcp_dynamic_cast<Tempus::StepperIMEX_RK<double>>(stepper) != Teuchos::null ||
717  rcp_dynamic_cast<Tempus::StepperIMEX_RK_Partition<double>>(stepper) != Teuchos::null) {
718  TEST_FLOATING_EQUALITY(modifierX->testStageX, 2.0, relTol);
719  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 2.0,relTol);
720  } else if (stepper->isImplicit()) {
721  // Stage values are overwritten and not available
722  // outside takeStep, so direct comparisons are needed.
723  if (rcp_dynamic_cast<Tempus::StepperDIRK_BackwardEuler<double>>(stepper) != Teuchos::null) {
724  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09900990099009901, relTol);
725  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09900990099009901, relTol);
726  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_2Stage2ndOrder<double>>(stepper) != Teuchos::null) {
727  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09979317463412091, relTol);
728  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09979317463412091, relTol);
729  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_3Stage2ndOrder<double>>(stepper) != Teuchos::null) {
730  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.049921670528461, relTol);
731  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.049921670528461, relTol);
732  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_2Stage3rdOrder<double>>(stepper) != Teuchos::null) {
733  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.02171123447937569, relTol);
734  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.02171123447937569, relTol);
735  } else if (rcp_dynamic_cast<Tempus::StepperEDIRK_2Stage3rdOrder<double>>(stepper) != Teuchos::null) {
736  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06659267480577136, relTol);
737  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06659267480577136, relTol);
738  } else if (rcp_dynamic_cast<Tempus::StepperDIRK_1StageTheta<double>>(stepper) != Teuchos::null) {
739  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
740  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
741  } else if (rcp_dynamic_cast<Tempus::StepperEDIRK_2StageTheta<double>>(stepper) != Teuchos::null) {
742  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
743  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
744  } else if (rcp_dynamic_cast<Tempus::StepperEDIRK_TrapezoidalRule<double>>(stepper) != Teuchos::null) {
745  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
746  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
747  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_ImplicitMidpoint<double>>(stepper) != Teuchos::null) {
748  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
749  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
750  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK22<double>>(stepper) != Teuchos::null) {
751  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0748907323303947, relTol);
752  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0748907323303947, relTol);
753  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK32<double>>(stepper) != Teuchos::null) {
754  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.08321767099874625, relTol);
755  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.08321767099874625, relTol);
756  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK23<double>>(stepper) != Teuchos::null) {
757  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.07878078755122744, relTol);
758  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.07878078755122744, relTol);
759  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK33<double>>(stepper) != Teuchos::null) {
760  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.08525184184135257, relTol);
761  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.08525184184135257, relTol);
762  } else if (rcp_dynamic_cast<Tempus::StepperDIRK_1Stage1stOrderRadauIA<double>>(stepper) != Teuchos::null) {
763  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09900990099009901, relTol);
764  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09900990099009901, relTol);
765  } else if (rcp_dynamic_cast<Tempus::StepperDIRK_2Stage2ndOrderLobattoIIIB<double>>(stepper) != Teuchos::null) {
766  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
767  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
768  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_5Stage4thOrder<double>>(stepper) != Teuchos::null) {
769  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983340822548158, 1.0e-14);
770  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983340822548158, 1.0e-14);
771  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_3Stage4thOrder<double>>(stepper) != Teuchos::null) {
772  TEST_FLOATING_EQUALITY(modifierX->testStageX, -0.009988159068259408, relTol);
773  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, -0.009988159068259408, relTol);
774  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_5Stage5thOrder<double>>(stepper) != Teuchos::null) {
775  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06446224812649308, relTol);
776  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06446224812649308, relTol);
777  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_21Pair<double>>(stepper) != Teuchos::null) {
778  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.001960592098813843, relTol);
779  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.001960592098813843, relTol);
780  } else if (rcp_dynamic_cast<Tempus::StepperDIRK_General<double>>(stepper) != Teuchos::null) {
781  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09979317463412091, relTol);
782  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09979317463412091, relTol);
783  } else {
784  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
785  "Error - unknown stepperType = "+stepper->getStepperType());
786  }
787  } else {
788  // Stage values are overwritten and not available
789  // outside takeStep, so direct comparisons are needed.
790  if (rcp_dynamic_cast<Tempus::StepperERK_3_8Rule<double>>(stepper) != Teuchos::null) {
791  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09966666666666668, relTol);
792  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09966666666666668, relTol);
793  } else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrder<double>>(stepper) != Teuchos::null) {
794  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, relTol);
795  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, relTol);
796  } else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrderHeun<double>>(stepper) != Teuchos::null) {
797  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06666666666666667, relTol);
798  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06666666666666667, relTol);
799  } else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrderTVD<double>>(stepper) != Teuchos::null) {
800  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, relTol);
801  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, relTol);
802  } else if (rcp_dynamic_cast<Tempus::StepperERK_4Stage3rdOrderRunge<double>>(stepper) != Teuchos::null) {
803  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0995, relTol);
804  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0995, relTol);
805  } else if (rcp_dynamic_cast<Tempus::StepperERK_4Stage4thOrder<double>>(stepper) != Teuchos::null) {
806  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975, relTol);
807  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975, relTol);
808  } else if (rcp_dynamic_cast<Tempus::StepperERK_5Stage3rdOrderKandG<double>>(stepper) != Teuchos::null) {
809  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06662222222222222, relTol);
810  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06662222222222222, relTol);
811  } else if (rcp_dynamic_cast<Tempus::StepperERK_BogackiShampine32<double>>(stepper) != Teuchos::null) {
812  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333333, relTol);
813  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333333, relTol);
814  } else if (rcp_dynamic_cast<Tempus::StepperERK_ForwardEuler<double>>(stepper) != Teuchos::null) {
815  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0, relTol);
816  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0, relTol);
817  } else if (rcp_dynamic_cast<Tempus::StepperERK_General<double>>(stepper) != Teuchos::null) {
818  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975, relTol);
819  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975, relTol);
820  } else if (rcp_dynamic_cast<Tempus::StepperERK_Merson45<double>>(stepper) != Teuchos::null) {
821  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333332, relTol);
822  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333332, relTol);
823  } else if (rcp_dynamic_cast<Tempus::StepperERK_Midpoint<double>>(stepper) != Teuchos::null) {
824  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, relTol);
825  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, relTol);
826  } else if (rcp_dynamic_cast<Tempus::StepperERK_Trapezoidal<double>>(stepper) != Teuchos::null) {
827  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, relTol);
828  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, relTol);
829  } else {
830  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
831  "Error - unknown stepperType = "+stepper->getStepperType());
832  }
833  }
834  }
835 
836 
837  // Test Composite.
838  {
839  stepper->setModel(model);
840 
841  auto modifier = rcp(new StepperRKModifierTest());
842  auto observer = rcp(new StepperRKObserverTest());
843  auto modifierX = rcp(new StepperRKModifierXTest());
844  auto composite = rcp(new Tempus::StepperRKAppActionComposite<double>());
845 
846  composite->addRKAppAction(modifier);
847  composite->addRKAppAction(observer);
848  composite->addRKAppAction(modifierX);
849  stepper->setAppAction(composite);
850 
851  stepper->initialize();
852  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
853 
854  // Create a SolutionHistory.
855  auto solutionHistory = Tempus::createSolutionHistoryME(model);
856 
857  // Take one time step.
858  stepper->setInitialConditions(solutionHistory);
859  solutionHistory->initWorkingState();
860  double dt = 0.1;
861  solutionHistory->getWorkingState()->setTimeStep(dt);
862  stepper->takeStep(solutionHistory);
863 
864  auto xCS = solutionHistory->getCurrentState()->getX();
865  auto xWS = solutionHistory->getWorkingState()->getX();
866  auto Dt = solutionHistory->getWorkingState()->getTimeStep();
867 
868  // Test Modifier.
869  // Testing that each ACTION_LOCATION has been called.
870  TEST_COMPARE(modifier->testBEGIN_STEP, ==, true);
871  TEST_COMPARE(modifier->testBEGIN_STAGE, ==, true);
872  TEST_COMPARE(modifier->testBEFORE_SOLVE, ==, true);
873  TEST_COMPARE(modifier->testAFTER_SOLVE, ==, true);
874  TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==, true);
875  TEST_COMPARE(modifier->testEND_STAGE, ==, true);
876  TEST_COMPARE(modifier->testEND_STEP, ==, true);
877 
878  const double relTol = 1.0e-14;
879  // Testing that values can be set through the modifier.
880  TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(xCS), 0),relTol);
881  TEST_FLOATING_EQUALITY(modifier->testWorkingValue, get_ele(*(xWS), 0),relTol);
882  TEST_FLOATING_EQUALITY(modifier->testDt, Dt/10.0, relTol);
883 
884  auto testName = testNameOrig + " - Modifier";
885  TEST_COMPARE(modifier->testName, ==, testName);
886 
887 
888  // Test Observer.
889  // Testing that each ACTION_LOCATION has been called.
890  TEST_COMPARE(observer->testBEGIN_STEP, ==, true);
891  TEST_COMPARE(observer->testBEGIN_STAGE, ==, true);
892  TEST_COMPARE(observer->testBEFORE_SOLVE, ==, true);
893  TEST_COMPARE(observer->testAFTER_SOLVE, ==, true);
894  TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==, true);
895  TEST_COMPARE(observer->testEND_STAGE, ==, true);
896  TEST_COMPARE(observer->testEND_STEP, ==, true);
897 
898  // Testing that values can be observed through the observer.
899  TEST_FLOATING_EQUALITY(observer->testCurrentValue, get_ele(*(xCS), 0),relTol);
900  TEST_FLOATING_EQUALITY(observer->testWorkingValue, get_ele(*(xWS), 0),relTol);
901  TEST_FLOATING_EQUALITY(observer->testDt, Dt/10.0, relTol);
902 
903  testName = testNameOrig + " - Observer";
904  TEST_COMPARE(observer->testName, ==, testName);
905 
906 
907  // Test ModifierX.
908  // Testing that each ACTION_LOCATION has been called.
909  TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==, true);
910  TEST_COMPARE(modifierX->testX_BEGIN_STAGE, ==, true);
911  TEST_COMPARE(modifierX->testX_BEFORE_SOLVE, ==, true);
912  TEST_COMPARE(modifierX->testX_AFTER_SOLVE, ==, true);
913  TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==, true);
914  TEST_COMPARE(modifierX->testXDOT_END_STAGE, ==, true);
915  TEST_COMPARE(modifierX->testX_END_STEP, ==, true);
916 
917  // Testing that values can be set through the modifierX.
918  TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(xCS), 0), relTol);
919  TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, relTol);
920 
921  auto time = solutionHistory->getWorkingState()->getTime();
922  TEST_FLOATING_EQUALITY(modifierX->testTime, time, relTol);
923 
924  // Stage Number should be -1 outside stage loop.
925  TEST_COMPARE(stepper->getStageNumber(), ==, -1);
926  // The last stage number through X_BEFORE_EXPLICIT_EVAL should be
927  // the number of stages minus one.
928  TEST_COMPARE(modifierX->testStageNumber,==,stepper->getNumberOfStages()-1);
929 
930  if (rcp_dynamic_cast<Tempus::StepperIMEX_RK<double>>(stepper) != Teuchos::null ||
931  rcp_dynamic_cast<Tempus::StepperIMEX_RK_Partition<double>>(stepper) != Teuchos::null) {
932  TEST_FLOATING_EQUALITY(modifierX->testStageX, 2.0, relTol);
933  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 2.0,relTol);
934  } else if (stepper->isImplicit()) {
935  // Stage values are overwritten and not available
936  // outside takeStep, so direct comparisons are needed.
937  if (rcp_dynamic_cast<Tempus::StepperDIRK_BackwardEuler<double>>(stepper) != Teuchos::null) {
938  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09900990099009901, relTol);
939  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09900990099009901, relTol);
940  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_2Stage2ndOrder<double>>(stepper) != Teuchos::null) {
941  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09979317463412091, relTol);
942  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09979317463412091, relTol);
943  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_3Stage2ndOrder<double>>(stepper) != Teuchos::null) {
944  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.049921670528461, relTol);
945  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.049921670528461, relTol);
946  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_2Stage3rdOrder<double>>(stepper) != Teuchos::null) {
947  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.02171123447937569, relTol);
948  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.02171123447937569, relTol);
949  } else if (rcp_dynamic_cast<Tempus::StepperEDIRK_2Stage3rdOrder<double>>(stepper) != Teuchos::null) {
950  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06659267480577136, relTol);
951  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06659267480577136, relTol);
952  } else if (rcp_dynamic_cast<Tempus::StepperDIRK_1StageTheta<double>>(stepper) != Teuchos::null) {
953  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
954  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
955  } else if (rcp_dynamic_cast<Tempus::StepperEDIRK_2StageTheta<double>>(stepper) != Teuchos::null) {
956  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
957  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
958  } else if (rcp_dynamic_cast<Tempus::StepperEDIRK_TrapezoidalRule<double>>(stepper) != Teuchos::null) {
959  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
960  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
961  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_ImplicitMidpoint<double>>(stepper) != Teuchos::null) {
962  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
963  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
964  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK22<double>>(stepper) != Teuchos::null) {
965  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0748907323303947, relTol);
966  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0748907323303947, relTol);
967  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK32<double>>(stepper) != Teuchos::null) {
968  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.08321767099874625, relTol);
969  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.08321767099874625, relTol);
970  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK23<double>>(stepper) != Teuchos::null) {
971  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.07878078755122744, relTol);
972  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.07878078755122744, relTol);
973  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK33<double>>(stepper) != Teuchos::null) {
974  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.08525184184135257, relTol);
975  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.08525184184135257, relTol);
976  } else if (rcp_dynamic_cast<Tempus::StepperDIRK_1Stage1stOrderRadauIA<double>>(stepper) != Teuchos::null) {
977  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09900990099009901, relTol);
978  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09900990099009901, relTol);
979  } else if (rcp_dynamic_cast<Tempus::StepperDIRK_2Stage2ndOrderLobattoIIIB<double>>(stepper) != Teuchos::null) {
980  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
981  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
982  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_5Stage4thOrder<double>>(stepper) != Teuchos::null) {
983  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983340822548158, relTol);
984  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983340822548158, relTol);
985  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_3Stage4thOrder<double>>(stepper) != Teuchos::null) {
986  TEST_FLOATING_EQUALITY(modifierX->testStageX, -0.009988159068259408, relTol);
987  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, -0.009988159068259408, relTol);
988  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_5Stage5thOrder<double>>(stepper) != Teuchos::null) {
989  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06446224812649308, relTol);
990  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06446224812649308, relTol);
991  } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_21Pair<double>>(stepper) != Teuchos::null) {
992  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.001960592098813843, relTol);
993  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.001960592098813843, relTol);
994  } else if (rcp_dynamic_cast<Tempus::StepperDIRK_General<double>>(stepper) != Teuchos::null) {
995  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09979317463412091, relTol);
996  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09979317463412091, relTol);
997  } else {
998  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
999  "Error - unknown stepperType = "+stepper->getStepperType());
1000  }
1001  } else {
1002  // For explicit steppers, stageX is under written and not available
1003  // outside takeStep, so direct comparisons are needed.
1004  if (rcp_dynamic_cast<Tempus::StepperERK_3_8Rule<double>>(stepper) != Teuchos::null) {
1005  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09966666666666668, relTol);
1006  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09966666666666668, relTol);
1007  } else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrder<double>>(stepper) != Teuchos::null) {
1008  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, relTol);
1009  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, relTol);
1010  } else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrderHeun<double>>(stepper) != Teuchos::null) {
1011  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06666666666666667, relTol);
1012  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06666666666666667, relTol);
1013  } else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrderTVD<double>>(stepper) != Teuchos::null) {
1014  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, relTol);
1015  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, relTol);
1016  } else if (rcp_dynamic_cast<Tempus::StepperERK_4Stage3rdOrderRunge<double>>(stepper) != Teuchos::null) {
1017  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0995, relTol);
1018  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0995, relTol);
1019  } else if (rcp_dynamic_cast<Tempus::StepperERK_4Stage4thOrder<double>>(stepper) != Teuchos::null) {
1020  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975, relTol);
1021  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975, relTol);
1022  } else if (rcp_dynamic_cast<Tempus::StepperERK_5Stage3rdOrderKandG<double>>(stepper) != Teuchos::null) {
1023  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06662222222222222, relTol);
1024  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06662222222222222, relTol);
1025  } else if (rcp_dynamic_cast<Tempus::StepperERK_BogackiShampine32<double>>(stepper) != Teuchos::null) {
1026  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333333, relTol);
1027  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333333, relTol);
1028  } else if (rcp_dynamic_cast<Tempus::StepperERK_ForwardEuler<double>>(stepper) != Teuchos::null) {
1029  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0, relTol);
1030  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0, relTol);
1031  } else if (rcp_dynamic_cast<Tempus::StepperERK_General<double>>(stepper) != Teuchos::null) {
1032  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975, relTol);
1033  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975, relTol);
1034  } else if (rcp_dynamic_cast<Tempus::StepperERK_Merson45<double>>(stepper) != Teuchos::null) {
1035  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333332, relTol);
1036  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333332, relTol);
1037  } else if (rcp_dynamic_cast<Tempus::StepperERK_Midpoint<double>>(stepper) != Teuchos::null) {
1038  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, relTol);
1039  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, relTol);
1040  } else if (rcp_dynamic_cast<Tempus::StepperERK_Trapezoidal<double>>(stepper) != Teuchos::null) {
1041  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, relTol);
1042  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, relTol);
1043  } else {
1044  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
1045  "Error - unknown stepperType = "+stepper->getStepperType());
1046  }
1047  }
1048  }
1049 }
1050 
1051 
1052 } // namespace Tempus_Test
1053 #endif // Tempus_UnitTest_Utils_hpp
Unit test class for RK Stepper Observer AppAction.
General Implicit Runge-Kutta Butcher Tableau.
RK Implicit 2 Stage 2nd order Lobatto IIIB.
void testRKAppAction(const Teuchos::RCP< Tempus::StepperRKBase< double > > &stepper, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model, Teuchos::FancyOStream &out, bool &success)
Unit test utility for Stepper RK AppAction.
virtual void modify(Teuchos::RCP< Tempus::SolutionHistory< double > > sh, Teuchos::RCP< Tempus::StepperRKBase< double > > stepper, const typename Tempus::StepperRKAppAction< double >::ACTION_LOCATION actLoc)
Modify RK Stepper at action location.
void testExplicitRKAccessorsFullConstruction(const RCP< Tempus::StepperExplicitRK< double > > &stepper)
Unit test utility for ExplicitRK Stepper construction and accessors.
Explicit Runge-Kutta time stepper.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
Backward Euler Runge-Kutta Butcher Tableau.
General Explicit Runge-Kutta Butcher Tableau.
RK Explicit 5 Stage 3rd order by Kinnmark and Gray.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
#define TEST_COMPARE(v1, comp, v2)
RK Explicit 4 Stage 3rd order by Runge.
Unit test class for RK Stepper Modifier AppAction.
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
virtual void observe(Teuchos::RCP< const Tempus::SolutionHistory< double > > sh, Teuchos::RCP< const Tempus::StepperRKBase< double > > stepper, const typename Tempus::StepperRKAppAction< double >::ACTION_LOCATION actLoc)
Observe RK Stepper at action location.
RK Trapezoidal Rule (A.K.A. RK Crank-Nicolson)
Partitioned Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
This composite AppAction loops over added AppActions.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Nonmember contructor from a Thyra ModelEvaluator.
Base class for Runge-Kutta methods, ExplicitRK, DIRK and IMEX.
Explicit RK 3/8th Rule Butcher Tableau.
Diagonally Implicit Runge-Kutta (DIRK) time stepper.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Explicit RK Bogacki-Shampine Butcher Tableau.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > > x, const double time, const double dt, const int stageNumber, const typename Tempus::StepperRKModifierXBase< double >::MODIFIER_TYPE modType)
Observe RK Stepper at end of takeStep.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
ACTION_LOCATION
Indicates the location of application action (see algorithm).
void testDIRKAccessorsFullConstruction(const RCP< Tempus::StepperDIRK< double > > &stepper)
Unit test utility for ExplicitRK Stepper construction and accessors.
Forward Euler Runge-Kutta Butcher Tableau.
Explicit RK Merson Butcher Tableau.
Runge-Kutta 4th order Butcher Tableau.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
RK Explicit 3 Stage 3rd order by Heun.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.