Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_UnitTest_Utils.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ****************************************************************************
3 // Tempus: Copyright (2017) Sandia Corporation
4 //
5 // Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
6 // ****************************************************************************
7 // @HEADER
8 
9 #ifndef Tempus_UnitTest_Utils_hpp
10 #define Tempus_UnitTest_Utils_hpp
11 
13 #include "Tempus_SolutionHistory.hpp"
21 
22 #include "../TestModels/SinCosModel.hpp"
23 #include "../TestModels/VanDerPolModel.hpp"
24 
25 namespace Tempus_Unit_Test {
26 
27 using Teuchos::RCP;
28 using Teuchos::rcp;
29 using Teuchos::rcp_const_cast;
30 using Teuchos::rcp_dynamic_cast;
31 using Teuchos::ParameterList;
32 
34 
35 /** \brief Unit test utility for Stepper construction through StepperFactory.
36  */
37 void testFactoryConstruction(std::string stepperType,
38  const Teuchos::RCP<const Thyra::ModelEvaluator<double> >& model)
39 {
40  RCP<StepperFactory<double> > sf = Teuchos::rcp(new StepperFactory<double>());
41 
42  // Test using stepperType
43  // Passing in model.
44  auto stepper = sf->createStepper(stepperType, model);
45  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
46  // With setting model.
47  stepper = sf->createStepper(stepperType);
48  stepper->setModel(model);
49  stepper->initialize();
50  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
51 
52  // Test using ParameterList.
53  // Passing in model.
54  auto stepperPL = rcp_const_cast<ParameterList>(stepper->getValidParameters());
55  stepper = sf->createStepper(stepperPL, model);
56  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
57  // With setting model.
58  stepper = sf->createStepper(stepperPL);
59  stepper->setModel(model);
60  stepper->initialize();
61  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
62 }
63 
64 
65 /** \brief Unit test utility for ExplicitRK Stepper construction and accessors.
66  */
68  const RCP<Tempus::StepperExplicitRK<double> >& stepper)
69 {
70  auto model = rcp(new Tempus_Test::SinCosModel<double>());
71  stepper->setModel(model);
72  stepper->initialize();
73  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
74 
75  // Default values for construction.
76  auto modifier = rcp(new Tempus::StepperRKModifierDefault<double>());
77  auto modifierX = rcp(new Tempus::StepperRKModifierXDefault<double>());
78  auto observer = rcp(new Tempus::StepperRKObserverDefault<double>());
79  bool useFSAL = stepper->getUseFSALDefault();
80  std::string ICConsistency = stepper->getICConsistencyDefault();
81  bool ICConsistencyCheck = stepper->getICConsistencyCheckDefault();
82  bool useEmbedded = stepper->getUseEmbeddedDefault();
83 
84  // Test the set functions.
85 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
86  auto obs = rcp(new Tempus::StepperRKObserverComposite<double>());
87  stepper->setObserver(obs); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
88 #endif
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());
96 
97 
98  std::string stepperType = stepper->getStepperType();
99  // Full argument list construction.
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()); }
105 #endif
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()); }
114 #endif
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()); }
123 #endif
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
129  { auto s = rcp(new Tempus::StepperERK_3_8Rule<double>(
130  model, obs, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded));
131  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
132 #endif
133  auto s = rcp(new Tempus::StepperERK_3_8Rule<double>(
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()); }
141 #endif
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()); }
150 #endif
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()); }
159 #endif
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()); }
168 #endif
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
174  { auto s = rcp(new Tempus::StepperERK_ForwardEuler<double>(
175  model, obs, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded));
176  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
177 #endif
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
183  { auto s = rcp(new Tempus::StepperERK_Merson45<double>(
184  model, obs, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded));
185  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
186 #endif
187  auto s = rcp(new Tempus::StepperERK_Merson45<double>(
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
192  { auto s = rcp(new Tempus::StepperERK_Midpoint<double>(
193  model, obs, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded));
194  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
195 #endif
196  auto s = rcp(new Tempus::StepperERK_Midpoint<double>(
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
201  { auto s = rcp(new Tempus::StepperERK_Trapezoidal<double>(
202  model, obs, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded));
203  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
204 #endif
206  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
207  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
208  }
209  else TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Error - unknown stepperType = "+stepperType);
210 }
211 
212 
213 /** \brief Unit test utility for ExplicitRK Stepper construction and accessors.
214  */
216  const RCP<Tempus::StepperDIRK<double> >& stepper)
217 {
218  auto model = rcp(new Tempus_Test::SinCosModel<double>());
219  stepper->setModel(model);
220  stepper->initialize();
221  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
222 
223  // Default values for construction.
224  auto modifier = rcp(new Tempus::StepperRKModifierDefault<double>());
225  auto modifierX = rcp(new Tempus::StepperRKModifierXDefault<double>());
226  auto observer = rcp(new Tempus::StepperRKObserverDefault<double>());
227  auto solver = rcp(new Thyra::NOXNonlinearSolver());
228  solver->setParameterList(Tempus::defaultSolverParameters());
229 
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();
235 
236  // Test the set functions.
237 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
238  auto obs = rcp(new Tempus::StepperRKObserverComposite<double>());
239  stepper->setObserver(obs); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
240 #endif
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());
250 
251 
252  std::string stepperType = stepper->getStepperType();
253  // Full argument list construction.
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()); }
260 #endif
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()); }
272 #endif
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()); }
283 #endif
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()); }
296 #endif
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()); }
307 #endif
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") {
313  double theta = 0.5;
314 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
315  { auto s = rcp(new Tempus::StepperDIRK_1StageTheta<double>(
316  model, obs, solver, useFSAL, ICConsistency, ICConsistencyCheck,
317  useEmbedded, zeroInitialGuess), theta);
318  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
319 #endif
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") {
325  double theta = 0.5;
326 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
327  { auto s = rcp(new Tempus::StepperEDIRK_2StageTheta<double>(
328  model, obs, solver, useFSAL, ICConsistency, ICConsistencyCheck,
329  useEmbedded, zeroInitialGuess, theta));
330  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
331 #endif
333  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
334  useEmbedded, zeroInitialGuess, modifier, theta));
335  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
336  s->setTheta(theta);
337  s->initialize();
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()); }
345 #endif
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()); }
356 #endif
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
363  { auto s = rcp(new Tempus::StepperSDIRK_SSPDIRK22<double>(
364  model, obs, solver, useFSAL,
365  ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess));
366  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
367 #endif
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
374  { auto s = rcp(new Tempus::StepperSDIRK_SSPDIRK32<double>(
375  model, obs, solver, useFSAL,
376  ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess));
377  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
378 #endif
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
385  { auto s = rcp(new Tempus::StepperSDIRK_SSPDIRK23<double>(
386  model, obs, solver, useFSAL,
387  ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess));
388  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
389 #endif
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
396  { auto s = rcp(new Tempus::StepperSDIRK_SSPDIRK33<double>(
397  model, obs, solver, useFSAL,
398  ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess));
399  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
400 #endif
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()); }
411 #endif
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()); }
422 #endif
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()); }
433 #endif
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()); }
444 #endif
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()); }
455 #endif
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
462  { auto s = rcp(new Tempus::StepperSDIRK_21Pair<double>(
463  model, obs, solver, useFSAL,
464  ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess));
465  TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized()); }
466 #endif
467  auto s = rcp(new Tempus::StepperSDIRK_21Pair<double>(
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);
472 
473 }
474 
475 
476 /** \brief Unit test class for RK Stepper Modifier AppAction.
477  */
479  : virtual public Tempus::StepperRKModifierBase<double>
480 {
481 public:
482 
483  /// Constructor
485  : testBEGIN_STEP(false),
486  testBEGIN_STAGE(false),
487  testBEFORE_SOLVE(false),
488  testAFTER_SOLVE(false),
490  testEND_STAGE(false),
491  testEND_STEP(false),
492  testCurrentValue(-0.99),
493  testWorkingValue(-0.99),
494  testDt(-1.5),
495  testType("")
496  {}
497 
498  /// Destructor
500 
501  /// Modify RK Stepper at action location.
502  virtual void modify(
503  Teuchos::RCP<Tempus::SolutionHistory<double> > sh,
504  Teuchos::RCP<Tempus::StepperRKBase<double> > stepper,
506  {
507  switch(actLoc) {
509  {
510  testBEGIN_STEP = true;
511  auto x = sh->getCurrentState()->getX();
512  testCurrentValue = get_ele(*(x), 0);
513  testType = stepper->getStepperType() + " - Modifier";
514  stepper->setStepperType(testType);
515  break;
516  }
518  {
519  testBEGIN_STAGE = true;
520  break;
521  }
523  {
524  testBEFORE_SOLVE = true;
525  testDt = sh->getWorkingState()->getTimeStep()/10.0;
526  break;
527  }
529  {
530  testAFTER_SOLVE = true;
531  break;
532  }
534  {
536  break;
537  }
539  {
540  testEND_STAGE = true;
541  break;
542  }
544  {
545  testEND_STEP = true;
546  auto x = sh->getWorkingState()->getX();
547  testWorkingValue = get_ele(*(x), 0);
548  break;
549  }
550  default:
551  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
552  "Error - unknown action location.\n");
553  }
554  }
555 
565  double testDt;
566  std::string testType;
567 };
568 
569 
570 /** \brief Unit test class for RK Stepper Observer AppAction.
571  */
573  : virtual public Tempus::StepperRKObserverBase<double>
574 {
575 public:
576 
577  /// Constructor
579  : testBEGIN_STEP(false),
580  testBEGIN_STAGE(false),
581  testBEFORE_SOLVE(false),
582  testAFTER_SOLVE(false),
584  testEND_STAGE(false),
585  testEND_STEP(false),
586  testCurrentValue(-0.99),
587  testWorkingValue(-0.99),
588  testDt(-1.5),
589  testType("")
590  {}
591 
592  /// Destructor
594 
595  /// Observe RK Stepper at action location.
596  virtual void observe(
597  Teuchos::RCP<const Tempus::SolutionHistory<double> > sh,
598  Teuchos::RCP<const Tempus::StepperRKBase<double> > stepper,
600  {
601  switch(actLoc) {
603  {
604  testBEGIN_STEP = true;
605  auto x = sh->getCurrentState()->getX();
606  testCurrentValue = get_ele(*(x), 0);
607  break;
608  }
610  {
611  testBEGIN_STAGE = true;
612  break;
613  }
615  {
616  testBEFORE_SOLVE = true;
617  testDt = sh->getWorkingState()->getTimeStep()/10.0;
618  break;
619  }
621  {
622  testAFTER_SOLVE = true;
623  testType = stepper->getStepperType() + " - Observer";
624  break;
625  }
627  {
629  break;
630  }
632  {
633  testEND_STAGE = true;
634  break;
635  }
637  {
638  testEND_STEP = true;
639  auto x = sh->getWorkingState()->getX();
640  testWorkingValue = get_ele(*(x), 0);
641  break;
642  }
643  default:
644  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
645  "Error - unknown action location.\n");
646  }
647  }
648 
658  double testDt;
659  std::string testType;
660 };
661 
662 
664  : virtual public Tempus::StepperRKModifierXBase<double>
665 {
666 public:
667 
668  /// Constructor
670  : testX_BEGIN_STEP(false),
671  testX_BEGIN_STAGE(false),
672  testX_BEFORE_SOLVE(false),
673  testX_AFTER_SOLVE(false),
675  testXDOT_END_STAGE(false),
676  testX_END_STEP(false),
677  testX(-0.99),
678  testEndStageX(-0.99),
679  testDt(-1.5),
680  testTime(-1.5),
681  testStageNumber(-1),
682  testStageX(-0.99)
683  {}
684 
685  /// Destructor
687 
688  /// Observe RK Stepper at end of takeStep.
689  virtual void modify(
690  Teuchos::RCP<Thyra::VectorBase<double> > x,
691  const double time, const double dt,
692  const int stageNumber,
694  {
695  switch(modType) {
697  {
698  testX_BEGIN_STEP = true;
699  testX = get_ele(*(x), 0);
700  break;
701  }
703  {
704  testX_BEGIN_STAGE = true;
705  break;
706  }
708  {
709  testX_BEFORE_SOLVE = true;
710  testDt = dt;
711  break;
712  }
714  {
715  testX_AFTER_SOLVE = true;
716  testTime = time;
717  break;
718  }
720  {
722  testStageNumber = stageNumber;
723  testStageX = get_ele(*(x), 0); // x should be the stage value.
724  break;
725  }
727  {
728  testXDOT_END_STAGE = true;
729  testEndStageX = get_ele(*(x), 0);
730  break;
731  }
733  {
734  testX_END_STEP = true;
735  break;
736  }
737  default:
738  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
739  "Error - unknown action location.\n");
740  }
741  }
742 
750  double testX;
752  double testDt;
753  double testTime;
755  double testStageX;
756 };
757 
758 
759 /** \brief Unit test utility for Stepper RK AppAction.
760  */
762  const Teuchos::RCP<Tempus::StepperRKBase<double> >& stepper,
763  const Teuchos::RCP<const Thyra::ModelEvaluator<double> >& model,
764  Teuchos::FancyOStream &out, bool &success)
765 {
766  auto testTypeOrig = stepper->getStepperType();
767 
768  // Test Modifier.
769  {
770  stepper->setModel(model);
771  auto modifier = rcp(new StepperRKModifierTest());
772  stepper->setAppAction(modifier);
773  stepper->initialize();
774  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
775  auto testType = testTypeOrig + " - Modifier";
776 
777  // Create a SolutionHistory.
778  auto solutionHistory = Tempus::createSolutionHistoryME(model);
779 
780  // Take one time step.
781  stepper->setInitialConditions(solutionHistory);
782  solutionHistory->initWorkingState();
783  double dt = 0.1;
784  solutionHistory->getWorkingState()->setTimeStep(dt);
785  stepper->takeStep(solutionHistory);
786 
787  // Testing that each ACTION_LOCATION has been called.
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);
795 
796  // Testing that values can be set through the modifier.
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);
803 
804  TEST_COMPARE(modifier->testType, ==, testType);
805  }
806 
807  // Test Observer.
808  {
809  stepper->setModel(model);
810  auto observer = rcp(new StepperRKObserverTest());
811  stepper->setAppAction(observer);
812  stepper->setStepperType(testTypeOrig);
813  stepper->initialize();
814  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
815 
816  // Create a SolutionHistory.
817  auto solutionHistory = Tempus::createSolutionHistoryME(model);
818 
819  // Take one time step.
820  stepper->setInitialConditions(solutionHistory);
821  solutionHistory->initWorkingState();
822  double dt = 0.1;
823  solutionHistory->getWorkingState()->setTimeStep(dt);
824  stepper->takeStep(solutionHistory);
825 
826  // Testing that each ACTION_LOCATION has been called.
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);
834 
835  // Testing that values can be observed through the observer.
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);
842 
843  auto testType = testTypeOrig + " - Observer";
844  TEST_COMPARE(observer->testType, ==, testType);
845  }
846 
847  // Test ModifierX.
848  {
849  stepper->setModel(model);
850  auto modifierX = rcp(new StepperRKModifierXTest());
851  stepper->setAppAction(modifierX);
852  stepper->setStepperType(testTypeOrig);
853  stepper->initialize();
854  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
855 
856  // Create a SolutionHistory.
857  auto solutionHistory = Tempus::createSolutionHistoryME(model);
858 
859  // Take one time step.
860  stepper->setInitialConditions(solutionHistory);
861  solutionHistory->initWorkingState();
862  double dt = 0.1;
863  solutionHistory->getWorkingState()->setTimeStep(dt);
864  stepper->takeStep(solutionHistory);
865 
866  // Testing that each ACTION_LOCATION has been called.
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);
874 
875  // Testing that values can be set through the modifierX.
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);
880 
881  auto time = solutionHistory->getWorkingState()->getTime();
882  TEST_FLOATING_EQUALITY(modifierX->testTime, time, 1.0e-15);
883 
884  // Stage Number should be -1 outside stage loop.
885  TEST_COMPARE(stepper->getStageNumber(), ==, -1);
886  // The last stage number through X_BEFORE_EXPLICIT_EVAL should be
887  // the number of stages minus one.
888  TEST_COMPARE(modifierX->testStageNumber,==,stepper->getNumberOfStages()-1);
889 
890  if (rcp_dynamic_cast<Tempus::StepperIMEX_RK<double>>(stepper) != Teuchos::null ||
891  rcp_dynamic_cast<Tempus::StepperIMEX_RK_Partition<double>>(stepper) != Teuchos::null) {
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()) {
895  // For implicit steppers, stageX is separate memory which can be tested.
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);
899  } else {
900  // For explicit steppers, stageX is under written and not available
901  // outside takeStep, so direct comparisons are needed.
902  if (rcp_dynamic_cast<Tempus::StepperERK_3_8Rule<double>>(stepper) != Teuchos::null) {
903  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09966666666666668, 1.0e-15);
904  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09966666666666668, 1.0e-15);
905  } else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrder<double>>(stepper) != Teuchos::null) {
906  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, 1.0e-15);
907  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, 1.0e-15);
908  } else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrderHeun<double>>(stepper) != Teuchos::null) {
909  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06666666666666667, 1.0e-15);
910  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06666666666666667, 1.0e-15);
911  } else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrderTVD<double>>(stepper) != Teuchos::null) {
912  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, 1.0e-15);
913  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, 1.0e-15);
914  } else if (rcp_dynamic_cast<Tempus::StepperERK_4Stage3rdOrderRunge<double>>(stepper) != Teuchos::null) {
915  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09950000000000001, 1.0e-15);
916  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09950000000000001, 1.0e-15);
917  } else if (rcp_dynamic_cast<Tempus::StepperERK_4Stage4thOrder<double>>(stepper) != Teuchos::null) {
918  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975000000000001, 1.0e-15);
919  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975000000000001, 1.0e-15);
920  } else if (rcp_dynamic_cast<Tempus::StepperERK_5Stage3rdOrderKandG<double>>(stepper) != Teuchos::null) {
921  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06662222222222222, 1.0e-15);
922  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06662222222222222, 1.0e-15);
923  } else if (rcp_dynamic_cast<Tempus::StepperERK_BogackiShampine32<double>>(stepper) != Teuchos::null) {
924  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333333, 1.0e-15);
925  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333333, 1.0e-15);
926  } else if (rcp_dynamic_cast<Tempus::StepperERK_ForwardEuler<double>>(stepper) != Teuchos::null) {
927  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0, 1.0e-15);
928  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0, 1.0e-15);
929  } else if (rcp_dynamic_cast<Tempus::StepperERK_General<double>>(stepper) != Teuchos::null) {
930  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975000000000001, 1.0e-15);
931  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975000000000001, 1.0e-15);
932  } else if (rcp_dynamic_cast<Tempus::StepperERK_Merson45<double>>(stepper) != Teuchos::null) {
933  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333332, 1.0e-15);
934  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333332, 1.0e-15);
935  } else if (rcp_dynamic_cast<Tempus::StepperERK_Midpoint<double>>(stepper) != Teuchos::null) {
936  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, 1.0e-15);
937  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, 1.0e-15);
938  } else if (rcp_dynamic_cast<Tempus::StepperERK_Trapezoidal<double>>(stepper) != Teuchos::null) {
939  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, 1.0e-15);
940  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, 1.0e-15);
941  } else {
942  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
943  "Error - unknown stepperType = "+stepper->getStepperType());
944  }
945  }
946  }
947 
948 
949  // Test Composite.
950  {
951  stepper->setModel(model);
952 
953  auto modifier = rcp(new StepperRKModifierTest());
954  auto observer = rcp(new StepperRKObserverTest());
955  auto modifierX = rcp(new StepperRKModifierXTest());
956  auto composite = rcp(new Tempus::StepperRKAppActionComposite<double>());
957 
958  composite->addRKAppAction(modifier);
959  composite->addRKAppAction(observer);
960  composite->addRKAppAction(modifierX);
961  stepper->setAppAction(composite);
962 
963  stepper->initialize();
964  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
965 
966  // Create a SolutionHistory.
967  auto solutionHistory = Tempus::createSolutionHistoryME(model);
968 
969  // Take one time step.
970  stepper->setInitialConditions(solutionHistory);
971  solutionHistory->initWorkingState();
972  double dt = 0.1;
973  solutionHistory->getWorkingState()->setTimeStep(dt);
974  stepper->takeStep(solutionHistory);
975 
976  auto xCS = solutionHistory->getCurrentState()->getX();
977  auto xWS = solutionHistory->getWorkingState()->getX();
978  auto Dt = solutionHistory->getWorkingState()->getTimeStep();
979 
980  // Test Modifier.
981  // Testing that each ACTION_LOCATION has been called.
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);
989 
990  // Testing that values can be set through the modifier.
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);
994 
995  auto testType = testTypeOrig + " - Modifier";
996  TEST_COMPARE(modifier->testType, ==, testType);
997 
998 
999  // Test Observer.
1000  // Testing that each ACTION_LOCATION has been called.
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);
1008 
1009  // Testing that values can be observed through the observer.
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);
1013 
1014  testType = testType + " - Observer";
1015  TEST_COMPARE(observer->testType, ==, testType);
1016 
1017 
1018  // Test ModifierX.
1019  // Testing that each ACTION_LOCATION has been called.
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);
1027 
1028  // Testing that values can be set through the modifierX.
1029  TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(xCS), 0), 1.0e-15);
1030  TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, 1.0e-15);
1031 
1032  auto time = solutionHistory->getWorkingState()->getTime();
1033  TEST_FLOATING_EQUALITY(modifierX->testTime, time, 1.0e-15);
1034 
1035  // Stage Number should be -1 outside stage loop.
1036  TEST_COMPARE(stepper->getStageNumber(), ==, -1);
1037  // The last stage number through X_BEFORE_EXPLICIT_EVAL should be
1038  // the number of stages minus one.
1039  TEST_COMPARE(modifierX->testStageNumber,==,stepper->getNumberOfStages()-1);
1040 
1041  if (rcp_dynamic_cast<Tempus::StepperIMEX_RK<double>>(stepper) != Teuchos::null ||
1042  rcp_dynamic_cast<Tempus::StepperIMEX_RK_Partition<double>>(stepper) != Teuchos::null) {
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()) {
1046  // For implicit steppers, stageX is separate memory which can be tested.
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);
1050  } else {
1051  // For explicit steppers, stageX is under written and not available
1052  // outside takeStep, so direct comparisons are needed.
1053  if (rcp_dynamic_cast<Tempus::StepperERK_3_8Rule<double>>(stepper) != Teuchos::null) {
1054  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09966666666666668, 1.0e-15);
1055  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09966666666666668, 1.0e-15);
1056  } else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrder<double>>(stepper) != Teuchos::null) {
1057  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, 1.0e-15);
1058  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, 1.0e-15);
1059  } else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrderHeun<double>>(stepper) != Teuchos::null) {
1060  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06666666666666667, 1.0e-15);
1061  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06666666666666667, 1.0e-15);
1062  } else if (rcp_dynamic_cast<Tempus::StepperERK_3Stage3rdOrderTVD<double>>(stepper) != Teuchos::null) {
1063  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, 1.0e-15);
1064  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, 1.0e-15);
1065  } else if (rcp_dynamic_cast<Tempus::StepperERK_4Stage3rdOrderRunge<double>>(stepper) != Teuchos::null) {
1066  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09950000000000001, 1.0e-15);
1067  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09950000000000001, 1.0e-15);
1068  } else if (rcp_dynamic_cast<Tempus::StepperERK_4Stage4thOrder<double>>(stepper) != Teuchos::null) {
1069  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975000000000001, 1.0e-15);
1070  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975000000000001, 1.0e-15);
1071  } else if (rcp_dynamic_cast<Tempus::StepperERK_5Stage3rdOrderKandG<double>>(stepper) != Teuchos::null) {
1072  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06662222222222222, 1.0e-15);
1073  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06662222222222222, 1.0e-15);
1074  } else if (rcp_dynamic_cast<Tempus::StepperERK_BogackiShampine32<double>>(stepper) != Teuchos::null) {
1075  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333333, 1.0e-15);
1076  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333333, 1.0e-15);
1077  } else if (rcp_dynamic_cast<Tempus::StepperERK_ForwardEuler<double>>(stepper) != Teuchos::null) {
1078  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0, 1.0e-15);
1079  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0, 1.0e-15);
1080  } else if (rcp_dynamic_cast<Tempus::StepperERK_General<double>>(stepper) != Teuchos::null) {
1081  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975000000000001, 1.0e-15);
1082  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975000000000001, 1.0e-15);
1083  } else if (rcp_dynamic_cast<Tempus::StepperERK_Merson45<double>>(stepper) != Teuchos::null) {
1084  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333332, 1.0e-15);
1085  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333332, 1.0e-15);
1086  } else if (rcp_dynamic_cast<Tempus::StepperERK_Midpoint<double>>(stepper) != Teuchos::null) {
1087  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, 1.0e-15);
1088  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, 1.0e-15);
1089  } else if (rcp_dynamic_cast<Tempus::StepperERK_Trapezoidal<double>>(stepper) != Teuchos::null) {
1090  TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, 1.0e-15);
1091  TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, 1.0e-15);
1092  } else {
1093  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
1094  "Error - unknown stepperType = "+stepper->getStepperType());
1095  }
1096  }
1097  }
1098 }
1099 
1100 
1101 } // namespace Tempus_Test
1102 #endif // Tempus_UnitTest_Utils_hpp
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.
virtual void modify(Teuchos::RCP< Tempus::SolutionHistory< double > > sh, Teuchos::RCP< Tempus::StepperRKBase< double > > stepper, const typename Tempus::StepperRKAppAction< double >::ACTION_LOCATION actLoc)
Modify RK Stepper at action location.
void testExplicitRKAccessorsFullConstruction(const RCP< Tempus::StepperExplicitRK< double > > &stepper)
Unit test utility for ExplicitRK Stepper construction and accessors.
Explicit Runge-Kutta time stepper.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
Backward Euler Runge-Kutta Butcher Tableau.
General Explicit Runge-Kutta Butcher Tableau.
RK Explicit 5 Stage 3rd order by Kinnmark and Gray.
Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
RK Explicit 4 Stage 3rd order by Runge.
Unit test class for RK Stepper Modifier AppAction.
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
virtual void observe(Teuchos::RCP< const Tempus::SolutionHistory< double > > sh, Teuchos::RCP< const Tempus::StepperRKBase< double > > stepper, const typename Tempus::StepperRKAppAction< double >::ACTION_LOCATION actLoc)
Observe RK Stepper at action location.
RK Trapezoidal Rule (A.K.A. RK Crank-Nicolson)
Partitioned Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
This composite AppAction loops over added AppActions.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Nonmember contructor from a Thyra ModelEvaluator.
Base class for Runge-Kutta methods, ExplicitRK, DIRK and IMEX.
Explicit RK 3/8th Rule Butcher Tableau.
Diagonally Implicit Runge-Kutta (DIRK) time stepper.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
Explicit RK Bogacki-Shampine Butcher Tableau.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > > x, const double time, const double dt, const int stageNumber, const typename Tempus::StepperRKModifierXBase< double >::MODIFIER_TYPE modType)
Observe RK Stepper at end of takeStep.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
ACTION_LOCATION
Indicates the location of application action (see algorithm).
void testDIRKAccessorsFullConstruction(const RCP< Tempus::StepperDIRK< double > > &stepper)
Unit test utility for ExplicitRK Stepper construction and accessors.
Forward Euler Runge-Kutta Butcher Tableau.
Explicit RK Merson Butcher Tableau.
Runge-Kutta 4th order Butcher Tableau.
RK Explicit 3 Stage 3rd order by Heun.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.