9 #ifndef Tempus_UnitTest_Utils_hpp
10 #define Tempus_UnitTest_Utils_hpp
13 #include "Tempus_SolutionHistory.hpp"
22 #include "../TestModels/SinCosModel.hpp"
23 #include "../TestModels/VanDerPolModel.hpp"
25 namespace Tempus_Unit_Test {
29 using Teuchos::rcp_const_cast;
30 using Teuchos::rcp_dynamic_cast;
31 using Teuchos::ParameterList;
38 const Teuchos::RCP<
const Thyra::ModelEvaluator<double> >& model)
44 auto stepper = sf->createStepper(stepperType, model);
45 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
47 stepper = sf->createStepper(stepperType);
48 stepper->setModel(model);
49 stepper->initialize();
50 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
54 auto stepperPL = rcp_const_cast<ParameterList>(stepper->getValidParameters());
55 stepper = sf->createStepper(stepperPL, model);
56 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
58 stepper = sf->createStepper(stepperPL);
59 stepper->setModel(model);
60 stepper->initialize();
61 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
71 stepper->setModel(model);
72 stepper->initialize();
73 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
79 bool useFSAL = stepper->getUseFSALDefault();
80 std::string ICConsistency = stepper->getICConsistencyDefault();
81 bool ICConsistencyCheck = stepper->getICConsistencyCheckDefault();
82 bool useEmbedded = stepper->getUseEmbeddedDefault();
85 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
87 stepper->setObserver(obs); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
89 stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
90 stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
91 stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
92 stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
93 stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
94 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
95 stepper->setUseEmbedded(useEmbedded); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
98 std::string stepperType = stepper->getStepperType();
100 if (stepperType ==
"RK Explicit 3 Stage 3rd order") {
101 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
103 model, obs, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded));
104 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
107 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
108 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
109 }
else if (stepperType ==
"RK Explicit 3 Stage 3rd order by Heun") {
110 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
112 model, obs, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded));
113 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
116 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
117 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
118 }
else if (stepperType ==
"RK Explicit 3 Stage 3rd order TVD") {
119 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
121 model, obs, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded));
122 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
125 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
126 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
127 }
else if (stepperType ==
"RK Explicit 3/8 Rule") {
128 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
130 model, obs, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded));
131 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
134 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
135 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
136 }
else if (stepperType ==
"RK Explicit 4 Stage 3rd order by Runge") {
137 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
139 model, obs, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded));
140 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
143 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
144 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
145 }
else if (stepperType ==
"RK Explicit 4 Stage") {
146 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
148 model, obs, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded));
149 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
152 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
153 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
154 }
else if (stepperType ==
"RK Explicit 5 Stage 3rd order by Kinnmark and Gray") {
155 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
157 model, obs, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded));
158 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
161 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
162 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
163 }
else if (stepperType ==
"Bogacki-Shampine 3(2) Pair") {
164 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
166 model, obs, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded));
167 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
170 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
171 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
172 }
else if (stepperType ==
"RK Forward Euler") {
173 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
175 model, obs, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded));
176 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
179 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
180 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
181 }
else if (stepperType ==
"Merson 4(5) Pair") {
182 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
184 model, obs, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded));
185 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
188 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
189 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
190 }
else if (stepperType ==
"RK Explicit Midpoint") {
191 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
193 model, obs, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded));
194 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
197 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
198 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
199 }
else if (stepperType ==
"RK Explicit Trapezoidal") {
200 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
202 model, obs, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded));
203 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
206 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
207 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
209 else TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Error - unknown stepperType = "+stepperType);
219 stepper->setModel(model);
220 stepper->initialize();
221 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
227 auto solver = rcp(
new Thyra::NOXNonlinearSolver());
230 bool useFSAL = stepper->getUseFSALDefault();
231 std::string ICConsistency = stepper->getICConsistencyDefault();
232 bool ICConsistencyCheck = stepper->getICConsistencyCheckDefault();
233 bool useEmbedded = stepper->getUseEmbeddedDefault();
234 bool zeroInitialGuess = stepper->getZeroInitialGuess();
237 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
239 stepper->setObserver(obs); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
241 stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
242 stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
243 stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
244 stepper->setSolver(solver); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
245 stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
246 stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
247 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
248 stepper->setUseEmbedded(useEmbedded); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
249 stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
252 std::string stepperType = stepper->getStepperType();
254 if (stepperType ==
"RK Backward Euler") {
255 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
257 model, obs, solver, useFSAL,
258 ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess));
259 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
262 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
263 useEmbedded, zeroInitialGuess, modifier));
264 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
265 }
else if (stepperType ==
"SDIRK 2 Stage 2nd order") {
266 double gamma = 0.2928932188134524;
267 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
269 model, obs, solver, useFSAL, ICConsistency, ICConsistencyCheck,
270 useEmbedded, zeroInitialGuess, gamma));
271 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
274 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
275 useEmbedded, zeroInitialGuess, modifier, gamma));
276 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
277 }
else if (stepperType ==
"SDIRK 3 Stage 2nd order") {
278 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
280 model, obs, solver, useFSAL,
281 ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess));
282 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
285 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
286 useEmbedded, zeroInitialGuess, modifier));
287 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
288 }
else if (stepperType ==
"SDIRK 2 Stage 3rd order") {
289 std::string gammaType =
"3rd Order A-stable";
290 double gamma = 0.7886751345948128;
291 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
293 model, obs, solver, useFSAL, ICConsistency, ICConsistencyCheck,
294 useEmbedded, zeroInitialGuess, gammaType, gamma));
295 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
298 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
299 useEmbedded, zeroInitialGuess, modifier, gammaType, gamma));
300 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
301 }
else if (stepperType ==
"EDIRK 2 Stage 3rd order") {
302 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
304 model, obs, solver, useFSAL,
305 ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess));
306 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
309 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
310 useEmbedded, zeroInitialGuess, modifier));
311 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
312 }
else if (stepperType ==
"DIRK 1 Stage Theta Method") {
314 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
316 model, obs, solver, useFSAL, ICConsistency, ICConsistencyCheck,
317 useEmbedded, zeroInitialGuess), theta);
318 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
321 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
322 useEmbedded, zeroInitialGuess, modifier, theta));
323 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
324 }
else if (stepperType ==
"EDIRK 2 Stage Theta Method") {
326 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
328 model, obs, solver, useFSAL, ICConsistency, ICConsistencyCheck,
329 useEmbedded, zeroInitialGuess, theta));
330 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
333 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
334 useEmbedded, zeroInitialGuess, modifier, theta));
335 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
338 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
339 }
else if (stepperType ==
"RK Trapezoidal Rule") {
340 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
342 model, obs, solver, useFSAL,
343 ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess));
344 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
347 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
348 useEmbedded, zeroInitialGuess, modifier));
349 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
350 }
else if (stepperType ==
"RK Implicit Midpoint") {
351 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
353 model, obs, solver, useFSAL,
354 ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess));
355 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
358 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
359 useEmbedded, zeroInitialGuess, modifier));
360 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
361 }
else if (stepperType ==
"SSPDIRK22") {
362 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
364 model, obs, solver, useFSAL,
365 ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess));
366 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
369 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
370 useEmbedded, zeroInitialGuess, modifier));
371 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
372 }
else if (stepperType ==
"SSPDIRK32") {
373 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
375 model, obs, solver, useFSAL,
376 ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess));
377 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
380 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
381 useEmbedded, zeroInitialGuess, modifier));
382 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
383 }
else if (stepperType ==
"SSPDIRK23") {
384 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
386 model, obs, solver, useFSAL,
387 ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess));
388 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
391 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
392 useEmbedded, zeroInitialGuess, modifier));
393 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
394 }
else if (stepperType ==
"SSPDIRK33") {
395 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
397 model, obs, solver, useFSAL,
398 ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess));
399 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
402 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
403 useEmbedded, zeroInitialGuess, modifier));
404 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
405 }
else if (stepperType ==
"RK Implicit 1 Stage 1st order Radau IA") {
406 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
408 model, obs, solver, useFSAL,
409 ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess));
410 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
413 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
414 useEmbedded, zeroInitialGuess, modifier));
415 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
416 }
else if (stepperType ==
"RK Implicit 2 Stage 2nd order Lobatto IIIB") {
417 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
419 model, obs, solver, useFSAL,
420 ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess));
421 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
424 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
425 useEmbedded, zeroInitialGuess, modifier));
426 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
427 }
else if (stepperType ==
"SDIRK 5 Stage 4th order") {
428 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
430 model, obs, solver, useFSAL,
431 ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess));
432 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
435 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
436 useEmbedded, zeroInitialGuess, modifier));
437 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
438 }
else if (stepperType ==
"SDIRK 3 Stage 4th order") {
439 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
441 model, obs, solver, useFSAL,
442 ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess));
443 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
446 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
447 useEmbedded, zeroInitialGuess, modifier));
448 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
449 }
else if (stepperType ==
"SDIRK 5 Stage 5th order") {
450 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
452 model, obs, solver, useFSAL,
453 ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess));
454 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
457 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
458 useEmbedded, zeroInitialGuess, modifier));
459 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
460 }
else if (stepperType ==
"SDIRK 2(1) Pair") {
461 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
463 model, obs, solver, useFSAL,
464 ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess));
465 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
468 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
469 useEmbedded, zeroInitialGuess, modifier));
470 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
471 }
else TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Error - unknown stepperType = "+stepperType);
511 auto x = sh->getCurrentState()->getX();
513 testType = stepper->getStepperType() +
" - Modifier";
525 testDt = sh->getWorkingState()->getTimeStep()/10.0;
546 auto x = sh->getWorkingState()->getX();
551 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
552 "Error - unknown action location.\n");
605 auto x = sh->getCurrentState()->getX();
617 testDt = sh->getWorkingState()->getTimeStep()/10.0;
623 testType = stepper->getStepperType() +
" - Observer";
639 auto x = sh->getWorkingState()->getX();
644 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
645 "Error - unknown action location.\n");
690 Teuchos::RCP<Thyra::VectorBase<double> > x,
691 const double time,
const double dt,
692 const int stageNumber,
699 testX = get_ele(*(x), 0);
738 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
739 "Error - unknown action location.\n");
763 const Teuchos::RCP<
const Thyra::ModelEvaluator<double> >& model,
764 Teuchos::FancyOStream &out,
bool &success)
766 auto testTypeOrig = stepper->getStepperType();
770 stepper->setModel(model);
772 stepper->setAppAction(modifier);
773 stepper->initialize();
774 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
775 auto testType = testTypeOrig +
" - Modifier";
781 stepper->setInitialConditions(solutionHistory);
782 solutionHistory->initWorkingState();
784 solutionHistory->getWorkingState()->setTimeStep(dt);
785 stepper->takeStep(solutionHistory);
788 TEST_COMPARE(modifier->testBEGIN_STEP, ==,
true);
789 TEST_COMPARE(modifier->testBEGIN_STAGE, ==,
true);
790 TEST_COMPARE(modifier->testBEFORE_SOLVE, ==,
true);
791 TEST_COMPARE(modifier->testAFTER_SOLVE, ==,
true);
792 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
793 TEST_COMPARE(modifier->testEND_STAGE, ==,
true);
794 TEST_COMPARE(modifier->testEND_STEP, ==,
true);
797 auto x = solutionHistory->getCurrentState()->getX();
798 TEST_FLOATING_EQUALITY(modifier->testCurrentValue,get_ele(*(x), 0),1.0e-15);
799 x = solutionHistory->getWorkingState()->getX();
800 TEST_FLOATING_EQUALITY(modifier->testWorkingValue,get_ele(*(x), 0),1.0e-15);
801 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
802 TEST_FLOATING_EQUALITY(modifier->testDt, Dt/10.0, 1.0e-15);
804 TEST_COMPARE(modifier->testType, ==, testType);
809 stepper->setModel(model);
811 stepper->setAppAction(observer);
812 stepper->setStepperType(testTypeOrig);
813 stepper->initialize();
814 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
820 stepper->setInitialConditions(solutionHistory);
821 solutionHistory->initWorkingState();
823 solutionHistory->getWorkingState()->setTimeStep(dt);
824 stepper->takeStep(solutionHistory);
827 TEST_COMPARE(observer->testBEGIN_STEP, ==,
true);
828 TEST_COMPARE(observer->testBEGIN_STAGE, ==,
true);
829 TEST_COMPARE(observer->testBEFORE_SOLVE, ==,
true);
830 TEST_COMPARE(observer->testAFTER_SOLVE, ==,
true);
831 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
832 TEST_COMPARE(observer->testEND_STAGE, ==,
true);
833 TEST_COMPARE(observer->testEND_STEP, ==,
true);
836 auto x = solutionHistory->getCurrentState()->getX();
837 TEST_FLOATING_EQUALITY(observer->testCurrentValue,get_ele(*(x), 0),1.0e-15);
838 x = solutionHistory->getWorkingState()->getX();
839 TEST_FLOATING_EQUALITY(observer->testWorkingValue,get_ele(*(x), 0),1.0e-15);
840 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
841 TEST_FLOATING_EQUALITY(observer->testDt, Dt/10.0, 1.0e-15);
843 auto testType = testTypeOrig +
" - Observer";
844 TEST_COMPARE(observer->testType, ==, testType);
849 stepper->setModel(model);
851 stepper->setAppAction(modifierX);
852 stepper->setStepperType(testTypeOrig);
853 stepper->initialize();
854 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
860 stepper->setInitialConditions(solutionHistory);
861 solutionHistory->initWorkingState();
863 solutionHistory->getWorkingState()->setTimeStep(dt);
864 stepper->takeStep(solutionHistory);
867 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==,
true);
868 TEST_COMPARE(modifierX->testX_BEGIN_STAGE, ==,
true);
869 TEST_COMPARE(modifierX->testX_BEFORE_SOLVE, ==,
true);
870 TEST_COMPARE(modifierX->testX_AFTER_SOLVE, ==,
true);
871 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
872 TEST_COMPARE(modifierX->testXDOT_END_STAGE, ==,
true);
873 TEST_COMPARE(modifierX->testX_END_STEP, ==,
true);
876 auto x = solutionHistory->getCurrentState()->getX();
877 TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(x), 0), 1.0e-15);
878 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
879 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, 1.0e-15);
881 auto time = solutionHistory->getWorkingState()->getTime();
882 TEST_FLOATING_EQUALITY(modifierX->testTime, time, 1.0e-15);
885 TEST_COMPARE(stepper->getStageNumber(), ==, -1);
888 TEST_COMPARE(modifierX->testStageNumber,==,stepper->getNumberOfStages()-1);
892 TEST_FLOATING_EQUALITY(modifierX->testStageX, 2.0, 1.0e-15);
893 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 2.0,1.0e-15);
894 }
else if (stepper->isImplicit()) {
896 auto stageX = stepper->getStageX();
897 TEST_FLOATING_EQUALITY(modifierX->testStageX, get_ele(*(stageX), 0),1.0e-15);
898 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, get_ele(*(stageX), 0),1.0e-15);
903 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09966666666666668, 1.0e-15);
904 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09966666666666668, 1.0e-15);
906 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, 1.0e-15);
907 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, 1.0e-15);
909 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06666666666666667, 1.0e-15);
910 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06666666666666667, 1.0e-15);
912 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, 1.0e-15);
913 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, 1.0e-15);
915 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09950000000000001, 1.0e-15);
916 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09950000000000001, 1.0e-15);
918 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975000000000001, 1.0e-15);
919 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975000000000001, 1.0e-15);
921 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06662222222222222, 1.0e-15);
922 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06662222222222222, 1.0e-15);
924 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333333, 1.0e-15);
925 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333333, 1.0e-15);
927 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0, 1.0e-15);
928 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0, 1.0e-15);
930 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975000000000001, 1.0e-15);
931 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975000000000001, 1.0e-15);
933 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333332, 1.0e-15);
934 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333332, 1.0e-15);
936 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, 1.0e-15);
937 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, 1.0e-15);
939 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, 1.0e-15);
940 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, 1.0e-15);
942 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
943 "Error - unknown stepperType = "+stepper->getStepperType());
951 stepper->setModel(model);
958 composite->addRKAppAction(modifier);
959 composite->addRKAppAction(observer);
960 composite->addRKAppAction(modifierX);
961 stepper->setAppAction(composite);
963 stepper->initialize();
964 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
970 stepper->setInitialConditions(solutionHistory);
971 solutionHistory->initWorkingState();
973 solutionHistory->getWorkingState()->setTimeStep(dt);
974 stepper->takeStep(solutionHistory);
976 auto xCS = solutionHistory->getCurrentState()->getX();
977 auto xWS = solutionHistory->getWorkingState()->getX();
978 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
982 TEST_COMPARE(modifier->testBEGIN_STEP, ==,
true);
983 TEST_COMPARE(modifier->testBEGIN_STAGE, ==,
true);
984 TEST_COMPARE(modifier->testBEFORE_SOLVE, ==,
true);
985 TEST_COMPARE(modifier->testAFTER_SOLVE, ==,
true);
986 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
987 TEST_COMPARE(modifier->testEND_STAGE, ==,
true);
988 TEST_COMPARE(modifier->testEND_STEP, ==,
true);
991 TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(xCS), 0),1.0e-15);
992 TEST_FLOATING_EQUALITY(modifier->testWorkingValue, get_ele(*(xWS), 0),1.0e-15);
993 TEST_FLOATING_EQUALITY(modifier->testDt, Dt/10.0, 1.0e-15);
995 auto testType = testTypeOrig +
" - Modifier";
996 TEST_COMPARE(modifier->testType, ==, testType);
1001 TEST_COMPARE(observer->testBEGIN_STEP, ==,
true);
1002 TEST_COMPARE(observer->testBEGIN_STAGE, ==,
true);
1003 TEST_COMPARE(observer->testBEFORE_SOLVE, ==,
true);
1004 TEST_COMPARE(observer->testAFTER_SOLVE, ==,
true);
1005 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
1006 TEST_COMPARE(observer->testEND_STAGE, ==,
true);
1007 TEST_COMPARE(observer->testEND_STEP, ==,
true);
1010 TEST_FLOATING_EQUALITY(observer->testCurrentValue, get_ele(*(xCS), 0),1.0e-15);
1011 TEST_FLOATING_EQUALITY(observer->testWorkingValue, get_ele(*(xWS), 0),1.0e-15);
1012 TEST_FLOATING_EQUALITY(observer->testDt, Dt/10.0, 1.0e-15);
1014 testType = testType +
" - Observer";
1015 TEST_COMPARE(observer->testType, ==, testType);
1020 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==,
true);
1021 TEST_COMPARE(modifierX->testX_BEGIN_STAGE, ==,
true);
1022 TEST_COMPARE(modifierX->testX_BEFORE_SOLVE, ==,
true);
1023 TEST_COMPARE(modifierX->testX_AFTER_SOLVE, ==,
true);
1024 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
1025 TEST_COMPARE(modifierX->testXDOT_END_STAGE, ==,
true);
1026 TEST_COMPARE(modifierX->testX_END_STEP, ==,
true);
1029 TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(xCS), 0), 1.0e-15);
1030 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, 1.0e-15);
1032 auto time = solutionHistory->getWorkingState()->getTime();
1033 TEST_FLOATING_EQUALITY(modifierX->testTime, time, 1.0e-15);
1036 TEST_COMPARE(stepper->getStageNumber(), ==, -1);
1039 TEST_COMPARE(modifierX->testStageNumber,==,stepper->getNumberOfStages()-1);
1043 TEST_FLOATING_EQUALITY(modifierX->testStageX, 2.0, 1.0e-15);
1044 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 2.0,1.0e-15);
1045 }
else if (stepper->isImplicit()) {
1047 auto stageX = stepper->getStageX();
1048 TEST_FLOATING_EQUALITY(modifierX->testStageX, get_ele(*(stageX), 0),1.0e-15);
1049 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, get_ele(*(stageX), 0),1.0e-15);
1054 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09966666666666668, 1.0e-15);
1055 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09966666666666668, 1.0e-15);
1057 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, 1.0e-15);
1058 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, 1.0e-15);
1060 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06666666666666667, 1.0e-15);
1061 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06666666666666667, 1.0e-15);
1063 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, 1.0e-15);
1064 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, 1.0e-15);
1066 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09950000000000001, 1.0e-15);
1067 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09950000000000001, 1.0e-15);
1069 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975000000000001, 1.0e-15);
1070 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975000000000001, 1.0e-15);
1072 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06662222222222222, 1.0e-15);
1073 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06662222222222222, 1.0e-15);
1075 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333333, 1.0e-15);
1076 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333333, 1.0e-15);
1078 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0, 1.0e-15);
1079 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0, 1.0e-15);
1081 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975000000000001, 1.0e-15);
1082 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975000000000001, 1.0e-15);
1084 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333332, 1.0e-15);
1085 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333332, 1.0e-15);
1087 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, 1.0e-15);
1088 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, 1.0e-15);
1090 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, 1.0e-15);
1091 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, 1.0e-15);
1093 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
1094 "Error - unknown stepperType = "+stepper->getStepperType());
1102 #endif // Tempus_UnitTest_Utils_hpp
At the beginning of the stage.
At the beginning of the step.
Unit test class for RK Stepper Observer AppAction.
RK Implicit 2 Stage 2nd order Lobatto IIIB.
void testRKAppAction(const Teuchos::RCP< Tempus::StepperRKBase< double > > &stepper, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model, Teuchos::FancyOStream &out, bool &success)
Unit test utility for Stepper RK AppAction.
Default observer for StepperRK.
virtual void modify(Teuchos::RCP< Tempus::SolutionHistory< double > > sh, Teuchos::RCP< Tempus::StepperRKBase< double > > stepper, const typename Tempus::StepperRKAppAction< double >::ACTION_LOCATION actLoc)
Modify RK Stepper at action location.
void testExplicitRKAccessorsFullConstruction(const RCP< Tempus::StepperExplicitRK< double > > &stepper)
Unit test utility for ExplicitRK Stepper construction and accessors.
Explicit Runge-Kutta time stepper.
Modify at the end of the step.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
Base observer for StepperRK.
Modify after the implicit solve.
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
Backward Euler Runge-Kutta Butcher Tableau.
Base ModifierX for StepperRK.
General Explicit Runge-Kutta Butcher Tableau.
Modify at the beginning of the stage.
RK Explicit 5 Stage 3rd order by Kinnmark and Gray.
Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
RK Explicit 4 Stage 3rd order by Runge.
Unit test class for RK Stepper Modifier AppAction.
Before the implicit solve.
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
virtual void observe(Teuchos::RCP< const Tempus::SolutionHistory< double > > sh, Teuchos::RCP< const Tempus::StepperRKBase< double > > stepper, const typename Tempus::StepperRKAppAction< double >::ACTION_LOCATION actLoc)
Observe RK Stepper at action location.
RK Trapezoidal Rule (A.K.A. RK Crank-Nicolson)
Partitioned Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
This composite AppAction loops over added AppActions.
bool testBEFORE_EXPLICIT_EVAL
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Nonmember contructor from a Thyra ModelEvaluator.
Modify before the implicit solve.
bool testBEFORE_EXPLICIT_EVAL
Base class for Runge-Kutta methods, ExplicitRK, DIRK and IMEX.
Explicit RK 3/8th Rule Butcher Tableau.
Diagonally Implicit Runge-Kutta (DIRK) time stepper.
Modify at the beginning of the step.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
Explicit RK Bogacki-Shampine Butcher Tableau.
StepperRKModifierTest()
Constructor.
virtual ~StepperRKObserverTest()
Destructor.
EDIRK 2 Stage Theta Method.
StepperRKModifierXTest()
Constructor.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > > x, const double time, const double dt, const int stageNumber, const typename Tempus::StepperRKModifierXBase< double >::MODIFIER_TYPE modType)
Observe RK Stepper at end of takeStep.
Modify at the end of the stage.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
Modify before the explicit evaluation.
ACTION_LOCATION
Indicates the location of application action (see algorithm).
Default ModifierX for StepperRK.
RK Explicit 3 Stage 3rd order TVD.
void testDIRKAccessorsFullConstruction(const RCP< Tempus::StepperDIRK< double > > &stepper)
Unit test utility for ExplicitRK Stepper construction and accessors.
After the implicit solve.
Before the explicit evaluation.
Default modifier for StepperRK.
Forward Euler Runge-Kutta Butcher Tableau.
virtual ~StepperRKModifierXTest()
Destructor.
Explicit RK Merson Butcher Tableau.
Runge-Kutta 4th order Butcher Tableau.
This observer is a composite observer,.
RK Explicit 3 Stage 3rd order.
RK Implicit 1 Stage 1st order Radau IA.
bool testX_BEFORE_EXPLICIT_EVAL
virtual ~StepperRKModifierTest()
Destructor.
Base modifier for StepperRK.
RK Explicit 3 Stage 3rd order by Heun.
StepperRKObserverTest()
Constructor.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.