Tempus Version of the Day
Time Integration
Loading...
Searching...
No Matches
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
12
14
16
17#include "Tempus_StepperIMEX_RK.hpp"
18#include "Tempus_StepperIMEX_RK_Partition.hpp"
19
27
28
29namespace Tempus_Unit_Test {
30
31using Teuchos::RCP;
32using Teuchos::rcp;
33using Teuchos::rcp_const_cast;
34using Teuchos::rcp_dynamic_cast;
35using Teuchos::ParameterList;
36
38
42 const RCP<Tempus::StepperExplicitRK<double> >& stepper)
43{
44 auto model = rcp(new Tempus_Test::SinCosModel<double>());
45 stepper->setModel(model);
46 stepper->initialize();
47 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
48
49 // Default values for construction.
50 auto modifier = rcp(new Tempus::StepperRKModifierDefault<double>());
51 auto modifierX = rcp(new Tempus::StepperRKModifierXDefault<double>());
52 auto observer = rcp(new Tempus::StepperRKObserverDefault<double>());
53 bool useFSAL = stepper->getUseFSAL();
54 std::string ICConsistency = stepper->getICConsistency();
55 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
56 bool useEmbedded = stepper->getUseEmbedded();
57
58 // Test the set functions.
59 stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
60 stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
61 stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
62 stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
63 stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
64 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
65 stepper->setUseEmbedded(useEmbedded); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
66
67
68 std::string stepperType = stepper->getStepperType();
69 // Full argument list construction.
70 if (stepperType == "RK Explicit 3 Stage 3rd order") {
72 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
73 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
74 } else if (stepperType == "RK Explicit 3 Stage 3rd order by Heun") {
76 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
77 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
78 } else if (stepperType == "RK Explicit 3 Stage 3rd order TVD") {
80 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
81 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
82 } else if (stepperType == "RK Explicit 3/8 Rule") {
84 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
85 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
86 } else if (stepperType == "RK Explicit 4 Stage 3rd order by Runge") {
88 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
89 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
90 } else if (stepperType == "RK Explicit 4 Stage") {
92 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
93 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
94 } else if (stepperType == "RK Explicit 5 Stage 3rd order by Kinnmark and Gray") {
96 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
97 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
98 } else if (stepperType == "Bogacki-Shampine 3(2) Pair") {
100 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
101 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
102 } else if (stepperType == "RK Forward Euler") {
104 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
105 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
106 } else if (stepperType == "Merson 4(5) Pair") {
108 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
109 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
110 } else if (stepperType == "RK Explicit Midpoint") {
112 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
113 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
114 } else if (stepperType == "RK Explicit Trapezoidal") {
116 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
117 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
118 }
119 else TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Error - unknown stepperType = "+stepperType);
120}
121
122
126 const RCP<Tempus::StepperDIRK<double> >& stepper)
127{
128 auto model = rcp(new Tempus_Test::SinCosModel<double>());
129 stepper->setModel(model);
130 stepper->initialize();
131 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
132
133 // Default values for construction.
134 auto modifier = rcp(new Tempus::StepperRKModifierDefault<double>());
135 auto modifierX = rcp(new Tempus::StepperRKModifierXDefault<double>());
136 auto observer = rcp(new Tempus::StepperRKObserverDefault<double>());
137 auto solver = rcp(new Thyra::NOXNonlinearSolver());
138 solver->setParameterList(Tempus::defaultSolverParameters());
139
140 bool useFSAL = stepper->getUseFSAL();
141 std::string ICConsistency = stepper->getICConsistency();
142 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
143 bool useEmbedded = stepper->getUseEmbedded();
144 bool zeroInitialGuess = stepper->getZeroInitialGuess();
145
146 // Test the set functions.
147 stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
148 stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
149 stepper->setSolver(solver); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
150 stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
151 stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
152 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
153 stepper->setUseEmbedded(useEmbedded); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
154 stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
155
156
157 std::string stepperType = stepper->getStepperType();
158 // Full argument list construction.
159 if (stepperType == "RK Backward Euler") {
161 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
162 useEmbedded, zeroInitialGuess, modifier));
163 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
164 } else if (stepperType == "SDIRK 2 Stage 2nd order") {
165 double gamma = 0.2928932188134524;
167 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
168 useEmbedded, zeroInitialGuess, modifier, gamma));
169 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
170 } else if (stepperType == "SDIRK 3 Stage 2nd order") {
172 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
173 useEmbedded, zeroInitialGuess, modifier));
174 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
175 } else if (stepperType == "SDIRK 2 Stage 3rd order") {
176 std::string gammaType = "3rd Order A-stable";
177 double gamma = 0.7886751345948128;
179 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
180 useEmbedded, zeroInitialGuess, modifier, gammaType, gamma));
181 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
182 } else if (stepperType == "EDIRK 2 Stage 3rd order") {
184 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
185 useEmbedded, zeroInitialGuess, modifier));
186 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
187 } else if (stepperType == "DIRK 1 Stage Theta Method") {
188 double theta = 0.5;
190 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
191 useEmbedded, zeroInitialGuess, modifier, theta));
192 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
193 } else if (stepperType == "EDIRK 2 Stage Theta Method") {
194 double theta = 0.5;
196 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
197 useEmbedded, zeroInitialGuess, modifier, theta));
198 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
199 s->setTheta(theta);
200 s->initialize();
201 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
202 } else if (stepperType == "RK Trapezoidal Rule") {
204 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
205 useEmbedded, zeroInitialGuess, modifier));
206 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
207 } else if (stepperType == "RK Implicit Midpoint") {
209 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
210 useEmbedded, zeroInitialGuess, modifier));
211 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
212 } else if (stepperType == "SSPDIRK22") {
214 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
215 useEmbedded, zeroInitialGuess, modifier));
216 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
217 } else if (stepperType == "SSPDIRK32") {
219 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
220 useEmbedded, zeroInitialGuess, modifier));
221 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
222 } else if (stepperType == "SSPDIRK23") {
224 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
225 useEmbedded, zeroInitialGuess, modifier));
226 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
227 } else if (stepperType == "SSPDIRK33") {
229 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
230 useEmbedded, zeroInitialGuess, modifier));
231 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
232 } else if (stepperType == "RK Implicit 1 Stage 1st order Radau IA") {
234 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
235 useEmbedded, zeroInitialGuess, modifier));
236 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
237 } else if (stepperType == "RK Implicit 2 Stage 2nd order Lobatto IIIB") {
239 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
240 useEmbedded, zeroInitialGuess, modifier));
241 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
242 } else if (stepperType == "SDIRK 5 Stage 4th order") {
244 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
245 useEmbedded, zeroInitialGuess, modifier));
246 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
247 } else if (stepperType == "SDIRK 3 Stage 4th order") {
249 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
250 useEmbedded, zeroInitialGuess, modifier));
251 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
252 } else if (stepperType == "SDIRK 5 Stage 5th order") {
254 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
255 useEmbedded, zeroInitialGuess, modifier));
256 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
257 } else if (stepperType == "SDIRK 2(1) Pair") {
259 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
260 useEmbedded, zeroInitialGuess, modifier));
261 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
262 } else TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Error - unknown stepperType = "+stepperType);
263
264}
265
266
270 : virtual public Tempus::StepperRKModifierBase<double>
271{
272public:
273
276 : testBEGIN_STEP(false),
277 testBEGIN_STAGE(false),
278 testBEFORE_SOLVE(false),
279 testAFTER_SOLVE(false),
281 testEND_STAGE(false),
282 testEND_STEP(false),
283 testCurrentValue(-0.99),
284 testWorkingValue(-0.99),
285 testDt(-1.5),
286 testName("")
287 {}
288
291
293 virtual void modify(
294 Teuchos::RCP<Tempus::SolutionHistory<double> > sh,
295 Teuchos::RCP<Tempus::StepperRKBase<double> > stepper,
297 {
298 switch(actLoc) {
299 case StepperRKAppAction<double>::BEGIN_STEP:
300 {
301 testBEGIN_STEP = true;
302 auto x = sh->getCurrentState()->getX();
303 testCurrentValue = get_ele(*(x), 0);
304 testName = stepper->getStepperType() + " - Modifier";
305 stepper->setStepperName(testName);
306 break;
307 }
308 case StepperRKAppAction<double>::BEGIN_STAGE:
309 {
310 testBEGIN_STAGE = true;
311 break;
312 }
313 case StepperRKAppAction<double>::BEFORE_SOLVE:
314 {
315 testBEFORE_SOLVE = true;
316 testDt = sh->getWorkingState()->getTimeStep()/10.0;
317 break;
318 }
319 case StepperRKAppAction<double>::AFTER_SOLVE:
320 {
321 testAFTER_SOLVE = true;
322 break;
323 }
324 case StepperRKAppAction<double>::BEFORE_EXPLICIT_EVAL:
325 {
327 break;
328 }
329 case StepperRKAppAction<double>::END_STAGE:
330 {
331 testEND_STAGE = true;
332 break;
333 }
334 case StepperRKAppAction<double>::END_STEP:
335 {
336 testEND_STEP = true;
337 auto x = sh->getWorkingState()->getX();
338 testWorkingValue = get_ele(*(x), 0);
339 break;
340 }
341 default:
342 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
343 "Error - unknown action location.\n");
344 }
345 }
346
356 double testDt;
357 std::string testName;
358};
359
360
364 : virtual public Tempus::StepperRKObserverBase<double>
365{
366public:
367
370 : testBEGIN_STEP(false),
371 testBEGIN_STAGE(false),
372 testBEFORE_SOLVE(false),
373 testAFTER_SOLVE(false),
375 testEND_STAGE(false),
376 testEND_STEP(false),
377 testCurrentValue(-0.99),
378 testWorkingValue(-0.99),
379 testDt(-1.5),
380 testName("")
381 {}
382
385
387 virtual void observe(
388 Teuchos::RCP<const Tempus::SolutionHistory<double> > sh,
389 Teuchos::RCP<const Tempus::StepperRKBase<double> > stepper,
391 {
392 switch(actLoc) {
393 case StepperRKAppAction<double>::BEGIN_STEP:
394 {
395 testBEGIN_STEP = true;
396 auto x = sh->getCurrentState()->getX();
397 testCurrentValue = get_ele(*(x), 0);
398 break;
399 }
400 case StepperRKAppAction<double>::BEGIN_STAGE:
401 {
402 testBEGIN_STAGE = true;
403 break;
404 }
405 case StepperRKAppAction<double>::BEFORE_SOLVE:
406 {
407 testBEFORE_SOLVE = true;
408 testDt = sh->getWorkingState()->getTimeStep()/10.0;
409 break;
410 }
411 case StepperRKAppAction<double>::AFTER_SOLVE:
412 {
413 testAFTER_SOLVE = true;
414 testName = stepper->getStepperType() + " - Observer";
415 break;
416 }
417 case StepperRKAppAction<double>::BEFORE_EXPLICIT_EVAL:
418 {
420 break;
421 }
422 case StepperRKAppAction<double>::END_STAGE:
423 {
424 testEND_STAGE = true;
425 break;
426 }
427 case StepperRKAppAction<double>::END_STEP:
428 {
429 testEND_STEP = true;
430 auto x = sh->getWorkingState()->getX();
431 testWorkingValue = get_ele(*(x), 0);
432 break;
433 }
434 default:
435 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
436 "Error - unknown action location.\n");
437 }
438 }
439
449 double testDt;
450 std::string testName;
451};
452
453
455 : virtual public Tempus::StepperRKModifierXBase<double>
456{
457public:
458
461 : testX_BEGIN_STEP(false),
462 testX_BEGIN_STAGE(false),
463 testX_BEFORE_SOLVE(false),
464 testX_AFTER_SOLVE(false),
466 testXDOT_END_STAGE(false),
467 testX_END_STEP(false),
468 testX(-0.99),
469 testEndStageX(-0.99),
470 testDt(-1.5),
471 testTime(-1.5),
472 testStageNumber(-1),
473 testStageX(-0.99)
474 {}
475
478
480 virtual void modify(
481 Teuchos::RCP<Thyra::VectorBase<double> > x,
482 const double time, const double dt,
483 const int stageNumber,
485 {
486 switch(modType) {
487 case StepperRKModifierXBase<double>::X_BEGIN_STEP:
488 {
489 testX_BEGIN_STEP = true;
490 testX = get_ele(*(x), 0);
491 break;
492 }
493 case StepperRKModifierXBase<double>::X_BEGIN_STAGE:
494 {
495 testX_BEGIN_STAGE = true;
496 break;
497 }
498 case StepperRKModifierXBase<double>::X_BEFORE_SOLVE:
499 {
500 testX_BEFORE_SOLVE = true;
501 testDt = dt;
502 break;
503 }
504 case StepperRKModifierXBase<double>::X_AFTER_SOLVE:
505 {
506 testX_AFTER_SOLVE = true;
507 break;
508 }
509 case StepperRKModifierXBase<double>::X_BEFORE_EXPLICIT_EVAL:
510 {
512 testStageNumber = stageNumber;
513 testStageX = get_ele(*(x), 0); // x should be the stage value.
514 break;
515 }
516 case StepperRKModifierXBase<double>::X_END_STAGE:
517 {
518 testXDOT_END_STAGE = true;
519 testEndStageX = get_ele(*(x), 0);
520 break;
521 }
522 case StepperRKModifierXBase<double>::X_END_STEP:
523 {
524 testX_END_STEP = true;
525 testTime = time;
526 break;
527 }
528 default:
529 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
530 "Error - unknown action location.\n");
531 }
532 }
533
541 double testX;
543 double testDt;
544 double testTime;
547};
548
549
553 const Teuchos::RCP<Tempus::StepperRKBase<double> >& stepper,
554 const Teuchos::RCP<const Thyra::ModelEvaluator<double> >& model,
555 Teuchos::FancyOStream &out, bool &success)
556{
557 auto testNameOrig = stepper->getStepperType();
558
559 // Test Modifier.
560 {
561 stepper->setModel(model);
562 auto modifier = rcp(new StepperRKModifierTest());
563 stepper->setAppAction(modifier);
564 stepper->initialize();
565 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
566 auto testName = testNameOrig + " - Modifier";
567
568 // Create a SolutionHistory.
569 auto solutionHistory = Tempus::createSolutionHistoryME(model);
570
571 // Take one time step.
572 stepper->setInitialConditions(solutionHistory);
573 solutionHistory->initWorkingState();
574 double dt = 0.1;
575 solutionHistory->getWorkingState()->setTimeStep(dt);
576 stepper->takeStep(solutionHistory);
577
578 // Testing that each ACTION_LOCATION has been called.
579 TEST_COMPARE(modifier->testBEGIN_STEP, ==, true);
580 TEST_COMPARE(modifier->testBEGIN_STAGE, ==, true);
581 TEST_COMPARE(modifier->testBEFORE_SOLVE, ==, true);
582 TEST_COMPARE(modifier->testAFTER_SOLVE, ==, true);
583 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==, true);
584 TEST_COMPARE(modifier->testEND_STAGE, ==, true);
585 TEST_COMPARE(modifier->testEND_STEP, ==, true);
586
587 // Testing that values can be set through the modifier.
588 auto x = solutionHistory->getCurrentState()->getX();
589 TEST_FLOATING_EQUALITY(modifier->testCurrentValue,get_ele(*(x), 0),1.0e-14);
590 x = solutionHistory->getWorkingState()->getX();
591 TEST_FLOATING_EQUALITY(modifier->testWorkingValue,get_ele(*(x), 0),1.0e-14);
592 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
593 TEST_FLOATING_EQUALITY(modifier->testDt, Dt/10.0, 1.0e-14);
594
595 TEST_COMPARE(modifier->testName, ==, testName);
596 }
597
598 // Test Observer.
599 {
600 stepper->setModel(model);
601 auto observer = rcp(new StepperRKObserverTest());
602 stepper->setAppAction(observer);
603 stepper->setStepperName(testNameOrig);
604 stepper->initialize();
605 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
606
607 // Create a SolutionHistory.
608 auto solutionHistory = Tempus::createSolutionHistoryME(model);
609
610 // Take one time step.
611 stepper->setInitialConditions(solutionHistory);
612 solutionHistory->initWorkingState();
613 double dt = 0.1;
614 solutionHistory->getWorkingState()->setTimeStep(dt);
615 stepper->takeStep(solutionHistory);
616
617 // Testing that each ACTION_LOCATION has been called.
618 TEST_COMPARE(observer->testBEGIN_STEP, ==, true);
619 TEST_COMPARE(observer->testBEGIN_STAGE, ==, true);
620 TEST_COMPARE(observer->testBEFORE_SOLVE, ==, true);
621 TEST_COMPARE(observer->testAFTER_SOLVE, ==, true);
622 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==, true);
623 TEST_COMPARE(observer->testEND_STAGE, ==, true);
624 TEST_COMPARE(observer->testEND_STEP, ==, true);
625
626 // Testing that values can be observed through the observer.
627 auto x = solutionHistory->getCurrentState()->getX();
628 TEST_FLOATING_EQUALITY(observer->testCurrentValue,get_ele(*(x), 0),1.0e-14);
629 x = solutionHistory->getWorkingState()->getX();
630 TEST_FLOATING_EQUALITY(observer->testWorkingValue,get_ele(*(x), 0),1.0e-14);
631 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
632 TEST_FLOATING_EQUALITY(observer->testDt, Dt/10.0, 1.0e-14);
633
634 auto testName = testNameOrig + " - Observer";
635 TEST_COMPARE(observer->testName, ==, testName);
636 }
637
638 // Test ModifierX.
639 {
640 stepper->setModel(model);
641 auto modifierX = rcp(new StepperRKModifierXTest());
642 stepper->setAppAction(modifierX);
643 stepper->setStepperName(testNameOrig);
644 stepper->initialize();
645 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
646
647 // Create a SolutionHistory.
648 auto solutionHistory = Tempus::createSolutionHistoryME(model);
649
650 // Take one time step.
651 stepper->setInitialConditions(solutionHistory);
652 solutionHistory->initWorkingState();
653 double dt = 0.1;
654 solutionHistory->getWorkingState()->setTimeStep(dt);
655 stepper->takeStep(solutionHistory);
656
657 // Testing that each ACTION_LOCATION has been called.
658 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==, true);
659 TEST_COMPARE(modifierX->testX_BEGIN_STAGE, ==, true);
660 TEST_COMPARE(modifierX->testX_BEFORE_SOLVE, ==, true);
661 TEST_COMPARE(modifierX->testX_AFTER_SOLVE, ==, true);
662 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==, true);
663 TEST_COMPARE(modifierX->testXDOT_END_STAGE, ==, true);
664 TEST_COMPARE(modifierX->testX_END_STEP, ==, true);
665
666 const double relTol = 1.0e-14;
667 // Testing that values can be set through the modifierX.
668 auto x = solutionHistory->getCurrentState()->getX();
669 TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(x), 0), relTol);
670 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
671 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, relTol);
672
673 auto time = solutionHistory->getWorkingState()->getTime();
674 TEST_FLOATING_EQUALITY(modifierX->testTime, time, relTol);
675
676 // Stage Number should be -1 outside stage loop.
677 TEST_COMPARE(stepper->getStageNumber(), ==, -1);
678 // The last stage number through X_BEFORE_EXPLICIT_EVAL should be
679 // the number of stages minus one.
680 TEST_COMPARE(modifierX->testStageNumber,==,stepper->getNumberOfStages()-1);
681
682 if (rcp_dynamic_cast<Tempus::StepperIMEX_RK<double>>(stepper) != Teuchos::null ||
683 rcp_dynamic_cast<Tempus::StepperIMEX_RK_Partition<double>>(stepper) != Teuchos::null) {
684 TEST_FLOATING_EQUALITY(modifierX->testStageX, 2.0, relTol);
685 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 2.0,relTol);
686 } else if (stepper->isImplicit()) {
687 // Stage values are overwritten and not available
688 // outside takeStep, so direct comparisons are needed.
689 if (rcp_dynamic_cast<Tempus::StepperDIRK_BackwardEuler<double>>(stepper) != Teuchos::null) {
690 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09900990099009901, relTol);
691 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09900990099009901, relTol);
692 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_2Stage2ndOrder<double>>(stepper) != Teuchos::null) {
693 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09979317463412091, relTol);
694 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09979317463412091, relTol);
695 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_3Stage2ndOrder<double>>(stepper) != Teuchos::null) {
696 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.049921670528461, relTol);
697 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.049921670528461, relTol);
698 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_2Stage3rdOrder<double>>(stepper) != Teuchos::null) {
699 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.02171123447937569, relTol);
700 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.02171123447937569, relTol);
701 } else if (rcp_dynamic_cast<Tempus::StepperEDIRK_2Stage3rdOrder<double>>(stepper) != Teuchos::null) {
702 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06659267480577136, relTol);
703 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06659267480577136, relTol);
704 } else if (rcp_dynamic_cast<Tempus::StepperDIRK_1StageTheta<double>>(stepper) != Teuchos::null) {
705 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
706 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
707 } else if (rcp_dynamic_cast<Tempus::StepperEDIRK_2StageTheta<double>>(stepper) != Teuchos::null) {
708 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
709 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
710 } else if (rcp_dynamic_cast<Tempus::StepperEDIRK_TrapezoidalRule<double>>(stepper) != Teuchos::null) {
711 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
712 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
713 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_ImplicitMidpoint<double>>(stepper) != Teuchos::null) {
714 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
715 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
716 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK22<double>>(stepper) != Teuchos::null) {
717 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0748907323303947, relTol);
718 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0748907323303947, relTol);
719 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK32<double>>(stepper) != Teuchos::null) {
720 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.08321767099874625, relTol);
721 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.08321767099874625, relTol);
722 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK23<double>>(stepper) != Teuchos::null) {
723 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.07878078755122744, relTol);
724 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.07878078755122744, relTol);
725 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK33<double>>(stepper) != Teuchos::null) {
726 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.08525184184135257, relTol);
727 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.08525184184135257, relTol);
728 } else if (rcp_dynamic_cast<Tempus::StepperDIRK_1Stage1stOrderRadauIA<double>>(stepper) != Teuchos::null) {
729 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09900990099009901, relTol);
730 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09900990099009901, relTol);
731 } else if (rcp_dynamic_cast<Tempus::StepperDIRK_2Stage2ndOrderLobattoIIIB<double>>(stepper) != Teuchos::null) {
732 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
733 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
734 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_5Stage4thOrder<double>>(stepper) != Teuchos::null) {
735 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983340822548158, 1.0e-14);
736 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983340822548158, 1.0e-14);
737 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_3Stage4thOrder<double>>(stepper) != Teuchos::null) {
738 TEST_FLOATING_EQUALITY(modifierX->testStageX, -0.009988159068259408, relTol);
739 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, -0.009988159068259408, relTol);
740 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_5Stage5thOrder<double>>(stepper) != Teuchos::null) {
741 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06446224812649308, relTol);
742 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06446224812649308, relTol);
743 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_21Pair<double>>(stepper) != Teuchos::null) {
744 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.001960592098813843, relTol);
745 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.001960592098813843, relTol);
746 } else if (rcp_dynamic_cast<Tempus::StepperDIRK_General<double>>(stepper) != Teuchos::null) {
747 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09979317463412091, relTol);
748 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09979317463412091, relTol);
749 } else {
750 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
751 "Error - unknown stepperType = "+stepper->getStepperType());
752 }
753 } else {
754 // Stage values are overwritten and not available
755 // outside takeStep, so direct comparisons are needed.
756 if (rcp_dynamic_cast<Tempus::StepperERK_3_8Rule<double>>(stepper) != Teuchos::null) {
757 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09966666666666668, relTol);
758 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09966666666666668, relTol);
759 } else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrder<double>>(stepper) != Teuchos::null) {
760 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, relTol);
761 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, relTol);
762 } else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrderHeun<double>>(stepper) != Teuchos::null) {
763 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06666666666666667, relTol);
764 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06666666666666667, relTol);
765 } else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrderTVD<double>>(stepper) != Teuchos::null) {
766 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, relTol);
767 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, relTol);
768 } else if (rcp_dynamic_cast<Tempus::StepperERK_4Stage3rdOrderRunge<double>>(stepper) != Teuchos::null) {
769 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0995, relTol);
770 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0995, relTol);
771 } else if (rcp_dynamic_cast<Tempus::StepperERK_4Stage4thOrder<double>>(stepper) != Teuchos::null) {
772 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975, relTol);
773 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975, relTol);
774 } else if (rcp_dynamic_cast<Tempus::StepperERK_5Stage3rdOrderKandG<double>>(stepper) != Teuchos::null) {
775 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06662222222222222, relTol);
776 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06662222222222222, relTol);
777 } else if (rcp_dynamic_cast<Tempus::StepperERK_BogackiShampine32<double>>(stepper) != Teuchos::null) {
778 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333333, relTol);
779 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333333, relTol);
780 } else if (rcp_dynamic_cast<Tempus::StepperERK_ForwardEuler<double>>(stepper) != Teuchos::null) {
781 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0, relTol);
782 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0, relTol);
783 } else if (rcp_dynamic_cast<Tempus::StepperERK_General<double>>(stepper) != Teuchos::null) {
784 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975, relTol);
785 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975, relTol);
786 } else if (rcp_dynamic_cast<Tempus::StepperERK_Merson45<double>>(stepper) != Teuchos::null) {
787 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333332, relTol);
788 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333332, relTol);
789 } else if (rcp_dynamic_cast<Tempus::StepperERK_Midpoint<double>>(stepper) != Teuchos::null) {
790 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, relTol);
791 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, relTol);
792 } else if (rcp_dynamic_cast<Tempus::StepperERK_Trapezoidal<double>>(stepper) != Teuchos::null) {
793 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, relTol);
794 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, relTol);
795 } else {
796 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
797 "Error - unknown stepperType = "+stepper->getStepperType());
798 }
799 }
800 }
801
802
803 // Test Composite.
804 {
805 stepper->setModel(model);
806
807 auto modifier = rcp(new StepperRKModifierTest());
808 auto observer = rcp(new StepperRKObserverTest());
809 auto modifierX = rcp(new StepperRKModifierXTest());
810 auto composite = rcp(new Tempus::StepperRKAppActionComposite<double>());
811
812 composite->addRKAppAction(modifier);
813 composite->addRKAppAction(observer);
814 composite->addRKAppAction(modifierX);
815 stepper->setAppAction(composite);
816
817 stepper->initialize();
818 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
819
820 // Create a SolutionHistory.
821 auto solutionHistory = Tempus::createSolutionHistoryME(model);
822
823 // Take one time step.
824 stepper->setInitialConditions(solutionHistory);
825 solutionHistory->initWorkingState();
826 double dt = 0.1;
827 solutionHistory->getWorkingState()->setTimeStep(dt);
828 stepper->takeStep(solutionHistory);
829
830 auto xCS = solutionHistory->getCurrentState()->getX();
831 auto xWS = solutionHistory->getWorkingState()->getX();
832 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
833
834 // Test Modifier.
835 // Testing that each ACTION_LOCATION has been called.
836 TEST_COMPARE(modifier->testBEGIN_STEP, ==, true);
837 TEST_COMPARE(modifier->testBEGIN_STAGE, ==, true);
838 TEST_COMPARE(modifier->testBEFORE_SOLVE, ==, true);
839 TEST_COMPARE(modifier->testAFTER_SOLVE, ==, true);
840 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==, true);
841 TEST_COMPARE(modifier->testEND_STAGE, ==, true);
842 TEST_COMPARE(modifier->testEND_STEP, ==, true);
843
844 const double relTol = 1.0e-14;
845 // Testing that values can be set through the modifier.
846 TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(xCS), 0),relTol);
847 TEST_FLOATING_EQUALITY(modifier->testWorkingValue, get_ele(*(xWS), 0),relTol);
848 TEST_FLOATING_EQUALITY(modifier->testDt, Dt/10.0, relTol);
849
850 auto testName = testNameOrig + " - Modifier";
851 TEST_COMPARE(modifier->testName, ==, testName);
852
853
854 // Test Observer.
855 // Testing that each ACTION_LOCATION has been called.
856 TEST_COMPARE(observer->testBEGIN_STEP, ==, true);
857 TEST_COMPARE(observer->testBEGIN_STAGE, ==, true);
858 TEST_COMPARE(observer->testBEFORE_SOLVE, ==, true);
859 TEST_COMPARE(observer->testAFTER_SOLVE, ==, true);
860 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==, true);
861 TEST_COMPARE(observer->testEND_STAGE, ==, true);
862 TEST_COMPARE(observer->testEND_STEP, ==, true);
863
864 // Testing that values can be observed through the observer.
865 TEST_FLOATING_EQUALITY(observer->testCurrentValue, get_ele(*(xCS), 0),relTol);
866 TEST_FLOATING_EQUALITY(observer->testWorkingValue, get_ele(*(xWS), 0),relTol);
867 TEST_FLOATING_EQUALITY(observer->testDt, Dt/10.0, relTol);
868
869 testName = testNameOrig + " - Observer";
870 TEST_COMPARE(observer->testName, ==, testName);
871
872
873 // Test ModifierX.
874 // Testing that each ACTION_LOCATION has been called.
875 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==, true);
876 TEST_COMPARE(modifierX->testX_BEGIN_STAGE, ==, true);
877 TEST_COMPARE(modifierX->testX_BEFORE_SOLVE, ==, true);
878 TEST_COMPARE(modifierX->testX_AFTER_SOLVE, ==, true);
879 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==, true);
880 TEST_COMPARE(modifierX->testXDOT_END_STAGE, ==, true);
881 TEST_COMPARE(modifierX->testX_END_STEP, ==, true);
882
883 // Testing that values can be set through the modifierX.
884 TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(xCS), 0), relTol);
885 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, relTol);
886
887 auto time = solutionHistory->getWorkingState()->getTime();
888 TEST_FLOATING_EQUALITY(modifierX->testTime, time, relTol);
889
890 // Stage Number should be -1 outside stage loop.
891 TEST_COMPARE(stepper->getStageNumber(), ==, -1);
892 // The last stage number through X_BEFORE_EXPLICIT_EVAL should be
893 // the number of stages minus one.
894 TEST_COMPARE(modifierX->testStageNumber,==,stepper->getNumberOfStages()-1);
895
896 if (rcp_dynamic_cast<Tempus::StepperIMEX_RK<double>>(stepper) != Teuchos::null ||
897 rcp_dynamic_cast<Tempus::StepperIMEX_RK_Partition<double>>(stepper) != Teuchos::null) {
898 TEST_FLOATING_EQUALITY(modifierX->testStageX, 2.0, relTol);
899 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 2.0,relTol);
900 } else if (stepper->isImplicit()) {
901 // Stage values are overwritten and not available
902 // outside takeStep, so direct comparisons are needed.
903 if (rcp_dynamic_cast<Tempus::StepperDIRK_BackwardEuler<double>>(stepper) != Teuchos::null) {
904 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09900990099009901, relTol);
905 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09900990099009901, relTol);
906 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_2Stage2ndOrder<double>>(stepper) != Teuchos::null) {
907 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09979317463412091, relTol);
908 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09979317463412091, relTol);
909 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_3Stage2ndOrder<double>>(stepper) != Teuchos::null) {
910 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.049921670528461, relTol);
911 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.049921670528461, relTol);
912 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_2Stage3rdOrder<double>>(stepper) != Teuchos::null) {
913 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.02171123447937569, relTol);
914 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.02171123447937569, relTol);
915 } else if (rcp_dynamic_cast<Tempus::StepperEDIRK_2Stage3rdOrder<double>>(stepper) != Teuchos::null) {
916 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06659267480577136, relTol);
917 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06659267480577136, relTol);
918 } else if (rcp_dynamic_cast<Tempus::StepperDIRK_1StageTheta<double>>(stepper) != Teuchos::null) {
919 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
920 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
921 } else if (rcp_dynamic_cast<Tempus::StepperEDIRK_2StageTheta<double>>(stepper) != Teuchos::null) {
922 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
923 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
924 } else if (rcp_dynamic_cast<Tempus::StepperEDIRK_TrapezoidalRule<double>>(stepper) != Teuchos::null) {
925 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
926 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
927 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_ImplicitMidpoint<double>>(stepper) != Teuchos::null) {
928 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
929 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
930 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK22<double>>(stepper) != Teuchos::null) {
931 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0748907323303947, relTol);
932 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0748907323303947, relTol);
933 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK32<double>>(stepper) != Teuchos::null) {
934 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.08321767099874625, relTol);
935 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.08321767099874625, relTol);
936 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK23<double>>(stepper) != Teuchos::null) {
937 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.07878078755122744, relTol);
938 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.07878078755122744, relTol);
939 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_SSPDIRK33<double>>(stepper) != Teuchos::null) {
940 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.08525184184135257, relTol);
941 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.08525184184135257, relTol);
942 } else if (rcp_dynamic_cast<Tempus::StepperDIRK_1Stage1stOrderRadauIA<double>>(stepper) != Teuchos::null) {
943 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09900990099009901, relTol);
944 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09900990099009901, relTol);
945 } else if (rcp_dynamic_cast<Tempus::StepperDIRK_2Stage2ndOrderLobattoIIIB<double>>(stepper) != Teuchos::null) {
946 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
947 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
948 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_5Stage4thOrder<double>>(stepper) != Teuchos::null) {
949 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983340822548158, relTol);
950 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983340822548158, relTol);
951 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_3Stage4thOrder<double>>(stepper) != Teuchos::null) {
952 TEST_FLOATING_EQUALITY(modifierX->testStageX, -0.009988159068259408, relTol);
953 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, -0.009988159068259408, relTol);
954 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_5Stage5thOrder<double>>(stepper) != Teuchos::null) {
955 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06446224812649308, relTol);
956 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06446224812649308, relTol);
957 } else if (rcp_dynamic_cast<Tempus::StepperSDIRK_21Pair<double>>(stepper) != Teuchos::null) {
958 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.001960592098813843, relTol);
959 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.001960592098813843, relTol);
960 } else if (rcp_dynamic_cast<Tempus::StepperDIRK_General<double>>(stepper) != Teuchos::null) {
961 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09979317463412091, relTol);
962 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09979317463412091, relTol);
963 } else {
964 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
965 "Error - unknown stepperType = "+stepper->getStepperType());
966 }
967 } else {
968 // For explicit steppers, stageX is under written and not available
969 // outside takeStep, so direct comparisons are needed.
970 if (rcp_dynamic_cast<Tempus::StepperERK_3_8Rule<double>>(stepper) != Teuchos::null) {
971 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09966666666666668, relTol);
972 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09966666666666668, relTol);
973 } else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrder<double>>(stepper) != Teuchos::null) {
974 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, relTol);
975 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, relTol);
976 } else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrderHeun<double>>(stepper) != Teuchos::null) {
977 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06666666666666667, relTol);
978 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06666666666666667, relTol);
979 } else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrderTVD<double>>(stepper) != Teuchos::null) {
980 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, relTol);
981 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, relTol);
982 } else if (rcp_dynamic_cast<Tempus::StepperERK_4Stage3rdOrderRunge<double>>(stepper) != Teuchos::null) {
983 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0995, relTol);
984 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0995, relTol);
985 } else if (rcp_dynamic_cast<Tempus::StepperERK_4Stage4thOrder<double>>(stepper) != Teuchos::null) {
986 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975, relTol);
987 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975, relTol);
988 } else if (rcp_dynamic_cast<Tempus::StepperERK_5Stage3rdOrderKandG<double>>(stepper) != Teuchos::null) {
989 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06662222222222222, relTol);
990 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06662222222222222, relTol);
991 } else if (rcp_dynamic_cast<Tempus::StepperERK_BogackiShampine32<double>>(stepper) != Teuchos::null) {
992 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333333, relTol);
993 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333333, relTol);
994 } else if (rcp_dynamic_cast<Tempus::StepperERK_ForwardEuler<double>>(stepper) != Teuchos::null) {
995 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0, relTol);
996 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0, relTol);
997 } else if (rcp_dynamic_cast<Tempus::StepperERK_General<double>>(stepper) != Teuchos::null) {
998 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975, relTol);
999 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975, relTol);
1000 } else if (rcp_dynamic_cast<Tempus::StepperERK_Merson45<double>>(stepper) != Teuchos::null) {
1001 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333332, relTol);
1002 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333332, relTol);
1003 } else if (rcp_dynamic_cast<Tempus::StepperERK_Midpoint<double>>(stepper) != Teuchos::null) {
1004 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, relTol);
1005 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, relTol);
1006 } else if (rcp_dynamic_cast<Tempus::StepperERK_Trapezoidal<double>>(stepper) != Teuchos::null) {
1007 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, relTol);
1008 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, relTol);
1009 } else {
1010 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
1011 "Error - unknown stepperType = "+stepper->getStepperType());
1012 }
1013 }
1014 }
1015}
1016
1017
1018} // namespace Tempus_Test
1019#endif // Tempus_UnitTest_RK_Utils_hpp
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Backward Euler Runge-Kutta Butcher Tableau.
General Implicit Runge-Kutta Butcher Tableau.
Diagonally Implicit Runge-Kutta (DIRK) time stepper.
RK Trapezoidal Rule (A.K.A. RK Crank-Nicolson)
Explicit RK 3/8th Rule Butcher Tableau.
Runge-Kutta 4th order Butcher Tableau.
RK Explicit 5 Stage 3rd order by Kinnmark and Gray.
Explicit RK Bogacki-Shampine Butcher Tableau.
Forward Euler Runge-Kutta Butcher Tableau.
General Explicit Runge-Kutta Butcher Tableau.
Explicit RK Merson Butcher Tableau.
Explicit Runge-Kutta time stepper.
Partitioned Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
This composite AppAction loops over added AppActions.
ACTION_LOCATION
Indicates the location of application action (see algorithm).
Base class for Runge-Kutta methods, ExplicitRK, DIRK and IMEX.
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
Unit test class for RK Stepper Modifier AppAction.
virtual void modify(Teuchos::RCP< Tempus::SolutionHistory< double > > sh, Teuchos::RCP< Tempus::StepperRKBase< double > > stepper, const typename Tempus::StepperRKAppAction< double >::ACTION_LOCATION actLoc)
Modify RK Stepper at action location.
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.
Unit test class for RK Stepper Observer AppAction.
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.
void testDIRKAccessorsFullConstruction(const RCP< Tempus::StepperDIRK< double > > &stepper)
Unit test utility for ExplicitRK Stepper construction and accessors.
void testExplicitRKAccessorsFullConstruction(const RCP< Tempus::StepperExplicitRK< double > > &stepper)
Unit test utility for ExplicitRK Stepper construction and accessors.
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.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Nonmember contructor from a Thyra ModelEvaluator.
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.