Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_UnitTest_RK_Utils.hpp
Go to the documentation of this file.
1 //@HEADER
2 // *****************************************************************************
3 // Tempus: Time Integration and Sensitivity Analysis Package
4 //
5 // Copyright 2017 NTESS and the Tempus contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 //@HEADER
9 
10 #ifndef Tempus_UnitTest_RK_Utils_hpp
11 #define Tempus_UnitTest_RK_Utils_hpp
12 
14 
16 
17 #include "Tempus_StepperIMEX_RK.hpp"
18 #include "Tempus_StepperIMEX_RK_Partition.hpp"
19 
27 
28 namespace Tempus_Unit_Test {
29 
31 using Teuchos::RCP;
32 using Teuchos::rcp;
33 using Teuchos::rcp_const_cast;
34 using Teuchos::rcp_dynamic_cast;
35 
37 
41  const RCP<Tempus::StepperExplicitRK<double>>& stepper)
42 {
43  auto model = rcp(new Tempus_Test::SinCosModel<double>());
44  stepper->setModel(model);
45  stepper->initialize();
46  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
47 
48  // Default values for construction.
49  auto modifier = rcp(new Tempus::StepperRKModifierDefault<double>());
50  auto modifierX = rcp(new Tempus::StepperRKModifierXDefault<double>());
51  auto observer = rcp(new Tempus::StepperRKObserverDefault<double>());
52  bool useFSAL = stepper->getUseFSAL();
53  std::string ICConsistency = stepper->getICConsistency();
54  bool ICConsistencyCheck = stepper->getICConsistencyCheck();
55  bool useEmbedded = stepper->getUseEmbedded();
56 
57  // Test the set functions.
58  stepper->setAppAction(modifier);
59  stepper->initialize();
60  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
61  stepper->setAppAction(modifierX);
62  stepper->initialize();
63  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
64  stepper->setAppAction(observer);
65  stepper->initialize();
66  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
67  stepper->setUseFSAL(useFSAL);
68  stepper->initialize();
69  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
70  stepper->setICConsistency(ICConsistency);
71  stepper->initialize();
72  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
73  stepper->setICConsistencyCheck(ICConsistencyCheck);
74  stepper->initialize();
75  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
76  stepper->setUseEmbedded(useEmbedded);
77  stepper->initialize();
78  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
79 
80  std::string stepperType = stepper->getStepperType();
81  // Full argument list construction.
82  if (stepperType == "RK Explicit 3 Stage 3rd order") {
84  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
85  modifier));
86  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
87  }
88  else if (stepperType == "RK Explicit 3 Stage 3rd order by Heun") {
90  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
91  modifier));
92  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
93  }
94  else if (stepperType == "RK Explicit 3 Stage 3rd order TVD") {
96  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
97  modifier));
98  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
99  }
100  else if (stepperType == "RK Explicit 3/8 Rule") {
102  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
103  modifier));
104  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
105  }
106  else if (stepperType == "RK Explicit 4 Stage 3rd order by Runge") {
108  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
109  modifier));
110  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
111  }
112  else if (stepperType == "RK Explicit 4 Stage") {
114  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
115  modifier));
116  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
117  }
118  else if (stepperType ==
119  "RK Explicit 5 Stage 3rd order by Kinnmark and Gray") {
121  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
122  modifier));
123  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
124  }
125  else if (stepperType == "Bogacki-Shampine 3(2) Pair") {
127  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
128  modifier));
129  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
130  }
131  else if (stepperType == "RK Forward Euler") {
133  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
134  modifier));
135  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
136  }
137  else if (stepperType == "Merson 4(5) Pair") {
139  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
140  modifier));
141  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
142  }
143  else if (stepperType == "RK Explicit Midpoint") {
145  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
146  modifier));
147  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
148  }
149  else if (stepperType == "RK Explicit Trapezoidal") {
151  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
152  modifier));
153  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
154  }
155  else
156  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
157  "Error - unknown stepperType = " + stepperType);
158 }
159 
163  const RCP<Tempus::StepperDIRK<double>>& stepper)
164 {
165  auto model = rcp(new Tempus_Test::SinCosModel<double>());
166  stepper->setModel(model);
167  stepper->initialize();
168  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
169 
170  // Default values for construction.
171  auto modifier = rcp(new Tempus::StepperRKModifierDefault<double>());
172  auto modifierX = rcp(new Tempus::StepperRKModifierXDefault<double>());
173  auto observer = rcp(new Tempus::StepperRKObserverDefault<double>());
174  auto solver = rcp(new Thyra::NOXNonlinearSolver());
175  solver->setParameterList(Tempus::defaultSolverParameters());
176 
177  bool useFSAL = stepper->getUseFSAL();
178  std::string ICConsistency = stepper->getICConsistency();
179  bool ICConsistencyCheck = stepper->getICConsistencyCheck();
180  bool useEmbedded = stepper->getUseEmbedded();
181  bool zeroInitialGuess = stepper->getZeroInitialGuess();
182 
183  // Test the set functions.
184  stepper->setAppAction(modifierX);
185  stepper->initialize();
186  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
187  stepper->setAppAction(observer);
188  stepper->initialize();
189  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
190  stepper->setSolver(solver);
191  stepper->initialize();
192  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
193  stepper->setUseFSAL(useFSAL);
194  stepper->initialize();
195  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
196  stepper->setICConsistency(ICConsistency);
197  stepper->initialize();
198  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
199  stepper->setICConsistencyCheck(ICConsistencyCheck);
200  stepper->initialize();
201  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
202  stepper->setUseEmbedded(useEmbedded);
203  stepper->initialize();
204  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
205  stepper->setZeroInitialGuess(zeroInitialGuess);
206  stepper->initialize();
207  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
208 
209  std::string stepperType = stepper->getStepperType();
210  // Full argument list construction.
211  if (stepperType == "RK Backward Euler") {
213  model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
214  zeroInitialGuess, modifier));
215  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
216  }
217  else if (stepperType == "SDIRK 2 Stage 2nd order") {
218  double gamma = 0.2928932188134524;
220  model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
221  zeroInitialGuess, modifier, gamma));
222  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
223  }
224  else if (stepperType == "SDIRK 3 Stage 2nd order") {
226  model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
227  zeroInitialGuess, modifier));
228  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
229  }
230  else if (stepperType == "SDIRK 2 Stage 3rd order") {
231  std::string gammaType = "3rd Order A-stable";
232  double gamma = 0.7886751345948128;
234  model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
235  zeroInitialGuess, modifier, gammaType, gamma));
236  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
237  }
238  else if (stepperType == "EDIRK 2 Stage 3rd order") {
240  model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
241  zeroInitialGuess, modifier));
242  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
243  }
244  else if (stepperType == "DIRK 1 Stage Theta Method") {
245  double theta = 0.5;
247  model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
248  zeroInitialGuess, modifier, theta));
249  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
250  }
251  else if (stepperType == "EDIRK 2 Stage Theta Method") {
252  double theta = 0.5;
254  model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
255  zeroInitialGuess, modifier, theta));
256  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
257  s->setTheta(theta);
258  s->initialize();
259  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
260  }
261  else if (stepperType == "RK Trapezoidal Rule") {
263  model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
264  zeroInitialGuess, modifier));
265  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
266  }
267  else if (stepperType == "RK Implicit Midpoint") {
269  model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
270  zeroInitialGuess, modifier));
271  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
272  }
273  else if (stepperType == "SSPDIRK22") {
275  model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
276  zeroInitialGuess, modifier));
277  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
278  }
279  else if (stepperType == "SSPDIRK32") {
281  model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
282  zeroInitialGuess, modifier));
283  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
284  }
285  else if (stepperType == "SSPDIRK23") {
287  model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
288  zeroInitialGuess, modifier));
289  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
290  }
291  else if (stepperType == "SSPDIRK33") {
293  model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
294  zeroInitialGuess, modifier));
295  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
296  }
297  else if (stepperType == "RK Implicit 1 Stage 1st order Radau IA") {
299  model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
300  zeroInitialGuess, modifier));
301  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
302  }
303  else if (stepperType == "RK Implicit 2 Stage 2nd order Lobatto IIIB") {
305  model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
306  zeroInitialGuess, modifier));
307  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
308  }
309  else if (stepperType == "SDIRK 5 Stage 4th order") {
311  model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
312  zeroInitialGuess, modifier));
313  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
314  }
315  else if (stepperType == "SDIRK 3 Stage 4th order") {
317  model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
318  zeroInitialGuess, modifier));
319  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
320  }
321  else if (stepperType == "SDIRK 5 Stage 5th order") {
323  model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
324  zeroInitialGuess, modifier));
325  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
326  }
327  else if (stepperType == "SDIRK 2(1) Pair") {
329  model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
330  zeroInitialGuess, modifier));
331  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
332  }
333  else
334  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
335  "Error - unknown stepperType = " + stepperType);
336 }
337 
341  : virtual public Tempus::StepperRKModifierBase<double> {
342  public:
345  : testBEGIN_STEP(false),
346  testBEGIN_STAGE(false),
347  testBEFORE_SOLVE(false),
348  testAFTER_SOLVE(false),
350  testEND_STAGE(false),
351  testEND_STEP(false),
352  testCurrentValue(-0.99),
353  testWorkingValue(-0.99),
354  testDt(-1.5),
355  testName("")
356  {
357  }
358 
361 
363  virtual void modify(
367  {
368  switch (actLoc) {
370  testBEGIN_STEP = true;
371  auto x = sh->getCurrentState()->getX();
372  testCurrentValue = get_ele(*(x), 0);
373  testName = stepper->getStepperType() + " - Modifier";
374  stepper->setStepperName(testName);
375  break;
376  }
378  testBEGIN_STAGE = true;
379  break;
380  }
382  testBEFORE_SOLVE = true;
383  testDt = sh->getWorkingState()->getTimeStep() / 10.0;
384  break;
385  }
387  testAFTER_SOLVE = true;
388  break;
389  }
392  break;
393  }
395  testEND_STAGE = true;
396  break;
397  }
399  testEND_STEP = true;
400  auto x = sh->getWorkingState()->getX();
401  testWorkingValue = get_ele(*(x), 0);
402  break;
403  }
404  default:
405  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
406  "Error - unknown action location.\n");
407  }
408  }
409 
419  double testDt;
420  std::string testName;
421 };
422 
426  : virtual public Tempus::StepperRKObserverBase<double> {
427  public:
430  : testBEGIN_STEP(false),
431  testBEGIN_STAGE(false),
432  testBEFORE_SOLVE(false),
433  testAFTER_SOLVE(false),
435  testEND_STAGE(false),
436  testEND_STEP(false),
437  testCurrentValue(-0.99),
438  testWorkingValue(-0.99),
439  testDt(-1.5),
440  testName("")
441  {
442  }
443 
446 
448  virtual void observe(
452  {
453  switch (actLoc) {
455  testBEGIN_STEP = true;
456  auto x = sh->getCurrentState()->getX();
457  testCurrentValue = get_ele(*(x), 0);
458  break;
459  }
461  testBEGIN_STAGE = true;
462  break;
463  }
465  testBEFORE_SOLVE = true;
466  testDt = sh->getWorkingState()->getTimeStep() / 10.0;
467  break;
468  }
470  testAFTER_SOLVE = true;
471  testName = stepper->getStepperType() + " - Observer";
472  break;
473  }
476  break;
477  }
479  testEND_STAGE = true;
480  break;
481  }
483  testEND_STEP = true;
484  auto x = sh->getWorkingState()->getX();
485  testWorkingValue = get_ele(*(x), 0);
486  break;
487  }
488  default:
489  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
490  "Error - unknown action location.\n");
491  }
492  }
493 
503  double testDt;
504  std::string testName;
505 };
506 
508  : virtual public Tempus::StepperRKModifierXBase<double> {
509  public:
512  : testX_BEGIN_STEP(false),
513  testX_BEGIN_STAGE(false),
514  testX_BEFORE_SOLVE(false),
515  testX_AFTER_SOLVE(false),
517  testXDOT_END_STAGE(false),
518  testX_END_STEP(false),
519  testX(-0.99),
520  testEndStageX(-0.99),
521  testDt(-1.5),
522  testTime(-1.5),
523  testStageNumber(-1),
524  testStageX(-0.99)
525  {
526  }
527 
530 
532  virtual void modify(
533  Teuchos::RCP<Thyra::VectorBase<double>> x, const double time,
534  const double dt, const int stageNumber,
536  modType)
537  {
538  switch (modType) {
540  testX_BEGIN_STEP = true;
541  testX = get_ele(*(x), 0);
542  break;
543  }
545  testX_BEGIN_STAGE = true;
546  break;
547  }
549  testX_BEFORE_SOLVE = true;
550  testDt = dt;
551  break;
552  }
554  testX_AFTER_SOLVE = true;
555  break;
556  }
559  testStageNumber = stageNumber;
560  testStageX = get_ele(*(x), 0); // x should be the stage value.
561  break;
562  }
564  testXDOT_END_STAGE = true;
565  testEndStageX = get_ele(*(x), 0);
566  break;
567  }
569  testX_END_STEP = true;
570  testTime = time;
571  break;
572  }
573  default:
574  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
575  "Error - unknown action location.\n");
576  }
577  }
578 
586  double testX;
588  double testDt;
589  double testTime;
591  double testStageX;
592 };
593 
598  const Teuchos::RCP<const Thyra::ModelEvaluator<double>>& model,
599  Teuchos::FancyOStream& out, bool& success)
600 {
601  auto testNameOrig = stepper->getStepperType();
602 
603  // Test Modifier.
604  {
605  stepper->setModel(model);
606  auto modifier = rcp(new StepperRKModifierTest());
607  stepper->setAppAction(modifier);
608  stepper->initialize();
609  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
610  auto testName = testNameOrig + " - Modifier";
611 
612  // Create a SolutionHistory.
613  auto solutionHistory = Tempus::createSolutionHistoryME(model);
614 
615  // Take one time step.
616  stepper->setInitialConditions(solutionHistory);
617  solutionHistory->initWorkingState();
618  double dt = 0.1;
619  solutionHistory->getWorkingState()->setTimeStep(dt);
620  stepper->takeStep(solutionHistory);
621 
622  // Testing that each ACTION_LOCATION has been called.
623  TEST_COMPARE(modifier->testBEGIN_STEP, ==, true);
624  TEST_COMPARE(modifier->testBEGIN_STAGE, ==, true);
625  TEST_COMPARE(modifier->testBEFORE_SOLVE, ==, true);
626  TEST_COMPARE(modifier->testAFTER_SOLVE, ==, true);
627  TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==, true);
628  TEST_COMPARE(modifier->testEND_STAGE, ==, true);
629  TEST_COMPARE(modifier->testEND_STEP, ==, true);
630 
631  // Testing that values can be set through the modifier.
632  auto x = solutionHistory->getCurrentState()->getX();
633  TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(x), 0),
634  1.0e-14);
635  x = solutionHistory->getWorkingState()->getX();
636  TEST_FLOATING_EQUALITY(modifier->testWorkingValue, get_ele(*(x), 0),
637  1.0e-14);
638  auto Dt = solutionHistory->getWorkingState()->getTimeStep();
639  TEST_FLOATING_EQUALITY(modifier->testDt, Dt / 10.0, 1.0e-14);
640 
641  TEST_COMPARE(modifier->testName, ==, testName);
642  }
643 
644  // Test Observer.
645  {
646  stepper->setModel(model);
647  auto observer = rcp(new StepperRKObserverTest());
648  stepper->setAppAction(observer);
649  stepper->setStepperName(testNameOrig);
650  stepper->initialize();
651  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
652 
653  // Create a SolutionHistory.
654  auto solutionHistory = Tempus::createSolutionHistoryME(model);
655 
656  // Take one time step.
657  stepper->setInitialConditions(solutionHistory);
658  solutionHistory->initWorkingState();
659  double dt = 0.1;
660  solutionHistory->getWorkingState()->setTimeStep(dt);
661  stepper->takeStep(solutionHistory);
662 
663  // Testing that each ACTION_LOCATION has been called.
664  TEST_COMPARE(observer->testBEGIN_STEP, ==, true);
665  TEST_COMPARE(observer->testBEGIN_STAGE, ==, true);
666  TEST_COMPARE(observer->testBEFORE_SOLVE, ==, true);
667  TEST_COMPARE(observer->testAFTER_SOLVE, ==, true);
668  TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==, true);
669  TEST_COMPARE(observer->testEND_STAGE, ==, true);
670  TEST_COMPARE(observer->testEND_STEP, ==, true);
671 
672  // Testing that values can be observed through the observer.
673  auto x = solutionHistory->getCurrentState()->getX();
674  TEST_FLOATING_EQUALITY(observer->testCurrentValue, get_ele(*(x), 0),
675  1.0e-14);
676  x = solutionHistory->getWorkingState()->getX();
677  TEST_FLOATING_EQUALITY(observer->testWorkingValue, get_ele(*(x), 0),
678  1.0e-14);
679  auto Dt = solutionHistory->getWorkingState()->getTimeStep();
680  TEST_FLOATING_EQUALITY(observer->testDt, Dt / 10.0, 1.0e-14);
681 
682  auto testName = testNameOrig + " - Observer";
683  TEST_COMPARE(observer->testName, ==, testName);
684  }
685 
686  // Test ModifierX.
687  {
688  stepper->setModel(model);
689  auto modifierX = rcp(new StepperRKModifierXTest());
690  stepper->setAppAction(modifierX);
691  stepper->setStepperName(testNameOrig);
692  stepper->initialize();
693  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
694 
695  // Create a SolutionHistory.
696  auto solutionHistory = Tempus::createSolutionHistoryME(model);
697 
698  // Take one time step.
699  stepper->setInitialConditions(solutionHistory);
700  solutionHistory->initWorkingState();
701  double dt = 0.1;
702  solutionHistory->getWorkingState()->setTimeStep(dt);
703  stepper->takeStep(solutionHistory);
704 
705  // Testing that each ACTION_LOCATION has been called.
706  TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==, true);
707  TEST_COMPARE(modifierX->testX_BEGIN_STAGE, ==, true);
708  TEST_COMPARE(modifierX->testX_BEFORE_SOLVE, ==, true);
709  TEST_COMPARE(modifierX->testX_AFTER_SOLVE, ==, true);
710  TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==, true);
711  TEST_COMPARE(modifierX->testXDOT_END_STAGE, ==, true);
712  TEST_COMPARE(modifierX->testX_END_STEP, ==, true);
713 
714  const double relTol = 1.0e-14;
715  // Testing that values can be set through the modifierX.
716  auto x = solutionHistory->getCurrentState()->getX();
717  TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(x), 0), relTol);
718  auto Dt = solutionHistory->getWorkingState()->getTimeStep();
719  TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, relTol);
720 
721  auto time = solutionHistory->getWorkingState()->getTime();
722  TEST_FLOATING_EQUALITY(modifierX->testTime, time, relTol);
723 
724  // Stage Number should be -1 outside stage loop.
725  TEST_COMPARE(stepper->getStageNumber(), ==, -1);
726  // The last stage number through X_BEFORE_EXPLICIT_EVAL should be
727  // the number of stages minus one.
728  TEST_COMPARE(modifierX->testStageNumber, ==,
729  stepper->getNumberOfStages() - 1);
730 
731  if (rcp_dynamic_cast<Tempus::StepperIMEX_RK<double>>(stepper) !=
732  Teuchos::null ||
733  rcp_dynamic_cast<Tempus::StepperIMEX_RK_Partition<double>>(stepper) !=
734  Teuchos::null) {
735  TEST_FLOATING_EQUALITY(modifierX->testStageX, 2.0, relTol);
736  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 2.0, relTol);
737  }
738  else if (stepper->isImplicit()) {
739  // Stage values are overwritten and not available
740  // outside takeStep, so direct comparisons are needed.
741  if (rcp_dynamic_cast<Tempus::StepperDIRK_BackwardEuler<double>>(
742  stepper) != Teuchos::null) {
743  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09900990099009901,
744  relTol);
745  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09900990099009901,
746  relTol);
747  }
748  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_2Stage2ndOrder<double>>(
749  stepper) != Teuchos::null) {
750  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09979317463412091,
751  relTol);
752  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09979317463412091,
753  relTol);
754  }
755  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_3Stage2ndOrder<double>>(
756  stepper) != Teuchos::null) {
757  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.049921670528461,
758  relTol);
759  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.049921670528461,
760  relTol);
761  }
762  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_2Stage3rdOrder<double>>(
763  stepper) != Teuchos::null) {
764  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.02171123447937569,
765  relTol);
766  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.02171123447937569,
767  relTol);
768  }
769  else if (rcp_dynamic_cast<Tempus::StepperEDIRK_2Stage3rdOrder<double>>(
770  stepper) != Teuchos::null) {
771  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06659267480577136,
772  relTol);
773  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06659267480577136,
774  relTol);
775  }
776  else if (rcp_dynamic_cast<Tempus::StepperDIRK_1StageTheta<double>>(
777  stepper) != Teuchos::null) {
778  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826,
779  relTol);
780  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826,
781  relTol);
782  }
783  else if (rcp_dynamic_cast<Tempus::StepperEDIRK_2StageTheta<double>>(
784  stepper) != Teuchos::null) {
785  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826,
786  relTol);
787  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826,
788  relTol);
789  }
790  else if (rcp_dynamic_cast<Tempus::StepperEDIRK_TrapezoidalRule<double>>(
791  stepper) != Teuchos::null) {
792  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826,
793  relTol);
794  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826,
795  relTol);
796  }
797  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_ImplicitMidpoint<double>>(
798  stepper) != Teuchos::null) {
799  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826,
800  relTol);
801  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826,
802  relTol);
803  }
804  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK22<double>>(
805  stepper) != Teuchos::null) {
806  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0748907323303947,
807  relTol);
808  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0748907323303947,
809  relTol);
810  }
811  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK32<double>>(
812  stepper) != Teuchos::null) {
813  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.08321767099874625,
814  relTol);
815  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.08321767099874625,
816  relTol);
817  }
818  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK23<double>>(
819  stepper) != Teuchos::null) {
820  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.07878078755122744,
821  relTol);
822  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.07878078755122744,
823  relTol);
824  }
825  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK33<double>>(
826  stepper) != Teuchos::null) {
827  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.08525184184135257,
828  relTol);
829  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.08525184184135257,
830  relTol);
831  }
832  else if (rcp_dynamic_cast<
834  stepper) != Teuchos::null) {
835  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09900990099009901,
836  relTol);
837  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09900990099009901,
838  relTol);
839  }
840  else if (rcp_dynamic_cast<
842  stepper) != Teuchos::null) {
843  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826,
844  relTol);
845  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826,
846  relTol);
847  }
848  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_5Stage4thOrder<double>>(
849  stepper) != Teuchos::null) {
850  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983340822548158,
851  1.0e-14);
852  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983340822548158,
853  1.0e-14);
854  }
855  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_3Stage4thOrder<double>>(
856  stepper) != Teuchos::null) {
857  TEST_FLOATING_EQUALITY(modifierX->testStageX, -0.009988159068259408,
858  relTol);
859  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, -0.009988159068259408,
860  relTol);
861  }
862  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_5Stage5thOrder<double>>(
863  stepper) != Teuchos::null) {
864  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06446224812649308,
865  relTol);
866  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06446224812649308,
867  relTol);
868  }
869  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_21Pair<double>>(stepper) !=
870  Teuchos::null) {
871  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.001960592098813843,
872  relTol);
873  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.001960592098813843,
874  relTol);
875  }
876  else if (rcp_dynamic_cast<Tempus::StepperDIRK_General<double>>(stepper) !=
877  Teuchos::null) {
878  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09979317463412091,
879  relTol);
880  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09979317463412091,
881  relTol);
882  }
883  else {
885  true, std::logic_error,
886  "Error - unknown stepperType = " + stepper->getStepperType());
887  }
888  }
889  else {
890  // Stage values are overwritten and not available
891  // outside takeStep, so direct comparisons are needed.
892  if (rcp_dynamic_cast<Tempus::StepperERK_3_8Rule<double>>(stepper) !=
893  Teuchos::null) {
894  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09966666666666668,
895  relTol);
896  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09966666666666668,
897  relTol);
898  }
899  else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrder<double>>(
900  stepper) != Teuchos::null) {
901  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, relTol);
902  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, relTol);
903  }
904  else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrderHeun<double>>(
905  stepper) != Teuchos::null) {
906  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06666666666666667,
907  relTol);
908  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06666666666666667,
909  relTol);
910  }
911  else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrderTVD<double>>(
912  stepper) != Teuchos::null) {
913  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, relTol);
914  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, relTol);
915  }
916  else if (rcp_dynamic_cast<Tempus::StepperERK_4Stage3rdOrderRunge<double>>(
917  stepper) != Teuchos::null) {
918  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0995, relTol);
919  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0995, relTol);
920  }
921  else if (rcp_dynamic_cast<Tempus::StepperERK_4Stage4thOrder<double>>(
922  stepper) != Teuchos::null) {
923  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975, relTol);
924  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975, relTol);
925  }
926  else if (rcp_dynamic_cast<Tempus::StepperERK_5Stage3rdOrderKandG<double>>(
927  stepper) != Teuchos::null) {
928  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06662222222222222,
929  relTol);
930  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06662222222222222,
931  relTol);
932  }
933  else if (rcp_dynamic_cast<Tempus::StepperERK_BogackiShampine32<double>>(
934  stepper) != Teuchos::null) {
935  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333333,
936  relTol);
937  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333333,
938  relTol);
939  }
940  else if (rcp_dynamic_cast<Tempus::StepperERK_ForwardEuler<double>>(
941  stepper) != Teuchos::null) {
942  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0, relTol);
943  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0, relTol);
944  }
945  else if (rcp_dynamic_cast<Tempus::StepperERK_General<double>>(stepper) !=
946  Teuchos::null) {
947  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975, relTol);
948  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975, relTol);
949  }
950  else if (rcp_dynamic_cast<Tempus::StepperERK_Merson45<double>>(stepper) !=
951  Teuchos::null) {
952  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333332,
953  relTol);
954  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333332,
955  relTol);
956  }
957  else if (rcp_dynamic_cast<Tempus::StepperERK_Midpoint<double>>(stepper) !=
958  Teuchos::null) {
959  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, relTol);
960  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, relTol);
961  }
962  else if (rcp_dynamic_cast<Tempus::StepperERK_Trapezoidal<double>>(
963  stepper) != Teuchos::null) {
964  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, relTol);
965  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, relTol);
966  }
967  else {
969  true, std::logic_error,
970  "Error - unknown stepperType = " + stepper->getStepperType());
971  }
972  }
973  }
974 
975  // Test Composite.
976  {
977  stepper->setModel(model);
978 
979  auto modifier = rcp(new StepperRKModifierTest());
980  auto observer = rcp(new StepperRKObserverTest());
981  auto modifierX = rcp(new StepperRKModifierXTest());
982  auto composite = rcp(new Tempus::StepperRKAppActionComposite<double>());
983 
984  composite->addRKAppAction(modifier);
985  composite->addRKAppAction(observer);
986  composite->addRKAppAction(modifierX);
987  stepper->setAppAction(composite);
988 
989  stepper->initialize();
990  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
991 
992  // Create a SolutionHistory.
993  auto solutionHistory = Tempus::createSolutionHistoryME(model);
994 
995  // Take one time step.
996  stepper->setInitialConditions(solutionHistory);
997  solutionHistory->initWorkingState();
998  double dt = 0.1;
999  solutionHistory->getWorkingState()->setTimeStep(dt);
1000  stepper->takeStep(solutionHistory);
1001 
1002  auto xCS = solutionHistory->getCurrentState()->getX();
1003  auto xWS = solutionHistory->getWorkingState()->getX();
1004  auto Dt = solutionHistory->getWorkingState()->getTimeStep();
1005 
1006  // Test Modifier.
1007  // Testing that each ACTION_LOCATION has been called.
1008  TEST_COMPARE(modifier->testBEGIN_STEP, ==, true);
1009  TEST_COMPARE(modifier->testBEGIN_STAGE, ==, true);
1010  TEST_COMPARE(modifier->testBEFORE_SOLVE, ==, true);
1011  TEST_COMPARE(modifier->testAFTER_SOLVE, ==, true);
1012  TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==, true);
1013  TEST_COMPARE(modifier->testEND_STAGE, ==, true);
1014  TEST_COMPARE(modifier->testEND_STEP, ==, true);
1015 
1016  const double relTol = 1.0e-14;
1017  // Testing that values can be set through the modifier.
1018  TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(xCS), 0),
1019  relTol);
1020  TEST_FLOATING_EQUALITY(modifier->testWorkingValue, get_ele(*(xWS), 0),
1021  relTol);
1022  TEST_FLOATING_EQUALITY(modifier->testDt, Dt / 10.0, relTol);
1023 
1024  auto testName = testNameOrig + " - Modifier";
1025  TEST_COMPARE(modifier->testName, ==, testName);
1026 
1027  // Test Observer.
1028  // Testing that each ACTION_LOCATION has been called.
1029  TEST_COMPARE(observer->testBEGIN_STEP, ==, true);
1030  TEST_COMPARE(observer->testBEGIN_STAGE, ==, true);
1031  TEST_COMPARE(observer->testBEFORE_SOLVE, ==, true);
1032  TEST_COMPARE(observer->testAFTER_SOLVE, ==, true);
1033  TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==, true);
1034  TEST_COMPARE(observer->testEND_STAGE, ==, true);
1035  TEST_COMPARE(observer->testEND_STEP, ==, true);
1036 
1037  // Testing that values can be observed through the observer.
1038  TEST_FLOATING_EQUALITY(observer->testCurrentValue, get_ele(*(xCS), 0),
1039  relTol);
1040  TEST_FLOATING_EQUALITY(observer->testWorkingValue, get_ele(*(xWS), 0),
1041  relTol);
1042  TEST_FLOATING_EQUALITY(observer->testDt, Dt / 10.0, relTol);
1043 
1044  testName = testNameOrig + " - Observer";
1045  TEST_COMPARE(observer->testName, ==, testName);
1046 
1047  // Test ModifierX.
1048  // Testing that each ACTION_LOCATION has been called.
1049  TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==, true);
1050  TEST_COMPARE(modifierX->testX_BEGIN_STAGE, ==, true);
1051  TEST_COMPARE(modifierX->testX_BEFORE_SOLVE, ==, true);
1052  TEST_COMPARE(modifierX->testX_AFTER_SOLVE, ==, true);
1053  TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==, true);
1054  TEST_COMPARE(modifierX->testXDOT_END_STAGE, ==, true);
1055  TEST_COMPARE(modifierX->testX_END_STEP, ==, true);
1056 
1057  // Testing that values can be set through the modifierX.
1058  TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(xCS), 0), relTol);
1059  TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, relTol);
1060 
1061  auto time = solutionHistory->getWorkingState()->getTime();
1062  TEST_FLOATING_EQUALITY(modifierX->testTime, time, relTol);
1063 
1064  // Stage Number should be -1 outside stage loop.
1065  TEST_COMPARE(stepper->getStageNumber(), ==, -1);
1066  // The last stage number through X_BEFORE_EXPLICIT_EVAL should be
1067  // the number of stages minus one.
1068  TEST_COMPARE(modifierX->testStageNumber, ==,
1069  stepper->getNumberOfStages() - 1);
1070 
1071  if (rcp_dynamic_cast<Tempus::StepperIMEX_RK<double>>(stepper) !=
1072  Teuchos::null ||
1073  rcp_dynamic_cast<Tempus::StepperIMEX_RK_Partition<double>>(stepper) !=
1074  Teuchos::null) {
1075  TEST_FLOATING_EQUALITY(modifierX->testStageX, 2.0, relTol);
1076  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 2.0, relTol);
1077  }
1078  else if (stepper->isImplicit()) {
1079  // Stage values are overwritten and not available
1080  // outside takeStep, so direct comparisons are needed.
1081  if (rcp_dynamic_cast<Tempus::StepperDIRK_BackwardEuler<double>>(
1082  stepper) != Teuchos::null) {
1083  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09900990099009901,
1084  relTol);
1085  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09900990099009901,
1086  relTol);
1087  }
1088  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_2Stage2ndOrder<double>>(
1089  stepper) != Teuchos::null) {
1090  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09979317463412091,
1091  relTol);
1092  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09979317463412091,
1093  relTol);
1094  }
1095  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_3Stage2ndOrder<double>>(
1096  stepper) != Teuchos::null) {
1097  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.049921670528461,
1098  relTol);
1099  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.049921670528461,
1100  relTol);
1101  }
1102  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_2Stage3rdOrder<double>>(
1103  stepper) != Teuchos::null) {
1104  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.02171123447937569,
1105  relTol);
1106  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.02171123447937569,
1107  relTol);
1108  }
1109  else if (rcp_dynamic_cast<Tempus::StepperEDIRK_2Stage3rdOrder<double>>(
1110  stepper) != Teuchos::null) {
1111  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06659267480577136,
1112  relTol);
1113  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06659267480577136,
1114  relTol);
1115  }
1116  else if (rcp_dynamic_cast<Tempus::StepperDIRK_1StageTheta<double>>(
1117  stepper) != Teuchos::null) {
1118  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826,
1119  relTol);
1120  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826,
1121  relTol);
1122  }
1123  else if (rcp_dynamic_cast<Tempus::StepperEDIRK_2StageTheta<double>>(
1124  stepper) != Teuchos::null) {
1125  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826,
1126  relTol);
1127  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826,
1128  relTol);
1129  }
1130  else if (rcp_dynamic_cast<Tempus::StepperEDIRK_TrapezoidalRule<double>>(
1131  stepper) != Teuchos::null) {
1132  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826,
1133  relTol);
1134  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826,
1135  relTol);
1136  }
1137  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_ImplicitMidpoint<double>>(
1138  stepper) != Teuchos::null) {
1139  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826,
1140  relTol);
1141  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826,
1142  relTol);
1143  }
1144  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK22<double>>(
1145  stepper) != Teuchos::null) {
1146  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0748907323303947,
1147  relTol);
1148  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0748907323303947,
1149  relTol);
1150  }
1151  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK32<double>>(
1152  stepper) != Teuchos::null) {
1153  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.08321767099874625,
1154  relTol);
1155  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.08321767099874625,
1156  relTol);
1157  }
1158  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK23<double>>(
1159  stepper) != Teuchos::null) {
1160  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.07878078755122744,
1161  relTol);
1162  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.07878078755122744,
1163  relTol);
1164  }
1165  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK33<double>>(
1166  stepper) != Teuchos::null) {
1167  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.08525184184135257,
1168  relTol);
1169  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.08525184184135257,
1170  relTol);
1171  }
1172  else if (rcp_dynamic_cast<
1174  stepper) != Teuchos::null) {
1175  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09900990099009901,
1176  relTol);
1177  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09900990099009901,
1178  relTol);
1179  }
1180  else if (rcp_dynamic_cast<
1182  stepper) != Teuchos::null) {
1183  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826,
1184  relTol);
1185  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826,
1186  relTol);
1187  }
1188  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_5Stage4thOrder<double>>(
1189  stepper) != Teuchos::null) {
1190  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983340822548158,
1191  relTol);
1192  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983340822548158,
1193  relTol);
1194  }
1195  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_3Stage4thOrder<double>>(
1196  stepper) != Teuchos::null) {
1197  TEST_FLOATING_EQUALITY(modifierX->testStageX, -0.009988159068259408,
1198  relTol);
1199  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, -0.009988159068259408,
1200  relTol);
1201  }
1202  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_5Stage5thOrder<double>>(
1203  stepper) != Teuchos::null) {
1204  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06446224812649308,
1205  relTol);
1206  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06446224812649308,
1207  relTol);
1208  }
1209  else if (rcp_dynamic_cast<Tempus::StepperSDIRK_21Pair<double>>(stepper) !=
1210  Teuchos::null) {
1211  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.001960592098813843,
1212  relTol);
1213  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.001960592098813843,
1214  relTol);
1215  }
1216  else if (rcp_dynamic_cast<Tempus::StepperDIRK_General<double>>(stepper) !=
1217  Teuchos::null) {
1218  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09979317463412091,
1219  relTol);
1220  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09979317463412091,
1221  relTol);
1222  }
1223  else {
1225  true, std::logic_error,
1226  "Error - unknown stepperType = " + stepper->getStepperType());
1227  }
1228  }
1229  else {
1230  // For explicit steppers, stageX is under written and not available
1231  // outside takeStep, so direct comparisons are needed.
1232  if (rcp_dynamic_cast<Tempus::StepperERK_3_8Rule<double>>(stepper) !=
1233  Teuchos::null) {
1234  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09966666666666668,
1235  relTol);
1236  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09966666666666668,
1237  relTol);
1238  }
1239  else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrder<double>>(
1240  stepper) != Teuchos::null) {
1241  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, relTol);
1242  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, relTol);
1243  }
1244  else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrderHeun<double>>(
1245  stepper) != Teuchos::null) {
1246  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06666666666666667,
1247  relTol);
1248  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06666666666666667,
1249  relTol);
1250  }
1251  else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrderTVD<double>>(
1252  stepper) != Teuchos::null) {
1253  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, relTol);
1254  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, relTol);
1255  }
1256  else if (rcp_dynamic_cast<Tempus::StepperERK_4Stage3rdOrderRunge<double>>(
1257  stepper) != Teuchos::null) {
1258  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0995, relTol);
1259  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0995, relTol);
1260  }
1261  else if (rcp_dynamic_cast<Tempus::StepperERK_4Stage4thOrder<double>>(
1262  stepper) != Teuchos::null) {
1263  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975, relTol);
1264  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975, relTol);
1265  }
1266  else if (rcp_dynamic_cast<Tempus::StepperERK_5Stage3rdOrderKandG<double>>(
1267  stepper) != Teuchos::null) {
1268  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06662222222222222,
1269  relTol);
1270  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06662222222222222,
1271  relTol);
1272  }
1273  else if (rcp_dynamic_cast<Tempus::StepperERK_BogackiShampine32<double>>(
1274  stepper) != Teuchos::null) {
1275  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333333,
1276  relTol);
1277  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333333,
1278  relTol);
1279  }
1280  else if (rcp_dynamic_cast<Tempus::StepperERK_ForwardEuler<double>>(
1281  stepper) != Teuchos::null) {
1282  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0, relTol);
1283  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0, relTol);
1284  }
1285  else if (rcp_dynamic_cast<Tempus::StepperERK_General<double>>(stepper) !=
1286  Teuchos::null) {
1287  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975, relTol);
1288  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975, relTol);
1289  }
1290  else if (rcp_dynamic_cast<Tempus::StepperERK_Merson45<double>>(stepper) !=
1291  Teuchos::null) {
1292  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333332,
1293  relTol);
1294  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333332,
1295  relTol);
1296  }
1297  else if (rcp_dynamic_cast<Tempus::StepperERK_Midpoint<double>>(stepper) !=
1298  Teuchos::null) {
1299  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, relTol);
1300  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, relTol);
1301  }
1302  else if (rcp_dynamic_cast<Tempus::StepperERK_Trapezoidal<double>>(
1303  stepper) != Teuchos::null) {
1304  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, relTol);
1305  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, relTol);
1306  }
1307  else {
1309  true, std::logic_error,
1310  "Error - unknown stepperType = " + stepper->getStepperType());
1311  }
1312  }
1313  }
1314 }
1315 
1316 } // namespace Tempus_Unit_Test
1317 #endif // Tempus_UnitTest_RK_Utils_hpp
Unit test class for RK Stepper Observer AppAction.
void testDIRKAccessorsFullConstruction(const RCP< Tempus::StepperDIRK< double >> &stepper)
Unit test utility for ExplicitRK Stepper construction and accessors.
General Implicit Runge-Kutta Butcher Tableau.
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 Implicit 2 Stage 2nd order Lobatto IIIB.
Explicit Runge-Kutta time stepper.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
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...
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.
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.
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.
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.
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.
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.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
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).
Forward Euler Runge-Kutta Butcher Tableau.
void testExplicitRKAccessorsFullConstruction(const RCP< Tempus::StepperExplicitRK< double >> &stepper)
Unit test utility for ExplicitRK Stepper construction and accessors.
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.