Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros 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 
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_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;
33 using Teuchos::ParameterList;
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));
48  auto implicitModel = rcp(new Tempus_Test::VanDerPol_IMEXPart_ImplicitModel<double>());
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->getUseFSALDefault();
72  std::string ICConsistency = stepper->getICConsistencyDefault();
73  bool ICConsistencyCheck = stepper->getICConsistencyCheckDefault();
74  bool zeroInitialGuess = stepper->getZeroInitialGuess();
75  std::string stepperType = "IMEX RK SSP2";
76  auto stepperERK = Teuchos::rcp(new Tempus::StepperERK_Trapezoidal<double>());
77  auto explicitTableau = stepperERK->getTableau();
78  auto stepperSDIRK = Teuchos::rcp(new Tempus::StepperSDIRK_2Stage3rdOrder<double>());
79  auto implicitTableau = stepperSDIRK->getTableau();
80  int order = 2;
81 
82 
83  // Test the set functions.
84 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
85  auto obs = rcp(new Tempus::StepperRKObserverComposite<double>());
86  stepper->setObserver(obs); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
87 #endif
88  stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
89  stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
90  stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
91  stepper->setSolver(solver); 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->setZeroInitialGuess(zeroInitialGuess); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
96 
97  stepper->setStepperType(stepperType); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
98  stepper->setExplicitTableau(explicitTableau); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
99  stepper->setImplicitTableau(implicitTableau); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
100  stepper->setOrder(order); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
101 
102  TEUCHOS_TEST_FOR_EXCEPT(explicitTableau != stepper->getTableau());
103  TEUCHOS_TEST_FOR_EXCEPT(explicitTableau != stepper->getExplicitTableau());
104  TEUCHOS_TEST_FOR_EXCEPT(implicitTableau != stepper->getImplicitTableau());
105 
106  // Full argument list construction.
107 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
109  model, obs, solver, useFSAL,
110  ICConsistency, ICConsistencyCheck, zeroInitialGuess,
111  stepperType, explicitTableau, implicitTableau, order));
112  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
113 #endif
115  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
116  zeroInitialGuess, modifier, stepperType, explicitTableau,
117  implicitTableau, order));
118  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
119 
120  // Test stepper properties.
121  std::cout << "ordero = " << stepper->getOrder() << std::endl;
122  TEUCHOS_ASSERT(stepper->getOrder() == 2);
123 }
124 
125 
126 // ************************************************************
127 // ************************************************************
128 TEUCHOS_UNIT_TEST(IMEX_RK_Partition, StepperFactory_Construction)
129 {
130  // Setup the explicit VanDerPol ModelEvaluator
131  const bool useProductVector = true;
132  auto explicitModel = rcp(new Tempus_Test::VanDerPol_IMEX_ExplicitModel<double>(Teuchos::null, useProductVector));
133  auto implicitModel = rcp(new Tempus_Test::VanDerPol_IMEXPart_ImplicitModel<double>());
134 
135  // Setup the IMEX Pair ModelEvaluator
136  const int numExplicitBlocks = 1;
137  const int parameterIndex = 4;
139  explicitModel, implicitModel,
140  numExplicitBlocks, parameterIndex));
141 
142  testFactoryConstruction("Partitioned IMEX RK SSP2", model);
143 }
144 
145 
146 // ************************************************************
147 // ************************************************************
148 TEUCHOS_UNIT_TEST(IMEX_RK_Partition, StepperFactory_Construction_General_wo_Parameterlist)
149 {
150  // Setup the explicit VanDerPol ModelEvaluator
151  const bool useProductVector = true;
152  auto explicitModel = rcp(new Tempus_Test::VanDerPol_IMEX_ExplicitModel<double>(Teuchos::null, useProductVector));
153  auto implicitModel = rcp(new Tempus_Test::VanDerPol_IMEXPart_ImplicitModel<double>());
154 
155  // Setup the IMEX Pair ModelEvaluator
156  const int numExplicitBlocks = 1;
157  const int parameterIndex = 4;
159  explicitModel, implicitModel,
160  numExplicitBlocks, parameterIndex));
161 
162  RCP<StepperFactory<double> > sf = Teuchos::rcp(new StepperFactory<double>());
163 
164  auto stepper = sf->createStepper("General Partitioned IMEX RK", model);
165  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
166 }
167 
168 
169 // ************************************************************
170 // ************************************************************
171 TEUCHOS_UNIT_TEST(IMEX_RK_Partition, StepperFactory_Construction_General_wo_Parameterlist_Model)
172 {
173  // Setup the explicit VanDerPol ModelEvaluator
174  const bool useProductVector = true;
175  auto explicitModel = rcp(new Tempus_Test::VanDerPol_IMEX_ExplicitModel<double>(Teuchos::null, useProductVector));
176  auto implicitModel = rcp(new Tempus_Test::VanDerPol_IMEXPart_ImplicitModel<double>());
177 
178  // Setup the IMEX Pair ModelEvaluator
179  const int numExplicitBlocks = 1;
180  const int parameterIndex = 4;
182  explicitModel, implicitModel,
183  numExplicitBlocks, parameterIndex));
184 
185  RCP<StepperFactory<double> > sf = Teuchos::rcp(new StepperFactory<double>());
186 
187  auto stepper = sf->createStepper("General Partitioned IMEX RK");
188  stepper->setModel(model);
189  stepper->initialize();
190  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
191 }
192 
193 
194 // ************************************************************
195 // ************************************************************
196 TEUCHOS_UNIT_TEST(IMEX_RK_Partition, AppAction)
197 {
198  auto stepper = rcp(new Tempus::StepperIMEX_RK_Partition<double>());
199 
200  // Setup the explicit VanDerPol ModelEvaluator
201  const bool useProductVector = true;
202  auto explicitModel = rcp(new Tempus_Test::VanDerPol_IMEX_ExplicitModel<double>(Teuchos::null, useProductVector));
203  auto implicitModel = rcp(new Tempus_Test::VanDerPol_IMEXPart_ImplicitModel<double>());
204 
205  // Setup the IMEX Pair ModelEvaluator
206  const int numExplicitBlocks = 1;
207  const int parameterIndex = 4;
209  explicitModel, implicitModel,
210  numExplicitBlocks, parameterIndex));
211 
212  testRKAppAction(stepper, model, out, success);
213 }
214 
215 
216 } // 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.
ModelEvaluator pair for implicit and explicit (IMEX) evaulations.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)