Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_UnitTest_IMEX_RK.cpp
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 #include "Teuchos_UnitTestHarness.hpp"
10 #include "Teuchos_XMLParameterListHelpers.hpp"
11 #include "Teuchos_TimeMonitor.hpp"
12 #include "Teuchos_DefaultComm.hpp"
13 
14 #include "Thyra_VectorStdOps.hpp"
15 
19 
20 #include "../TestModels/VanDerPol_IMEX_ExplicitModel.hpp"
21 #include "../TestModels/VanDerPol_IMEX_ImplicitModel.hpp"
22 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
23 
24 #include <fstream>
25 #include <vector>
26 
27 namespace Tempus_Unit_Test {
28 
29 using Teuchos::RCP;
30 using Teuchos::rcp;
31 using Teuchos::rcp_const_cast;
32 using Teuchos::rcp_dynamic_cast;
33 using Teuchos::ParameterList;
34 using Teuchos::sublist;
35 using Teuchos::getParametersFromXmlFile;
36 
39 
40 
41 // ************************************************************
42 // ************************************************************
43 TEUCHOS_UNIT_TEST(IMEX_RK, Default_Construction)
44 {
45  // Setup the IMEX Pair ModelEvaluator
46  auto explicitModel = rcp(new Tempus_Test::VanDerPol_IMEX_ExplicitModel<double>());
47  auto implicitModel = rcp(new Tempus_Test::VanDerPol_IMEX_ImplicitModel<double>());
49  explicitModel, implicitModel));
50 
51  // Default construction.
52  auto stepper = rcp(new Tempus::StepperIMEX_RK<double>());
53  stepper->setModel(model);
54  stepper->initialize();
55  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
56 
57  // Default values for construction.
58  auto modifier = rcp(new Tempus::StepperRKModifierDefault<double>());
59  auto modifierX = rcp(new Tempus::StepperRKModifierXDefault<double>());
60  auto observer = rcp(new Tempus::StepperRKObserverDefault<double>());
61  auto solver = rcp(new Thyra::NOXNonlinearSolver());
62  solver->setParameterList(Tempus::defaultSolverParameters());
63 
64  bool useFSAL = stepper->getUseFSALDefault();
65  std::string ICConsistency = stepper->getICConsistencyDefault();
66  bool ICConsistencyCheck = stepper->getICConsistencyCheckDefault();
67  bool zeroInitialGuess = stepper->getZeroInitialGuess();
68  std::string stepperType = "IMEX RK SSP2";
69  auto stepperERK = Teuchos::rcp(new Tempus::StepperERK_Trapezoidal<double>());
70  auto explicitTableau = stepperERK->getTableau();
71  auto stepperSDIRK = Teuchos::rcp(new Tempus::StepperSDIRK_2Stage3rdOrder<double>());
72  auto implicitTableau = stepperSDIRK->getTableau();
73  int order = 2;
74 
75 
76  // Test the set functions.
77 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
78  auto obs = rcp(new Tempus::StepperRKObserverComposite<double>());
79  stepper->setObserver(obs); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
80 #endif
81  stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
82  stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
83  stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
84  stepper->setSolver(solver); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
85  stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
86  stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
87  stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
88  stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
89 
90  stepper->setStepperType(stepperType); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
91  stepper->setExplicitTableau(explicitTableau); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
92  stepper->setImplicitTableau(implicitTableau); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
93  stepper->setOrder(order); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
94 
95  TEUCHOS_TEST_FOR_EXCEPT(explicitTableau != stepper->getTableau());
96  TEUCHOS_TEST_FOR_EXCEPT(explicitTableau != stepper->getExplicitTableau());
97  TEUCHOS_TEST_FOR_EXCEPT(implicitTableau != stepper->getImplicitTableau());
98 
99  // Full argument list construction.
100 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
101  stepper = rcp(new Tempus::StepperIMEX_RK<double>(
102  model, obs, solver, useFSAL, ICConsistency, ICConsistencyCheck,
103  zeroInitialGuess, stepperType, explicitTableau, implicitTableau, order));
104  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
105 #endif
106  stepper = rcp(new Tempus::StepperIMEX_RK<double>(
107  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
108  zeroInitialGuess, modifier, stepperType, explicitTableau,
109  implicitTableau, order));
110  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
111 
112  // Test stepper properties.
113  TEUCHOS_ASSERT(stepper->getOrder() == 2);
114 }
115 
116 
117 // ************************************************************
118 // ************************************************************
119 TEUCHOS_UNIT_TEST(IMEX_RK, StepperFactory_Construction)
120 {
121  // Setup the IMEX Pair ModelEvaluator
122  auto explicitModel = rcp(new Tempus_Test::VanDerPol_IMEX_ExplicitModel<double>());
123  auto implicitModel = rcp(new Tempus_Test::VanDerPol_IMEX_ImplicitModel<double>());
125  explicitModel, implicitModel));
126 
127  testFactoryConstruction("IMEX RK SSP2", model);
128 }
129 
130 
131 // ************************************************************
132 // ************************************************************
133 TEUCHOS_UNIT_TEST(IMEX_RK, StepperFactory_Construction_General_wo_Parameterlist)
134 {
135  // Setup the IMEX Pair ModelEvaluator
136  auto explicitModel = rcp(new Tempus_Test::VanDerPol_IMEX_ExplicitModel<double>());
137  auto implicitModel = rcp(new Tempus_Test::VanDerPol_IMEX_ImplicitModel<double>());
139  explicitModel, implicitModel));
140 
141  RCP<StepperFactory<double> > sf = Teuchos::rcp(new StepperFactory<double>());
142 
143  auto stepper = sf->createStepper("General IMEX RK", model);
144  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
145 }
146 
147 
148 // ************************************************************
149 // ************************************************************
150 TEUCHOS_UNIT_TEST(IMEX_RK, StepperFactory_Construction_General_wo_Parameterlist_Model)
151 {
152  // Setup the IMEX Pair ModelEvaluator
153  auto explicitModel = rcp(new Tempus_Test::VanDerPol_IMEX_ExplicitModel<double>());
154  auto implicitModel = rcp(new Tempus_Test::VanDerPol_IMEX_ImplicitModel<double>());
156  explicitModel, implicitModel));
157 
158  RCP<StepperFactory<double> > sf = Teuchos::rcp(new StepperFactory<double>());
159 
160  auto stepper = sf->createStepper("General IMEX RK");
161  stepper->setModel(model);
162  stepper->initialize();
163  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
164 }
165 
166 
167 // ************************************************************
168 // ************************************************************
169 TEUCHOS_UNIT_TEST(IMEX_RK, AppAction)
170 {
171  auto stepper = rcp(new Tempus::StepperIMEX_RK<double>());
172  // Setup the IMEX Pair ModelEvaluator
173  auto explicitModel = rcp(new Tempus_Test::VanDerPol_IMEX_ExplicitModel<double>());
174  auto implicitModel = rcp(new Tempus_Test::VanDerPol_IMEX_ImplicitModel<double>());
176  explicitModel, implicitModel));
177 
178  testRKAppAction(stepper, model, out, success);
179 }
180 
181 
182 } // namespace Tempus_Test
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.
Explicit Runge-Kutta time stepper.
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
ModelEvaluator pair for implicit and explicit (IMEX) evaulations.
Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)