Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_UnitTest_IMEX_RK_Partition.cpp
Go to the documentation of this file.
1 //@HEADER
2 // *****************************************************************************
3 // Tempus: Time Integration and Sensitivity Analysis Package
4 //
5 // Copyright 2017 NTESS and the Tempus contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 //@HEADER
9 
11 
13 
14 #include "../TestModels/VanDerPol_IMEX_ExplicitModel.hpp"
15 #include "../TestModels/VanDerPol_IMEXPart_ImplicitModel.hpp"
16 
17 namespace Tempus_Unit_Test {
18 
20 using Teuchos::RCP;
21 using Teuchos::rcp;
22 using Teuchos::rcp_const_cast;
23 using Teuchos::rcp_dynamic_cast;
24 using Teuchos::sublist;
25 
28 
29 // ************************************************************
30 // ************************************************************
31 TEUCHOS_UNIT_TEST(IMEX_RK_Partition, Default_Construction)
32 {
33  // Setup the explicit VanDerPol ModelEvaluator
34  const bool useProductVector = true;
35  auto explicitModel =
37  Teuchos::null, useProductVector));
38  auto implicitModel =
40 
41  // Setup the IMEX Pair ModelEvaluator
42  const int numExplicitBlocks = 1;
43  const int parameterIndex = 4;
45  explicitModel, implicitModel, numExplicitBlocks, parameterIndex));
46 
47  // Default construction.
48  auto stepper = rcp(new Tempus::StepperIMEX_RK_Partition<double>());
49  stepper->setModel(model);
50  stepper->initialize();
51  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
52 
53  // Default values for construction.
54  auto modifier = rcp(new Tempus::StepperRKModifierDefault<double>());
55  auto modifierX = rcp(new Tempus::StepperRKModifierXDefault<double>());
56  auto observer = rcp(new Tempus::StepperRKObserverDefault<double>());
57  auto solver = rcp(new Thyra::NOXNonlinearSolver());
58  solver->setParameterList(Tempus::defaultSolverParameters());
59 
60  bool useFSAL = stepper->getUseFSAL();
61  std::string ICConsistency = stepper->getICConsistency();
62  bool ICConsistencyCheck = stepper->getICConsistencyCheck();
63  bool zeroInitialGuess = stepper->getZeroInitialGuess();
64  std::string stepperType = "Partitioned IMEX RK SSP2";
66  auto explicitTableau = stepperERK->getTableau();
67  auto stepperSDIRK =
69  auto implicitTableau = stepperSDIRK->getTableau();
70  int order = 2;
71 
72  // Test the set functions.
73  stepper->setAppAction(modifier);
74  stepper->initialize();
75  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
76  stepper->setAppAction(modifierX);
77  stepper->initialize();
78  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
79  stepper->setAppAction(observer);
80  stepper->initialize();
81  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
82  stepper->setSolver(solver);
83  stepper->initialize();
84  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
85  stepper->setUseFSAL(useFSAL);
86  stepper->initialize();
87  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
88  stepper->setICConsistency(ICConsistency);
89  stepper->initialize();
90  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
91  stepper->setICConsistencyCheck(ICConsistencyCheck);
92  stepper->initialize();
93  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
94  stepper->setZeroInitialGuess(zeroInitialGuess);
95  stepper->initialize();
96  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
97 
98  stepper->setStepperName(stepperType);
99  stepper->initialize();
100  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
101  stepper->setExplicitTableau(explicitTableau);
102  stepper->initialize();
103  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
104  stepper->setImplicitTableau(implicitTableau);
105  stepper->initialize();
106  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
107  stepper->setOrder(order);
108  stepper->initialize();
109  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
110 
111  TEUCHOS_TEST_FOR_EXCEPT(explicitTableau != stepper->getTableau());
112  TEUCHOS_TEST_FOR_EXCEPT(explicitTableau != stepper->getExplicitTableau());
113  TEUCHOS_TEST_FOR_EXCEPT(implicitTableau != stepper->getImplicitTableau());
114 
115  // Full argument list construction.
117  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
118  zeroInitialGuess, modifier, stepperType, explicitTableau, implicitTableau,
119  order));
120  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
121 
122  // Test stepper properties.
123  // out << "order = " << stepper->getOrder() << std::endl;
124  TEUCHOS_ASSERT(stepper->getOrder() == 2);
125 }
126 
127 // ************************************************************
128 // ************************************************************
129 TEUCHOS_UNIT_TEST(IMEX_RK_Partition, StepperFactory_Construction)
130 {
131  // Setup the explicit VanDerPol ModelEvaluator
132  const bool useProductVector = true;
133  auto explicitModel =
135  Teuchos::null, useProductVector));
136  auto implicitModel =
138 
139  // Setup the IMEX Pair ModelEvaluator
140  const int numExplicitBlocks = 1;
141  const int parameterIndex = 4;
143  explicitModel, implicitModel, numExplicitBlocks, parameterIndex));
144 
145  testFactoryConstruction("Partitioned IMEX RK SSP2", model);
146 }
147 
148 // ************************************************************
149 // ************************************************************
150 TEUCHOS_UNIT_TEST(IMEX_RK_Partition,
151  StepperFactory_Construction_General_wo_Parameterlist)
152 {
153  // Setup the explicit VanDerPol ModelEvaluator
154  const bool useProductVector = true;
155  auto explicitModel =
157  Teuchos::null, useProductVector));
158  auto implicitModel =
160 
161  // Setup the IMEX Pair ModelEvaluator
162  const int numExplicitBlocks = 1;
163  const int parameterIndex = 4;
165  explicitModel, implicitModel, numExplicitBlocks, parameterIndex));
166 
168 
169  auto stepper = sf->createStepper("General Partitioned IMEX RK", model);
170  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
171 }
172 
173 // ************************************************************
174 // ************************************************************
175 TEUCHOS_UNIT_TEST(IMEX_RK_Partition,
176  StepperFactory_Construction_General_wo_Parameterlist_Model)
177 {
178  // Setup the explicit VanDerPol ModelEvaluator
179  const bool useProductVector = true;
180  auto explicitModel =
182  Teuchos::null, useProductVector));
183  auto implicitModel =
185 
186  // Setup the IMEX Pair ModelEvaluator
187  const int numExplicitBlocks = 1;
188  const int parameterIndex = 4;
190  explicitModel, implicitModel, numExplicitBlocks, parameterIndex));
191 
193 
194  auto stepper = sf->createStepper("General Partitioned IMEX RK");
195  stepper->setModel(model);
196  stepper->initialize();
197  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
198 }
199 
200 // ************************************************************
201 // ************************************************************
202 TEUCHOS_UNIT_TEST(IMEX_RK_Partition, AppAction)
203 {
204  auto stepper = rcp(new Tempus::StepperIMEX_RK_Partition<double>());
205 
206  // Setup the explicit VanDerPol ModelEvaluator
207  const bool useProductVector = true;
208  auto explicitModel =
210  Teuchos::null, useProductVector));
211  auto implicitModel =
213 
214  // Setup the IMEX Pair ModelEvaluator
215  const int numExplicitBlocks = 1;
216  const int parameterIndex = 4;
218  explicitModel, implicitModel, numExplicitBlocks, parameterIndex));
219 
220  testRKAppAction(stepper, model, out, success);
221 }
222 
223 } // namespace Tempus_Unit_Test
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.
van der Pol model formulated for the partitioned IMEX-RK.
Partitioned Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
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_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
ModelEvaluator pair for implicit and explicit (IMEX) evaulations.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)