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