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: Copyright (2017) Sandia Corporation
4 //
5 // Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
6 // ****************************************************************************
7 // @HEADER
8 
11 #include "Teuchos_TimeMonitor.hpp"
12 #include "Teuchos_DefaultComm.hpp"
13 
14 #include "Thyra_VectorStdOps.hpp"
15 
16 #include "Tempus_StepperFactory.hpp"
19 
20 #include "../TestModels/VanDerPol_IMEX_ExplicitModel.hpp"
21 #include "../TestModels/VanDerPol_IMEXPart_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;
34 using Teuchos::sublist;
35 using Teuchos::getParametersFromXmlFile;
36 
39 
40 
41 // ************************************************************
42 // ************************************************************
43 TEUCHOS_UNIT_TEST(IMEX_RK_Partition, Default_Construction)
44 {
45  // Setup the explicit VanDerPol ModelEvaluator
46  const bool useProductVector = true;
47  auto explicitModel = rcp(new Tempus_Test::VanDerPol_IMEX_ExplicitModel<double>(Teuchos::null, useProductVector));
49 
50  // Setup the IMEX Pair ModelEvaluator
51  const int numExplicitBlocks = 1;
52  const int parameterIndex = 4;
54  explicitModel, implicitModel,
55  numExplicitBlocks, parameterIndex));
56 
57 
58  // Default construction.
59  auto stepper = rcp(new Tempus::StepperIMEX_RK_Partition<double>());
60  stepper->setModel(model);
61  stepper->initialize();
62  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
63 
64  // Default values for construction.
65  auto modifier = rcp(new Tempus::StepperRKModifierDefault<double>());
66  auto modifierX = rcp(new Tempus::StepperRKModifierXDefault<double>());
67  auto observer = rcp(new Tempus::StepperRKObserverDefault<double>());
68  auto solver = rcp(new Thyra::NOXNonlinearSolver());
69  solver->setParameterList(Tempus::defaultSolverParameters());
70 
71  bool useFSAL = stepper->getUseFSAL();
72  std::string ICConsistency = stepper->getICConsistency();
73  bool ICConsistencyCheck = stepper->getICConsistencyCheck();
74  bool zeroInitialGuess = stepper->getZeroInitialGuess();
75  std::string stepperType = "Partitioned IMEX RK SSP2";
77  auto explicitTableau = stepperERK->getTableau();
79  auto implicitTableau = stepperSDIRK->getTableau();
80  int order = 2;
81 
82 
83  // Test the set functions.
84  stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
85  stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
86  stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
87  stepper->setSolver(solver); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
88  stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
89  stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
90  stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
91  stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
92 
93  stepper->setStepperName(stepperType); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
94  stepper->setExplicitTableau(explicitTableau); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
95  stepper->setImplicitTableau(implicitTableau); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
96  stepper->setOrder(order); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
97 
98  TEUCHOS_TEST_FOR_EXCEPT(explicitTableau != stepper->getTableau());
99  TEUCHOS_TEST_FOR_EXCEPT(explicitTableau != stepper->getExplicitTableau());
100  TEUCHOS_TEST_FOR_EXCEPT(implicitTableau != stepper->getImplicitTableau());
101 
102  // Full argument list construction.
104  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
105  zeroInitialGuess, modifier, stepperType, explicitTableau,
106  implicitTableau, order));
107  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
108 
109  // Test stepper properties.
110  //std::cout << "order = " << stepper->getOrder() << std::endl;
111  TEUCHOS_ASSERT(stepper->getOrder() == 2);
112 }
113 
114 
115 // ************************************************************
116 // ************************************************************
117 TEUCHOS_UNIT_TEST(IMEX_RK_Partition, StepperFactory_Construction)
118 {
119  // Setup the explicit VanDerPol ModelEvaluator
120  const bool useProductVector = true;
121  auto explicitModel = rcp(new Tempus_Test::VanDerPol_IMEX_ExplicitModel<double>(Teuchos::null, useProductVector));
123 
124  // Setup the IMEX Pair ModelEvaluator
125  const int numExplicitBlocks = 1;
126  const int parameterIndex = 4;
128  explicitModel, implicitModel,
129  numExplicitBlocks, parameterIndex));
130 
131  testFactoryConstruction("Partitioned IMEX RK SSP2", model);
132 }
133 
134 
135 // ************************************************************
136 // ************************************************************
137 TEUCHOS_UNIT_TEST(IMEX_RK_Partition, StepperFactory_Construction_General_wo_Parameterlist)
138 {
139  // Setup the explicit VanDerPol ModelEvaluator
140  const bool useProductVector = true;
141  auto explicitModel = rcp(new Tempus_Test::VanDerPol_IMEX_ExplicitModel<double>(Teuchos::null, useProductVector));
143 
144  // Setup the IMEX Pair ModelEvaluator
145  const int numExplicitBlocks = 1;
146  const int parameterIndex = 4;
148  explicitModel, implicitModel,
149  numExplicitBlocks, parameterIndex));
150 
152 
153  auto stepper = sf->createStepper("General Partitioned IMEX RK", model);
154  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
155 }
156 
157 
158 // ************************************************************
159 // ************************************************************
160 TEUCHOS_UNIT_TEST(IMEX_RK_Partition, StepperFactory_Construction_General_wo_Parameterlist_Model)
161 {
162  // Setup the explicit VanDerPol ModelEvaluator
163  const bool useProductVector = true;
164  auto explicitModel = rcp(new Tempus_Test::VanDerPol_IMEX_ExplicitModel<double>(Teuchos::null, useProductVector));
166 
167  // Setup the IMEX Pair ModelEvaluator
168  const int numExplicitBlocks = 1;
169  const int parameterIndex = 4;
171  explicitModel, implicitModel,
172  numExplicitBlocks, parameterIndex));
173 
175 
176  auto stepper = sf->createStepper("General Partitioned IMEX RK");
177  stepper->setModel(model);
178  stepper->initialize();
179  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
180 }
181 
182 
183 // ************************************************************
184 // ************************************************************
185 TEUCHOS_UNIT_TEST(IMEX_RK_Partition, AppAction)
186 {
187  auto stepper = rcp(new Tempus::StepperIMEX_RK_Partition<double>());
188 
189  // Setup the explicit VanDerPol ModelEvaluator
190  const bool useProductVector = true;
191  auto explicitModel = rcp(new Tempus_Test::VanDerPol_IMEX_ExplicitModel<double>(Teuchos::null, useProductVector));
193 
194  // Setup the IMEX Pair ModelEvaluator
195  const int numExplicitBlocks = 1;
196  const int parameterIndex = 4;
198  explicitModel, implicitModel,
199  numExplicitBlocks, parameterIndex));
200 
201  testRKAppAction(stepper, model, out, success);
202 }
203 
204 
205 } // 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.
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.
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)